Skip to content

Instantly share code, notes, and snippets.

Avatar

Gordon Brander gordonbrander

View GitHub Profile
View memoize.js
function id(x) {
return x;
}
// Memoize a function -- creates a new function that will cache the results of
// the first return by serializing inputs as a key.
//
// * `fn`: the function to be memoized.
// * `hash`: a function to create the cache key.
// * `out`: a function to process memoized data on the way out. Useful if you need
View smd.js
(function(exports) {
var modules = {}
var factories = {}
// Require a module by id.
function require(id) {
if (!(id in factories)) throw Error(id + ' module is not defined')
if (!(id in modules)) {
modules[id] = {}
factories[id](require, modules[id])
View linked-list.js
// https://en.wikipedia.org/wiki/Linked_list
// https://blog.jcoglan.com/2007/07/23/writing-a-linked-list-in-javascript/
// Reducible prototype for linked list node.
var __node__ = {
reduce: function reduceNodes(reducer, initial) {
var node = this;
var accumulated = initial;
do {
accumulated = reducer(accumulated, node);
View idOf.js
function uid() {
// Generate a unique and non-colliding id.
return Math.random().toString(36).slice(2);
}
// Create unique, non-colliding ID namespace.
var __id__ = uid();
function idOf(thing) {
return (thing && typeof(thing) === ('object' || 'function')) ?
You can’t perform that action at this time.