Interview Questions Headline Animator

Saturday, August 22, 2009

Dots instead of spaces in Studio 2008 while running test cases…

Well I was running my test cases today and suddenly all my white spaces turned into dots. Yes it creeped the heck out of me.

First thing I thought was to get rid of that. Went to Tools and Options and couldn’t find the setting that would get rid of the nauseating dots.

So I started trying all the shortcut keys. But initially nothing worked. Now Ctrl + R + D happens to be a combination that debugs the tests in context. So I thought the key pattern that enables and disables the visible whitespace feature has to be similar.

Discovery: Ctrl + E + S

Tuesday, August 18, 2009

Left outer join in Entity Framework

This evening I heard someone say that Left Outer Joins are not possible in Entity Framework or perhaps Left Outer Joins are possible, but they bring in all the data and then filter out the right table.

I felt an urge to argue, but I resisted. I thought I would investigate before I waste time. I came up with some articles pretty quickly.

  1. Left Outer Join in LINQ
  2. Left Outer Join using Inverse Navigation Property
  3. DefiningQuery Element
  4. Left Outer Join in LINQ to SQL
  5. LINQ to Entities with Multiple Left Outer Joins

I am sure these should resolve all questions related to Left Outer Joins.

Now about the performance and the question about how the data is brought, I am pretty sure we can prove that LINQ Queries all support deferred execution. But we can always prove that using the SQL Query Profiler.

Hope this helps.

Wednesday, July 29, 2009

Singleton Vs. Static Class

Well I was asked this question once. “What is a singleton design pattern and why should I use it? Why not use a static class instead?”

And it was quite surprising how it went. I said that Singleton is used when you need to maintain state. Static classes are used when you want to club together a bunch of stateless methods that do something irrespective of which instance calls these methods. Math class is a good example.

So he asked me, can I not maintain state in a static class? So I said if you want to instantiate something in a static class how would imageyou do it? And surprisingly he told me that he would do it in a static constructor. I asked him, is it possible to instantiate anything in the static constructor or even declare an instance type in a static class? And he asked me is it not possible? I said it is not as far as I know and he asked me if I am sure.

Now the way the questions were asked about this subject, I was quite surprised. The interviewer looked quite convinced that instance types can be declared in a static class. I am surprised how he was allowed to take the interview in the first place. Or was he checking my confidence?

I wonder.

Monday, July 27, 2009

To query the local object context

When faced with the dilemma that what if I wanted to insert something and before I actually saved the changes into a persistent storage (database) by calling SaveAllChanges() method on the data context, I wanted to do a select, and also I wanted to make sure that this select is done on the just inserted objects, what should I be doing?

Well generally we write a generic method that gets all the records for a generic object. it looks like this:

IQueryable<T> result = null;

string type = typeof(T).Name;

//ObjectQuery query = entities.CreateQuery<T>(type);

ObjectQuery query = Context.CreateQuery<T>(type);

result = (

IQueryable<T>)query;

return result;

This will only query into the database. So if you have just recently inserted some records, but haven't yet committed them, they won’t appear in the results.

However, if we provide another method (an overload perhaps) that handles local objects, this would be possible. When I say local objects, I mean objects that have been inserted into the Object Context and yet not been persisted into the database. this method would look something like this:

IQueryable

<T> result = null;

string type = typeof(T).Name;

return from stateEntry in context.ObjectStateManager.GetObjectStateEntries(EntityState.Added |

EntityState.Modified |

EntityState.Unchanged)

where stateEntry.Entity != null && stateEntry.EntitySet.Name == type

select stateEntry.Entity as T;

This way we give the option to the user of the API to choose which kind of select he wants to fire. A local one or one on the database.

Tuesday, July 14, 2009

Entity Framework, Business Objects and Beyond…

Back during the RMI days, we used to generate skeleton (henceforth referred to as skel or skels) and stubs for all long range service communications… Yes… WCF has its roots there and perhaps further into the past…! Details available here.

Looking at it from an architectural perspective, the data contracts were designed in such a way that the changes are minimal because every change in the stub would have to trickle down all the way to the client.

We have come a long now and Service Oriented Architecture is something that must be considered in any well behaved and decent enterprise application. In an environment such as this, I wouldn’t ever suggest having client dependencies on any 7 letter word starting with an ‘s’ ending with an ‘e’ and having ‘ervic’ in between.

