Skip to content

Instantly share code, notes, and snippets.

View vls's full-sized avatar

Liang Zhaohao vls

View GitHub Profile
@vls
vls / gist:850505
Created March 2, 2011 04:56
simulate DOM building
javascript: (function n(e){e.eq(0).fadeIn(99,function(){n(e.slice(1))})})($(":visible").hide())
@vls
vls / timeit.py
Created July 15, 2011 01:13
python time test decorator function
import time, functools
def timeit(func):
@functools.wraps(func)
def __do__(*args,**kwargs):
start = time.time()
result= func(*args,**kwargs)
print '%s used time %ss'%(func.__name__,time.time()-start)
return result
return __do__
@vls
vls / comm.sh
Created July 16, 2011 02:32
some common utility functions
function log()
{
local msg=$1
now=`date "+%Y-%m-%d %H:%M:%S"`
i=${#FUNCNAME[@]}
lineno=${BASH_LINENO[$i-2]}
file=${BASH_SOURCE[$i-1]}
echo "${now} ${file}:${lineno} ${msg}"
@vls
vls / new_subprocess.py
Created August 26, 2011 10:30
Python 2.6.5 subprocess SIG_PIPE bug fix
from sub import *
import sys
import os
import types
import traceback
import gc
import signal
import errno
@vls
vls / gist:1236794
Created September 23, 2011 05:20
get the comment of the last commit in svn
#get the comment of the last commit in svn
svn log -q -v --xml --with-all-revprops -r head | grep "^<msg" | sed -e "s/<msg>\(.*\)/\1/g"
@vls
vls / gist:1271927
Created October 8, 2011 06:06
checkout from git. The destination directory will NOT be under source control
git archive --format=tar HEAD | (cd ~/beta/web && tar xf -)
git archive --format=tar HEAD | ssh app08.gz "(cd ~/beta/qn_fd_system && tar xf -)"
@vls
vls / make_data.py
Created December 20, 2011 08:11
make test dataset
#!/usr/bin/env python
import os
begin = 1
end = 3000000
inc = 3000000
for j in xrange(3):
with open('%s.txt' % (j + 1), 'w') as wf:
for i in xrange(begin, end + 1):
@vls
vls / export_plain.py
Created February 21, 2012 03:23
test script for re2 and re2
#!/usr/bin/env python
#encoding=utf-8
import time
import os, sys
import re
import pickle
import re2
re2.set_fallback_notification(re2.FALLBACK_WARNING)
@vls
vls / c_re2_plain.c
Created February 21, 2012 03:26
test program for re2
#include <re2/re2.h>
#include <iostream>
#include <string>
#include <cassert>
#include <stdio.h>
#include <vector>
#include <cstdlib>
#include <time.h>
#include <unistd.h>
@vls
vls / gist:1873993
Created February 21, 2012 05:37
pyre2 modification
cdef inline _re2.StringPiece* _alloc_sp(self, char* cstring, Py_ssize_t& size):
cdef _re2.StringPiece * sp
sp = new _re2.StringPiece(cstring, size)
return sp
cdef inline void _dealloc_sp(self, _re2.StringPiece* sp):
del sp
cdef inline _my_match(self, _re2.StringPiece sp_zero, int pos, int size, _re2.re2_Anchor anchoring, _re2.StringPiece* submatch, int nsubmatch):
return self.re_pattern.Match(sp_zero, <int>pos, <int>size, anchoring, submatch, nsubmatch)