Archive for September, 2012

A few zsh tricks I’ve learned so far

September 30, 2012 Leave a comment

It’s the second day since I installed zsh onto my Mac OSX Lion (the exact procedures work on Mountain Lion as well) and I couldn’t help to sharing a few tips that I’ve learned so far:
1. Find all .pdf files under current directory
ls **/*.pdf

2. Go to folder ~/Documents/things/2nd_backup, current folder is ~
cd D/t/2, followed by Tab, autocompletion will change the command into
cd ~/Documents/things/2nd_backup

3.stop a process without running ps
kill, followed by space, tab
If you already know part of the process name, simply, for example
kill ht, Tab (intend to kill running htop process), if htop is the only one that matches ht, command will be automatically converted to
kill pid_of_htop, pretty neat, isn’t it?

4. change default theme from robbyrussell to gentoop The reason I did the switch is because robbyrussell lacks the indication if a user runs “sudo -s” to become root (given the user is given the privilege) and I happened to be a Gentoo fan.
Find the following line in ~/.zshrc and change robbyrussel to gentoo

[UPDATE 10:05PM EDT, 9/30/2012]
I found robbyrussell to be very attractive so I decided to tweak it a bit so it will indicate sudoer status:
vi ~/.oh-my-zsh/themes/robbyrussell.zsh-theme
add “%# ” to the end of PROMPT setting:
PROMPT='%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}%# '
With this change I can easily find out if I am running shell as normal user (%) or root (#), see the screenshot below:

Categories: zsh

Mac OS X Lion zsh installation with brew guide

September 30, 2012 2 comments
brew install zsh
cd $HOME
git clone .oh-my-zsh
sudo chsh -s /usr/local/bin/zsh yourusernamehere
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

Since I am a git nut, I fell in love with zsh right away after I saw the following when I was testing the auto-completion feature of zsh (glad the default zshrc.zsh-template has git enabled in the plugins setting):

The big yellow X means there are changes under current repository, “exp” in red is the name of the current branch. Once I committed the changes, the big yellow X sign disappeared. In other words I don’t even need to type git status to check if current repository is clean – can’t stop loving this feature.


Categories: zsh

Array min, max with Coffeescript

September 19, 2012 Leave a comment

Quite simple actually:

  Math.max.apply(null, this)

  Math.min.apply(null, this)

a=[6, 5, 17, -3, 4.5]
console.log a.max()
console.log a.min()


Categories: coffeescript, Programming

Yet another must have node.js module – underscore-cli

September 12, 2012 Leave a comment

If you love underscore.js and happen to be a CLI nut, you should not miss out underscore-cli, see

for details, or simply install via (assuming you are already using node.js)

sudo npm install -g underscore-cli

Test Drive:
curl|underscore print --color

Categories: javascript, node.js

Calling initialization function only once with this js trick

September 12, 2012 Leave a comment

There are times when an initialization function in a js object needs to be called only once. Here’s one of the solutions I came up with. When F.paint() is called, a check on the initialization tag (need_init) is performed. need_init remains undefined until init() is called for the first time.

The code:

var F=(function() {
	var self=this;

	var init=function() {
	return {
		paint: function() {
			if(typeof self.need_init==='undefined') {
			console.log('Now I am ready to paint.');


Output from the above example:
Now I am ready to paint.
Now I am ready to paint.
Now I am ready to paint.

Enjoy coding.

Categories: javascript, Programming

Dualboot Mountain Lion + Ubuntu 12.04 LTS on the same hard drive howto

September 4, 2012 Leave a comment

Shortly after Mountain Lion was released I did a clean installation onto my HP 4530S and have been very happy with the result, but I am also a huge Ubutu fan and I’ve been dual booting Ubuntu 12.04 LTS through a SD card on the same machine. All was working fine except I don’t like the Ubuntu booting speed (it’s one of those 95MB/s 16GB Sandisk SD cards, fast on the paper but it takes over 30-second to boot into Ubuntu) so I decided to dual boot ML and Ubuntu from the same hard drive (Agility 3 SATAIII 120GB, and it turned out to be not very difficult.

What is needed:
1) ML Unibeast installation disk
2) HP Installer (Or Multibeast if on non-HP4530s systems)
3) Ubuntu installation disk

1) Re-partition hard drive ML installation, when I did the ML installation, I started with 1-partition scheme as I was not planning for dual-booting. To re-size the ML partition is a piece of cake (I was amazed how Mac OS X can handle this so well, online resize the OS drive, looking at you Window$), just launch disk utility -> click on the hard drive, click the + sign, adjust the divider, click on the new partition and adjust the size through its size from the text field if needed. The new partition will be created as free space and no other changes are required. Hit Apply.
2) Reboot with Ubuntu installation disk, choose “Something else” when asked how to install, create a ext4 / partition and a 2GB swap partition (adjust the sizes if you want, I have 8GB of RAM so I am not worried about swap that much). My root partition is created as /dev/sdb3, when it comes to boot loader installation, make sure you choose this as where GRUB would be installed, if you choose the wrong partition, first partition, for example, you will need to do some extra work to fix it.
3) Once Ubuntu is installed, reboot with Unibeast, make sure to choose the hard drive ML installation when Chimera menu comes up. Log in to ML and install Chimera again from HP installer (or Multibeast).
4) Shutdown, remove Unibeast installation disk, power up, when Chimera boot logo appears, hit any key you will see the Ubuntu partition along with the original ML partition.

Note: This post is created after I successfully dual boot into the newly installed Ubuntu 12.04 LTS. Cheers.