<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Random Ramblings!</title>
	<atom:link href="http://vikasrao.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://vikasrao.wordpress.com</link>
	<description></description>
	<lastBuildDate>Fri, 27 Jan 2012 23:04:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='vikasrao.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Random Ramblings!</title>
		<link>http://vikasrao.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://vikasrao.wordpress.com/osd.xml" title="Random Ramblings!" />
	<atom:link rel='hub' href='http://vikasrao.wordpress.com/?pushpress=hub'/>
		<item>
		<title>JavaScript quiz from Perfection Kills</title>
		<link>http://vikasrao.wordpress.com/2011/08/25/javascript-quiz-from-perfection-kills/</link>
		<comments>http://vikasrao.wordpress.com/2011/08/25/javascript-quiz-from-perfection-kills/#comments</comments>
		<pubDate>Thu, 25 Aug 2011 14:54:26 +0000</pubDate>
		<dc:creator>vikasvrao</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[interview questions]]></category>
		<category><![CDATA[JavaScript quiz]]></category>

		<guid isPermaLink="false">http://vikasrao.wordpress.com/?p=203</guid>
		<description><![CDATA[I came across this JavaScript quiz on a very cool blog and since I really enjoy solving such problems, I took the quiz. The result was humbling, and I was eager to find out why I got some of the questions wrong. I figured out why each problem behaves the way it does so I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=203&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I came across <a href="http://perfectionkills.com/javascript-quiz/" target="_blank">this JavaScript quiz</a> on a very cool blog and since I really enjoy solving such problems, I took the quiz. The result was humbling, and I was eager to find out why I got some of the questions wrong. I figured out why each problem behaves the way it does so I put them together for others below.</p>
<p><pre class="brush: jscript;">
1. (function(){
      return typeof arguments;
    })();

</pre></p>
<p>(a) “object” (b) “array” (c) “arguments” (d) “undefined”</p>
<p>The answer is (a). The arguments array is of type &#8220;object&#8221;. My first instinct was to think its an array, until I realized there was a typeof to be considered.<br />
<pre class="brush: jscript;">
2. var f = function g(){ return 23; };
    typeof g();
</pre><br />
(a) “number” (b) “undefined” (c) “function” (d) Error</p>
<p>This results in an error because the function g has been assigned to the var f. So the answer is (d)<br />
<pre class="brush: jscript;">
3. (function(x){
      delete x;
      return x;
    })(1);
  </pre><br />
 (a) 1 (b) null (c) undefined (d) Error</p>
<p> I made the mistake of assuming I could delete x, but apparently you cannot delete arguments inside a function. So the answer is 1 which is option (a).<br />
 <pre class="brush: jscript;">
4. var y = 1, x = y = typeof x;
    x;
  </pre><br />
(a) 1 (b) “number” (c) undefined (d) “undefined”</p>
<p>The answer here is &#8220;number&#8221;, because after assigning a value of 1 to y, x is also assigned that value. Doing a typeof on 1 obviously yields &#8220;number&#8221;.<br />
<pre class="brush: jscript;">
5. (function f(f){
      return typeof f();
    })(function(){ return 1; });
  </pre><br />
 (a) “number” (b) “undefined” (c) “function” (d) Error</p>
<p> Notice that we pass a function which returns 1 to the function f, which inturn executes the passed function and evaluates the type of the returned value. So typeof 1 results in &#8220;number&#8221; which is option (a)<br />
 <pre class="brush: jscript;">
 6. var foo = {
      bar: function() { return this.baz; },
      baz: 1
    };
    (function(){
      return typeof arguments[0]();
    })(foo.bar);
 </pre><br />
 (a) “undefined” (b) “object” (c) “number” (d) “function”</p>
<p> This returns &#8220;undefined&#8221; because when the foo.bar function is executed, &#8220;this&#8221; refers to the window scope which ofcourse knows nothing about baz. How do you fix this?<br />
 Remember how to use JavaScript&#8217;s call() and apply()? If not, check <a href="http://vikasrao.wordpress.com/2011/06/09/javascripts-call-and-apply-methods/" target="_blank">here</a><br />
 In this case, we need to specify the &#8220;this&#8221; to be the object &#8220;foo&#8221;, like this:<br />
 <pre class="brush: jscript;">
 var foo = {     
      bar: function() { return this.baz; },
      baz: 1
    };
    (function(){
      return typeof arguments[0].call(foo);
    })(foo.bar);
    </pre><br />
<pre class="brush: jscript;">
7.  var foo = {
      bar: function(){ return this.baz; },
      baz: 1
    }
    typeof (f = foo.bar)();
  </pre><br />
 (a) “undefined” (b) “object” (c) “number&#8221; (d) “function”</p>
<p> The above returns &#8220;undefined&#8221; because assigning foo.bar to a global variable &#8220;f&#8221; means the value of &#8220;this&#8221; inside foo.bar is &#8220;window&#8221;, and again, since window would not have a baz property, the value is undefined.<br />
 <pre class="brush: jscript;">
 8. var f = (function f(){ return &quot;1&quot;; }, function g(){ return 2; })();
    typeof f;
  </pre><br />
 (a) “string” (b) “number” (c) “function” (d) “undefined”</p>
<p> This one tripped me up! The comma apparently executes the function on its right. &#8220;,&#8221; is a left-associative operator which returns the value on its right, which makes the above to be var f = 2. typeof 2 will return &#8220;number&#8221; which is option (b).<br />
 <pre class="brush: jscript;">
 9. var x = 1;
    if (function f(){}) {
      x += typeof f;
    }
    x;
  </pre><br />
(a) 1 (b) “1function” (c) “1undefined” (d) NaN</p>
<p>This returns &#8220;1undefined&#8221; because x+ typeof f where &#8220;f&#8221; is undefined returns 1 + &#8220;undefined&#8221; = &#8220;1undefined&#8221;. Also note how if(function(){}) evaluated to true.<br />
<pre class="brush: jscript;">
10.  var x = [typeof x, typeof y][1];
    typeof typeof x;
  </pre><br />
(a) “number” (b) “string” (c) “undefined” (d) “object”</p>
<p>typeof &#8220;y&#8221; which is undefined returns &#8220;undefined&#8221;, typeof &#8220;undefined&#8221; is &#8220;string&#8221;, and another typeof on it still returns &#8220;string&#8221;.<br />
<pre class="brush: jscript;">
11. (function(foo){
      return typeof foo.bar;
    })({ foo: { bar: 1 } });
  </pre><br />
(a) “undefined” (b) “object” (c) “number” (d) Error</p>
<p>This one is simple, typeof foo.bar is a trick question because the argument foo is just an object, so to really get the &#8220;bar&#8221; value, it has to be typeof foo.foo.bar in this case. Either way, the answer is &#8220;undefined&#8221;.<br />
<pre class="brush: jscript;">
12. (function f(){
      function f(){ return 1; }
      return f();
      function f(){ return 2; }
    })();
  </pre><br />
(a) 1 (b) 2 (c) Error (e.g. “Too much recursion”) (d) undefined</p>
<p>I made the mistake of thinking the value is 1, but if you pay careful attention, you&#8217;ll realize both functions are called f, which means when return f() executes, function returns value 2 because its been parsed second. So the answer is &#8220;2&#8243;.<br />
<pre class="brush: jscript;">
13. function f(){ return f; }
    new f() instanceof f;
  </pre><br />
(a) true (b) false</p>
<p>This evaluates to false because new f() returns a function which is not an instanceof the function f.<br />
<pre class="brush: jscript;">
14. with (function(x, undefined){}) length;
  </pre><br />
 (a) 1 (b) 2 (c) undefined (d) Error</p>
<p> This evaluates to 2, because the functions length is the number of expected arguments. </p>
<br />Filed under: <a href='http://vikasrao.wordpress.com/category/javascript/'>JavaScript</a> Tagged: <a href='http://vikasrao.wordpress.com/tag/interview-questions/'>interview questions</a>, <a href='http://vikasrao.wordpress.com/tag/javascript-quiz/'>JavaScript quiz</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vikasrao.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vikasrao.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vikasrao.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vikasrao.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vikasrao.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vikasrao.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vikasrao.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vikasrao.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vikasrao.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vikasrao.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vikasrao.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vikasrao.wordpress.com/203/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vikasrao.wordpress.com/203/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vikasrao.wordpress.com/203/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=203&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vikasrao.wordpress.com/2011/08/25/javascript-quiz-from-perfection-kills/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/285b210dadc7b994f64ef19485a44c7d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vikasvrao</media:title>
		</media:content>
	</item>
		<item>
		<title>Subscribing to Facebook Graph API&#8217;s real time updates using CURL.</title>
		<link>http://vikasrao.wordpress.com/2011/07/05/subscribing-to-facebook-graph-apis-real-time-updates-using-curl/</link>
		<comments>http://vikasrao.wordpress.com/2011/07/05/subscribing-to-facebook-graph-apis-real-time-updates-using-curl/#comments</comments>
		<pubDate>Tue, 05 Jul 2011 21:51:11 +0000</pubDate>
		<dc:creator>vikasvrao</dc:creator>
				<category><![CDATA[Facebook graph API]]></category>
		<category><![CDATA[Facebook real time updates]]></category>

		<guid isPermaLink="false">http://vikasrao.wordpress.com/?p=198</guid>
		<description><![CDATA[Facebook allows you to subscribe to an application user&#8217;s activity on Facebook, so that you can subscribe to them, and use that information for various things. This is great because (the other alternative is) having to run a daemon process in order to find out a user&#8217;s Facebook activity is painful. However, as awesome as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=198&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Facebook allows you to subscribe to an application user&#8217;s activity on Facebook, so that you can subscribe to them, and use that information for various things. This is great because (the other alternative is) having to run a daemon process in order to find out a user&#8217;s Facebook activity is painful. </p>
<p>However, as awesome as this service is, understanding their documentation on this topic is a whole another matter. I found it almost impossible to decipher, as a lot of things were unclear or left unexplained. Look here: <a href="http://developers.facebook.com/docs/reference/api/realtime/" target="_blank">http://developers.facebook.com/docs/reference/api/realtime/</a></p>
<p>Luckily I found a blog post explaining how to do this, <a href="http://chaolam.wordpress.com/2010/06/07/implementing-facebook-real-time-updates-api-with-curl-examples/" target="_blank">here</a> it is. </p>
<p>I&#8217;ll run down the steps again below, as a few of the steps are now easier:</p>
<p>1. Get access token: <a href="https://developers.facebook.com/tools/access_token/" target="_blank">https://developers.facebook.com/tools/access_token/</a> gives you access tokens to all your apps on facebook.</p>
<p>2. Check if access token works:<br />
<pre class="brush: perl;">
curl &quot;https://graph.facebook.com/&lt;appid&gt;/subscriptions?access_token=&lt;access token from  step (1)&gt;&quot;
</pre></p>
<p>Since you originally have no subscriptions, you get: </p>
<p>{&#8220;data&#8221;:[]} or some kind of error. </p>
<p>3. If you got empty JSON back in step 2, now you can subscribe to updates(here I want to subscribe to user checkins):</p>
<p><pre class="brush: perl;">
curl -F 'object=user' \
-F 'callback_url=&lt;callback url you have to implement&gt;' \
-F 'fields=checkins' \
-F 'verify_token=&lt;secret token&gt;' \
&quot;https://graph.facebook.com/&lt;your-app-id&gt;/subscriptions?access_token=&lt;access token from (1)&quot;
</pre></p>
<p>The callback_url should be something along the lines of: <a href="https://github.com/facebook/php-sdk/blob/master/examples/example.php" target="_blank">https://github.com/facebook/php-sdk/blob/master/examples/example.php</a></p>
<p>This call should return &#8220;null&#8221; if successful. Once you have subscribed to updates, Facebook starts posting activities of all your application users to the callback_url above.</p>
<p>4. To verify step 3 was successful, run step 2 again, and this time, it should return something like this:<br />
<pre class="brush: jscript;">
{&quot;data&quot;:[{&quot;object&quot;:&quot;user&quot;,&quot;callback_url&quot;:&quot;http:\/\/yourdomain.com\/callback.php&quot;,&quot;fields&quot;:[&quot;checkins&quot;],&quot;active&quot;:true}]}
</pre></p>
<p>The above response means the subscription to updates about user checkins are now active. Hopefully this helps people who are confused about how to get real time updates working.</p>
<br />Filed under: <a href='http://vikasrao.wordpress.com/category/facebook-graph-api/'>Facebook graph API</a> Tagged: <a href='http://vikasrao.wordpress.com/tag/facebook-graph-api/'>Facebook graph API</a>, <a href='http://vikasrao.wordpress.com/tag/facebook-real-time-updates/'>Facebook real time updates</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vikasrao.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vikasrao.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vikasrao.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vikasrao.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vikasrao.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vikasrao.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vikasrao.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vikasrao.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vikasrao.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vikasrao.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vikasrao.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vikasrao.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vikasrao.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vikasrao.wordpress.com/198/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=198&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vikasrao.wordpress.com/2011/07/05/subscribing-to-facebook-graph-apis-real-time-updates-using-curl/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/285b210dadc7b994f64ef19485a44c7d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vikasvrao</media:title>
		</media:content>
	</item>
		<item>
		<title>Accessing user&#8217;s Facebook checkins via Graph API</title>
		<link>http://vikasrao.wordpress.com/2011/07/05/accessing-users-facebook-checkins-via-graph-api/</link>
		<comments>http://vikasrao.wordpress.com/2011/07/05/accessing-users-facebook-checkins-via-graph-api/#comments</comments>
		<pubDate>Tue, 05 Jul 2011 21:22:35 +0000</pubDate>
		<dc:creator>vikasvrao</dc:creator>
				<category><![CDATA[Facebook graph API]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Facebook connect]]></category>
		<category><![CDATA[graph api]]></category>
		<category><![CDATA[Graph API checkins]]></category>
		<category><![CDATA[me/checkins]]></category>

		<guid isPermaLink="false">http://vikasrao.wordpress.com/?p=195</guid>
		<description><![CDATA[Your application might want to use a user&#8217;s checkin data in various ways, I outline below how to fetch a user&#8217;s facebook checkin information and get the Facebook page for that location. First of all, you need to have the permissions to access a user&#8217;s checkin data. Look at http://developers.facebook.com/tools/explorer for information on this. Once [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=195&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Your application might want to use a user&#8217;s checkin data in various ways, I outline below how to fetch a user&#8217;s facebook checkin information and get the Facebook page for that location. </p>
<p>First of all, you need to have the permissions to access a user&#8217;s checkin data. Look at <a href="http://developers.facebook.com/tools/explorer" target="_blank">http://developers.facebook.com/tools/explorer</a> for information on this.</p>
<p>Once you have the required permissions and the user is logged in via Facebook connect:</p>
<p><pre class="brush: jscript;">

//dojo.hitch to make the object scope available
FB.api(&quot;/me/checkins&quot;, dojo.hitch(this, function(response){
	if(response.data &amp;&amp; response.data.length &gt; 0) {
		dojo.forEach(response.data, function(item) {
            var locationId = item.id; 
            var locationName = item.place.name; //name of the place
            // To get a Facebook link to the location
            var locationLink = this.getLocationLink(locationName, locationId);
            console.log(locationLink); //print location link
        });
	}
}));

/**
* Output like this: http://www.facebook.com/pages/Espetus-Churrascaria-Brazilian-Steakhouse/166393336742282
*/
getLocationLink: function(locationName, locationId) {        
        var baseURL = 'http://wwww.facebook.com/pages/';
        var locationNameArr = locationName.split(' ');
        var locationLink = '';
        for(var i = 0; i &lt; locationNameArr.length; i++) {
            locationLink += locationNameArr[i];
            if(i != locationNameArr.length-1) locationLink += &quot;-&quot;;
        }        
        return baseURL + locationLink + '/' + locationId;
    },
    
</pre></p>
<p>More information on whats available with the Checkin object is outlined here: <a href="http://developers.facebook.com/docs/reference/api/checkin/" target="_blank">http://developers.facebook.com/docs/reference/api/checkin/</a></p>
<p>The /me/checkins request usually returns the most recent 25 checkins, with a hook to access more of the checkin information if required. </p>
<br />Filed under: <a href='http://vikasrao.wordpress.com/category/facebook-graph-api/'>Facebook graph API</a>, <a href='http://vikasrao.wordpress.com/category/javascript/'>JavaScript</a> Tagged: <a href='http://vikasrao.wordpress.com/tag/facebook-connect/'>Facebook connect</a>, <a href='http://vikasrao.wordpress.com/tag/graph-api/'>graph api</a>, <a href='http://vikasrao.wordpress.com/tag/graph-api-checkins/'>Graph API checkins</a>, <a href='http://vikasrao.wordpress.com/tag/mecheckins/'>me/checkins</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vikasrao.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vikasrao.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vikasrao.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vikasrao.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vikasrao.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vikasrao.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vikasrao.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vikasrao.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vikasrao.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vikasrao.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vikasrao.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vikasrao.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vikasrao.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vikasrao.wordpress.com/195/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=195&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vikasrao.wordpress.com/2011/07/05/accessing-users-facebook-checkins-via-graph-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/285b210dadc7b994f64ef19485a44c7d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vikasvrao</media:title>
		</media:content>
	</item>
		<item>
		<title>Facebook Graph API &#8211; Facebook connect using JavaScript</title>
		<link>http://vikasrao.wordpress.com/2011/07/05/facebook-graph-api-facebook-connect-using-javascript/</link>
		<comments>http://vikasrao.wordpress.com/2011/07/05/facebook-graph-api-facebook-connect-using-javascript/#comments</comments>
		<pubDate>Tue, 05 Jul 2011 21:04:34 +0000</pubDate>
		<dc:creator>vikasvrao</dc:creator>
				<category><![CDATA[Facebook graph API]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Facebook connect]]></category>
		<category><![CDATA[FB.getLoginStatus]]></category>

		<guid isPermaLink="false">http://vikasrao.wordpress.com/?p=192</guid>
		<description><![CDATA[To use facebook connect on your website, or to allow a user to login to your website using facebook, its important to use Facebook Connect. I prefer doing this via JavaScript because its the language I am most comfortable with. Basics on how to set up and register a facebook app have been covered elsewhere, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=192&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>To use facebook connect on your website, or to allow a user to login to your website using facebook, its important to use Facebook Connect. I prefer doing this via JavaScript because its the language I am most comfortable with. </p>
<p>Basics on how to set up and register a facebook app have been covered <a href="http://ottopress.com/2010/how-to-setup-your-facebook-connect-application/" target="_blank">elsewhere</a>, over here I&#8217;m going to focus on the code which makes this happen.</p>
<p>To get started, make sure you import the Facebook JavaScript file. You also need to add a div whose id is fb-root, and you also specify your application credentials. For example:</p>
<p><pre class="brush: jscript;">

&lt;div id=&quot;fb-root&quot;&gt;&lt;/div&gt;
&lt;script src=&quot;http://connect.facebook.net/en_US/all.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
  FB.init({
    appId  : 'YOUR APP ID',
    status : true, // check login status
    cookie : true, // enable cookies to allow the server to access the session
    xfbml  : true  // parse XFBML
  });
&lt;/script&gt;

</pre></p>
<p>Once you do this, the FB object becomes available for use in your application. The best way to invite the user to login and/or provide permissions to your application is to use the FB.getLoginStatus() method:</p>
<p><pre class="brush: jscript;">
FB.getLoginStatus(function(response) {
	(response.session) ? showAccountInfo(): showLoginButton(); 
	FB.Event.subscribe('auth.statusChange', function() { // do something when auth status changes }); 
});
</pre></p>
<p>If the user is not logged in or has not provided the required permissions to your application, display the login button. </p>
<p><pre class="brush: jscript;">
&lt;img style=&quot;cursor: pointer;&quot; 
onclick=&quot;FB.login( function(response) {yourObject.onStatus(response)},{ perms: 'email,publish_stream,offline_access,user_checkins,friends_birthday' })&quot;
src=&quot;https://s-static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif&quot;/&gt;
</pre></p>
<p>The image, when clicked, calls the onStatus() method. &#8220;yourObject&#8221; assumes you are writing Object oriented JavaScript and the object is available in the namespace. </p>
<p>The permissions requested above are: email,publish_stream,offline_access,user_checkins,friends_birthday. You may want less, more or just the default information facebook makes available about every user. More information on permissions is available here: <a href="https://developers.facebook.com/tools/explorer" target="_blank">https://developers.facebook.com/tools/explorer</a></p>
<p>Thats it! The steps to have a user login and provide the required permissions to your application using the Facebook Graph API using JavaScript.</p>
<br />Filed under: <a href='http://vikasrao.wordpress.com/category/facebook-graph-api/'>Facebook graph API</a>, <a href='http://vikasrao.wordpress.com/category/javascript/'>JavaScript</a> Tagged: <a href='http://vikasrao.wordpress.com/tag/facebook-connect/'>Facebook connect</a>, <a href='http://vikasrao.wordpress.com/tag/facebook-graph-api/'>Facebook graph API</a>, <a href='http://vikasrao.wordpress.com/tag/fb-getloginstatus/'>FB.getLoginStatus</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vikasrao.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vikasrao.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vikasrao.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vikasrao.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vikasrao.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vikasrao.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vikasrao.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vikasrao.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vikasrao.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vikasrao.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vikasrao.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vikasrao.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vikasrao.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vikasrao.wordpress.com/192/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=192&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vikasrao.wordpress.com/2011/07/05/facebook-graph-api-facebook-connect-using-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/285b210dadc7b994f64ef19485a44c7d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vikasvrao</media:title>
		</media:content>
	</item>
		<item>
		<title>Preventing JavaScript memory leaks with Dojo disconnect</title>
		<link>http://vikasrao.wordpress.com/2011/06/24/preventing-javascript-memory-leaks-with-dojo-disconnect/</link>
		<comments>http://vikasrao.wordpress.com/2011/06/24/preventing-javascript-memory-leaks-with-dojo-disconnect/#comments</comments>
		<pubDate>Sat, 25 Jun 2011 05:47:36 +0000</pubDate>
		<dc:creator>vikasvrao</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[dojo.connect]]></category>
		<category><![CDATA[dojo.disconnect]]></category>
		<category><![CDATA[memory leaks in javascript]]></category>

		<guid isPermaLink="false">http://vikasrao.wordpress.com/?p=189</guid>
		<description><![CDATA[One of the things with using event listeners in JavaScript is that it causes memory leaks. This causes the website performance to slow down after a while. A pretty good description of how and why these memory leaks happen is explained here. In Dojo, attaching events to an element are done as below: Eugene Lazutkin&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=189&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of the things with using event listeners in JavaScript is that it causes memory leaks. This causes the website performance to slow down after a while. A pretty good description of how and why these memory leaks happen is explained <a href="http://www.javascriptkit.com/javatutors/closuresleak/index3.shtml" target="_blank">here</a>.</p>
<p>In Dojo, attaching events to an element are done as below:</p>
<p><pre class="brush: jscript;">
dojo.connect(dojo.byId('elementId'), 'onclick'/*or other events*/, scope/*context*/, function(event) {
   //do something when the event happens.
});
</pre></p>
<p>Eugene Lazutkin&#8217;s solution <a href="http://stackoverflow.com/questions/1214624/dojo-disconnect-question/1215532#1215532" target="_blank">here</a> on StackOverflow is perfect in my opinion. I&#8217;ve started using it in all the Dijit widgets I&#8217;ve been writing. I put this in the destroy() method of the widget.</p>
<p><pre class="brush: jscript;">
dojo.forEach(handles, dojo.disconnect);
</pre></p>
<br />Filed under: <a href='http://vikasrao.wordpress.com/category/javascript/'>JavaScript</a> Tagged: <a href='http://vikasrao.wordpress.com/tag/dojo-connect/'>dojo.connect</a>, <a href='http://vikasrao.wordpress.com/tag/dojo-disconnect/'>dojo.disconnect</a>, <a href='http://vikasrao.wordpress.com/tag/memory-leaks-in-javascript/'>memory leaks in javascript</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vikasrao.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vikasrao.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vikasrao.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vikasrao.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vikasrao.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vikasrao.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vikasrao.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vikasrao.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vikasrao.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vikasrao.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vikasrao.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vikasrao.wordpress.com/189/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vikasrao.wordpress.com/189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vikasrao.wordpress.com/189/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=189&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vikasrao.wordpress.com/2011/06/24/preventing-javascript-memory-leaks-with-dojo-disconnect/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/285b210dadc7b994f64ef19485a44c7d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vikasvrao</media:title>
		</media:content>
	</item>
		<item>
		<title>Understanding CSS box model properly</title>
		<link>http://vikasrao.wordpress.com/2011/06/16/understanding-css-box-model-properly/</link>
		<comments>http://vikasrao.wordpress.com/2011/06/16/understanding-css-box-model-properly/#comments</comments>
		<pubDate>Fri, 17 Jun 2011 06:05:36 +0000</pubDate>
		<dc:creator>vikasvrao</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[css box model]]></category>
		<category><![CDATA[dojo.position]]></category>
		<category><![CDATA[html box model]]></category>
		<category><![CDATA[margin]]></category>
		<category><![CDATA[padding]]></category>

		<guid isPermaLink="false">http://vikasrao.wordpress.com/?p=184</guid>
		<description><![CDATA[I&#8217;ve noticed a lot of developers are unsure of how the box model concept works with respect to how rectangles are created for elements laid out on the DOM tree. Although this document explains it pretty well, I built a small example which I feel also demonstrates the core concept reasonably well. http://jsfiddle.net/thxzc/1/ 4 main [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=184&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve noticed a lot of developers are unsure of how the box model concept works with respect to how rectangles are created for elements laid out on the DOM tree. Although this <a href="http://www.w3.org/TR/CSS2/box.html" target="_blank">document</a> explains it pretty well, I built a small example which I feel also demonstrates the core concept reasonably well. </p>
<p><a href="http://jsfiddle.net/thxzc/1/" target="_blank">http://jsfiddle.net/thxzc/1/</a></p>
<p>4 main concepts to properly understand the box model:</p>
<ol>
<li><strong>Content:</strong> The actual content area with a width and height specified to it.</li>
<li><strong>Padding:</strong> Clears space inside the rectangle created for the content rectangle above. This padding also assumes he background color of the content area.
</li>
<li><strong>Margin:</strong> Clears space OUTSIDE the rectangle created for the content rectangle above. </li>
<li><strong>Border:</strong> The border wraps around the content area/rectangle + the padding. It may or may not have its own color.</li>
</ol>
<p>The actual size of the node includes the padding and the border. So if the width of a node is 200px, and it has a 10px padding and 1px border around it. Its real width is 222px(width + paddingLeft + paddingRight + borderLeft + borderRight).</p>
<p>Execute the example again and you will see how the height and width of the content area are computed: <a href="http://jsfiddle.net/thxzc/1/" target="_blank">http://jsfiddle.net/thxzc/1/</a></p>
<br />Filed under: <a href='http://vikasrao.wordpress.com/category/javascript/'>JavaScript</a> Tagged: <a href='http://vikasrao.wordpress.com/tag/css-box-model/'>css box model</a>, <a href='http://vikasrao.wordpress.com/tag/dojo-position/'>dojo.position</a>, <a href='http://vikasrao.wordpress.com/tag/html-box-model/'>html box model</a>, <a href='http://vikasrao.wordpress.com/tag/margin/'>margin</a>, <a href='http://vikasrao.wordpress.com/tag/padding/'>padding</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vikasrao.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vikasrao.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vikasrao.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vikasrao.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vikasrao.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vikasrao.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vikasrao.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vikasrao.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vikasrao.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vikasrao.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vikasrao.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vikasrao.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vikasrao.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vikasrao.wordpress.com/184/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=184&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vikasrao.wordpress.com/2011/06/16/understanding-css-box-model-properly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/285b210dadc7b994f64ef19485a44c7d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vikasvrao</media:title>
		</media:content>
	</item>
		<item>
		<title>Removing duplicates from a JavaScript object array</title>
		<link>http://vikasrao.wordpress.com/2011/06/09/removing-duplicates-from-a-javascript-object-array/</link>
		<comments>http://vikasrao.wordpress.com/2011/06/09/removing-duplicates-from-a-javascript-object-array/#comments</comments>
		<pubDate>Fri, 10 Jun 2011 01:37:04 +0000</pubDate>
		<dc:creator>vikasvrao</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[filter duplicates from array]]></category>
		<category><![CDATA[Remove duplicates from Javascript array]]></category>

		<guid isPermaLink="false">http://vikasrao.wordpress.com/?p=180</guid>
		<description><![CDATA[Removing duplicates from a JavaScript array is an often encountered problem but after searching around, I have found very few good solutions to this. I wrote a small program but I realized that my solution had a O(n2) complexity. So I asked on twitter if someone knew of a better solution: Dont like my method [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=180&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Removing duplicates from a JavaScript array is an often encountered problem but after searching around, I have found very few good solutions to this. I wrote a small program but I realized that my solution had a O(n2) complexity. So I asked on twitter if someone knew of a better solution:</p>
<blockquote class='twitter-tweet'><p>Dont like my method to filter duplicates in an array using JavaScript. Anyone have a better approach? <a href="http://bit.ly/mt1H7f" rel="nofollow">http://bit.ly/mt1H7f</a> <a href="http://twitter.com/search?q=%23javascript" title="#javascript">#javascript</a> <a href="http://twitter.com/search?q=%23dojo" title="#dojo">#dojo</a>&mdash; <br />&nbsp; (@vikasrao) <a href='http://twitter.com/#!/vikasrao/status/77134502132064256' data-datetime='2011-06-04T22:07:53+00:00'>June 04, 2011</a></p></blockquote>
<p>My friend pointed out that I can use a map. Since a JavaScript object is essentially a map. I came up with:</p>
<p><pre class="brush: jscript;">
var arr = [
    { name: &quot;a&quot;, age: 24},
    { name: &quot;b&quot;, age: 25},
    { name: &quot;a&quot;, age: 24},
    { name: &quot;b&quot;, age: 25}
];

var newarr = [];
var unique = {};

dojo.forEach(arr, function(item) {
    if (!unique[item.age]) {
        newarr.push(item);
        unique[item.age] = item;
    }
});

console.log(dojo.toJson(newarr)); //prints [{&quot;name&quot;:&quot;a&quot;,&quot;age&quot;:24},{&quot;name&quot;:&quot;b&quot;,&quot;age&quot;:25}]
</pre></p>
<p>Here&#8217;s a JsFiddle link for the above code: <a href="http://jsfiddle.net/k6v3R/1/" target="_blank">http://jsfiddle.net/k6v3R/1/</a></p>
<p>I&#8217;m sure there are better solutions out there, but the complexity for the above code is O(n) although I&#8217;m thinking I don&#8217;t need to use both an object and an array to filter unique items. </p>
<br />Filed under: <a href='http://vikasrao.wordpress.com/category/javascript/'>JavaScript</a> Tagged: <a href='http://vikasrao.wordpress.com/tag/filter-duplicates-from-array/'>filter duplicates from array</a>, <a href='http://vikasrao.wordpress.com/tag/remove-duplicates-from-javascript-array/'>Remove duplicates from Javascript array</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vikasrao.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vikasrao.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vikasrao.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vikasrao.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vikasrao.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vikasrao.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vikasrao.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vikasrao.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vikasrao.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vikasrao.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vikasrao.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vikasrao.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vikasrao.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vikasrao.wordpress.com/180/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=180&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vikasrao.wordpress.com/2011/06/09/removing-duplicates-from-a-javascript-object-array/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/285b210dadc7b994f64ef19485a44c7d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vikasvrao</media:title>
		</media:content>
	</item>
		<item>
		<title>JavaScript&#8217;s call and apply methods</title>
		<link>http://vikasrao.wordpress.com/2011/06/09/javascripts-call-and-apply-methods/</link>
		<comments>http://vikasrao.wordpress.com/2011/06/09/javascripts-call-and-apply-methods/#comments</comments>
		<pubDate>Thu, 09 Jun 2011 17:55:58 +0000</pubDate>
		<dc:creator>vikasvrao</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[call() and apply()]]></category>
		<category><![CDATA[dojo.hitch]]></category>
		<category><![CDATA[JavaScript call() and Apply()]]></category>

		<guid isPermaLink="false">http://vikasrao.wordpress.com/?p=176</guid>
		<description><![CDATA[A lot of people starting out with JavaScript are unsure of how JavaScript&#8217;s call() and apply() methods work. Some have a theoretical understanding of it but are not sure where they would use these powerful methods. I&#8217;m taking a stab below at explaining them: Call and Apply are JavaScript methods used to pass the required [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=176&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A lot of people starting out with JavaScript are unsure of how JavaScript&#8217;s call() and apply() methods work. Some have a theoretical understanding of it but are not sure where they would use these powerful methods. I&#8217;m taking a stab below at explaining them:</p>
<p>Call and Apply are JavaScript methods used to pass the required object scope for a function to execute as expected. </p>
<p>The syntax for the JavaScript call method:<br />
<pre class="brush: jscript;">
fun.call(object, arg1, arg2, ...)
</pre></p>
<p>The syntax for the JavaScript apply method:<br />
<pre class="brush: jscript;">
fun.apply(object, [argsArray])
</pre></p>
<p>The main difference is that call() accepts an argument list, while apply() accepts a single array of arguments.</p>
<p>So if you want to call a function which prints something and pass an object scope for it to execute in, you can do:<br />
<pre class="brush: jscript;">
function printSomething() {
    console.log(this);
}
printSomething.apply(new SomeObject(),[]); // empty arguments array
// OR
printSomething.call(new SomeObject()); // no arguments
</pre></p>
<p>Here&#8217;s a JsFiddle example below which explains how scope can be passed as required: <a href="http://jsfiddle.net/8uRXe/8/" target="_blank">http://jsfiddle.net/8uRXe/8/</a></p>
<p>The first alert window uses the scope of the dojo widget, while the second call without any scope passed to it uses the default window scope for the &#8220;this&#8221; object printed from the printSomething() method. </p>
<p>Dojo provides a hitch method which allows the programmer to pass around scope. This hitch method along with dojo.connect is probably what I love most about Dojo.<br />
<pre class="brush: jscript;">
  var myObj = {
        foo: &quot;bar&quot;
    };
    var func = dojo.hitch(myObj, function() {
        console.log(this.foo);
    });
    func();
</pre></p>
<p>Here&#8217;s a small example continuing the earlier examples: <a href="http://jsfiddle.net/8uRXe/9/" target="_blank">http://jsfiddle.net/8uRXe/9/</a></p>
<p>Hopefully this sheds some light on these 2 powerful JavaScript methods. </p>
<br />Filed under: <a href='http://vikasrao.wordpress.com/category/javascript/'>JavaScript</a> Tagged: <a href='http://vikasrao.wordpress.com/tag/call-and-apply/'>call() and apply()</a>, <a href='http://vikasrao.wordpress.com/tag/dojo-hitch/'>dojo.hitch</a>, <a href='http://vikasrao.wordpress.com/tag/javascript-call-and-apply/'>JavaScript call() and Apply()</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vikasrao.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vikasrao.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vikasrao.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vikasrao.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vikasrao.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vikasrao.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vikasrao.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vikasrao.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vikasrao.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vikasrao.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vikasrao.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vikasrao.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vikasrao.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vikasrao.wordpress.com/176/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=176&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vikasrao.wordpress.com/2011/06/09/javascripts-call-and-apply-methods/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/285b210dadc7b994f64ef19485a44c7d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vikasvrao</media:title>
		</media:content>
	</item>
		<item>
		<title>Validate email address using JavaScript</title>
		<link>http://vikasrao.wordpress.com/2011/06/04/validate-email-address-using-javascript/</link>
		<comments>http://vikasrao.wordpress.com/2011/06/04/validate-email-address-using-javascript/#comments</comments>
		<pubDate>Sat, 04 Jun 2011 23:16:49 +0000</pubDate>
		<dc:creator>vikasvrao</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Email address validation using JavaScript]]></category>
		<category><![CDATA[email validation]]></category>
		<category><![CDATA[JavaScript regex]]></category>

		<guid isPermaLink="false">http://vikasrao.wordpress.com/?p=161</guid>
		<description><![CDATA[In order to validate email address using JavaScript, use this simple check: Breakdown of : /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{3}$ First part checks for alpha numberic characters, period, underscore and &#8211; are allowed. Needs to have an @ sign Last part can only contain 3 characters (a-z or A-Z) alphabets only, if you want anywhere between 2-4 characters, you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=161&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In order to validate email address using JavaScript, use this simple check:</p>
<p><pre class="brush: jscript;">
//where emailString is the string under consideration
if(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{3}$/.test(emailString)) {
 console.log(&quot;valid email address&quot;);
}
</pre></p>
<p>Breakdown of : /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{3}$</p>
<ul>
<li>First part checks for alpha numberic characters, period, underscore and &#8211; are allowed.</li>
<li>Needs to have an @ sign</li>
<li>Last part can only contain 3 characters (a-z or A-Z) alphabets only, if you want anywhere between 2-4 characters, you can use {2,4} instead of {3} like I have.</li>
</ul>
<p>UPDATE:<br />
This below should work just as well as the above regex. For more useful info, check <a href="http://www.javascriptkit.com/javatutors/redev2.shtml" target="_blank">this</a> out.</p>
<p><pre class="brush: jscript;">
(/^[/\w/._-]+@[/\w/.-]+\.[a-zA-Z]{3}$/.test(&quot;vikas123@gmail.com&quot;))
</pre></p>
<p>The above code in action <a href="http://jsfiddle.net/raybr/JVWwg/2/" target="_blank">here</a></p>
<br />Filed under: <a href='http://vikasrao.wordpress.com/category/javascript/'>JavaScript</a> Tagged: <a href='http://vikasrao.wordpress.com/tag/email-address-validation-using-javascript/'>Email address validation using JavaScript</a>, <a href='http://vikasrao.wordpress.com/tag/email-validation/'>email validation</a>, <a href='http://vikasrao.wordpress.com/tag/javascript-regex/'>JavaScript regex</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vikasrao.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vikasrao.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vikasrao.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vikasrao.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vikasrao.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vikasrao.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vikasrao.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vikasrao.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vikasrao.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vikasrao.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vikasrao.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vikasrao.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vikasrao.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vikasrao.wordpress.com/161/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=161&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vikasrao.wordpress.com/2011/06/04/validate-email-address-using-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/285b210dadc7b994f64ef19485a44c7d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vikasvrao</media:title>
		</media:content>
	</item>
		<item>
		<title>Sorting birthdays received from Facebook&#8217;s graph API</title>
		<link>http://vikasrao.wordpress.com/2011/06/02/sorting-birthdays-received-from-facebooks-graph-api/</link>
		<comments>http://vikasrao.wordpress.com/2011/06/02/sorting-birthdays-received-from-facebooks-graph-api/#comments</comments>
		<pubDate>Thu, 02 Jun 2011 15:49:55 +0000</pubDate>
		<dc:creator>vikasvrao</dc:creator>
				<category><![CDATA[Facebook graph API]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[graph api]]></category>
		<category><![CDATA[javascript sort by date]]></category>

		<guid isPermaLink="false">http://vikasrao.wordpress.com/?p=155</guid>
		<description><![CDATA[While working with Friend lists using Facebook&#8217;s graph API, you may want to retrieve your friends and do something based on their birthdays. Here&#8217;s some sample code to sort your friends based on upcoming birthdays. Filed under: Facebook graph API, JavaScript Tagged: Facebook graph API, graph api, javascript sort by date<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=155&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>While working with Friend lists using Facebook&#8217;s graph API, you may want to retrieve your friends and do something based on their birthdays. Here&#8217;s some sample code to sort your friends based on upcoming birthdays.</p>
<p><pre class="brush: jscript;">
FB.api(&quot;/me/friends?fields=id,name,birthday,picture, link&quot;, dojo.hitch(this, function(response) {
    var birthdays = response.data; //list of friend objects from facebook
    var currentMonth = new Date().getMonth() + 1;
    var upcoming = [];
    dojo.forEach(birthdays, function(item) {
        if (item.birthday) {
            var bday = item.birthday;
            //if the birthday is after today
            if (currentMonth &lt;= bday.substr(0, 2) * 1 &amp;&amp; new Date().getDate() &lt;= new Date(bday).getDate()) {
                upcoming.push(item);
            }
        }
    });

    //set the year to current year because of birth years being different.
    var year = new Date().getFullYear();
    upcoming = upcoming.sort(function(a, b) {
        return new Date(a.birthday).setYear(year) - new Date(b.birthday).setYear(year);
    });

    console.log(upcoming);//console log here, but do whatever you want with the sorted friends
}));
</pre></p>
<br />Filed under: <a href='http://vikasrao.wordpress.com/category/facebook-graph-api/'>Facebook graph API</a>, <a href='http://vikasrao.wordpress.com/category/javascript/'>JavaScript</a> Tagged: <a href='http://vikasrao.wordpress.com/tag/facebook-graph-api/'>Facebook graph API</a>, <a href='http://vikasrao.wordpress.com/tag/graph-api/'>graph api</a>, <a href='http://vikasrao.wordpress.com/tag/javascript-sort-by-date/'>javascript sort by date</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vikasrao.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vikasrao.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vikasrao.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vikasrao.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vikasrao.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vikasrao.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vikasrao.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vikasrao.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vikasrao.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vikasrao.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vikasrao.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vikasrao.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vikasrao.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vikasrao.wordpress.com/155/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vikasrao.wordpress.com&amp;blog=2314041&amp;post=155&amp;subd=vikasrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vikasrao.wordpress.com/2011/06/02/sorting-birthdays-received-from-facebooks-graph-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/285b210dadc7b994f64ef19485a44c7d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vikasvrao</media:title>
		</media:content>
	</item>
	</channel>
</rss>