We should think about providing all client apps independence so that any server / database / service changes do not affect the client… to a great extent…

Now there is a big discussion going on across the Internet about whether business objects should be separately created or should we treat EF entities as business objects. After all that’s what they are. Business Objects carry data from the client to the server and back and that’s what EF entities do… really really well… with all those amazing features such as state management, change tracking, yadda yadda… “straight out of the box” as they call it…

“Well couldn’t I agree more. But wait… entities are created from the database right…? using the EF Designer…?”

“Yes… and you could create in a number of other ways…”

“Well… doesn’t that mean that the design of my business objects would be dictated by the database design?”

“Of course not… Hell no… it is not necessary that you have to import all the entities from the database straight… of course you have the choice to customize them… manually…”

“Hmm… That’s nice… so now I can create my business objects with inheritance and everything just as I want them to and then map it to my database… True Object Relational Mapping…”

“Umm… Wait… did you say Inheritance… well you have that exception… you see the entities are already inherited from ObjectContext. And since there is no true multiple inheritance… you have that constraint… At least not in Framework 3.5… I don’t know if that would be available in Framework 4.0 either…”

“Ok… so what if the structure of the entities change…”

“Well all you have to do is regenerate the proxies and you are done…”

“Umm… new proxies…? Do you mean a change in the data contract…? what if I am not consuming the change… Like I have first name and last name in one of my screen and I don’t need the middle name although, i need it somewhere in the server… Do I still have to break the data contract…?”

“Err… Yes…”

Precisely why you should not be using Custom Entities or EF entities as business objects. You might be able to solve all your problems using partial classes and all code customizations… But end of the day, you are breaking the dependency rule.

There’s a reason why they call it a Data Contract.

The solution would be to create a separate business objects layer and then map your business objects with the EF entities. There are a couple of really smart implementations available. One of them could be implementing the Observer Design Pattern so any change could be tracked and reacted to.

Speaking of which I just discovered a good video in which Eric Meijer talks about the Reactive Framework. Definitely worth a watch.

Tuesday, July 07, 2009

“Open in new tab” hangs IE 8

I have been facing this problem for some time, and to tell you the truth, it gets a little embarrassing when if you are trying to show something to a larger group.

All you need to do these days, is Bing it and I got this. But this is with IE 8. Heck I thought why not give it a shot. And what do you know. It works with IE 8 too.

Wednesday, June 03, 2009

Function Import and loading of referenced data

Why do Entity Framework Function Imports do not have eager loading? Because when you use Entity SQL or regular Object context to retrieve data, it is a live connection. So whenever you say eager loading enabled, it gets the data from the database using the live connection. But if you want to do it using Function Import, EF doesn’t know where to get the data from, since the stored procedure that the function import maps to, doesn’t get that data. Perhaps in the later versions of EF, the team might add the feature which can mix and match the object context and the stored procedure to get the required data. But as of now it is not possible.

Saturday, May 30, 2009

Does not have a valid user

“Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects”

You are sitting at home, working on your work laptop, you have a deadline to meet, give an entity relationship diagram for your technical specification document for the module you are working on. So you decide to create a temporary database on your machine itself and then generate a database diagram.

You try to create the diagram and this is the error message you get. You go check the “Files” page of the database properties and it rightly contains your office alias. you refresh it and it still doesn’t work. You think it is some security / privilege issue. You check the Securities tab and everything is in order. It still doesn’t work.

You distinctly remember it to be working when you tried it yesterday at work. It just doesn’t budge now. Wonder what’s wrong.

The problem is you were at work yesterday which you are not now. Meaning you are not on the corporate network and you don’t have the Domain Server available. SQL Server tries to validate your credentials with the Domain Server. It doesn’t find it. If you have any means to get on to your corporate network, like RAS, perhaps, then you should and you will see it will work like magic.

Thursday, May 28, 2009

Xsd to Database

There are times when you have to work with XML. Yes those dreadful times. Specially the times when you get data as XML. And not just master data you sometimes get transactional data in XML. Think about it. How much worse can it get if you had to work with transactional data, and sync it with the database?

I am working on something in that direction. Although I haven’t finalized the approach yet, but it would involve creating an xsd, converting the xsd into datasets and then moving the data into the database.

But have you wondered how you would create a database that is similar to the xsd? Of course you won’t hand code it? Smart developers use smart tools. I found this cool tool that does it all for me. it is called XSD2DB. Isn’t that an intuitive name? It is available download for here.

