<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>lalit.org</title>
	<atom:link href="http://www.lalit.org/feed" rel="self" type="application/rss+xml" />
	<link>http://www.lalit.org</link>
	<description>Personal page of Lalit Patel, an engineer, entrepreneur, geek from Bhubaneswar, India.</description>
	<lastBuildDate>Thu, 03 Jun 2010 05:23:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ternary nuances in PHP</title>
		<link>http://www.lalit.org/lab/ternary-operator-nuances-in-php</link>
		<comments>http://www.lalit.org/lab/ternary-operator-nuances-in-php#comments</comments>
		<pubDate>Tue, 18 May 2010 08:20:31 +0000</pubDate>
		<dc:creator>Lalit</dc:creator>
				<category><![CDATA[lab]]></category>

		<guid isPermaLink="false">http://www.lalit.org/?p=408</guid>
		<description><![CDATA[Yesterday while working on one of my projects, I came across a weird scenario: a very simple statement written in PHP was not behaving the way it should.
Below is the simplified version of the code I was working with:

$i = 1;echo $i == 1 ? 'One' : $i == 2 ? 'Two' : 'Three';

At first [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday while working on one of my projects, I came across a weird scenario: a very simple statement written in PHP was not behaving the way it should.</p>
<p>Below is the simplified version of the code I was working with:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><ol><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span> ? <span style="color: #0000ff;">'One'</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">2</span> ? <span style="color: #0000ff;">'Two'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'Three'</span><span style="color: #339933;">;</span></div></li></ol></pre></div></div>

<p><span id="more-408"></span>At first glance, it is obvious that the output of the above code should be &#8216;<strong><code>One</code></strong>&#8216;, but the output here is &#8216;<strong><code>Two</code></strong>&#8216;.</p>
<p>After RTFM, I came to know that PHP <a rel="nofollow" href="http://www.php.net/manual/en/language.operators.comparison.php" target="_blank">recommends</a> that we avoid &#8220;stacking&#8221; ternary expressions. PHP&#8217;s behaviour when using more than one ternary operator within a single statement is non-obvious. The above expression will be evaluated as following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><ol><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">// a more obvious version of the same code as above</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span> ? <span style="color: #0000ff;">'One'</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'Two'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'Three'</span><span style="color: #339933;">;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">// here, you can see that the first expression is</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">// evaluated to 'true', which in turn evaluates to</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">// 'One', thus returning the true branch of the</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">// second ternary expression.</span></div></li></ol></pre></div></div>

<p>Correct representation that produces the expected result is:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><ol><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span> ? <span style="color: #0000ff;">'One'</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">2</span> ? <span style="color: #0000ff;">'Two'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'Three'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></li></ol></pre></div></div>

<p>I wonder why developers would leave a feature in the langauge that is ambiguous or not obvious. Has to be a very good reason. But this scenario is a rare one, at least I stumbled across (or noticed) this case for the first time.</p>
<p>Have you come across any other such nuance in PHP?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lalit.org/lab/ternary-operator-nuances-in-php/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Clever Google Ad Hack</title>
		<link>http://www.lalit.org/blog/clever-google-ad-hack</link>
		<comments>http://www.lalit.org/blog/clever-google-ad-hack#comments</comments>
		<pubDate>Sat, 31 Oct 2009 09:59:25 +0000</pubDate>
		<dc:creator>Lalit</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[ads]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[hacks]]></category>

		<guid isPermaLink="false">http://www.lalit.org/?p=391</guid>
		<description><![CDATA[
Notice how they use the ad title as a part of the image.
]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-392 alignnone" style="border: 1px solid #ccc;" title="Google Chrome Ad on Facebook" src="http://www.lalit.org/wordpress/wp-content/uploads/2009/10/innovative-ad-hacks.png" alt="Google Chrome Ad on Facebook" width="242" height="229" /></p>
<p>Notice how they use the ad title as a part of the image.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lalit.org/blog/clever-google-ad-hack/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Vacation Relaxation?</title>
		<link>http://www.lalit.org/blog/vacation-relaxation</link>
		<comments>http://www.lalit.org/blog/vacation-relaxation#comments</comments>
		<pubDate>Wed, 30 Sep 2009 17:28:20 +0000</pubDate>
		<dc:creator>Lalit</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[comics]]></category>
		<category><![CDATA[humor]]></category>

		<guid isPermaLink="false">http://www.lalit.org/?p=388</guid>
		<description><![CDATA[
exactly how I feel  
]]></description>
			<content:encoded><![CDATA[<p><a href="http://phdcomics.com" rel="nofollow"><img src="http://www.lalit.org/wordpress/wp-content/uploads/2009/09/phd092809s.gif" alt="phd092809s" title="phd092809s" width="600" height="384" class="alignnone size-full wp-image-387" /></a><br />
exactly how I feel <img src='http://www.lalit.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.lalit.org/blog/vacation-relaxation/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Looking for Geek Ninjas</title>
		<link>http://www.lalit.org/blog/looking-for-geek-ninjas</link>
		<comments>http://www.lalit.org/blog/looking-for-geek-ninjas#comments</comments>
		<pubDate>Wed, 22 Jul 2009 16:13:03 +0000</pubDate>
		<dc:creator>Lalit</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[bitrhymes]]></category>
		<category><![CDATA[jobs]]></category>
		<category><![CDATA[startups]]></category>

		<guid isPermaLink="false">http://www.lalit.org/?p=376</guid>
		<description><![CDATA[
There is always so much to do in a startup that people won&#8217;t be too picky about your paper qualifications, if you can solve problems for them without screwing up.
&#8211; Paul Graham
My startup BitRhymes is looking for such talented guys.
BitRhymes prides itself in its flat organization structure and comprising brilliant and enthusiastic minds. You will [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" title="We are Hiring" src="http://www.bitrhymes.com/www/res/imgs/hiring.png" alt="" width="200" height="178" /></p>
<blockquote class="quote"><p>There is always so much to do in a startup that people won&#8217;t be too picky about your paper qualifications, if you can solve problems for them without screwing up.</p></blockquote>
<p>&#8211; Paul Graham</p>
<p>My startup BitRhymes is <a href="http://www.bitrhymes.com/www/bt.careers.php">looking for</a> such talented guys.</p>
<p><span id="more-376"></span>BitRhymes prides itself in its flat organization structure and comprising brilliant and enthusiastic minds. You will be working on innovative, fun ideas that are used by millions of users world wide using some of the most cutting edge technologies in the Web 2.0 arena. The work you do will have a global reach, imagine changing a line of code that makes an immediate impact to a million people world-wide. Unlike normal outsourcing companies, you don’t throw away petty websites after developing them, you develop applications that are live and breathing.</p>
<h3>Open Positions</h3>
<ul>
<li><a href="http://www.bitrhymes.com/www/bt.careers.php#p1">Sr. Actionscript/Flash Developer</a></li>
<li><a href="http://www.bitrhymes.com/www/bt.careers.php#p2">LAMP Platform Developer</a></li>
<li><a href="http://www.bitrhymes.com/www/bt.careers.php#p3">Asst Producer / Game Concept Developer</a></li>
<li><a href="http://www.bitrhymes.com/www/bt.careers.php#p4">QA Engineer</a></li>
</ul>
<h3>Benefits include:</h3>
<ul>
<li>BEST pay package for the right candidate.</li>
<li>Working with cutting edge technology.</li>
<li>Being part of a small team. No corporate bullshit.</li>
<li>Flexible work hours and Fun workplace.</li>
<li>We will even pay for your home internet connectivity.</li>
</ul>
<p>If this excites you, <a href="http://www.bitrhymes.com/www/bt.contact.php">contact us</a> or drop a mail with your resume to <a href="javascript:;">ninjas (at) bitrhymes (dot) com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lalit.org/blog/looking-for-geek-ninjas/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nandan Nilekani, the proudest Indian in the world.</title>
		<link>http://www.lalit.org/inspiration/nandan-nilekani-the-proudest-indian-in-the-world</link>
		<comments>http://www.lalit.org/inspiration/nandan-nilekani-the-proudest-indian-in-the-world#comments</comments>
		<pubDate>Sat, 27 Jun 2009 13:32:00 +0000</pubDate>
		<dc:creator>Lalit</dc:creator>
				<category><![CDATA[inspiration]]></category>
		<category><![CDATA[government]]></category>
		<category><![CDATA[india]]></category>
		<category><![CDATA[industry]]></category>
		<category><![CDATA[leader]]></category>

		<guid isPermaLink="false">http://www.lalit.org/?p=327</guid>
		<description><![CDATA[Quoting the TOI:
He’s been a poster boy of Indian infotech, co-founded a company that has become a byword for participative entrepreneurship, given Thomas Friedman the idea for the bestselling ‘The World Is Flat’, and himself penned a book, ‘Imagining India’.
And now, at the age of 54, his shareholding in Infosys alone worth Rs 3,500 crore, [...]]]></description>
			<content:encoded><![CDATA[<p>Quoting the <a href="http://colonp.tumblr.com/post/131127524/nandan-nilekani-the-proudest-indian-in-world-on-26th" target="_blank">TOI</a>:</p>
<blockquote><p><a href="http://www.lalit.org/wordpress/wp-content/uploads/2009/06/n2.jpg"><img class="alignleft size-medium wp-image-332" style="margin-right: 10px;" title="Nandan Nilekani. (TOI Photo)" src="http://www.lalit.org/wordpress/wp-content/uploads/2009/06/n2.jpg" alt="" width="200" height="275" /></a>He’s been a poster boy of Indian infotech, co-founded a company that has become a byword for participative entrepreneurship, given Thomas Friedman the idea for the bestselling ‘The World Is Flat’, and himself penned a book, ‘Imagining India’.</p>
<p><span id="more-327"></span>And now, at the age of 54, his shareholding in Infosys alone worth Rs 3,500 crore, Nandan Nilekani has taken on one of the most ambitious government programs ever envisaged: heading the project to equip every Indian with a biometric <a href="http://nprindia.blogspot.com/2009/06/all-about-nilekanis-uid-project.html" target="_blank">Unique Identification Card</a>.</p>
<p>This is the biggest movement from private sector to government in India in re-callable memory.</p></blockquote>
<p>Back in College when we used to have those personality development classes, each one has to come up and say what they wanted to achieve in their lives. That was one question I hated to answer, not because I didn&#8217;t have an answer to that, because how hard I try, I was not able to put the point clearly in front of the class. I used to say, <em>&#8220;I want to be Computer Scientist and I want to do something that impacts people lives, enriches them. To do something makes my family and my country proud.&#8221;</em> That &#8217;something&#8217; here was very vague to describe, no popular example to put forth.</p>
<p>Today, I have a one word to describe that, <strong>Nilekeni</strong>.</p>
<p>Personally, there can be nothing bigger than the Mr. Prime Minister of India himself calling you up and giving you an offer to serve the country. That is the ultimate respect I can ask for. In my opinion he did the right thing accepting the offer. An inspiration to both current and future leaders.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lalit.org/inspiration/nandan-nilekani-the-proudest-indian-in-the-world/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Vanity</title>
		<link>http://www.lalit.org/blog/vanity</link>
		<comments>http://www.lalit.org/blog/vanity#comments</comments>
		<pubDate>Sat, 13 Jun 2009 05:56:25 +0000</pubDate>
		<dc:creator>Lalit</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[geek]]></category>

		<guid isPermaLink="false">http://www.lalit.org/?p=322</guid>
		<description><![CDATA[ Couldn&#8217;t help my geek ego,
grabbed it right at 9.31am IST 
http://www.facebook.com/lalitpatel
]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="Facebook" src="http://profile.ak.facebook.com/object3/1310/46/n20531316728_2397.jpg" alt="" width="49" height="49" /> Couldn&#8217;t help my geek ego,<br />
grabbed it right at 9.31am IST <img src='http://www.lalit.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<a href="http://www.facebook.com/lalitpatel">http://www.facebook.com/lalitpatel</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lalit.org/blog/vanity/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>If you don&#8217;t give a damn or you don&#8217;t understand&#8230;</title>
		<link>http://www.lalit.org/inspiration/if-you-dont-give-a-damn-you-dont-understand</link>
		<comments>http://www.lalit.org/inspiration/if-you-dont-give-a-damn-you-dont-understand#comments</comments>
		<pubDate>Thu, 12 Feb 2009 21:48:55 +0000</pubDate>
		<dc:creator>Lalit</dc:creator>
				<category><![CDATA[inspiration]]></category>
		<category><![CDATA[lyrics]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[song]]></category>

		<guid isPermaLink="false">http://www.lalit.org/?p=292</guid>
		<description><![CDATA[You can cry all you want but your cry wont get you no where;
You can run all you want but your mind wont get you no where;
You can scream all you want but your scream wont get you no where;
You can dream all you want &#8216;coz your dream might get you somewhere.
If you don&#8217;t give [...]]]></description>
			<content:encoded><![CDATA[<p>You can cry all you want but your cry wont get you no where;<br />
You can run all you want but your mind wont get you no where;<br />
You can scream all you want but your scream wont get you no where;<br />
You can dream all you want &#8216;coz your dream might get you somewhere.</p>
<p>If you don&#8217;t give a damn or you don&#8217;t understand, its like you going nowhere.<span id="more-292"></span></p>
<p>Live your life like you care for something, anything, the real thing!<br />
What does it mean to you? How does it feel to you?</p>
<p>If you don&#8217;t give a damn or you don&#8217;t understand, its like you going nowhere.</p>
<p><strong>—The Freelance Hellraiser<br />
</strong></p>
<p><a href="http://www.lalit.org/wordpress/wp-content/uploads/2009/02/freelance_hellraiser.jpg"><img class="alignnone size-medium wp-image-293" title="Waiting for Clearance" src="http://www.lalit.org/wordpress/wp-content/uploads/2009/02/freelance_hellraiser-300x300.jpg" alt="" width="300" height="300" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lalit.org/inspiration/if-you-dont-give-a-damn-you-dont-understand/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting most out of Amazon S3</title>
		<link>http://www.lalit.org/lab/setting-cache-headers-files-in-amazon-s3</link>
		<comments>http://www.lalit.org/lab/setting-cache-headers-files-in-amazon-s3#comments</comments>
		<pubDate>Sun, 02 Nov 2008 10:19:35 +0000</pubDate>
		<dc:creator>Lalit</dc:creator>
				<category><![CDATA[lab]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[s3]]></category>

		<guid isPermaLink="false">http://www.lalit.org/?p=259</guid>
		<description><![CDATA[Amazon S3 is a very useful service. S3, according to the official Amazon Web Services website is
Amazon S3 is storage for the Internet. It is designed to make web-scale computing easier for developers.
Its a no frills service and does exactly what it promises &#8212; makes it easy for developers so that they can concentrate on [...]]]></description>
			<content:encoded><![CDATA[<p><a rel="nofollow" href="http://aws.amazon.com/s3">Amazon S3</a> is a very useful service. S3, according to the official Amazon Web Services website is</p>
<blockquote><p>Amazon S3 is storage for the Internet. It is designed to make web-scale computing easier for developers.</p></blockquote>
<p>Its a no frills service and does exactly what it promises &#8212; makes it easy for developers so that they can concentrate on features and leave the scaling to Amazon. If you are new to Amazon S3, heres a good <a href="http://www.labnol.org/internet/host-images-files-on-amazon-s3-storage/4923/">starting guide</a> for you.</p>
<p>S3 is like a sharp sword, you must know how to play with it lest you can hurt yourself. Thats exactly what happened to me. <span id="more-259"></span>One of the many applications that we are developing on MySpace, <a href="http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=104651">Sketch Me</a>, required us to store (and serve) huge amount of image data (user sketches). And due to the viral nature of the application, the load almost tripled every month. S3 was a clear choice. It saved us time, money and headache. Our current stats (with caching) are:</p>
<ul>
<li>Total files stored: <strong>205GB</strong></li>
<li>Bandwidth per month: <strong>2TB</strong></li>
<li>GET Requests per month: <strong>112m</strong></li>
</ul>
<p>Clearly I would not like to waste time setting up image serving servers that can handle such load and I am more than happy to outsource it to Amazon S3.</p>
<p>You would be surprised before caching when our total images were just 5GB, the no of requests were <strong>263m ($363.91)</strong> (almost double to what it is now with 205GB of images)</p>
<p>So if we take the total request to be directly proportional to number of images, with that rate the actual requests should be approx 4.5 billion or $15,000 :O</p>
<h3>How did I tame the beast?</h3>
<p>At first look the pricing of Amazon&#8217;s S3 services seems quite cheap. Wait until you get your first bill and you will see have cents add up to huge $$$.</p>
<blockquote><p><strong>Storage</strong></p>
<ul>
<li>$0.150 per GB – first 50 TB / month of storage used</li>
</ul>
<p><strong>Data Transfer</strong></p>
<ul>
<li>$0.100 per GB – all data transfer in</li>
<li>$0.170 per GB – first 10 TB / month data transfer out</li>
</ul>
<p><strong>Requests</strong></p>
<ul>
<li>$0.01 per 1,000 PUT, POST, or LIST requests</li>
<li class="c_red">$0.01 per 10,000 GET and all other requests</li>
</ul>
</blockquote>
<p>So after getting the first bill for a few hundred dollars, I sat down thinking how to bring that down. When I was digging the HTTP headers, I found out that by default S3 doesn’t have any cache request headers set. So even when the visitor has the requested the file from S3 before and has it in his browser cache, the browser will send a HTTP <code>GET</code> request to S3 just to verify if the file has changed. S3 returns a <code>304 Not Modified</code> header if the file has not changed and file wont be downloaded. You may think, S3 saved me a few GB of bandwidth cost. But each of this requests cost you ($0.01 per 10,000 GET) which is generally the bulk of the S3 bill.</p>
<p>Since photos our users upload almost never change. Asking S3 every time if the file has changed on S3 is certainly not required. You can stop browser sending this extra request for the same user by setting appropriate <code>Cache-Control</code> headers or <code>Expires</code> headers for the files. We can set <code>Cache-Control max-age=864000</code> which will tell browser to not request the same file until next 10 days (3600*24*10 sec)</p>
<p><img class="alignnone size-full wp-image-268" title="s3_304" src="http://www.lalit.org/wordpress/wp-content/uploads/2008/11/s3_304.png" alt="" width="328" height="76" /></p>
<p>Fortunately S3 allows us to do that, but there is no simple and easy way to do that. So I decided write a small script (<a href="#domestication">see below</a>) to achieve this.</p>
<h3><a id="domestication" name="domestication"></a>After Domestication</h3>
<p>After setting Cache headers, my bill got down drastically. The traffic doubled and number of images  almost tripled (5GB &#8211; 15GB) within a month while the number of requests was reduced 3 times. So that is <strong>9 times reduction in cost</strong>. Ideally, your bandwidth cost should be more than your requests cost.</p>
<p><img class="alignnone size-full wp-image-266" title="s3_bill" src="http://www.lalit.org/wordpress/wp-content/uploads/2008/11/s3_bill.png" alt="" width="497" height="403" /></p>
<p>If you own a high traffic blog or website, you can also store your javascripts or css files on S3 by using far fetched expires headers and using versioning (changing file name when contents change) so that the browser knows when the file has changed.</p>
<p><strong>For Example:</strong></p>
<p><code>&lt;link href="http://s3.amazonaws.com/lalit/style.css?<strong>v=3</strong>" ... /&gt;</code><br />
after change in stylesheet, change your code to,<br />
<code>&lt;link href="http://s3.amazonaws.com/lalit/style.css?<strong>v=4</strong>" ... /&gt;</code></p>
<h3>Domestication</h3>
<p>The popular <a rel="nofollow" href="https://addons.mozilla.org/en-US/firefox/addon/3247">Firefox extension S3Fox</a> doesn&#8217;t allow us to do that. So I decided write a small script using the <a rel="nofollow" href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1448&amp;categoryID=47">S3 PHP REST Library</a>.</p>
<blockquote><p>You can download the code <a href="http://www.lalit.org/wordpress/wp-content/uploads/2008/11/s3_upload.zip">here</a> (zip 6k).</p></blockquote>
<p><small><b class="red">Update:</b> Fixed a bug in code (mime type calculation was failing on some php configurations)</small></p>
<p>To use the script, you have to upload it to your server (running PHP). You need to edit the <code>upload.php</code> file to specify your AWS access key and Secret, your S3 bucket name.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><ol><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">/* One time settings. */</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000088;">$awsAccessKey</span>	<span style="color: #339933;">=</span> <span style="color: #0000ff;">'---'</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">// your AWS Key</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000088;">$awsSecretKey</span>	<span style="color: #339933;">=</span> <span style="color: #0000ff;">'---'</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">// your AWS Secret</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000088;">$bucket_name</span>	<span style="color: #339933;">=</span> <span style="color: #0000ff;">'---'</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">// S3 Bucket name</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000088;">$age</span>		<span style="color: #339933;">=</span> <span style="color: #cc66cc;">3600</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">24</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">// Cache age 10 days	</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">/* File Data */</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000088;">$s3_dir_name</span>	<span style="color: #339933;">=</span> <span style="color: #0000ff;">'dir1/dir2/'</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">// Directory on s3 where you want to upload file</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">				<span style="color: #666666; font-style: italic;">// example http://s3.amazonawas.com/bucket_name/dir1/dir2/filename.ext</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000088;">$upload_file</span>	<span style="color: #339933;">=</span> <span style="color: #0000ff;">'filename.ext'</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">// name of the file you want to upload.</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">				<span style="color: #666666; font-style: italic;">// keep it in the same dir as this file.</span></div></li></ol></pre></div></div>

<p>After you have saved the config info, every time you need to upload a file, you have to specify the file name and the dir name in <code>upload.php</code> and callit from the browser http://yoursite.com/s3/upload.php. (I know it sucks,  I promise will make it better soon)</p>
<p>If you want to escape all this trouble, there is a paid tool <a rel="external nofollow" href="http://www.bucketexplorer.com/">Bucket Explorer</a> which helps you to upload files with custom headers. I havn&#8217;t used it but it looks great and works on Win/Linux/Mac.</p>
<p>I hope your next S3 bill will come down <img src='http://www.lalit.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.lalit.org/lab/setting-cache-headers-files-in-amazon-s3/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Powerpoint / Slideshow Karaoke</title>
		<link>http://www.lalit.org/lab/powerpoint-slideshow-karaoke</link>
		<comments>http://www.lalit.org/lab/powerpoint-slideshow-karaoke#comments</comments>
		<pubDate>Mon, 29 Sep 2008 13:43:21 +0000</pubDate>
		<dc:creator>Lalit</dc:creator>
				<category><![CDATA[lab]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[karaoke]]></category>
		<category><![CDATA[slideshare]]></category>
		<category><![CDATA[slideshow]]></category>

		<guid isPermaLink="false">http://www.lalit.org/?p=239</guid>
		<description><![CDATA[Last year while I was at SlideShare.net, me and my friends were thinking of some cool ways to use our API. At the same time we were checking out emails from our users about how they are using sideshows in more fun way. Just then we came to know about PowerPoint Karaoke here and here.
Demo
After [...]]]></description>
			<content:encoded><![CDATA[<p>Last year while I was at <a href="http://www.slideshare.net">SlideShare.net</a>, me and my friends were thinking of some cool ways to use our <a href="http://www.slideshare.net/developers">API</a>. At the same time we were checking out emails from our users about how they are using sideshows in more fun way. Just then we came to know about PowerPoint Karaoke <a href="http://heathervescent.blogs.com/heathervescent/2007/04/powerpoint_kara.html">here </a>and <a href="http://www.boston.com/bostonglobe/ideas/articles/2008/03/02/slide_show/">here</a>.</p>
<h3>Demo</h3>
<p>After a few hours of javascript hacking, <a href="http://www.slidesharetoys.com/karaoke/">this is what</a> I came up with.<br />
<span id="more-239"></span></p>
<h3>How it works</h3>
<p>It will fetch random (Creative Commons Licensed) sideshows from slideshare.net using the API. The application uses the SlideShare.net API and Prototype/Scriptacluous to create some pretty visual effects. The <a href="http://www.slidesharetoys.com/karaoke/">SlideShare Karaoke Randomizer</a> was used for the first time on 11th July at the <a rel="nofollow" href="http://upcoming.yahoo.com/event/199762/">Creative Commons Salon</a> in San Francisco!</p>
<p style="text-align: center;"><a href="http://www.lalit.org/wordpress/wp-content/uploads/2008/09/k1.jpg"><img class="size-full wp-image-250 aligncenter" title="Karaoke" src="http://www.lalit.org/wordpress/wp-content/uploads/2008/09/k1.jpg" alt="" width="460" height="265" /></a></p>
<p style="text-align: center;"><a href="http://www.lalit.org/wordpress/wp-content/uploads/2008/09/k2.jpg"><img class="size-full wp-image-249 aligncenter" title="Karaoke" src="http://www.lalit.org/wordpress/wp-content/uploads/2008/09/k2.jpg" alt="" width="466" height="272" /></a></p>
<p>Here&#8217;s a great writeup for <a href="http://heathervescent.blogs.com/heathervescent/2007/04/powerpoint_kara.html">how to run your own PPT karaoke</a>.<br />
More info on SlideShare.net blog <a rel="nofollow" href="http://blog.slideshare.net/2008/09/05/slideshare-as-a-party-game/">here</a> and <a rel="nofollow" href="http://blog.slideshare.net/2007/07/11/slideshare-karoake-randomizer/">here</a></p>
<h3>Download</h3>
<p>The code has been released under the CC-GPL license at <a href="http://code.google.com/p/slideshare-toys/">Google Code project hosting</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lalit.org/lab/powerpoint-slideshow-karaoke/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Aksharabhyas</title>
		<link>http://www.lalit.org/lab/aksharabhyas</link>
		<comments>http://www.lalit.org/lab/aksharabhyas#comments</comments>
		<pubDate>Mon, 29 Sep 2008 11:40:26 +0000</pubDate>
		<dc:creator>Lalit</dc:creator>
				<category><![CDATA[lab]]></category>
		<category><![CDATA[akshara]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[education]]></category>
		<category><![CDATA[multilinugal]]></category>
		<category><![CDATA[orissa]]></category>
		<category><![CDATA[oriya]]></category>

		<guid isPermaLink="false">http://www.lalit.org/?p=226</guid>
		<description><![CDATA[Aksharabhyas is a interactive game for children to learn Oriya. I made this game for the school Akshara to promote multilingual education among children and to encourage the use of Oriya (Odia) in schools.
Download: Aksharabhyas (zip 605kb)

Screenshots

]]></description>
			<content:encoded><![CDATA[<p>Aksharabhyas is a interactive game for children to learn Oriya. I made this game for the school <a href="http://www.akshara.info" rel="nofollow">Akshara</a> to promote multilingual education among children and to encourage the use of <a rel="nofollow" href="http://en.wikipedia.org/wiki/Oriya_language">Oriya (Odia)</a> in schools.</p>
<blockquote><p>Download: <a href='http://www.lalit.org/wordpress/wp-content/uploads/2008/09/akshara.zip'>Aksharabhyas</a> (zip 605kb)</p></blockquote>
<p><span id="more-226"></span></p>
<h3>Screenshots</h3>
<p><a href="http://www.lalit.org/wordpress/wp-content/uploads/2008/09/ssakshara.png"><img src="http://www.lalit.org/wordpress/wp-content/uploads/2008/09/ssakshara.png" alt="" title="ssakshara" width="500" height="381" class="alignleft size-full wp-image-228" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lalit.org/lab/aksharabhyas/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
