I came across this piece by Joel, where he says ”It’s harder to read code than to write it”.

PERFECT. Atleast my programming experience matches with what he says. On the other hand, I do not interpret it as ’so just stop reading code and do something else’. If you have to do real programming, you have to spend time ’understanding’ already written code.

Now, the deeper reasons for why it could be hard to read code could be:
  • To read code, you need to have a purpose. That purpose is defined by any feature, typically, a bug fix or an enhancement task. But any feature does not use all code. So you will not read all code.
  • Next, it is humanly impossible to read all code of any application (Have you ever)? In fact I have not even completely read all the code of any application that I wrote completely! Let alone all the code, you will not read all code related just to the feature you are working on.
  • Reading code without input/output information is a mindless task. It is not productive and does not make sense. This is because input/output information gives meaning to code without having to infer it, which otherwise is hard, error prone and cumbersome.

Here I have found my detective utilities (here , here) very handy. It eliminates the futility of reading code as it helps me ’understand’ code relevant to the feature I am working upon as it provides:
  • Code trace relevant to a feature (I start, stop detective)
  • Code information such as input, output, argument names and time spent

With the information provided by detective, I can explain the code in business terms to someone else while pointing to function names. Thats it. I have learnt the lesson the hard way.

So if Joel says ”Its harder to read code than to write it.”, we now have a corallary:

”Never read code without contextual information.”
 
 
I have 3 Seagate GoFlex drives as described below.
Picture
Original configuration of the Go Flex drives
My Macbook Pro has one Firwire 800 port, one Firewire 400 port, 2 USB 2.0 ports. But as you can see above, the Seagate portable 1 TB drive comes with a USB 3.0 interface. I can as well connect it to a USB 2.0 port but that would be a sheer waste. Further despite all permutations and combinations, I can at the most end up with only one free USB 2.0 port. But I also have an express card slot and I can easily add two USB 3.0 ports using an express card such as this one by Sonnet. Finally I decided to go with the following configuration.
Picture
Upgraded configuration of the Go Flex drives
Picture
I ordered the Sonnet express card through SYW and when it arrived I installed the driver as per the instructions, restarted my Mac, connected the two USB 3.0 drives, but the drives were not recognized. The LEDs on the two drives were blinking. A bit of investigation showed me that the express card would need an external power supply if the power drawn by the USB device(s) is more than what the card can provide. This was also verifed when I looked at the key features on the overview page of the Sonnet Express card.

Picture
I then connected an external +5V 3.5mm power supply and bingo the drives were up and running. So if you have such an express card and have connected devices that do not seem to work, check out the power requirements. With this setup not only do I get higher speeds for my external drives, but I also have freed up 2 USB 2.0 ports on the laptop. Very useful.

 
 
I have discovered that I used to over estimate the value that books bring to the table, whenever I have tried to learn a new skill or a new tool.

I think that could be beacause in reality I would learn something new to not just learn it, but to apply it somewhere. Such (valid) applications of any skill or tool are potentially infinite. As no book can cover all potential applications or usage of a skill or a tool, I would come unstuck when applying the knowledge gained. With experience, I have now changed my method of using books.

The first part I use a book for is to gain a conceptual understanding of the skill or the tool and for such an understanding, I have found it is unnecessary to deep dive [1] into the book working my way systematically through it. [2]

The second and most important part is I then choose to work upon an application of the skill or tool I have selected to learn, while using a book as one of the tools in the process. By doing that I am more focused on producing things which is what matters finally as opposed to the false expectations and satisfaction gained by working through a book.

I now treat a book as an aid, a tool, a mentor, a navigator that I refer to when I am stuck instead of the earlier feeling of being stuck despite having worked through a book.

The only care I have to take in this process is to pick a good useful application to work upon, which is possible if I am willing to think through it enough and then there is this.

The other minor advantage I have gained by following this process is that I do not suffer from the pressure of having to complete a book cover to cover. In fact, I now do not even have to care if I will ever complete the book, as long as it provides me value as a tool.

To cite just one example, recently I wanted to learn about algorithms and data structures. So instead of working my way through books; I picked up this book, and understood the concepts. Just the first 2 chapters sufficed. Next I chose to actually find applications where algorithms are important part of the solution. I chose to work on those applications, while using the books as a tool. Not only did this process work, but it also taught me how to actually use algorithms in the real world instead of working on some descoped abstract problems in a textbook.

Overall, I have repeated this process more than once and I have found it to be more productive in learning a skill or a tool than just working through a book. And I plan to stick to it as of now.

[1] A purely systemtatic theoretical perusal could be useful, but I fail to realize what is the point of theory if it does not lead to something useful? May be I am missing something here!

