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 freebase($query, $lang = 'it,en', $limit = 5) { | |
$isid = (strpos($query, '/m/') !== false); | |
if($isid) | |
$limit = 1; | |
$q = array( | |
'key' => 'PUT_YOUR_KEY_HERE', | |
'query' => $query, | |
'output' => '(name description notable)', | |
'lang' => $lang, | |
'limit' => $limit |
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 route($method, $route, $func = null) { | |
static $routes = array(); | |
if(!$func) { | |
$r = null; | |
$n = ''; | |
$argv = array(); | |
foreach(explode('/', $route) as $arg) { | |
$n .= ($n == '/' ? $arg : "/$arg"); | |
if($r) | |
$argv[] = $arg; |
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
global $HT_DEFAULT_FMTS; | |
$HT_DEFAULT_FMTS = array( | |
'year_0' => "An year ago", | |
'years_0' => "%d years ago", | |
'year_1' => "An year from now", | |
'years_1' => "%d years from now", | |
'month_0' => "A month ago", | |
'months_0' => "%d months ago", | |
'month_1' => "A month from now", | |
'months_1' => "%d months from now", |
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
dt() { | |
[ -z "$1" ] && n="dvtm-$RANDOM" || n=$1 | |
f="/tmp/abduco.$n" | |
if [ -e "$f" ]; then | |
abduco -a "$f" | |
else | |
abduco -c "$f" dvtm | |
fi | |
} |
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 prepare_form() { | |
$key = key($_FILES); | |
if(!$key) | |
return; | |
$files = @$_FILES[$key]; | |
if(@$_POST[$key]) { | |
$files = array_merge($files, $_POST[$key]); | |
unset($_POST[$key]); | |
} | |
$ret = []; |
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 buildhier($items, $pk = 'parent_id', $ck = 'id', $subk = 'children') { | |
$map = array(); | |
foreach($items as $k => &$item) { | |
$c = $item[$ck]; | |
$map[$c] = &$item; | |
} | |
unset($item); | |
foreach($items as $item) { | |
$p = $item[$pk]; | |
if(!$p) |
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 trackxhr() { | |
var xhrsend = XMLHttpRequest.prototype.send; | |
XMLHttpRequest.prototype.send = function() { | |
var onready = this.onreadystatechange; | |
console.log('XHR', 'sending...'); | |
this.onreadystatechange = function() { | |
if(this.readyState == 4) | |
console.log('XHR', 'done'); | |
if(onready) | |
onready.apply(this, arguments); |
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 collects(elems) { | |
var i, len, v, keys = null, ret = {}; | |
len = elems ? elems.length : 0; | |
for(i = 0; i < len; ++i) { | |
if(!elems[i].name) | |
continue; | |
keys = elems[i].name.replace(/\[([^\]]*)\]/g, ",$1").split(','); | |
v = (elems[i].type == "checkbox" ? (elems[i].checked ? elems[i].value : "") : elems[i].value); | |
deepset(ret, keys, v); |
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 serialize(obj, _name) { | |
var i, pfx, tp, str = []; | |
if(!obj) | |
return _name; | |
tp = typeof obj; | |
if(obj.length && tp != 'object' && tp != 'string') { /* pure arrays */ | |
for(i = 0; i < obj.length; ++i) { | |
pfx = (_name ? _name+'['+i+']' : i); | |
str.push(pfx+'='+obj[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 xhr(method, hdrs, action, data, callback) { | |
var r = new XMLHttpRequest(); | |
r.onreadystatechange = function() { | |
if(r.readyState == 4 && r.status == 200) | |
callback(JSON.parse(r.responseText)); /* always expect JSON */ | |
}; | |
switch(method.toUpperCase()) { | |
case "POST": |
OlderNewer