named parameters for bash function
function myFunc {
while [[ $# -gt 0 ]]; do local "$1"; shift; done
#require paramName
}
myFunc paramName=paramValue
Now you can have named parameters for your bash functions, it made my library more useful since the script will be more readable. For compulsory parameters, you should check if it has been set or not. Some people do “local $*” instead of the while loop, but it will not work with parameters like paramName=”value with space”.
font Source Code Pro for your vim
Adobe has released Source Code Pro, a open source programming font. I switched it with vim, and I am loving it. I use 14pt and Light. Give it a try!
bash vi line editing mode
bash:
set -o vi
If you use vim you will love this. This enables vi mode for bash. It means you can use b, w to navigate backward and forward on words, f, F to find characters. Definitely helps with command line editing.
git: delete remote branch
Posted by yifanz in version control on May 22, 2012
git push origin :branch_name
Python strptime and number of week in the year
from datetime import datetime
d = datetime(2012, 4, 10, 0, 0, 0)
d_str = d.strftime('%Y%W')
# d_str = '201215'
dw = datetime.strptime(d_str, '%Y%W')
# dw = datetime.datetime(2012, 1, 1, 0, 0) <----- WHY?
# to make %W work, you have to use it together with %w
dw = datetime.strptime(d_str+' 0', '%Y%W %w')
# dw = datetime.datetime(2012, 4, 15, 0, 0)
Sequel Pro – ultimate sql gui interface
Posted by yifanz in Useful Stuff on April 25, 2012
Recently I’ve been using mysql at work, one of my colleague suggested Sequel Pro. It is a nice gui application for mysql mainly. There are plans to support sqlite but not done yet. I strongly recommend you checking it out if you have to deal with mysql.
git create branch to track remote branch
Posted by yifanz in version control on April 25, 2012
git branch –track my_branch origin/remote_branch
git checkout my_branch