January 28, 2008

My Bose Story

"After this there's no turning back!" This is not only true with taking the red pill. It's also the case with getting used to comfort. I bought Bose in-ear headphones a few months back. As many reviewers have warned, the tips of the earphones fall out easily. I lost mine twice and luckily found them back. When my friend borrowed my earphones he didn't pay enough attention to the tips so it got lost. (In my opinion, any device that needs special care/attention is badly designed.) I play music almost all the time when I drive. Today I went to Bose store to buy the tips and I was listening to music on the way using my old Panasonic earphones . I couldn't believe myself when my ears started paining within 30 minutes of listening. I'm glad that I bought the slightly overpriced Bose earphones, as they are doing good to my ears. If you are a heavy earphone user, consider getting something really good. I bet it's worth the money.

January 16, 2008

More Linux fun: screen brightness

I like to use a GNU/Linux machine than a Windows machine for at least two reasons:
  • GNU/Linux user environment (especially KDE) is customizable.
  • You get to see how things are implemented, which is kinda fun.
What’s the pain point in using a GNU/Linux machine? Upgrades are scary. New version of the OS may not support your hardware. It takes a while for Linux machines to support new hardware.

In this post, I will tell you how an OS upgrade broke a functionality on my machine and how I fixed it (which was a fun experience).

Update 1: zerosk8 says in a comment that the command xbacklight can be used to control screen brightness from the command line.  On Ubuntu machines, run sudo apt-get install xbacklight to install the command on your machine.  Thank you zerosk8!  (Near the end of this post I am discussing how I set up keyboard shortcuts for adjusting brightness.  This part might be useful even if you use xbacklight command.)

Update 2: The technique described in this post worked on my Lenovo laptop (with an ATI graphics card).  It didn’t, however, work on my Samsung N150 laptop (which has an Intel graphics card).  Check this blog post of mine to see what works on the Samsung machine.

Original post:
My upgrade to Kubuntu Gutsy broke the functionality of Fn+Home and Fn+End keys on my ThinkPad. (If you use Sony Vaio, look at Daniel’s comment. Thanks Daniel for the information!) These keys are used to control the brightness of the LCD screen. When I was Googling around to find a solution, I learned that the LCD screen driver provides a file system-like interface for controlling it. The file /sys/class/backlight/acpi_video0/brightness acts as the interface for adjusting screen brightness. So I wrote the following shell script to adjust screen brightness:
# Adjust LCD brightness of ThinkPad laptops.


