Tuesday, April 27, 2010

HTTP Headers are a multi-map

RFC 2616:
Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma.
Today, I found and fixed a cool bug in the AmazonCloudFront client for .NET. The original implementation of the client used the System.Net.WebHeaderCollection.Add() method to specify headers for a CloudFront request. An example of one of the request headers is If-Match - this header uniquely identifies a CloudFront distribution, and the value associated with this header is the ETag specified for the request.

Using the Add method is fine if a new request object is created for every CloudFront request; the issue arises when an attempt is made to reuse an existing SetDistributionConfigRequest object to perform another CloudFront request, albeit with new parameters. In the reuse case, the new header values will be appended to the existing headers' values.

Let's take the case of If-Match: when the request was sent over HTTP, CloudFront received a comma-separated value for If-Match containing all the ETags specified during the lifetime of the request object. When CloudFront received this string, it couldn't verify the identity of the distribution, and rejected the request.

The fix: Use the WebHeaderCollection's [] accessor to set a unique value for every request header. Fixing this bug makes it now possible for the same request object to be reused for multiple calls.

Friday, April 02, 2010

Critiquing the iPad, and getting it wrong!

I like Cory Doctorow, especially his unique take on technology and all things geek. In fact, Boing Boing was the first RSS feed I subscribed to, ever! His latest piece on why he dislikes the iPad is a miss though; he doesn't get some basic tenets of why the iPad will succeed.
if you can't open it, you don't own it.
I consider myself to be quite the technophile, but when it comes to unscrewing the back off my laptop and fiddling with its innards, I *seriously* consider my alternatives. Most people that own computers panic when it runs slowly, panic even more when they get a Virus alert, and suffer a melt-down when their computer crashes or their hard drive fails. You think the average computer owner can bring out their screwdriver set and start tinkering with their computer? A laptop or desktop, as open as a hardware platform as can be, is still very intimidating to a regular Joe.

The iPhone was criticized for being a closed hardware and software platform. Did this stop the really inclined tinkerers from peeking inside and figuring out how these devices worked? No! For proof of this phenomenon, you don't have to go farther than Mumbai's grey market. For a very fair price (10 - 20 US$), you can pick from a number of "technicians" who can open your iPhone, replace your battery, tweak the hardware settings on the LCD, jailbreak the device, et al. Mumbai, Delhi, Moscow, Seattle - hardware geeks everywhere know everything they need to repair an iPhone, to hack an iPhone, to replace the software on the iPhone. What's that about not being able to customize the device?
The way you improve your iPad isn't to figure out how it works and making it better. The way you improve the iPad is to buy iApps. Buying an iPad for your kids isn't a means of jump-starting the realization that the world is yours to take apart and reassemble; it's a way of telling your offspring that even changing the batteries is something you have to leave to the professionals.
Isn't that what you do with a car, or a TV, or a DVD player, or a clock radio, or ... Why is this a bad thing? Why is it such a blasphemy that a device is locked down so as to enable scenarios that make it simpler to use and interact with than any other device available? In this age of information overload, the iPad offers me the ability to never have to learn how to make it work other than pressing its power button. Brain cells saved only to be wasted on something else that might help me find a job or improve my life!

What made me write this post though was this paragraph:
But with the iPad, it seems like Apple's model customer is that same stupid stereotype of a technophobic, timid, scatterbrained mother as appears in a billion renditions of "that's too complicated for my mom" (listen to the pundits extol the virtues of the iPad and time how long it takes for them to explain that here, finally, is something that isn't too complicated for their poor old mothers).
My mother isn't stupid, but she does struggle with using a computer. When did our measure of stupidity become proficiency with a computer? My mother could whoop most people's behinds when it comes to most things not related to using her computer; that she can't use her computer is not so much her fault as it is the fault of Microsoft or Apple or the other software makers. But I would buy the iPad for her, like I would buy an iPhone for her. She took to my iPhone and my Macbook Pro like a duck takes to water. In fact, my mom doesn't know how to use Copy/Paste and until a few days ago, didn't even think she needed such functionality!

April 3rd is tomorrow, and let me tell you something - the iPad will sell, and the 2nd version of the device will outsell its predecessor, and so on. When I used to walk around the 1st Gen iPhone, my friends used to mock me. These same friends now connect to the world with said iPhone. We have severe technological amnesia - being critical of something today doesn't preclude owning the thing tomorrow (or a year from now). I hope Cory wakes up and smells the coffee at some point; the rest of us common folk have already seen the light.

Friday, March 26, 2010

Mobile platform multi-tasking revisited

Everyone is clamoring for multi-tasking on their mobile smartphones. android has it, windows mobile has it but the iPhone and the new dangle windows phone 7 don't. This isn't that hard of a ponlem to solve you would think, but it really is. Reason - constrained resources on the phone and no good user interaction model for users to kill rogue applications.

The biggest issue with multi-tasking on phones though is reduced battery life. Right now, my iPhone barely gives me 5 hours of usage; I shudder to think what my battery life will reduce to once multi-tasking becomes du jour. Single-tasking is plain not good enough because switching to another app means all context is lost in the current app. There are times when I am listening to an episode of fresh air in my browser and the phone rings - bam, need to start the episode from scratch! So we are at an impasse, unless...

