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 (root, factory) { | |
if (typeof define === 'function' && define.amd) { | |
// AMD. Register as an anonymous module. | |
define([], factory); | |
} else if (typeof exports === 'object') { | |
// Node. Does not work with strict CommonJS, but | |
// only CommonJS-like environments that support module.exports, | |
// like Node. | |
module.exports = factory(); | |
} else { |
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 extend(/* objects */) { | |
var args = [].slice.call(arguments,0), | |
base = args.shift(), | |
len = args.length; | |
while (args.length) { | |
var o = args.pop(); | |
for (var prop in o) { | |
// properties override those existing | |
if (typeof base[prop] === 'undefined' && typeof o[prop] !== 'function') { | |
base[prop] = o[prop]; |
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
/** | |
* Return a random number between min/max where the mean | |
* result is approximately the mode across a uniform distribution. | |
* @param min {Number} - lower limit of range (inclusive) | |
* @param max {Number} - upper limit of range (inclusive) | |
* @return {Function} - a function that returns a random number between 'min' and 'max' | |
*/ | |
var genRandomFromRangeFn = function(min, max) { | |
return function() { | |
var res = Math.round(Math.random() * (max - min)) + min; |
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 slice = Array.prototype.slice, | |
join = Array.prototype.join, | |
concat = Array.prototype.concat, | |
toString = Object.prototype.toString, | |
isString = function(o){ return toString.call(o) == '[object String]'; }, | |
isArray = function(o) { return toString.call(o) == '[object Array]'; }; | |
// I Combinator |
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
<!DOCTYPE html> | |
<html ng-app="app"> | |
<head> | |
<script src="http://code.jquery.com/jquery.min.js"></script> | |
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"> | |
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> | |
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script> | |
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> |
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
<!DOCTYPE html> | |
<html ng-app="app"> | |
<head> | |
<script src="http://code.jquery.com/jquery.min.js"></script> | |
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"> | |
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> | |
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script> | |
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> |
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 assert = { | |
test: 1, | |
equal: function(exp, target) { | |
console.log("[test](%d) expected "+target+" got " + exp + " (%s)", this.test++, (exp == target ? 'SUCCESS' : 'FAIL')); | |
} | |
}; | |
// SKITTLES | |
// Given a target goal in kilograms, and a number of | |
// small bags of skittles (1kg) and large bags of skittles (5kg) |
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
// | |
// Some common utility combinators and helpers | |
// | |
function flip(fn) { | |
return function() { | |
var args = [].slice.call(arguments); | |
return fn.apply(this, args.reverse()); | |
}; | |
} |
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
// | |
// This is the actual implementation using our minimal functional library | |
// | |
var validate = { | |
'values': function(o) { return !isNull(o) && !isUndefined(o) && (isBoolean(o) || isNumber(o) || isString(o)); }, | |
'arrays': function(o) { return !isNull(o) && !isUndefined(o) && isArray(o); } | |
} | |
var build = { | |
'values': function(prop, val) { return [prop,"=",qs(val.toString())].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
['Function','Array'].forEach(function(type) { | |
var checkFn = 'is'+type; | |
window[checkFn] = function(o){ return Object.prototype.toString.call(o) == '[object ' + type + ']'; }; | |
}); | |
// Return new list as combination of the two lists passed | |
// The second list can be a function which will be passed each item | |
// from the first list and should return an array to permute that item | |
// with. If either argument is not a list, it will be treated as a list. | |
// |