Skip to content

Instantly share code, notes, and snippets.

View fulmicoton's full-sized avatar
🤪

Paul Masurel fulmicoton

🤪
View GitHub Profile
@fulmicoton
fulmicoton / gist:2012239
Created March 10, 2012 17:33
poor man's 3d
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
@fulmicoton
fulmicoton / wordcount.py
Last active December 17, 2015 06:09
Computes the 10 most frequent token from stdin or a couple of files.
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 != "":
@fulmicoton
fulmicoton / Kaggle Yandex parse code
Created December 11, 2013 12:29
Parse function returns a generator of session object. It takes a generator of tuples as an input.
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):
def fibo_dynamic(n):
cur = 0 # F_i
next = 1 # F_i+1
while True:
yield cur
(cur, next) = (next, cur+next)
def fibo_dynamic(n):
cur = 0 # F_i
next = 1 # F_i+1
while True:
yield cur
(cur, next) = (next, cur+next)
template<typename TFloat>
bool _Field::to_float(TFloat* dest) const {
/* */
if (length == 0) {
return false;
}
int offset=0;
int sign = 1;
import csv
from contextlib import contextmanager
import sys
@contextmanager
def getstdin():
try:
yield sys.stdin # process.stdout
print "a"
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'>\
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"):
from collections import defaultdict
class Trie(object):
__slots__ = ('terminal', 'children')
def __init__(self,):
self.terminal = False