Monthly Archives: September 2012

arbitrary base conversion

arbitrary base conversion. function getValueOfDigit(digit, alphabet) { var pos = alphabet.indexOf(digit); return pos; } function convert(src, srcAlphabet, dstAlphabet) { var srcBase = srcAlphabet.length; var dstBase = dstAlphabet.length; var wet = src; var val = 0; var mlt = 1; while … Continue reading

Posted in Uncategorized | Leave a comment

Server-Sent Events

Server-Sent Events var source =newEventSource(‘/stats’); source.onopen =function(){   connectionOpen(true); }; source.onerror =function(){   connectionOpen(false); }; source.addEventListener(‘connections’, updateConnections,false); source.addEventListener(‘requests’, updateRequests,false); source.addEventListener(‘uptime’, updateUptime,false); source.onmessage =function(event){   // a message without a type was fired };    

Posted in Uncategorized | Leave a comment

Introducing Web SQL Databases

Introducing Web SQL Databases var db = openDatabase(‘mydb’,’1.0′,’my first database’,2*1024*1024);   var db = openDatabase(‘mydb’,’1.0′,’my first database’,2*1024*1024); db.transaction(function(tx){   // here be the transaction   // do SQL magic here using the tx object });   var db = openDatabase(‘mydb’,’1.0′,’my … Continue reading

Posted in Uncategorized | Leave a comment

Drag and Drop and Automatically Send to the Server

Drag and Drop and Automatically Send to the Server var formData =newFormData();for(var i =0; i < files.length; i++){   formData.append(‘file’, files[i]);}// now post a new XHR requestvar xhr =newXMLHttpRequest(); xhr.open(‘POST’,’/upload’); xhr.onload =function(){   if(xhr.status ===200){     console.log(‘all done: ‘+ … Continue reading

Posted in Uncategorized | Leave a comment

Storing Data the Simple HTML5 Way

Storing Data the Simple HTML5 Way Get Storing The API for localStorage and sessionStorage is exactly the same, and distills down to the following methods: .setItem(key, value); .getItem(key) .removeItem(key) .clear() .key(index) .length http://php-html.net/tutorials/html5-local-storage-guide/ localStorage.name =’Remy’; localStorage.doctors = JSON.stringify(doctors); var html5docs = JSON.parse(localStorage.doctors); alert(‘There be … Continue reading

Posted in Uncategorized | Leave a comment

Optimize Images With HTML5 Canvas

Optimize Images With HTML5 Canvas 01 function addNoise(canvas) { 02    var ctx = canvas.getContext(‘2d’); 03   04    // Get canvas pixels 05    var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height); 06    var pixels = imageData.data; 07   08    for (var i = 0, il = pixels.length; i … Continue reading

Posted in Uncategorized | Leave a comment

JavaScript sprintf

JavaScript sprintf  string sprintf(string format , [mixed arg1 [, mixed arg2 [ ,…]]]); A type specifier that can be any of: % — print a literal “%” character b — print an integer as a binary number c — print an integer as … Continue reading

Posted in Uncategorized | Leave a comment