Monday, September 15, 2008

The 'tee' Command

Sometimes you don't see an old, good thing, until you really need them.

tee is Linux shell command using which you can redirect a program's output to the screen as the same time dumping it on a file.

Usage:
$ < program> | tee < output_file>

If it is your own program, make sure that it flushes the output time to time if you want to readily see the output on the screen.

Wednesday, August 20, 2008

Boolean AND and OR

Yesterday, at the lab, we went into an argument on the boolean operator precedence. We always talk about precedence in arithmetic operators, but the precedence in boolean operator is hardly a topic of discussion. One of my colleague claimed that logical AND has higher priority than the logical OR; I sided with another saying that they have equal priority. So we ended up writing sample programs (in python) to verify our claims:

if a or b and c:
print "true1"
if a and b or c:
print "true2"

It's embarrassing that we had this doubt at this stage of the academic life (6th year Ph.D.). But the funny thing is that we couldn't test our claims because of how the compiler works. The programing languages don't go into processing the second operant of a OR statement, if the first is "true"; same with a AND statement, if the first operant is "false". I don't want to write the whole story of why this feature makes the tests invalid, but think about it and you will see it.

Ultimately, we ended up looking at the language documentation (which we should've done in the first place!) and found out my other colleague is right - the AND operator do have higher priority than the OR operator.

Nothing new in this story, but I was just surprised to see how couldn't test the priority programmatically.

Sunday, July 6, 2008

Google Search Tricks

Here is a nice article from Lifehacker.com on top 10 Google search tricks.
http://lifehacker.com/339474/top-10-obscure-google-search-tricks

Wednesday, June 18, 2008

Firefox 3 Add-Ons and Other Stuffs

As a person who uses Firefox on three different computers regularly, synchronizing bookmarks is very essential to me. Earlier I was using Google FF Sync, but it is discontinued with FF3. Fortunately I found Foxmarks. It works great for my need.

Another problem I had was that I can not access some of the private web pages of my research group at UofT from home - the access is denied for external (to UofT) IP addresses. The proper solution is to setup a VPN connection. But, once the VPN is activated, everything goes through the VPN resulting in unnecessary traffic going through UofT. FoxyProxy is a great FF extension to solve this problem. It can filter my http queries so that only a selected queries go through UofT. The only problem is to create an ssh connection to my lab computer and keep it alive all the time. Still, you can safely put the ssh connection in the background using -fN options. The additional benefit of using FoxyProxy is that now I can access premium websites like IEEEExplore and Oxford Online Dictionary from home (UofT has a enterprise subscription to these websites.)

Another excellent extension I am using is FireGestures: it let you perform many menu actions by drawing figures using mouse (like the graffiti handwriting recognition.) If you are a "mouse-man", it is an essential FF extension; but even for a "shortcut-key-man" like me, it helps a lot.

Do you know now you can now make the FF to call gmail compose box whenever you click a "mailto:" link? It is a new feature introduced with FF3. This link has detailed instructions.

Firefox 3 Look & Feel

Yeah, yeah, I too downloaded it on the "Download Day" -- in three computers actually: office Linux, home Linux, and Laptop Windows. :-)

One of the nice features of the new Firefox 3 is that its look & feel is integrated with the native look of the operating systems. It is generally not obvious in Windows, because all the Windows applications have to follow the rule. But it is very obvious in Linux (no idea about Mac platform.)

However, there is a catch using Firefox 3 with KDE desktop environment, because Firefox 3 is incorporated with the GTK widget set, whereas KDE uses the QT widget set. Still I was able to get the KDE look & feel in Firefox 3 in my Kubuntu system using Kubuntu's system settings. Go to the System Settings -> Appearance -> GTK Styles and Fonts and make sure all the GTK components are set to use the KDE settings.

Before I realized that FF3 is using native look & feel, I had this irritating widget set in FF3. Only after I searched through Google for a while, I realized that I can not change anything in FF3, but have to change my KDE look & feel. I was using Domino widget style, which was fine outside FF3 but terrible for gmail. Once I switched to QtCurve widget style (just my preference, nothing particular), everything was good.

FF3's native theme on Linux is boring, and many other themes from Mozilla web site behave oddly. After a few iterations, I am now settled with "Phoenity Reborn" theme; it looks pretty good!

Wednesday, June 11, 2008

Enabling Java API Documentation Inside Eclipse

If you enable Java API documentation inside Eclipse, you can access relevant part of it, using mouseover or F2 key on any Java native class and method names. For this, you have to first download and install java documentation (if not already installed) and specify its location in the Eclipse properties:
http://ubuntuforums.org/showthread.php?t=476280

Monday, June 9, 2008

Clock Speed-Up After Kernel Update

My Kubuntu desktop suddenly got a clock speed-up after I upgraded my Kernel to 2.6.24-19 -- the mouse pointer blinked twice as fast and video and audio started playing with 2x speed by default! I found out that it is probably because I am running a 32bit system on AMD64 dual core. I then found a nice hack on the grub entries to correct the speed-up:
http://ubuntuforums.org/showthread.php?t=75281
I used the "noapic acpi=off" option and now things are fine.

Friday, March 14, 2008

Installing sun java 6 and setting up eclipse in Ubuntu

I found out this nice guide:
http://ubuntuforums.org/showthread.php?t=201378

Ant/Eclipse Problem in Kubuntu/Ubuntu

After I have started using Sun Java 6 (java-1.5.0-sun), I encountered a problem with using ant in Eclipse (I didn't try from the command line) - eclipse started complaining about the package org.apache.tools. After some digging in the web, I found out that it is a bug in Ubuntu:
https://bugs.launchpad.net/ubuntu/+source/eclipse/+bug/134537

I used the solution provided by the user Mikael Nilsson and I got it working.

Sunday, February 24, 2008

SSH through SSH tunnel

I had a problem of having the ports on my lab machine blocked to external connections by a firewall. In other words, I couldn't connect to my lab machine's ssh server from home. But I had ssh access to the firewall. So I created a ssh tunnel to my lab machine as follows:

$ ssh -fN -L 9500:my.lab.machine:22 myfirewalllogin@the.firewall.machine
This will create a ssh tunnel in the background through the firewall machine and maps my lab machine's ssh port (22) to my localhost's port 9500 (can be any higher ports).

Now I can create the ssh connection to my lab machine as if it is in my local host:
$ ssh -p 9500 mylablogin@localhost

If you want to do scp files you can do similar but with -P (capital P) instead -p.
$ scp -P 9500 mylablogin@localhost:labfiles localdir

Anybody can figure it out my carefully reading the ssh man page ;-) and this approach works for accessing any remote, behind-the-firewall applications (mail server, rsync, etc.)