Google
 

Tuesday, June 14, 2011

NTC PSTN Number to Name

NTC's website has a nice feature called Telephone search. This is particularly handy when you get a call from landline (PSTN) number and have no idea who's calling. Ofcourse you can go to the site and search, but the following bash script makes it faster.

#!/bin/bash

#
# Nepal Telecom PSTN Number to Name search
#

if [ "$1" == "" ] ; then
echo "Usage: " $0 "phone_number"
exit
fi

# Prefix 01, if not provided
if [[ $1 =~ ^01 ]] ; then
NUMBER=$1
else
NUMBER="01$1"
fi

wget -q http://ntc.net.np/telsearchRes.php
--post-data "searchFor=name&telno=$NUMBER&submitted=Search" -O - | html2text | grep "$NUMBER" | tr '_' ' ' | sed 's/ [\ ]*/ /g'

Save the file, chmod it as executable.

To use,
./telsearch 5544132
| 1 |015544132|Ntc |Cellular Mobile And New S|Jawalakhel|

Saturday, May 14, 2011

Fixing overused touchpad with sticky note

If you're like me who spends more time with laptop than anything/one else, you'll end up with touchpad like this:

Due to overuse, the outer coarse layer wears off and touchpad starts acting funny. Plus it's difficult to slide your finger over it.

Fix? Stick a sticky-note over the touchpad. This surprisingly works!

Tuesday, May 10, 2011

Grub2 recordfail FAIL

I have this headless, keyboardless server running on Ubuntu 10.04. Runs fine, but once in a while while there's power cut off the server still remains dead when the power is back. I connected monitor and keyboard and found that the problem is with Grub2.

Turns out there's a variable named recordfail which is set to 1 during next boot whenever there's some problem with the computer (like due to power failure).

Now if you see /boot/grub/grub.cfg file, it has the following lines:

if [ ${recordfail} = 1 ]; then
set timeout=-1
else
set timeout=10
fi
Which means, the timeout counter is disabled whenever the recordfail variable is set. This is nice for desktop environment, which has a monitor, so I can see the Grub countdown is disabled so I can proceed with Repair option if I have to, but for headless servers the computer just sits idle at Grub screen, puzzling the poor sysadmin.

Fix? I changed the timeout=-1 to timeout=10.

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.