Category Archives: Code Snippets

ipAddrInt, ipAddrStr in VBscript / VBA / VB6

Function ipAddrInt(ip) Dim a, tmp a = Split(ip, “.”, 4) tmp = a(0) * 16777216# + a(1) * 65536 + a(2) * 256 + a(3) * 1 ipAddrInt = tmp End Function Function ipAddrStr(i) Dim s, tmp s = Right(String(8, … Continue reading

Posted in Uncategorized, VBasic | Tagged , , | Leave a comment

JSZip: JavaScript zip class

JSZip: JavaScript zip class. var zip = new JSZip(); zip.file(“file.txt”, “content”); zip.file(“file.txt”).name // “file.txt” zip.file(“file.txt”).data // “content” zip.file(“file.txt”).options.dir // false // utf8 example var zip = new JSZip(zipFromAjaxWithUTF8); zip.file(“amount.txt”).data // “€15” zip.file(“amount.txt”).asText() // “€15” Download See also: the test suite

Posted in Code Snippets | Leave a comment

JavaScript implementation of Gzip

 JavaScript implementation of Gzip jsolait library // LZW-compress a string function lzw_encode(s){     var dict ={};     var data =(s +””).split(“”);     varout=[];     var currChar;     var phrase = data[0];     var code … Continue reading

Posted in Code Snippets | Leave a comment

Run-length encoding in different languages

Run-length encoding JavaScript Here’s an encoding method that walks the input string character by character function encode(input) { var encoding = []; var prev, count, i; for (count = 1, prev = input[0], i = 1; i < input.length; i++) … Continue reading

Posted in Code Snippets | Leave a comment

Javascript LZW implementation (Lempel ZivWelch)

Javascript LZW. LZW The LZW compression/decompression algorithm patent expired in 2004 and it is relatively easy to implement in Javascript. This is partly due to the fact that you get free hash table implementations in Javascript and string handling is … Continue reading

Posted in Code Snippets | Leave a comment

RLE implementation in Javascript (run length encoding)

Javascript RLE. RLE Run length encoding is simple to implement, and efficient to decompress. It particularly suits encoding Chuckie Egg levels because they are comprised of large spans of identical cells such as walls and empty areas. The encoding algorithm … Continue reading

Posted in Code Snippets | Leave a comment

javascript base62 encode – decode

function base62_encode() function(a,b,c){for(a=a!==+a||a%1?-1:a,b=””;a>=0;a=Math.floor(a/62)||-1)b=String.fromCharCode(((c=a%62)>9?c>35?29:87:48)+c)+b;return b} function base62_decode() function(a,b,c,d){for(b=c=(a===(a+=””)&&/^[a-z\d]+$/i.test(a))-1;d=a.charCodeAt(c++);)b=b*62+d-[,48,29,87][d>>5];return b} 140byt.es. function ( a, // positive base10 encoded integer b, // placeholder for result c // placeholder for modulo ) { for ( a = a !== +a || a % 1 … Continue reading

Posted in Code Snippets | Tagged , | Leave a comment