Skip to content

Instantly share code, notes, and snippets.

View lutzky's full-sized avatar

Ohad Lutzky lutzky

View GitHub Profile
@lutzky
lutzky / gist:10907342
Last active August 29, 2015 13:59
Unit test for add-one Laplace smoothing
def test_p_word(self):
e = Evaluator()
# Add negative reviews
e.add_review(False, {"horrible", "crappy", "boring"})
e.add_review(False, {"awfully", "mediocre"})
e.add_review(False, {"terrible", "boring"})
# Add positive reviews
e.add_review(True, {"wonderful", "delightful", "awesome"})
class Container < Struct.new :val
def inspect
return "&<#{val.inspect}>"
end
end
irb(main):010:0> a = Container.new(5)
=> &<5>
irb(main):011:0> s = [a,a]
=> [&<5>, &<5>]
meizu/%.meizu.avi : %.avi
cd meizu && meizu-convert ../$<
all: $(patsubst %,meizu/%,$(patsubst %.avi,%.meizu.avi,$(wildcard *.avi)))
#!/bin/bash
# A simple script to make sure I am running rtorrent in a screen
if ! ps -o uname -C rtorrent | grep -q `whoami`; then
screen -d -m rtorrent
fi
MAX_KEY_LENGTH = 20
PEAK_MIN_OFFSET = 4
NUM_LETTERS = 26
FIRST_LETTER = "A"
KEY_LENGTH_GUESS = 6
def index_of_coincidence(s, shift):
"""Find the index of coincidence of s with itself shifted by shift"""
Epsilon = 1e-10
def d_dx(&f) # :yields: x
Proc.new do |x|
(f[x + Epsilon] - f[x])/Epsilon
end
end