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

<channel>
	<title>indiWiz.com &#187; Scripting</title>
	<atom:link href="http://indiwiz.com/category/scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://indiwiz.com</link>
	<description>Subhash&#039;s Tech Log</description>
	<lastBuildDate>Wed, 03 Mar 2010 13:24:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Accessing RESTful WebServices with Prototype.js</title>
		<link>http://indiwiz.com/2009/07/22/accessing-restful-webservices-with-prototype-js/</link>
		<comments>http://indiwiz.com/2009/07/22/accessing-restful-webservices-with-prototype-js/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 07:30:14 +0000</pubDate>
		<dc:creator>Subhash Chandran</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[webservice]]></category>

		<guid isPermaLink="false">http://indiwiz.com/?p=396</guid>
		<description><![CDATA[We can make Ajax requests using Prototype.js (version 1.6.0.3) thus: var url = ...; new Ajax.Request( url, { method:'DELETE', onComplete:function doMessage(response){ alert(response.status); } }); While working on this code, we found out that the method parameter accepted only GET or POST requests. When we give any other request type like DELETE or PUT, the Prototype.js [...]]]></description>
			<content:encoded><![CDATA[<p>We can make Ajax requests using <a href="http://www.prototypejs.org/">Prototype.js</a> (version 1.6.0.3) thus:</p>
<pre class="brush: jscript;">
var url = ...;
new Ajax.Request(
            url,
            {
               method:'DELETE',
               onComplete:function doMessage(response){
                   alert(response.status);
               }
            });
</pre>
<p>While working on this code, we found out that the <tt>method</tt> parameter accepted only GET or POST requests. When we give any other request type like DELETE or PUT, the Prototype.js library converted the request to POST.</p>
<p><a href="http://www.linkedin.com/in/arunjeganath">Arun Jeganath</a> found <a href="https://prototype.lighthouseapp.com/projects/8886/tickets/289-allow-put-delete-and-other-http-methods-on-ajax-requests">this post</a> where the same issue is discussed. The problem was solved when we commented these lines from the Prototype.js code:</p>
<pre>
      if (!['get', 'post'].include(this.method)) {
        //simulate other verbs over post
        params['_method'] = this.method;
        this.method = 'post';
      }
</pre>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://indiwiz.com/2009/07/22/accessing-restful-webservices-with-prototype-js/&amp;title=Accessing+RESTful+WebServices+with+Prototype.js" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://indiwiz.com/2009/07/22/accessing-restful-webservices-with-prototype-js/&amp;title=Accessing+RESTful+WebServices+with+Prototype.js" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://indiwiz.com/2009/07/22/accessing-restful-webservices-with-prototype-js/&amp;title=Accessing+RESTful+WebServices+with+Prototype.js&amp;desc=We%20can%20make%20Ajax%20requests%20using%20Prototype.js%20%28version%201.6.0.3%29%20thus%3A%0D%0A%0D%0A%5Bsourcecode%20language%3D%22javascript%22%5D%0D%0Avar%20url%20%3D%20...%3B%0D%0Anew%20Ajax.Request%28%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20url%2C%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20method%3A%27DELETE%27%2C%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20onComplete%3Afunction%20doMessage%28response%29%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20alert%28response." rel="nofollow" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://indiwiz.com/2009/07/22/accessing-restful-webservices-with-prototype-js/&amp;t=Accessing+RESTful+WebServices+with+Prototype.js" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://indiwiz.com/2009/07/22/accessing-restful-webservices-with-prototype-js/&amp;title=Accessing+RESTful+WebServices+with+Prototype.js&amp;summary=We%20can%20make%20Ajax%20requests%20using%20Prototype.js%20%28version%201.6.0.3%29%20thus%3A%0D%0A%0D%0A%5Bsourcecode%20language%3D%22javascript%22%5D%0D%0Avar%20url%20%3D%20...%3B%0D%0Anew%20Ajax.Request%28%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20url%2C%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20method%3A%27DELETE%27%2C%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20onComplete%3Afunction%20doMessage%28response%29%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20alert%28response.&amp;source=indiWiz.com" rel="nofollow" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://indiwiz.com/2009/07/22/accessing-restful-webservices-with-prototype-js/&amp;title=Accessing+RESTful+WebServices+with+Prototype.js" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://indiwiz.com/2009/07/22/accessing-restful-webservices-with-prototype-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>37 Signals Launches Sprockets</title>
		<link>http://indiwiz.com/2009/02/20/37-signals-launches-sprockets/</link>
		<comments>http://indiwiz.com/2009/02/20/37-signals-launches-sprockets/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 08:58:04 +0000</pubDate>
		<dc:creator>Subhash Chandran</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[news]]></category>

		<guid isPermaLink="false">http://indiwiz.com/?p=207</guid>
		<description><![CDATA[Sprockets (site) is described thus: Sprockets is a Ruby library that preprocesses and concatenates JavaScript source files. This is not a new idea, I have seen similar compiler in Liferay source for aggregating CSS files. Since this is sponsored by 37 Signals (creators or Ruby on Rails), Sprockets&#8217;s syntax can become a kind of standard. [...]]]></description>
			<content:encoded><![CDATA[<p>Sprockets (<a href="http://getsprockets.org/">site</a>) is described thus: <i>Sprockets is a Ruby library that preprocesses and concatenates JavaScript source files</i>. This is not a new idea, I have seen similar compiler in <a href="http://www.liferay.com/">Liferay</a> source for aggregating CSS files. Since this is sponsored by <a href="http://www.37signals.com/">37 Signals</a> (creators or Ruby on Rails), Sprockets&#8217;s syntax can become a kind of standard. Already <a href="http://www.prototypejs.org/">Prototype</a> and <a href="http://script.aculo.us/">Script.aculo.us</a> JavaScript libraries (two OpenSource JavaScript libraries popular in RoR) comply to Sprockets&#8217;s syntax.</p>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://indiwiz.com/2009/02/20/37-signals-launches-sprockets/&amp;title=37+Signals+Launches+Sprockets" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://indiwiz.com/2009/02/20/37-signals-launches-sprockets/&amp;title=37+Signals+Launches+Sprockets" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://indiwiz.com/2009/02/20/37-signals-launches-sprockets/&amp;title=37+Signals+Launches+Sprockets&amp;desc=Sprockets%20%28site%29%20is%20described%20thus%3A%20Sprockets%20is%20a%20Ruby%20library%20that%20preprocesses%20and%20concatenates%20JavaScript%20source%20files.%20This%20is%20not%20a%20new%20idea%2C%20I%20have%20seen%20similar%20compiler%20in%20Liferay%20source%20for%20aggregating%20CSS%20files.%20Since%20this%20is%20sponsored%20by%2037%20Signals%20%28creators%20or%20Ruby%20on%20Rails%29%2C%20Sprockets%27s" rel="nofollow" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://indiwiz.com/2009/02/20/37-signals-launches-sprockets/&amp;t=37+Signals+Launches+Sprockets" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://indiwiz.com/2009/02/20/37-signals-launches-sprockets/&amp;title=37+Signals+Launches+Sprockets&amp;summary=Sprockets%20%28site%29%20is%20described%20thus%3A%20Sprockets%20is%20a%20Ruby%20library%20that%20preprocesses%20and%20concatenates%20JavaScript%20source%20files.%20This%20is%20not%20a%20new%20idea%2C%20I%20have%20seen%20similar%20compiler%20in%20Liferay%20source%20for%20aggregating%20CSS%20files.%20Since%20this%20is%20sponsored%20by%2037%20Signals%20%28creators%20or%20Ruby%20on%20Rails%29%2C%20Sprockets%27s&amp;source=indiWiz.com" rel="nofollow" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://indiwiz.com/2009/02/20/37-signals-launches-sprockets/&amp;title=37+Signals+Launches+Sprockets" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://indiwiz.com/2009/02/20/37-signals-launches-sprockets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google CDN for popular JavaScript libraries</title>
		<link>http://indiwiz.com/2009/01/27/google-cdn-for-popular-javascript-libraries/</link>
		<comments>http://indiwiz.com/2009/01/27/google-cdn-for-popular-javascript-libraries/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 14:35:10 +0000</pubDate>
		<dc:creator>Subhash Chandran</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://indiwiz.com/?p=184</guid>
		<description><![CDATA[Google is hosting versions of popular OpenSource JavaScript libraries (as a CDN&#8211;Content Delivery Network). The list of libraries include Prototype, jQuery, Scriptaculous, YUI and others. These can be directly linked to the Google URL. The advantages: Bandwidth saving: these files need not be hosted in local webservers, saving local bandwidth. Effective client side caching: if [...]]]></description>
			<content:encoded><![CDATA[<p>Google is <a href="http://code.google.com/apis/ajaxlibs/">hosting versions of popular OpenSource JavaScript libraries</a> (as a <a href="http://en.wikipedia.org/wiki/Content_Delivery_Network">CDN&#8211;Content Delivery Network</a>). The list of libraries include <a href="http://www.prototypejs.org/">Prototype</a>, <a href="http://jquery.com/">jQuery</a>, <a href="http://script.aculo.us/">Scriptaculous</a>, <a href="http://developer.yahoo.com/yui/">YUI</a> and others. These can be directly linked to the Google URL. The advantages:</p>
<ul>
<li>Bandwidth saving: these files need not be hosted in local webservers, saving local bandwidth.</li>
<li>Effective client side caching: if a person visits 100 sites using Prototype library version 1.6.0.3, and if all these sites link to the Google CDN, then the script will be downloaded to the user&#8217;s system only once.</li>
</ul>
<p>Now the common fear among people: what if the URL changes? What happens when newer version of the libraries come up? Google&#8217;s promise (from the site):</p>
<p><i>Google works directly with the key stake holders for each library effort and accepts the latest stable versions as they are released. Once we host a release of a given library, we are committed to hosting that release indefinitely.</i></p>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://indiwiz.com/2009/01/27/google-cdn-for-popular-javascript-libraries/&amp;title=Google+CDN+for+popular+JavaScript+libraries" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://indiwiz.com/2009/01/27/google-cdn-for-popular-javascript-libraries/&amp;title=Google+CDN+for+popular+JavaScript+libraries" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://indiwiz.com/2009/01/27/google-cdn-for-popular-javascript-libraries/&amp;title=Google+CDN+for+popular+JavaScript+libraries&amp;desc=Google%20is%20hosting%20versions%20of%20popular%20OpenSource%20JavaScript%20libraries%20%28as%20a%20CDN--Content%20Delivery%20Network%29.%20The%20list%20of%20libraries%20include%20Prototype%2C%20jQuery%2C%20Scriptaculous%2C%20YUI%20and%20others.%20These%20can%20be%20directly%20linked%20to%20the%20Google%20URL.%20The%20advantages%3A%0A%0A%0ABandwidth%20saving%3A%20these%20files%20need%20not%20be%20host" rel="nofollow" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://indiwiz.com/2009/01/27/google-cdn-for-popular-javascript-libraries/&amp;t=Google+CDN+for+popular+JavaScript+libraries" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://indiwiz.com/2009/01/27/google-cdn-for-popular-javascript-libraries/&amp;title=Google+CDN+for+popular+JavaScript+libraries&amp;summary=Google%20is%20hosting%20versions%20of%20popular%20OpenSource%20JavaScript%20libraries%20%28as%20a%20CDN--Content%20Delivery%20Network%29.%20The%20list%20of%20libraries%20include%20Prototype%2C%20jQuery%2C%20Scriptaculous%2C%20YUI%20and%20others.%20These%20can%20be%20directly%20linked%20to%20the%20Google%20URL.%20The%20advantages%3A%0A%0A%0ABandwidth%20saving%3A%20these%20files%20need%20not%20be%20host&amp;source=indiWiz.com" rel="nofollow" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://indiwiz.com/2009/01/27/google-cdn-for-popular-javascript-libraries/&amp;title=Google+CDN+for+popular+JavaScript+libraries" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://indiwiz.com/2009/01/27/google-cdn-for-popular-javascript-libraries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JEdit Macro for XML/HTML Special Character Conversion</title>
		<link>http://indiwiz.com/2008/12/31/jedit-macro-for-xml-special-character-conversion/</link>
		<comments>http://indiwiz.com/2008/12/31/jedit-macro-for-xml-special-character-conversion/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 08:33:26 +0000</pubDate>
		<dc:creator>Subhash Chandran</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[jedit]]></category>

		<guid isPermaLink="false">http://indiwiz.com/?p=126</guid>
		<description><![CDATA[One of the common requirement I face often when posting text to blog/forum/Wiki etc. is character conversion: &#38; &#38;amp; &#60; &#38;lt; &#62; &#38;gt; &#34; &#38;quot; &apos; &#38;apos; I developed a small JEdit Macro for doing this. This macro can be executed from JEdit menu Macros &#62; Run Other Macro..., or can be installed by copying [...]]]></description>
			<content:encoded><![CDATA[<p>One of the common requirement I face often when posting text to blog/forum/Wiki etc. is character conversion:</p>
<table border="0" cellspacing="5">
<tr>
<td>&amp;</td>
<td><tt>&amp;amp;</tt></td>
</tr>
<tr>
<td>&lt;</td>
<td><tt>&amp;lt;</tt></td>
</tr>
<tr>
<td>&gt;</td>
<td><tt>&amp;gt;</tt></td>
</tr>
<tr>
<td>&quot;</td>
<td><tt>&amp;quot;</tt></td>
</tr>
<tr>
<td>&apos;</td>
<td><tt>&amp;apos;</tt></td>
</tr>
</table>
<p>I developed a small <a href="http://code.google.com/p/wiztools/source/browse/jedit-macros/trunk/encodeForXML.bsh">JEdit Macro</a> for doing this. This macro can be executed from JEdit menu <tt>Macros &gt; Run Other Macro...</tt>, or can be installed by copying to: <tt>${user.home}/.jedit/macros/</tt> (later executed from the menu <tt>Macros</tt>). This macro operates on selected text.</p>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://indiwiz.com/2008/12/31/jedit-macro-for-xml-special-character-conversion/&amp;title=JEdit+Macro+for+XML%2FHTML+Special+Character+Conversion" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://indiwiz.com/2008/12/31/jedit-macro-for-xml-special-character-conversion/&amp;title=JEdit+Macro+for+XML%2FHTML+Special+Character+Conversion" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://indiwiz.com/2008/12/31/jedit-macro-for-xml-special-character-conversion/&amp;title=JEdit+Macro+for+XML%2FHTML+Special+Character+Conversion&amp;desc=One%20of%20the%20common%20requirement%20I%20face%20often%20when%20posting%20text%20to%20blog%2Fforum%2FWiki%20etc.%20is%20character%20conversion%3A%0D%0A%0D%0A%0D%0A%0D%0A%20%20%26amp%3B%26amp%3Bamp%3B%0D%0A%0D%0A%0D%0A%20%20%26lt%3B%26amp%3Blt%3B%0D%0A%0D%0A%0D%0A%20%20%26gt%3B%26amp%3Bgt%3B%0D%0A%0D%0A%0D%0A%20%20%26quot%3B%26amp%3Bquot%3B%0D%0A%0D%0A%0D%0A%20%20%26apos%3B%26amp%3Bapos%3B%0D%0A%0D%0A%0D%0A%0D%0AI%20developed%20a%20small%20JEdit%20Macro%20for%20doing%20this.%20This%20macro%20can%20be%20execu" rel="nofollow" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://indiwiz.com/2008/12/31/jedit-macro-for-xml-special-character-conversion/&amp;t=JEdit+Macro+for+XML%2FHTML+Special+Character+Conversion" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://indiwiz.com/2008/12/31/jedit-macro-for-xml-special-character-conversion/&amp;title=JEdit+Macro+for+XML%2FHTML+Special+Character+Conversion&amp;summary=One%20of%20the%20common%20requirement%20I%20face%20often%20when%20posting%20text%20to%20blog%2Fforum%2FWiki%20etc.%20is%20character%20conversion%3A%0D%0A%0D%0A%0D%0A%0D%0A%20%20%26amp%3B%26amp%3Bamp%3B%0D%0A%0D%0A%0D%0A%20%20%26lt%3B%26amp%3Blt%3B%0D%0A%0D%0A%0D%0A%20%20%26gt%3B%26amp%3Bgt%3B%0D%0A%0D%0A%0D%0A%20%20%26quot%3B%26amp%3Bquot%3B%0D%0A%0D%0A%0D%0A%20%20%26apos%3B%26amp%3Bapos%3B%0D%0A%0D%0A%0D%0A%0D%0AI%20developed%20a%20small%20JEdit%20Macro%20for%20doing%20this.%20This%20macro%20can%20be%20execu&amp;source=indiWiz.com" rel="nofollow" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://indiwiz.com/2008/12/31/jedit-macro-for-xml-special-character-conversion/&amp;title=JEdit+Macro+for+XML%2FHTML+Special+Character+Conversion" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://indiwiz.com/2008/12/31/jedit-macro-for-xml-special-character-conversion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Search for the perfect Ajax auto-complete library</title>
		<link>http://indiwiz.com/2008/12/31/search-for-the-perfect-ajax-auto-complete/</link>
		<comments>http://indiwiz.com/2008/12/31/search-for-the-perfect-ajax-auto-complete/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 06:47:25 +0000</pubDate>
		<dc:creator>Subhash Chandran</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://indiwiz.com/?p=121</guid>
		<description><![CDATA[Yesterday we (Krithika and myself) spent some time finding a perfect Ajax auto-complete solution for one of our internal projects. We wanted to have a tag search box with auto-complete functionality. We had created a front-end layer for our Java tagging API (developed by Arun) using RESTful interface. This exposed searched result in JSON. So [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday we (Krithika and myself) spent some time finding a perfect Ajax auto-complete solution for one of our internal projects. We wanted to have a tag search box with auto-complete functionality. We had created a front-end layer for our Java tagging API (developed by Arun) using RESTful interface. This exposed searched result in JSON. So our need was for a Ajax library which provided auto-complete feature which satisfied following parameters:</p>
<ol>
<li>The code we need to incorporate for enabling auto-complete should be minimal.</li>
<li>Should not be flashy.</li>
<li>Should consume JSON content.</li>
</ol>
<p>This seemed to be a trivial task, but it took quite some time to find and finalize on <a href="http://www.beauscott.com/examples/autocomplete/doc/ns_examples.html">AutoComplete 1.2 by Beau Scott</a>. This script was simple to integrate, and did not require us to configure any sophisticated CSS. It allowed us to consume our RESTful service without any modification.</p>
<p>During our search, we were surprised to find how badly certain popular Ajax libraries implemented this oft-used functionality. The famous <a href="http://script.aculo.us/">Scriptaculous</a> library&#8217;s implementation has the implementation detailed here: <a href="http://github.com/madrobby/scriptaculous/wikis/ajax-autocompleter">http://github.com/madrobby/scriptaculous/wikis/ajax-autocompleter</a>. If you go through this document, you will see that the script requires the server to return data in this format:</p>
<pre>
&lt;ul&gt;
    &lt;li&gt;your mom&lt;/li&gt;
    &lt;li&gt;yodel&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>This is bad design. A server code returning data as HTML. This cannot be consumed effectively by other clients. The next one which we picked up was <a href="http://developer.yahoo.com/yui/autocomplete/">YUI Autocomplete</a>. The amount of configuration effort needed from our side scared us. We didn&#8217;t plunge deeper!</p>
<p>Another one which we tried was <a href="http://www.devbridge.com/projects/autocomplete/">DevBridge&#8217;s Auto Complete</a>. This looked simple to implement, and the look and feel was simplistic. But it had an issue: the call to the server-side code was passed as a query string (<tt>query=</tt>). We were using RESTful URL and we cannot modify our backend-code to comply to the requirements of the UI layer. But I did a little hack and made this script compliant to our requirement. But finally, we decided against using this patched-script because it had additional dependencies like images and CSS styles to be specified.</p>
<p>As said earlier, the script which matched all our requirements was <a href="http://www.beauscott.com/examples/autocomplete/doc/ns_examples.html">AutoComplete 1.2 by Beau Scott</a>.</p>
<p>The only worry for me from this exercise was the divide between the front-end developers and backend developers. Such a common functionality was not being addressed by popular frameworks without sacrificing functionality and addressing usability&#8211;and, more importantly, complying to established enterprise patterns like consuming data (like JSON and XML instead of HTML snippet) and support for RESTful URLs.</p>
<p>Hope 2009 annihilates this divide <img src='http://indiwiz.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://indiwiz.com/2008/12/31/search-for-the-perfect-ajax-auto-complete/&amp;title=Search+for+the+perfect+Ajax+auto-complete+library" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://indiwiz.com/2008/12/31/search-for-the-perfect-ajax-auto-complete/&amp;title=Search+for+the+perfect+Ajax+auto-complete+library" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://indiwiz.com/2008/12/31/search-for-the-perfect-ajax-auto-complete/&amp;title=Search+for+the+perfect+Ajax+auto-complete+library&amp;desc=Yesterday%20we%20%28Krithika%20and%20myself%29%20spent%20some%20time%20finding%20a%20perfect%20Ajax%20auto-complete%20solution%20for%20one%20of%20our%20internal%20projects.%20We%20wanted%20to%20have%20a%20tag%20search%20box%20with%20auto-complete%20functionality.%20We%20had%20created%20a%20front-end%20layer%20for%20our%20Java%20tagging%20API%20%28developed%20by%20Arun%29%20using%20RESTful%20interfac" rel="nofollow" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://indiwiz.com/2008/12/31/search-for-the-perfect-ajax-auto-complete/&amp;t=Search+for+the+perfect+Ajax+auto-complete+library" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://indiwiz.com/2008/12/31/search-for-the-perfect-ajax-auto-complete/&amp;title=Search+for+the+perfect+Ajax+auto-complete+library&amp;summary=Yesterday%20we%20%28Krithika%20and%20myself%29%20spent%20some%20time%20finding%20a%20perfect%20Ajax%20auto-complete%20solution%20for%20one%20of%20our%20internal%20projects.%20We%20wanted%20to%20have%20a%20tag%20search%20box%20with%20auto-complete%20functionality.%20We%20had%20created%20a%20front-end%20layer%20for%20our%20Java%20tagging%20API%20%28developed%20by%20Arun%29%20using%20RESTful%20interfac&amp;source=indiWiz.com" rel="nofollow" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://indiwiz.com/2008/12/31/search-for-the-perfect-ajax-auto-complete/&amp;title=Search+for+the+perfect+Ajax+auto-complete+library" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://indiwiz.com/2008/12/31/search-for-the-perfect-ajax-auto-complete/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JEdit, powerful search and replace using BeanShell</title>
		<link>http://indiwiz.com/2008/12/17/jedit-powerful-search-and-replace-using-beanshell/</link>
		<comments>http://indiwiz.com/2008/12/17/jedit-powerful-search-and-replace-using-beanshell/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 08:57:12 +0000</pubDate>
		<dc:creator>Subhash Chandran</dc:creator>
				<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[jedit]]></category>

		<guid isPermaLink="false">http://indiwiz.com/?p=95</guid>
		<description><![CDATA[JEdit is my favorite text editor. And today I was pleased to find some powerful scripting capability in its search and replace functionality. Basically I wanted to enclose a RegularExpression pattern with: &#60;a href=""&#62;PATTERN&#60;/a&#62; The Search and Replace dialog provided an option Return value of a BeanShell snippet. So whatever RegularExpression pattern grouping I provided, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.jedit.org/">JEdit</a> is my favorite text editor. And today I was pleased to find some powerful scripting capability in its <a href="http://www.jedit.org/users-guide/search-replace.html">search and replace functionality</a>. Basically I wanted to enclose a RegularExpression pattern with:</p>
<pre>
&lt;a href=""&gt;PATTERN&lt;/a&gt;
</pre>
<p>The Search and Replace dialog provided an option <i>Return value of a BeanShell snippet</i>. So whatever RegularExpression pattern grouping I provided, I was able to access them using the BeanShell variable <i>_1</i> to <i>_9</i>. So my final replace statement became:</p>
<pre>
"&lt;a href\"\"&gt;" + _1 + "&lt;/a&gt;"
</pre>
<p>Cool solution to a simple problem.</p>
<p><img src="http://indiwiz.files.wordpress.com/2008/12/jedit_search_replace.png" alt="jedit_search_replace" title="jedit_search_replace" width="505" height="449" class="alignnone size-full wp-image-99" /></p>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://indiwiz.com/2008/12/17/jedit-powerful-search-and-replace-using-beanshell/&amp;title=JEdit%2C+powerful+search+and+replace+using+BeanShell" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://indiwiz.com/2008/12/17/jedit-powerful-search-and-replace-using-beanshell/&amp;title=JEdit%2C+powerful+search+and+replace+using+BeanShell" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://indiwiz.com/2008/12/17/jedit-powerful-search-and-replace-using-beanshell/&amp;title=JEdit%2C+powerful+search+and+replace+using+BeanShell&amp;desc=JEdit%20is%20my%20favorite%20text%20editor.%20And%20today%20I%20was%20pleased%20to%20find%20some%20powerful%20scripting%20capability%20in%20its%20search%20and%20replace%20functionality.%20Basically%20I%20wanted%20to%20enclose%20a%20RegularExpression%20pattern%20with%3A%0A%0A%0A%26lt%3Ba%20href%3D%22%22%26gt%3BPATTERN%26lt%3B%2Fa%26gt%3B%0A%0A%0AThe%20Search%20and%20Replace%20dialog%20provided%20an%20option%20Return" rel="nofollow" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://indiwiz.com/2008/12/17/jedit-powerful-search-and-replace-using-beanshell/&amp;t=JEdit%2C+powerful+search+and+replace+using+BeanShell" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://indiwiz.com/2008/12/17/jedit-powerful-search-and-replace-using-beanshell/&amp;title=JEdit%2C+powerful+search+and+replace+using+BeanShell&amp;summary=JEdit%20is%20my%20favorite%20text%20editor.%20And%20today%20I%20was%20pleased%20to%20find%20some%20powerful%20scripting%20capability%20in%20its%20search%20and%20replace%20functionality.%20Basically%20I%20wanted%20to%20enclose%20a%20RegularExpression%20pattern%20with%3A%0A%0A%0A%26lt%3Ba%20href%3D%22%22%26gt%3BPATTERN%26lt%3B%2Fa%26gt%3B%0A%0A%0AThe%20Search%20and%20Replace%20dialog%20provided%20an%20option%20Return&amp;source=indiWiz.com" rel="nofollow" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://indiwiz.com/2008/12/17/jedit-powerful-search-and-replace-using-beanshell/&amp;title=JEdit%2C+powerful+search+and+replace+using+BeanShell" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://indiwiz.com/2008/12/17/jedit-powerful-search-and-replace-using-beanshell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript: Dynamically Creating and Manipulating DOM Elements</title>
		<link>http://indiwiz.com/2008/12/10/javascript-dynamically-creating-and-manipulating-dom-elements/</link>
		<comments>http://indiwiz.com/2008/12/10/javascript-dynamically-creating-and-manipulating-dom-elements/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 09:24:49 +0000</pubDate>
		<dc:creator>Subhash Chandran</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://indiwiz.com/?p=57</guid>
		<description><![CDATA[I was pleasantly surprised to see that JavaScript now supports XML-DOM methods for manipulating JavaScript DOM trees. A quick look at the features: Init Before we proceed with the examples, the setup part. All the examples that follow assume the existence of this in the HTML page: &#60;div id=&#34;placeholderId&#34;/&#62; Creating new element Let us assume [...]]]></description>
			<content:encoded><![CDATA[<p>I was pleasantly surprised to see that JavaScript now supports XML-DOM methods for manipulating JavaScript DOM trees. A quick look at the features:</p>
<h3>Init</h3>
<p>Before we proceed with the examples, the setup part. All the examples that follow assume the existence of this in the HTML page:</p>
<pre class="brush: xml;">
&lt;div id=&quot;placeholderId&quot;/&gt;
</pre>
<h3>Creating new element</h3>
<p>Let us assume the requirement of placing <tt>&lt;br/&gt;</tt> element inside the placeholder. The code:</p>
<pre class="brush: jscript;">
var e = document.getElementById('placeholderId');
var eBr = document.createElement('br');
e.appendChild(eBr);
</pre>
<h3>Adding attribute</h3>
<p>Suppose we want to add the attribute <tt>id=&quot;brId&quot;</tt>, we would write:</p>
<pre class="brush: jscript;">
eBr.setAttribute('id', 'brId');
</pre>
<h3>Deleting attribute</h3>
<pre class="brush: jscript;">
eBr.removeAttribute('id');
</pre>
<h3>Deleting element</h3>
<pre class="brush: jscript;">
var e = document.getElementById('brId');
var eParent = e.parentNode;
eParent.removeChild(e);
</pre>
<h3>Creating elements with text element</h3>
<p>Consider that we want to have the following paragraph element inside the <tt>placeholderId</tt> <tt>&lt;div&gt;</tt>:</p>
<pre>
&lt;p align="right"&gt;Hello World!&lt;/p&gt;
</pre>
<p>It can be achieved thus:</p>
<pre class="brush: jscript;">
var e = document.getElementById('placeholderId');
var ePara = document.createElement('p');
ePara.setAttribute('align', 'right');
var eTxt = document.createTextNode('Hello World!');
ePara.appendChild(eTxt);
e.appendChild(ePara);
</pre>
<p>Happy hacking with this info <img src='http://indiwiz.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://indiwiz.com/2008/12/10/javascript-dynamically-creating-and-manipulating-dom-elements/&amp;title=JavaScript%3A+Dynamically+Creating+and+Manipulating+DOM+Elements" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://indiwiz.com/2008/12/10/javascript-dynamically-creating-and-manipulating-dom-elements/&amp;title=JavaScript%3A+Dynamically+Creating+and+Manipulating+DOM+Elements" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://indiwiz.com/2008/12/10/javascript-dynamically-creating-and-manipulating-dom-elements/&amp;title=JavaScript%3A+Dynamically+Creating+and+Manipulating+DOM+Elements&amp;desc=I%20was%20pleasantly%20surprised%20to%20see%20that%20JavaScript%20now%20supports%20XML-DOM%20methods%20for%20manipulating%20JavaScript%20DOM%20trees.%20A%20quick%20look%20at%20the%20features%3A%0A%0AInit%0A%0ABefore%20we%20proceed%20with%20the%20examples%2C%20the%20setup%20part.%20All%20the%20examples%20that%20follow%20assume%20the%20existence%20of%20this%20in%20the%20HTML%20page%3A%0A%0A%5Bsourcecode%20lan" rel="nofollow" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://indiwiz.com/2008/12/10/javascript-dynamically-creating-and-manipulating-dom-elements/&amp;t=JavaScript%3A+Dynamically+Creating+and+Manipulating+DOM+Elements" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://indiwiz.com/2008/12/10/javascript-dynamically-creating-and-manipulating-dom-elements/&amp;title=JavaScript%3A+Dynamically+Creating+and+Manipulating+DOM+Elements&amp;summary=I%20was%20pleasantly%20surprised%20to%20see%20that%20JavaScript%20now%20supports%20XML-DOM%20methods%20for%20manipulating%20JavaScript%20DOM%20trees.%20A%20quick%20look%20at%20the%20features%3A%0A%0AInit%0A%0ABefore%20we%20proceed%20with%20the%20examples%2C%20the%20setup%20part.%20All%20the%20examples%20that%20follow%20assume%20the%20existence%20of%20this%20in%20the%20HTML%20page%3A%0A%0A%5Bsourcecode%20lan&amp;source=indiWiz.com" rel="nofollow" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://indiwiz.com/2008/12/10/javascript-dynamically-creating-and-manipulating-dom-elements/&amp;title=JavaScript%3A+Dynamically+Creating+and+Manipulating+DOM+Elements" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://indiwiz.com/2008/12/10/javascript-dynamically-creating-and-manipulating-dom-elements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python 3.0 Released</title>
		<link>http://indiwiz.com/2008/12/08/python-30-released/</link>
		<comments>http://indiwiz.com/2008/12/08/python-30-released/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 04:52:10 +0000</pubDate>
		<dc:creator>Subhash Chandran</dc:creator>
				<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://indiwiz.com/?p=46</guid>
		<description><![CDATA[My language of preference after Java, has a new release: 3.0. This is an interesting release as it breaks backwards compatibility. A conversion tool for 2.0 code migration to 3.0 is also made available by the community. Share this on del.icio.us Digg this! Post this on Diigo Share this on Facebook Share this on LinkedIn [...]]]></description>
			<content:encoded><![CDATA[<p>My language of preference after Java, has a new release: <a href="http://python.org/download/releases/3.0/">3.0</a>. This is an interesting release as it <a href="http://docs.python.org/3.0/whatsnew/3.0.html">breaks backwards compatibility</a>. A <a href="http://svn.python.org/view/sandbox/trunk/2to3/">conversion tool</a> for 2.0 code migration to 3.0 is also <a href="http://svn.python.org/view/sandbox/trunk/2to3/">made available by the community</a>.</p>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://indiwiz.com/2008/12/08/python-30-released/&amp;title=Python+3.0+Released" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://indiwiz.com/2008/12/08/python-30-released/&amp;title=Python+3.0+Released" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://indiwiz.com/2008/12/08/python-30-released/&amp;title=Python+3.0+Released&amp;desc=My%20language%20of%20preference%20after%20Java%2C%20has%20a%20new%20release%3A%203.0.%20This%20is%20an%20interesting%20release%20as%20it%20breaks%20backwards%20compatibility.%20A%20conversion%20tool%20for%202.0%20code%20migration%20to%203.0%20is%20also%20made%20available%20by%20the%20community." rel="nofollow" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://indiwiz.com/2008/12/08/python-30-released/&amp;t=Python+3.0+Released" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://indiwiz.com/2008/12/08/python-30-released/&amp;title=Python+3.0+Released&amp;summary=My%20language%20of%20preference%20after%20Java%2C%20has%20a%20new%20release%3A%203.0.%20This%20is%20an%20interesting%20release%20as%20it%20breaks%20backwards%20compatibility.%20A%20conversion%20tool%20for%202.0%20code%20migration%20to%203.0%20is%20also%20made%20available%20by%20the%20community.&amp;source=indiWiz.com" rel="nofollow" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://indiwiz.com/2008/12/08/python-30-released/&amp;title=Python+3.0+Released" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://indiwiz.com/2008/12/08/python-30-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beautiful Closures</title>
		<link>http://indiwiz.com/2008/11/18/beautiful-closures/</link>
		<comments>http://indiwiz.com/2008/11/18/beautiful-closures/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 08:27:54 +0000</pubDate>
		<dc:creator>Subhash Chandran</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[closure]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://indiwiz.wordpress.com/?p=6</guid>
		<description><![CDATA[One of the irritating things when writing code in Java is when managing files or database resources. We have to write so much redundant code: File f = new File(&#34;/etc/passwd&#34;); BufferedReader br = null; try{ br = new BufferedReader(new FileReader(f)); String str; while((str=br.readLine())!=null){ System.out.println(str); } } catch(IOException ex){ ... } finally{ if(br != null){ try{ [...]]]></description>
			<content:encoded><![CDATA[<p>One of the irritating things when writing code in Java is when managing files or database resources. We have to write so much redundant code:</p>
<pre class="brush: java;">
File f = new File(&quot;/etc/passwd&quot;);
BufferedReader br = null;
try{
  br = new BufferedReader(new FileReader(f));
  String str;
  while((str=br.readLine())!=null){
    System.out.println(str);
  }
}
catch(IOException ex){
  ...
}
finally{
  if(br != null){
    try{
      br.close();
    }
    catch(IOException ex){
      ...
    }
  }
}
</pre>
<p>So much redundancy is ground for human errors. Issues like these are beautifully solved using programming concept called Closures. For example, in the newly released 2.6 version of Python, the same would be written as:</p>
<pre class="brush: python;">
with open('/etc/passwd', 'r') as f:
    for line in f:
        print line
</pre>
<p>In the above code, even when an exception is raised during file read, the file is gracefully closed when the control exits with block. A similar example in Groovy:</p>
<pre class="brush: java;">
File f = new File(&quot;/etc/passwd&quot;)
f.eachLine{
  line -&gt;
  println line
}
</pre>
<p>Martin Fowler has written a short introduction to <a href="http://martinfowler.com/bliki/Closure.html">Closures</a>.</p>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://indiwiz.com/2008/11/18/beautiful-closures/&amp;title=Beautiful+Closures" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://indiwiz.com/2008/11/18/beautiful-closures/&amp;title=Beautiful+Closures" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://indiwiz.com/2008/11/18/beautiful-closures/&amp;title=Beautiful+Closures&amp;desc=One%20of%20the%20irritating%20things%20when%20writing%20code%20in%20Java%20is%20when%20managing%20files%20or%20database%20resources.%20We%20have%20to%20write%20so%20much%20redundant%20code%3A%0A%0A%5Bsourcecode%20language%3D%27java%27%5D%0AFile%20f%20%3D%20new%20File%28%22%2Fetc%2Fpasswd%22%29%3B%0ABufferedReader%20br%20%3D%20null%3B%0Atry%7B%0A%20%20br%20%3D%20new%20BufferedReader%28new%20FileReader%28f%29%29%3B%0A%20%20String%20str%3B%0A%20%20w" rel="nofollow" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://indiwiz.com/2008/11/18/beautiful-closures/&amp;t=Beautiful+Closures" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://indiwiz.com/2008/11/18/beautiful-closures/&amp;title=Beautiful+Closures&amp;summary=One%20of%20the%20irritating%20things%20when%20writing%20code%20in%20Java%20is%20when%20managing%20files%20or%20database%20resources.%20We%20have%20to%20write%20so%20much%20redundant%20code%3A%0A%0A%5Bsourcecode%20language%3D%27java%27%5D%0AFile%20f%20%3D%20new%20File%28%22%2Fetc%2Fpasswd%22%29%3B%0ABufferedReader%20br%20%3D%20null%3B%0Atry%7B%0A%20%20br%20%3D%20new%20BufferedReader%28new%20FileReader%28f%29%29%3B%0A%20%20String%20str%3B%0A%20%20w&amp;source=indiWiz.com" rel="nofollow" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://indiwiz.com/2008/11/18/beautiful-closures/&amp;title=Beautiful+Closures" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://indiwiz.com/2008/11/18/beautiful-closures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
