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
//Thanks to perfectionkills.com <http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/> | |
__getClass = function(val) { | |
return Object.prototype.toString.call(val) | |
.match(/^\[object\s(.*)\]$/)[1]; | |
}; | |
var whatis = function(val) { | |
if(val === undefined) | |
return 'undefined'; |
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 def = function(functions, parent) { | |
return function() { | |
var types = []; | |
var args = []; | |
eachArg(arguments, function(i, elem) { | |
args.push(elem); | |
types.push(whatis(elem)); | |
}); | |
if(functions.hasOwnProperty(types.join())) { | |
return functions[types.join()].apply(parent, 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
var namespace = function(str, root) { | |
var chunks = str.split('.'); | |
if(!root) | |
root = window; | |
var current = root; | |
for(var i = 0; i < chunks.length; i++) { | |
if (!current.hasOwnProperty(chunks[i])) | |
current[chunks[i]] = {}; | |
current = current[chunks[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
<?php | |
function request($url) { | |
$c = curl_init(); | |
curl_setopt($c, CURLOPT_URL, $url); | |
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 3); | |
curl_setopt($c, CURLOPT_TIMEOUT, 5); | |
curl_setopt($c, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); | |
$response = curl_exec($c); |
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
<?php | |
function request($url) { | |
$c = curl_init(); | |
curl_setopt($c, CURLOPT_URL, $url); | |
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 3); | |
curl_setopt($c, CURLOPT_TIMEOUT, 5); | |
curl_setopt($c, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); | |
$response = curl_exec($c); |
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 fancyDate(then, now, suffix) { | |
if(now === undefined) | |
now = new Date(); | |
if(suffix === undefined) | |
suffix = 'ago'; | |
var thenMs = null; | |
typeof then === 'number' ? thenMs = then : thenMs = then.getTime(); | |
var nowMs = null; |
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
#Complete dictionary merge | |
def update(d1, d2): | |
for k,v in d2.items(): | |
if k in d1 and type(d1[k]) is dict and type(v) is dict: | |
update(d1[k], v) | |
else: | |
d1[k] = v | |
return d1 | |
#Deep merges two dictionaries to a given level, after that level it only overwrites the values |
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
//SORT WITH STRINGIFICATION | |
var orderedStringify = function(o, fn) { | |
var props = []; | |
var res = '{'; | |
for(var i in o) { | |
props.push(i); | |
} | |
props = props.sort(fn); | |
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
//SORT WITH STRINGIFICATION | |
sortProperties = function(o, fn) { | |
var res = {}; | |
var props = keys(o); | |
props = fn ? props.sort(fn): props.sort(); | |
for(var i = 0; i < props.length; i++) { | |
res[props[i]] = o[props[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
Array.prototype.chain = function() { | |
var res = undefined; | |
var args = []; | |
var i = 0; | |
while (arguments.hasOwnProperty(i)) { | |
args.push(arguments[i]); | |
i++; | |
} | |
OlderNewer