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 *calendar (month, year) { | |
var c = new Date(year, month, 0).getDate(); | |
var l = new Date(year, month - 1, 0).getDate(); | |
var o = new Date(year, month - 1, 1).getDay(); | |
var p = o > 0 ? 1 - o : -6; | |
var m = 42 + p; | |
while (p < m) |
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 readable($size, $unit = array('B', 'KB', 'MB', 'GB', 'TB', 'PB')) { | |
return ($size > 1024) ? readable($size/1024, array_slice($unit, 1)) : round($size, 2) . ' ' . array_shift($unit); | |
} |
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
/* | |
* Input: Base64 encoded string | |
* Output: Raw byte-array | |
*/ | |
function decodeStringToArray(s) { | |
return Array.prototype.map.call(atob(s), function(c) { return c.charCodeAt() }); | |
} | |
/* | |
* Input: Raw byte-array |
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 () { | |
var s, r, t; | |
function replace(parent) { | |
var n, w = document.createTreeWalker(parent, NodeFilter.SHOW_TEXT, null, false), | |
c = ['љ','Љ','њ','Њ','џ','Џ','ч','Ч','ћ','Ћ','ж','Ж','ш','Ш','ђ','Ђ','з','З','е','Е','р','Р','т','Т','у','У','и','И','о','О','п','П','а','А','с','С','д','Д','ф','Ф','г','Г','х','Х','ј','Ј','к','К','л','Л','ц','Ц','в','В','б','Б','н','Н','м','М'], | |
l = ['lj','Lj','nj','Nj','dž','Dž','č','Č','ć','Ć','ž','Ž','š','Š','đ','Đ','z','Z','e','E','r','R','t','T','u','U','i','I','o','O','p','P','a','A','s','S','d','D','f','F','g','G','h','H','j','J','k','K','l','L','c','C','v','V','b','B','n','N','m','M']; | |
while (n = w.nextNode()) | |
c.forEach(function(v, i) { n.nodeValue = n.nodeValue.split(l[i]).join(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 byteLength(l) { | |
return Math.floor(Math.log(l)/Math.log(256))+1; | |
} |
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 berLength(l) { | |
var ll, bl; | |
if (l < 128) { | |
bl = [l]; | |
} else { | |
ll = Math.floor(Math.log(l)/Math.log(256))+1; | |
bl = [128 + ll]; | |
while (ll-- > 0) |
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 TemplateEngine(templ) { | |
if (typeof templ != "undefined") | |
templ = document.getElementById(templ).innerHTML.replace(/\n|\r/g, "").replace(/>\s+</g, "><").trim(); | |
return function compile(data, template) { | |
var match, tpart, i, template = template || templ; | |
while (match = /\{\{#([a-zA-Z]+)\}\}(.+)\{\{\/\1\}\}/g.exec(template)) { | |
for (tpart = '', i = 0; i < data[match[1]].length; i++) | |
tpart += compile(data[match[1]][i], match[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
/** | |
* depth: 1 - monochrome | |
* 4 - 4-bit grayscale | |
* 8 - 8-bit grayscale | |
* 16 - 16-bit colour | |
* 32 - 32-bit colour | |
**/ | |
function drawArray(arr, depth) { | |
var offset, height, data, image; |
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 arrayToString(input) { | |
return decodeURIComponent( | |
input.map(function(v) { | |
return '%'+v.toString(16); | |
}) | |
.join('') | |
); | |
}; | |
function stringToArray(input) { |