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
_.mixin({ | |
cacheFor: function(wait, fn) { | |
return _.throttle(fn, wait, { trailing: 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 isUsingImperialSystem(countryCode) { | |
return /US|PR|JM|BS|GU|BZ|VI|KY|PW/.test(countryCode); | |
} |
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
/* | |
Kilo.js | |
#toSize: 2048 => "2 KB" | |
#toBytes: "2 KB" => 2048 | |
*/ | |
var Kilo = (function() { | |
"use strict"; | |
var kilo = 1024; | |
var sizes = { "B": 0, "KB": 1, "MB": 2, "GB": 3, "TB": 4 }; | |
var sizesNames = Object.keys(sizes); |
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 generateOfficeWebAppURL(url) { | |
return "http://view.officeapps.live.com/op/view.aspx?src=" + encodeURIComponent(url); | |
} |
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
// https://github.com/jquery/jquery/blob/master/src/core/init.js#L14 | |
var isHTMLString = (function() { | |
var rHTML = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/; | |
return function(str) { | |
return rHTML.test(str); | |
}; | |
}()); |
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 geolocate = function(callback) { | |
callback = typeof callback === "function" ? callback : function(){}; | |
if ('Geo' in window) { | |
callback(window.Geo); | |
} else { | |
var script = document.createElement('script'); | |
script.src = "https://geoiplookup.wikimedia.org/"; | |
script.onload = function() { callback(window.Geo) }; | |
document.head.appendChild(script); | |
} |
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
_.mixin({ | |
whenOnline: function(fn, context) { | |
return function() { | |
var args = arguments; | |
context = context || this; | |
if (navigator.onLine) { | |
fn.apply(context, args); | |
} else { | |
window.addEventListener('online', function online() { | |
fn.apply(context, args); |
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
// https://github.com/felixge/node-mysql/blob/master/lib/protocol/SqlString.js | |
function escapeSqlString(text) { | |
return text.replace(/[\0\n\r\b\t\\\'\"\x1a]/g, function(s) { | |
switch(s) { | |
case "\0" : return "\\0"; | |
case "\n" : return "\\n"; | |
case "\r" : return "\\r"; | |
case "\b" : return "\\b"; | |
case "\t" : return "\\t"; | |
case "\x1a": return "\\Z"; |
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 isValidUrl = (function() { | |
var protocols = ["http", "https", "ftp"]; | |
var requireProtocol = false; | |
var requireTLD = true; | |
var pattern = new RegExp('^(?!mailto:)(?:(?:' + protocols.join('|') + ')://)' + (requireProtocol ? '' : '?') + '(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))' + (requireTLD ? '' : '?') + ')|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$', 'i'); | |
return function(str) { | |
return (typeof str === "string") && str.length < 2083 && pattern.test(str); | |
} | |
}()); |
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
location.search.substr(1).split("&").reduce(function(o, pair) { | |
pair = pair.split("="); | |
o[pair[0]] = pair[1] && decodeURIComponent(pair[1]); | |
return o; | |
}, {}); |
OlderNewer