Skip to content

Instantly share code, notes, and snippets.

View horiajurcut's full-sized avatar

Horia Jurcut horiajurcut

View GitHub Profile
var Person = function(hobbies) { this.hobbies = hobbies || []; }
Person.prototype.worthy = function() {
for (var i = 0; i < this.hobbies.length; i++)
if (this.hobbies[i] === 'programming') return true;
};
Person.prototype.visit = function() {
this.worthy() && alert('Open Doors @ [e-spres-oh]');
};
(new Person(['coffee', 'music', 'programming'])).visit();
def insertion_sort(a = []):
length = len(a)
j = 1
while j < length:
key = a[j]
i = j - 1
while i >= 0 and a[i] > key:
a[i + 1] = a[i]
i = i - 1
a[i + 1] = key
X = [9, 3, 1, 10, 3, 2, 8, 6, 4, 5, 0]
def merge(L, R):
A = []
i, j = 0, 0
while i < len(L) and j < len(R):
if L[i] < R[j]:
A.append(L[i])
i = i + 1
from functools import wraps
from collections import defaultdict
def memo(func):
cache = {}
@wraps(func)
def wrap(*args):
if args not in cache:
cache[args] = func(*args)
@memo
def fib(i):
if i < 2:
return 1
return fib(i-1) + fib(i-2)
def merge_sort(seq):
mid = len(seq) // 2
left, right = seq[:mid], seq[mid:]
if len(left) > 1:
left = merge_sort(left)
if len(right) > 1:
right = merge_sort(right)
// Extending jQuery.when
if (jQuery.when.all === undefined) {
jQuery.when.all = function(deferreds) {
var deferred = new jQuery.Deferred();
$.when.apply(jQuery, deferreds).then(
function() {
deferred.resolve(Array.prototype.slice.call(arguments));
},
function() {
var cityDetails = $.ajax({
type: 'GET',
url: '/path/to/resource',
beforeSend: function() {
console.log('Before sending the Request');
},
success: function(result) {
console.log(result);
console.log('Response received.');
},
var loadingMessages: [
'Caffeinating our Development team!',
'Locating the required gigapixels to render...',
'Shovelling coal into the server...',
'Please wait... the architects are still drafting!',
'Warming up Large Hadron Collider...',
'Yes there really are magic elves with an abacus working frantically in here.',
'Elf down! We are cloning the elf that was supposed to get you the data. Please wait.',
'1,000,000 bottles of beer on the wall...',
'Have you lost weight?',
from datetime import datetime
from datetime import timedelta
from datetime import date
class Holiday(object):
_message = "Hello"
def get_start_date(self):
raise NotImplementedError