This file contains 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 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 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 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 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 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 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 |
This file contains 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 | |
import heapq | |
ENGLISH = defaultdict(list) | |
for w in open("/usr/share/dict/american-english"): | |
w_stripped = w.strip() | |
ENGLISH[tuple(sorted(w_stripped))].append(w_stripped) | |
print heapq.nlargest(1, ENGLISH.itervalues(), key=len)[0] |
This file contains 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 | |
import heapq | |
ENGLISH = defaultdict(list) | |
for w in open("/usr/share/dict/american-english"): | |
w_stripped = w.strip() | |
ENGLISH[tuple(sorted(w_stripped))].append(w_stripped) | |
print heapq.nlargest(1, ENGLISH.itervalues(), key=len)[0] |
This file contains 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 numpy as np | |
import cProfile | |
def bits_to_int(bits,): | |
n = 0 | |
for b in bits[::-1]: | |
n *= 2 | |
n += b | |
return n |
OlderNewer