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

adler32 checksum in javascript

function(a,b,c,d,e,f){for(b=65521,c=1,d=e=0;f=a.charCodeAt(e++);d=(d+c)%b)c=(c+f)%b;return(d< example: <!DOCTYPE html> <title>Foo</title> <div>Expected value: <b>1802963080</b></div> <div>Actual value: <b id=“ret”></b></div> <script>   var adler32 = function(a,b,c,d,e,f){for(b=65521,c=1,d=e=0;f=a.charCodeAt(e++);d=(d+c)%b)c=(c+f)%b;return(d<<16)|c}   document.getElementById( “ret” ).innerHTML = adler32(“140byt.es is totally rad!”) </script> {   “name”: “adler32”,   “description”: “a javascript port of wikipedia’s example C implementation of Adler32”, … Continue reading

Posted in Code Snippets | Tagged , | Leave a comment

jquery.facedetection

jaysalvat/jquery.facedetection. A jQuery plugin which detects faces in pictures and returns theirs coords. This plugin uses an algorithm by Liu Liu. Demo here: http://facedetection.jaysalvat.com/ Html & Scripts Includes <script src=”http://code.jquery.com/jquery-1.4.3.min.js”></script&gt; <script src=”js/facedetection/ccv.js”></script> <script src=”js/facedetection/face.js”></script> <script src=”js/jquery.facedetection.js”></script> Image <img id=”myPicture” src=”img/face.jpg”> … Continue reading

Posted in Code Snippets | Leave a comment

jQuery Face Detection

jQuery Face Detection Demo.

Posted in Code Snippets | Leave a comment