Tuesday, April 21, 2009

Your user profile was not loaded correctly! You have been logged on with a temporary profile.

This is not a problem that I feel you would encounter on a regular basis. I think I had a unique problem because of which I encountered this one. When you install an operating system it allows you to create a profile. Now I installed the machine at home. Which means I was not on the corpnet of Microsoft which means I could not log on to the domain. So when I created a profile named after my alias, it was considered as a local profile and not a domain profile. And a folder was created under “C:\Users” with my alias name.

I am not sure if this makes any sense or not, but hey, I am a software program writer not a network administrator. So please excuse my jargon. Anyway, when I actually logged on to the domain with my brand new operating system the next day, a new profile had to be created for the domain. Now since there was a folder already with my alias name in “C:\Users” the brand new operating system create a brand new profile with in the format <alias.domain> so now there was a “.” in my profile directory name.

What happens is this “.” sometimes creates problems in installing certain software. I got the error message saying “There is an invalid character in the directory path of My Documents”. I checked the path and could find only one anomaly. And no points (“.”) for guessing what.

So I decided I will rename the profile directory. I straight away went to the directory and though I would rename it to something else. of course it wouldn’t let you. So I thought I would log on as a local administrator and then do it. Also I made sure that I start windows in safe mode.

After Logging on I backup my documents, and delete the profile and assume that the next time I log on, it will automatically create the new directory for me. Guess what… Not that easy…

So after a long research I found out that there are registry entries out of which windows reads the location of the profile directory. So if it doesn’t find the directory at the specified location, it creates a temporary directory and logs you on with a temporary profile. And after the log on is complete, it gives you that message.

So here is what you do to save your life. Please do this only if you have already deleted your profile and did not take backup. If you are doing your research before you have messed with your machine, please skip these steps and refer below.

  1. Log on with local administrator account, preferably in safe mode. To boot the machine in safe mode, Click F8 during boot.
  2. Click Start + Run and type in regedit and then Enter.
  3. Open HKEY_LOCAL_MACHINE
  4. Open Software
  5. Open Microsoft
  6. Open Windows NT
  7. Open Current Version
  8. Open ProfileList
  9. Here you will see keys that belong to each profile. To find your problematic profile navigate to each key and refer to the ProfileImagePath entry on the right hand side.
  10. Once you find your problematic profile, just delete the key. This means delete the folder on the left hand side tree view that contains your alias in the ProfileImagePath entry.
  11. Restart machine.

There is another way you can actually backup your profile and create a new one.

Click on “Start”, Right click “Computer” and go to “properties”

Click on “Change Settings”

image

Go to the “Advanced” tab and click on User Profiles “Settings” button

image

image

“Change type” will allow you to change your profile type between Roaming and Local Profiles

“Delete” will delete that profile. Including the registry entries and everything.

“Copy To” will back up your profile. It is always advisable to backup your profile from here rather than from anywhere else. Your profile contains more than you can see. Hidden Files, System Files, etc. This takes care of everything in a safe manner.

Hope this helps.

Wednesday, January 28, 2009

Are you Eager? Or are you Lazy? Or are you both on a case to case basis...??

Entity Framework, Eager Loading and Lazy Loading, my own 2 cents. For those new to Entity Framework, we are talking about the patterns that you can use to load related objects. The strategy by which you would load entity objects that are related to the one in question. There is a beautiful resource that mentions it all. I do not think there is any elaboration required in that matter. But this is not the meat of the matter.

