Archive for Linux

yet another ~./vimrc

set tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab number
nnoremap <F7> :tabp<Enter>
nnoremap <F8> :tabn<Enter>
nnoremap <F6> :bd<Enter>
nnoremap <F5> :tabnew<Enter>

set sessionoptions=blank,buffers,curdir,folds,globals,help,localoptions,options,resize,tabpages,winsize,winpos

Create Session:
:mksession /path/to/session/file.vim

Restore Session:
$ vim -S /path/to/session/file.vim
:source %


Mount remote system locally over ssh

with certificate authentication or password prompt
sshfs /mnt/my_remote_system  -o reconnect -o follow_symlinks -o allow_other


or with plain text password:

echo “my_password” | sshfs /mnt/my_remote_system  -o reconnect -o follow_symlinks -o allow_other -o password_stdin


Getting Started with Git

Below are some helpful links and tips for getting started with the Git version control system.

Git is rapidly becoming one of the most widely used version control systems is use today. Git is especially is open source projects as it allows for rapid merging: a feature not found in most version control systems. Git is also compact and FAST.

If you’re a developer, I encourage you to write open source software as a means of deliberate practice. Using Git in the context of open source will really help other contribute and use your work. I recommend specifically. Even professionally, I think that Git’s market share will continue to rise and be more prevalent in the workplace.

After using subversion for years, I dropped it in favour of Git. And below are a few notes that I learned along the way that may make it easier for you to get started. I hope you find using as fun as I do.


Here’s an excellent intro video. You should probably watch this first. There are two parts.

Here’s a nice, short book on how GIT works. You may want to come back to this after you’ve played with the commands for a couple of days. But I do recommend coming back to it. It has lot of explanations that show how git works. I personally read this first. After reading it, I had a great grasp of the concepts which made it easier to memorize the commands.

//see my git links on my delicious account (note: there are 3 pages; some of the more useful ones are older links; the newer links are more advanced items, so you may want to skip them for now)

//Install Git on Ubuntu
sudo apt-get install git-core


Finding the Usage

//Run: git <command> –help to see usage on that command
//eg. git push –help

Some Common Commands

git clone -o github_remote

git pull github_remote

git push github_remote github_branch_master

git push –all github_remote

git status

git commit -a -m “Fixed error with homepage not displaying the correct timezone.”

git add -i


//warning: destructive (like an svn revert); know what you’re doing first with this.

git reset –hard master

//add this bash alias to your ~/.bashrc file to be able to recursively add empty directories to a repository

alias git_add_empty_dirs=’find . \( -type d -empty \) -and \( -not -regex ./\.git.* \) -exec touch {}/.gitignore \;’

//turns on the shell colors for all working copies

git config –global color.ui always

//makes git status = git st

git config –global status

//create an alias to easily recursively update the submodules within a project

git config –global alias.subup “submodule update –init –recursive”

More Useful Git Resources

For people who have used SVN:

A Simple Workflow for using GIT in small teams

Also, the git official website has a lot of resources…

Here’s a great article on rebasing:


Create your own linux/mysql/php development box for Windows or Mac OS X

Download iso of ubuntu server edition 11
Download VirtualBox

Install VirtualBox
Create a new VM with 1000mb ram and 20GB of storage
	- bridge the network connection
	- default install (enable openssh server)
$ sudo su -
$ visudo
$ vim /etc/network/interfaces
	auto eth0
	iface eth0 inet static

$ /etc/init.d/networking restart
$ ifconfig
$ ping  //confirms internet connectivity
$ apt-get update  //update package manager sources
$ apt-get install mysql-server  //install mysql
$ apt-get install apache2
$ apt-get install php5
$ php -v  //confirm php 5.3.5
$ apt-get install samba  //install samba
$ vim /etc/samba/smb.conf
	- enable (uncomment) [homes]
	- read only = no
	- create mask = 0775
	- directory mask = 0775
