Skip to content

Instantly share code, notes, and snippets.

View anoopelias's full-sized avatar

Anoop Elias anoopelias

View GitHub Profile
@anoopelias
anoopelias / Closure.markdown
Created December 10, 2012 16:03
Closure..

Closure..

Couple of months back, when I started looking at Scala as a programming language, a key computer programming concept came up - Closure. I couldn't find a page which explains what it is and how to use it, so here it goes,

Definition

A closure is a first-class function with free variables that are bound in the lexical environment. (Source wikipedia)

First-class functions

First-class functions are those that can be assigned to a variable to be carried around and be executed at a later point of time. Subsequently this will enable those functions being passed as arguments, as well as returned back. An example in Scala is shown below.

@anoopelias
anoopelias / MemoryLeakTest.java
Created September 3, 2012 21:16
Test memory leak in java code
import java.util.WeakHashMap;
import junit.framework.Assert;
import org.junit.Test;
public class MemoryLeakTest {
@Test
public void test_stack_memory_leak() {
@anoopelias
anoopelias / Inheritance.js
Created August 11, 2012 13:40
A snippet to show the idea of prototype object and inheritance in JavaScript
ObjMaker = function() {
this.a = "first";
};
ObjMaker.prototype.b = "second";
var objMaker = new ObjMaker();
ObjMaker.prototype.c = "third";
console.log("objMaker.a " + objMaker.a); // Prints 'first'
console.log("objMaker.b " + objMaker.b); // Prints 'second'