[2] Anyways, just reading through books is useless.
 
 
For the images on this website that appear within a post, I wanted to ensure that the image fits within the post’s container div otherwise it looks kind of ugly. I tried the following CSS rule but it did not work for Firefox. (I do not even test on IE!)
.post img{width:100%}
Now even if this worked for all images, however I have varied image sources where I do not have a direct control over the image type and image size, the two variables that I want to control. I prefer that images be of PNG format with the width scaled to 500 px. That would work best for my website layout. However it is cumbersome and boring to convert each image by opening it in some image processing software like ColorSync or Preview, changing its type and scaling it to the desired dimensions.

For such tasks, automator comes to the rescue. It will be great if I have two options in the context menu that allow me to:
  • Convert the image to PNG type
  • Scale the image width to 500 px
With Automator, you can create a service for each of the above, since an automator service appears as a context menu option.

Creating an automator service

Please watch my screencast below to understand how to use Automator to create a service.
To summarize, open Automator, choose ’Change type of Picture’ action in the Library, add it to the Service while allowing a copy of the image to be created and choosing some destination folder. You can now see the context menu option 'Scale for my website'. Similary you can create an automator service to scale your image while choosing the action ’Scale Images’ from the Library.

This was neatly done with Automator and it appears to be a very useful utility.

However the Automator app does not provide any mechanism to delete a service. In order to delete a service, just navigate to Library/Services in your home folder. Now just select the service that you do not want and Trash it.
 
 
I am a programmer by profession. For around a year now, I have had the privilege of working from home. Yes, its a privilege, which I think you can avail of only when you have built a niche programming skill set.

I have worked long enough in a cubicle to be able to compare working from home to that in a cubicle. Before I actually worked as I do now if you had asked me, I would have easily mentioned the following advantages of working from home.

Visible Advantages

  • Saving travel time. And if you can save time, it is worth a lot more if you can put that saved time to good use. Of course, if you are lucky enough to have your cubicle within a 3 km radius of where you stay, you still accrue the saved time.
  • Saving travel cost. Yes, if you are in India and with fuel prices soaring every other day, even an approximate calculation saves you a lot of money assuming the minimum total travel distance to and fro is at least 20 kms. Now if you are in a big corporate, they may have travel facilities but you lose the flexibility of following your own schedule. In addition, you vehicle undergoes less stress and the consequence is less service charges as well!
  • Saving outdoor cost. The moment one steps outside, there will be expenses. Of course it will vary with each person, but nonetheless by working from home, you may not realize that you save these outdoor costs as well. Examples of outdoor costs are impromptu lunches, cofee breaks, implusive shopping with a colleague etc.
Now if you add these up over a long term period, they will turn out to be significant. These are good to have advantages. But over a period of time, I observed that my work efficiency was to put even conservatively 5x what it was in a cube. I was startled.

Invisible Advantage

I had not done anything special before embarking upon working from home and it suddenly dawned upon me that I was completely shielded from unnecessary distractions of a cubicled workplace. If you have worked in a cubicle, I need not cite examples of such distractions; but for the sake of some enthusiastic programmer out there; I will cite a few. Uncalled for meetings, false alarm driven panic and inconsequential interventions which is labeled as ’behavior of a team man’, supplementary work such as ’trainings [both conducting and attending], the stupid HR parties, the list is endless :-).

While working from home, I observed and noted carefully that all my communications were centered only around my work and responsibilities. All other distractions just faded into thin air. And I realized that I was actually not working from home, but working in solitude. Solitude enables productivity, uncluttered thinking and the result is intrinsic joy.

So what are you waiting for? Go find your solitude for work.

Recommended Reading

 
 
’One works without thinking how to work.’ - Jasper Johns
Being a software programmer, most of my work is centered around implementing ideas. The other day, I realized about my work pattern that I am not really productive if I work for more than 4 to 6 hours each day. Why? I figured that whenever I work for 4 to 6 hours of a total of 8-9 hours, I spend the rest of my time reviewing my work. These reviews have always been very useful to guide me become better at my craft.

For example, I recently identified a very important area of improvement in the context of my work, which led to the tracer utility.

What I have also observed is that if I do not restrict myself to such time limits, I am productive only in a spike but the consistency is absent. My brain (whatever I have of it) just stops working and I am transformed into a dumb robot. And thus the realization of my consistent productivity number of 4 to 6 hours per day.

What is the gist of all this for me? I think it is the essence of thoughtful balanced work. If most of my work is based around implementing ideas, and if thoughts produce ideas, but if I am not thinking, then it is bound to be thoughtless work! Anyway, what is the point of doing thoughtless work?

Recommended Reading

 
 
Picture
1: Is my Mac good enough to make omlettes?
Recently I upgraded my Macbook pro with the following:
  • Increased the RAM from 2GB to 4GB RAM
  • Upgraded from Tiger to Snow Leopard
  • Installed a new battery as the old battery had run out of life after serving me well.
