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
W = 490 | |
H = 315 | |
load_image_into_canvas = (path, ctx, callback=((ctx)->))-> | |
img = new Image() | |
img.onload = -> | |
ctx.drawImage img,0,0,W,H | |
callback ctx | |
img.src = path | |
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
import re | |
import fileinput | |
from collections import Counter | |
token_ptn = re.compile("[^\w]+") | |
word_count = Counter() | |
for line in fileinput.input(): | |
for token in token_ptn.split(line): | |
if token != "": |
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
import itertools | |
from collections import defaultdict, OrderedDict | |
from math import log | |
def dcg(scores): | |
return sum( (2**score - 1) / log(i+2) for (i, score) in enumerate(scores) ) | |
class Session(object): |
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 fibo_dynamic(n): | |
cur = 0 # F_i | |
next = 1 # F_i+1 | |
while True: | |
yield cur | |
(cur, next) = (next, cur+next) |
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 fibo_dynamic(n): | |
cur = 0 # F_i | |
next = 1 # F_i+1 | |
while True: | |
yield cur | |
(cur, next) = (next, cur+next) |
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
template<typename TFloat> | |
bool _Field::to_float(TFloat* dest) const { | |
/* */ | |
if (length == 0) { | |
return false; | |
} | |
int offset=0; | |
int sign = 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
import csv | |
from contextlib import contextmanager | |
import sys | |
@contextmanager | |
def getstdin(): | |
try: | |
yield sys.stdin # process.stdout | |
print "a" |
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
app.directive('bzColorPicker', function() { | |
var evtFakeDom = $("<div>"); | |
return { | |
restrict: 'E', | |
template: "<div class='bz-color-picker' ng-click='toggle($event)'>\ | |
<div class='iris' style='background-color: {{ color }}'></div>\ | |
<i class='icon-caret-down'></i>\ | |
<div class='bz-color-picker-palette'>\ | |
<input type='radio' class='color' ng-model='color' value='#f06548' style='background-color: #f06548'>\ | |
<input type='radio' class='color' ng-model='color' value='#fdc766' style='background-color: #fdc766'>\ |
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 find_permutations_range(w): | |
if len(w) == 0: | |
yield "" | |
else: | |
for rank in range(len(w)): | |
w_without_rank = [l for (i, l) in enumerate(w) if i != rank] | |
for perm in find_permutations_range(w_without_rank): | |
yield w[rank] + perm | |
for w in find_permutations_range("jambon"): |
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 collections import defaultdict | |
class Trie(object): | |
__slots__ = ('terminal', 'children') | |
def __init__(self,): | |
self.terminal = False |
OlderNewer