OS161 on Ubuntu 10.10

I was trying to get Ubuntu 10.10 to work with OS161. It was a big struggle but the main trick of getting it to work was having gcc 3.4. To install gcc 3.4 you would use the following command

wget http://ge.archive.ubuntu.com/ubuntu/pool/universe/g/gcc-3.4/libstdc++6-dev_3.4.6-6ubuntu3_i386.deb &&
wget http://ge.archive.ubuntu.com/ubuntu/pool/universe/g/gcc-3.4/gcc-3.4_3.4.6-8ubuntu2_i386.deb &&
wget http://ge.archive.ubuntu.com/ubuntu/pool/universe/g/gcc-3.4/gcc-3.4-base_3.4.6-8ubuntu2_i386.deb &&
sudo dpkg -i *.deb &&

You would then probably like to change your default gcc to 3.4 by doing the following command

cd /usr/bin/
sudo ln -s gcc-3.4 gcc

Then you can get the source of os161 and follow the nice step by step instructions by clicking here.

Hope this lets you spent less time configuring and more time hacking.


Leave a comment

Express with Jade on node.js

Over the weekend, I was playing around with node.js – a javascript implementation of an event I/O handler. Node.js is an event based framework that allows developer to easily build scalable network programs. The framework runs on the javascript V8 engine and was influenced by by Ruby’s Event Machine and Python’s Twisted. Node.js breaks the barrier between server side language and client side language.

Node.js is very easy to use, node.js came with a neat package manager like python’s easy_install and ruby’s gem. The packages that I played around with was express – a web framework, and Jade– a template engine. Below, I will show you how to combine the two packages Jade and Express to make a web app in 5 minutes.
first, make sure you have node.js, npm, express and jade installed on your machine.

Then create a file (call it example.js) using any editor you wish, and paste the code below.


