Saturday, December 25, 2010

Load Balancing LTSP clients using Ethernet Bridging

Typical LTSP setup has the following configuration:

| Server |
| eth0 | eth1 |
/ |
/ |
Internet Switch
| | |
Client-1 Client-2 ... Client-n

LTSP Clients

The problem with this is that the network card bottlenecks the performance. Once the number of clients increases (usually >5), even though the server is capable of handling the load, the network card (usually, 100BASE-TX) can't provide the throughput.

There are two solutions to this:
1. Use 1000BASE-T (gigabit) ethernet cards and switches
2. Use load balancing

Using gigabit ethernet cards solves the problem but they are expensive. The switches are expensive too. Plus there are flow control problems if the clients have 100Base-TX cards, which is usually the case.

Load balancing is an easier and cheaper approach. Although this can also go fairly complicated, here i'm going for the simplest one using ethernet bridging.

The trick is to use multiple NICs connected to multiple switches. Then bridge the cards to provide a common interface. Here's what it looks like:

| Server |
+------------------- +
| eth0 | eth1 = eth2 |
/ | |
/ | |
Internet Switch Switch
| |
+----+-------+ +----+-------+
| | | | | |
C-1 C-2 ... C-n C-1 C-2 ... C-n

LTSP Clients LTSP Clients