usage() {
  echo >&2 Usage: lcd-brightness [value]

case $# in
  cat $CTRL_FILE
  echo $1 >$CTRL_FILE
The code feels right when looking at it. Let’s try it out.
$ ./lcd-brightness
$ ./lcd-brightness 70
./lcd-brightness: line 16: /sys/class/backlight/acpi_video0/brightness: Permission denied
$ sudo ./lcd-brightness  # sudo runs the command as root.
$ sudo ./lcd-brightness 70  # This worked -- screen brightness changed.
So this problem looks like a permission issue. Just to make sure:
$ ls -l /sys/class/backlight/acpi_video0/brightness
-rw-r--r-- 1 root root 4.0K Jan 17 16:47 /sys/class/backlight/acpi_video0/brightness
So only root can change the screen brightness. But I don’t want to sudo all the time to adjust screen brightness. I said to myself, “I know how to handle this.” And I installed my script like this:
$ sudo cp ./lcd-brightness /usr/local/bin/
$ sudo chmod 755 /usr/local/bin/lcd-brightness
$ sudo chmod +s /usr/local/bin/lcd-brightness
$ ls -l /usr/local/bin/lcd-brightness
-rwsr-sr-x 1 root root 7.3K Jan 17 08:21 /usr/local/bin/lcd-brightness
Time to test this newly installed script.
$ type lcd-brightness
lcd-brightness is /usr/local/bin/lcd-brightness
$ lcd-brightness
$ lcd-brightness 80
/usr/local/bin/lcd-brightness: line 16: /sys/class/backlight/acpi_video0/brightness: Permission denied
# Huh?  Let’s try again as root?
$ sudo lcd-brightness 80   # This changes the brightness
Looks like setuid bit is not working as I expected. Some more Googling around gave me the answer. Wikipedia article on setuid says: “Due to the increased likelihood of security flaws, many operating systems ignore the setuid attribute when applied to executable shell scripts.“ That explains everything. So my next option is to write it as a C program. I translated this shell script into C as follows:
 * Change/query the brightness of LCD screen.

#include <stdio.h>

void usage()
  fprintf(stderr, "Usage: lcd-brightness [value]\n");

int main(int argc, char *argv[])
  FILE *fp;
  int bright = 0;
  const char *kFileName =

  switch (argc) {
    case 1:
      fp = fopen(kFileName, "r");
      fscanf(fp, "%d", &bright);
      printf("%d\n", bright);
    case 2:
      fp = fopen(kFileName, "w");
      bright = atoi(argv[1]);
      fprintf(fp, "%d\n", bright);
      return -1;

  return 0;
Compiling this file and installing the binary like earlier does the job. Cool :-)

In case you didn’t know exactly how to install this program, or too lazy to type commands, use these commands:
$ gcc lcd-brightness.c
$ sudo cp ./a.out /usr/local/bin/lcd-brightness
$ sudo chmod +s /usr/local/bin/lcd-brightness
$ ls -l /usr/local/bin/lcd-brightness
-rwsr-sr-x 1 root root 7.3K Jun  7 21:47 /usr/local/bin/lcd-brightness
But this is not the end of story. Later I found a usability problem with this program. I use this program only when I want to either increase or decrease the screen brightness. That is a two-step process — first I have to run the program and find the screen brightness. Then run it again with appropriate brightness argument. This is not an optimal way to use a program like this. So I decided to write two more shell scripts on top of lcd-brightness command. Here are those scripts:
$ cat increase-lcd-brightness
# Increase LCD brightness by 10.
# Assumes that lcd-brightness command is on $PATH.
lcd-brightness $(expr $(lcd-brightness) + 10)
$ cat decrease-lcd-brightness
# Decrease LCD brightness by 10.
# Assumes that lcd-brightness command is on $PATH.
lcd-brightness $(expr $(lcd-brightness) - 10)
The scripts are very simple, aren’t they? But there’s still another usability issue: I have to switch to a terminal to invoke these commands, which might be a distraction when I am coding or reading some document. Correct approach would be to use shortcut keys for this. So I went ahead and defined two new global shortcut keys on my machine. On KDE it’s done from Control Center. I opened the corresponding applet by selecting K Menu > System Settings > Accessibility > Input Actions. Added a new action called “Increase LCD Brightness” with type as “Keyboard Shortcut -> Command/URL (simple)”.
Chose the keyboard shortcut Ctrl+Alt+=.
For command, I gave the path to increase-lcd-brightness script.
Likewise, I assigned Ctrl+Alt+- to decrease-lcd-brightness script. And that’s about it. Now I can use shortcut keys for adjusting screen brightness. Now you understand when I say “Linux is customizable,” don’t you? ;-)

January 15, 2008

Oh civilisation!

  • I am not trying to that say something is right or wrong. I am not trying to propose a solution. I am just trying to analyse the reason behind eve teasing.
  • This is just a hypothesis I am putting forth. I haven't done any research to verify this.
This is a response to CoNfUsEd's this post. You may want to read that first. Why do men do eve teasing? Because their sex life is not as good as they want it to be. (A man could be sleeping with several women and yet remain "perverted". What he actually wants in his sex life is only up to him. He might still be unsatisfied and looking for more 'different' ways to get sexual pleasure. After all, sex is more and more related to mind than body.) OK. Why some (or most) men are not happy with their sex life? Because they are not allowed to do whatever they want. Because they are not allowed to do sex experiments. Especially in India, people believe that extramarital sex is a Bad Thing and tie it to the so-called Indian culture (IMNSHO this so-called culture is a BS). In addition to that, they are encouraged to repress all their emotions and act like Good Men. How long can someone keep repressing something? Why do we repress our sexual desires? Because that's a part of our so-called civilisation. Civilisation has done several Good Things to us, the society. Like everything else, it brings its own Bad Things. This is just a side effect of the way our society works. Unless we change something very fundamental to our society (e.g. throw the idea of marriages into trash) men will continue to harass women; women will keep saying "WTF?" whenever they face such harassments; people like me who think they have the solution for everything under the sun would keep proposing not-so-practical ideas. Welcome to Civilised World!-)

