Friday, June 04, 2010

Can’t connect to MySQL server on ’server’

Its been a long time since I wrote anything here. So, I thought let me resume by sharing a little piece of information I gathered the other day. So, I have been using MySQL to manage some data related to my research. I have installations on multiple machines that I use, and recently I had to install it on another ubuntu machine. I did the following:

<code>sudo apt-get install php5 mysql-server apache2 phpmyadmin</code>

It worked fine, but then, my python script that runs on another machine began to complain that it could not connect to my MySQL server:

 Can't connect to MySQL server on 'server'

Now that was just ridiculous because this has never happened before. So I trolled and trolled till I found what I was looking for:

http://www.webmasterworld.com/forum10/6141.htm

So, turns out that there is this tiny piece of configuration information in your /etc/mysql/my.cnf file that says:

bind-address = 127.0.0.1

which essentially means that all connections coming in from anywhere other than the local machine will not be entertained. Remove or comment that line and restart your server. Things start working!

Sunday, September 27, 2009

Rick Riordan at the National Book Festival

I was at the National Book Festival yesterday in Washington DC where several authors including Rick Riordan, John Grisham, Jodi Picoult and the like did book signings and talked to their fans. The event by itself was sort of poorly managed because the management probably did not expect a crowd on such a big scale (the Smithsonian metro station was closed in the afternoon due to too much crowd!).

But all that apart, people who went with the intention of meeting their favourite authors had a successful day, and that was perhaps the only worthy reason to go to the festival because the book festival did not have any book stalls (other than a jam packed Borders tent selling only very specific books).

Anyway, so I wen't to catch a glimpse of  Rick Riordan since I am an insane Percy Jackson fan.I got to the pavilion atleast 15 minutes in advance while the previous author was still speaking. After some pushing and jostling I finally edged into the tent and escaped the rain outside. There was hardly any place to stand but I positioned myself so that I could operate my camera.

His talk was quite funny in general and he gave his eager fans a glimpse of what is in store for them in the upcoming months:

1. There will a second Camp Half Blood series of books (yes you heard it right!) coming up soon. I forget if he mentioned when it will be out, but he mentioned that there will be more of Percy and Annabeth to come although Percy will not be the main character in the new series and there will be a new generation of demigods. The new series will probably be based on the next big prophecy that we encountered in "the last olympian".

2. May next year is going to be about Riordan's next novel that is based on Egyptian mythology. Now that is something that sounds really exciting. Riordan even read the first few lines from this upcoming book that he says is currently with his editor now!

3. Finally he talked about the Lightning Thief movie that is set to release in February next year. He mentioned that the role of Chiron will be played by Pierce Brosnan and that of Medusa will be played by Uma Thurman. Now that is some interesting cast.

Since I am travelling currently, I will upload pictures soon.

Tuesday, June 30, 2009

Using multiple applications with ASPNETDB

As a web developer, I have used ASPNETDB several times to manage the membership and role information for my applications. It has been a while since I have done software development in ASP.NET. So when I try things now, I realize there are several small things that I knew at my fingertips back then, come with a little more effort right now. I hooked up a new application to use the ASPNETDB, and tried to create a new login. I got the error that the username already exists.

This was surprising, because it was a new application. I realized that the application was actually pointing to the same instance of ASPNETDB on my DB server. I knew that there was some way of isolating multiple applications in the same membership database. After a bit of research I recalled out to do it:

In the web.config file, look for the following section:

<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ApplicationServices"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""
applicationName="/"
/>
</providers>
</membership>

Change the value of the applicationName attribute inside the providers element to then name of your application, and you are good to go!

Friday, June 05, 2009

Free Internet?

This is a short post from the Greater Rochester International Airport as I wait for my flight. No other service at an airport makes me happier than free internet. The first time I saw this was when my flight to Memphis was delayed by a couple of hours and I was stuck waiting at Charlotte Douglas Int'l airport. I saw an unusually high number of people using their laptops and somehow got the feeling that there might be internet connectivity. I booted up my machine and to my pleasant surprise, I was right. I was able to establish a secure connection to my school network and get some work done while I waited. For internet savvy people like us, there isn't really much you can do if you are stuck waiting at an airport, and a free connection just saves your day.

But I was wondering what is it that allows an airport to host a free wifi connection. Large and prestigious airports like the O'Hare Int'l airport at Chicago do not have a free wifi connection. What is it that prevents them from doing so? What is the business model followed at the lesser known airports that lets them provide this service to travellers?

Sunday, March 15, 2009

Shuffle shuffle

Several weeks ago, I found myself thinking, how I could shuffle a list/array given to me in a random order. This is a typically commonplace thing to do in several applications: online card games, your favourite music player etc.

The interesting thing about this problem is how some naive approaches, even though easy to code and efficient enough, do not achieve the desired randomness.

Lets define the problem: You have an input array which has elements in positions 1 through n. The objective is to produce a random permutation of the array. By a random permutation, we mean to say that each permutation of the array is equally likely. So a truly randomized algorithm will generate each permutation with a probability of 1/n!

The first approach that comes to mind is the naive approach of generating a random number between 1 and n for each element in the array and placing the element at the position indicated by the random number. This could be accomplished by using another auxillary array and placing elements into the new positions generated. The pseudocode could look something like the following:

