Tuesday, January 27, 2009

Firefox Nepali Dictionary now public

Firefox Nepali Dictionary Plugin has been approved for public status. The plugin is now also listed at Dictionary and Languages page at Firefox Addon site.

For more on the plugin, see this blog post.

Tuesday, January 13, 2009

Using wget and dd to download file segment

Prasanna's this tweet caught my attention:

what would be sweet is if I could download segments from a file using wget ... any ideas?

Well, dd can help.

Suppose we need to extract 889th byte to 1298th byte of GPLv2 document, located at

1. Create a file (gpl_partial.txt) containing 888 bytes (i.e., the portion to skip)

dd if=/dev/zero of=gpl_partial.txt bs=1 count=888
2. Download the rest of the file and save it to gpl_partial.txt. (Assuming the server supports Range header)

wget -c -O gpl_partial.txt
wget interactively shows the download byte count. You can stop the download (Ctrl+c) after required bytes have been downloaded.

3. Now extract the required segment from gpl_partial.txt and save it to gpl_segment.txt (889th byte to 1298th byte = 410 bytes)

dd if=gpl_partial.txt of=gpl_segment.txt bs=1 skip=888 count=410

If wget is not a requirement, you can use cURL to get rid of all the hassles. To achieve the above mentioned segment,
curl -o gpl_segment.txt -r 888-1297
Or, if you wanna do it in Python way, use httpheader Python module.

Monday, January 05, 2009

No Wifi to Master-mode

Linux recognizes my wifi card as AR242x and there's no out-of-the-box support till now.

$ lspci | grep 'Wireless'
02:00.0 Ethernet controller: Atheros Communications Inc. AR242x 802.11abg Wireless PCI Express Adapter (rev 01)
However compiling the latest snapshot from works. (Instructions here)
$ wget -c
$ tar xvf madwifi*.tar.gz
$ cd madwifi*r*

$ sudo make install
$ sudo modprobe ath_pci
$ sudo modprobe wlan_scan_sta
Cool. But the problem is no other modes except managed-mode seem to work.
$ sudo iwconfig ath1 mode ad-hoc
Error for wireless request "Set Mode" (8B06) :
SET failed on device ath1 ; Operation not permitted.
I was little curious about this as every wireless card supports at least ad-hoc mode if not managed. So I did a lil' diggin into madwifi's source code and found out that it supports all modes including master (or ap) mode too. This was quite startling to me coz i've been told that Master (or AP) mode is only for dedicated Wireless APs or expensive wireless cards.

Madwifi comes with nice wlanconfig tool.
$ wlanconfig
usage: wlanconfig athX create [nounit] wlandev wifiY
wlanmode [sta|adhoc|ap|monitor|wds|ahdemo] [uniquebssid]
usage: wlanconfig athX destroy
usage: wlanconfig athX list [active|ap|caps|chan|freq|keys|scan|sta|wme]
Now to start AP mode,
$ sudo wlanconfig ath1 destroy
$ sudo wlanconfig ath1 create wlandev wifi0 wlanmode ap
Now set the ESSID for the wireless network and IP for the interface
$ sudo ifconfig ath1
$ sudo iwconfig ath1 essid 'TestAP'
Voila! It worked and I can connect to this AP from another computer, set the IP to 192.168.0.x range and ping too. Now I'm wondering if AP mode is available in every card but is restricted by software so that ppl are forced to buy expensive APs.

Thursday, January 01, 2009

Battery charged notification

Load-shedding is driving us nuts! My solution is to move all my works to laptop and buy a spare battery. I think this is more cost effective and energy saving than buying expensive inverters. I've got an extra 8-cell battery for my laptop and altogether I have 6+ hours of backup.

But the problem is I keep forgetting to charge the batteries. The one in laptop starts charging when light is back but when it's done charging I forget to switch battery.

The solution lies at /proc/acpi/battery/BAT1/state

$ cat /proc/acpi/battery/BAT1/state
present: yes
capacity state: ok
charging state: discharging
present rate: 1342 mA
remaining capacity: 2201 mAh
present voltage: 11432 mV
Our line of concern is 'charging state:' which can have one of three values - charging, discharging or charged. So here's a simple bash script to monitor this file for charged state and pop a message to switch the battery.


while : ; do
if grep -iq 'charged' /proc/acpi/battery/BAT1/state
# nofify if previous state is uncharged
if [ $charged = 0 ] ; then
zenity --info --text "Battery charged. You might wanna charge another."
sleep 5m # wait for 5 minutes
Now put this program to System > Preferences > Sessions > Startup Programs.