This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getSnapshot(callback) { | |
"use strict"; | |
callback = callback || Boolean; | |
var canvas = document.createElement("canvas"), | |
ctx = canvas.getContext("2d"), | |
webkit = false, | |
moz = false, | |
v = null, | |
W = 800, | |
H = 600, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function salad(numbers) { // word salad function for making (hopefully) human-memorable hashes for 64 digit strings (adapt as needed) | |
var r = "ability|able|about|above|accept|access|according|account|achieve|across|act|action|activity|actually|add|addition|admit|advantage|advice|affair|affect|after|again|against|age|ago|agree|agreement|air|all|allow|almost|along|already|also|although|always|among|amount|analysis|and|animal|announce|another|answer|any|anyone|anything|anyway|appear|application|apply|approach|appropriate|area|argue|argument|arm|army|around|arrive|art|ask|aspect|association|assume|attempt|attention|attitude|authority|available|avoid|award|aware|away|baby|back|bad|bank|base|basic|basis|bear|because|become|bed|before|begin|behavior|behind|believe|benefit|better|between|beyond|big|bill|bit|black|blood|board|body|book|both|box|boy|break|bring|brother|build|building|business|but|buy|call|campaign|can|capital|car|care|carry|case|catch|cause|cell|central|center|century|certain|certainly|chance|change|c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sanitize(ht){ // tested in ff, ch, ie9+ | |
return new Option(ht).innerHTML; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//public domain, based on https://www.schneier.com/blog/archives/2014/10/spritz_a_new_rc.html | |
function spritz(key, str) { | |
var s = [], | |
j = 0, | |
w = 17, | |
k = 0, | |
res = [], | |
l = key.length, | |
m = str.length, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// public domain, from wikipedia description: https://en.wikipedia.org/wiki/RC4#Spritz | |
function rc4(key, str) { | |
var s = [], | |
j = 0, | |
x, res = [], | |
i, j, y, l = key.length, | |
m = str.length; | |
for(i = 0; i < 256; i++) s[i] = i; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//a promise-based ajax io | |
function pGet(url, data) { | |
return new Promise(function(y, n) { | |
var e = new XMLHttpRequest(); | |
e.responseType="document"; | |
e.onload=x=>y(e.response); | |
if(n) e.onerror=x=>n(e); | |
e.open(data?"POST":"GET", url, true); | |
setTimeout(e.send.bind(e,data), 0); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var words = { | |
abandon: "forsake, desert", | |
abbey: "monastery", | |
able: "capable", | |
abolish: "get rid of", | |
abortion: "termination pregnancy", | |
abridge: "shorten, cut", | |
absence: "failure to be present", | |
absolute: "perfect or complete", | |
absorb: "take in, suck up", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function freeze(ob) { | |
for(var k in ob) { | |
if(!freeze.hasOwnProperty.call(ob, k)) continue; | |
if(typeof ob[k] === "object" && ob[k]) freeze(v); | |
} | |
return Object.freeze(ob); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cls(fn, state){ | |
return Object.freeze(fn.call(state)); | |
} | |
var x= cls(function(){return{ | |
get: ( )=> this.val, | |
set: (v)=> this.val=v, | |
}}, { | |
val: 654 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//enough parens here to compile lisp apps... | |
var x= Object.freeze(((val)=>({ | |
get: ( )=> val, | |
set: (v)=> val=v, | |
}))(123)); | |
x.get(); // 123 | |
x.set(321); // 321 | |
x.get(); // 321 |