Skip to content

Instantly share code, notes, and snippets.

ben6 benwei

Block or report user

Report or block benwei

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View vimtips_regex01
replace
test-keyworkd : anything ;
to
“test-keyworkd” :“anything”,
regex:
s/^\([ \t]*\)\([a-z-]*\):[ \t]*\(.*\);/\1"\2":"\3",/g
@benwei
benwei / vim-note01
Created Jul 6, 2014
vim search and replace binary characters by regular expression
View vim-note01
/\%xnn characters (nn range is 00-FF)
%s/\%xnn//g -- replace all \xnn characters (nn range is 00-FF)
%s/\%unnnn//g -- replace all unicode code 'nnnn' characters, (nn range is 0000-FFFF)
@benwei
benwei / makefile
Created Feb 3, 2012
membuddy.c & makefile
View makefile
#http://en.wikipedia.org/wiki/Buddy_memory_allocation
#This is a dummy code for Buddy memory allocation implementation.
CFLAGS=-DHAVE_DEV_SYS
LDFLAGS=
CFILES=membuddy.c
OBJS=$(CFILES:.c=.o)
BINNAME=membuddy
all: $(BINNAME)
@benwei
benwei / closure.py
Created Jul 3, 2012
closure sample h4
View closure.py
# reference:
# http://stackoverflow.com/questions/3190706/nonlocal-keyword-in-python-2-x
# http://en.wikipedia.org/wiki/Closure_(computer_science)#Example
#
def counter():
d = {'x': 0} # tested with python 2.7.2
def increment(y=1):
# nonlocal only work for python3
#nonlocal x
d['x'] += y
@benwei
benwei / yd
Created Nov 27, 2012
yd script is a simple wrapper while cache read word for ydict
View yd
#!/bin/sh
YD_HIST_DIR="${HOME}/.ydict_history"
mkdir -p "$YD_HIST_DIR/_relation/"
echo "$@" >> "${YD_HIST_DIR}"/_words.txt
WordCacheFile="${YD_HIST_DIR}"/"$@".txt
WordRelationFile="${YD_HIST_DIR}"/_relation/"$@".txt
if [ ! -f "$WordCacheFile" ]; then
ydict -u -w "$@" | sed -e "s/'/'/g" -e "s/\(.\[36m\)[ ]*/\1 /g" > "$WordCacheFile"
@benwei
benwei / regex_fun.js
Created Nov 27, 2012
convert function to that.func (javascript)
View regex_fun.js
// regexp
// convert
// function a (a1,a2)
// that.a = function (a1, a2)
cat jsfile.js | sed -e 's/^\([ \t]*\)function[ \t]*\([a-zA-Z]*\)(/\1that.\2 = function (/g'
@benwei
benwei / BWSpentTime.js
Created Dec 7, 2012
SpentTime class for node js
View BWSpentTime.js
function SpentTime () {
this.reset = function () {
start = new Date();
}
this.diff = function () {
var now = new Date();
return (now.getTime() - start.getTime())
}
var start = new Date();
}
@benwei
benwei / dict.sh
Created Oct 26, 2015
simple dictionary using curl with dict protocol
View dict.sh
#!/bin/sh
## refernce http://www.dict.org/rfc2229.txt
word="$1"
if [ -z "$word" ]; then
echo "syntax: ./dict <word>"
exit 1
fi
curl "dict://dict.org/d:$word"
@benwei
benwei / shell_script_path.sh
Created Nov 9, 2015
get script's location path
View shell_script_path.sh
t="${0%%`basename $0`}"; cd "$t" ; SCT_PATHPATH=`pwd`
echo $SCT_PATHPATH
View git_over_ssh.md

how to git over ssh

create a base repository

 $ mkdir -p testprj
 $ cd testprj
 $ git init --bare
You can’t perform that action at this time.