NaiveShuffle(A[1...n], B[1....n])            //randomly permutes the elements in array A
for i from 1 to n
random <- RandomNumber(1,n)
B[random] <- A[i]
for i from 1 to n
A[i] <- B[i]



The above approach is very crude in the sense it uses an auxillary array and also parses through the array twice instead of just once. Still, the worst case running time of the above algorithm is O(n).

Random(1, n) generates a random number 1 and n (both inclusive). We assume that the random number generator generates truly random numbers in the interval specified. Also, we assume some kind of collision resolution mechanism. We are assuming that this method returns a random number in O(1) time.

All that said, a O(n) algorithm is not bad at all for this purpose. There is only one problem, this algorithm is WRONG! (hah...fat chance, didn't we name it a naive algorithm?). Why is that? This is because in every iteration, we generate n possible choices. Since there are n such iterations, the total number of permutations generated is n.n.n.n.......n times = n^n

The  total number of permutations possible while shuffling an array is n!. Since n^n is not exactly divisible by n!, there have to be some permutations which appear more frequently than the others (basic pigeonhole principle). Thus this naive algorithm does not generate truly random permutations.

Lets try something else. We generate a random priority between 1 and n^3 the Random(1, n^3)  routine, and assign a it to each element in the array. Then sort the array based on these weights.

e.g. if the original array is A<1,2,3,4> and we generate priorities randomly as P<34,56,8,77>, then when we sort array A based on the increasing order of the priorities assigned using array P, then we get the shuffled array as <3, 1, 2, 4>.

We used the interval [1, n^3] to generate priorities so as to reduce collisions. I will not delve into the correctness of this algorithm. The running time of this shuffling by sorting algorithm depends on which sorting algorithm we use. Typically it is Big-Theta(n lg n).

Another approach to solve this problem, is to shuffle by swapping:
Shuffle[1...n]
for i from 2 to n
temp = Generate(x from 1 to i)
swap(i,temp)


Notice that the interval for generating random numbers keeps decreasing. For the first iteration, there are n choices. For the 2nd iteration, there are (n-1) choices and so on.

Hence the total number of choices generated by this algorithm is: n(n-1)(n-2).....3.2.1 = n!

which is exactly equal to the total number of possible permutations. Moreover, since we iterate over the array only once, this algorithm runs in O(n) time.

Saturday, January 17, 2009

The White Tiger: Aravind Adiga

TheWhiteTigerCoverThis novel, published in the year 2008 won the Man Booker Prize in the same year. I bought the book out of instinct, although I haven't had a very pleasant experience with a couple of other books that have won the same prize. Many people said that the books that won this award were difficult to read and not well accessible. One of my friends gave me a very bad review of the book, but I had no choice but to read it since I had already bought it. I approached the book without any pre-concieved  expectations and I was pleasantly surprised. While I did not bother asking my friend why she did not like the book, there are several reasons why I would recommend the book to any reader.
First of all, the book is an effortless read, and the story flows at a good pace. The story is narrated in first person by Balram Halwai, who is the protagonist. It is his account of his rise from lowly origins in a village in rural India amidst crushing poverty where even the basic amenities of life are hard to come by; to his current position as a successful entrepreneur in a big city. But the story is not one of inspiration as one would imagine from such an account. Instead it is a story full of intrigue, corruption and crime, but narrated with an innocent and brutally honest tone that makes you chuckle throughout. The story takes a swipe at the corrupt political system of the country and how the people are forced to play along with it if they want to survive. What moves you while reading this story is how the honest and hardworking village boy is transformed into a shrewd, scheming man who does not hesitate to take the law into his own hands.
Adiga has done a masterful job in this darkly comic debut novel of his with a sharp observation and sardonic voice.

Thursday, January 15, 2009

Unaccustomed Earth: Jhumpa Lahiri

UnaccustomedEarth Edited Cover pageThis is Jhumpa Lahiri's third piece of work (after Interpreter of Maladies and The Namesake). Sticking to her theme, this is also a set of short stories, based on the lives of expatriate Bengali parents and their american-raised children. I used to really want happy endings from books and stories I read. Jhumpa Lahiri is not someone who would give me that. Her stories are colorful, full of real characters that you would come to love; her writing is superlative and flows with an effortless pace; but the stories end abruptly at a crucial emotional juncture when the characters are at some kind of an emotional high point. I am always left wanting for more, but I end up accepting the stories for what they are.
One thing I noticed in her first two works is her brilliant descriptions of food and cooking, so much so that I used to be amazed at her culinary knowledge. I was looking forward to the same, but found that missing in Unaccustomed Earth.
There are two parts in the book: the first one has 4 stories, and the 2nd part has 3 stories. I did not realize till the middle of the last story that the 3 stories in the 2nd part are actually related: based on the same two protagonists. Each story in the trilogy are spaced apart by a number of years .You could call me dim for not figuring this out earlier, but these stories are just like the previous ones, and each one could be read without any bearing on the previous ones, and none of them give any direct indication of a connection, except for the names of the characters (which could have been anything in any of the stories without affecting the plot). The first two parts are narrated by the two individual characters, based around their separate lives. The third story is narrated by the author, linking the two characters together finally. Being a fan of different narrative styles, I loved this.
Finally, Jhumpa proves that she can write not only about life in the US, but also Europe, where a considerable portion of the final story is based.
Brilliant piece of writing. Highly recommended reading.

Monday, January 12, 2009

one flew east, one flew west….

OneFlewOverTheCukoosNestCoverI recently finished reading One Flew Over the Cukoo's Nest: by Ken Kesey. This novel has been included in TIME Magazine's 100 Best English-language Novels from 1923 to 2005.

The novel is based in the mental ward in a psychiatric hospital in Oregon. It is an allegory on the psychopathic obsession of that time (the 1960s). The story is narrated by a gigantic, half-Indian "Chief Bromden", a patient of the ward who suffers from hallucinations and delusions.The ward is controlled by a tyrannical nurse: Nurse Ratched who reigns over all the inhabitants of the ward, including the orderlies, the staff nurses, and even the doctor. He controls everyone with surgical precision, using underhanded tactics to render everyone helpless and submissive.

Things change with the arrival of Randal McMurphy, a Korean veteral who has a history of insubbordination and street brawls. McMurphy quickly realizes that several patients in the ward are sane and simply emasculated because of the nurse and her controlling tactics.

This novel is about the fight between authority and free spirit.

Saturday, January 03, 2009

Pillars of the earth

PillarsOfTheEarthCoverI started reading this book by Ken Follet over 5 months ago. When I just had a couple of dozen pages left to finish the book, I went away to the US and for some reason I did not carry the book with me. Now that I am back in India for a while, I finished the book today. It is a really big book with over a thousand pages. There are several plots in the story, and like most really long stories, you feel that some of those could have been avoided for the sake of a smaller and crisper story.

The plot of the story revolves around the building of a cathedral in medieval England during the period of civil war and how the lives of several people around the cathedral is embroiled in politics and powerplay. The book spans several years and hence the author has been able to sketch the characters in great detail (no surprise there).

Several  reviews on amazon tout this book as a breakthrough in the historical fiction genre, which I think is a bunch of nonsense (no wonder since the book was a part of Oprah's book club). I don't really have good things to say about Oprah's book club and I would probably have not picked up this book had I known earlier, but the book did turn out to be entertaining, with a lot of gratuitous sex and violence thrown in. Sometimes it drags simply because the plot is very twisted and long.

I did learn a bit about medieval architecture, cathedrals, clergymen, nobles and the like. All in all, I recommend this book for a one time read. Entertaining, but long.

Wednesday, December 24, 2008

Sending bulk emails using Outlook and C#

I have always derived pleasure writing programs that solve real world problems. This is one such problem that I was able to solve. With the holiday season on, you might want to send greetings to your numerous business contacts. If you have several contacts that you want to send personalized messages to, then you very well can imagine how much time and effort that will take.
So this is what I set out to do: create an application that would send out emails to several contacts, with a personalized greeting line, but similar message body. Also, depending on the type of contact, you might want to send a different message. E.g. if it is a close colleague of yours, then you might want to send a more personalized mail rather than a one liner. Since these are personalized emails, these need to be sent from your actual email id rather than an SMTP server on your dev machine. Also, I needed this application to work for someone else who runs only MS Office on his machine. So I decided to use Microsoft Office Outlook 2007 for this task.
The first thing to do was to decide the fomat in which I would store all the configuration information that would be used by the application: So I created two different text files, mail1.txt and mail2.txt each with a separate email message:

Hello {0}
Mail body

Where {0} is a placeholder that will be replaced by the receiver name. mail1.txt and mail2.txt have the same structure except for the mail body depending on the requirement.
Next, I needed to create a list of names and the corresponding email IDs to which the mails are to be sent. Also, I needed a flag that will indicate the type of message that is to be sent, i.e. mail1 or mail2. I created a comma separated file with the following format:

<Receiver’s name>, <email id>, <mail body to be sent, i.e. 1 or 2>

I wrote a console application in C# that uses the Microsoft Office 2007 Primary Interop assemblies to automate sending emails to all these contacts specified. The emails get sent using the default account configured in your Outlook. The code looks something like the following. Please note that this is a quick hack which actually works and that I have not really done a lot of error handling or exception management on this because I know the conditions under which this will be used.

Microsoft.Office.Interop.Outlook.Application app = null;
Microsoft.Office.Interop.Outlook._NameSpace ns = null;
Microsoft.Office.Interop.Outlook.PostItem item = null;
Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null;
Microsoft.Office.Interop.Outlook.MAPIFolder subFolder = null;
Microsoft.Office.Interop.Outlook.MailItem memo = null;
Microsoft.Office.Interop.Outlook.MAPIFolder sentFolder = null;
StreamReader addressReader = null;
StreamReader contentsReader = null;
StreamWriter logWriter = null;

try
{
addressReader = new StreamReader(ConfigurationManager.AppSettings["addresses"]);
String currentLine = String.Empty;
String[] currentReceiver = null;
String messageBodyFile = String.Empty;
logWriter = new StreamWriter(Path.Combine(Environment.CurrentDirectory, "Log.txt"), false);
while (!addressReader.EndOfStream)
{
currentLine = addressReader.ReadLine();
currentReceiver = currentLine.Split(',');
switch (currentReceiver[2])
{
case "1":
messageBodyFile = ConfigurationManager.AppSettings["contentsFile1"];
break;

case "2":
messageBodyFile = ConfigurationManager.AppSettings["contentsFile2"];
break;

default:
Console.WriteLine("Could not send email to ", currentReceiver[0]);
logWriter.WriteLine("Could not send email to ", currentReceiver[0]);
currentReceiver[1] = String.Empty;
break;
}

#region EmailInit

app = new Microsoft.Office.Interop.Outlook.Application();
ns = app.GetNamespace("MAPI");
ns.Logon(null, null, false, false);
sentFolder = ns.GetDefaultFolder(OlDefaultFolders.olFolderSentMail);
memo = (Microsoft.Office.Interop.Outlook.MailItem)app.CreateItem(OlItemType.olMailItem);

#endregion

contentsReader = new StreamReader(messageBodyFile);
memo.To = currentReceiver[1].Trim();
memo.Subject = ConfigurationManager.AppSettings["mailSubject"].Trim();
memo.Body = String.Format(contentsReader.ReadToEnd(), currentReceiver[0]);
memo.BodyFormat = OlBodyFormat.olFormatHTML;
memo.Send();
Console.WriteLine("{0}: Sent email with body {1} to {2}:{3}", DateTime.Now, currentReceiver[2], currentReceiver[0], currentReceiver[1]);
logWriter.WriteLine("{0}: Sent email with body {1} to {2}:{3}", DateTime.Now, currentReceiver[2], currentReceiver[0], currentReceiver[1]);
contentsReader.Close();
contentsReader.Dispose();
}
}

catch (System.Exception ex)
{
Console.WriteLine(ex.ToString());
EventLog.WriteEntry("Email Automation", ex.Message, EventLogEntryType.Error);
}

finally
{
ns = null;
app = null;
inboxFolder = null;
addressReader.Close();
addressReader.Dispose();
logWriter.Close();
logWriter.Dispose();
}

Saturday, November 29, 2008

What now?

So, I vented my anger by writing a blog-post about the latest terror attacks. Apparently the NSG has flushed out the scum from the Taj hotel. Things are going back to normal. I have not watched the news since the evening of the ill fated day (EST). One of the questions I asked a couple of questions in that post was:

"What can we as citizens of a civilized society do to protect our interests? The cause of these terror attacks are varied in various places, but it is innocent people walking on the street who bear the brunt (and the people who go out to fight for us)"

And I have been thinking about this on and off. I have asked this question to several people. I am just plain baffled by the lack of responses or ideas. Varish said that it is time for the political system of the country to start acting tough. Really? Is this the time for the gov to start acting? The government should have acted way too long ago. Anyway, that is not even the point.

We all have conceded at some point that the government of ours is not doing much other than condemning the attacks and making vain platitudes. The dirty politicians will even turn this to their advantage so that they can gain political mileage for the upcoming general elections.

All right! Enough trash talk. We know that the government is not doing what it is supposed to. So I ask the question again. What do WE do? We are the educated elite of the country. We cast those votes. We elect those representatives. Is there something we can do to help? I feel we are totally lost on that question.

I suggested doing a signature campaign amongst the student and young professional networks in and out of India. We could send those signatures with a message to our respected Prime Minister. My good friend asked me whats the point behind a signature campaign? I said, "we need to make sure that the government understands that the educated elite of the country, both in India and abroad needs to see some real action now, and not just empty promises."

Then he asked me a question to which I did not really have an answer: "Doesn't the government already know that it has to battle terrorism?" . Just that any Indian government does not have the guts to take the right steps which are against their own self serving motives. And even we the people are to blame. Everytime there is an attack on teh city, we say that Mumbai is unbreakable. We are the most resilient city in the world. Hell we don't want to be resilient! Why is it that all these pains and agonies are forgotten a couple of days after the bloodstains have been washed? The sacrifices of the security forces and the pains of the people disappear into oblivion and we settle down into our old routine. This continues till the time there is another attack. Oh yes, don't be fooled into thinking that they are done.

So I was set into thinking what would the damn signature campaign achieve? It would probably serve the purpose to make it clear to the government that we are pissed off. But doesn't the gov already know that? Like Jayu said "they cannot be that detached from public sentiment". So how do we make them do it? In an ideal democracy (oh and we are very proud of the fact that we are a democracy) the people are able to hold the gov accountable for their actions and inactions. Why can't we do that in India?

"Electoral power is supposed to be the form of public control over its govt in a democracy. Here it gets sold for free sarees and rice during election time. The educated middle class has a very small say in the overall process."

So this is my sincere message to everyone reading this post. This general election, PLEASE GO AND VOTE. Cast a responsible vote. Our only goal should be to cast aside all our feelings of mutual distrust and communal agendas and questions of religion and reservation, and elect a government that would actually ensure that our people don't get slaughtered on their own street.

The only other weapons that we have are the RTI and the PIL. But only the legislature has the right to ammend the constitution. The courts can only direct the legislature to do something. So let us wield the only real weapon we have. The right to vote. Let the current government understand that they have to prove a point to us, and that we are watching. And let them consider this a threat: we will not vote for you if we do not see results.

Note to all the readers: If you have any ideas, post a comment.

Thursday, November 27, 2008

What is the solution to all this mess?

As I write this, my city burns. Terror attacks in several locations in Mumbai....it is all over the news. I don't think the country has witnessed such carnage in a long time. Yes, I say long time because India has sort of gotten used to the idea of terror attacks now. Mumbai itself has been the target of several such attacks. Barely a couple of months go by when you hear about another one of these bomb blasts on TV. Few things make me feel more helpless than a terror attack. And as I write this, I am sitting several thousands of miles away from my city.

But there was something very different about what happened today/yesterday (depending on which part of the world you live in). All this while the terrorists were hidden; they planted bombs clandestinely and ran away. This time, they had the guts to walk into my city, fire at people, lob grenades, hold people hostage and gut some of the main spots in the city. What is noticeable is that these terrorists have targetted places that are frequented by westerners. Colaba is an area that has a good density of foreign tourists and the Taj hotel (where one of the bloody gunbattles are being fought) plays hosts to several foreign tourists and business delegates. This is not just an attack on India. This is an attack on all the good people of the world who want peace.

There were reports of these terrorists dragging people out of the hotel and asking for their passports to look for people from the US, UK and the like. I don't know if this is confirmed news (it was definitely aired on one of the news channels broadcasting the events, so I took it at face value).

A few questions strike me:

1. Why is it that we are not able to prevent such blatant attacks on our home? Is our intelligence system so bad that we had no clue?

2. What do these terrorists want? Perhaps we could make a deal with them if we are too scared to go out and settle scores (atleast that seems to be the case to me a lot of times, and a lot of people will agree)

3. What can we as citizens of a civilized society do to protect our interests? The cause of these terror attacks are varied in various places, but it is innocent people walking on the street who bear the brunt (and the people who go out to fight for us)

The situation in India is unique, as compared to other countries that face the threat of terrorism. We have several internal problems and have a very troubled history, marred by communal conflicts. The scars of such conflicts are magnified by terrorist masterminds who turn troubled youth into blood-thirsty monsters. In the very early days of terrorism, terrorists used to be foreigners (I will not name the country, but we all know who I am talking about). As time progressed, terrorists started to come from interiors of the country. These are dissatisfied youth, who have been affected by communal clashes, who are brainwashed by the big terrorist organizations, trained by them and sent back into our country to cause misery to innocent people.

The solution has to be two pronged:

1. Deal with the external elements who propagate the terrorist ideas and fund such endeavors. This can only be done when like minded countries cooperate with each other to end global terrorism. This is because all global terrorism is interlinked and is funded and propagated by the same set of big organizations.

2. Deal with the internal elements. Bust the sleeper cells. Throw out the hidden extremists. Enforce the rule of law so that the gullible youth is not misguided by these scumbags.

All this has to be implemented around a framework that is designed to prevent such future occurences. A working intelligence system (do we really have one?), a proper disaster management system, adequate security measures at hot spots. I know people say that it is difficult to police a country of billions. But this is the price we pay if we don't. After the serial train blasts, we installed faulty metal detectors at some stations (the ones on the entrance of CST station barely worked), and assign 2 police constables at each major station. Did that work? We never thought that the outside of the station could be vulnerable too. Perhaps we thought that these terrorists are gonna keep planting train bombs. Do we even have trained people who are capable enough to design solutions to handle these problems? All this infrastructure has to be put into place.

The last thing I want to see is these stupid political parties trying to gain mileage out of this mess by pointing fingers at each other.  I will be very very pissed off if a party calls a Mumbai bandh or a Maharastra bandh (or any such extension) to gain public attention. Such measures gain nothing and simply cause more distress to the already troubled people. I want to see some action. I need these terrorists killed. I don't want empty promises. Are you listening? Oh and if there is something I could do........let me know. Right now I am limited to watching the news, writing pissed off emails and angry blog posts.

Wednesday, October 08, 2008

Touchy feely gcc

I am writing code in C after several years. Needless to say, I am woefully out of touch and don't remember the most basic of things. Add to that, I am writing code using a simple text editor and compiling it using gcc on commandline. Every time I see a funny error, it takes me a while to actually understand what is wrong. A really good IDE with awesome intellisense really does spoil you!

So I got this funny little compilation error which left me stumped:

/tmp/cckI2FzP.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status


I googled and found that this error is normally related to C++, but I was writing code in plain old C. So what was wrong? I found later that I had named my code file as List.C instead of List.c. After renaming it to List.c, all was well.

Turns out that filename extensions in linux are case sensitive (wonder why I did not run into that problem all these years),  and that C is a commonly used extension for C++

Tuesday, September 02, 2008

How I met Rafael Nadal

So I was out in NYC on the second day of my trip. We did not have much planned. I wanted to go to Rockefeller Center and my friends agreed kinda for the want of a better plan. So we got out of the subway station, and we saw this Brazilian carnival happening. You know what to expect in such a place. It was full of life and lots of people; brimming full of food, music drinks, and some other good things.
After a while I got very thirsty and wanted to get out of the place cos it was too crowded. Then we went over to Rockefeller Center and later the St. Patrick’s cathedral and did the regular tourist stuff (you know…clicking pics and all that). Most of the people were already tired and they were sitting on the cathedral stairs outside. One of my friends suddenly said, “Hey, Rafael Nadal just walked along the street).
“What?”. I did not want to believe that, but I just found myself saying “Lets go” and I started running across the street. I heard my friend say that he was wearing a yellow tshirt. My mind was a whirl. It could easily have been a mistake. But NYC is currently hosting the US Open and I did not want to miss a glimpse of the world’s top seeded tennis player. I spotted the man in question from across the street but the crossing was difficult due to the traffic. I had to wait for the walk signal to come on, an then I ran again. He looked slightly taller than what I expected and the hair looked shorter and straigher from behind. Nevertheless I kept running and went ahead past him. I heard that unmistakable voice speaking fluent Spanish. I forgot to mention, he was walking with a couple of other guys (and they were all walking very fast, as if they were in a hurry).
I turned around and looked at him. I was still not sure and I just stood there while he walked past. I saw someone else approach him and shake his hand while he continued to race along the road. I was reluctant to approach him since he seemed in such a hurry and I told my friends that he wont stop for us. But two of my friends were insistent and they went and they stopped him and requested for a picture. I did not see much, but I just happened to notice Nadal turn around and pose for the photograph. I ran ahead to bask in the moment.

Nadal

I was meeting my favourite tennis star of the time. Ironically the guy who clicked the photograph was the one who was most crazy about Nadal. (Thanks for clicking the picture Sanatan). After the picture was clicked, we yelled a “Thanks Rafa” chorus and we knew that our day was made.

Wednesday, August 27, 2008

Back to school

Ok. I am back after a long hiatus. Today marks the completion of 3 weeks since I landed in the USA. I have come here to pursue a Masters' Degree in Computer Science. I could not think of anything to write about because most of my recent posts have been about books I have read. The last book I read was "Pillars of the Earth" by Ken Follet, and unfortunately I did not get enough time to complete it before my flight to the US. And for some reason, I did not even carry the book with me (maybe it was the size of the book). So, its been 3 weeks since I read anything creative and hence no posts. Life in the US is not very different from what it was back home. I still feel like I am here on an extended nightout at a friend's house.

The past 3 weeks were spent in setting up my new house, shopping, eating, sleeping, shopping, opening bank accounts, roaming around campus, shopping, waiting for my new laptop to get delivered, and other miscellaneous things not worth writing about. This makes me feel that I have done absolutely nothing productive in the past 3 weeks. Oh yes, I have this big obsession about productivity and using my time effectively (but I end up wasting most of my time anyway and then fret about it in posts like these).

One noticeable difference between life in Bombay and life here in the US is that I do not have to use public transport as extensively as I had to while in India. My university runs a shuttle service which takes me to most nearby places, and not just to and fro. That having said, it is quite difficult to go even relative far off places without a car. Bombay suburban transport system rocks. Yes, I said Bombay and not Mumbai. You would be surprised....people here do not know Mumbai, and I like calling it by the old name. It got a classy zing to it.

As it is apparent, I am suffering from a writer's block. Suggest me of something to write about.

Tuesday, July 22, 2008

To God belongs the East and the West

My Name is Red (Benim Adım Kırmızı) is a turkish novel by Orhan Pamuk, a Nobel laureate. It won the International IMPAC Dublin Literary Award in 2003, as well as the French Prix du meilleur livre étranger and Italian Premio Grinzane Cavour awards in 2002. The book in consideration in this article is the English translation by Erdağ M. Göknar. There have been questions about the English translation not being as good as the Turkish version and the word order being quite difficult. But honestly, I did not know that the book I was reading was actually an English translation and not an original English work.

My Name is RedThe story is based in 16th century Istanbul, a year before the thousandth anniversary (calculated in lunar years) of Hegira (the migration of Muhammad and his followers to the city of Medina). The Ottoman Sultan Murat III has commissioned an illustrated manuscript to display his power to the Venetian Doge. This manuscript is to be made utilizing the “controversial” aspects and techniques of the Frankish masters, namely portraiture and perspectives. Due to this reason, the Head Illuminator of the Sultan is bypassed and the work is commissioned to Enishte Effendi, who co-ordinates Master miniaturists Stork, Olive, Butterfly and Elegant. It is rumored that the paintings are blasphemous and an affront to Islam and The Prophet. Subsequently, the master guilder Elegant working on the manuscript is murdered. The book follows the path of a murder mystery where the identity of the murderer is revealed at the end. Pamuk’s knowledge of Islamic miniatures is mind-blowing. He goes on to narrate several stories from Islamic lore, stories of great miniaturists and their history, going back to Behzad and the Chinese influences brought by the Mongols. The book discusses and debates about various topics, the most prominent of these are:

·        Form and style,

·        The relationship of art to society, religion and God, and

·        The artistic, cultural and political differences between the Ottomans and the Venetians.

The first thing that strikes you while reading this novel is that the story is narrated in several different voices which recur throughout the story. No two consecutive chapters are narrated by the same narrator and all speak in the first person. There are a couple of rather unusual narrators: a gold coin, a tree, a dog, Satan, and even Death itself. I later figured that these narrators are in fact the central themes of the illustrations appearing in the secret manuscript in question in the book. One of the central points about traditional miniatures, I learned, is that they always appear as illustrations of a story, and never as independent paintings. Pamuk has adopted this style in his narration of the story: by describing the protagonists as part of an old manuscript, supporting the story. The characters are aware that they are characters in a story and address the reader with irony.

The setting of the story in late sixteenth century Istanbul is detailed; the plot is engaging (albeit a bit slow moving in certain places) with several interesting characters. Indeed there are too many themes in the book (art, religion, Allah, love, lust, jealousy, hatred, intrigue, murder) and I cannot do justice to all of them in this short article. If you are interested in Islamic art, Ottoman miniatures or medieval Istanbul, then pick up this book. But be warned, this is not an easy or quick read.

Friday, June 27, 2008

So it goes….

Slaughterhouse Five : Kurt Vonnegut
This book is widely regarded as one of the best anti war novels of all times. It begins as a memoir and is based around the Allied bombings of Dresden in World War II. The author Kurt Vonnegut is a minor character in the story as the narrator and is quite funny. Both Billy Pilgrim and Kurt Vonnegut are portrayed as prisoners of war in Germany.

SlaughterHouseFiveCoverThe book has an unusual narrative style which is quite nonlinear in time since the protagonist Billy Pilgrim is "unstuck in time" i.e. he experiences different periods of his life in seemingly random order and he has no idea which part of his life he will visit next. As a result of this queer condition, Billy experiences his own death several times and he switches back and forth between prisoner camp in Germany and his life as an affluent optometrist in Ilium, NY, and sometimes his stay on the planet Tralfamadore. One of the important events in Billy's life is when he gets abduced by aliens from the planet Tralfamadore. The Tralfamadorians teach Billy about the concept of time as the fourth dimension, fate, and death's lack of discrimination. To the Tralfamadorians, who can see in four dimensions, everything always exists and has always existed. Everyone is alive and has always been alive. They see time as we might see the Rocky Mountains, stretching endlessly on both ends. So if all events are predecided, then "what about free will?" asks Billy. The Tralfamadorian responds: "I've visited thirty-one inhabited planets in the universe... Only on Earth is there any talk of free will". This lends to the belief that human beings do what they do because they must.

The book opens with the narrator's account of his own relation with the Dresden bombings and his reasons for writing the book. Although there is no reason to believe that this account is also not fictional. Thus, the real story begins with chapter 2. I found this form of writing unusual (although amusing) which they say, is common to postmodern meta-fiction. Throughout the story, the author pokes fun at the concept of war, portraying the characters in sarcastically humorous light. Vonnegut says that the soldiers dying in these wars are young men barely out of high school. That is the reason he portrays these soldiers as scared young men instead of heroes of war. This is so that his book does not encourage more wars in which children would be sent to die (quite like the so called Childrens' Crusades).

