Skip to content

Instantly share code, notes, and snippets.

View thinkphp's full-sized avatar
💭
If I have seen further it is only by standing on the shoulders of giants. NEWTON

Adrian Statescu thinkphp

💭
If I have seen further it is only by standing on the shoulders of giants. NEWTON
View GitHub Profile
@thinkphp
thinkphp / gist:1388653
Created November 23, 2011 13:26
$extend(subClass,superClass)
var Human = function(name){
this.name = name;
this.isAlive = true;
this.energy = 1;
};
Human.prototype.eat = function() {
return this.energy++;
};
@thinkphp
thinkphp / gist:1393131
Created November 25, 2011 09:34
Dmitry A. Soshnikov Class
/**
* class.js
* @author Dmitry A. Soshnikov
*/
function Class(params) {
/**
* Constructor function
* If not specified, use default
@thinkphp
thinkphp / gist:1404261
Created November 29, 2011 10:04
currying
function addEvent(elem, evType, fn, useCapture) {
if(elem.addEventListener) {
return elem.addEventListener(evType, fn, useCapture);
} else if(elem.attachEvent){
var r = elem.attachEvent('on'+evType,fn);
return r;
} else {
elem['on'+evType] = fn;
}
}
@thinkphp
thinkphp / gist:1406419
Created November 29, 2011 20:43
inheritance $extend
$extend = function(subClass,superClass) {
function F() {};
F.prototype = superClass.prototype;
subClass.prototype = new F();
subClass.prototype.constructor = subClass;
subClass._base = superClass;
subClass._super = superClass.prototype;
};
@thinkphp
thinkphp / gist:1437638
Created December 6, 2011 10:06
inherit.py
#inherit.py
class SchoolMember:
'''Represents any school member'''
def __init__(self, name, age):
self.name = name
self.age = age
print 'Initialized SchoolMember constructor: %s' % self.name
@thinkphp
thinkphp / gist:1437749
Created December 6, 2011 10:45
merge-demo.py
'''
Merging two arrays or three..or four..or five..or ...n :P
by Adrian Statescu <adrian@thinkphp.ro>
MIT Style License
'''
import merge
l = ([2,4,6,8],[1,3,5,7,9],[11,12,13,14,15,16,17])
i = 1;
ll = l[0]
@thinkphp
thinkphp / gist:1437751
Created December 6, 2011 10:45
merge.py
'''
by Adrian Statescu <adrian@thinkphp.ro>
MIT Style License
'''
def merge(arrA,arrB):
arrC = []
i = 0
j = 0
n = len(arrA)-1
m = len(arrB)-1
@thinkphp
thinkphp / gist:1439637
Created December 6, 2011 19:45
Breadth-First Traversal.php
/**
* Breadth-First Traversal of a Binary Tree in PHP
* by Adrian Statescu <adrian@thinkphp.ro>
* MIT Style License
*/
class Node {
public $info;
public $left;
public $right;
@thinkphp
thinkphp / gist:1439668
Created December 6, 2011 19:53
Breadth-First Traversal.py
'''
Breadth-First Traversal of a Binary Tree in Python
by Adrian Statescu <adrian@thinkphp.ro>
MIT Style License
Given a tree (binary tree), prints all it's elements by level (breadth first traversal)
9
2 4
@thinkphp
thinkphp / gist:1440007
Created December 6, 2011 21:06
Breadth-First Traversal of a Binary Tree.js
/**
* Breadth-First Traversal of a Binary Tree in JS
* by Adrian Statescu <adrian@thinkphp.ro>
* MIT Style License
*/
function Node(info){
this.info = info
this.left = null;