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 later = Function.bind.bind(window.setTimeout, window); | |
// Usage | |
element.addEventListener('click', later(foo, 1000)); | |
// On click, `foo` will be executed after 1 second with the usual event parameters passed along |
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
// Script# Core Runtime | |
// More information at http://projects.nikhilk.net/ScriptSharp | |
// | |
window.isUndefined=function(o){return(o===undefined);}; | |
window.isNull=function(o){return(o===null);}; | |
window.isNullOrUndefined=function(o){return(o===null)||(o===undefined);}; | |
window.__scriptsharp='0.5.5.0'; | |
document.getElementsBySelector=function(cssSelector,root){ | |
var all=root?root.getElementsByTagName('*'):document.getElementsByTagName('*'); | |
var matches=[]; |
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; | |
var call = Function.prototype.call; | |
var toArray = function () { return call.apply(slice, arguments); } | |
// Usage: | |
toArray(arguments); //=> make an array from all arguments | |
toArray(arguments, 1, 3); //=> make an array from arguments[1] to arguments[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
var not = function(fn){ return function(){ return !fn.apply(this, arguments); }; }; | |
var nullOrUndefined = function(e){ return this[e] == null; }; | |
var notNullOrUndefined = not(nullOrUndefined); | |
var existsIn = function(e){ return this.indexOf(e) != -1; }; | |
var doesntExistIn = not(existsIn); | |
var merge = function(dest, source){ | |
var validKeys = Object.keys(source).filter(notNullOrUndefined, source); |
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 hugeNum = Math.pow(2, 51); | |
function generateArguments(numberOfArgs) { | |
var letters = []; | |
while(numberOfArgs--) letters.push("arg_" + Math.ceil(Math.random() * hugeNum)); | |
return letters; | |
} | |
Function.prototype.partial = function partial() { | |
var fn = this; |
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
redact.js>node redact.js US forces are moving into turkey on a crazy whim to find terrorist twitter users | |
US ██████ are ██████ into ██████ on a █████ whim to ██████████████ twitter users |
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 isMobile = { | |
tests:[ | |
function() { | |
return navigator.userAgent.match(/Android/i); | |
}, | |
function() { | |
return navigator.userAgent.match(/BlackBerry/i); | |
}, | |
function() { | |
return navigator.userAgent.match(/iPhone|iPad|iPod/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
AJAXRequest: function(url, action){ | |
/* ---------------------- | |
Small AJAX Library | |
------------------------- */ | |
xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function(){ | |
// check if the request is ready and the status is ok | |
if (xhr.readyState === 4 && xhr.status === 200){ |
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 slots = [], num = 1000; for(var i = 0; i < num; i++) setTimeout(function(s, d, done){ slots[s] = Date.now() - d; done(); }, 1000, i, Date.now(), function(){ if(!--num) { console.log("Mean:", slots.reduce(function(p, c, i) { var d = c - p; return p + d / 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(global){ | |
var exeQueue = []; | |
exeQueue.insertOrdered = function(val) { | |
var l = this.length, | |
order = val.order; | |
while(l--) { | |
if(this[l].order > order) break; | |
} |