Archive for the ‘Howtos’ Category

While i was working on the project onspot_v2, i came across with a specific need. onspot_v2 makes use of the django admin interface for data entry. When employees are entering data, ‘branch’ field in the form will get populated automatically as per the branch of the employee. When a manager is entering data using the form, an extra field should appear to select the ‘branch’ instead of automatically populating. Googling didn’t help much. Finally i thought of overriding the ModelAdmin.add_view() method which is invoked when you try to add an entry using the admin. I changed the editable property of the field ‘branch’ inside after checking the request.user and it worked out. Part of my code in admin.py

from django.contrib import admin
from books.models import Agent, PolicyIssue

class PolicyIssueAdmin(admin.ModelAdmin):
    def add_view(self, request, form_url='', extra_context=None):
        if request.user.get_profile().is_employee:
            self.model.branch.field.editable = False
            self.model.branch.field.editable = True
        return super(PolicyIssueAdmin, self).add_view(request, form_url)

admin.site.register(PolicyIssue, PolicyIssueAdmin)

Read Full Post »

My ISP provides unlimited download from 2am to 8am. So i was not able to sleep after 2 from the time i switched to the new broadband plan. Keeping the system on and setting a cronjob to start downloading after 2 was an option. But i was more concerned about the increasing electricity charge, than my sleep. Besides it is my social responsibility to save energy as a gonna-be software engineer :p. After a bit of googling and hacking i was able to wake up my system at a particular time. Here i am going to explain how i made my arch linux system to boot automatically at 2 am.

The configuration is done in Arch Linux. For automatic wakeup it needs a BIOS which supports RTC alarm. Most of them manufactured after 2000 supports this feature.

1) Check if your BIOS supports automatic wakeup

Execute the command below as root.

# grep rtc /var/log/messages.log
rtc_cmos 00:03: RTC can wake from S4
rtc0: alarms up to one month

If you can find something like this in the output.It says that the system can wakeup and a wakeup time can be setup.

2) Enable automatic wakeup in BIOS

Go to your BIOS setup, Under Power Management search for something like “Wake by RTC Alarm” or “Resume by RTC alarm” or “RTC resume”.Then enable it.

3) Set the hardware clock time standard as UTC

Edit the /etc/rc.conf file as root and set the HARDWARECLOCK variable to UTC

[ragsagar@h4ckb0x ~]$ grep ^HARDWARECLOCK /etc/rc.conf

Make sure that your timezone is set correctly in /etc/rc.conf
More help : https://wiki.archlinux.org/index.php/Time

4) Set the alarm time

Execute the following commands as root

# echo 0 > /sys/class/rtc/rtc0/wakealarm
# echo `date '+%s' -d '+ 5 minutes'` > /sys/class/rtc/rtc0/wakealarm

This will set the the alarm time as 5 minutes into the future.

Now run

$ cat /sys/class/rtc/rtc0/wakealarm

If the output of above command is something like “1313383930”, the alarm is set. It is epoch time. If it doesn’t yield any result make sure that the HARDWARECLOCK variable is set to UTC and reboot and try again to set the alarm time.

Now run

$ cat /proc/driver/rtc

Go through rtc_time, alrm_time and alrm_date and check if they are correct(will be in UTC).Turn off the system and leave the power on. Check if the system is booting automatically after five mintues.

5) Setting the alarm to a particular time and date.

To set the alarm to woke up the system at 16th Aug 2:05am, Run the following as root

# echo 0 > /sys/class/rtc/rtc0/wakealarm
# date --date "Aug 16 , 2011 02:05:00" +%s > /sys/class/rtc/rtc0/wakealarm

You can convert the epoch time to readable format and check the alarm time is correct.

[root@h4ckb0x ragsagar]# cat /sys/class/rtc/rtc0/wakealarm
[root@h4ckb0x ragsagar]# date -d @1313440500 +%F" "%T
2011-08-16 02:05:00

Note : The mythtv wiki about acpi wakeup says that setting the hardware clock after setting alarm will disable the alarm while most of the linux distribution sets hardware clock during shutdown. They suggest to disable hardware clock adjusting during shutdown. To do that in Archlinux set the HARDWARECLOCK=”” in /etc/rc.conf . But in my arch system the alarm was not working when i set HARDWARECLOCK=”” whereas it worked when i gave HARDWARECLOCK=”UTC”. So if the wake up alarm is not working do try after changing the value of this variable.