Lets say, there are three NICs: eth0, eth1 and eth2. eth0 is connected to internet. eth1 (say, is connected to LTSP clients. eth2 is unused and is supposed to be bridged with eth1.

First install bridge-utils
# apt-get install bridge-utils
Create a bridge (br0) and add eth1 and eth2 to it
# brctl addbr br0
# brctl stp br0 off
# brctl addif br0 eth1
# brctl addif br0 eth2
Now release the IP addresses of eth1 and eth2
# ifconfig eth1 down
# ifconfig eth2 down
# ifconfig eth1 up
# ifconfig eth2 up
Assign the LTSP IP address to bridge.
# ifconfig br0 up
Now connect eth1 and eth2 to separate switches, and each switch to (equal number of) LTSP clients.

Tuesday, December 21, 2010

Tiny Issue Tracker

I find most issue trackers bloated for most of my requirements. I usually need a simple issue tracker to communicate between couple of persons but most issue trackers available have plethora of features, usually with full blown database.

So here's my solution: Tiny Issue Tracker. A PHP/SQLite based, single-file issue tracker.


- Super Lightweight (currently ~17KB, ~500 lines of code)
- Multi-user
- Email Notifications
- Auto DB creation on first run
- Issue Priority (High, Medium, Low)
- Comment on issues
- Throw and run!

Installation is as simple as it can get:
- Modify configurations in the file (tit.php)
- Upload to webserver (rename if necessary) & load from browser

username, password = demo, demo123
Check email notifications at

PS: The acronym is a complete coincidence though :P

Tuesday, December 14, 2010

HackJatra v0.1

Jitendra started the discussion, but i wouldn't be wrong if i say we all had the itch. A hackathon was in everybody's mind since quite a while. So we started a email discussion among fellow hackers, mostly Pulchowk Campus BCT'ians. We had few projects in mind - ATM Locator, Khanchuwa and Online Nepali Donation system. All we needed was a date for the event. But before we could finalize that, we coined a term for the event.

HackJatra. For non-Nepalis out there, Jatra means festivity. Later the term was also informally understood as "Hack by day, Jatra by night" :P. More on that later..

Finally, we fixed the date and venue: 11th December, 2010 at IT Park Banepa, starting from 9am.

The project we did were:

1. ATM Locator
Map enabled app to list and search ATMs in Nepal.
Team: Abhinav Singh, Bibek Shrestha, Jitendra Harlalka, Subodh Satyal, Sushil Shilpakar

2. Khanchuwa
Community based delicacies listing portal. The idea was discussed at BarCamp Kathmandu 2010.
Team: Jwalanta Shrestha, Abhishek Singh

3. Tweet NEA
Automated twitter accounts to tweet the loadshedding schedule.
Team: Manish Modi, Suraj Sapkota

More on the projects in the wiki.

Needless to say, the event was extremely fun. The joy of hacking for fun with extremely talented fellow hackers is indescribable. The projects we started are almost done; few more hours of collaborations and they'll all be ready to launch.

Future plans:
1. Do some branding of HackJatra; create a logo, have a website and make the projects more accessible and sharable.
2. Encourage other teams to do similar HackJatras
3. Do another HackJatra ASAP

O BTW, we even had booze party by night (Jatra :P)

Friday, November 12, 2010

Generating Tag Cloud the Unix way

UPDATE: I've modified the script to add color and transparency :)

Ushaft's this tweet on creating tag cloud caught my attention. While there are better tools available online, i decided to give it a try in Linux :)

First we need to generate a frequency list of words out of a file. No brainer. I used the GNU/GPL license as source text.

cat /usr/share/common-licenses/GPL |
tr 'A-Z' 'a-z' |
sed 's/[^a-z ]//g' |
sed 's/\s/\n/g' |
awk '{if (length($1)>=3) print $1 }' |
sort | uniq -c | sort -nr > freq.txt

Explanation (per line):
1. Print the license
2. Convert to lowercase
3. Remove punctuations
4. One word per line
5. Discard words with 2 or less long
6. Grab frequency and write to freq.txt

freq.txt needs some editing to remove irrelevant words like "the", "but", etc.

Now to create tag cloud, i wrote a simple awk script that outputs svg file. Saved this as gentagcloud.awk (Please change the width, height and scale variable to your taste)

#!/bin/awk -f



print "<?xml version=\"1.0\"
encoding=\"UTF-8\" standalone=\"no\"?>"
print "<svg width=\"",WIDTH,"\" height=\"",
HEIGHT,"\" version=\"1.1\"

R = int(rand()*9)
G = int(rand()*9)
B = int(rand()*9)

print "<text style=\"fill:#",R,G,B,";opacity:0.75;

END{ print "</svg>" }

Now to create tag cloud,

awk -f gentagcloud.awk < freq.txt > tagcloud.svg

Tada! Tag cloud generated, view tagcloud.svg in your browser or image viewer

If you have ImageMagick installed, you can convert it directly to png too. (Transparency isnt handled properly. If you have workarounds, please comment)

awk -f gentagcloud.awk < freq.txt | convert - tagcloud.png

BTW, the tag cloud was like this: (lil' ugly, but WTH :))

Thursday, February 25, 2010

Internet Connection Sharing in Linux over Ad-hoc Wireless

Laptops are common these days and so is wireless networking that comes with it. Almost all of us use Wireless Router for wireless networking and internet sharing. But most of us might not be familiar with ad-hoc mode that works in every wireless card and can eliminate the use of router altogether. Here's how:

To setup ad-hoc wireless, you basically set two or more wireless cards to same ESSID in ad-hoc mode and different IP addresses.

Setting the wireless card in ad-hoc mode

Generally iwconfig is used to set the wireless mode, but if you have madwifi drivers (see this too), the commands are slightly different. Go to terminal and type,

If you see interfaces named wlan0, wlan1, etc iwconfig will work. If you see interface names similar to ath1 and wifi0, then madwifi specific commands are to be used.

For general wifi cards:
sudo iwconfig wlan0 mode ad-hoc
Replace wlan0 with the interface name as listed by iwconfig

For cards using madwifi driver:
sudo wlanconfig ath1 destroy
sudo wlanconfig ath1 create wlandev wifi0 wlanmode adhoc
Now set essid. Pick some name like 'adhocwifi'
sudo iwconfig wlan0 essid adhocwifi
If required, to set encryption key
sudo iwconfig wlan0 key 1234567890
Now set IP address:
sudo ifconfig wlan0
Follow the above steps for another wireless card and set IP address in same subnet, say, and ping each other.

The whole ad-hoc mode setting can also be done using GUI network-manager, but since i'm not so much fond of graphical interface i'm not covering it. It should be simple.. :)

Internet Connection Sharing

Now to share the internet over wireless,
sudo iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
where ppp0 is the connection you want to share (PPPoE connection in this case)

You also need to enable IP forwarding:
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
Or, to enable permanently add the following line to /etc/sysctl.conf
Some ISPs might limit the TTL so that you wont be able to share the internet. Fix:
sudo iptables -t mangle -A PREROUTING -j TTL --ttl-inc 1

Using the shared internet (in Linux)

Now to use the shared internet on another computer, set it to ad-hoc mode and assign IP address in the same subnet as described above and perform the following:

1. Set the IP of computer sharing internet as gateway
sudo route add default gw
2. Set DNS server. We're using Google's DNS.
sudo sh -c "echo 'nameserver' >> /etc/resolv.conf"
You can also use IP and DNS Masquerading to ease the task.

Using the shared internet (in M$ Windows)

If you want to use the shared internet on M$ Windows,

1. Connect to the Wireless Network (in this case 'adhocwifi')
2. Go to Network Connections
3. Right click the Wireless Connection
4. Select the Internet Protocol (TCP/IP) and click Properties
5. Set IP to (or accordingly in the same subnet as set on Linux box), gateway to (as set on Linux box) and DNS to

Friday, February 19, 2010

Overriding extension compatibility check for FF3.5+

Disabling extension compatibility check for Firefox was easy. Go to about:config and create a boolean value named extensions.checkCompatibility and set it to false.

Until Firefox 3.5!
(More specifically, products that are based on < Gecko 1.9.2)

Newer Firefox requires you to append version number to the variable. This will ensure the extension override wont work forever as FF is upgraded to next version. For example, in Firefox 3.6, the variable would be extensions.checkCompatibility.3.6

Explained in detail here:

Wednesday, February 17, 2010

Converting Latex document to HTML / ODT / DOC

I do all my documents in Latex. Actually i usually use emacs org-mode first and later convert it to Latex, but when it comes to using bibtex, it's all latex. It works great and the output dvi/pdf files look so professional. However recently i had to submit the file in .doc format, and i had a real hard time finding good tools to do that.

There are no direct Latex to .doc converters, so the best bet is to go Latex -> HTML -> DOC. There are lots of Latex to HTML converters like latex2html, tth and hevea, but most of them either don't produce good HTML or mess with bibliography references. But after some research i found the best: TeX4ht

TeX4ht is available in ubuntu/debian repo, so to install

sudo apt-get install tex4ht
Conversion is simple:
htlatex document
(please note, there is no .tex suffix)

This will generate document.html, css and bunch of .png files.

Now to convert it to wordprocessor files (odt, doc..),
1. Open the html file with
2. File > Save as
3. Choose the format you want to save it in (odt, doc)

If you have images in the document, they will be linked instead of embedded in the document. To fix this: (source)
1. Edit > Links
2. Click "Break Link" for each image link

Thursday, February 04, 2010

mpg123: Lightest mp3 player in Linux

If you are in search of the lightest barebone mp3 player in Linux, nothing can beat mpg123. Unless you want flashy visualizations and playlist management and such, mpg123 can save you a lot of memory and cpu horsepower.

Installation is easy. In Ubuntu,

sudo apt-get install mpg123

Mpg123 comes with loads of options. Check out the man page for details. Here I'm gonna share a few usage tips.

Shuffle-play a directory of mp3s:
mpg123 -CZ /path/to/mp3/folder/*

-Z option is for shuffle, -C is for control. From man page:
-C, --control
Enable terminal control keys. By default use ’s’ to
stop, ’p’ to pause, ’f’ to jump forward to the next
song, ’b’ to jump back to the beginning of the song,
’,’ to rewind, ’.’ to fast forward, and ’q’ to quit.
Type ’h’ for a full list of available controls.


Don't fall off your chair! Yes, mpg123 also comes with 32-band equalizer. But there's no inbuilt graphical UI for that, you need to create the plain-text file. There's an editor though if you like, but creating one is not hard either. From man page:
-E file, --equalizer
Enables equalization, taken from file. The file needs to
contain 32 lines of data, additional comment lines may be
prefixed with #. Each data line consists of two floating-
point entries, separated by whitespace. They specify the
multipliers for left and right channel of a certain
frequency band, respectively. The first line corresponds
to the lowest, the 32nd to the highest frequency band.
Note that you can control the equalizer interactively
with the generic control interface.

I've made one with party feel: party.txt

mpg123 -CZ -E party.txt mp3_file

Songs again and again:

Plus if you kind of person who listens to couple of songs again and again for weeks (instead of shuffled huge playlist), then hi5! :) and here's how to do that with mpg123:
mpg123 -CZ song1.mp3 song2.mp3

Wednesday, February 03, 2010

Making DLink DWL-650+ PCMCIA Wireless card work under linux

The DLink DWL-650+ PCMCIA Wireless card doesn't work on recent Linux distros (I tried Ubuntu Hardy to Jaunty). After plugging in, the system hangs with CapsLock flashing.

Turns out the card is handled by acx module and the support is broken for this card. So use ndiswrapper instead.

First blacklist acx module. Open /etc/modprobe.d/blacklist.conf file and add the following line

blacklist acx
Now install ndiswrapper
sudo apt-get install ndiswrapper-common
Now get the Windows driver for the card from here. Extract the file, go to the winxp folder and,
sudo ndiswrapper -i AIRPLUS.INF
The card should work now.