Skip to content

Instantly share code, notes, and snippets.

ben6 benwei

  • Taiwan
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
@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();
}
View git_over_ssh.md

how to git over ssh

create a base repository

 $ mkdir -p testprj
 $ cd testprj
 $ git init --bare
View SOIPAddress.c
//
// SOIPAddress.c
//
/*
Copyright (c) 2013, Ben Wei
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
@benwei
benwei / blink_by_serial_input_char_a.ino
Last active Dec 16, 2015
blink arduino's led (pin 13) by serial input with char 'a'
View blink_by_serial_input_char_a.ino
@benwei
benwei / cwc_l.sh
Created Jul 16, 2013
one line to list line count of c file
View cwc_l.sh
#!/bin/sh
find -name "*.c" | while read fn ; do wc -l $fn ; done
View vimtips_regex01
replace
test-keyworkd : anything ;
to
“test-keyworkd” :“anything”,
regex:
s/^\([ \t]*\)\([a-z-]*\):[ \t]*\(.*\);/\1"\2":"\3",/g
You can’t perform that action at this time.