Google
 

Saturday, March 19, 2011

Nepal Map API

District-level Nepal Map PHP API. Generates variable-sized map of Nepal with user defined colors for districts.

Source and example:
https://github.com/jwalanta/NepalMapAPI

Demo (with maphilight jQuery plugin):
http://diyaalo.com/nepalmapapi/

Thanx a lot to Jitendra for providing the GIS map of Nepal.

Tuesday, February 08, 2011

Javascript Deselect on Focus

Here's the scenario: you've got two text input, userid and email address. For email address field, I want to have the domain part pre-filled (say, @example.com). Now when the user enters the userid and jumps to email input, the browser selects the whole text as default behavior. But I want to append userid to the beginning and select only the userid part. Using jQuery, the usual code would be like this:

However, THIS DOESN'T WORK!!






To make this to work, you need to set the selectionStart and selectionEnd values after a while the inputbox is focused.


Thursday, February 03, 2011

Fixing resolution for bigger external monitor

If you happen to connect our Linux laptop or netbook to an external monitor, you're likely to get into resolution trouble. For smaller resolutions (<=1024x768), it's not a bigger deal but once you try higher and unusual resolutions, like 1440x900, things don't turn out that well. Here's how to switch to such resolutions under (Ubuntu) Linux. I'm connecting my laptop (Intel 845GM chipset) to an external monitor (1440x900 native).

Fire up terminal and run the following command; first calculate VESA CVT mode lines

$ cvt 1440 900
Output:
# 1440x900 59.89 Hz (CVT 1.30MA) hsync: 55.93 kHz; pclk: 106.50 MHz
Modeline "1440x900_60.00" 106.50 1440 1528 1672 1904 900 903 909 934 -hsync +vsync

Now, lets see my card's supported resolutions out of the box.
$ xrandr
Output:
Screen 0: minimum 320 x 200, current 1280 x 800, maximum 4096 x 4096
VGA1 connected (normal left inverted right x axis y axis)
1360x768 59.8
1024x768 60.0
800x600 60.3 56.2
848x480 60.0
640x480 59.9 59.9
1440x900_60.00 59.6
LVDS1 connected 1280x800+0+0 (normal left inverted right x axis y axis) 331mm x 207mm
1280x800 59.9*+
1024x768 60.0
800x600 60.3
640x480 59.9
TV1 disconnected (normal left inverted right x axis y axis)

In the above output, VGA1 is the external monitor and LVDS1 is the laptop's LCD panel. Now use the modeline information to create a new custom resolution and add it to VGA1
$ xrandr --newmode "1440x900"  106.50  1440 1528 1672 1904  900 903 909 934 -hsync +vsync
$ xrandr --addmode VGA1 1440x900
The changes are temporary though. If you want it to make it permanent, add them to ~/.xprofile

Now go to System > Preferences > Monitors. The external monitor's list of resolutions should show 1440x900.

Some more info:
Connecting to external monitor has two options, mirror or extend. Choosing mirror gives the same output to both monitors. Extend, well, extends the display over both monitors. But it has a catch: for Compiz to extend over external monitor, the maximum possible horizontal resolution (see first line of xrandr output above, in my case 4096) should be at least double of sum of total horizontal resolution of two monitors.

In my case, if I try to extend my 1280x800 to an 1440x900 external monitor, its not gonna work as 2*(1280+1440)=5440 > 4096. So mirroring is the only option. However if you set the resolution while compiz is on, it's gonna be "confused". Here's the workaround:

1. Add the custom resolution as described above
2. Disable Compiz (System > Preference > Appearance > Visual Effects > None)
3. Change Resolution, and set the laptop's output to off
4. Enable Compiz again

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, 192.168.0.254) 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 0.0.0.0 up
# ifconfig eth2 0.0.0.0 up
Assign the LTSP IP address to bridge.
# ifconfig br0 192.168.0.254 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.
Source: https://github.com/jwalanta/tit


Features

- 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

Demo
http://diyaalo.com/tit
username, password = demo, demo123
Check email notifications at http://demo123.mailinator.com/

PS: The acronym is a complete coincidence though :P