Skip to content

Instantly share code, notes, and snippets.

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
@gordonbrander
gordonbrander / smd.js
Last active September 3, 2017 05:16 — forked from anonymous/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])
// 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);
@gordonbrander
gordonbrander / idOf.js
Last active December 14, 2015 06:29 — forked from anonymous/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')) ?