Older blog entries for rkrishnan (starting at number 244)

Laptop Power Supply

Common folklore (confirmed by some Norwegian friends) is that heat is not a friend of laptop batteries. The life of a laptop battery tend to reduce in Indian weather. One of the Dell Laptops I bought in early 2008 can now work barely 30 minutes with a fully charged battery.

Linux kernel provides a wealth of information (through ACPI) about the Battery like the make, type, serial number etc. Look under /sys/class/power_supply/BAT0/. This is what I have: ~$ cat /sys/class/power_supply/BAT0/status Unknown ~$ cat /sys/class/power_supply/BAT0/technology Li-ion ~$ cat /sys/class/power_supply/BAT0/type Battery ~$ cat /sys/class/power_supply/BAT0/serial_number 32511 ~$ cat /sys/class/power_supply/BAT0/manufacturer SANYO ~$ cat /sys/class/power_supply/BAT0/model_name 42T4511 ~$ cat /sys/class/power_supply/BAT0/energy_full_design 84240000 ~$ cat /sys/class/power_supply/BAT0/energy_full 64530000 ~$ cat /sys/class/power_supply/BAT0/energy_now 63160000 It looks like, my battery (this is a work laptop, Lenovo Thinkpad T61 running Debian x86-64 unstable) is functioning at a lesser capacity than it is designed. It will be nice to corelate these readings with the actual performance of the battery. I tend to run this machine mostly with AC, but I will try profiling it for battery performance and see how much time these numbers translate to.

Syndicated 2010-03-06 08:00:00 from Ramakrishnan Muthukrishnan

git - renaming branches

I was working on a project recently, which involved cloning another git repository and adding my own changes into it. After I cloned it, I forgot to create and switch to the new branch and do my changes there. So all my changes were in the ‘master’ branch. I rather wanted to have my changes in my own branch. git makes these things trivial. All you have to do is rename your current master:

$ git branch -m <old-branch-name> <new-branch-name>
$ git branch (should show the new name)
Now, do a git log and find out which is the commit before you started making the change and do:
$ git checkout -b <old-branch-name> <commit-sha1>
That’s it and you have the whole thing as you wanted it to be.

Thanks to my friend Anand for the tip on the -m option to git branch. Most git gems seem to be deep embedded in those switches of the sub commands of git.

Syndicated 2010-01-24 08:00:00 from Ramakrishnan Muthukrishnan

insertion sort in clojure

Here is my first cut, non-lazy implementation of insertion sort.

gist id=282146

Syndicated 2010-01-21 08:00:00 from Ramakrishnan Muthukrishnan

social networking

The so called “social networking” websites seem to be the new craze (or is it already too old?). I used to have an account in facebook and orkut for more than 2 years and it was mainly used to connect back to classmates and the likes. But it turned out to be a distraction, atleast for a while. One just connects to a friend and almost never talks to him or her again thru these websites. Instead we post what we ate for breakfast, what new year resolutions we took etc etc - those phrases which carry zero information. And some people use it to show off their new materialistic possessions like their new Honda Cities and their newly built houses and their latest trip across atlantic etc.One can easily sink an hour a day browsing from a link to another without leaving facebook.com.

In the end, I decided that my time is more precious and enough is enough. So I am facebook/orkut free from today. Facebook incidentally only de-activates the account.

I didn’t tell my friends in facebook or orkut that I am leaving. But I guess in the true spirit of social networking, they don’t care, so it doesn’t matter.

Syndicated 2010-01-21 08:00:00 from Ramakrishnan Muthukrishnan

Tale of autocomplete

As  a web user, I have always known that those automatic suggestions you get when you search for something at Google or when you fill in the forms while booking a Flight or Train Ticket are the handiwork of Javascript scripts working behind the scenes. Off late, I was very curious to know how exactly this works. This took me through a long road in the unknown territory.

To give a short summary for those like me, what really happens is that the JS script running on your browser (which gets downloaded from the webpage/site you are viewing) issues various HTTP requests to the server “asynchronously” while you are plugging in some values into a form. There is a standard way of issueing this request  - XMLHttpRequest. Once we get the data, we can modify the structure of the HTML Page. I was sort of lying. HTML page is not modified. The HTML page is read by the browser, parsed and arranged as a Tree structure and is made accessible to the JS Script. This structure is called DOM - Document Object Model. Think of DOM as a parsed HTML page re-arranged as a Tree, because HTML Document is indeed a heirarchical data structure and can be represented as a tree. The attributes of any HTML tag is now an attribute of a node in the tree and is accessible to the JS. JS script can now add/delete/change any node or its properties in the tree. When a change in DOM is made, it reflects immediately in the rendered page and one need not do a “refresh”.

But all this comes because the server can respond to those “asynchronous” requests coming from the browser and respond back with data. If it can’t, then all these are useless. One has to write code at the server side to handle these requests and return the required data (usually as XML or as JSON, an alternative to XML or key/value pairs which express the data as Javascript objects).

