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 createObservedArray | |
* @params function observer A callback function returning the name of the used Array function. | |
* @returns Array The observed array | |
* @note This is just a simple way to observe an array, do not use in production ;) | |
*/ | |
function createObservedArray(observer) { | |
var array = [], | |
methods = ['pop', 'push', 'shift', 'unshift', 'slice', 'splice', 'reduce']; | |
for (var i = methods.length; i--;) { |
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 que = (function (q) { | |
/** | |
* Pause & queue a set of dynamically added async requests until the `resume` promise is resolved. | |
* | |
* @method que | |
* @param {Function} pause A function that returns a boolean which results the que instance to pause. Will be executed with every add() or resolved promise. | |
* @param {Function} resume A function that returns a promise which tells the que instance to resume when it resolves. It does nothing when the promise is rejected. | |
* @return {Object} que instance | |
*/ | |
function que(pause, resume) { |
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 getHashCode(obj) { | |
var hashCode = 0; | |
if (typeof obj === 'object') | |
for (var prop in obj) { | |
var code = getHashCode(prop) + getHashCode(obj[prop]); | |
hashCode += code * code; | |
} | |
else | |
for(var str = "" + obj, i = str.length; i--;) | |
hashCode += 100 / (i + str.charCodeAt(i)); |
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
waterfall(['a', 'bbbb', 'cc'], function(item){ | |
return function(resolve){ | |
setTimeout(function(){ | |
console.log(item); | |
resolve(); | |
}, item.length * 1000); | |
}; | |
}); |
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
// deburglar.getDupes(); | |
var deburglar = (function () { | |
var dict = {}; | |
var maybeTheOriginalOpen = XMLHttpRequest.prototype.open; | |
XMLHttpRequest.prototype.open = function (method, url) { | |
if (!dict[url]) | |
dict[url] = 0; | |
dict[url]++; | |
return maybeTheOriginalOpen.apply(this, arguments); | |
}; |
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(w){ | |
var oldST = w.setTimeout; | |
var oldSI = w.setInterval; | |
var oldCI = w.clearInterval; | |
var timers = []; | |
w.timers = timers; | |
w.setTimeout = function(fn, delay){ | |
var id = oldST(function(){ | |
fn && fn(); | |
removeTimer(id); |
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 getParameters(func) { | |
var funcString = func.toString(); | |
var indexStart = funcString.indexOf('(') + 1; | |
var indexEnd = funcString.indexOf(')'); | |
return funcString | |
.substring(indexStart, indexEnd) | |
.trim() | |
.split(/\s*,\s*/); | |
} |
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 thueMorse(i) { | |
var a = '0', b = '1'; | |
for (; i--;) | |
a += [b, b += a][0]; | |
return a; | |
} | |
thueMorse(0); // 0 | |
thueMorse(1); // 01 | |
thueMorse(4); // 0110100110010110 |
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 int32toIP(nMask) { | |
for (var nFlag = 0, nShifted = nMask, sMask = ''; nFlag < 32; | |
nFlag++, sMask += String(nShifted >>> 31), nShifted <<= 1); | |
return sMask.match(/.{1,8}/g).map(function (x) { return parseInt(x, 2); }).join('.'); | |
} | |
int32toIP(255); // "0.0.0.255" | |
int32toIP(256); // "0.0.1.0" | |
int32toIP(1333333337); // "79.121.13.89" | |
int32toIP(7527203073); // "192.168.1.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
.blink { | |
animation: fade 3000ms infinite; | |
} |