Skip to content

Instantly share code, notes, and snippets.

View buzzdecafe's full-sized avatar
💭
quaquaquaqua

buzzdecafe

💭
quaquaquaqua
View GitHub Profile
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
@timruffles
timruffles / maybe-es6.js
Last active December 20, 2015 12:19
Generators let you cut away at boiler-plate. Here I'm using it to do similar things to Haskell's Maybe, which effectively defines an error state (e.g NaN) once, and then write a lot of code that doesn't now have to bother checking for it explicitly. The numericalProcess can now be defined without any checking for NaN, in a point-free (not refere…
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
@CrossEye
CrossEye / tap.md
Last active December 19, 2015 17:39

Interesting and yet frightening technique

Run the following code against [Ramda][ramda].

// Simple predicate to test whether a number is even
var even = function(n) {return (n % 2) === 0;};

// Generates an infinite list of Fibonacci numbers

var fibsgen = generator(

@AutoSponge
AutoSponge / delegate.js
Created June 25, 2013 14:16
experiment in creating a delegation api capable of returning various important values
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") {
@dypsilon
dypsilon / frontendDevlopmentBookmarks.md
Last active March 27, 2025 08:16
A badass list of frontend development resources I collected over time.
@CrossEye
CrossEye / Functor.js
Last active July 26, 2020 19:59
First Functor Fantasy
(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]