var express = require('express')
var jade = require('jade')
app = express.createServer();
var local_var = "I am a local var";
jade.renderFile('index.jade', {locals:{local_var:local_var}} ,function(err,html){
console.log("Express server is started on port %s", app.address().port);

The first two lines imports the two packages that we are going to use and gives them each a name space.

app = express.createServer();
This allows us to have a handle on a concrete server

app.get('/',function(req,res){ .....});
defines a call back on our server. Every time the url path ‘/’ of our server is queried,
the function(req,res){….} will be called.

jade.renderFile('index.jade', {locals:{local_var:local_var}} ,function(err,html){

renders the file ‘index.jade’ and pass the local variables defined in the hash {locals:{local_var:local_var}} to the template for proper variable substitution, in our case local_var (defined as “I am a local var”).
res.send(html) then sends the html that was rendered back to the client.

Our template file will look like the below. Paste it into a file in the same directory as example.js, and name this file index.jade.

p= local_var
The above basically says that the paragraph will contain the value of what ever is defined in the variable ‘local_var’.

runnning the app

$ node example.js
Express server is started on port <port>

testing if it works
curl localhost:<port>

the above should give you

<p>I am a local var</p>


1 Comment


CASCON 2010 has been a fruitful one, it was there which I had my abstract published at ACM, I chaired for a conference for the first time. I had prepare weeks on my topic – which was clearly not enough and I was still as nervous as hell during the presentation.  My presentation was on cache-oblivious algorithms. “A cache-oblivious algorithm (or cache-transcendent algorithm) is an algorithm designed to use the CPU cache without having the size of the cache (or the length of the cache lines, etcetera) as an explicit parameter.”  as described by wikipedia. To present a topic, I had to understood the cache-oblivious algos completely, and it was not easy at all, since cache-oblivious algorithms are fairly new concepts. I was learning most of the material off this paper and 2 lectures videos from MIT, some of the algorithms were trivial, while others tooks days to understand the basic. The evaluation of my presentation not all positive, some people thought it was too deep into the algorithms. I hope to learn from this experience and improve my presentation skill for future workshops; for whatever conference it might be.

Leave a comment

Using finger with awk, finding out lab account info of your teammates in case you forgot

On one evening during my third year at U of T, I was working on an CSC343(intro to databases) assignment with my partner. When the assignment was finally completed I was overjoyed, with the assignment due in less than an hour, my partner put me in charge of submitting the assignment as he had to leave immediately and run some errands. When I was ready to submit the assignment electronically on a online app, the app asked me for my partner’s lab account name. I was in total panick, because I forgot his account name! I took a DEEP breath and tried to call my partner on his cell phone, but he didn’t pick up. “FML, my partner’s gonna kille me” I thought . I then messaged a friend and asked for consultation and possibly prayers. Instead of prayers however, she gave me a bash shell script that uses for loops, finger, /etc/pwd and grep. The script was magix, because it located my partner’s account info, and to this day, I still think she is l33t.

Now a year later, I wondered if there were a simpler way to find out the account information of a classmate by name (or part of his/her name) without using shell scripts. And here is what I came up with

export $REGEX=<name>
cat /etc/passwd | awk -F : '{print $1}' |xargs finger -l|awk '/Name: [a-zA-Z]*'$REGEX'[a-zA-Z]*/{print $0;getline;print}'

The command might look daunting at first, but if you break it down, it is really simple.
cat /etc/passwd displays various information of all the user accounts on system, it usually looks like this

riak:x:114:123:Riak Data Store,,,:/var/lib/riak:/bin/bash
mysql:x:115:124:MySQL Server,,,:/nonexistent:/bin/false

for more information on /etc/passwod visit here

awk -F : {print $1}

The above command basically says that for each line, print the first ($1) element delimited by the symbol “:”. In our case it will display all of the user account name.


The above would be an example of user accounts.

xargs finger -l

finger allows us to find more information on a given account name, including the user’s name. This is pretty essential.

awk '/Name: [a-zA-Z]*'$REGEX'[a-zA-Z]*/{print $0;getline;print}'

prints the line that contain the values that are defined by $REGEX.

So this little trick command allows the user to find account information based on the user’s registered user name, I hope this is useful to you, and I hope my WTF moment doesn’t happen to you.


Leave a comment

Linux networking/ip notes

Networking can be a pain, and in linux there are several config files that I must remember where they are and what they do. Note Ubuntu is a bit different.

For various configuration like hostname, gateway, and/or the type of protocol to use.
The below is a summary of possible field and their values, thanks to this faq

NETWORKING=answer, where answer is yes or no -Configure networking or not to configure networking.
FORWARD_IPV4=answer, where answer is yes or no -Perform IP forwarding or not to perform IP forwarding.
HOSTNAME=hostname, where hostname is the hostname of your server.
GATEWAY=gwip, where gwip is the IP address of the remote network gateway -if available.
GATEWAYDEV=gwdev, where gwdev is the device name eth# you use to access the remote gateway.

an example network file can be


This file contains the configuration for a specific network device (in our case it is ifcfg-eth0)

DEVICE=devicename, where devicename is the name of the physical network device.
IPADDR=ipaddr, where ipaddr is the IP address.
NETMASK=netmask, where netmask is the netmask IP value.
NETWORK=network, where network is the network IP address.
BROADCAST=broadcast, where broadcast is the broadcast IP address.
ONBOOT=answer, where answer is yes or no. Do the interface need to be active or inactive at boot time.
BOOTPROTO=proto, where proto is one of the following :
none - No boot-time protocol should be used.
bootp - The bootp now pump protocol should be used.
dhcp - The dhcp protocol should be used.
USERCTL=answer, where answer is one of the following:
yes - Non-root users are allowed to control this device.
no - Only the super-user root is allowed to control this device.

an example network-script file can be


Contains information on the dns that this machine is using
An example file would be

search example.com
;the name server that the resolver should query.

A special note on the search parameter; it is the list of domains that we will search by default. for example if we nslookup on svn, it will actually lookup for svn.example.com. if we didn’t have the search rule below, it would just search for svn and give a not found response.

Leave a comment

Ubuntu 10.10 Checking battery state…

A few days ago I had to reinstall by ubuntu on my T-400. After the re installation, it required me to upgrade my video driver using a proprietary software. After I restarted my computer, the machine gets stuck at the boot stage, displaying the message “Checking battery state….”

I attempted at searching on Google for ways to remedy this my problem, but no luck. I was frustrated and figured that I might be able to figure something out if I had a terminal. I went to tty1 by pressing ctrl + alt + F1, I then removed my graphics configuration by issuing the following command
sudo rm /etc/X11/xorg.conf
I then issued a reboot
sudo reboot
and everything was fine and I could login into my machine normally.


Using awk to remove python2.7

Today I wanted to remove python 2.7, and I didn’t really want to do it manually by doing sudo rm on individual python2.7 file/folder. So instead I used whereis, xargs, and grep to help me. I used the following command 

whereis python | awk 'BEGIN{FS=" "}{for(i=1;i<NF;i++) print $i}' | grep python2.7 |xargs sudo rm -fr

Lets walk this through step by step.

>whereis python

Finds all python files that are in the standard directory, for example in my machine it produced
python2: /usr/bin/python2.7 /usr/bin/python2.6-config /usr/bin/python2.6 /etc/python2.7 /etc/python2.6 /usr/lib/python2.7 /usr/lib/python2.6 /usr/local/bin/python2.7 /usr/local/bin/python2.7-config /usr/local/lib/python2.7

We want to split this line by white spaces; this is where the awk expression comes along.
awk 'BEGIN{FS=" "}{for(i=1;i<NF;i++) print $i}

The above uses awk to split white space delimited strings into seperate lines, the FS is a special awk’s built-in variable that determines the delimited string, in our case it is a space. The NF stands for the total number of elements.
I got the following on my machine.


then with some help of grep and xargs I was able to successfully remove python2.7 from my system with precision.

grep python2.7 |xargs sudo rm -fr

This is only a little taste of awk’s power, it fully supports regular expression and makes command line scripting a breeze.
For example if you wanted to kill all processes that contains the word java, then you can just do

ps ax | grep java| awk '/java/{print $2;}' |xargs kill -9

especially useful for killing multiple java processes that hangs.
I for one have just begin to use awk, and I see it as a essential tool for all scripters in linux environment.