16 Aug 2007

Sify Broadband Client for Linux

I wrote about my home-grown Sify Broadband client some time ago. As with any program it needed some tweaks. Now it's pretty much stable. This is how now I connect to the Internet.
  • Configuring the network: My laptop has to use a DHCP-based network in my office. Sify requires that I use a static IP address. I have added a virtual network interface to the computer by adding these lines to my /etc/network/interfaces file:
    iface sify inet static
    address 10.15.66.107
    netmask 255.255.255.0
    gateway 10.15.66.1
    dns-nameservers 202.144.10.50 202.144.13.50
    When I am at home, I activate this network settings on eth0 by running: $ sudo ifdown eth0 $ sudo ifup eth0=sify
  • Signing into Sify network: $ sify.py i
  • Signing out of Sify: $ sify.py o
Requirements For this script to work, you must have the following installed:
  • Python 2.4
  • BeautifulSoup (Python XML parser library)
Download and Install ** Update: This project is now hosted on Google Code. See http://code.google.com/p/msify/wiki/GettingStarted for more information and to download the latest version. ** Download the zip archive at http://www.megaupload.com/?d=QR5TC7DK. Extract the contents of the archive into a local directory in your computer. Edit the .sify file and specify your username, password, IP address etc. Then run sify.py to login or logout. Fine Print
  • I developed and tested this on a Kubuntu Dapper machine. It works fine for my usage; but I cannot guarantee that this will work for you. I don't provide any warranty of any sort.
  • This script is released under GPL V2. Feel free to change and/or redistribute.

13 Aug 2007

Don't attach those Windoze Media format files, puhlease...

<rant> It's been more than two and a half years since YouTube was launched. It's the most famous video sharing service on the Internet today. I know a lot of people know about it. But the problem is they don't use it. Very often I get emails with a zip files attached to it. The zip file contains one single WMV file. Instead of taking all the pain to zip a WMV file (which results in almost no file size difference; but a hell lot of annoyance), if at all they upload it to YouTube or some other fancy video sharing program they like, it would be a pleasant experience for us to watch it. </rant>

15 Jul 2007

Thanks Chinmayi

You wake up in the morning and switch on your computer. You find that there are 95 scraps in your Orkut profile. Many of them are from strangers whom you have never seen and quite possibly won't ever see in your life. How would you respond to those scraps? To be honest, I would just delete my Orkut profile and get away from there. But Chinmayi, the singer, responds to most of scraps (or maybe all of them?). Yesterday I just found her profile in Orkut, and I couldn't resist my want to say a "Hi" to her. I don't know anything about music; I just listen to songs as a not-so-serious hobby. I like Chinmayi because of her voice. After reading her blog and seeing her on Vijay TV, I really started liking her personality. I could even say that I am a fan of her. When I wrote a scrap on her Orkut scrapbook I didn't expect her to respond to my scrap. I know she is very busy. If my assumption is right, Carnatic music practitioners like her do practice daily for at least a couple hours. All the weekends she has concerts. As she is working in the movie industry, most definitely she will have to meet with many important people. Surprisingly, I got a response from her! I was really happy to see her scrap on my scrapbook. When I searched for my scrap in her scrapbook I got the next surprise: 95 new scraps have been written on her scrapbook in one single day! And, she is taking time to respond to my scrap. Most definitely she doesn't know me, I am not ever going to meet her at all in my life. But still she takes the time to acknowledge my message. She has about three blogs and a web site. In addition to these many scraps, she would get comments for her blogs, feedback for her web site, and emails sent directly to her mailbox. All I could think of is that she is a good woman. I want to thank her for the respect she has shown to my message. But this time I just say it here, in my blog -- because I don't want to spam her again. Thanks Chinmayi!

4 Jul 2007

Code Duplication

You might have heard people talking about not duplicating code so that it becomes easy to maintain. Back those days, I didn't know all these and used to make a hell lot of mistakes while programming. By the word mistake, I mean doing something that makes developing and maintaining software harder than it ought to be. Of course, that helped me learn a lot of principles. The first thing I learned from my mistakes is not to duplicate code/ideas. Since I was bit by duplicated code very often, I try my best to reduce duplication as much as possible. In this post I am giving a few examples to show how I try to avoid duplication. Obvious Duplication The first pattern I recognised in my code was something like the following.
if exam.mark >= 35:
    exam.result = 'pass'
    logging.debug('Setting result to pass.')
    return 'pass'
else:
    exam.result = 'fail'
    logging.debug('Setting result to fail.')
    return 'fail'
Obviously this code is duplicating ideas, so must be refactored. How will you refactor this to take away the duplication? I will write it this way:
if exam.mark >= 35:
    exam.result = 'pass'
else:
    exam.result = 'fail'
logging.debug('Setting result to ' + exam.result)
return exam.result
(To be more precise, I will also replace the literals 35, 'pass', and 'fail' with appropriately named constant variables.) More Subtle Cases This is (part of) a PyUnit test case for an imaginary function double, that takes a number and multiplies it by 2.
def testDouble(self):
    inp = 5
    expected = inp * 2
    actual = double(inp)
    self.assertEqual(expected, actual)
Here, I have used the variable inp to avoid having to duplicate the test input I am passing to double. As another example, see this code that assigns a grade to a student based on the mark they have scored.
if mark < 35:
    grade = 'N/A'
elif mark >= 35 and mark < 50:
    grade = 'D'
elif mark >= 50 and mark < 70:
    grade = 'C'
elif mark >= 70 and mark < 90:
    grade = 'B'
else:
    grade = 'A'
I would rewrite this code like this to avoid duplication of the boundary values (although this is a very small duplication).
if mark < 35:
    grade = 'N/A'
elif mark < 50:
    grade = 'D'
elif mark < 70:
    grade = 'C'
elif mark < 90:
    grade = 'B'
else:
    grade = 'A'
Tell me about the ways you follow to make your code more maintainable.

1 Jul 2007

Web Development 101

They say a picture is worth 1000 words. So a video should worth more than a picture. Definitely a hands on experience is worth much more than a video. All you starting web developers: here is your most important lesson. I'll tell you what I did to learn this lesson. If you follow what I did, hopefully you will also learn :-) Steps to follow:
  1. Think of a very good Tamil song that you don't have right now, but would love to add it to your music collection.
  2. Google for it and most likely you will get a link for that song in Raaga.com. (If not pick another song; in this particular exercise, we are gonna learn from Raaga.com.)
  3. Click on the link in Google results and if you are lucky, you can listen to the song in their site. If you run any non-Windoze OS you're doomed.
  4. Then you decide: alright, I really like this song and I'm gonna download. Click on "Download" button. You will be politely informed (with a JavaScript alert) that you got to log in if you want to download.
  5. So, you click on Register link. And you know the rest: I am too lazy to type all that now.
  6. You will have to activate your account, this, that, and all other bullshit.
  7. After you have downloaded that song, sit back and think "do I want my site to be as brain-damaged as Raaga.com?"
If you are really unfortunate (like me) you will end up visiting their site often and curse them every time. See my shopping cart now: I have no idea how item 2 and 3 differ. Worse, I cannot find that out at all. That's all for now. Now you're free to dream about your cool web site.