$ sudo smbpasswd myusername
$ /etc/init.d/smbd restart //restart samba service to apply changes
	- should be able to connect to your smb share via windows or mac (
$ apt-get install git-core


Resume a file using rsync over ssh

Sometimes it happens that a file transfer using SCP fails for some reason. Oh no! now you have to start from scratch…

There’s a quick workaround, use rsync over ssh. No rsyncd is needed, and the transfer is secure. It works like this:


It may still take some time to run based on the file size, but it will certainly take less overall time as it will not transfer the whole file again.


Export to CSV with MySQL

On Ubuntu, this will create a file in /var/lib/mysql/[DB_NAME]/output.csv

I had to run the query as MySQL root. Didn’t try to find out what permission actually permitted the user to write to the file. It’s probably create table though.

SELECT, v.title,, v.slug, v.description
video v
video_category vc ON v.video_category_id =
OUTFILE 'output.csv'


Hiphop Benchmarks


Hiphop is Facebook’s PHP compiler. It compiles php source into c++ source. This is my experiment with compiling and running it with a couple of scripts from


I’m using a build at c3876a7dcaf1694f7c23232149df3283753ed9f9 from (Sept 8th, 2010).

I was able to build successfully under ubuntu with the help of this document:

If for some reason make fails, you’ll need to delete the CMakeCache.txt file and build again once you’ve resolved the build error.

On to the benchmarks…

I’m using GNU time for the benchmarks:


# lshw -short
H/W path Device Class Description
system System Product Name
/0 bus A8V
/0/0 memory 64KiB BIOS
/0/4 processor AMD Athlon(tm) 64 Processor 3700+
/0/4/5 memory 64KiB L1 cache
/0/4/6 memory 1MiB L2 cache
/0/37 memory 2GiB System Memory
/0/37/0 memory 512MiB DIMM DDR Synchronous 333 MHz (3.0 ns)
/0/37/1 memory 512MiB DIMM DDR Synchronous 333 MHz (3.0 ns)
/0/37/2 memory 512MiB DIMM DDR Synchronous 333 MHz (3.0 ns)
/0/37/3 memory 512MiB DIMM DDR Synchronous 333 MHz (3.0 ns)
/0/100 bridge K8T800Pro Host Bridge
/0/100/1 bridge VT8237 PCI bridge [K8T800/K8T890 South]
/0/100/1/0 display Radeon RV100 QY [Radeon 7000/VE]
/0/100/a eth0 network 88E8001 Gigabit Ethernet Controller
/0/100/f storage VIA VT6420 SATA RAID Controller
/0/100/f.1 scsi0 storage VT82C586A/B/VT82C686/A/B/VT823x/A/C PIPC Bus Master IDE
/0/100/f.1/0 /dev/sda disk 300GB ST3300831A
/0/100/f.1/0/1 /dev/sda1 volume 276GiB EXT3 volume
/0/100/f.1/0/2 /dev/sda2 volume 2941MiB Extended partition
/0/100/f.1/0/2/5 /dev/sda5 volume 2941MiB Linux swap / Solaris partition


Benchmark 1:



gtime php fasta.php
User: 278.85 System: 1.39 Elapsed: 6:50.66 68%CPU (0text+0data 30000max)k

gtime ./program
User: 190.81 System: 5.64 Elapsed: 6:58.20 46%CPU (0text+0data 1041840max)k

gtime ./build/program > output.txt
User: 199.91 System: 1.05 Elapsed: 3:21.98 CPU: 99% Memory( Avg Res: 0kB Max Res: 1041856kB )

gtime php fasta.php > output2.txt
User: 330.14 System: 1.17 Elapsed: 5:32.78 CPU: 99% Memory( Avg Res: 0kB Max Res: 30000kB )

Both output.txt files are 243MB.

Benchmark 2:



gtime php btrees.php
stretch tree of depth 16 check: -1
65536 trees of depth 4 check: -65536
16384 trees of depth 6 check: -16384
4096 trees of depth 8 check: -4096
1024 trees of depth 10 check: -1024
256 trees of depth 12 check: -256
64 trees of depth 14 check: -64
long lived tree of depth 15 check: -1
User: 40.59 — System: 0.08 — Elapsed: 0:40.89 — CPU: 99% — Max Res Memory: 312944kB

gtime build/program
stretch tree of depth 16 check: -1
65536 trees of depth 4 check: -65536
16384 trees of depth 6 check: -16384
4096 trees of depth 8 check: -4096
1024 trees of depth 10 check: -1024
256 trees of depth 12 check: -256
64 trees of depth 14 check: -64
long lived tree of depth 15 check: -1
User: 9.86 — System: 0.06 — Elapsed: 0:09.98 — CPU: 99% — Max Res Memory: 237152kB


In benchmark 1, Hiphop performed similarly when outputing to the shell, but was 65% faster when output was piped to a file. However, it consumed 3500% more memory than its php counterpart.

In benchmark 2, Hiphop was 411% faster and consumed 75% of the memory that the php version did.

Future Considerations

Hopefully I’ll be able to add more benchmarks as time goes on. Hiphop is still very young and unstable; though, it does show promising results even now.


Linux Simple Benchmark with gnu time

This is used to show the runtime length of an executable in linux. It also shows the memory usage.

Download and compile GNU Time

tar -xvzf time-1.7.tar.gz
cd time-1.7
make install
ln -s `pwd`/time /usr/local/bin/time

Add an alias to ~/.bashrc

alias gtime='/usr/local/bin/time -f "User: %U -- System: %S -- Elapsed: %E -- CPU: %P -- Max Res Memory: %MkB"'

Use the command to run a benchmark

gtime ./program

The output looks something like this:

User: 40.59 -- System: 0.08 -- Elapsed: 0:40.89 -- CPU: 99% -- Max Res Memory: 312944kB


Create and Email a patch with Git

Create a patch of a single commit.
git format-patch f98358d9b7af7e7429fec40b2da88feb5fafe6cf -1

Email the patch as an attachment.
echo "My Message Body" | mutt -s "my subject line" -a 0001-Added-database-build-infrastructure.patch --

Apply the patch.
git apply 0001-Added-database-build-infrastructure.patch


Keeping the Time Current on a Linux Server

apt-get install rdate
rdate -s
crontab -e
34 3 * * * /usr/bin/rdate -s

See if the above ntp server doesn’t work for you.