image How do you design an application that uses Entity Framework as a data access strategy? There are a no. of things to consider. The apparent answer all over the Internet is the Repository Pattern (ref: http://blogs.infosupport.com/blogs/willemm/archive/2008/08/18/Using-ADO.NET-Entity-framework-with-the-repository-pattern.aspx, http://blogs.microsoft.co.il/blogs/kim/archive/2008/11/12/data-access-with-the-entity-framework.aspx, http://www.simonsegal.net/blog/2009/01/13/entity-framework-repository-specifications-and-fetching-strategies/). The purpose of the repository pattern is "A system with a complex domain model often benefits from a layer, such as the one provided by Data Mapper (165), that isolates domain objects from details of the database access code." All said and done, we write the repository to abstract the CRUD from the Application Layer. This way, simply put, we don't need to write separate routines to do CRUD behaviour on every entity type. The functions look something like this:

-------------------------------------------------------------------------------------------

/// <summary>
/// Returns the required querable object to the caller
/// </summary>
/// <typeparam name="T">Generic Object</typeparam>
/// <returns>IQueryable<T></returns>
private IQueryable<T> GetTable<T>()
{
     IQueryable<T> result = null; 
     string type = typeof(T).Name; 
     ObjectQuery query = Context.CreateQuery<T>(type);
     result = (
IQueryable<T>)query;
     return result;
}

This routine is called like this.

////<summary>
////Return all instances of type T.
////</summary>
////<returns></returns>
public virtual IEnumerable<T> All<T>()
{
     System.Data.Linq.
DataLoadOptions dlo = new System.Data.Linq.DataLoadOptions();
     return GetTable<T>();
}

And this in turn is called like this:

public IEnumerable<Employee> GetEmployees()
{
     IEnumerable<Employee> employees = this.dbProvider.All<Employee>();
     return employees;
}

-----------------------------------------------------------------------------------------------------------------------------

Now if you see, we have one function retrieve all types of entity objects. Now let's get to the actual topic in hand. Eager loading and lazy loading. I cannot opt for any of the mentioned patterns, because I do not have the type of the pattern that I am going to return at design time. I have already postponed that by using Generics. Just last night I learnt from Daniel Simmons that Framework 4.0 they are planning to add a property to Context object in order to opt in implicit lazy loading.

While I am still trying to figure out a good way of working around eager loading and lazy loading, as of now (before 4.0 arrives) I am firing separate queries to get all types of related objects. And interestingly, once I fire the queries for the related objects and enumerate them, the principal object at hand gets populated with related objects. So next time you want to reference the related objects, just go ahead and use the beautiful sentence completion features such as this: "txtAddressLine1.Text = employee.EmployeeAddress.First().Address.AddressLine1;"

Thursday, January 15, 2009

StyleCop and Good Code

So you are serious about your code quality huh... well StyleCop is a fantastic tool to ensure that. The best part is, it integrates with Studio 2008. It is simple.

  1. Go to This Location, click on downloads and download the latest version of StyleCop. As of now it is the version 4.3
  2. Install StyleCop. It asks you information about integration. Let it integrate with Studio for the moment.
  3. Fire up Visual Studio
  4. Click on Tools and say Run StyleCop and look at the 1001 warnings that StyleCop gives.

Now when you use StyleCop, most of the warnings are not what you really want to work upon. Like Documentation, for instance, imagewho cares whether there is a blank space line above a comment or not...? So you can go to Solutions Explorer and click on Style Cop Settings. This will bring up the "Microsoft StyleimageCop Project Settings" Dialogue box which will allow you to customize your rules set. Allow you to enable / disable rules as per your own special requirements / whims / fancies / moods... :)

It is a fun little tool and I could have written more about it but then I decided that I won't spoil the fun. You guys go ahead and explore.

Thursday, January 08, 2009

Entity Framework FAQ

Lately everyone in my team and around my bay have been talking about Entity Framework. Well since I have been an early adopter, writing my small apps using Entity Framework and fighting for it on my project, people have been coming to me to ask questions. I have been taking pride in answering them (happy to help), most of the times... until lately... since I have been working on too many things...

I just came across an FAQ which pretty much covers it all (thanks Daniel...!). I thought I will add it to my browser favourites. But then I thought that would just help me and not everyone.

Happy to help... :)

Sunday, January 04, 2009

New year resolutions

  1. Move to domain: Focus more on domain knowledge than on Technicalities. My blog will be filled more with how a technology applies in solving a business problem rather than how to solve a technical problem.
  2. I will track my investments: All these years I have been only investing to save tax. It is mandatory to invest in Insurance linked funds and so I invested. It increased my salary a little bit. I didn't look at it from a returns perspective. After I got married October last year, I was made to realize by my investment savvy wife that saving tax is just not enough. There is potential to make our lives better and that I should. That's another reason why I love my wife so much. She brings out the best in me and makes me want to get better every day
  3. I will cut costs: Yes I have lived a lavish life. Beyond my means, beyond what a sane person should do. This year I will not put money into things that I do not have to. Every extra penny that I have after spending the constant costs, I will save.
  4. I will Make a savings Plan: Every month after I get my salary, approximately 60% of my salary goes directly into Infrastructure costs (big word...!!) Rent, Maid Salaries, car EMI, House hold expenses for mom and dad and household expenses for us are infrastructure costs. The rest of the money is slowly spent over the month on small things such as eating out and such. Since I am not keeping track of where the money is going, I end up spending more. Up-front investment is required. A savings plan is required which gets implemented as soon as I get the salary.
  5. Insurance Policies: Re-activate the LIC policy that became dormant last year. Save for the new annual tax benefit investments on a monthly basis rather than on an annual basis. It is always a fight around December when I have to make the savings towards the end of the financial year.
  6. Gym: Last entire year I was extremely irregular in gym. I need to get back into discipline
  7. Guitar: At least 5 hours of cumulative practice over a week should be good.

