Wednesday, May 20, 2009

Quote of the Day

If you want your wife to listen and pay strict attention to every word you say, talk in your sleep.

Friday, May 15, 2009

Using Twitter for Status Messages

I started using twitter for my gmail status messages. They are also available on my blog.

URL for my twitter account is http://twitter.com/tnsatish

RSS Feed is http://twitter.com/statuses/user_timeline/38406967.rss

Tomorrow, I will try to use it to the maximum extent (for election results). :)

Saturday, May 09, 2009

A Programmer dies and goes to heaven.


He reaches the pearly gates and is amazed to see a happy crowd all waving banners and chanting his name.

After a few minutes St. Peter comes running across and says, "I'm sorry I wasn't here to greet you personally. God is looking forward to meeting such a remarkable man as yourself."

The programmer is perplexed. "I've tried to lead a good life, but I am overwhelmed by your welcome," he tells St. Peter.

"It's the least we can do for someone as special as you are. Imagine, living to the age of 160 and still looking so young," says St. Peter.

The man looks even more dumbfounded and replies, "160? I don't know what you mean. I'm only 40."

St. Peter replies, "But that can't be right - we've seen your time sheets!"

Source: Funtoosh

Wednesday, May 06, 2009

Abusing Properties in C#


C# properties allows one to access data similar to variables instead of methods. Internally, the implementation might be same. But, by looking at the code which uses properties, one thinks that, it is using variables. If we don't use properties, then, we have to use methods to get the same.

I wanted to get the data from sharepoint list, and wrote the following code. (list is a sharepoint list SPList).

for (int rowIndex = 0; rowIndex < rows; rowIndex++)
{
    for (int colIndex = 0; colIndex < columns; colIndex++)
    {
        Console.WriteLine(list.Items[rowIndex][columnNames[colIndex]]);
    }
}

The list contains around 3000 items, and each item contains around 40 columns. For this, the above code took around 17 hours. It is not a feasible option for me. So, I tried various things, and finally changed the code to below.

SPListItemCollection listItems = list.Items;
foreach (SPListItem listItem in listItems)
{
    for (int colIndex = 0; colIndex < columns; colIndex++)
    {
        Console.WriteLine(listItem[columnNames[colIndex]]);
    }
}

How much time do you think the above code would take?

It took 2 minutes.


For the people who know only C# and no other language, probably, it may not be a surprise. But, for those who have good knowledge in other languages, it does not make sense. Many developers (those who worked in other languages) think properties similar to variables. It is not intuitive to cache the value from the properties.

If there is lot of computation to be done, then they should use methods. If the data is ready and no computation/retrieval is required, then they can use properties.

While optimizing the performance for the above code, few non-developers in my team insisted me to use profiler to find out the problem in the above code. But, I did not run any profiler on the code. One non-developer ran the profiler on that code and got the results, and other non-developers insisted me to take those results. If you are a developer and know that sharepoint is a proprietary software, then I don't need to explain anything on this.

Sunday, May 03, 2009

Google Reader in Offline Mode From Different System


By using Google Gears, Google Reader can be used in Offline Mode. In this, if we go to offline mode, then we can read feeds without connecting to internet. But, this is possible only from the same browser from which we went to offline mode.

Whenever I don't have internet at home, I wanted to store the feeds in my pen drive, and read it from home. For that, I have done the following.

Install sqlite db from http://www.sqlite.org/download.html.
Add sqlite folder to the path.
Get the googlereader.vim from http://www.tnsatish.com/software/googlereader.vim.

The google reader database is in a single file and is located at C:\Documents and Settings\<username>\Local Settings\Application Data\Mozilla\Firefox\Profiles\<somestring>.default\Google Gears for Firefox\www.google.com\http_80. The filename would be something like GR-379e715a5932e600#database.

Copy both database file and vim script to a folder, and run the following commands from that folder.

c:\> sqlite3 GR-379e715a5932e600#database
sqlite> .output reader.html
sqlite> .dump
sqlite> .quit

c:\> vim -s googlereader.vim reader.html

After the above commands, reader.html will contain all the unread feeds. If you want all the feeds including read feeds, then in the vim script, remove the fourth line :g/state.com.google.read",/d.