January 12, 2008

Another nice trick on my Unix machine

My computer had a problem. I could only mount the root and tmp partitions as read-only. But I had to copy the output of a command from my computer to another computer. I would usually run the command with the output redirected to a temporary file. Then I will scp that temporary file to whatever machine the file has to be transfered to. Since the hard disk was mounted as read-only, I could not create a temporary file with the command's output. So, I ran the command (dpkg --get-selections) as follows:
dkpg --get-selections | ssh server 'cat >~/package.txt'
This saved the output of dpkg command on the machine server. Cool, no? :) PS: I am writing this down here because I don't want to forget this and reinvent the same trick again. When I need it sometime later, I can just a do a Google Search and find this :-)

January 08, 2008

Got DataOne

The white box on the left-hand side is my wireless router. The black one on the right-hand side is my ADSL modem. So well, what are they doing at my home? I just got a new BSNL DataOne connection, and these devices help me now update my blog with this news :) I am happy that finally I have got a "good" Internet connection. I am sad at the same time that I cannot continue to support MSify any more. My Sify account is active for at least two more months. If I get any bug report or feature request within this time-frame, I will sure work on it. I won't even mind keeping my Sify connection to support MSify if there are users who want me to maintain it. So if you are a user, please let me know if you want me to keep supporting MSify. If you use Sify Broadband but not MSify, I encourage you to try it out and let me know your comments.

January 04, 2008

Blogger Annoyances

A few minor annoyances with Blogger (aka BlogSpot).
  • Preview: Blog preview is really bad. Unless your blog's background colour is white (or some bright colour), you have no clue how different colours of text actually look on the page. It would be nice if Blogger uses the blog's template to show the preview.
  • Default country: Can you guess how many Blogger users are there in Afghanistan? Blogger says there are 221,000 Afghan users. By default Blogger sets your country to Afghanistan, and many people don't bother to change it or somehow ignore it.
  • Private profiles: I know Blogger does it for privacy concerns of people. But I hate when I see a page like this:

January 01, 2008

Black background for text?

I know how much you love that black background of your blog. I accept, that background colour makes your blog look cool. But you know what? It's very hard to read white text on a black background. Especially when the text is in 8 point sans-serif font. If you wish to do me (and all the people like me who are almost always on computers) a favour, please:
  • Don't use black as the background colour (some dark shade of gray is ok I guess). Switching between other apps that use white as background colour and your blog is a very bad exercise for the eyes.
  • Don't use colours for emphasize -- use bold, italics etc. (Reason: when the post is read from an RSS reader like Google Reader, all we can see is yellow (or that other bright colour you used for highlighting) text on a white background. Obviously, yellow text on white background is not readable.)
  • Don't assume your blog is readable in its current design. Different devices/computers render things differently. Shown below is a typical BlogSpot blog on my GNU/Linux machine. I think it looks much better on a Windows machine.
  • Don't assume everyone can read it if you are able to read it. There are people with all kinds of inabilities. You never know how your readers feel. (I asked my optician, "I can read all the letters that you showed while testing. But I can't read text from that poster out there. Maybe I should try a different lens?" He answered me with a smile, "Human eyes cannot easily read white text on a black background. This is normal, you're fine with this lens.") Just think about it -- almost ALL the software that you use has dark text on a light background. This cannot be a coincidence.
Have a wonderful 2008 you all! PS: I am not complaining here. I am just requesting people to make their blogs/web sites a bit more easier on my eyes.