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
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
(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
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 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
function convertStringToInput(str){ | |
var result = []; | |
for (var i = 0, l = str.length; i < l; i++) { | |
var charCode = str.charCodeAt(i); | |
result.push(charCode > 255 ? '+' + charCode.toString(16) : charCode); | |
} | |
return result.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
/** | |
* Converts a BGR base10 color to an RGB Hex value. | |
* | |
* @method colorToHexString | |
* @param {Integer} dColor A color as integer. | |
* @returns {String} The RGB hex code as string. | |
*/ | |
function colorToHexString(dColor) { | |
return '#' + ("000000" + (((dColor & 0xFF) << 16) + (dColor & 0xFF00) + ((dColor >> 16) & 0xFF)).toString(16)).slice(-6); | |
} |
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 Promise(o, fnNames){ | |
fnNames = fnNames || ['done', 'fail', 'always']; | |
var done = fnNames[0], | |
fail = fnNames[1], | |
always = fnNames[2]; | |
o.states = { none: 0 }; | |
o.states[done] = 1; | |
o.states[fail] = 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
0 = Black | |
8 = Gray | |
1 = Blue | |
9 = Light Blue | |
2 = Green | |
A = Light Green | |
3 = Aqua | |
B = Light Aqua | |
4 = Red | |
C = Light Red |