Original link: http://www.concentric.net/~Ttwang/tech/inthash.htm
Taken from: http://web.archive.org/web/20071223173210/http://www.concentric.net/~Ttwang/tech/inthash.htm
Reformatted using pandoc
Thomas Wang, Jan 1997
last update Mar 2007
abstract class Dual(val rank: Int) { | |
self => | |
// Cell value accessor | |
protected def get(r: Int, c: Int): Double | |
// Memoizing cell value accessor | |
def apply(r: Int, c: Int): Double = memo.getOrElseUpdate(r - c, self.get(r, c)) | |
// The memo table |
Original link: http://www.concentric.net/~Ttwang/tech/inthash.htm
Taken from: http://web.archive.org/web/20071223173210/http://www.concentric.net/~Ttwang/tech/inthash.htm
Reformatted using pandoc
Thomas Wang, Jan 1997
last update Mar 2007
var Nothing = {Nothing: true} | |
function MaybeGenerator() { | |
var g = arguments[arguments.length - 1] | |
// list of functions that test for any "Nothing" values | |
var maybes = [].slice.call(arguments,0,arguments.length - 1) | |
return function(value) { | |
var generator = g.apply(null,[].slice.call(arguments,1)) | |
var result |
function s4() { | |
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); | |
} | |
function guid() { | |
return (s4() + s4() + "-" + s4() + s4() + "-" + s4() + "-" + s4() + s4() + s4()).toLowerCase(); | |
} | |
function handle(scope, fnName, args, componentResult) { | |
return function (key) { | |
var component = scope.component = scope.composite.components[key]; | |
if (fnName in component && typeof component[fnName] === "function") { |
Attention: the list was moved to
https://github.com/dypsilon/frontend-dev-bookmarks
This page is not maintained anymore, please update your bookmarks.
(function(global) { | |
var types = function(obj) { | |
throw new TypeError("fmap called on unregistered type: " + obj); | |
}; | |
// inefficient as hell, but as long as there aren't too many types.... | |
global.Functor = function(type, defs) { | |
var oldTypes = types; | |
types = function(obj) { | |
if (type.prototype.isPrototypeOf(obj)) { |
var boxes = [ | |
{id: "A", weight: 12, value: 4}, | |
{id: "B", weight: 2, value: 2}, | |
{id: "C", weight: 1, value: 1}, | |
{id: "D", weight: 4, value: 10}, | |
{id: "E", weight: 1, value: 2} | |
]; | |
var knapsack = Stack(function (config) { | |
//decide next or finish | |
if (config.availableOptions.length) { |
var strategy = {}; | |
strategy["slice"] = function () { | |
return Array.prototype.slice.call(arguments, 0); | |
}; | |
strategy["cache slice"] = (function () { | |
var slice = Array.prototype.slice; | |
return function () { | |
return slice.call(arguments, 0); | |
}; | |
}()); |
function shift(arr, i) { | |
var cut = arr.length - i; | |
return arr.slice(cut).concat(arr.slice(0, cut)); | |
} | |
var arr = [1,2,3,4,5]; | |
shift(arr, 1); //[5, 1, 2, 3, 4] | |
shift(arr, 3); //[3, 4, 5, 1, 2] |