Yes, there is a third solution; an idea which is more of a hybrid approach - application hibernation. Switching to another app puts the current app into a form of suspended animation, kinda like the pause button for media playback. The application's state is saved to persistent storage and room is made for the new application. It would be trivial to provide a list of "suspended"/paused applications, with a cool ui that allows a user to literally press Play on the application they want to turn "On". It's going to be really interesting to see what strategy the 3 leading mobile platforms will adopt.  

Tuesday, March 23, 2010

Is High Fructose Corn Syrup good for you? The debate rages on...

I happened to switch on the TV last Thursday around the time of ABC’s nightly news programme. Under normal circumstances, I would have switched to a recorded program or to another channel, but the story being featured was on the deleterious effects of Fructose on our body. It turns out that the food industry has been lying to us, repeatedly; imagine my shock and horror! Even food dubbed healthy is full of fructose – probiotics, fruit juice, yoghurt, Special-K; the list is endless. Unlike sucrose, fructose tampers with the body’s Leptin production , which results in the lack of appetite regulation (we continue to feel hungry even after our body has received the necessary nutrients).

Of course, the Corn Growers lobby in Washington was also mentioned. Corn is pure starch, and it is the most abundant crop in America; some Corn in my food is to be expected. Was it really *some* thought? I had to know exactly how prevalent the grain was though, so I conducted a small “Corn” experiment this weekend at the grocery stores I frequent. I have a list of maybe 20 items I buy on a regular basis – some from Safeway but most from Trader Joe’s. I went down my list and read through the ingredients of the processed foods (including the unfrozen kind) - mostly juice, yoghurt, cereal, veggie patties, peanut butter pretzels, etc. It’s hard to get exact amounts of individual ingredients, so I just put a check against items that contained Corn or Fructose on the list; my findings were eye-opening!

Regardless of provenance and seller, about 75% of all processed food I purchase contain corn in one form or another (syrup, powder or whole). Fructose came in at a slightly lower 54%, the remaining 46% contained sugar. You should know this – I am a careful, anal even, shopper and read the ingredients before buying anything. Even I haven’t staved off the corn growers onslaught on my system. I guess the cost of healthy eating is a lifetime of vigilance.

What am I going to do now that I have this information? My findings suggest I need to eat more real food, less fruit juice, more fruit pulp, and cook more. I’m going to see how long this latest revelation makes me cook fresh meals before I succumb to the convenience of packaged food. Stay tuned.

Saturday, March 20, 2010

Being profligate in a recession - NYC sports teams

In this time of recession, it seems profligate, reckless even, for American sports teams to be erecting billion dollar pantheons for their respective sports. Take the professional baseball and football teams of New York City for instance.
At the same time, the Jets and the Giants are moving to yet another new stadium in the Meadowlands, which will replace a perfectly good Giants Stadium, to accommodate shrimp-and-wine tastes. The new place will still hold major soccer matches, particularly if the United States is chosen to host the 2018 or 2022 World Cup.
Parts of the world are so in debt and in need of funds that people don't have enough to put two square meals on the table. These teams are/were playing in perfectly functioning stadiums and ball parks; such excess!

Friday, March 19, 2010

System.Uri constructor makes the host lower-case

I stumbled upon this cool property of the System.Uri class today; the .NET Framework's Uri class knows that DNS names are case-insensitive. If you pass a string to a Uri constructor with mixed or upper case letters, the constructor will make the DNS/host part of the string lower-case.

So,

Uri uri = new Uri("http://WWW.YAHoo.com/FoO");
Console.WriteLine(Uri.Host);
will print: "www.yahoo.com"

Console.WriteLine(uri.AbsolutePath);
will print: "FoO"

Thursday, March 18, 2010

Apple might be setting itself up for a Mobile Search Fail

APPLE and Google remain partners in certain areas. Google pays Apple millions of dollars annually to make its search engine the default on Apple’s Web browser, on the iPhone and soon, perhaps, on the iPad.

But there is wide speculation in technology circles that Apple is preparing to give Google a public black eye: by making Microsoft’s offering, Bing, the preferred search engine on the iPad, and perhaps even on the iPhone. One Apple employee says that Qi Lu, the president of Microsoft’s online services division, was recently seen visiting Apple’s campus in Cupertino to discuss such a deal. Microsoft declined to comment.
At the time of this writing, there is no physical device that runs Windows Phone 7 Series, but the initial buzz around the new platform and devices is frenzied. The devices are going to have an application store and an SDK out of the gates, and all of the Windows 7 phones will have Bing as their default search engine. If the platform catches on, and Android continues its onward march at the steady clip it is today, the default search engine on Apple will no longer be a priority for either Google or Microsoft. Why would either of the two companies pay a third almost a billion dollars to feature its search engine on *another* mobile phone platform?

Thinking about this some more, Microsoft might still make such a deal with the *perceived* devil, simply because it is the underdog in search. So yes, Apple will give Google a black eye, but really, will it even make a dent in Google's armor? In true Google style, it might just yank out the blackened eye and replace it with another commodity eye it bought for cheap on the open market!