<?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>on the count of three</title>
	<atom:link href="http://www.aloshbennett.in/weblog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.aloshbennett.in/weblog</link>
	<description>script, goodies and kind</description>
	<lastBuildDate>Sun, 23 Oct 2011 09:12:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>30 sec puzzle: spot the null pointer</title>
		<link>http://www.aloshbennett.in/weblog/2011/java/30-sec-puzzle-spot-the-null-pointer/</link>
		<comments>http://www.aloshbennett.in/weblog/2011/java/30-sec-puzzle-spot-the-null-pointer/#comments</comments>
		<pubDate>Sun, 23 Oct 2011 09:12:05 +0000</pubDate>
		<dc:creator>aloshbennett</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.aloshbennett.in/weblog/?p=280</guid>
		<description><![CDATA[I got a null pointer exception at the line mentioned. What could have caused it? private ARTTimerTask timerTask = ARTTimerTask.getInstance&#40;&#41;; ... public void notify&#40;String messageId, Long messageTime&#41; &#123; ... //NPE in the line below timerTask.addMessage&#40;messageId, System.currentTimeMillis&#40;&#41; - messageTime&#41;; &#125; Here&#8217;s the relevant section from ARTTimerTask: private static final ARTTimerTask _INSTANCE = new ARTTimerTask&#40;&#41;; &#160; public [...]]]></description>
			<content:encoded><![CDATA[<p>I got a null pointer exception at the line mentioned. What could have caused it?</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">private</span> ARTTimerTask timerTask <span style="color: #339933;">=</span> ARTTimerTask.<span style="color: #660066;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...
<span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> notify<span style="color: #009900;">&#40;</span>String messageId<span style="color: #339933;">,</span> Long messageTime<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    ...
    <span style="color: #006600; font-style: italic;">//NPE in the line below</span>
    timerTask.<span style="color: #660066;">addMessage</span><span style="color: #009900;">&#40;</span>messageId<span style="color: #339933;">,</span>
                  System.<span style="color: #660066;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> messageTime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Here&#8217;s the relevant section from ARTTimerTask:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">private</span> static final ARTTimerTask _INSTANCE 
                                <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ARTTimerTask<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">public</span> static ARTTimerTask getInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> _INSTANCE<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>(Debashish comes over to the desk, takes a look and proclaims, &#8220;This A*** B***** is pathetic&#8221;. 7 seconds!)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aloshbennett.in/weblog/2011/java/30-sec-puzzle-spot-the-null-pointer/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Moving on</title>
		<link>http://www.aloshbennett.in/weblog/2011/java/moving-on/</link>
		<comments>http://www.aloshbennett.in/weblog/2011/java/moving-on/#comments</comments>
		<pubDate>Sat, 30 Apr 2011 09:09:55 +0000</pubDate>
		<dc:creator>aloshbennett</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.aloshbennett.in/weblog/?p=269</guid>
		<description><![CDATA[I&#8217;ve decided to call it a day at Oracle. And its been a long day too. As part of Innovation Labs at 24/7 Customer, my new organization, we are building a platform for predictive analysis and intervention in CLM area. A lot of exciting things on the plate already and the team is very passionate [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve decided to call it a day at Oracle. And its been a long day too.</p>
<p>As part of <a href="http://www.247customer.com/company/24x7-ilabs.php">Innovation Labs</a> at 24/7 Customer, my new organization, we are building a platform for predictive analysis and intervention in CLM area. A lot of exciting things on the plate already and the team is very passionate and dynamic. Small organizations are really nimble footed and flexible, and I&#8217;m liking it.</p>
<p>In fact, I find myself recruiting already. In case you are interested, reach out to me at gmail.com. The id would be aloshbennett. A more detailed job description can be found <a href="http://www.aloshbennett.in/files/ilabs-jd.pdf">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aloshbennett.in/weblog/2011/java/moving-on/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Introduction to WebServices &#8211; IEEE Session</title>
		<link>http://www.aloshbennett.in/weblog/2011/sessions/introduction-to-webservices-ieee-session/</link>
		<comments>http://www.aloshbennett.in/weblog/2011/sessions/introduction-to-webservices-ieee-session/#comments</comments>
		<pubDate>Thu, 31 Mar 2011 14:26:05 +0000</pubDate>
		<dc:creator>aloshbennett</dc:creator>
				<category><![CDATA[Sessions]]></category>

		<guid isPermaLink="false">http://www.aloshbennett.in/weblog/?p=244</guid>
		<description><![CDATA[An introductory session on web services was conducted at BITS Plianl campus at Hyderabad in association with IEEE on 26th March 2011. The talks introduced the students to XML, WSDL and SOAP and REST styles of services. I have to say that I am impressed with the students who turned up at the event. Some [...]]]></description>
			<content:encoded><![CDATA[<p>An introductory session on web services was conducted at BITS Plianl campus at Hyderabad in association with IEEE on 26th March 2011. The talks introduced the students to XML, WSDL and SOAP and REST styles of services.</p>
<p>I have to say that I am impressed with the students who turned up at the event. Some of them are into very interesting projects and it feels great to see them do things over and above the curriculum.</p>
<p>With me were <a href="http://twitter.com/#!/bjgindia">Bhaskar Ghosh</a> and <a href="http://twitter.com/#!/neilghosh">Neil Ghosh</a> who actually delivered the talks and conducted the hands-on lab.</p>
<p>Overall, a very pleasant experience. Special thanks to Dr Geetha Deviprasad who made the event possible.</p>
<p>The event is covered in detail at <a href="http://neilghosh.com/2011/03/28/ieee-tutorial-on-webservices-at-bits-hyderabad/">Neil&#8217;s blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aloshbennett.in/weblog/2011/sessions/introduction-to-webservices-ieee-session/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HTML5 Canvas Sample &#8211; Building a maze</title>
		<link>http://www.aloshbennett.in/weblog/2011/web-2-0/html5-canvas-sample-building-a-maze/</link>
		<comments>http://www.aloshbennett.in/weblog/2011/web-2-0/html5-canvas-sample-building-a-maze/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 18:22:27 +0000</pubDate>
		<dc:creator>aloshbennett</dc:creator>
				<category><![CDATA[Web 2.0]]></category>

		<guid isPermaLink="false">http://www.aloshbennett.in/weblog/?p=220</guid>
		<description><![CDATA[There are a lot of features that HTML5 bring. What makes canvas popular? There! Canvas provides a screen area onto which you could draw 2D shapes and images. The set of APIs are simple. But the strength of the canvas comes from how you could manipulate it using javascript. We start by defining a canvas. [...]]]></description>
			<content:encoded><![CDATA[<p>There are a lot of features that HTML5 bring. What makes canvas popular?</p>
<p><iframe src="http://www.aloshbennett.in/apps/maze.html" width="370" height="390" frameborder="0"><br/></iframe><br />
There!</p>
<p>Canvas provides a screen area onto which you could draw 2D shapes and images. The set of APIs are simple. But the strength of the canvas comes from how you could manipulate it using javascript.</p>
<p>We start by defining a canvas. Note that the canvas element would be rendered only if your browser supports it.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;canvas <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;canvas&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100&quot;</span>&gt;</span>Your browser does not support canvas.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>canvas&gt;</span></pre></div></div>

<p>Next, we define an array in javascript to hold the maze data, initialize it and start building our maze by venturing out into the first cell.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">    <span style="color: #003366; font-weight: bold;">var</span> board <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> maze<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>            <span style="color: #006600; font-style: italic;">//initialize the maze</span>
        explorePath<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>           <span style="color: #006600; font-style: italic;">//start exploring</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> canvas <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;canvas&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>canvas.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            context <span style="color: #339933;">=</span> canvas.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;2d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #006600; font-style: italic;">//paint the maze black</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span> SIZE<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            board<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> j<span style="color: #339933;">&lt;</span>SIZE<span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                board<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//fill the board array with zeroes</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>For the explorePath method, we use a recursive algorithm</p>
<pre>
Paint the cell white
Initialize options list {UP, DOWN, FORWARD, BACKWARD}
While options:
    Select option randomly
    If valid option - Cell is unoccupied, we don't create tunnels etc.
         explorePath(option)
     remove explore option from list
end loop.
</pre>
<p>In short, we are doing a back-tracking traversal (DFS) of the option tree.</p>
<p>The algorithm works fine until we try to put a delay between each explorePath call to get that nice effect.<br />
You see, it is not really easy to sleep() in javascript. There is no equivalent of Java sleep.</p>
<p>What we could do is this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  setTimeOut<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'explorePath()'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This would call the explorePath after a delay of 100 milliseconds. But, the call to setTimeOut() is non-blocking and it would continue execution while scheduling explorePath() to be executed after 100 milliseconds.</p>
<p>We could maintain our own call stack and choose not to call the explorePath() recursively. But it is easier to just push the maze positions to be painted white into a stack and continue execution. Once the display stack is ready we could pop from it and render onto canvas in a delayed manner using setTimeOut().</p>
<p>Finally, we could add a nice touch to the maze by not changing its directions too often, but in a timely manner based on a seeded probability.</p>
<p>Here&#8217;s the <a href="http://www.aloshbennett.in/apps/maze.html">complete source</a> (right click and view source). And don&#8217;t forget to save your maze as a PNG (again, right click and save).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aloshbennett.in/weblog/2011/web-2-0/html5-canvas-sample-building-a-maze/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Implementation and Testing of Software Projects</title>
		<link>http://www.aloshbennett.in/weblog/2010/sessions/implementation-and-testing-of-software-projects/</link>
		<comments>http://www.aloshbennett.in/weblog/2010/sessions/implementation-and-testing-of-software-projects/#comments</comments>
		<pubDate>Sun, 19 Dec 2010 18:15:21 +0000</pubDate>
		<dc:creator>aloshbennett</dc:creator>
				<category><![CDATA[Sessions]]></category>

		<guid isPermaLink="false">http://www.aloshbennett.in/weblog/?p=196</guid>
		<description><![CDATA[Computer Society of India, Hyderabad Chapter had organized a Workshop on Project Development and I was lucky to give a talk on its implementation and testing aspects. Among the speakers was Mr Raju Kanchibhotla, Chairman of CSI, Hyderabad who gave an inspiring talk on taking IT to the masses. Here are the slides from the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://csihyderabad.org/">Computer Society of India, Hyderabad Chapter</a> had organized a Workshop on Project Development and I was lucky to give a talk on its implementation and testing aspects. Among the speakers was Mr Raju Kanchibhotla, Chairman of CSI, Hyderabad who gave an inspiring talk on taking IT to the masses.</p>
<p>Here are the slides from the talk.</p>
<p><a title="View Implementation and Testing of Software Projects on Scribd" href="http://www.scribd.com/doc/45647901/Implementation-and-Testing-of-Software-Projects" style="margin: 12px auto 6px auto; font-family: Helvetica,Arial,Sans-serif; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none; display: block; text-decoration: underline;">Implementation and Testing of Software Projects</a> <object id="doc_639043362848163" name="doc_639043362848163" height="600" width="100%" type="application/x-shockwave-flash" data="http://d1.scribdassets.com/ScribdViewer.swf" style="outline:none;" ><param name="movie" value="http://d1.scribdassets.com/ScribdViewer.swf"><param name="wmode" value="opaque"><param name="bgcolor" value="#ffffff"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><param name="FlashVars" value="document_id=45647901&#038;access_key=key-u1pny70vpqgolt6s3b0&#038;page=1&#038;viewMode=list"><embed id="doc_639043362848163" name="doc_639043362848163" src="http://d1.scribdassets.com/ScribdViewer.swf?document_id=45647901&#038;access_key=key-u1pny70vpqgolt6s3b0&#038;page=1&#038;viewMode=list" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" height="600" width="100%" wmode="opaque" bgcolor="#ffffff"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.aloshbennett.in/weblog/2010/sessions/implementation-and-testing-of-software-projects/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Functional programming the LISP way</title>
		<link>http://www.aloshbennett.in/weblog/2010/lisp/functional-programming-the-lisp-way/</link>
		<comments>http://www.aloshbennett.in/weblog/2010/lisp/functional-programming-the-lisp-way/#comments</comments>
		<pubDate>Sun, 12 Dec 2010 20:50:19 +0000</pubDate>
		<dc:creator>aloshbennett</dc:creator>
				<category><![CDATA[Lisp]]></category>

		<guid isPermaLink="false">http://www.aloshbennett.in/weblog/?p=169</guid>
		<description><![CDATA[Lately, there&#8217;s been a lot of talk about functional programming. The newer generation languages advertise themselves as multi-paradigm ( as opposed to java&#8217;s object oriented style). Java is doing catching up by bringing in Project Lambda in JDK 8, and Predicates has already started becoming popular (here&#8217;s a good starter by Arun Vydianathan). This post [...]]]></description>
			<content:encoded><![CDATA[<p>Lately, there&#8217;s been a lot of talk about <a href="http://en.wikipedia.org/wiki/Functional_programming">functional programming</a>. The newer generation languages advertise themselves as <a href="http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language">multi-paradigm</a> ( as opposed to java&#8217;s object oriented style). Java is doing catching up by bringing in Project Lambda in JDK 8, and Predicates has already started becoming popular (<a href="http://arunsark.wordpress.com/2010/12/10/guavagoogle-collections-unleash-the-power/">here&#8217;s</a> a good starter by <a href="http://arunsark.wordpress.com/">Arun Vydianathan</a>).</p>
<p>This post is an introduction to a very potent and heady LISP cocktail of Higher Order Functions, Lamdas and Macros.</p>
<blockquote><p><b>Summary:</b></p>
<p><b>Higher Order Functions</b>: Functions that take other function as its argument. A function that filters a list can be converted into higher order function by providing the actual filtering function as an argument.</p>
<p><b>Lambda Expression</b>: Dynamically creates functions and attaches a context to them. The filtering function can be created at runtime as a lambda and its bounds set at runtime.</p>
<p><b>Macro</b>: Creates code at runtime by substituting the macro with corresponding expression. While Lambdas let you replace the bound conditions, macros let you decide the structure of your filter function.
</p></blockquote>
<p><b>Higher Order Functions</b><br />
You could print all students belonging to &#8220;ELX&#8221; department from a list like this:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> print-students <span style="color: #66cc66;">&#40;</span>students-lst<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>loop for student in students-lst
       <span style="color: #b1b100;">do</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">equal</span> <span style="color: #ff0000;">&quot;ELX&quot;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">getf</span> student <span style="color: #66cc66;">:</span><span style="color: #555;">department</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	       <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">print</span> student<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Now if you want to print the students who had received &#8216;A&#8217; grade, you are at a loss. You cannot do that without writing a new function by duplicating the looping logic.</p>
<p>Enter Higher Order Functions. Higher Order Functions are functions which take another function as its argument. The example above can be modified into a generic higher order function if we could abstract the evaluation logic into another function.</p>
<p>Consider the following re-write</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> print-students <span style="color: #66cc66;">&#40;</span>students-lst<span style="color: #66cc66;">,</span> eval-student<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>loop for student in students-lst
       <span style="color: #b1b100;">do</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">funcall</span> eval-student student<span style="color: #66cc66;">&#41;</span>
	       <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">print</span> student<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> eval-elx-department <span style="color: #66cc66;">&#40;</span>student<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">equal</span> <span style="color: #ff0000;">&quot;ELX&quot;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">getf</span> student <span style="color: #66cc66;">:</span><span style="color: #555;">department</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> t<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> eval-a-grade <span style="color: #66cc66;">&#40;</span>student<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">equal</span> <span style="color: #ff0000;">&quot;A&quot;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">getf</span> student <span style="color: #66cc66;">:</span><span style="color: #555;">grade</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> t<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>print-students *students-lst* #'eval-a-grade<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Note: LISP built-in functions REMOVE-IF and REMOVE-IF-NOT takes a list and a evaluation function, applies the evaluation function to every element in the list and returns a new list which contains/doesn&#8217;t contain the element. The idea of predicates is very similar to this.</p>
<p><b>Lambda Expressions</b><br />
If we could parameterize the grade from the eval-a-grade function, we would have a generic eval-grade and that would have been just great!<br />
Unfortunately, the print-students function expects an evaluation function that takes in a single argument: student.<br />
Using Lambda expressions, it is possible to custom make a function with a context. Lambda expressions are used to create anonymous functions with a scope attached to them. The variables used within the lambda expressions are evaluated in the context they are run in.</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> eval-grade <span style="color: #66cc66;">&#40;</span>grade<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>student<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">equal</span> grade <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">getf</span> student <span style="color: #66cc66;">:</span><span style="color: #555;">grade</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> t<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>print-students *students-lst* <span style="color: #66cc66;">&#40;</span>eval-grade <span style="color: #ff0000;">&quot;A&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>print-students *students-lst* <span style="color: #66cc66;">&#40;</span>eval-grade <span style="color: #ff0000;">&quot;B&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p><b>Macros</b><br />
LISP macro is a very powerful beast that can be used to generate code dynamically. Instead of having multiple evaluation functions, it is possible to write a LISP macro to dynamically generate a lisp function based on the inputs you pass to it.</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defmacro</span> eval-student <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&amp;</span>key dept grade<span style="color: #66cc66;">&#41;</span>
  `<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span><span style="color: #66cc66;">&#40;</span>student<span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">and</span> <span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> dept
		 `<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">equal</span> <span style="color: #66cc66;">,</span>dept <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">getf</span> student <span style="color: #66cc66;">:</span><span style="color: #555;">department</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	    <span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> grade
		 `<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">equal</span> <span style="color: #66cc66;">,</span>grade <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">getf</span> student <span style="color: #66cc66;">:</span><span style="color: #555;">age</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>print-students *students-lst* <span style="color: #66cc66;">&#40;</span>eval-student <span style="color: #66cc66;">:</span><span style="color: #555;">dept</span> <span style="color: #ff0000;">&quot;ELX&quot;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">grade</span> <span style="color: #ff0000;">&quot;A&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>The eval-student macro expands to</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #b1b100;">LAMBDA</span> <span style="color: #66cc66;">&#40;</span>STUDENT<span style="color: #66cc66;">&#41;</span> 
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">AND</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">EQUAL</span> <span style="color: #ff0000;">&quot;ELX&quot;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">GETF</span> PERSON <span style="color: #66cc66;">:</span><span style="color: #555;">DEPT</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">EQUAL</span> <span style="color: #ff0000;">&quot;A&quot;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">GETF</span> PERSON <span style="color: #66cc66;">:</span><span style="color: #555;">GRADE</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Note: Though very powerful, it is easy to cut yourself using macros. Use discretion when using them.</p>
<p>Functional programming is a great way to modularize and reduce the size of your code. More than that, it is fun! Happy coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aloshbennett.in/weblog/2010/lisp/functional-programming-the-lisp-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shortly &#8211; URL shortner for Firefox</title>
		<link>http://www.aloshbennett.in/weblog/2010/foss/shortly-url-shortner-for-firefox/</link>
		<comments>http://www.aloshbennett.in/weblog/2010/foss/shortly-url-shortner-for-firefox/#comments</comments>
		<pubDate>Thu, 25 Nov 2010 18:20:35 +0000</pubDate>
		<dc:creator>aloshbennett</dc:creator>
				<category><![CDATA[foss]]></category>
		<category><![CDATA[firefox extension "url shortner"]]></category>

		<guid isPermaLink="false">http://www.aloshbennett.in/weblog/?p=162</guid>
		<description><![CDATA[Introducing Shortly, an extension for firefox to create short URLs using bit.ly service. Take it out for a spin and let me know what changes and features you&#8217;d like to see.]]></description>
			<content:encoded><![CDATA[<p>Introducing <a href="http://www.aloshbennett.in/foss/#shortly">Shortly</a>, an extension for firefox to create short URLs using <a href="http://bit.ly/">bit.ly</a> service.</p>
<p>Take it out for a spin and let me know what changes and features you&#8217;d like to see.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aloshbennett.in/weblog/2010/foss/shortly-url-shortner-for-firefox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reflection and the missing Security Manager</title>
		<link>http://www.aloshbennett.in/weblog/2010/java/reflection-and-the-missing-security-manager/</link>
		<comments>http://www.aloshbennett.in/weblog/2010/java/reflection-and-the-missing-security-manager/#comments</comments>
		<pubDate>Tue, 16 Nov 2010 19:09:48 +0000</pubDate>
		<dc:creator>aloshbennett</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.aloshbennett.in/weblog/?p=160</guid>
		<description><![CDATA[Here&#8217;s an interesting trick that&#8217;s been around for a long time: Consider the Person class here, with password as a private data member. public class Person &#123; &#160; private String name; private String password; &#160; public String getName&#40;&#41; &#123; return name; &#125; &#160; public boolean login&#40;String password&#41; &#123; if&#40;this.password&#40;equals&#40;password&#41;&#41; &#123; .... &#125; &#125; ... &#125; [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an interesting trick that&#8217;s been around for a long time:</p>
<p>Consider the Person class here, with password as a private data member.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Person <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> name<span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> password<span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000000; font-weight: bold;">return</span> name<span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> login<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> password<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">password</span><span style="color: #009900;">&#40;</span>equals<span style="color: #009900;">&#40;</span>password<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         ....
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
   ...
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The Java scope rules does not allow me to access or modify the password field that&#8217;s declared private. All the same, I could do it using reflection as shown below:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">   Person person <span style="color: #339933;">=</span> db.<span style="color: #006633;">queryPerson</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;alosh&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #666666; font-style: italic;">//System.out.println(&quot;password: &quot;+person.password); -- won't compile</span>
&nbsp;
   <span style="color: #003399;">Field</span> field <span style="color: #339933;">=</span> person.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   field.<span style="color: #006633;">setAccessible</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;password: &quot;</span><span style="color: #339933;">+</span>field.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>person<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   field.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span>person, <span style="color: #0000ff;">&quot;welcome&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   person.<span style="color: #006633;">login</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;welcome&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   ...</pre></div></div>

<p>It all boils down to this line of code.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">   field.<span style="color: #006633;">setAccessible</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>All reflection access to an object (methods, fields, constructors) is through the interface <i>AccessibleObject</i> which lets the reflected object suppress the normal access controls. By setting the access flag, the reflected object is now open.<br />
But the access flags are not flipped before it checks with the security manager. Reflection and SecurityManager together provides the power to control access dynamically.</p>
<p>Our little trick could then be attributed to the SecurityManager. Or like in this case, the lack of a SecurityManager.</p>
<p>By default the JVM does not have a SecurityManager available. A security manager could be installed either by passing the following option to the jvm</p>
<pre>-Djava.security.manager</pre>
<p>or by setting one in the code</p>
<pre>System.setSecurityManager(new SecurityManager());</pre>
<p>(Now the snippet mentioned in the beginning will not work.)</p>
<p>* SecurityManager is not enabled by default in the JVM.<br />
* Majority of the JEE servers out there don&#8217;t run a SecurityManager unless asked for.<br />
* Many applications would not run with SecurityManager in place.</p>
<p>Isn&#8217;t it against Java&#8217;s principle of &#8216;Secure by Default&#8217;?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aloshbennett.in/weblog/2010/java/reflection-and-the-missing-security-manager/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unity to replace GNOME in Ubuntu 11.04</title>
		<link>http://www.aloshbennett.in/weblog/2010/linux/unity-to-replace-gnome/</link>
		<comments>http://www.aloshbennett.in/weblog/2010/linux/unity-to-replace-gnome/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 13:28:28 +0000</pubDate>
		<dc:creator>aloshbennett</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.aloshbennett.in/weblog/?p=153</guid>
		<description><![CDATA[Starting with Ubuntu 11.04 (codenamed Natty Narwhal), Unity would be the default shell of choice for the desktop edition. Though Unity (already available on the netbook editions) is far from ready, there are a couple of cool features it brings to the table. The immediate changes are aimed at reducing the wastage of screen space. [...]]]></description>
			<content:encoded><![CDATA[<p>Starting with Ubuntu 11.04 (codenamed Natty Narwhal), <a href="http://arstechnica.com/open-source/news/2010/10/shuttleworth-unity-shell-will-be-default-desktop-in-ubuntu-1104.ars">Unity would be the default shell of choice</a> for the desktop edition.</p>
<p>Though Unity (already available on the netbook editions) is far from ready, there are a couple of cool features it brings to the table.</p>
<p>The immediate changes are aimed at reducing the wastage of screen space. The application menu (in the maximized mode) gets integrated into the top panel. So does the status bar &#8211; this would be replaced by an indicator on the top panel. This is a huge relief for people like me who runs firefox with extensions that hide menubars, trying to salvage every bit of screen space.</p>
<p>There is also the promise of a Mac styled dock and application switcher.</p>
<p>The Unity project plans to include <a href="http://gnomejournal.org/article/70/an-introduction-to-gnome-zeitgeist">zeitgeist</a>,  a sophisticated data engine that understands user activities and correlates them. This can provide useful context to search and browsing applications.</p>
<p>There are also plans to evolve from directory based file storage to something that&#8217;s more intuitive and search oriented (yey!! first step towards <a href="http://www.aloshbennett.in/weblog/2010/linux/tag-based-filesystem-part-1/">tag based systems</a>).</p>
<p>GNOME 3 is coming next April, and there is a worry that throwing in a new desktop shell would divide the development community. Nevertheless I like Ubuntu&#8217;s aggressiveness when it comes to redefining the image of Linux.</p>
<p>In the good spirit of choice, GNOME and KDE would be very much available as login options.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aloshbennett.in/weblog/2010/linux/unity-to-replace-gnome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cross Site Scripting through image EXIF</title>
		<link>http://www.aloshbennett.in/weblog/2010/web-2-0/cross-site-scripting-through-image-exif/</link>
		<comments>http://www.aloshbennett.in/weblog/2010/web-2-0/cross-site-scripting-through-image-exif/#comments</comments>
		<pubDate>Mon, 18 Oct 2010 09:35:54 +0000</pubDate>
		<dc:creator>aloshbennett</dc:creator>
				<category><![CDATA[Web 2.0]]></category>

		<guid isPermaLink="false">http://www.aloshbennett.in/weblog/?p=138</guid>
		<description><![CDATA[Cross Site Scripting (XSS) seems to be the most common vulnerability today with every other site having run into it at least once. In a nutshell, whenever a website displays unsanitized user-driven data (supplied directly or indirectly), it makes itself susceptible to XSS. Image EXIF information is no exception. Though the EXIF is usually written [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Cross-site_scripting">Cross Site Scripting (XSS)</a> seems to be the most common vulnerability today with every other site having run into it at least once. In a nutshell, whenever a website displays unsanitized user-driven data (supplied directly or indirectly), it makes itself susceptible to XSS.</p>
<p>Image <a href="http://en.wikipedia.org/wiki/EXIF">EXIF</a> information is no exception. Though the EXIF is usually written by the digital camera, it could be edited using any of the tools available freely. It is possible to modify any tag including the Camera Make and Model and supply javascript snippets instead of them.</p>
<p>Here&#8217;s a <a href="http://img259.imageshack.us/img259/163/scriptw.jpg">sample image</a> with javascript alerts written into its EXIF. (Upload the pic to <a href="http://www.jpginfo.com/">jpeginfo.com</a> to see the javascript at work. The site doesn&#8217;t persist the image and hence is safe.) Most of the big names in photosharing already sanitizes the EXIF tags before displaying them, but there are a lot of smaller websites which are prone to this kind of XSS.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aloshbennett.in/weblog/2010/web-2-0/cross-site-scripting-through-image-exif/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