Wednesday, December 17, 2008

It's all there in the cloud...!!

So what's this new buzz word... everyone has been talking about it...

Essentially what we are doing is taking our applications and putting them in a cloud. Cloud meaning highly available servers which are provided by huge service providers such as Microsoft, Amazon, etc. Now since I strongly believe that it is business that drives technology, it is the business side that we need to understand first. why do we need it. I have my servers in house, I deploy my apps on my servers, I control and maintain them then why would I want it to be on servers that others control? It is like the analogy that my valuables are in my house, how can it be a better idea to go and put them somewhere else. Well the answer to that question is another question. Do you put all your money under your mattress in your house? Or is it a better idea to go and put them in the bank?

There are many benefits in building the applications from the cloud. Let's take cost for example. The cost of hosting an application on the cloud is just a fraction of what you will have to incur in deploying the application on one of your in-house servers. Along with it comes the maintenance cost. Employing people to maintain the Servers, business continuity planning, and so on and so forth. The list goes on. The Cloud providers on the other hand can provide you all the same services at a fraction of the cost. They work on much much larger scales. So it makes sense for them too.

Another interesting perspective is that, let's say you are an application vendor. You go and talk to a customer to sell your app. Let's say you convince the customer in buying the app. That means you have convinced one person. The person who takes the decisions. Let's say he consults a team before he takes the decision. Even in that case you have convinced that team. And most usually, the people who make the decisions are not the people who end up using your app. And there is no way for them, yet, to find out whether or not the app is good enough for them in their context. So then you go ahead and deploy the app and then start using it. Then the users, find out how much the application was worth in their context and they may or may not like it. Although this is the model we have been working on all these years, it doesn't look like a very effective model does it?

Let's change the scenario. Same application vendor, but this time, he has his application as a software as a service, deployed on the cloud. He just has to go and say, "Well you don't have to guess, I don't have to convince you. Why don't you use the application yourself for a few days and find out?" The users use the app, they like it fine; if they don't, well they don't have to buy it. And of course there is the "pay as you go" model in Software as a service. Just stop paying when you stop using the software.

And the best part is you don't have to go fight it out with your IT for deployment. It's all there in the cloud...!!

Saturday, December 13, 2008

Hot fix for the Entity Framework Bug

I had recently posted about a bug on SQL CE Entity Framework. Please note that the links mentioned in there for the bug and the hot fix are internal to Microsoft. The hot fix shall be released as a KB article in a couple of weeks.

Wednesday, November 26, 2008

SQL Server Compact Edition / Entity Framework bug

I am working on this really smart, smart client application installer. Which smartly installs other pieces of another smart client application as and when required.

It makes sure that only those bits are downloaded that are not already installed. So it takes care of upgrades on its own. So basically we are writing our own "ClickOnce" functionality.
Why are we not using ClickOnce out of the box? Well that would require another post, but let's say we require much more granularity than what "ClickOnce" provides us, on this "Installation Manager", and put it at that.

Anyways, I am doing some book keeping using SQL Server CE on the client machine to maintain account of upgrades and installations. For this I am querying the SQL Server CE database and in the process and I encounter an error that says:

"The ntext and image data types cannot be used in WHERE, HAVING, GROUP BY, ON, or IN clauses, except when these data types are used with the LIKE or IS NULL predicates."

I am not even working on ntext data type. The select query goes something like this:

IQueryable files = entities.FileInfo.Where(fileInfo => fileInfo.FileName.Equals(fileName));

And "FileName" is not an ntext datatype in the entity "fileInfo". It is an nvarchar.
Interestingly, if you fire the same query on the Management Studio (SQL Version of the query of course), it works fine. It only breaks when you use LINQ to SQL or EF.