Now it should be noted that mine is a MBP that I bought in early 2007. However of late I noticed that it would heat up a lot. In fact it would resemble a toaster.

Usual Suspects

The following could be the usual suspects I thought, one of the upgrades and the fact that for my work, I would be running a host of softwares preciesly the reason for which I had increased RAM in the first place.

After some, what else, googling, I figured that many people had experienced heating problems after upgrading to snow leopard. Come to think of it, Snow Leopard should have made the laptop a lot cooler or probably the Snow Leopard could not acclimitize to the new environment!

The Chill Pill Solution

If you are suffering from the same problem, the following steps could as well help you. They did help me.
  • Step 1: Reset your PRAM and NVRAM as per the steps outlined here.
  • Step 2: Delete any fan control software you have may have installed, except smcfancontrol.I had Fan Control installed which requires the following steps for a complete clean uninstall:
    • Open System Preferences - Other. Here right click Fan Control and remove it.
    • Now run the following commands at your terminal. With this Fan control, will be completely out of the way.
sudo rm -r /Library/StartupItems/FanControlDaemon 
sudo rm /Library/PreferencePanes/Fan Control.prefPane

  • Step 3: Install smcfancontrol which you can download from here. With SMC Fan Control you can control your fan speeds. At higher speeds, it may add a bit of noise, but thats tolerable to toasting your Mac. Additionally, you can also make SMC display your fan speed and temperature.
Now even with all the softwares such as Virtual Box, 2+ heavy Java processes, Flash Builder; I have the operating tempearature around 65. With normal web browsing usage, the temperatures touch around 50. The problem per se is not the operating temperature, but if your laptop runs at high temperature constantly and finally crashes, which did happen to me more than once, that forced me to find a fix.
Finally, take Activity Montior’s help to keep a tab on CPU usage.
 
 
Yesterday, it was Gandhi Jayanti.

Today, a day later, I had cleaned my iSkins and placed them for drying on a newspaper. Here is the visual.
Picture
What is Gandhi saying?
Well, what’s so special about it? It seemed to me as if Gandhi is saying ”Despite all the technical advancements, retain your simplicity.”
 
 
Please refer to the word rectangle problem on this page

Analysis

This is similar to a board game like Queens and Kinghts or Sudoku. Let us then define the rules of the board game called ’word rectangle’. They can be stated as:
  • Each row of the board should form a valid word.
  • Each column of the board should form a valid word.
As is typical with board games, we can first build a search tree and walk through this tree. As soon as we find the above rules or constraints violated, we can backtrack while discarding the rest of the search tree. This is a problem of constraint propogation and search with backtracking.

The better way to think of this problem is that while typically board games give you the size of the board, here we are supposed to find the size of the board. As such our search tree should contain the following:
  • The words and their prefixes. The prefix is a constraint propogation heuristic to check if the constraints are violated, while filling the board. Obviously this turns out to be a suffix tree!
  • The words sorted by length from maximum to minimum. Then we can do binary search to determine the words beginning with a given letter and of length l in this sorted list. In fact if you do an inorder traversal of the suffix tree, you will end up with the sorted words!
Thus our search tree is made up of a suffix tree and sorted list.

Algorithm

  • Build the search tree as described in the previous section.
  • Pick a word ’w’ of largest length from the search tree.
  • Find out the largest possible length for each distinct letter of the ’w’.
  • Pick the smallest length ’l’ from the lengths determined in previous step. THis is because, we will have words of the smallest length available for all letters of word ’w’.
  • Now for each letter of the word ’w’, pick a word of length ’l’ beginning with that letter. Now check if the rules of the board are satisifed. The rules will be assumed to be satisfied if the word length is 1. A word length of 1 implies the row or column is yet to be filled. If the rules are violated, discared the chosen word and pick another word of length ’l’ for the letter in consideration. Repeat the process till the board is filled.
  • That board’s row and column lengths are the maximum possible lengths.
 
 
Please refer to the Tour the T problem on this page.

Analysis

This is an instance of the Traveling Salesman Problem. We can model the entire subway as a weighted graph G=(V,E) where V is a station and E is an edge that connects two stations and w is the weight of the edge that represents the travel time between the two stations.

Algorithm

  • Build the weighted graph of the subway, while collecting those stations that are hubs connecting multiple lines. For example, Park St is a hub.
  • Now find the minimum spanning tree and do a depth first traversal of the tree.
  • Find the shortest path between the successive vertices sorted in depth first order. This will build a route that traverses all the stations at least once.
  • Now on the route, find out the hubs where line has been changed and add the waiting time for such line changes.
  • If your start station is not Kendall square, then find the shortest route between the penultimate station on the route and Kendall square, to build the final route.