All in all, a very entertaining and funny book. Quite an easy read.

Sunday, June 22, 2008

In a hole in the ground there lived a hobbit

The Hobbit by J.R.R Tolkien was nominated for the Carnegie Medal and awarded a prize from the New York Herald Tribune for best juvenile fiction of the year (1938). Also, The Hobbit has been recognized as "Most Important 20th-Century Novel (for Older Readers)" in the Children's Books of the Century poll in Books for Keeps.

hobbit cover I should probably have read this book before reading Lord of the Rings since quite a few characters in the epic tale have been introduced in The Hobbit: most notably the titular protagonist Bilbo Baggins, Gandalf the wizard, Gollum aka Smeagol. Also noteworthy is a side character Gloin, who is said to be the father of Gimli- Elf Friend (Fellowship of the Rings). Two other noteworthy characters are the dwarves Balin and Ori. Recall that the Fellowship of the Rings discovers Balin's tomb in Mazarbul in the Mines of Moria and the Book of Mazarbul written by Ori. The story also accounts how Bilbo Baggins gains the possession of the One Ring. The ring, along with the character of Gollum, sets the tone for the much known sequel.

The tale is based around a typical comfort loving, homely hobbit Bilbo Baggins who finds himself on an adventure with thirteen dwarves also accompanied by Gandalf, an itinerant wizard who disappears in the middle of the story later to reappear at key moments (typical Gandalf). Gandalf is out on his own business but incidentally assisting the dwarves on their quest. The team of the thirteen dwarves and the "burglar" Bilbo have set out to reclaim an ancient treasure of Thror the Dwarf King under the mountain which is now guarded by a ferrocious dragon Smaug. Their journey takes them over strange and dangerous lands which lands them into mortal peril more than once. The story is in the form of an episodic quest and the prose is interspersed with poetry and songs that are typical to Tolkien's works.

