Skip to content

Instantly share code, notes, and snippets.

@Rich-Harris
Rich-Harris / README.md
Last active May 6, 2024 10:29
Testing array.splice vs array.pop vs set.delete

You have an array. Its sort order doesn't matter. You want to remove an item from this array.

The obvious thing to do would be to use splice:

function remove(array, item) {
  const index = array.indexOf(item);
  array.splice(index, 1);
}
@Rich-Harris
Rich-Harris / lookup-vs-nested-foreach.js
Created June 29, 2020 17:44
lookup vs nested foreach
// re https://stackoverflow.com/questions/62621666/how-can-i-reliably-merge-objects-from-these-2-arrays-and-loop-the-resulting-arra/62623714?noredirect=1#comment110766294_62623714
function with_nested_for_each([a, b]) {
const result = [];
a.forEach(p => {
b.forEach(q => {
if (p.code === q.code) {
result.push(Object.assign({}, p, q));
}
@Rich-Harris
Rich-Harris / custom-element.js
Created June 20, 2018 18:59
Svelte with/without `customElement: true`
var hw = (function () {
'use strict';
function noop() {}
function assign(tar, src) {
for (var k in src) tar[k] = src[k];
return tar;
}
@DashW
DashW / ScreenRecorder.cs
Last active May 6, 2024 10:27
ScreenRecorder - High Performance Unity Video Capture Script
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading;
class BitmapEncoder
{
public static void WriteBitmap(Stream stream, int width, int height, byte[] imageData)
@ismailbaskin
ismailbaskin / turkce_isimler.sql
Last active May 6, 2024 10:27
Türkçe isim veritabanı
-- Turkce isimler sozlugu twitter : http://twitter.com/baskindev
CREATE TABLE `isimler` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`isimler` varchar(255) DEFAULT NULL,
`cinsiyet` varchar(255) DEFAULT NULL COMMENT 'erkek : E , kadın : K , uniseks : U',
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
-- ----------------------------
@Tomakin
Tomakin / axios_httpClient.js
Last active May 6, 2024 10:26
default axios http requests
import axios from "axios";
import { authenticationService, success, error } from "../_services/index";
class httpClient {
constructor() {
const stringUser = localStorage.getItem("currentUser");
const userObject = JSON.parse(stringUser) || "{}";
const token = userObject.token || "{}";
const instancer = axios.create({
// addEventListener polyfill IE6+
if ( !window.addEventListener ) {
(function ( win, doc ) {
var Event, addEventListener, removeEventListener, head, style;
Event = function ( e, element ) {
var property, instance = this;
for ( property in e ) {
instance[ property ] = e[ property ];
<script type="text/javascript">
// See MDN: https://developer.mozilla.org/en-US/docs/DOM/MutationObserver?redirectlocale=en-US&redirectslug=DOM%2FDOM_Mutation_Observers
(function(){
// select the target node
var target = document.querySelector('body');
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
var i={};
// create an observer instance
var observer = new MutationObserver(function(mutations) {
@Rich-Harris
Rich-Harris / App.html
Created March 28, 2018 15:33 — forked from paulocoghi/App.html
Multiple components and store variables ($)
<InputAdd></InputAdd>
<List></List>
<script>
import InputAdd from './InputAdd.html'
import List from './List.html'
import { Store } from 'svelte/store.js';
@Oranzh
Oranzh / AES-256 encryption and decryption in PHP and C#.md
Created March 24, 2018 04:19
AES-256 encryption and decryption in PHP and C#

AES-256 encryption and decryption in PHP and C#

Update: There is a more secure version available. Details

PHP

<?php

$plaintext = 'My secret message 1234';