Skip to content

Instantly share code, notes, and snippets.

export function getIn(key, obj, alt) {
return key in obj ? obj[key] : alt;
}
export function getOwn(key, obj, alt) {
return obj.hasOwnProperty(key) ? obj[key] : alt;
}
export function set(key, obj, val) {
obj[key] = val;
@DEADB17
DEADB17 / function-helpers.js
Last active December 9, 2016 16:05
Commonly used js function helpers. When lodash is too much.
/**
* Partial function application. Fixes the number of arguments to a function,
* producing another function of smaller arity.
*
* @arg {function} fn Target function.
* @arg {...*} args Arguments to fix.
* @return {function} New function with fixed arguments.
*/
const part = (fn, ...args) => fn.bind(undefined, ...args);
@DEADB17
DEADB17 / cheney.cpp
Last active August 29, 2015 14:26 — forked from rednaxelafx/cheney.cpp
Pseudo-code that implements Cheney's algorithm for copying GC
// Pseudo-code that implements Cheney's algorithm
class Object {
// remains null for normal objects
// non-null for forwarded objects
Object* _forwardee;
public:
void forward_to(address new_addr);
Object* forwardee();
@DEADB17
DEADB17 / ceki-tco.js
Last active August 29, 2015 14:24 — forked from be5invis/ceki-tco.js
// noprotect
function Returning(k){
var k1 = function(x){ return k(x) }
k1.isReturn = true;
k1.ori = k;
return k1;
}
function interpret(c, e, k){
if(typeof c === 'string') return k(e[c]);
else if(c instanceof Array) switch(c[0]) {
@DEADB17
DEADB17 / genfun.js
Created December 16, 2014 21:35
Minimalistic javascript generic functions inspired by https://github.com/pjeby/simplegeneric.js
(function(xports) {
'use strict';
var noMeth = function () { throw new ReferenceError('No such method'); };
var defProp = Object.defineProperty || function (obj, prop, desc) {
return obj[prop] = desc.value;
};
var genfun = function (key, defaultFun) {
if (!defaultFun) { defaultFun = noMeth; }
var appl = function () {
var obj = arguments[0];