This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(""); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Good | |
function lambdafy( f ) | |
{ | |
return function lambdafier() { | |
var args = Array.prototype.slice.call(arguments); | |
return function lambda(){ | |
f.apply( this , args ); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function merge(object, boltOn) { | |
//Simply merge the properties of boltOn into object | |
for(var property in boltOn) | |
if(boltOn.hasOwnProperty(property)) | |
object[property] = boltOn[property]; | |
return object; | |
} | |
function compose( /*Constructor1, Constructor2, ..*/ ) { | |
//Keep a closure reference for later |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Dump all 'user space' globals | |
Many thanks to glutamat: http://stackoverflow.com/questions/14585537 */ | |
void( (function() | |
{ | |
var w = document.body.appendChild( document.createElement("iframe") ).contentWindow, | |
known = | |
[ | |
"screenLeft" , "screenTop" , "scrollX" , "scrollY" , "pageYOffset" , "pageXOffset" , /* Scrolling related built-ins */ | |
"innerWidth" , "innerHeight" , "outerWidth" , "outerHeight" , /* Size related built-ins */ | |
"defaultstatus" , "defaultStatus", /* Status bar text related built-ins */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isPrime( n ) | |
{ | |
if( n < 2 ) | |
return false | |
if( n < 4 ) | |
return true; | |
if( n % 2 == 0 ) | |
return false; | |
if( n % 3 == 0 ) | |
return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Excerpt from: https://github.com/Animatron/player/blob/master/anm.collisions.js | |
function edgeTest(p1, p2, p3, r2) { | |
var rot = [ -(p2[1] - p1[1]), | |
p2[0] - p1[0] ]; | |
var ref = (rot[0] * (p3[0] - p1[0]) + | |
rot[1] * (p3[1] - p1[1])) >= 0; | |
for (var i = 0, il = r2.length; i < il; i+=2) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function formatNumber( n , precision ) | |
{ | |
n = n * 1; | |
return n.toLocaleString().split(".")[0] + "." + n.toFixed( precision || 2 ).split(".")[1]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Permute will give all permutations for the provided array ( sourceSet ) | |
do not provide usedSet nor permutationSet | |
Based on http://stackoverflow.com/a/9960925/7602 | |
*/ | |
function permute( sourceSet , usedSet , permutationsSet ) { | |
permutationsSet = permutationsSet || []; | |
usedSet = usedSet || []; | |
for (var i = 0; i < sourceSet.length; i++) { | |
usedSet.push( sourceSet.splice(i, 1)[0] ); | |
if (!sourceSet.length) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sortfunction(a, b) | |
{ | |
return (a - b) //causes an array to be sorted numerically and ascending | |
} | |
function canWeDoIt( target , a ) | |
{ | |
if( a.length == 1 ) | |
return (a[0] == target); | |
if( a[0] == target ) |
OlderNewer