After a little research I find out that there is a bug in SQL Server 3.5 RTM which was incidentally not resolved even in the "SQL Server Compact 3.5 SP1 English". And later there was an out of the bag release that was made to resolve this issue. So the Hotfix, cannot be installed directly. You need to uninstall "Microsoft SQL Server Compact 3.5 SP1 English" from Add Remove Programs before you install this hotfix.

Once the Hotfix is installed, your query will just work...!

In case if you are wondering whether you need to re-install "Microsoft SQL Server Compact 3.5 SP1 English"? Well, installing it back will remove the hotfix. So DO NOT DO THAT.

Sunday, November 23, 2008

Best RSS Feed Reader

My wife is a writer, and a pretty good one for that matter. Recently she went for a job interview, where she was asked a lot of questions about current affairs, and she doesn't exactly read the news regularly. So I told her she should. But she doesn't like reading the news paper, and I told her about online news. About RSS Feeds and Feed Readers.

So which feed reader do you use. Of course every developer uses one. So what else does a developer use? Internet Explorer and Microsoft Outlook. Post Internet Explorer 7, you can subscribe to RSS Feeds using IE. you can read the posts online on IE. But the beautiful thing is every time you subscribe to a feed on IE, it nicely goes and adds itself on the RSS Feeds folder in Microsoft Outlook. This gives you the offline reading facility of course it also depends on what you are subscribing to. Some of the stuff is just not available offline. Like MSDN Magazine, which just has a one liner and a link to the actual article.

Speaking of which, MSDN Magazine is available online since January 2008. The MSDN Magazine is a fantastic read and is on top of my reading list every month. Some of the articles are just too good. Like for instance, this month my favorites are: The editor's note (which is always a pleasure to read), Thread Management in the CLR, Design for testability, Static Analysis tools for .Net.

Other favorites on my feed reader are:

  1. Ann-Dee's Tic-Tacs (My wife's weblog)
  2. Stack Overflow
  3. Threads watched by Channel 9 Team
  4. Business Week Online - Tech Beat

Wednesday, November 19, 2008

Downloading and installing AdventureWorks Database

I am assuming that you want to write a prototype of some sort for which you want a sample database to work with. And I am assuming that you don't have AdventureWorks on your machine. Putting down quick set of steps:

  1. Go to http://www.codeplex.com/MSFTDBProdSamples/Release/ProjectReleases.aspx?ReleaseId=4004
  2. Click on AdventureWorksDB.mdi, in case you are looking for the AdventureWorks Database for SQL Server 2005. there are also other sample databases available. This post is specifically for the AdventureWorks database for SQL Server 2005
  3. Accept the Agreement
  4. Download and run the installable.
  5. Open Visual Studio Command Prompt.
  6. Type in SQLCMD and press enter
  7. Type in the command
    "exec sp_attach_db @dbname=N'AdventureWorks', @filename1=N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Data.mdf', @filename2=N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_log.ldf'"



  8. Please note that the Drive could be either C:\ or D:\ depending upon where you have installed the AdventureWorks Database MSI.



 



This will attach the AdventureWorks database. Fire up SQL Server Management Studio and confirm whether Adventure Works exists or not.

Saturday, November 15, 2008

The Sleeping Giant...

I am going to talk about the experience that I went through recently, when I met with a quite dangerous accident. It could have been quite fatal, fortunately, it wasn't. This post is going to be starting from around 2 seconds before I met with the accident to about 5 minutes after the accident. photo

on the 14th of November 2008, around 11.45 AM, I was going to work on my motorcycle. You see there are these lorries that haul huge stones from the stone quarries to wherever they take them, and the lorry drivers are very careless. They never abide the traffic rules. One such lorry driver was driving on the opposite direction and he suddenly decided that he needs to take a 'U' turn, and he did, just 10 or so meters ahead of me. I was driving around 80 Kilometers an hour and didn't have enough reaction time. I applied both the brakes simultaneously, bringing the bike down to around 60 kilometers an hour, and had a head on collision with the lorry. The bikes front went under the lorry I collided with the lorry head on. This is what happened.