This is the essense of what happens in the so called “Web 2.0” style websites. Unfortunately, web has too many jargons which creates an impression that it is highly complex. It is complex but with a bit of effort, it is not difficult to understand.

I found the IBM DeveloperWorks series on AJAX very useful in understanding the above concepts.

Syndicated 2009-12-25 08:00:00 from Ramakrishnan Muthukrishnan

cell phone battery charger

I misplaced my cell phone charger about 2 months ago and ever since, had been charging my cell phone with the micro USB cable connected to the laptop. So far, I have managed to charge the phone before it completely exhausted the power. Until yesterday. I thought it is just a matter of plugging in, the cable into the phone and connect the other end of the cable to the computer. The phone did start charging. But at some point, it got enough power to bootup and decided to automatically bootup. Once booted up, it shows up as a USB Mass Storage device. But before it enumerates, the phone powers off again. The issue is that, before enumeration, the host controller gives out only 100 mA of current. It can give out 500 mA, only after enumeration. The current was just not enough to keep it going and it kept on booting up and powering down again and again.

Finally I found a way to break the dead lock by rebooting the computer and stop the boot at GRUB prompt. Turned out that the BIOS configured the USB Host Controller to give out 500 mA and it quickly charged up, enough to enumerate, so that I could turn on the computer again.

Syndicated 2009-11-11 08:00:00 from Ramakrishnan Muthukrishnan

debian and other off-work projects

I met another debian package maintainer today for gpg key signing and general chat. I understood how horribly outdated I am, with the happenings in the debian world though I still manage to read some of the debian emails. It provided enough motivation for me to work on some of my packages.But that would mean taking time off from my Lisp study.

I have not been able to keep up with SICP videos though I managed to see (multiple times) up to 4b. I need to catch up with the book though. Currently I am working through Seibel’s Programming Common Lisp. I have also set my eyes on Clojure and had been going through its features. I also worked some small programs with it and found it to be incredibly powerful. It has immutable data structures which is better suited for creating pure functional programs, unlike CL where data is mutable.

I have zero Java knowledge though and often find myself struggling to use java classes from clojure.

Syndicated 2009-11-08 08:00:00 from Ramakrishnan Muthukrishnan

coders at work

Peter Seibel

The book is a collection of conversations with some very well known figures in the computing world. These people have done significant contributions to the body of knowledge and are “inventors/practitioners” of Unix/C, Lisp, Java, Erlang, TeX etc.

Peter has done a great contribution to the computing world by bring out this book (not to mention his other great book “Practical Common Lisp”). The subjects seem to have been very carefully chosen and are experts in their respective fields. But did I miss anyone? Yes, Richard Stallman. He has done some really great deal of programming, all by himself. Nevertheless, this book is a great contribution into the field of Computing folklore and biographies and is very very inspirational. Hats off to Peter for painstakingly undertaking this massive activity of researching the backgrounds and also for researching various topics. It is not easy to talk to these great people in the same language.

The questions are spontaneous and encourages the people to open up the story gradually. Mix of context specific ones and generic ones. Peter also seem to have been careful about not getting into a duel on various usual flamewars. For instance, Peter never asked the question “Vi or Emacs?”.

These are some of the questions, Peter seem to have asked everyone.

  • When did you start to program? (A great deal discussion follows on details about the machine and methods used.)
  • What are your usual ways of debugging? Do you use print statements or use a debugger ?
  • Do you consider yourself as a programmer or an engineer or a craftsmen or an artist?
  • What are the differences between programming and prose writing?
  • What is different in the programming between then and now? This is usually followed by really good discussions of the difficulties of modern day coding with layers on top of layers. Even though source code is available, the sheer amount of knowledge on various libraries and abstractions built by modern day computing systems make it very difficult for a newbie to understand what is going on under the hood. It also make the system inefficient because the computing hardware has become better and cheaper and so no one cares for these things.
  • What are your favourite programming books? Needless to say, "The art of computer programming" is in the list. Some said, they read all volumes cover to cover.
  • What is beautiful code? Importance of reading good code.
  • How do you read code?
It is amazing, how early some of the people touched their first computers. Remember these are 60s and 70s and not even 80s. Contrasting this with my own experiences, I think I am one of the many  nfortunates who had no idea what computers are until I went to the college for undergraduate degree.

It is also amazing to see that these folks are still tinkering with the machine and programming, pretty much every day. In contrast, my job is trying to keep me away fron hands on programming. I am instead trying to work with what others have done and bending it to work with other things and in the process, not writing much code at all.

