Skip to content

Instantly share code, notes, and snippets.

View lisabug's full-sized avatar
😇
Focusing

Yuanqin Lu lisabug

😇
Focusing
View GitHub Profile
@lisabug
lisabug / java_String_hashcode.py
Created March 10, 2016 09:13 — forked from hanleybrand/java_String_hashcode.py
python function that produces the same result as java's String.hashCode() found at http://garage.pimentech.net/libcommonPython_src_python_libcommon_javastringhashcode/
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
@lisabug
lisabug / default_list_value_in_dict.py
Created March 11, 2016 09:31
[Python] use list as dict default value
a_dict = {}
for i in xrange(100):
for j in xrange(100):
a_dict.setdefault(i, []).append(j)

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@lisabug
lisabug / git.md
Created March 17, 2016 15:32 — forked from suziewong/git.md
Git的多账号如何处理? 1.同一台电脑多个git(不同网站的)账号 2.同一台电脑多个git(同一个网站的比如github的)多个账号

1.同一台电脑可以有2个git账号(不同网站的)

首先不同网站,当然可以使用同一个邮箱,比如我的github,gitlab,bitbucket的账号都是monkeysuzie[at]gmail.com 这时候不用担心密钥的问题,因为这些网站push pull 认证的唯一性的是邮箱 比如我的windows 上 2个账号一个gitlab 一个github (用的都是id_rsa)

host github
  hostname github.com
  Port 22

host gitlab.zjut.com

@lisabug
lisabug / ssh_gfw.sh
Created March 26, 2016 10:33
利用ssh翻墙
ssh -qTfNn -D 7070 username@remotehost
@lisabug
lisabug / vgg16_mxnet.py
Created April 9, 2016 04:11
VGG16 symbol definition of mxnet
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())
@lisabug
lisabug / progressbar.py
Last active December 5, 2016 10:10
ProgressBar in Python
# 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
@lisabug
lisabug / ToDictMixin.py
Created December 21, 2016 09:53
ToDictMixin Class in Python
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