﻿<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title type="text">Nerdworks Blogorama - Nerdspeak</title><subtitle type="text">The nerd shall inherit the earth.</subtitle><updated>2011-11-24T04:09:03Z</updated><author><name>Ranju. V</name><uri>http://blogorama.nerdworks.in/</uri><email>avranju@gmail.com</email></author><icon>http://blogorama.nerdworks.in/images/nw_logo.png</icon><id>http://blogorama.nerdworks.in/</id><link href="http://blogorama.nerdworks.in/" rel="alternate" type="text/html" /><link href="http://blogorama.nerdworks.in/atom.ashx" rel="self" type="application/atom+xml" /><entry><title>IE9 web cast / Chennai Web Camps / OSI Days 2011</title><link href="http://blogorama.nerdworks.in/entry-IE9webcastChennaiWebCampsOSIDa.aspx" rel="alternate" type="text/html" /><id>http://blogorama.nerdworks.in/comment.aspx?entryID=68</id><updated>2011-11-24T04:09:03Z</updated><published>2011-11-24T04:06:30Z</published><content type="html">&lt;p&gt;It has been a somewhat hectic two weeks shuttling between Chennai and Bangalore for a bunch of stuff. As usual, I’ve been happily handing out promises about posting resources for my talks on my blog. Like candy. Turns out you’ve got to come good on them eventually. So here goes:&lt;/p&gt;  &lt;h3&gt;IE9 Web Cast on ECMAScript 5&lt;/h3&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="https://2vqcza.bay.livefilestore.com/y1p5eeTX9Yctq964iB4Y6MjQ4VC1Bb1oC5mKQi6CsVMQWQAG8_DT4AUalzu876ge_2zQuERLsQRHDl0EP6H80k92Q/IE9%20and%20ECMAScript%205.pptx?download&amp;amp;psid=1" target="_blank"&gt;Get the deck&lt;/a&gt; (there isn’t much in the deck but there it is for what its worth).&lt;/li&gt;    &lt;li&gt;Get the &lt;a href="http://blogorama.nerdworks.in/entry-JavaScriptevalconsole.aspx" target="_blank"&gt;JavaScript eval console&lt;/a&gt; I was showing off in the session.&lt;/li&gt; &lt;/ol&gt;  &lt;h3&gt;Chennai Web Camps&lt;/h3&gt;  &lt;blockquote&gt;   &lt;p&gt;All the resources for the web camps sessions are available &lt;a href="http://blogorama.nerdworks.in/entry-WebCampsVirtualTechDaysandjsFo.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt; &lt;/blockquote&gt;  &lt;h3&gt;OSI Days 2011&lt;/h3&gt;  &lt;ol&gt;   &lt;li&gt;Session on &lt;a href="http://2011.osidays.com/proposal/webmatrix-building-complete-website-within-hour" target="_blank"&gt;WebMatrix: Building a complete website within an hour&lt;/a&gt;       &lt;ul&gt;       &lt;li&gt;Get the &lt;a href="https://2vqcza.bay.livefilestore.com/y1pXD21izvPLpVu9mm36kmbffp3rah3GAVMExZUpGaIGs14jMTX1rlG3v0wZIyxZgbPc59nMMgi1NhxsDoMSiJfeA/wm.pptx?download&amp;amp;psid=1" target="_blank"&gt;deck&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;Get &lt;a href="http://bit.ly/vK5gsM" target="_blank"&gt;WebMatrix&lt;/a&gt;&lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Session on &lt;a href="http://2011.osidays.com/proposal/building-cross-browser-html5-web-apps" target="_blank"&gt;building cross browser HTML5 web apps&lt;/a&gt;       &lt;ul&gt;       &lt;li&gt;Get the &lt;a href="https://2vqcza.bay.livefilestore.com/y1ppMwwTdk-qkxwBmRTNqJjMdjc2pGNvOvOAKxDNHPx1VO72wE5qFADpoi_hPLA2nvghN9VjjkMbnir5C2HYdnfIQ/cross-browser.pptx?download&amp;amp;psid=1" target="_blank"&gt;deck&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;Get the &lt;a href="https://2vqcza.bay.livefilestore.com/y1pInxhWZtREX5IF49DVSJYrWnIhVtKeVyyr6KLxa52d3I8fEkQCaG65nkgKBNGOIZobUUH4FQGZW97cJfvHQa6Mw/cross-browser-demos.zip?download&amp;amp;psid=1" target="_blank"&gt;demos&lt;/a&gt;&lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;That’s all folks. Hope the sessions were useful. If you’ve got feedback on any of these, please feel free to leave a comment. If you want to be nasty and use dirty words, please &lt;a href="http://blogorama.nerdworks.in/contact.aspx" target="_blank"&gt;email&lt;/a&gt; them to me.&lt;/p&gt;  </content></entry><entry><title>Partial function application in JavaScript</title><link href="http://blogorama.nerdworks.in/entry-PartialfunctionapplicationinJa.aspx" rel="alternate" type="text/html" /><id>http://blogorama.nerdworks.in/comment.aspx?entryID=67</id><updated>2011-11-07T09:32:22Z</updated><published>2011-11-07T09:32:22Z</published><content type="html">&lt;p&gt;Partial function application is a functional programming technique that allows you to transform functions that take N parameters into functions that take a subset of N parameters. For example, say you have this fairly useless function:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="prettyprint"&gt;function add(a, b) {
    return a + b;
}&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let’s say that for some reason we need a version of &amp;quot;&lt;code&gt;add&lt;/code&gt;&amp;quot; that will always have the value 5 for the parameter &amp;quot;&lt;code&gt;a&lt;/code&gt;&amp;quot;. One way we might do it is like so:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="prettyprint"&gt;function add5(b) {
    return add(5, b);
}&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;No black magic there. I was wondering if there might be some way that we can automate the process of generating functions with part of their arguments pre-bound. Here’s what I came up with:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="prettyprint"&gt;function partialBind(f, context) {
    // arguments length MUST be greater than 2
    if(arguments.length &amp;lt;= 2) {
        // coz. what're you &amp;quot;partial binding&amp;quot; otherwise?!
        return null;
    }

    // convert args to array excluding param &amp;quot;f&amp;quot; and &amp;quot;context&amp;quot;
    var arrayProto = Array.prototype;
    var params = arrayProto.slice.call(arguments, 2, arguments.length);
    return function () {
        // append params passed to this function to &amp;quot;params&amp;quot;
        var args = params.slice(0, params.length);
        if (arguments.length &amp;gt; 0) {
            arrayProto.forEach.call(arguments, function (p) {
                args.push(p);
            });
        }

        // call the original function
        return f.apply(context, args);
    }
}&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;This function allows me to transform pretty much any function that takes at least 1 argument into a new function that takes a subset of the arguments. Transforming our &amp;quot;&lt;code&gt;add&lt;/code&gt;&amp;quot; function into a single parameter version with &amp;quot;&lt;code&gt;a&lt;/code&gt;&amp;quot; bound to 5 for instance, would now look like this:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="prettyprint"&gt;var add5 = partialBind(add, null, 5);
var val = add5(10);
assert(val === 15);&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;Interestingly, &amp;quot;&lt;code&gt;partialBind&lt;/code&gt;&amp;quot; allows us to compose argument binding to multiple levels. If we wanted to take our &amp;quot;&lt;code&gt;add5&lt;/code&gt;&amp;quot; function and create another version that binds the second parameter to, say 20, then we can do this:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="prettyprint"&gt;var add5_20 = partialBind(add5, null, 20);
var val = add5_20();
assert(val === 25);&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;Note that we are doing a partial bind of a function that is already a partial bind of another function. Turns out we can take this to as many levels as we want. The example given above is of course somewhat concocted because we could have achieved the same result with a single partial bind instead of doing it in two levels:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="prettyprint"&gt;var add5_20 = partialBind(add, null, 5, 20);
var val = add5_20();
assert(val === 25);&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;All of this works because JavaScript supports &lt;a href="http://blogorama.nerdworks.in/entry-JavaScriptclosuresactlikeimpli.aspx" target="_blank"&gt;closures&lt;/a&gt;. Pretty nifty don’t you think?&lt;/p&gt;  </content></entry><entry><title>Web Camps, Virtual Tech Days and jsFoo</title><link href="http://blogorama.nerdworks.in/entry-WebCampsVirtualTechDaysandjsFo.aspx" rel="alternate" type="text/html" /><id>http://blogorama.nerdworks.in/comment.aspx?entryID=66</id><updated>2011-10-17T05:28:01Z</updated><published>2011-10-17T05:07:14Z</published><content type="html">&lt;p&gt;So I’ve had a busy few weeks recently doing a bunch of sessions at &lt;a href="http://bit.ly/r56sCs" target="_blank"&gt;Web Camps&lt;/a&gt; (in Delhi and Hyderabad), &lt;a href="http://bit.ly/qgtuFu" target="_blank"&gt;Virtual Tech Days&lt;/a&gt; and &lt;a href="http://jsfoo.hasgeek.com/" target="_blank"&gt;jsFoo&lt;/a&gt;. At each of those events I promised attendees that I’d put up the demos and the decks on my blog “soon”. Well, truth be told I’ve not been exactly conscientious about doing this quickly and I apologize for that. At any rate here’s the material for folks who came by for these sessions:&lt;/p&gt;  &lt;h4&gt;Web Camps&lt;/h4&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;Bold and Beautiful with CSS3&lt;/strong&gt; – &lt;a href="http://bit.ly/q9tEsP" target="_blank"&gt;deck&lt;/a&gt; / &lt;a href="https://skydrive.live.com/?cid=2c5064cb54b16f50&amp;amp;sc=documents#cid=2C5064CB54B16F50&amp;amp;id=2C5064CB54B16F50%21516&amp;amp;sc=documents" target="_blank"&gt;demo&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Spice it up - Advanced HTML5 – &lt;/strong&gt;&lt;a href="http://bit.ly/pmHizA" target="_blank"&gt;deck&lt;/a&gt; / &lt;a href="https://skydrive.live.com/?cid=2c5064cb54b16f50&amp;amp;sc=documents#cid=2C5064CB54B16F50&amp;amp;id=2C5064CB54B16F50%21516&amp;amp;sc=documents" target="_blank"&gt;demo&lt;/a&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Folks who attended the Hyderabad event might remember that I used a HTML5/CSS3 version of the decks during the session. If you’d like a copy of that code then hang tight because I hope to put up a post here on how I built it and intend to share the source with that post.&lt;/p&gt;  &lt;h4&gt;Virtual Tech Days&lt;/h4&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;Socket programming on the web&lt;/strong&gt; – &lt;a href="http://bit.ly/pAMvjI" target="_blank"&gt;deck&lt;/a&gt; / &lt;a href="https://skydrive.live.com/?cid=2c5064cb54b16f50&amp;amp;sc=documents#cid=2C5064CB54B16F50&amp;amp;id=2C5064CB54B16F50%21523&amp;amp;sc=documents" target="_blank"&gt;demo&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Threading and async programming on the web&lt;/strong&gt; – &lt;a href="http://bit.ly/o7MQbF" target="_blank"&gt;deck&lt;/a&gt; / &lt;a href="https://skydrive.live.com/?cid=2c5064cb54b16f50&amp;amp;sc=documents#cid=2C5064CB54B16F50&amp;amp;id=2C5064CB54B16F50%21526&amp;amp;sc=documents" target="_blank"&gt;demo&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Baking some HTML5 goodness into your ASP.NET apps&lt;/strong&gt; – &lt;a href="http://bit.ly/q5F2fD" target="_blank"&gt;deck&lt;/a&gt; / &lt;a href="https://skydrive.live.com/?cid=2c5064cb54b16f50&amp;amp;sc=documents#cid=2C5064CB54B16F50&amp;amp;id=2C5064CB54B16F50%21529&amp;amp;sc=documents" target="_blank"&gt;demo&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;h4&gt;jsFoo&lt;/h4&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;A primer on ECMAScript 5&lt;/strong&gt; – &lt;a href="http://bit.ly/pJbCU5" target="_blank"&gt;deck&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Advanced JavaScript Techniques&lt;/strong&gt; – &lt;a href="http://bit.ly/o9tEfl" target="_blank"&gt;deck&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;     &lt;div align="left"&gt;&lt;strong&gt;Best practices for building async apps with JavaScript&lt;/strong&gt; – &lt;a href="http://bit.ly/nHCJPh" target="_blank"&gt;deck&lt;/a&gt; / &lt;a href="https://skydrive.live.com/?cid=2c5064cb54b16f50&amp;amp;sc=documents#cid=2C5064CB54B16F50&amp;amp;id=2C5064CB54B16F50%21539&amp;amp;sc=documents" target="_blank"&gt;demo&lt;/a&gt;&lt;/div&gt;   &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;A number of jsFoo attendees requested that I share the “eval” console that I used to geek out on many of the advanced JS and ES5 samples during the session. I already have a post on that here:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a title="http://bit.ly/js-eval" href="http://bit.ly/js-eval"&gt;http://bit.ly/js-eval&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;You should be able to download a copy for your own use from that post or use the &lt;a href="http://blogorama.nerdworks.in/arbit/webstuff/eval/" target="_blank"&gt;online version&lt;/a&gt; if you prefer that.&lt;/p&gt;  </content></entry></feed>