The discussions are very casual and not formal. It will be very interesting to hear the audio recordings of these conversations, which will obviously have much more interesting anecdotes and stories which Peter couldn’t have been able to incorporate into the book. Most subjects are older programmers. There are few younger ones.

  • Fitzpatrick: Importance of statistics.
  • Peter seem to have researched his subjects very well and have digged most of the information about them off the web. For example, he talks about Fitzpatrick's student day Livejournal entries, one of which said, he was stressed out and hated computers.
  • Most people used print statements instead of symbolic debuggers.
  • C++ hate seem to be a common thread.
  • code reviews as a pre-commit step.
  • bottom-up approach to coding. One exception was Joshua Bloch who said, he does the APIs first and then the implementation, which felt like a top-down method to me.
Some quotes from the book.
  • "C is a portable assembler"
  • "You can reason from effects back to causes. Which is the whole game in debugging"
  • "I tend not to buy into religions, any religions, whole hog. Whether it is object oriented programming or functional programming or Christianity or Judaism, I mine them for good ideas but I don't practice them in toto." : Joshua Bloch
  • " Oh, it's not worth the time, it's just the name of a variable, just don't get it. You're not going to produce a maintainable program with that attitude." Joshua Bloch
  • brilliant quote by Tony Hoare in his Turing Award speech about how there are two ways to design a system: "One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies."
  • "Bloch: I believe that code ownership can't be denied. In a way, it's  like motherhood - you give birth to the code that you write, and especially  if it is large, complex or original, it is yours."
  • Joe’s Law of Debugging, which is that all errors will be plus/minus three statements of the place you last changed the program
  • “Just start something, no matter how humble.” John Washbrook, a senior academic told Simon Peyton Jones. How true this is, as one begins a new programming project with a blank editor in front.
  • "programming languages are the user interfaces of programming": Simon Peyton Jones.
  • "Every five pages of my book is somebody's career" : Donald Knuth.
  • "The first rule of writing is to understand your audience—the better you know your reader the better you can write, of course. The second rule, for technical writing, is say everything twice in complementary ways so that the person who’s reading it has a chance to put the ideas into his or her brain in ways that reinforce each other." : Donald Knuth
  • "The problem is that coding isn’t fun if all you can do is call things out of a library, if you can’t write the library yourself. If the job of coding is just to be finding the right combination of parameters, that does fairly obvious things, then who’d want to go into that as a career?" : Knuth
Guy Steele and Peter Norvig interviews turned out to be great. I then read Simon Peyton Jones and that was great. Every interview turned out to be better than the previous one, whichever order you read it! I just wished there were more. May be dead tree books are a bad choice for such things.

Ken Thomson’s interview had quite a lot of surprises. I just loved this interview. Ken just opens up his mind on various very interesting things.

Peter, though an author of a successful Lisp book, never gets into an argument with Ken Thomson, when he kind of, thrash the Lisp machine concept and the mentality of MIT hackers at that time to compete with the Unix. I was also surprised when Ken said he had not heard of the “Worse is better” paper of Richard Gabriel which compares the Boston style vs New Jersey Style of computing. I also couldn’t justify the vague answer Ken gave regarding Buffer overflowscaused by slppy coding of C/C++ programs. Also Ken said, at Google he has no check-in rights. He also said he despise C++ (like many others in the book and elsewhere) developed by his ex co-worker. C++ has too many features and everyone use a subset of it. Ken clearly says that it is a badly designed language.

Ken also says about the well known story of his wife and kid who went away for a month when Ken was happily programming pieces of Unix at a fast pace. Ken says that when your wife and kid are away, you no longer have to sync with the Sun’s cycle of 24 hours and that he never experienced any stress during that time. Ken also feels (like his friend Rob Pike) that nothing new is happening in the computing world. According to him, the last significant change was the Internet. Ken also shares the same thought, which many others also expressed, that the modern day programming is all about layers on top of layers on top of layers and that a program depends on 40 different libraries which in turn depends on more libraries and at some point, one just can’t keep all that in one’s head. On top of it, things are now distributed with messages being passes from one place to another. Modern day free software projects like GNOME and Mono and gtk are good examples of this phenomenon. Personally, I find it extremely hard and intimidating to even figure out where to start looking if I see a problem and the very thought of it scares me away from such an undertaking. One instance is that on my laptop, the speaker volume control always resets to mute every time I bootup, no matter what the volume level was during the previous bootup. I had been trying to track the problem down for quite a while and finally the layers scared me away and I gave up.

There are some good discussions and contrasting opinions on Unit Testing and how and when to do it. Some of these have hit the headlines recently.

Overall, it is a very inspirational book for programmers and everyone interested in the craft or art or religion or whatever you call it, should read it.

Syndicated 2009-10-04 07:00:00 from Ramakrishnan Muthukrishnan

groklaw's PJ on RMS

This post ought to be read by the so called "open source" pragmatists.

Syndicated 2009-09-30 07:00:00 from Ramakrishnan Muthukrishnan

Paul Graham's On Lisp

I got myself, a spiral bound printout of Paul Graham’s ”On Lisp”. The missing diagrams are explained in this c.l.l post.

Syndicated 2009-09-29 07:00:00 from Ramakrishnan Muthukrishnan

235 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!