The publishers of the Hobbit requested for a sequel which eventally resulted in the epic Lord of the Rings. Tolkien rewrote some of the parts of the Hobbit in order to facilitate a smooth transition into the darker themes of the Lord of the Rings. Tolkien wrote The Hobbit as a story for children, and The Lord of the Rings for the same audience who had subsequently grown up since its publication. The Lord of the Rings was written in less humorous tones deals with more philosophical and darker themes: while the Hobbit has its share of death and danger, it is about the quest for a lost treasure. Even though many of the encounters are dangerous or threatening, the general tone is light-hearted. On the other hand, LOTR is about the war between good and evil: it is the war for middle earth. One can scarcely underestimate the gravity of that situation.

All said, I am quite amazed at the detailed work of Tolkien who has gone to extraordinary lengths to bring his fictional world to life. Middle Earth has a very well documented history: wars and legends, legacies left by kings, generations and genealogies, maps, ancient lands, wild characters, magical objects, runes, languages, lores, music, poetry; and all this changing through the times as characters change and their places are taken up by new generations. The chronology almost reads like a history textbook.

A live-action film version was announced on 18 December 2007, to be co-produced by MGM and New Line Cinema, and produced by Lord of the Rings director Peter Jackson. A date of 2011 has been proposed for its release.

 Far over misty mountains cold
