What is decorator ? Decorator is function which takes function as argument and return the function which is invoked in place on original function. Using decorator we can do some tasks before invoking the actual function. Syntax # decorator function, automatically get called before # actual function is invoked # whatever returned from decorator is… Continue reading Function decorators in Python
JavaScript Array sorting
Array is built-in object in JavaScript. There are many methods in Array object. One of the important method is sort method. This is used to sort the array as name implies. We will see some interesting examples on sorting the array – Simple sort var numbers = [4,3,4,2,5,6,3]; var sorted = numbers.sort(); // ascending order… Continue reading JavaScript Array sorting
JavaScript variable scope
Scope is the region of the code where we can access variable. When variable is no longer accessible in part of code we say variable is out of scope. In JavaScript there are three type of scopes. Local scope Global scope Automatic global scope Local Scope All variables declared using var keyword inside a function… Continue reading JavaScript variable scope
JavaScript call, apply and bind
All three functions are used to change the context of function. There is lot of confusion about these three functions. So I will try to explain the difference between these with simple example. Call Call is used to call the function with context (this) and arguments. function sayHello(a,b) { console.log(“argument a = ” + a);… Continue reading JavaScript call, apply and bind
JavaScript Closure
What is closure ? Closure is inner function enclosed within another function. It has access to the variables of enclosing scope and global scope. Closure has three scope chain – Global scope Enclosing scope Local scope Lets see some examples to understand this – // global scope var a = 5; function enclosing_func(b, c) { //… Continue reading JavaScript Closure
Operator Overloading in Python
What is operator overloading ? When operator behave differently depending on the arguments passed to it, it is called operator overloading. This is special case of polymorphism. If we apply + operator to 2 strings they are concatinated, if we apply it to numbers they are added and if we do it with lists, second… Continue reading Operator Overloading in Python
Configure Django with postgres
Django comes preconfigured with SQLite db. This is goood for playing with django features or doing some lightweight apps. For big applications we have to use the mysql or postgreSQL db. This article will give a step by step procedure to install and configure postgreSQL with django framework. Step 1 – Create python virtualenv for our… Continue reading Configure Django with postgres