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”.

, ,

Leave a comment

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!

,

Leave a comment

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.

, ,

Leave a comment

git: delete remote branch

git push origin :branch_name

, ,

Leave a comment

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)

Leave a comment

Sequel Pro – ultimate sql gui interface

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.

Leave a comment

git create branch to track remote branch

git branch –track my_branch origin/remote_branch
git checkout my_branch

,

Leave a comment

Follow

Get every new post delivered to your Inbox.