To dungeons deep and caverns old
We must away, ere break of day,
To find our long-forgotten gold.

Monday, May 26, 2008

The Enchantress of Florence: Salman Rushdie

Enchantress of Florence

I was told to be wary before picking up a Rushdie book because Rushdie’s works are normally considered very heavy, with challenging prose and long sentences. My friends told me to read one only if I was okay with spending a lot of time with the book. I remembered seeing Rushdie's interview on television several weeks ago when he spoke of his latest novel. He was talking about Jodha being an imaginary character in Mughal history. At that time I did understand the relevance of his statements. I thought it was probably because of the ongoing controversy about Jodhaa-Akbar: the movie.

Half of the story is based in the time of "Akbar the Greatest", in the city of victory – Sikri, while the other half is based in Renaissance Florence - the time of Niccolo Machiavelli. The story is about a lost Mughal princess: an enchantress who is the common thread between these different worlds. Magic and enchantments have a special place in this story and they have been treated very differently from other books based on magic. This is not fantasy fiction. It is historical fiction; in spite of the heavy concentration of enchantments throughout the story. The characters we meet include the Navratnas in akbar's court: Abul Fazl, Birbal, Tansen and the others. Then there is Salim, Badauni and the like.

The character of Queen Jodha is particularly enigmatic because of the magical character ascribed to her. Rushdie does not explain Jodha's character; he leaves it to the reader's imagination. She could either be a product of collective schizophrenia at the insistence of the Emperor’s will; or as a product of the amazing creative powers of the Emperor: The Shelter of the World, the Invincible.

