<?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>Anand Nalya &#187; Codeprix</title>
	<atom:link href="http://anandnalya.com/category/codeprix/feed/" rel="self" type="application/rss+xml" />
	<link>http://anandnalya.com</link>
	<description>blog</description>
	<lastBuildDate>Mon, 23 Aug 2010 11:48:16 +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>My first Scheme program</title>
		<link>http://anandnalya.com/2010/08/23/my-first-scheme-program/</link>
		<comments>http://anandnalya.com/2010/08/23/my-first-scheme-program/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 11:45:58 +0000</pubDate>
		<dc:creator>anand</dc:creator>
				<category><![CDATA[Codeprix]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[sicp]]></category>

		<guid isPermaLink="false">http://anandnalya.com/?p=116</guid>
		<description><![CDATA[I&#8217;ve just started experimenting with Scheme, specifically to follow Structure and Interpretation of Computer Programs. Here is a Scheme procedure that returns the sum of squares of two larger numbers out of the given three. 1 2 3 4 5 &#40;define &#40;sumLargeSquare a b c&#41; &#40;cond &#40;&#40;and &#40;&#60; a b&#41; &#40;&#60; a c&#41;&#41; &#40;+ &#40;* [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just started experimenting with Scheme, specifically to follow <a href="http://mitpress.mit.edu/sicp/full-text/book/book.html">Structure and Interpretation of Computer Programs</a>. Here is a Scheme procedure that returns the sum of squares of two larger numbers out of the given three.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>sumLargeSquare a b c<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">and</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;</span> a b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;</span> a c<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span> b b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span> c c<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">and</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;</span> b a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;</span> b c<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span> a a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span> c c<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span> a a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span> b b<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></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://anandnalya.com/2010/08/23/my-first-scheme-program/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8216;protected&#8217; implementation in Actionscript 3 is BROKEN</title>
		<link>http://anandnalya.com/2010/06/25/protected-implementation-in-actionscript-in-broken/</link>
		<comments>http://anandnalya.com/2010/06/25/protected-implementation-in-actionscript-in-broken/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 14:39:07 +0000</pubDate>
		<dc:creator>anand</dc:creator>
				<category><![CDATA[Codeprix]]></category>
		<category><![CDATA[actionscript]]></category>

		<guid isPermaLink="false">http://anandnalya.com/?p=111</guid>
		<description><![CDATA[Consider following code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 public class BaseClass&#123; public function modifyProperty&#40;property:String, value:Object&#41;:void&#123; this&#91;property&#93; = value; &#125; &#125; &#160; public class SubClass extends SubClass&#123; protected var count:int; &#125; &#160; public function test&#40;&#41;:void&#123; var testObj:BaseClass = new SubClass&#40;&#41;; testObj.modifyProperty&#40;'count', 3&#41;; &#125; Theoretically, the call at [...]]]></description>
			<content:encoded><![CDATA[<p>Consider following code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BaseClass<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> modifyProperty<span style="color: #66cc66;">&#40;</span>property:<span style="color: #0066CC;">String</span>, value:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#91;</span>property<span style="color: #66cc66;">&#93;</span> = value;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SubClass <span style="color: #0066CC;">extends</span> SubClass<span style="color: #66cc66;">&#123;</span>
	protected <span style="color: #000000; font-weight: bold;">var</span> count:<span style="color: #0066CC;">int</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> test<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> testObj:BaseClass = <span style="color: #000000; font-weight: bold;">new</span> SubClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	testObj.<span style="color: #006600;">modifyProperty</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'count'</span>, <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Theoretically, the call at line no. 13 should not cause any error as <code>count</code> is defined for </code>testObj</code> as a field in <code>SubClass</code>, but it gives a <code>Cannot create property count on SubClass</code>. Interestingly if we move <code>modifyProperty</code> method to <code>SubClass</code> or make <code>count</code> public, it works without any error.</p>
<p>So it can be said that we cannot access protected fields dynamically in a subclass.</p>
]]></content:encoded>
			<wfw:commentRss>http://anandnalya.com/2010/06/25/protected-implementation-in-actionscript-in-broken/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How Facebook (probably) implements SMS threads</title>
		<link>http://anandnalya.com/2009/11/16/how-facebook-probably-implements-sms-threads/</link>
		<comments>http://anandnalya.com/2009/11/16/how-facebook-probably-implements-sms-threads/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 16:14:05 +0000</pubDate>
		<dc:creator>anand</dc:creator>
				<category><![CDATA[Codeprix]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[sms]]></category>
		<category><![CDATA[text messages]]></category>
		<category><![CDATA[threads]]></category>

		<guid isPermaLink="false">http://anandnalya.com/2009/11/16/how-facebook-probably-implements-sms-threads/</guid>
		<description><![CDATA[A lot of web applications provides you the ability to receive or post updates using SMS (text messages). Twitter is the posterboy of such applications. But the feature that distinguishes Facebook SMS updates from any other service is that you can actually reply to individual messages and your message then becomes a part of the [...]]]></description>
			<content:encoded><![CDATA[<p>A lot of web applications provides you the ability to receive or post updates using SMS (text messages). Twitter is the posterboy of such applications. </p>
<p>But the feature that distinguishes Facebook SMS updates from any other service is that you can actually reply to individual messages and your message then becomes a part of the aforementioned thread. You don’t have to specify any special command to do so. Just hit the <em>reply&#160; </em>button and you are done. </p>
<p>How do they know which message belongs to which thread? Its simple, each message comes from a different number. For example, say A writes something on your wall, then you will receive a message from +91922305501. Also B sends a message to you, a message comes from +91922305502 and when C comments on your note, you get a message from +91922305503. How many numbers do facebook own? Probably 100 in India, from +91922305500 to +9192230599.&#160; A per user mapping of the number from which the message is sent and the object/thread id for that message is kept on the backend. So when the user replies to a particular number, say +91922305502 , it knows that is was a reply to the message sent by B and hence treats as a reply to that message. A rotation policy is used to decide from which number the message is to be sent. So after recieving a message from +9192230599, the next message will be from +91922305500&#160; and now you cannot reply to the thread represented by the earlier message from the same number.</p>
<p><em>Discalimer:</em> This is just a guess of how this functionality might have been implemented (or at least how I would implement it) and based strictly on SMSes received in India. Actual implementation might (probaly is) be entierly different from what is explained here.</p>
]]></content:encoded>
			<wfw:commentRss>http://anandnalya.com/2009/11/16/how-facebook-probably-implements-sms-threads/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bing/Google toggle bookmarklet</title>
		<link>http://anandnalya.com/2009/10/06/binggoogle-toggle-bookmarklet/</link>
		<comments>http://anandnalya.com/2009/10/06/binggoogle-toggle-bookmarklet/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 11:49:00 +0000</pubDate>
		<dc:creator>anand</dc:creator>
				<category><![CDATA[Codeprix]]></category>
		<category><![CDATA[bing]]></category>
		<category><![CDATA[bookmarklet]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[ie8]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://anandnalya.com/?p=100</guid>
		<description><![CDATA[I’ve been trying out Bing as my default search engine for last few months and the results are definitely at par with that of Google for most of the consumer categories. But sometimes you just need a quick toggle to see what Google would return for your query. So here is a small bookmarklet that [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been trying out <a href="http://bing.com/">Bing</a> as my default search engine for last few months and the results are definitely at par with that of Google for most of the consumer categories. But sometimes you just need a quick toggle to see what <a href="http://google.com/">Google</a> would return for your query. So here is a small bookmarklet that I wrote that toggles from Bing to Google and vice versa.</p>
<p>Drag this to you favourites bar: <a href="javascript:if(window.location.hostname.match(/\.bing\./))window.location.hostname='www.google.com';else if(window.location.hostname.match(/\.google\./))window.location.hostname='www.bing.com';">Bing/Google Toogle</a></p>
<p>Note: Its tested on IE8 only. A few tweaks might be required for Firefox.</p>
]]></content:encoded>
			<wfw:commentRss>http://anandnalya.com/2009/10/06/binggoogle-toggle-bookmarklet/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Minifying Javascript/css without changing file references in your source</title>
		<link>http://anandnalya.com/2009/06/05/minifying-javascriptcss-without-changing-file-references-in-your-source/</link>
		<comments>http://anandnalya.com/2009/06/05/minifying-javascriptcss-without-changing-file-references-in-your-source/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 13:21:02 +0000</pubDate>
		<dc:creator>anand</dc:creator>
				<category><![CDATA[Codeprix]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[compressor]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://anandnalya.com/?p=79</guid>
		<description><![CDATA[Rule 10 of Steve Souders High Performance Web Sites: Minify Javascript The most common problem faced while implemnting this is how you handle the full and minified version and how to change there reference in referencing documents. One of the easier ways to do this is to make it part of the deployment process. Here [...]]]></description>
			<content:encoded><![CDATA[<p>Rule 10 of Steve Souders High Performance Web Sites: <a href="http://developer.yahoo.net/blog/archives/2007/07/high_performanc_8.html">Minify Javascript</a></p>
<p>The most common problem faced while implemnting this is how you handle the full and minified version and how to change there reference in referencing documents. One of the easier ways to do this is to make it part of the deployment process. </p>
<p>Here are the relevent steps involved.</p>
<p>I&#8217;m using <a href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Execute this script after checking out the latest source from repository.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Minify all javascript files</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>javascript
<span style="color: #000000; font-weight: bold;">for</span> x <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">*</span>.js<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">do</span>
        java <span style="color: #660033;">-jar</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>compressor<span style="color: #000000; font-weight: bold;">/</span>yuicompressor-2.4.2.jar <span style="color: #660033;">-o</span> <span style="color: #800000;">${x%%.*}</span>-min.js <span style="color: #660033;">--preserve-semi</span>  <span style="color: #007800;">$x</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Minfiy all css files</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>css
<span style="color: #000000; font-weight: bold;">for</span> x <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">*</span>.css<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">do</span>
        java <span style="color: #660033;">-jar</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>compressor<span style="color: #000000; font-weight: bold;">/</span>yuicompressor-2.4.2.jar <span style="color: #660033;">-o</span> <span style="color: #800000;">${x%%.*}</span>-min.css  <span style="color: #007800;">$x</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

<p>Now you don&#8217;t want to replace all references to <em>x.css</em> or <em>x.js</em> in your development code with references to <em>x-min.css</em> and <em>x-min.js</em> respectively. So what you can do is rewrite all those filenames at the web server level.</p>
<p>For apache the following rewrite rules work fine:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">#enable rewriting</span>
<span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">on</span>
<span style="color: #00007f;">RewriteRule</span> /(.*)\.js /$<span style="color: #ff0000;">1</span>-min.js
<span style="color: #00007f;">RewriteRule</span> /(.*)\.css /$<span style="color: #ff0000;">1</span>-min.css</pre></td></tr></table></div>

<p><em>Caution:</em> Remember to delete existing minified css/js file before running the minifying script or you will end up with file names like x-min-min-min.js and so on. One way to do this is to clear the js/css folder before checking out files from your source repository.</p>
]]></content:encoded>
			<wfw:commentRss>http://anandnalya.com/2009/06/05/minifying-javascriptcss-without-changing-file-references-in-your-source/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Humanizing the time difference ( in django )</title>
		<link>http://anandnalya.com/2009/05/20/humanizing-the-time-difference-in-django/</link>
		<comments>http://anandnalya.com/2009/05/20/humanizing-the-time-difference-in-django/#comments</comments>
		<pubDate>Wed, 20 May 2009 10:02:35 +0000</pubDate>
		<dc:creator>anand</dc:creator>
				<category><![CDATA[Codeprix]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[filters]]></category>
		<category><![CDATA[humanize]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://anandnalya.com/?p=70</guid>
		<description><![CDATA[django.contrib.humanize is a set of Django template filters that adds human touch to data. It provides naturalday filter that formats date to &#8216;yesterday&#8217;, &#8216;today&#8217; or &#8216;tomorrow&#8217; when applicable. A similar requirement which the humanize pacakge does not address is to display time difference with this human touch. so here is a snippet that does so. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://docs.djangoproject.com/en/dev/ref/contrib/humanize/#module-django.contrib.humanize">django.contrib.humanize</a> is a set of Django template filters that adds human touch to data. It provides <a href="http://docs.djangoproject.com/en/dev/ref/contrib/humanize/#naturalday">naturalday</a> filter that formats date to &#8216;yesterday&#8217;, &#8216;today&#8217; or &#8216;tomorrow&#8217; when applicable.</p>
<p>A similar requirement which the humanize pacakge does not address is to display time difference with this human touch. so here is a snippet that does so.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django <span style="color: #ff7700;font-weight:bold;">import</span> template
&nbsp;
register = template.<span style="color: black;">Library</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
MOMENT = <span style="color: #ff4500;">120</span>    <span style="color: #808080; font-style: italic;"># duration in seconds within which the time difference </span>
                <span style="color: #808080; font-style: italic;"># will be rendered as 'a moment ago'</span>
&nbsp;
@register.<span style="color: #008000;">filter</span>
<span style="color: #ff7700;font-weight:bold;">def</span> naturalTimeDifference<span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    Finds the difference between the datetime value given and now()
    and returns appropriate humanize form
    &quot;&quot;&quot;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">datetime</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">datetime</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">isinstance</span><span style="color: black;">&#40;</span>value, <span style="color: #dc143c;">datetime</span><span style="color: black;">&#41;</span>:
        delta = <span style="color: #dc143c;">datetime</span>.<span style="color: black;">now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> - value
        <span style="color: #ff7700;font-weight:bold;">if</span> delta.<span style="color: black;">days</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">6</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> value.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%b %d&quot;</span><span style="color: black;">&#41;</span>                    <span style="color: #808080; font-style: italic;"># May 15</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> delta.<span style="color: black;">days</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">1</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> value.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%A&quot;</span><span style="color: black;">&#41;</span>                       <span style="color: #808080; font-style: italic;"># Wednesday</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> delta.<span style="color: black;">days</span> == <span style="color: #ff4500;">1</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">'yesterday'</span>                                <span style="color: #808080; font-style: italic;"># yesterday</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> delta.<span style="color: black;">seconds</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">3600</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>delta.<span style="color: black;">seconds</span> / <span style="color: #ff4500;">3600</span> <span style="color: black;">&#41;</span> + <span style="color: #483d8b;">' hours ago'</span>  <span style="color: #808080; font-style: italic;"># 3 hours ago</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> delta.<span style="color: black;">seconds</span> <span style="color: #66cc66;">&gt;</span>  MOMENT:
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>delta.<span style="color: black;">seconds</span>/<span style="color: #ff4500;">60</span><span style="color: black;">&#41;</span> + <span style="color: #483d8b;">' minutes ago'</span>     <span style="color: #808080; font-style: italic;"># 29 minutes ago</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">'a moment ago'</span>                             <span style="color: #808080; font-style: italic;"># a moment ago</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> defaultfilters.<span style="color: black;">date</span><span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://anandnalya.com/2009/05/20/humanizing-the-time-difference-in-django/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Running Glassfish as a service on CentOS</title>
		<link>http://anandnalya.com/2009/04/07/running-glassfish-as-a-service-on-centos/</link>
		<comments>http://anandnalya.com/2009/04/07/running-glassfish-as-a-service-on-centos/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 06:49:33 +0000</pubDate>
		<dc:creator>anand</dc:creator>
				<category><![CDATA[Codeprix]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://anandnalya.com/?p=56</guid>
		<description><![CDATA[Here is how you run glassfish as a service on CentOS: Create a user glassfish (you can call it anything you want) under which Glassfish will run. #useradd glassfish Install glassfish in /home/glassfish. Create the startup script /etc/init.d/glassifsh for glassfish. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 [...]]]></description>
			<content:encoded><![CDATA[<p>Here is how you run glassfish as a service on CentOS:</p>
<ol>
<li> Create a user <em>glassfish (</em>you can call it anything you want) under which Glassfish will run.

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#useradd glassfish</span></pre></div></div>

</li>
<li> <a href="https://glassfish.dev.java.net/downloads/v2.1-b60e.html">Install glassfish</a> in /home/glassfish.</li>
<li>Create the startup script <em>/etc/init.d/glassifsh</em> for glassfish.

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># glassfish:          Startup script for Glassfish Application Server.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># chkconfig: 3 80 05</span>
<span style="color: #666666; font-style: italic;"># description:      Startup script for domain1 of Glassfish Application Server.</span>
&nbsp;
<span style="color: #007800;">GLASSFISH_HOME</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>glassfish<span style="color: #000000; font-weight: bold;">/</span>glassfish;
<span style="color: #7a0874; font-weight: bold;">export</span> GLASSFISH_HOME
&nbsp;
<span style="color: #007800;">GLASSFISH_OWNER</span>=glassfish;
<span style="color: #7a0874; font-weight: bold;">export</span> GLASSFISH_OWNER
&nbsp;
start<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Starting Glassfish: &quot;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Starting Glassfish at <span style="color: #780078;">`date`</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$GLASSFISH_HOME</span><span style="color: #000000; font-weight: bold;">/</span>domains<span style="color: #000000; font-weight: bold;">/</span>domain1<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>startup.log
        <span style="color: #c20cb9; font-weight: bold;">su</span> <span style="color: #007800;">$GLASSFISH_OWNER</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$GLASSFISH_HOME</span>/bin/asadmin start-domain domain1&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$GLASSFISH_HOME</span><span style="color: #000000; font-weight: bold;">/</span>domains<span style="color: #000000; font-weight: bold;">/</span>domain1<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>startup.log
        <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">2</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
stop<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Stopping Glassfish: &quot;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Stopping Glassfish at <span style="color: #780078;">`date`</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$GLASSFISH_HOME</span><span style="color: #000000; font-weight: bold;">/</span>domains<span style="color: #000000; font-weight: bold;">/</span>domain1<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>startup.log
        <span style="color: #c20cb9; font-weight: bold;">su</span> <span style="color: #007800;">$GLASSFISH_OWNER</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$GLASSFISH_HOME</span>/bin/asadmin stop-domain domain1&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$GLASSFISH_HOME</span><span style="color: #000000; font-weight: bold;">/</span>domains<span style="color: #000000; font-weight: bold;">/</span>domain1<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>startup.log
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># See how we were called.</span>
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
        start<span style="color: #7a0874; font-weight: bold;">&#41;</span>
                start
                <span style="color: #000000; font-weight: bold;">;;</span>
        stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
                stop
                <span style="color: #000000; font-weight: bold;">;;</span>
        restart<span style="color: #7a0874; font-weight: bold;">&#41;</span>
                stop
                start
                <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #ff0000;">&quot;Usage: glassfish {start|stop|restart}&quot;</span>
                <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">esac</span></pre></td></tr></table></div>

</li>
<li>Install the service

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#chmod +x /etc/init.d/glassfish</span>
<span style="color: #666666; font-style: italic;">#chkconfig --add glassfish</span>
<span style="color: #666666; font-style: italic;">#chkconfig --level 3 glassfish on</span></pre></div></div>

</li>
<li>Start glassfish.

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#/etc/init.d/glassfish start</span></pre></div></div>

</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://anandnalya.com/2009/04/07/running-glassfish-as-a-service-on-centos/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Embedding flash object in Facebook Apps (FBML)</title>
		<link>http://anandnalya.com/2009/01/15/embedding-flash-object-in-facebook-apps-fbml/</link>
		<comments>http://anandnalya.com/2009/01/15/embedding-flash-object-in-facebook-apps-fbml/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 03:12:26 +0000</pubDate>
		<dc:creator>anand</dc:creator>
				<category><![CDATA[Codeprix]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[fbml]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[iframe]]></category>

		<guid isPermaLink="false">http://anandnalya.com/?p=30</guid>
		<description><![CDATA[Yesterday I was trying to include a flash object in a facebook app using FBML fb:swf tag. The flash object needed to change the url of the page it was running on on a particular event. But since facebook prevents direct script access from flash, this could not be done. Here is a simple workaround: [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I was trying to include a flash object in a facebook app using <a href="http://wiki.developers.facebook.com/index.php/FBML">FBML</a> <a href="http://wiki.developers.facebook.com/index.php/Fb:swf">fb:swf</a> tag. The flash object needed to change the url of the page it was running on on a particular event. But since facebook prevents direct script access from flash, this could not be done.</p>
<p>Here is a simple workaround:</p>
<p>1. Create a simple html page containing only the flash object that you want to include.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
   <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/html; charset=utf-8&quot;</span>&gt;</span>
   <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
   <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
   	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">object</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;application/x-shockwave-flash&quot;</span> <span style="color: #000066;">data</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;foo.swf&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;300&quot;</span>&gt;</span>
   		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">param</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;movie&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;foo.swf&quot;</span>&gt;</span>
         	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">param</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;quality&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;high&quot;</span>&gt;</span>
         	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">param</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;scale&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;noscale&quot;</span>&gt;</span>
         	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">param</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;salign&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;LT&quot;</span>&gt;</span>
         	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">param</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;menu&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;false&quot;</span>&gt;</span>
    	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">object</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>2. Embed this html on the facebook page using the <a href="http://wiki.developers.facebook.com/index.php/Fb:iframe">fb:iframe</a> tag.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;fb:iframe <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://anandnalya.com/foo.html&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #000066;">frameborder</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">scrolling</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;no&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>fb:iframe&gt;</span></pre></div></div>

<p>Now you can make all the Actionscript calls you want to. Only caveat to this approach is that you will no longer be able to make Facebook API calls directly from flash.</p>
]]></content:encoded>
			<wfw:commentRss>http://anandnalya.com/2009/01/15/embedding-flash-object-in-facebook-apps-fbml/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 2.693 seconds -->
