Skip to main content

Posts

Installing pyodbc on ubuntu

Installing pyodbc is straight forward but if  getting     "error: command 'gcc' failed with exit status 1"  when installing pyodbc, make sure you have installed  requirements  as below. sudo apt-get install unixODBC-dev g++ pip install pyodbc

Installing Python Imaging Library(PIL) on ubuntu

Install required packages sudo apt-get install libjpeg8 libjpeg62-dev libfreetype6 libfreetype6-dev python-dev Fixing the lib path sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib sudo ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib sudo ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib Install the PIL pip install pil If getting "ImportError: No module named PIL" on importing Image module also try from PIL import Image If not using virtualenv "$ sudo apt-get install python-imaging" will also install pil for the system.

Javascript Memoization Pattern

It happens sometime that you need to cache some data which has produced by a complex operation. Caching data helps you not to do repeat the complex operation. Caching the results of an operation is also known as Memoization. Followings are too example of this pattern. var setCache = function (param,val) {        setCache.cache[param] =val;        return setCache.cache[param];  }; setCache.cache={}; or you can just save the result of a function inside the  function: var setCache = function (param) {        if (!setCache.cache[param]){           var res;           //do the complex and heavy operation            //here and assign the  result to 'res'           setCache.cache[param] =res;        }        return setCache.cache[param]; }; setCache...

Chaining Pattern

With Chaining Pattern you can call object methods one after the others without assigning the result to other variables or break them in multiple statement or lines. For example: myobj.func1().func2(1,2,3).func3('fsnjk'); This pattern is only useful when object functions do not have to special return so, this pattern can  implemented by returning this in each object function. For example: var myelm={         hide: function(second){                 //code for hiding                  return this;         },         fadeIn: function(second){                 //code for fading                  return this;         } }; myelm.hide(1).fadeIn(2);

Javascript Private Members

Javascript does not have special syntax for private members however they can be implement by using closure in object constructor and using wrap function in object literal. Examples below shows how private members can be implemented. Example 1. Object Constructor function Grocery(){     //private     var type='fruit';          //public     this.getType=function(){         return type;     } } var orange=new Grocery(); alert(orange.type); //undefined alert(orange.getType()); //fruit Example 2. Object  Literal var orange; (function(){     //private     var type="fruit";          //public     orange={         getType:function(){             return type;         }     }; }()); alert(orange.getType...

Effect of dependency declaration in Javascript minified code

In the following example although function foo seems longer, but in minified version it is rather smaller than the boo function.This is because compilers will rename local variables name and declaring the dependency at the beginning of the foo function allows smaller code after minification. function boo() {     alert(App.namespace.f1);     alert(App.namespace.f2);     alert(App.namespace.f3); } /* minified boo alert(App.namespace.f1);alert(App.namespace.f2);alert(App.namespace.f3) */ function foo() {     var namespace = App.namespace;     alert(namespace.f1);     alert(namespace.f2);     alert(namespace.f3); } /* minified foo  var a=App.namespace;alert(a.f1);alert(a.f2);alert(a.f3) */