Truly, the character of Akbar is grand. I always admired Akbar as a great king; the grand unifier of Hindoostan, but never before had I imagined his character as he has been shown in this book. From Rushdie's descriptions, you can truly feel the awesome power vested in this man. He is the omnipotent emperor: the man who has the power to do absolutely anything in the world. He can conquer the world; He can bring the perfect woman of his dreams to life from a mere fantasy.

In the other part of the world we have Nicollo Machiavelli and his two friends growing up as young boys in Florence. There are glimpses of Girolamo Savonarola's weepers, whose doctrines are put to end in a blazing fire quite like the "bonfire of vanities”, practised by him and his followers. Only in this case it was Savonarola and his followers who were roasted in the fire. The story traces the fall of the Medici, the creation of the republic, the return of the Medici, the troubled times of Europe, Popes indulging in warmongering etc.

Rushdie's command over the English language is staggering. The prose is convoluted at times, which is quite a characteristic of his writing, but this is certainly not at the expense of readability. Although I took a little more time on this book than others of the same length, I did not quite realize it till I finished the book and sat down to write a review.

A celebration of creative writing. Recommended reading.

Monday, May 05, 2008

Styles on the Login.aspx page

I have been playing around with the ASP.NET login controls lately. After getting the membership and role management framework to work on my website (which is quite a task in itself), I set to figure out some other small things. In this case, I wanted to apply custom styles to the login control on my Login.aspx page.

