This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@memo | |
def fib(i): | |
if i < 2: | |
return 1 | |
return fib(i-1) + fib(i-2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'); | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from datetime import timedelta | |
from datetime import date | |
class Holiday(object): | |
_message = "Hello" | |
def get_start_date(self): | |
raise NotImplementedError |
OlderNewer