Skip to content

Instantly share code, notes, and snippets.

@c7x43t
c7x43t / README.md
Created June 6, 2019 17:13 — forked from lovasoa/README.md
Compute the intersection of large arrays in javascript

Array intersect

Fastest function to intersect a large number of big arrays in javascript, without dependencies

  • The compressed version is only 345 caracters long.
  • Faster than common libraries, even a large number of arrays, or on very big arrays. (See benchmarks)

Usage

// unfinieshed
function matchAll(regEx,str,group=0){
regEx.lastIntex=0;
var match;
var results=[];
while((match=regEx.exec(str))!==null){
results.push(match[group]);
}
return results;
}
// index size: ~ 146kB / distance / 1000 words
// https://www.kaggle.com/yk1598/symspell-spell-corrector
// https://github.com/wolfgarbe/SymSpell
function calculateWordDistance1Deletes(word){
var deletes={};
var fragment;
for(var j=0;j<word.length;j++){
fragment=wordCut(word,j);
deletes[fragment]!==undefined?deletes[fragment]++:(deletes[fragment]=1);
}
@c7x43t
c7x43t / tls.conf
Last active December 10, 2018 15:23 — forked from pascalandy/tls.conf
My Ghost blog, NGiNX TLS configuration | X25519 & secp384r1 | RSA & ECDSA
# RSA
ssl_certificate /path/fullchain.pem;
ssl_certificate_key /path/privkey.pem;
# ECDSA
ssl_certificate /path/0001_chain.pem;
ssl_certificate_key /path/itchy.nl.ec.key;
ssl_dhparam /path/dhparam4096.pem;
var html = '<div id="test_div"><ul><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul></div>';
var parser = new DOMParser();
var wrapper = parser.parseFromString(html, "text/html"); // this is a DocumentFragment
// Polyfill for DOMParser.parseFromString to support html: https://developer.mozilla.org/de/docs/Web/API/DOMParser
function handler(mutations) {}
var observer = new MutationObserver(handler);
var options = {attributes: true}
observer.observe(element, options);
@c7x43t
c7x43t / gist:935a7cbd457a16936001105cb57b5eb4
Created November 5, 2018 13:01 — forked from AndreasMadsen/gist:2693051
base64 shim [atob, btoa]
// Source: http://code.google.com/p/gflot/source/browse/trunk/flot/base64.js?r=153
/* Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>
* Version: 1.0
* LastModified: Dec 25 1999
* This library is free. You can redistribute it and/or modify it.
*/
/*
* Interfaces:
Statistical profiling result from isolate-0x55f6bb94e1f0-v8.log, (7139 ticks, 137 unaccounted, 0 excluded).
[Shared libraries]:
ticks total nonlib name
318 4.5% /usr/bin/node
194 2.7% /lib/x86_64-linux-gnu/libc-2.27.so
18 0.3% /usr/lib/x86_64-linux-gnu/libuv.so.1.0.0
2 0.0% [vdso]
1 0.0% /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25
Object.prototype[Symbol.iterator]=function* objectIterator(){
const keys=Object.keys(this);
for(var i=0;i<keys.length;i++) yield keys[i];
}
function getEventNames() {
var doc = [];
for (var i in document) {
doc.push(i)
};
doc = doc.filter(function(i) {
var e = document[i];
return i.substring(0, 2) == 'on' && (e == null || e instanceof Function)
})
.map(s => s.replace(/^on/, ""));