Mind Like Water

Cool things about code.

Install node.js in Ubuntu 10.04

Mon 12 March 2012 by Lance Jian in Linux.

Ubuntu 10.04 does not have a default node.js package. So if you want to use it, you need to install it manually:

sudo aptitude install git-core curl build-essential openssl libssl-dev
git clone https://github.com/joyent/node.git && cd node && git checkout v0.6.11
sudo make install
node -v

"v0.6.11" is the current release version of node.js. If you are not sure, run git tag to check which versions are available.

Up to this point, you are able to use the node command. You can then install npm which is a package manager of node.js its own:

curl http://npmjs.org/install.sh | sudo sh

After that, it's easy to install other node.js libraries. For example, to install uglifyjs, simply run:

sudo npm install -g uglify-js

Change PDF File Initial View

Sat 10 March 2012 by Lance Jian in Tool.

When you open PDF files using Adobe Reader, it will read initial view settings such as single page or double page stored in the PDF file. It's actually pretty easy to change this information in Linux:

  1. Install pdfedit: sudo apt-get install pdfedit
  2. Open the PDF file in pdfedit, right click the "catalog" node in the tree panel, choose "add item to dictionary"
  3. Add property name: "PageLayout"
  4. Select "name" and input "TwoPageRight"
  5. Click "add and close"
  6. Save the PDF file

This adds a name in the catalog dictionary of PDF file. It will be used by the Acrobat Reader. There are other possibilities:

  • SinglePage
  • OneColumn
  • TwoColumnLeft
  • TwoColumnRight
  • TwoPageLeft
  • TwoPageRight

"Column" means continuous page. "Page" means display as a single page. "Left" means start double pages with odd-numbered pages on the left.

Please note that not all PDF viewers support this setting.

Convert Mercurial Repository to Git

Sun 05 February 2012 by Lance Jian in Linux.

I have some old mercurial repositories, and recently I want to convert them into git repositories. It turns out that converting them is pretty easy. First, you need to get hg-fast-export:

git clone git://repo.or.cz/fast-export.git

Next, create a new git repository:

mkdir new_git_repo
cd new_git_repo
git init

Finally, use the hg-fast-export.sh script from the directory you just checked out in the first step:

/path/to/hg-fast-export.sh -r /path/to/hg_repo
git repack -a -d -f
git checkout BRANCH_NAME

BRANCH_NAME is the name of mercurial branch, the "default" branch in mercurial will be called "master".

hg-fast-export.sh supports --force parameter, you can use it if you get validation errors.

Change the Default Editor in Ubuntu

Fri 03 February 2012 by Lance Jian in Linux.

Ubuntu and Debian use the alternatives system to maintain the symbolic links for programs. For example, when you first run visudo after a fresh installation of Ubuntu, it will prompt a list of editors for you to choose from. Unfortunately, it doesn't tell you how to change that setting again. The mostly happend situation is: you set it to "nano" at first, and want to change it to "vi" at a later time.

Here is the command to bring up that list again:

sudo update-alternatives --config editor

Some people suggest using command EDITOR=vi visudo, or export EDITOR=vi; visudo. They both works, but it's really annoying that you have to remember and type so many letters everytime you run this command.

Use rxvt as cygwin Terminal

Wed 01 February 2012 by Lance Jian in Linux.

Cygwin is a windows program that simulates a Linux environment. The default installation uses cmd.exe as the terminal program which is not very convenient. For example, it can only be resized up to 80 characters in width. Fortunately, there is an rxvt package in the Cygwin distribution. You only need to tweak some options to make it look like the terminal in Unix system.

Right click "Start > Cygwin > rxvt-native" menu item, and select "Properties...", edit the "Target" field to:

C:\path-to-cygwin\bin\rxvt.exe -display :0 -geometry 80x43 +sb -bg black -fg gray -fn "DejaVu Sans Mono-16" -tn rxvt-cygwin-native -e /bin/bash --login

You can change the "DejaVu Sans Mono" font to any other font name you prefer.