<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4245795051931460477</id><updated>2024-10-24T14:47:28.710-07:00</updated><category term="Chef"/><category term="Game of Life HTML5 Canvas"/><category term="Maven Offline"/><category term="Spy javascript"/><category term="ruby_block notify"/><title type='text'>Rizwan Sharif</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://rizsharif.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://rizsharif.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Rizwan Sharif</name><uri>http://www.blogger.com/profile/01397871644088047383</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ZWeUMwdJyAl4qfOOBHmlUCWS51vOrWTg2A_LLfuSUpFbDY9V9LbAbceneQPqdgQquQYbneK7ElQ_y6M1J-vhkKY5QrfYGdNa1ykun_Ixup70WdnWvSeuzdSob93K0j8/s1600/*'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>13</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4245795051931460477.post-1370402708158042803</id><published>2013-06-27T15:16:00.001-07:00</published><updated>2013-06-27T15:16:42.541-07:00</updated><title type='text'>Chef clients bulk delete</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
===============================ACHTUNG===============================&lt;br /&gt;
&lt;br /&gt;
If you want to remove all clients from chef-server, then DONT use below command&lt;br /&gt;
&lt;br /&gt;
knife client bulk delete *&lt;br /&gt;
&lt;br /&gt;
instead use&lt;br /&gt;
&lt;br /&gt;
knife client bulk delete &#39;^(?!(chef|cli))&#39;&lt;br /&gt;
&lt;br /&gt;
it will not delete the clients used for proper functioning of chef server , like chef-validator , chef-ui etc&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://rizsharif.blogspot.com/feeds/1370402708158042803/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rizsharif.blogspot.com/2013/06/chef-clients-bulk-delete.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/1370402708158042803'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/1370402708158042803'/><link rel='alternate' type='text/html' href='http://rizsharif.blogspot.com/2013/06/chef-clients-bulk-delete.html' title='Chef clients bulk delete'/><author><name>Rizwan Sharif</name><uri>http://www.blogger.com/profile/01397871644088047383</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ZWeUMwdJyAl4qfOOBHmlUCWS51vOrWTg2A_LLfuSUpFbDY9V9LbAbceneQPqdgQquQYbneK7ElQ_y6M1J-vhkKY5QrfYGdNa1ykun_Ixup70WdnWvSeuzdSob93K0j8/s1600/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4245795051931460477.post-7872717860499325243</id><published>2013-06-11T20:05:00.000-07:00</published><updated>2013-06-11T20:05:25.467-07:00</updated><title type='text'>Updgrade Chef-Solo for vagrant</title><content type='html'>Vagrant, by default, uses an older version of chef-solo and you may run into problems because of that. Please follow the instructions in the readme file &lt;a href=&quot;https://github.com/rsharif/upgrade-chef-solo&quot;&gt;here&lt;/a&gt; to upgrade chef-solo to latest version for vagrant.&lt;br /&gt;
</content><link rel='replies' type='application/atom+xml' href='http://rizsharif.blogspot.com/feeds/7872717860499325243/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rizsharif.blogspot.com/2013/06/updgrade-chef-solo-for-vagrant.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/7872717860499325243'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/7872717860499325243'/><link rel='alternate' type='text/html' href='http://rizsharif.blogspot.com/2013/06/updgrade-chef-solo-for-vagrant.html' title='Updgrade Chef-Solo for vagrant'/><author><name>Rizwan Sharif</name><uri>http://www.blogger.com/profile/01397871644088047383</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ZWeUMwdJyAl4qfOOBHmlUCWS51vOrWTg2A_LLfuSUpFbDY9V9LbAbceneQPqdgQquQYbneK7ElQ_y6M1J-vhkKY5QrfYGdNa1ykun_Ixup70WdnWvSeuzdSob93K0j8/s1600/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4245795051931460477.post-6921876640550626840</id><published>2012-08-15T09:58:00.001-07:00</published><updated>2012-08-15T10:04:20.297-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Spy javascript"/><title type='text'>My Little Spy Function</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;I needed to spy on functions of an object and quickly came up with this little code to do much as i wanted.. For more advanced spying on javascript functions in your tests, consider using sinon.js or some other framework.&lt;br /&gt;
&lt;div&gt;&lt;pre class=&quot;brush: ruby&quot;&gt;function Spy(funcName,obj){

 var originalFunction ;
    if(typeof obj === &#39;object&#39;){
        originalFunction = obj[funcName];
    }
    else{
        originalFunction = global[funcName]
    }

 var numCalled = 0;
 var invocations = [];
 var spy = function(){
  numCalled++;
  invocations.push(arguments);
        if(typeof obj === &#39;object&#39;)
  return originalFunction.apply(obj,arguments);
        else
            return originalFunction.apply(global,arguments);
 }
 spy.calledOnce = function(){
  return numCalled == 1 ? true : false;
 }
 spy.times = function(num){
  return num == numCalled ? true : false ;
 }
 spy.firstCallWith = function(){
  return invocations[0];
 }
 spy.nthCallWith = function(n){
  return invocations[n-1];
 }
    if(typeof obj === &#39;object&#39;){
        obj[funcName] =  spy;
    } else {
        global[funcName] =  spy;
    }
 return spy;
}
&lt;/pre&gt;&lt;/div&gt;Now to spy on function emit of Dummy socket module below &lt;br /&gt;
&lt;div&gt;&lt;pre class=&quot;brush: ruby&quot;&gt;var Socket = function(){
    function emit(name,message){
    }
    return {
        &quot;emit&quot; : emit
    }
}
exports[&#39;Line Parser not invoked since no socket is connected&#39;] = function(test){
    test.expect(1);
    //given
    var socket = new Socket();
    var spy = new Spy(&quot;emit&quot; , socket);
    //Run the test
    //verify the spy
    test.ok(spy.calledOnce(), &quot;Socket.emit has been called once&quot;);

    test.done();
}
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rizsharif.blogspot.com/feeds/6921876640550626840/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rizsharif.blogspot.com/2012/08/my-little-spy-function.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/6921876640550626840'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/6921876640550626840'/><link rel='alternate' type='text/html' href='http://rizsharif.blogspot.com/2012/08/my-little-spy-function.html' title='My Little Spy Function'/><author><name>Rizwan Sharif</name><uri>http://www.blogger.com/profile/01397871644088047383</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ZWeUMwdJyAl4qfOOBHmlUCWS51vOrWTg2A_LLfuSUpFbDY9V9LbAbceneQPqdgQquQYbneK7ElQ_y6M1J-vhkKY5QrfYGdNa1ykun_Ixup70WdnWvSeuzdSob93K0j8/s1600/*'/></author><thr:total>0</thr:total><georss:featurename>310-440 N Bernardo Ave, Mountain View, CA 94043, USA</georss:featurename><georss:point>37.3885406 -122.0509766</georss:point><georss:box>37.3869636 -122.0534441 37.390117599999996 -122.0485091</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4245795051931460477.post-1708777139536647387</id><published>2012-05-21T12:51:00.000-07:00</published><updated>2012-05-21T12:51:59.899-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Maven Offline"/><title type='text'>Maven in offline mode</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I needed to tell maven to search my local repository only i.e maven should not try to connect to central repository.&lt;br /&gt;
Solution: just add -o flag like&lt;br /&gt;
&lt;br /&gt;
maven -o clean install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rizsharif.blogspot.com/feeds/1708777139536647387/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rizsharif.blogspot.com/2012/05/maven-in-offline-mode.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/1708777139536647387'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/1708777139536647387'/><link rel='alternate' type='text/html' href='http://rizsharif.blogspot.com/2012/05/maven-in-offline-mode.html' title='Maven in offline mode'/><author><name>Rizwan Sharif</name><uri>http://www.blogger.com/profile/01397871644088047383</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ZWeUMwdJyAl4qfOOBHmlUCWS51vOrWTg2A_LLfuSUpFbDY9V9LbAbceneQPqdgQquQYbneK7ElQ_y6M1J-vhkKY5QrfYGdNa1ykun_Ixup70WdnWvSeuzdSob93K0j8/s1600/*'/></author><thr:total>0</thr:total><georss:featurename>310-440 N Bernardo Ave, Mountain View, CA 94043, USA</georss:featurename><georss:point>37.3885726 -122.0510224</georss:point><georss:box>37.386995600000006 -122.05348989999999 37.3901496 -122.0485549</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4245795051931460477.post-2577195988973088884</id><published>2012-04-25T21:34:00.000-07:00</published><updated>2012-04-26T07:29:47.369-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Chef"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby_block notify"/><title type='text'>Chef : Notify resource from ruby_block</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Lets say for some sane/insane reason , you want to notify a resource to take some action from within ruby_block , you can accomplish it as follows&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: ruby&quot;&gt;
ruby_block &quot;dummy&quot; do
    block do
        if some_condition_is_true
           resources(:file =&amp;gt; &quot;create_file&quot;).run_action(:create)
        end
    end
end

file &quot;create_file&quot; do
         path &quot;/tmp/test.txt&quot;
         owner &quot;you&quot;
         content &quot;dummy&quot;
         action :nothing
end
&lt;/pre&gt;

&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;i&gt;Caveat :&lt;/i&gt;&lt;/b&gt;&lt;/h3&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If file resource &quot;create_file&quot; further notifies another resource , that resource will not be notified. What i mean to say is that calling a resource from within ruby_block by using run_action method directly does not build up the notification chain . For example if file resource was as below&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: javascript&quot;&gt;
file &quot;create_file&quot; do
         path &quot;/tmp/test.txt&quot;
         owner &quot;you&quot;
         content &quot;dummy&quot;
         action :nothing
         notifies :run , resources(:execute =&amp;gt; &quot;some_script&quot;)
end
&lt;/pre&gt;
and file resource is notified from within ruby_block , then file resource will not further notify &quot;some_script&quot; resource.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rizsharif.blogspot.com/feeds/2577195988973088884/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rizsharif.blogspot.com/2012/04/chef-notify-resource-from-rubyblock.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/2577195988973088884'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/2577195988973088884'/><link rel='alternate' type='text/html' href='http://rizsharif.blogspot.com/2012/04/chef-notify-resource-from-rubyblock.html' title='Chef : Notify resource from ruby_block'/><author><name>Rizwan Sharif</name><uri>http://www.blogger.com/profile/01397871644088047383</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ZWeUMwdJyAl4qfOOBHmlUCWS51vOrWTg2A_LLfuSUpFbDY9V9LbAbceneQPqdgQquQYbneK7ElQ_y6M1J-vhkKY5QrfYGdNa1ykun_Ixup70WdnWvSeuzdSob93K0j8/s1600/*'/></author><thr:total>0</thr:total><georss:featurename>1220 Tasman Dr, Sunnyvale, CA 94089, USA</georss:featurename><georss:point>37.4030943 -121.9916724</georss:point><georss:box>37.4015178 -121.9941399 37.4046708 -121.9892049</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4245795051931460477.post-2768270551534838451</id><published>2012-04-22T18:08:00.000-07:00</published><updated>2012-04-26T23:17:24.832-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Game of Life HTML5 Canvas"/><title type='text'>Game Of Life</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Just finished Basic &quot;&lt;a href=&quot;http://en.wikipedia.org/wiki/Conway&#39;s_Game_of_Life&quot;&gt;Game Of life&lt;/a&gt;&quot; simulation on HTML5 canvas. Here is the &lt;a href=&quot;http://rsharif.github.com/Game-Of-Life-On-Canvas/&quot; target=&quot;_blank&quot;&gt;demo&lt;/a&gt;&amp;nbsp;and here is the &lt;a href=&quot;https://github.com/rsharif/Game-Of-Life-On-Canvas/&quot; target=&quot;_blank&quot;&gt;source code&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
I used&amp;nbsp;kineticjs library to interact with canvas.&lt;br /&gt;
&lt;br /&gt;
Thanks &quot;&lt;a href=&quot;http://papermashup.com/pretty-css3-buttons/&quot;&gt;this site&lt;/a&gt;&quot; for button.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rizsharif.blogspot.com/feeds/2768270551534838451/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rizsharif.blogspot.com/2012/04/game-of-life.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/2768270551534838451'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/2768270551534838451'/><link rel='alternate' type='text/html' href='http://rizsharif.blogspot.com/2012/04/game-of-life.html' title='Game Of Life'/><author><name>Rizwan Sharif</name><uri>http://www.blogger.com/profile/01397871644088047383</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ZWeUMwdJyAl4qfOOBHmlUCWS51vOrWTg2A_LLfuSUpFbDY9V9LbAbceneQPqdgQquQYbneK7ElQ_y6M1J-vhkKY5QrfYGdNa1ykun_Ixup70WdnWvSeuzdSob93K0j8/s1600/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4245795051931460477.post-3063334447342484197</id><published>2012-04-09T22:16:00.000-07:00</published><updated>2012-04-09T22:20:40.334-07:00</updated><title type='text'>Nodejs Express : request.body is null</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Just had an other frustration with nodejs and this time again problem with header and fault was mine since i missed Content-type header.&lt;br /&gt;
While writing a nodeunit test ,&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: javascript&quot;&gt;exports.parseRequest = function(test){
 http = require(&#39;http&#39;)
 test.expect(1)
 options = {
  &quot;host&quot;: &quot;127.0.0.1&quot;,
  &quot;port&quot;: 3000,
  &quot;path&quot;: &quot;/movies/&quot;,
  &quot;method&quot;: &#39;POST&#39;,
  &quot;headers&quot; : {
   Content-Type&quot;:&quot;application/x-www-form-urlencoded&quot;
  }
 }  
 request = http.request(options,function(response){
  console.log(&quot;Status &quot;+response.statusCode)
  result = &#39;&#39;
  response.on(&#39;data&#39;,function(chunk){
   result += chunk
  })
  response.on(&#39;end&#39;,function(){
   response.destroy() 
   test.equal(result,&quot;Hello World&quot;, &quot;Reponse got&quot;)
   test.done();
   
  })
 })
 request.on(&#39;error&#39; , function (connectionException){
   console.log(&quot;ERROR occured while creating connection to localhost &quot;+connectionException);
 })
 request.write(&quot;data=sheat&quot;);
 request.end();
}
&lt;/pre&gt;
and there you go , i missed that content-type header on line 10 above and ended up wasting 30+mins to figure out why request.body is &#39;undefined&#39;.
&amp;gt;Make the header adjust according to content , application/json etc
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rizsharif.blogspot.com/feeds/3063334447342484197/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rizsharif.blogspot.com/2012/04/nodejs-express-requestbody-is-null.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/3063334447342484197'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/3063334447342484197'/><link rel='alternate' type='text/html' href='http://rizsharif.blogspot.com/2012/04/nodejs-express-requestbody-is-null.html' title='Nodejs Express : request.body is null'/><author><name>Rizwan Sharif</name><uri>http://www.blogger.com/profile/01397871644088047383</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ZWeUMwdJyAl4qfOOBHmlUCWS51vOrWTg2A_LLfuSUpFbDY9V9LbAbceneQPqdgQquQYbneK7ElQ_y6M1J-vhkKY5QrfYGdNa1ykun_Ixup70WdnWvSeuzdSob93K0j8/s1600/*'/></author><thr:total>0</thr:total><georss:featurename>1220 Tasman Dr, Sunnyvale, CA 94089, USA</georss:featurename><georss:point>37.4030943 -121.9916724</georss:point><georss:box>37.4015178 -121.9941399 37.4046708 -121.9892049</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4245795051931460477.post-8731319110634898025</id><published>2012-04-06T18:47:00.000-07:00</published><updated>2012-04-06T18:47:11.083-07:00</updated><title type='text'>Nodejs : not sending host header by default</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
After having heard about nodejs for so long now , i decided to play with it today and unfortunately ended up in frustation when i was not able to make the below &amp;lt;20 lines code execute successfully.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: javascript&quot;&gt;var connection = http.createClient(80, &quot;localhost&quot;);


