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 mkview(tpl, d) { | |
| var ret = tpl, re, k; | |
| for(k in d) { | |
| re = new RegExp("%{"+k+"}", "g"); | |
| ret = ret.replace(re , d[k]); | |
| } | |
| return ret; | |
| } |
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 strgeo($target) { | |
| $str = rawurlencode($target); | |
| $uri = "http://maps.googleapis.com/maps/api/geocode/json?address=${target}&sensor=true"; | |
| $d = json_decode(file_get_contents($uri), 1); | |
| $d = (@$d['results'][0]); | |
| if(!$d) | |
| return NULL; | |
| return [ | |
| 'targetf' => $d['formatted_address'], | |
| 'coords' => $d['geometry']['location'], |
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
| MYSQL_RES * | |
| mysql_exec(const char *sqlstr, ...) { | |
| MYSQL_RES *res; | |
| va_list ap; | |
| char *sql; | |
| int sqlen; | |
| va_start(ap, sqlstr); | |
| sqlen = vasprintf(&sql, sqlstr, ap); | |
| va_end(ap); |
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 deepset(obj, hier, val, _i) { | |
| var k; | |
| if(!_i) | |
| _i = 0; | |
| k = hier[_i]; | |
| if(!hier[_i + 1]) { | |
| if(obj[k] !== undefined) { | |
| if(typeof obj[k] == "string") | |
| obj[k] = [obj[k]]; |
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 eventsmap = []; | |
| function on(elems, evnm, callback) { | |
| var i, len, uuid; | |
| if(elems.length == undefined) | |
| elems = [elems]; | |
| len = elems.length; | |
| if(!len) | |
| return; |
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 extend(dst, src) { | |
| var k; | |
| for(k in src) | |
| dst[k] = src[k]; | |
| } |
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 trigger(elems, evnm, data) { | |
| var ev, i, len; | |
| if(typeof elems == 'object' && elems.length == undefined) | |
| elems = [elems]; | |
| len = elems.length; | |
| if(!len) | |
| return; | |
| ev = new CustomEvent(evnm, {detail:data}); | |
| for(i = 0; i < len; ++i) |
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 append(where, what) { | |
| var i, len, scripts, script, p, att; | |
| where.appendChild(what); | |
| scripts = $("script", what); | |
| len = scripts.length; | |
| for(i = 0; i < len; ++i) { | |
| script = document.createElement("script"); | |
| script.innerHTML = scripts[i].innerHTML; | |
| for(att in scripts[i].atts) |
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 pad(s, len, c, pr) { | |
| var rest; | |
| /* prevent arithmetic issues */ | |
| s = s.toString(); | |
| c = c.toString(); | |
| rest = len - s.length; | |
| if(rest <= 0) | |
| return s; | |
| [...Array(rest)].forEach(() => s=pr ? s+c : c+s); |
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
| int | |
| sleepu(double usec) { | |
| struct timespec req, rem; | |
| int r; | |
| req.tv_sec = 0; | |
| req.tv_nsec = usec * 1000; | |
| while((r = nanosleep(&req, &rem)) == -1 && errno == EINTR) | |
| req = rem; | |
| return r; |