To start downloading when the system boots up, i added a cronjob to restart the router at 2:15 and 7:45 (to account the download in happy hours). Also added “transmission-gtk” to the gnome-session-properties. So that transmission will be launched on startup and downloading will be started.

Reference :

Read Full Post »

My first post in tuxopia is a how-to for writing basic IRC bot in python.Thought of sharing the link here 🙂

Read Full Post »

Earlier we saw how to setup swanalekha in gentoo! Now lets see how to setup the same in slackware. Now its pretty easy when compared to what we have done in gentoo.As gentoo dont have any native binary package we downloaded the source from here and installed it.This time no need to install from source as i made a slackware binary package for swanalekha which makes the installation a piece of cake 😉
To install swanalekha, download the binary package from here
#wget http://ragsagar.freehostia.com/swanalekha_0.3.1_2.tgz
#installpkg swanalekha_0.3.1_2.tgz

Hey thats all. We installed swanalekha. Now start typing malayalam in your computer 🙂
For More Info on typing malayalam using swanalekha, go through this old post.
PS: Make sure that you have scim already installed in your computer.

Read Full Post »

Yesterday i installed debian lenny ( thanks to ashik salahudeen who sent me those DVDs for free 🙂 ).

I was not ready to waste another holiday.So started thinking of doing something and got landed in my usual plugin stuff.This time not audacious,its Rhythmbox.So downloaded my pidgin-audacious now playing code and rewritten it to access rhythmbox methods.This time there is a lot of changes in the code.This code is not going to use ‘watch’ command to execute it after a fixed period and another interesting feature is a format specifier kinda thing. ie Just write what you want in the status message and place a format specifier where you want to see the song title , album title and artist.
Format Specifiers are

%rbs ————–> for displaying song title
%rbt ————–> for displaying album title
%rba ————–> for displaying artist name

Script will append a seperate string containg songtitle and albumtitle if no format specifier is there in the status message at the time of running the script.

An example for appending status message using format specifier kinda thing:

%rbs in %rbt by %rba

pidgin-after-appending-formatspecifier kinda thing in status message

pidgin after appending format specifier kinda thing in status message

Now download the script and run it using these commands

$wget http://ragsagar.freehostia.com/pidgin-rb.py
$python pidgin-rb.py

Downloading and running the script

Downloading and running the script

pidgin after running the script

pidgin after running the script

PS : Run the script only after appending the format specifier kinda thing. You can run the script without appending anything, In this case the script will append status message like ” listening to [songname] in [albumname] “

Download Script

Read Full Post »

Swanalekha is a scim malayalam phonetic input method.We can type malayalam easily using swanalekha as it uses transliteration based input method!

Iam going to explain(not really :p) how i installed swanalekha in my gentoo installation!

As it is scim based, swanalekha definitely needs scim,so we have to install it frist.To install it you can use emerge command.it downloads and compiles its source and solves dependecies by itself,so need to worry about dependecy!

If you want to know the size and list of dependencies of scim that emerge downloads, use this command..

#emerge -pv scim

Install it using this command :

#emerge scim

Swanalekha needs another two packages named scim-tables and scim-m17n,they wont get installed with scim, so install them manually using this command..

#emerge scim-tables scim-m17n

Now get the source tarball from http://savannah.inetbridge.net/smc/Swanalekha/swanalekha_0.3.1_2.tar.gz

untar it and cd into it..

$tar -xvf swanalekha_0.3.1_2.tar.gz

$cd swanalekha_0.3.1_2

now run make as root


now configure scim and run


scim-setup window

scim-setup window

In the Global Setup tab under IMengine enable Malayalam.Restart scim for the changes to take effect.Now open your favourite text editor.Right click and select Scim Input Method from Input Methods.Then left click in the scim tray icon,select Malalyalam-Swanalekha from it and start typing malayalam!

malayalam typed using swanalekha in leafpad texteditor

PS: Hope you have malayalam fonts installed,otherwise get some fonts from here and copy it to ~/.fonts or /usr/share/fonts and restart x

Read Full Post »

%d bloggers like this: