Skip to content

Instantly share code, notes, and snippets.

@konijn
konijn / Hmm.js
Last active August 29, 2015 14:03
var Hmm = (function()
{ //A snippet/library to find records in table-like JS arrays
function getNamedValue( o , name )
{ //Name can have dots, 'car.tire.brand.name' should get the expected
var parts = name.split(".");
while( parts.length && o ){
o = o[parts.shift()];
}
return o;
//Good
function lambdafy( f )
{
return function lambdafier() {
var args = Array.prototype.slice.call(arguments);
return function lambda(){
f.apply( this , args );
}
}
}
@konijn
konijn / template.js
Created February 7, 2014 14:29
Tiny Templates
function fillTemplate( s )
{ //Replace ~ with further provided arguments
for( var i = 1, a = s.split('~'), s = '' ; i < arguments.length ; i++ )
s = s + a.shift() + arguments[i];
return s + a.join("");
}