The things that went through my mind during those 2 seconds before the collision and 5 minutes after, were quite profound. Now that I reflect upon it, it tells me about the stupendous processing power of the brain, when it is under stress. If only we could channel this power in a productive way. There were important things, and then the silliest things too. I cannot remember the exact sequence of things that my brain ran through, but I will try to list them down, at least as many as I remember (of course I don't remember everything).

So first when I see the lorry coming in, I think.

photo1"What's this guy doing? Is he crazy?"

"Should I just brake or should I turn left? Oh but there is this car and a bike on my left, I can't turn."

"Good I have disk brakes in the front. I won't fall and go under"

"Thank God I am wearing a helmet. I think it should be able to reduce the impact"

"Should I consider turning right?"

"I can't see what's coming from the opposite side."

"Dang... the driver is getting off to run already...!!!"

So that's when I realize that nothing can be done and that the collision is going to happen at a very high speed. That's when I give up and think,

"This month the finances were already down... How am I going to repair the bike..."

"My bike is not registered in Hyderabad. If I launch a complaint with the police, they will confiscate the bike and I would have to pay the road tax to get my bike back."

"I hope my laptop doesn't break, I will have to wait 2 or 3 weeks to get a new one. And I have my external hard drive in the bag. All the data is in it."

"I don't want to be perennially injured. Dang... that would be bad."

"I just got married I have to save myself."

"I had to finish the Click Once API Prototype today. Gone...!!!"

"Shit...! I wish I hadn't sold my car...!"

Now the collision happens...!!! And this is the most interesting part... the bike collides, I fall off and after that the bike goes under. Since the driver has already jumped off the lorry before the collision and run, the lorry slowly climbs over my bike and crushes it. The pictures are after the lorry climbs over the bike. Now the collision was at, at least 60 kilometers an hour so it is hard. I have hit the lorry with my head and chest. You can't imagine the power of the impact. After I fall off, the first thing I do, instinctively is get up. On standing up, I realize that I can't breathe. I feel my lungs are pushed deep into my chest and it pains when I laboriously try to pull in dear oxygen. It takes me around 7 to 10 breaths to pull in oxygen and get my breathing back to normal. During this time my head is going bonkers.

"My wife is going to really scream at me. I better not tell her before I reach home."

"Nothing is going to happen to me. I belong to the demonic tribes of Banasur, Narakasur and Babrubahan. And they were wicked difficult to kill."

"Heck I have been pushing weights in the gym for over 15 years now. This impact isn't going to do me nothing."

"I have to start breathing and then turn around and look at my bike. I have to analyze the damage and the expense this is going to cause me."

"Dang... I tore my jeans... Will have to buy a new one..."

"Oh but the oxygen first... breathe... breathe..."photo2

About 10 seconds later I breathe normally, turn around and look at my bike... I am standing on my legs, firm and strong. I can feel pain in my chest, my shoulder and my right upper thigh, very very close to my genitals. Heck I  just got married, I have to think about everything. I press my chest and see if I feel any sting, to find out if there are any bones broken. Nothing broken. I turn my neck around and check for my spine. No pain there. I take a little jab at my groin. The skin burns, but no internal pain... thankfully. All this time my 10 kg heavy laptop bag is on my back. I offload it carefully. People have started gathering all around me. I cannot see my bike any more because of the crowd. Someone gets me water and 3 people are asking me to sit down on a rock nearby. One local fellow with black clothes on comes to me and gives me an IPhone. He says some "Reddy" wants to talk to me. I take the phone and find out it is Koti. He asks me how I am. dang...! it wasn't more than a minute or perhaps a minute and a half after the collision. How did he find out? I see Pavan from the mailroom. He takes control of the situation. He calls the Ambulance, the police, and picks up my laptop bag. While all this is happening, I am thinking.

"How do I take out my bike before the police arrives?"

"I don't want the police to confiscate my bike."

"I don't think I have the strength to pull my bike out from under the lorry."

"I have to go home to my wife before she comes to know about this whole thing from someone else."

"But I can't leave the bike here. I have to get out of here with the bike."

"Nothing has happened to my hands. I think I will be able to code from home."

"Thank God Ma isn't here. She would have gotten awfully worried looking at me limp."

"Where's my phone? I hope my phone isn't broken."

That's when a guy comes to me and gives me my phone. And I am relieved to see that it isn't broken. Pavan tells me that he will take care of the bike. I get on to the ambulance and they suggest I go to Apollo Hospital and do at the checks.

At Apollo, all the checks are done later and I find out that no bones are broken, and that my diaphragm and liver, which were just under the point of impact are fine. The doctor tells me that I am a strong man and my gym workouts saved me. My friends Vikas and Rajesh come over to the hospital and take me home later in the evening.