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
'use strict'; | |
var INTERVAL = 50; | |
class Bubble { | |
constructor() { | |
this.x = parseInt(window.innerWidth * Math.random(), 10); | |
this.y = parseInt(window.innerHeight * Math.random(), 10); | |
this.xDir = Math.random() > 0.5 ? 1 : -1; | |
this.yDir = Math.random() > 0.5 ? 1 : -1; | |
this.size = parseInt(Math.random() * 100) + 40; |
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 an array of argument names | |
function getArgNames(fn) { | |
var matches = fn.toString().match(/\(([a-z_, ]+)\)/i); | |
if (matches.length > 1) { | |
return matches[1].replace(/\s+/g, '').split(','); | |
} | |
return []; | |
} | |
// some sample implementation |
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 Handler(fn) { | |
this.func = fn; | |
return this; | |
} | |
Handler.prototype.handle = function(errMsg, callback) { | |
this.exceptions[errMsg] = callback; | |
} | |
Handler.prototype.try = function(context) { | |
context = context || this; | |
try { |
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 yo(fn) { | |
if (fn instanceof Function) { | |
this.listeners.push(fn); | |
} else { | |
_.each(this.listeners, function (listener) { | |
listener(fn); | |
}) | |
} | |
} |
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
// language exceptions | |
var exceptions = { | |
"are": "were", | |
"eat": "ate", | |
"go": "went", | |
"have": "had", | |
"inherit": "inherited", | |
"is": "was", | |
"run": "ran", | |
"sit": "sat", |
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 Color(r, g, b) { | |
if (Array.isArray(r)) { | |
colors = r; | |
} else if (!g && !b) { | |
colors = this.asRGB(r); | |
} else { | |
colors = [r, g, b]; | |
} | |
this.r = colors[0]; | |
this.g = colors[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
var Rangemap = function(points, values) { | |
this.points = points || []; | |
this.values = values || []; | |
}; | |
Rangemap.prototype = { | |
"equalInRange": true, | |
"compare": function(a, b) { | |
if (a === b) { | |
return this.equalInRange; |
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
if (Object.defineProperty) { | |
Object.defineProperty(Object.prototype, 'doYouEven', { | |
value: function(key) { | |
var props = (key || '').split('.'), | |
item = this; | |
for (var i=0; i<props.length; i++) { | |
item = item[props[i]]; | |
if (typeof item === 'undefined') return false; | |
} | |
return true; |
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
/** | |
* Returns TRUE if all arguments passed in can be evaluated as true. | |
* Otherwise, returns FALSE. | |
*/ | |
function all() { | |
var i, l = arguments.length; | |
for (i = 0; i < l; i++) { | |
if (!arguments[i]) { | |
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
function fmtWholeNum (num) { | |
var n = parseFloat(num.toString().replace(/[^\d\.]+/, '')), | |
s = Math.floor(n).toString(); | |
return s.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") | |
} |
NewerOlder