As configured in my dotfiles.
start new:
tmux
start new with session name:
def java_string_hashcode(s): | |
h = 0 | |
for c in s: | |
h = (31 * h + ord(c)) & 0xFFFFFFFF | |
return ((h + 0x80000000) & 0xFFFFFFFF) - 0x80000000 |
def unsign32RightShift(num, sn): | |
return (num & (2**32-1)) >> sn |
a_dict = {} | |
for i in xrange(100): | |
for j in xrange(100): | |
a_dict.setdefault(i, []).append(j) |
As configured in my dotfiles.
start new:
tmux
start new with session name:
ssh -qTfNn -D 7070 username@remotehost |
def vgg16_symbol(): | |
data = mx.sym.Variable('data') | |
# conv1 | |
conv1_1 = mx.sym.Convolution(data=data, kernel=(3, 3), pad=(1, 1), num_filter=64, name="conv1_1") | |
relu1_1 = mx.sym.Activation(data=conv1_1, act_type="relu", name="relu1_1") | |
conv1_2 = mx.sym.Convolution(data=relu1_1, kernel=(3, 3), pad=(1, 1), num_filter=64, name="conv1_2") | |
relu1_2 = mx.sym.Activation(data=conv1_2, act_type="relu", name="relu1_2") | |
pool1 = mx.sym.Pooling(data=relu1_2, kernel=(2, 2), stride=(2, 2), pool_type="max", name="pool1") | |
from collections import Counter | |
import numpy | |
def _bleu_stats(hypothesis, reference): | |
yield len(hypothesis) | |
yield len(reference) | |
for n in xrange(1, 5): | |
s_ngrams = Counter([tuple(hypothesis[i:i + n]) for i in xrange(len(hypothesis) + 1 - n)]) | |
r_ngrams = Counter([tuple(reference[i:i + n]) for i in xrange(len(reference) + 1 - n)]) | |
yield sum((s_ngrams & r_ngrams).values()) |
# pip install progressbar | |
import progressbar | |
import time | |
progress = progressbar.ProgressBar(widgets=[progressbar.Bar('=', '[', ']'), ' ', | |
progressbar.Percentage(), ' ', | |
progressbar.ETA()]) | |
for i in progress(range(100)): | |
# do something here |
class ToDictMixin(object): | |
def to_dict(self): | |
return self._traverse_dict(self.__dict__) | |
def _traverse_dict(self, instance_dict): | |
output = {} | |
for key, value in instance_dict.items(): | |
output[key] = self._traverse(key, value) | |
return output | |