Friday, January 31, 2014

Javascript IDEs

http://www.jetbrains.com/webstorm/
http://www.aptana.com/
https://netbeans.org/
http://www.visualstudio.com/
http://www.sublimetext.com/
http://macromates.com/

Wednesday, January 29, 2014

Switch to Box from Dropbox

Couple of reasons:
1. Box sync works grea
2. Box has free 50GB storage
3. Box has new state-of-the-art preview UI
4. Box new iOS app is just awesome

Dropbox looks lightweight and ease of use, but after using Box for a while, it also meets my basic daily use requirements. I can share, collaborate files with my friends and family from anywhere and any device.

Two boxes, similar features, but one choice for me.

Wednesday, January 8, 2014

ES5 compatibility table

http://kangax.github.io/es5-compat-table/

We should start to use strict mode, Object, Array, and getter/setter etc new features with browser native support.

Strict mode

Object.create
Object.defineProperty
Object.defineProperties
Object.getPrototypeOf
Object.keys
Object.seal
Object.freeze
Object.preventExtensions
Object.isSealed
Object.isFrozen
Object.isExtensible
Object.getOwnPropertyDescriptor
Object.getOwnPropertyNames

Array.isArray
Array.prototype.indexOf
Array.prototype.lastIndexOf
Array.prototype.every
Array.prototype.some
Array.prototype.forEach
Array.prototype.map
Array.prototype.filter
Array.prototype.reduce
Array.prototype.reduceRight        

Getter in property initializer
Setter in property initializer

Date.prototype.toISOString
Date.now
JSON
Function.prototype.bind
String.prototype.trim       

Tuesday, January 7, 2014

Javascript code snippet

Here are some code snippets from
http://flippinawesome.org/2013/12/23/45-useful-javascript-tips-tricks-and-best-practices/


String.prototype.trim = function(){return this.replace(/^\s+|\s+$/g, "");};
Array.prototype.slice.call(arguments);
Object.prototype.toString.call(obj) === '[object Array]' ;
myArray.length = 0;

for (var name in object) { 
    if (object.hasOwnProperty(name)) {
        // do something with name                   
    } 
}

function escapeHTML(text) { 
    var replacements= {"<": "&lt;", ">": "&gt;","&": "&amp;", "\"": "&quot;"};                     
    return text.replace(/[<>&"]/g, function(character) { 
        return replacements[character]; 
    });
}

var xhr = new XMLHttpRequest ();
xhr.onreadystatechange = function () { 
    if (this.readyState == 4) { 
        clearTimeout(timeout); 
        // do something with response data
    } 

var timeout = setTimeout( function () { 
    xhr.abort(); // call error callback 
}, 60*1000 /* timeout after a minute */ );
xhr.open('GET', url, true); 

xhr.send();


var timerID = 0;
function keepAlive() {
    var timeout = 15000; 
    if (webSocket.readyState == webSocket.OPEN) { 
        webSocket.send(''); 
    } 
    timerId = setTimeout(keepAlive, timeout); 

function cancelKeepAlive() { 
    if (timerId) { 
        cancelTimeout(timerId); 
    } 
}