Doing this is as simple as assigning a class to the CssClass attribute of the Login control and to any sub-controls whose appearance you want to modify.

<body class="Body">

<form id="form1" runat="server">

<div>

<asp:Login ID="Login1" runat="server" CssClass="TextBox">

<LoginButtonStyle CssClass="Button" />

</asp:Login>

</div>

</form>

</body>

</html>

Now I should mention that these classes are contained in a .css file inside my App_Themes/Default/Styles folder.

So in the <head> section of the page, I added the following:

<link rel="stylesheet" type="text/css" href="../App_Themes/Default/Styles/LoginStyles.css" />

Simple enough eh? Wrong!

No matter what I tried, no matter how much I played with the path to the css file, the styles simply won’t be rendered on my page. The same styles get applied if you use them in a <style /> element in the page itself. I was flummoxed.

The thing to note here is that the authorization section in my website is configured as:

<authorization>

<deny users="?"/>

</authorization>

This means that unauthenticated users will not be able to access the website resources: which includes style sheets and/or images on the website!!

So, in order to get this to work, I had to move the stylesheets for the login page and the related images to a separate folder called “AllowAll” and make the following additions to my web.config file:

<location path="AllowAll">

<system.web>

<authorization>

<allow users="*"/>

</authorization>

</system.web>

</location>

Basically this section means that all users (*) should be allowed access inside the “AllowAll” folder, regardless of whether they are authenticated or not.

Then I simply changed the path to my stylesheet on the login.aspx page:

<link rel="stylesheet" type="text/css" href="AllowAll/LoginStyles.css" />

And that did the trick. Woof…so much for authorization!!