<?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>Dare to Dream?</title>
	<atom:link href="http://www.makuchaku.in/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://www.makuchaku.in/blog</link>
	<description>Good judgment comes from experience; Experience comes from bad judgment.</description>
	<lastBuildDate>Sun, 02 Oct 2011 19:29:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Speeding things up with tmpfs</title>
		<link>http://www.makuchaku.in/blog/speeding-things-up-with-tmpfs</link>
		<comments>http://www.makuchaku.in/blog/speeding-things-up-with-tmpfs#comments</comments>
		<pubDate>Sun, 02 Oct 2011 19:23:09 +0000</pubDate>
		<dc:creator>Mayank Jain (makuchaku)</dc:creator>
				<category><![CDATA[A strong urge to blog...]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.makuchaku.in/blog/?p=1101</guid>
		<description><![CDATA[Since I have 6GB of RAM in my new laptop, I thought (while watching the first episode of Big Boss 5) that lets put it to some good use. Did some research &#38; found out that I can actually create a small tmpfs partition from a portion of my extra RAM and use it to [...]


No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Since I have 6GB of RAM in my new laptop, I thought (while watching the first episode of Big Boss 5) that lets put it to some good use.</p>
<p>Did some research &amp; found out that I can actually create a small tmpfs partition from a portion of my extra RAM and use it to super-charge my disk access.</p>
<p>What if, I could keep the most accessed parts of my hard disk on this partition &amp; somehow figure out how to persistently do this, I think I can really really speed up the disk access.</p>
<p>I did a quick test to confirm this (/run is mounted on my Ubuntu 11.10 Beta2 as tmpfs partition)</p>
<p><strong>Test &#8211; time creation of a 1GB dummy file.</strong></p>
<p>On my regular 7200 rpm disk<br />
<img class="alignnone size-full wp-image-1102" title="1GB file creation on my 7200rpm disk drive" src="http://www.makuchaku.in/blog/wp-content/uploads/2011/10/snapshot-12.png" alt="" /></p>
<p>On the /run partition (which is mounted as tmpfs)<br />
<img title="1GB file creation on tmpfs partition (/run)" src="http://www.makuchaku.in/blog/wp-content/uploads/2011/10/snapshot-13.png" alt="" /></p>
<p>This clearly shows the benefit of using tmpfs for disk access.</p>
<p>In the posts following this post, I would try to document my experiences with tmpfs.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.makuchaku.in/blog/speeding-things-up-with-tmpfs/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AppDok is here!</title>
		<link>http://www.makuchaku.in/blog/appdok-is-here</link>
		<comments>http://www.makuchaku.in/blog/appdok-is-here#comments</comments>
		<pubDate>Tue, 09 Aug 2011 18:36:28 +0000</pubDate>
		<dc:creator>Mayank Jain (makuchaku)</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[AdoMado]]></category>
		<category><![CDATA[AppDok]]></category>

		<guid isPermaLink="false">http://www.makuchaku.in/blog/?p=1073</guid>
		<description><![CDATA[Tomorrow is when AppDok&#8217;s might is going to be tested! Wishing good luck to the AppDok&#8216;s launch tomorrow Fingers crossed! No related posts. Related posts brought to you by Yet Another Related Posts Plugin.


No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Tomorrow is when AppDok&#8217;s might is going to be tested!</p>
<p>Wishing good luck to the <a href="http://appdok.com">AppDok</a>&#8216;s launch tomorrow <img src='http://www.makuchaku.in/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Fingers crossed!</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.makuchaku.in/blog/appdok-is-here/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trip notes &#8211; Gangtok, Sikkim</title>
		<link>http://www.makuchaku.in/blog/trip-notes-gangtok-sikkim</link>
		<comments>http://www.makuchaku.in/blog/trip-notes-gangtok-sikkim#comments</comments>
		<pubDate>Sat, 16 Jul 2011 16:41:16 +0000</pubDate>
		<dc:creator>Mayank Jain (makuchaku)</dc:creator>
				<category><![CDATA[A strong urge to blog...]]></category>
		<category><![CDATA[Life]]></category>
		<category><![CDATA[Novice Traveller]]></category>

		<guid isPermaLink="false">http://www.makuchaku.in/blog/?p=1065</guid>
		<description><![CDATA[With this post, I am trying to start a new habit &#8211; of documenting tidbits about my trips with my wife (Kanika) to places worth remembering &#38; sharing about. I hope, with this, I will also renew the long lost will to sit and write for my dear blog Gangtok Some quick facts about our [...]


No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>With this post, I am trying to start a new habit &#8211; of documenting tidbits about my trips with my wife (Kanika) to places worth remembering &amp; sharing about.</p>
<p>I hope, with this, I will also renew the long lost will to sit and write for my dear blog <img src='http://www.makuchaku.in/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2><strong>Gangtok</strong></h2>
<p>Some quick facts about our journey&#8230;</p>
<ol>
<li>Our trip was scheduled from 29th June 2011 to 3rd July 2011.</li>
<li>Flight tickets costed us about INR 13,000 (we had booked our tickets about 1 month in advance)</li>
<li>Our stay was at a local guest house in Gangtok (arranged by Kanika&#8217;s mom) &#8211; cost &#8211; INR 100 /night</li>
<li>Travel from Bagdogra airport to Gangtok (guest house drop) &#8211; INR 820 (shared cab with another couple) (Maruti Van)</li>
<li>Travel from Gangtok (Guest house pickup) to Bagdogra Airport &#8211; INR 1,500 (same Maruti van, same driver, not shared)</li>
</ol>
<div><strong>Notes about Gangtok&#8230;</strong></div>
<div>Things which you should know before planning a trip there&#8230;</div>
<div>
<ul>
<li>Rains are a complete badass in Gangtok. It used to rain for complete nights during our stay (and during the days as well). Roads leading to the hills which are not well built get dangerously muddy &amp; almost unusable.</li>
<li>Paying extra to get an experienced driver and a good (&amp; heavy) car is a decision you should always try to be in favor of.</li>
<li>Season to visit &#8211; Oct/Nov and March/April (costly) &#8211; Its the best time to visit as the badass rains have either not started yet or just stopped. Winter is either setting in or giving way to summers. If lucky, you can also get to see snowfall at this time.</li>
<li>Off season &#8211; June/July (cheaper) &#8211; Though we had no choice about our travel dates &#8211; we did enjoy the climate at this time of the year. Not to mention, visiting Gangtok during this part of the year has its own advantages <img src='http://www.makuchaku.in/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>Travel inside Gangtok is VERY costly. The private taxi driving business is soo booming here that almost every next youngster is a private taxi driver in Gangtok. Be ready to shell out $$ if you plan to take up private cabs for your sigh seeing. What costed us just INR 820 one way (luckily we found a couple to share the cab with) &#8211; got inflated to INR 1500 just because we were the only folks travelling to the Airport that morning from our route.</li>
<li>There is NO airport in Gangtok. The only airport near Gangtok is in Bagdogra (West Bengal) &#8211; which is about 135 kilometers from Gangtok. This travel can take anywhere from 3 to 6 hours based on the condition of roads (&amp; traffic jams). Start early if your flight is in the first half of the day.</li>
<li>People of Gangtok are amazingly simple and friendly. I have not seen a city this friendly. Even Pune isn&#8217;t any close to Gangtok that way. Kudos to them <img src='http://www.makuchaku.in/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>When traveling first time to Gangtok, try to locate your destination hotel/lodge in reference to the MG Market. Its the heart of the city, has 3 large taxi stands built around it. Also, every driver knows this place. If at all possible, get a guest house near this market. Ours was about 10 kms further uphill and we really did witnessed some interesting times &#8211; trying to figure out how to reach our guest house.</li>
<li>If you plan to visit Nathula Pass, carry two photographs of yours. Not required, but also carry some identification papers (xerox) &#8211; as any visit to the Nathula Pass is sanctioned by the Army.</li>
</ul>
<div><strong>Places to visit </strong>(<a href="https://lh4.googleusercontent.com/-kZltcD55O6k/ThnLCRxhe3I/AAAAAAAAADU/MgIooDuw6uQ/IMG_2532.jpg" target="_blank">Map of Gangtok for reference</a>)</div>
<div>In our 3 days of stay at Gangtok, I think we saw almost all of what was there to see in this season.</div>
<div>
<ol>
<li>1st Day &#8211; We booked a cab for INR 1000 which took us to the North &amp; central tour of the city. It was a decently fulfilling day.</li>
<li>2nd Day &#8211; We opted to rest. Visited the MG Market, bought souvenirs, saw Delhi Belly at a local theater <img src='http://www.makuchaku.in/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  We also booked our travel to Nathula Pass (INR 600 per person, shared cab)</li>
<li>3rd Day &#8211; The journey to Nathula Pass was awesome. The valley below you looks breathtaking when you are going uphill. And at 15,000 feet, the climate is awesomely chilly. Hats off to the Army Jawans who live in such a harsh climate.</li>
</ol>
</div>
</div>
<p><strong>Gist</strong><br />
Its an amazingly breathtaking place. If you are willing to travel on long road journeys &amp; enjoy the journey more than the destination, its THE place for you.</p>
<p>I just wish, there was an airport inside Gangtok (or atleast Sikkim).</p>
<p>To end this post, I would like to show a brilliant piece of art I saw at the Handicrafts museum. I am completely in awe of the symmetry this drawing was made with. Whats even more brilliant, was the way this symmetry was achieved.</p>
<p><img src="https://lh4.googleusercontent.com/-yYiGGP1v4yI/ThnLCUjh1sI/AAAAAAAAABE/-2Z8SOyGD6M/s800/IMG_2510.jpg" alt="" width="600" height="800" /></p>
<p>Lord Gautama Buddha</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.makuchaku.in/blog/trip-notes-gangtok-sikkim/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Date arithmetic without having to worry about impact on dates, months or years!</title>
		<link>http://www.makuchaku.in/blog/date-arithmetic-without-having-to-worry-about-impact-on-dates-months-or-years</link>
		<comments>http://www.makuchaku.in/blog/date-arithmetic-without-having-to-worry-about-impact-on-dates-months-or-years#comments</comments>
		<pubDate>Mon, 09 May 2011 10:46:35 +0000</pubDate>
		<dc:creator>Mayank Jain (makuchaku)</dc:creator>
				<category><![CDATA[A strong urge to blog...]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[My Learnings]]></category>

		<guid isPermaLink="false">http://www.makuchaku.in/blog/?p=1062</guid>
		<description><![CDATA[Last night, my wife asked a very simple question&#8230; - &#8221;In shell scripting, given a date, how can I subtract 5 hours from it?&#8221; The question was particularly interesting because the moment you think about any arithmetic on dates, you need to calculate the impact on all the other values. For example, subtracting 5 hours from [...]


No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Last night, my wife asked a very simple question&#8230; - &#8221;In shell scripting, given a date, how can I subtract 5 hours from it?&#8221;</p>
<p>The question was particularly interesting because the moment you think about any arithmetic on dates, you need to calculate the impact on all the other values. For example, subtracting 5 hours from 0200 hours would shift the date by -1. Similar for months, years &#038; what not. Things get even more complicated by leap years, etc.</p>
<p>So, back to question. How do I subtract 5 hours from a given date? Usage of any other programming language is not allowed (Perl or Ruby).</p>
<p>I tried, searched internet for <a href="http://www.unix.com/answers-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html" target="_blank">some</a> <a href="http://en.wikipedia.org/wiki/Date_(Unix)" target="_blank">references</a> &#8211; I did came across some candid solutions, but they either resorted to Perl, or were <a href="http://www.kingcomputerservices.com/unix_101/date_arithmetic_part_1.htm" target="_blank">full fledged shell scripts</a> themselves.</p>
<p>And then it hit me.</p>
<blockquote><p>If I convert the given timestamp into seconds since Epoch, subtract the number of seconds in 5 hours &amp; convert the number of seconds back to a timestamp &#8211; it&#8217;ll be a whhakeroonie!!!</p></blockquote>
<p>Hence, this&#8230;</p>
<pre>
D="20110406164224"
date -d "${D:0:8} ${D:8:2}:${D:10:2}:${D:12:2}"
==> Wed Apr  6 16:42:24 IST 2011
date -d "${D:0:8} ${D:8:2}:${D:10:2}:${D:12:2}" +"%s"
==> 1302088344
expr 1302088344 - 18000
==> 1302070344
date -d @1302070344
==> Wed Apr  6 11:42:24 IST 2011
</pre>
<p>As you can see, the result is -5 hours from the timestamp.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.makuchaku.in/blog/date-arithmetic-without-having-to-worry-about-impact-on-dates-months-or-years/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple MapReduce with Javascript</title>
		<link>http://www.makuchaku.in/blog/simple-mapreduce-with-javascript</link>
		<comments>http://www.makuchaku.in/blog/simple-mapreduce-with-javascript#comments</comments>
		<pubDate>Sun, 08 May 2011 06:40:20 +0000</pubDate>
		<dc:creator>Mayank Jain (makuchaku)</dc:creator>
				<category><![CDATA[A strong urge to blog...]]></category>
		<category><![CDATA[AdoMado]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Startups]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.makuchaku.in/blog/?p=1057</guid>
		<description><![CDATA[The best way to understand MapReduce is to actually see &#38; feel it in action. Following is the simplest possible example I could cook&#8230; (Gist link) &#160; var Job = &#123; &#160; &#160; data : &#91; &#160; &#160; &#160; &#160; &#160; &#34;We are glad to see you here. This site is dedicated to&#34;, &#160; &#160; [...]


Related posts:<ol><li><a href='http://www.makuchaku.in/blog/kickass-mcv-for-your-javascript-apps' rel='bookmark' title='Kickass MCV for your Javascript Apps'>Kickass MCV for your Javascript Apps</a> <small>Very recently, I had an opportunity to work on a...</small></li>
</ol>

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>The best way to understand MapReduce is to actually see &amp; feel it in action. Following is the simplest possible example I could cook&#8230; (<a href="https://gist.github.com/961172">Gist link</a>)</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> Job = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; data : <span class="br0">&#91;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;We are glad to see you here. This site is dedicated to&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;poetry and to the people who make poetry possible&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;poets and their readers. FamousPoetsAndPoems.com is&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;a free poetry site. On our site you can find a large&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;collection of poems and quotes from over 631 poets&quot;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;Read and Enjoy Poetry&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;I, too, sing America&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;I am the darker brother&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;They send me to eat in the kitchen&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;When company comes&quot;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;But I laugh&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;And eat well&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;And grow strong&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;Tomorrow&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;Ill be at the table&quot;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;When company comes&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;Nobodyll dare&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;Say to me&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;Eat in the kitchen&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;Then&quot;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;Besides&quot;</span>, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;Theyll see how beautiful I am&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;And be ashamed&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;I, too, am America&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#93;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; map : <span class="kw2">function</span><span class="br0">&#40;</span>line<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> splits = line.<span class="me1">split</span><span class="br0">&#40;</span><span class="st0">&quot; &quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> temp = <span class="br0">&#91;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> i=<span class="nu0">0</span>; i&lt;splits .<span class="me1">length</span>; i++<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; temp.<span class="me1">push</span><span class="br0">&#40;</span><span class="br0">&#123;</span>key : splits<span class="br0">&#91;</span>i<span class="br0">&#93;</span>, value : <span class="nu0">1</span><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> temp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; reduce : <span class="kw2">function</span><span class="br0">&#40;</span>allSteps<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> result = <span class="br0">&#123;</span><span class="br0">&#125;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> i=<span class="nu0">0</span>; i&lt;allSteps.<span class="me1">length</span>; i++<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw2">var</span> step = allSteps<span class="br0">&#91;</span>i<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; result<span class="br0">&#91;</span>step.<span class="me1">key</span><span class="br0">&#93;</span> = result<span class="br0">&#91;</span>step.<span class="me1">key</span><span class="br0">&#93;</span> ? <span class="br0">&#40;</span>result<span class="br0">&#91;</span>step.<span class="me1">key</span><span class="br0">&#93;</span> + <span class="nu0">1</span><span class="br0">&#41;</span> : <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">return</span> result;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; init : <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw2">var</span> allSteps = <span class="br0">&#91;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> i=<span class="nu0">0</span>; i&lt;Job.<span class="me1">data</span>.<span class="me1">length</span>; i++<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; allSteps = allSteps.<span class="me1">concat</span><span class="br0">&#40;</span>Job.<span class="me1">map</span><span class="br0">&#40;</span>Job.<span class="me1">data</span><span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> result = Job.<span class="me1">reduce</span><span class="br0">&#40;</span>allSteps<span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; console.<span class="me1">log</span><span class="br0">&#40;</span>JSON.<span class="me1">stringify</span><span class="br0">&#40;</span>result<span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>; <span class="co1">// Job</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">Job.<span class="me1">init</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Copy &amp; paste this code in your browser&#8217;s JS console.</p>
<p>Console output&#8230;</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span><span class="st0">&quot;631&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;We&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;are&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;glad&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;to&quot;</span>:<span class="nu0">5</span>,<span class="st0">&quot;see&quot;</span>:<span class="nu0">2</span>,<span class="st0">&quot;you&quot;</span>:<span class="nu0">2</span>,<span class="st0">&quot;here.&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;This&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;site&quot;</span>:<span class="nu0">2</span>,<span class="st0">&quot;is&quot;</span>:<span class="nu0">2</span>,<span class="st0">&quot;dedicated&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;poetry&quot;</span>:<span class="nu0">3</span>,<span class="st0">&quot;and&quot;</span>:<span class="nu0">4</span>,<span class="st0">&quot;the&quot;</span>:<span class="nu0">5</span>,<span class="st0">&quot;people&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;who&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;make&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;possible&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;poets&quot;</span>:<span class="nu0">2</span>,<span class="st0">&quot;their&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;readers.&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;FamousPoetsAndPoems.com&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;a&quot;</span>:<span class="nu0">2</span>,<span class="st0">&quot;free&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;site.&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;On&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;our&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;can&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;find&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;large&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;collection&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;of&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;poems&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;quotes&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;from&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;over&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;Read&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;Enjoy&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;Poetry&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;I,&quot;</span>:<span class="nu0">2</span>,<span class="st0">&quot;too,&quot;</span>:<span class="nu0">2</span>,<span class="st0">&quot;sing&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;America&quot;</span>:<span class="nu0">2</span>,<span class="st0">&quot;I&quot;</span>:<span class="nu0">3</span>,<span class="st0">&quot;am&quot;</span>:<span class="nu0">3</span>,<span class="st0">&quot;darker&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;brother&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;They&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;send&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;me&quot;</span>:<span class="nu0">2</span>,<span class="st0">&quot;eat&quot;</span>:<span class="nu0">2</span>,<span class="st0">&quot;in&quot;</span>:<span class="nu0">2</span>,<span class="st0">&quot;kitchen&quot;</span>:<span class="nu0">2</span>,<span class="st0">&quot;When&quot;</span>:<span class="nu0">2</span>,<span class="st0">&quot;company&quot;</span>:<span class="nu0">2</span>,<span class="st0">&quot;comes&quot;</span>:<span class="nu0">2</span>,<span class="st0">&quot;But&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;laugh&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;And&quot;</span>:<span class="nu0">3</span>,<span class="st0">&quot;well&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;grow&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;strong&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;Tomorrow&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;Ill&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;be&quot;</span>:<span class="nu0">2</span>,<span class="st0">&quot;at&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;table&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;Nobodyll&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;dare&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;Say&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;Eat&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;Then&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;Besides&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;Theyll&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;how&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;beautiful&quot;</span>:<span class="nu0">1</span>,<span class="st0">&quot;ashamed&quot;</span>:<span class="nu0">1</span><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p></splits></pre>


<p>Related posts:<ol><li><a href='http://www.makuchaku.in/blog/kickass-mcv-for-your-javascript-apps' rel='bookmark' title='Kickass MCV for your Javascript Apps'>Kickass MCV for your Javascript Apps</a> <small>Very recently, I had an opportunity to work on a...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.makuchaku.in/blog/simple-mapreduce-with-javascript/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Why jQuery.proxy rocks my world!</title>
		<link>http://www.makuchaku.in/blog/why-jquery-proxy-rocks-my-world</link>
		<comments>http://www.makuchaku.in/blog/why-jquery-proxy-rocks-my-world#comments</comments>
		<pubDate>Wed, 27 Apr 2011 08:39:08 +0000</pubDate>
		<dc:creator>Mayank Jain (makuchaku)</dc:creator>
				<category><![CDATA[AdoMado]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[My Learnings]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web 2.0]]></category>

		<guid isPermaLink="false">http://www.makuchaku.in/blog/?p=1041</guid>
		<description><![CDATA[Its been very recent that I&#8217;m seriously looking into Javascript &#8211; and trust me, there is no dearth of stuff that can be achieved with purely client side code (HTML/CSS/JS). With the modern browsers churning out best of the breed in JS environments (both headed &#38; headless), everything is going to come to a browser [...]


Related posts:<ol><li><a href='http://www.makuchaku.in/blog/kickass-mcv-for-your-javascript-apps' rel='bookmark' title='Kickass MCV for your Javascript Apps'>Kickass MCV for your Javascript Apps</a> <small>Very recently, I had an opportunity to work on a...</small></li>
<li><a href='http://www.makuchaku.in/blog/how-to-commission-developer-machines-in-an-agile-way' rel='bookmark' title='How to commission developer machines in an agile way?'>How to commission developer machines in an agile way?</a> <small>During the past year &#8211; working at AdoMado, I&#8217;ve seen myself...</small></li>
</ol>

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><img style="float: left; margin: 5px;" src="http://jonraasch.com/blog/images/jquery-logo.gif" alt="" width="168" height="146" />Its been very recent that I&#8217;m seriously looking into Javascript &#8211; and trust me, there is no dearth of stuff that can be achieved with purely client side code (HTML/CSS/JS). With the modern browsers churning out best of the breed in JS environments (both headed &amp; headless), everything is going to come to a browser near you! Its just a matter of time!</p>
<p>Anyways, on more subtle issues, while writing a purely client side JS app using <a href="http://documentcloud.github.com/backbone">Backbone.js</a> &amp; <a href="http://jquerymobile.com/">jQuery Mobile</a> I came across <a href="http://api.jquery.com/jQuery.proxy/">jQuery.proxy</a> method &#8211; something that I&#8217;ve really started using almost everywhere.. The method is so useful that sometimes I wonder &#8211; why jQuery did not implement it in callback mechanism by default.</p>
<p>A quick overview about the problem&#8230;</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> FBNotificationWatcher = <span class="kw2">new</span> JS.<span class="kw2">Class</span><span class="br0">&#40;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; initialize : <span class="kw2">function</span><span class="br0">&#40;</span>timeout<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">url</span> = <span class="st0">&quot;http://foo/return/json&quot;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">getNotifications</span><span class="br0">&#40;</span><span class="br0">&#41;</span>; <span class="co1">// initiate the first fetch</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; getNotifications : <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; $.<span class="me1">ajax</span><span class="br0">&#40;</span><span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; <span class="co1">// do your ajax call</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; url : <span class="kw1">this</span>.<span class="me1">url</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; success : <span class="kw1">this</span>.<span class="me1">processNotifications</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; processNotifications : <span class="kw2">function</span><span class="br0">&#40;</span>rawNotificationData<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// process notifications&#8230; AND</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; setTimeout<span class="br0">&#40;</span>jQuery.<span class="me1">proxy</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">getNotifications</span>, <span class="kw1">this</span><span class="br0">&#41;</span>, <span class="kw1">this</span>.<span class="me1">timeout</span><span class="br0">&#41;</span>; <span class="co1">// start all over again&#8230;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>When a new object of FBNotificationWatcher is created, all goes well. this.getNotifications gets the JSON &amp; this.processNotifications processes it. However, when setTimeout&#8217;s occurs and this.getNotifications is called again, the context of &#8220;this&#8221; is set to the &#8220;window&#8221; object. And because of this, the code breaks in this.getNotifications method.</p>
<p>Now this is very frustrating &#8211; as you just lost the object you were operating within.</p>
<p>Solution? jQuery.proxy comes to rescue!</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"> &nbsp;processNotifications : <span class="kw2">function</span><span class="br0">&#40;</span>rawNotificationData<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// process notifications&#8230;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; setTimeout<span class="br0">&#40;</span>jQuery.<span class="me1">proxy</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">getNotifications</span>, <span class="kw1">this</span><span class="br0">&#41;</span>, <span class="kw1">this</span>.<span class="me1">timeout</span><span class="br0">&#41;</span>; <span class="co1">// start all over again&#8230;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>If we setup the setTimeout call like this, jQuery will guarantee that the context of &#8220;this&#8221; when this.getNotifications gets executed, will always be set to the original FBNotificationWatcher object which had setup the timer. The second argument to jQuery.proxy defines the context you want to get back when the setTimeout callback gets executed.</p>
<p>This concept can be used anywhere you want your callbacks to retain their context.</p>
<p>Read more about the method at <a href="http://api.jquery.com/jQuery.proxy/">jQuery API docs</a>.</p>


<p>Related posts:<ol><li><a href='http://www.makuchaku.in/blog/kickass-mcv-for-your-javascript-apps' rel='bookmark' title='Kickass MCV for your Javascript Apps'>Kickass MCV for your Javascript Apps</a> <small>Very recently, I had an opportunity to work on a...</small></li>
<li><a href='http://www.makuchaku.in/blog/how-to-commission-developer-machines-in-an-agile-way' rel='bookmark' title='How to commission developer machines in an agile way?'>How to commission developer machines in an agile way?</a> <small>During the past year &#8211; working at AdoMado, I&#8217;ve seen myself...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.makuchaku.in/blog/why-jquery-proxy-rocks-my-world/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

