This file contains hidden or 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
// get real XMLHttpRequest object | |
var RealXMLHttpRequest = window.XMLHttpRequest; | |
// create the overloaded XMLHttpObject | |
window.XMLHttpRequest = function(){ | |
// just in case someone is still using IE6, use a fallback | |
var ajax = !!RealXMLHttpRequest ? new RealXMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"), | |
realOpen = ajax.open; | |
// steal the 'open' function, since the request has o be open |
This file contains hidden or 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
.clearfix:after { | |
content: ""; | |
display: table; | |
clear: both; | |
} |
This file contains hidden or 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 gulp = require('gulp'); | |
// a regular async function | |
function async(done) { | |
console.log('async start'); | |
// take your time doing anything you want | |
setTimeout(function () { | |
console.log('async end'); | |
done(); |
This file contains hidden or 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
// the purpose of this is not to match any ID standard, but to allow for a | |
// reasonably and reliably unique ID when generating on a distributed system | |
function getId() { | |
return btoa( | |
(Math.random().toString(36).slice(-4)) + '_' + | |
(new Date()).toISOString() + '_' + | |
(Math.random().toString(36).slice(-6)) | |
); | |
} |
This file contains hidden or 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 parallelSync(funcs, done) { | |
if (typeof workers === 'function') { | |
done = workers; | |
workers = 1; | |
} | |
var counter = funcs.length; | |
var idx = 0; | |
var queue = [].concat(funcs); | |
var results = []; |
This file contains hidden or 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
// standardize a Promise with Continuation Passing Style | |
function PromiseCPS (promise) { | |
return function cpsFunc(done) { | |
promise.then( | |
function promiseSuccess() { | |
done.apply(undefined, [undefined].concat([].slice.call(arguments))); | |
}, function promiseFailure(reason) { | |
done(reason); | |
} | |
); |
This file contains hidden or 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 inherit(proto) { | |
function F() {}; | |
F.prototype = proto; | |
return new F; | |
// Note: use `Object.create` instead of `inherit` if you do not need to support old browsers | |
} | |
// create any "class" | |
function A() { |
This file contains hidden or 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 start = process.hrtime(); | |
// do work here | |
var diff = process.hrtime(start); | |
var nano = diff[0] * 1e9 + diff[1]; | |
console.log('benchmark took %d nanoseconds', nano); | |
console.log('benchmark took %d milliseconds', nano * 1e-6); |
This file contains hidden or 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
// http://jsfromhell.com/array/shuffle | |
function shuffle(v){ | |
for(var j, x, i = v.length; i; j = parseInt(Math.random() * i), x = v[--i], v[i] = v[j], v[j] = x); | |
return v; | |
}; |
This file contains hidden or 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 devLintReporter = function(issues, config, opts) { | |
if (!issues.length) { return; } | |
opts = opts || {}; | |
var chalk = gutil.colors; | |
var files = {}; | |
console.log(chalk.yellow('----------------------')); | |
console.log(chalk.yellow('JSHint Report:')); |