var request = connection.request(&#39;GET&#39;, &quot;/&quot;);

request.end();


request.on(&#39;response&#39;, function(response){
 
  var result = &quot;&quot;;
  console.log(response.statusCode)
  response.on(&#39;data&#39;, function(chunk){
   result += chunk;
  })
  response.on(&#39;end&#39;, function(){
   console.log(result);
  })
  
});
 
connection.addListener(&#39;error&#39; , function (connectionException){
 console.log(&quot;ERROR occured while calling Rotten Tomatoes Api &quot;+connectionException);
})

&lt;/pre&gt;
I was initially making call to rottentomatoes api and was getting 400 , Bad request.&lt;br /&gt;
I changed hostname to localhost ( i had apache running locally) and was more frustated to see the same 400. This prompted me to check the apache error_log and this is what i was getting there&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;client sent HTTP/1.1 request without hostname (see RFC2616 section 14.23):

&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
and little googling told me that nodejs does not send the host header by default [Stumped]. so i had to manually add the host header like below.&lt;br /&gt;
&lt;pre class=&quot;brush: javascript&quot;&gt;var request = connection.request(&#39;GET&#39;, &quot;/&quot; , {&quot;Host&quot;:&quot;localhost&quot;);

&lt;/pre&gt;
&lt;br /&gt;
I am not sure but i think it should be a good idea to include some common headers by default in the request sent by nodejs.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rizsharif.blogspot.com/feeds/8731319110634898025/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rizsharif.blogspot.com/2012/04/nodejs-not-sending-host-header-by.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/8731319110634898025'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/8731319110634898025'/><link rel='alternate' type='text/html' href='http://rizsharif.blogspot.com/2012/04/nodejs-not-sending-host-header-by.html' title='Nodejs : not sending host header by default'/><author><name>Rizwan Sharif</name><uri>http://www.blogger.com/profile/01397871644088047383</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ZWeUMwdJyAl4qfOOBHmlUCWS51vOrWTg2A_LLfuSUpFbDY9V9LbAbceneQPqdgQquQYbneK7ElQ_y6M1J-vhkKY5QrfYGdNa1ykun_Ixup70WdnWvSeuzdSob93K0j8/s1600/*'/></author><thr:total>0</thr:total><georss:featurename>380 N Bernardo Ave, Mountain View, CA 94043, USA</georss:featurename><georss:point>37.3885726 -122.0510224</georss:point><georss:box>37.386995600000006 -122.05348989999999 37.3901496 -122.0485549</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4245795051931460477.post-5617129883704793192</id><published>2012-01-20T16:09:00.000-08:00</published><updated>2012-08-10T15:52:02.775-07:00</updated><title type='text'>Favorite URLs</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Here is keep a list of articles i liked reading and will like to read again in some leisure time.&lt;br /&gt;
&lt;b&gt;Web:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://yuiblog.com/blog/2007/04/11/performance-research-part-4/&quot;&gt;Parallel Download Optimization For web&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://joost.zeekat.nl/constructors-considered-mildly-confusing.html&quot;&gt;Javascript Prototype&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://scribu.net/blog/javascript-var-keyword-for-php-developers.html&quot;&gt;Javascript &#39;var&#39; keyword&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://agiletesting.blogspot.com/2010/11/working-with-chef-attributes.html&quot;&gt;Chef Attributes&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.conigliaro.org/2011/07/20/initial-thoughts-on-migrating-from-amazon-ec2-to-rackspace-cloud/&quot; target=&quot;_blank&quot;&gt;Amazon vs Rackspace&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://javascriptweblog.wordpress.com/2010/07/06/function-declarations-vs-function-expressions/&quot; target=&quot;_blank&quot;&gt;Function Expressions vs Function Declarations&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth/&quot; target=&quot;_blank&quot;&gt;JS module Pattern&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://docstore.mik.ua/orelly/webprog/jscript/ch19_02.htm&quot; target=&quot;_blank&quot;&gt;JS Events&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.nczonline.net/blog/2010/07/27/determining-if-an-object-property-exists/&quot; target=&quot;_blank&quot;&gt;Object Property Detection&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://javascriptweblog.wordpress.com/2010/10/25/understanding-javascript-closures/&quot; target=&quot;_blank&quot;&gt;CLOSURE in JS&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.elijahmanor.com/2012/02/differences-between-jquery-bind-vs-live.html&quot; target=&quot;_blank&quot;&gt;bind vs live vs delegate vs on&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rizsharif.blogspot.com/feeds/5617129883704793192/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rizsharif.blogspot.com/2012/01/favorite-urls.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/5617129883704793192'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/5617129883704793192'/><link rel='alternate' type='text/html' href='http://rizsharif.blogspot.com/2012/01/favorite-urls.html' title='Favorite URLs'/><author><name>Rizwan Sharif</name><uri>http://www.blogger.com/profile/01397871644088047383</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ZWeUMwdJyAl4qfOOBHmlUCWS51vOrWTg2A_LLfuSUpFbDY9V9LbAbceneQPqdgQquQYbneK7ElQ_y6M1J-vhkKY5QrfYGdNa1ykun_Ixup70WdnWvSeuzdSob93K0j8/s1600/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4245795051931460477.post-712288141846696992</id><published>2011-09-01T01:55:00.000-07:00</published><updated>2011-09-01T01:55:47.520-07:00</updated><title type='text'>My Csv Parser For Java</title><content type='html'>&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;brush: java&quot;&gt;import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
&amp;nbsp;*
&amp;nbsp;* @author Rizwan Sharif
&amp;nbsp;*
&amp;nbsp;*/
public class CsvParser {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /**
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;* Original Regex without escaped qoutes: &amp;nbsp;(&quot;(([^&quot;]|&quot;&quot;)+)&quot;|([^,]+)|,)(?=(,|$))
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;* Regex explained :
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;* First Part : &quot;(([^&quot;]|&quot;&quot;)+)&quot; &amp;nbsp;if value starts with &quot; then it can either be followed by any character not &quot; &amp;nbsp;([^&quot;] or by &quot;&quot; , one or more times
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;* Second Part : ([^,]+) for simple values : any character except ,
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;* Third Part : , &amp;nbsp;can be only comma
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;* Forth Part : all above three parts should be followed either by comma or by Endline.
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*/
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; public static final String CSV_PATTERN = &quot;(\&quot;(([^\&quot;]|\&quot;\&quot;)+)\&quot;|([^,]+)|,)(?=(,|$))&quot;;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; private static Pattern csvRE;

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public CsvParser() {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; csvRE = Pattern.compile(CSV_PATTERN);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public List&amp;lt;String&amp;gt; parseLine(String line) {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; List&amp;lt;String&amp;gt; list = new ArrayList&amp;lt;String&amp;gt;();
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Matcher m = csvRE.matcher(line);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // For each field
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; while (m.find()) {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String match = m.group();
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (match == null)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (match.endsWith(&quot;,&quot;)) { &amp;nbsp;// trim trailing ,
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; match = match.substring(0, match.length() - 1);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (match.startsWith(&quot;\&quot;&quot;)) { // assume also ends with
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; match = match.substring(1, match.length() - 1);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (match.length() == 0)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; match = null;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; list.add(match);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return list;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }
}
&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rizsharif.blogspot.com/feeds/712288141846696992/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rizsharif.blogspot.com/2011/09/my-csv-parser-for-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/712288141846696992'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/712288141846696992'/><link rel='alternate' type='text/html' href='http://rizsharif.blogspot.com/2011/09/my-csv-parser-for-java.html' title='My Csv Parser For Java'/><author><name>Rizwan Sharif</name><uri>http://www.blogger.com/profile/01397871644088047383</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ZWeUMwdJyAl4qfOOBHmlUCWS51vOrWTg2A_LLfuSUpFbDY9V9LbAbceneQPqdgQquQYbneK7ElQ_y6M1J-vhkKY5QrfYGdNa1ykun_Ixup70WdnWvSeuzdSob93K0j8/s1600/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4245795051931460477.post-3477547107655897613</id><published>2011-06-11T16:18:00.000-07:00</published><updated>2011-06-13T02:52:20.805-07:00</updated><title type='text'>Javascript: How Double And &quot;&amp;&amp;&quot; Works</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Recently this question baffled us all.Coming from other languages we would expect that following line&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: javascript&quot;&gt;var result = &amp;nbsp;true &amp;amp;&amp;amp; &quot;Rizwan&quot; ;
&lt;/pre&gt;&lt;br /&gt;
assigns true or false to result variable (true in above case) but if you do &quot;alert(result)&quot; in next line , you see &quot;Rizwan&quot; in the alertbox instead of true.Confused? Read till end and it will be clear.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Javascript and Falsy Values&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; In javascript following are considered false&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&amp;nbsp; &amp;nbsp;false&lt;/li&gt;
&lt;li&gt;&amp;nbsp; &amp;nbsp;0&lt;/li&gt;
&lt;li&gt;&amp;nbsp; &amp;nbsp;null&lt;/li&gt;
&lt;li&gt;&amp;nbsp; &amp;nbsp;undefined&lt;/li&gt;
&lt;li&gt;&amp;nbsp; &amp;nbsp;&quot;&quot; ,empty String&lt;/li&gt;
&lt;li&gt;&amp;nbsp; &amp;nbsp;NaN (Not a number , like 0/0)&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
Everything else evaluates to true.&lt;br /&gt;
&lt;br /&gt;
Keeping this in mind , we go back to our problem&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: javascript&quot;&gt;var result = &amp;nbsp;true &amp;amp;&amp;amp; &quot;Rizwan&quot;;
&lt;/pre&gt;&lt;br /&gt;
In javascript &amp;amp;&amp;amp; operator evaluates its first operand and if its true, it returns whatever is the second operand (&quot;Rizwan&quot; in the above case) .&lt;br /&gt;
&lt;br /&gt;
And if first operand is falsy value , &amp;amp;&amp;amp; operarot just returns that first operand.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: javascript&quot;&gt;var result = &amp;nbsp;null &amp;amp;&amp;amp; &quot;Rizwan&quot;; // result will contain null
&lt;/pre&gt;&lt;br /&gt;
Similary || operator returns its first operand if its true , otherwise it returns it second operator if first operator is a falsy value.&amp;nbsp;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rizsharif.blogspot.com/feeds/3477547107655897613/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rizsharif.blogspot.com/2011/06/javascript-how-double-and-works.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/3477547107655897613'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/3477547107655897613'/><link rel='alternate' type='text/html' href='http://rizsharif.blogspot.com/2011/06/javascript-how-double-and-works.html' title='Javascript: How Double And &quot;&amp;&amp;&quot; Works'/><author><name>Rizwan Sharif</name><uri>http://www.blogger.com/profile/01397871644088047383</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ZWeUMwdJyAl4qfOOBHmlUCWS51vOrWTg2A_LLfuSUpFbDY9V9LbAbceneQPqdgQquQYbneK7ElQ_y6M1J-vhkKY5QrfYGdNa1ykun_Ixup70WdnWvSeuzdSob93K0j8/s1600/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4245795051931460477.post-6938857379172231487</id><published>2011-03-25T06:34:00.000-07:00</published><updated>2011-03-25T06:34:48.614-07:00</updated><title type='text'>Hotlinking</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;b&gt;Hotlinking:&lt;/b&gt; &lt;br /&gt;
Let&#39;s say i own example.com and i have webpage test.html accessible through www.example.com/test.html and test.html is codes as&lt;br /&gt;
&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;img src=&quot;rizwan.com/image1.jpg&quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now when you load example.com/test.html , image1 will be loaded from rizwan.com and not from example.com. So i have hotlinked image1 from my webpage to rizwan.com&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Problem:&lt;/b&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Since bandwidth is charged, and i have asked your browser to show that 500KB (lets assume) image1 from answer.com , answer.com is going to pay for that bandwidth , not example.com. Hence bandwidth theft.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Solution:&lt;/b&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://en.wikipedia.org/wiki/HTTP_referrer&quot;&gt; Http Referrer &lt;/a&gt;can be used to identify if image1 is being linked from any other site except answer.com. If yes , then we can simply reject the request or do whatever you like.&lt;br /&gt;
How can we check the referrer? Well Conditional Rewrite rules can help.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;border-collapse: separate; color: #333333; font-family: Times; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Lucida Grande&#39;,&#39;Lucida Sans Unicode&#39;,Lucida,Verdana,sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&lt;pre style=&quot;margin-bottom: 1em; margin-top: 1em; overflow: auto; width: 488px;&quot;&gt;RewriteCond %{HTTP_REFERRE] !^http://(www\.)?answer.com/.*$&lt;/pre&gt;&lt;pre style=&quot;margin-bottom: 1em; margin-top: 1em; overflow: auto; width: 488px;&quot;&gt;RewriteRule \.*/image1.jpg$ /image/sucker.jpg [L]&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Well , first condition checks if referrer is anything except our website, if yes then next rewrite rule is excuted and alternate image is sent instead of image1.jpg, You can as well return 404 , a low bandwidth image etc&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rizsharif.blogspot.com/feeds/6938857379172231487/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rizsharif.blogspot.com/2011/03/hotlinking.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/6938857379172231487'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/6938857379172231487'/><link rel='alternate' type='text/html' href='http://rizsharif.blogspot.com/2011/03/hotlinking.html' title='Hotlinking'/><author><name>Rizwan Sharif</name><uri>http://www.blogger.com/profile/01397871644088047383</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ZWeUMwdJyAl4qfOOBHmlUCWS51vOrWTg2A_LLfuSUpFbDY9V9LbAbceneQPqdgQquQYbneK7ElQ_y6M1J-vhkKY5QrfYGdNa1ykun_Ixup70WdnWvSeuzdSob93K0j8/s1600/*'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4245795051931460477.post-7026452290776815268</id><published>2010-10-07T12:36:00.000-07:00</published><updated>2012-03-30T20:24:46.348-07:00</updated><title type='text'>Bypass Query Over Limit For Geocoder:  Google Maps API</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Recently I needed to get Longitude/Latitudes of long list of cities.(more than thousand cities)&lt;br /&gt;
I used Geocoding API of google maps.&amp;nbsp; Using this API&amp;nbsp; , i sent individual requests to google geocoder passing in the name of individual city and storing back the longitude and latitude it returned.&lt;br /&gt;
&lt;br /&gt;
Since i looped over the name of the cities  , requests to geocoder were sent too quickly. and i got back the result &#39;QUERY OVER LIMIT&#39; . Infact google had specified a query rate limit , you cannot send too many requests in quick succession of time. I am not aware what actual rate limit is used by google , but some hit and trial showed me that if number of requests was kept to 15/s then it was fine.&lt;br /&gt;
&lt;br /&gt;
So i needed a way to sleep my loop after every 10 iterations (using 10/second rate ) . Now first thing that comes to your mind is &#39;hey use sleep function &#39; . Ah i wish i could but javascript supports no &#39;sleep&#39; or &#39;wait&#39; functions.&lt;br /&gt;
&lt;br /&gt;
So what then? Use setTimeout(&quot;function name&quot; , time in milliseconds) . it calls the &#39;function name&#39; after &#39;time in milliseconds&#39; expires.&lt;br /&gt;
&lt;pre class=&quot;brush: javascript&quot;&gt;counter=1; 
mySleepFunction= function ()
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; var geocoder=new google.maps.Geocoder();
&amp;nbsp;&amp;nbsp;&amp;nbsp; var cityList=[&quot;NewYork&quot;,&quot;Tokyo&quot;,&quot;Beijing&quot;,&quot;London&quot;,&quot;Paris&quot;,&quot;Berlin&quot;,&quot;Warsaw&quot;,&quot;Helsinki&quot;,&quot;Stockholm&quot;,,&quot;Lahore&quot;,&quot;Islamabad&quot;,,&quot;Karachi&quot;,&quot;Faisalabad&quot;,,&quot;Multan&quot;,&quot;Peshawar&quot;,,&quot;Quetta&quot;,&quot;Gwadar&quot;]; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for(;counter&amp;lt;= cityList.length ; counter++)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(counter %10 == 0)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; counter++;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; setTimeout(&quot;mySleepFunction()&quot;,5000);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (geocoder)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; geocoder.geocode({ &#39;address&#39;: cityList[counter-1] }, function (results, status)
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (status == google.maps.GeocoderStatus.OK)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log(results[0].address_components[0].long_name+&quot;,&quot;+results[0].geometry.location.lat()+&quot;,&quot;+results[0].geometry.location.lng());
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; // Parse return results here , google sends back xml/json and you can extract longitude/latitude 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //do whatever you like
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; });&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}
&lt;/pre&gt;
&lt;br /&gt;
Here is the result of above script:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHvfUP8TE4Pwq3uRUpLAlI7PhmCDTF4qLra9BNHanCidDq8napuSVphqm-8NKI24UvzdYH4e3k3Im_pWcMyx1-gQevUwXr13G6kx0LFT62j3zsLUVO9FlJmyIjLj-PhMZyLuxquFU1rf_5/s1600/Google+Query+Over+Limit.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;282&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHvfUP8TE4Pwq3uRUpLAlI7PhmCDTF4qLra9BNHanCidDq8napuSVphqm-8NKI24UvzdYH4e3k3Im_pWcMyx1-gQevUwXr13G6kx0LFT62j3zsLUVO9FlJmyIjLj-PhMZyLuxquFU1rf_5/s320/Google+Query+Over+Limit.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
So after every ten iterations , function sets timer for calling itself after 5secs until whole list is processed. I had a list of around 1000 cities and it took me around 15mins to get all the results .&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span id=&quot;:up&quot;&gt;Beware though, Google won&#39;t allow more than 2500 requests from one PC/user/client/&lt;wbr&gt;&lt;/wbr&gt;IP address(??) in 24hrs.&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rizsharif.blogspot.com/feeds/7026452290776815268/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rizsharif.blogspot.com/2010/10/recursion-settimeout-to-simulate-pause.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/7026452290776815268'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4245795051931460477/posts/default/7026452290776815268'/><link rel='alternate' type='text/html' href='http://rizsharif.blogspot.com/2010/10/recursion-settimeout-to-simulate-pause.html' title='Bypass Query Over Limit For Geocoder:  Google Maps API'/><author><name>Rizwan Sharif</name><uri>http://www.blogger.com/profile/01397871644088047383</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8ZWeUMwdJyAl4qfOOBHmlUCWS51vOrWTg2A_LLfuSUpFbDY9V9LbAbceneQPqdgQquQYbneK7ElQ_y6M1J-vhkKY5QrfYGdNa1ykun_Ixup70WdnWvSeuzdSob93K0j8/s1600/*'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHvfUP8TE4Pwq3uRUpLAlI7PhmCDTF4qLra9BNHanCidDq8napuSVphqm-8NKI24UvzdYH4e3k3Im_pWcMyx1-gQevUwXr13G6kx0LFT62j3zsLUVO9FlJmyIjLj-PhMZyLuxquFU1rf_5/s72-c/Google+Query+Over+Limit.PNG" height="72" width="72"/><thr:total>0</thr:total></entry></feed>