<?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>Naveen&#039;s Journal &#187; Hacks</title>
	<atom:link href="http://journal.naveeng.com/category/hacks/feed/" rel="self" type="application/rss+xml" />
	<link>http://journal.naveeng.com</link>
	<description>Peace.</description>
	<lastBuildDate>Thu, 25 Mar 2010 08:59:09 +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>Perl one-liner to sort a hash and return the top most key/value</title>
		<link>http://journal.naveeng.com/2007/10/17/perl-one-liner-to-sort-and-hash-and-return-the-top-most-keyvalue/</link>
		<comments>http://journal.naveeng.com/2007/10/17/perl-one-liner-to-sort-and-hash-and-return-the-top-most-keyvalue/#comments</comments>
		<pubDate>Wed, 17 Oct 2007 10:14:01 +0000</pubDate>
		<dc:creator>Naveen</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://journal.naveeng.com/2007/10/17/perl-one-liner-to-sort-and-hash-and-return-the-top-most-keyvalue/</guid>
		<description><![CDATA[A while ago Deepz asked me whether we can sort a hash and print the top most key or value or both in a single line, in PERL. After a little permutation &#38; combination, I wrote the following piece. I&#8217;m sure there must be a more elegant and efficient way of doing it, but this [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago <a href="http://blog.pradeep.net.in" target="_blank">Deepz </a>asked me whether we can sort a hash and print the top most key or value or both in a single line, in <a href="http://en.wikipedia.org/wiki/Perl" target="_blank">PERL</a>. After a little permutation &amp; combination, I wrote the following piece. I&#8217;m sure there must be a more elegant and efficient way of doing it, but this will also serve the purpose on most occasions and with a little tweaking can be applied to almost all hashes.</p>
<ul>
<li>The code needs to be  modified if the hash keys contain any digits</li>
<li>The sort algorithm can be changed as per the requirement, by default I&#8217;m sorting by hash values which are digits</li>
</ul>
<p><font face="courier new">print grep {s/\d//g} grep {/1/}  map { $i+=1 , $_.=$i ,  &#8220;\n&#8221;} sort {$hash{$a} &lt;=&gt; $hash{$b}} keys %hash;</font></p>
]]></content:encoded>
			<wfw:commentRss>http://journal.naveeng.com/2007/10/17/perl-one-liner-to-sort-and-hash-and-return-the-top-most-keyvalue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install Perl Modules without root</title>
		<link>http://journal.naveeng.com/2007/10/16/install-perl-modules-without-root/</link>
		<comments>http://journal.naveeng.com/2007/10/16/install-perl-modules-without-root/#comments</comments>
		<pubDate>Tue, 16 Oct 2007 18:40:16 +0000</pubDate>
		<dc:creator>Naveen</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://journal.naveeng.com/2007/10/16/install-perl-modules-without-root/</guid>
		<description><![CDATA[How many times Perl developers have to scratch their heads when they find that there is a module dependency which is breaking their code. Worse, they do not have sufficient privileges to install the required modules on the system. And the worst &#8211; there is no immediate way to get the module installed and the [...]]]></description>
			<content:encoded><![CDATA[<p>How many times <a href="http://en.wikipedia.org/wiki/Perl" target="_blank">Perl </a>developers have to scratch their heads when they find that there is a module dependency which is breaking their code. Worse, they do not have sufficient privileges to install the required modules on the system.  And the worst &#8211; there is no immediate way to get the module installed and the application needs to be tested/deployed ASAP! Well, I faced a similar situation during my experience in deploying a website on a shared hosting account, where I was on the mercy of the Hosting Service Provider to decide which modules I&#8217;m going to use and which not. But this is hardly the way a programmer works, and more so for a Perl programmer! I came across a few wonderful workarounds (hacks!) to overcome the above.</p>
<p>Download the module from <a href="http://search.cpan.org" target="_blank">CPAN</a> or elsewhere. Place it in any directory, where you have permissions. Preferably, create a directory called</p>
<pre>lib</pre>
<p>in the application directory and place your module there. Untar it, you will see a few files and folders &#8211; <strong>Makefile.pl</strong> (to install the module, we don&#8217;t need this) , <strong>Readme.txt </strong>(this either), <strong>Examples </strong>(not required), lib directory &#8211; this is the only thing we are concerned with. It contains the main module files. Go inside the lib directory, and copy all the folders (if any) and all <strong>.pm </strong>files and place them directly inside the lib directory you just created. Remove all other files and folders.</p>
<p>The next thing which you need to do is go to the Perl code where you want to use that module and write the following:</p>
<pre>BEGIN { unshift @INC, "./lib"; }</pre>
<pre>use Module::Name;</pre>
<p>And voila!! Your code works like a charm with all the functionalities of the module included.</p>
<p><strong>How it works? </strong>- When you use a module in a program, like</p>
<pre>use CGI::Ajax;</pre>
<p><strong>perl</strong> searches for it in a predefined library search path on the system. You can determine which directories are in the path by executing</p>
<pre>perl -e 'print for @INC;'</pre>
<p>Any module in order to be usable in the program needs to be in any of the directories above, which is where the modules get installed if installed via</p>
<pre>cpan or ppm</pre>
<p>command or using <strong>Makefile.pl</strong>.</p>
<p>But in the situation discussed, it is not the case, as we cannot install a module as it should be. Instead what we do is place the modules in a directory of our choice (lib) and then insert the path of that directory in the</p>
<pre>@INC</pre>
<p>so that later when the perl interpreter tries to do</p>
<pre>use Module::Name;</pre>
<p>it finds its path in</p>
<pre>@INC</pre>
<p><strong>Why BEGIN { } ? -</strong></p>
<pre>use Module::Name</pre>
<p>happens at compile time, when the interpreter reads the program while</p>
<pre>unshift @INC, "./lib"</pre>
<p>happens at run-time, after the compilation, i.e, attempt to load the module, even if the latter is placed above the former in the program. So in order to force the program to modify</p>
<pre>@INC</pre>
<p>before trying to use the module, we use</p>
<pre>BEGIN { }</pre>
<p>block. Any code which is written within</p>
<pre>BEGIN { }</pre>
<p>block is executed at compile-time as opposed to other code which is executed at run-time.</p>
<p><strong>Note: </strong>Remember that  many modules have further dependencies, i.e. modules which are required for the former to work. And if these dependencies are not on the system, the code won&#8217;t work. You need to perform the above operations for each of those dependencies as well. For example, if <a href="http://search.cpan.org/~bct/CGI-Ajax-0.701/lib/CGI/Ajax.pm" target="_blank">CGI::Ajax</a> requires <a href="http://search.cpan.org/~kasei/Class-Accessor-0.31/lib/Class/Accessor.pm" target="_blank">Class::Accessor </a>to work, you need to</p>
<p>a) create the directory <strong>CGI</strong> and place <strong>Ajax.pm</strong> within it</p>
<p>b) create the directory <strong>Class </strong>and place <strong>Accessor.pm </strong>and the directory <strong>Accessor </strong>within it and</p>
<p>c) <strong>unshift/push </strong>the path of the directory which contains these 2 directories <strong>CGI </strong>and <strong>Class,</strong> into <strong>@INC.</strong></p>
<p>I have used this method to use more than 30 odd modules and have faced no difficulty whatsoever. However it will not work if the module&#8217;s <strong>Makefile.pl </strong>does more than just copying the <strong>.pm </strong>files in the right place and do some other work such as using external C libraries etc.</p>
<p>Another method of extending</p>
<pre>@INC</pre>
<p>is setting the</p>
<pre>PERL5LIB</pre>
<p>environment variable on your system to include the path of the manually placed modules.</p>
<p>In Bourne Shell do something like-</p>
<pre>PERL5LIB=/path/to/module/directory; export PERL5LIB</pre>
<p>It is useful when you do no want to write the <strong>BEGIN </strong>blocks in all the files where you use the module. But only users who are setting the</p>
<pre>PERL5LIB</pre>
<p>environment variable can only use it and other users can&#8217;t.</p>
]]></content:encoded>
			<wfw:commentRss>http://journal.naveeng.com/2007/10/16/install-perl-modules-without-root/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>My First JAPH!</title>
		<link>http://journal.naveeng.com/2007/10/15/my-first-japh/</link>
		<comments>http://journal.naveeng.com/2007/10/15/my-first-japh/#comments</comments>
		<pubDate>Mon, 15 Oct 2007 18:05:53 +0000</pubDate>
		<dc:creator>Naveen</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[japh]]></category>

		<guid isPermaLink="false">http://journal.naveeng.com/2007/10/15/my-first-japh/</guid>
		<description><![CDATA[Finally after procrastinating for long, I decided to tread the path traversed only by the GODs of PERL &#8211; writing JAPHs!! And my brain storming for about 6 hours finally ended with a JAPH, not too bad for a debut, albeit a little amateur. For those of who are still wondering what the heck is [...]]]></description>
			<content:encoded><![CDATA[<p>Finally after procrastinating for long, I decided to tread the path traversed only by the <strong>GODs</strong> of <a href="http://en.wikipedia.org/wiki/PERL" target="_blank">PERL</a> &#8211; writing <a href="http://en.wikipedia.org/wiki/JAPH" target="_blank">JAPH</a>s!! And my brain storming for about 6 hours finally ended with a JAPH, not too bad for a debut, albeit a little amateur. For those of who are still wondering what the heck is a JAPH &#8211; it refers to a PERL program which prints the phrase <strong>JUST ANOTHER PERL HACKER. </strong>It is an art initiated by <a href="http://en.wikipedia.org/wiki/Randal_L._Schwartz" target="_blank">Randal Schwartz</a> and further mastered by the likes of Abigail. My piece of code is as follows:<br />
<font face="courier new"><br />
#!/usr/bin/perl</font></p>
<p><font face="courier new">@b=map +{keys %$_} , map +{chr}, grep {!/6[68]|7[0137]|81/} (65..85);</font></p>
<p><font face="courier new">%hs1=(74,1,85,2,83,3,84,4);<br />
%hs2=(65,1,78,2,79,3,84,4,72,5,69,6,82,7);<br />
%hs3=(80,1,69,2,82,3,76,4);<br />
%hs4=(72,1,65,2,67,3,75,4,69,5,82,6);</font></p>
<p><font face="courier new">for $i(1..4) { $n=&#8221;h2&#8243;.$i;for (0..13) {@abc=keys %{$b[$_]};$k=pop @abc;map { ${$n}{$_}++ } keys %{$b[$_]} if ((($i==1) &amp;&amp; ($k=~m![tsuj]!i)) || (($i==2) &amp;&amp; ($k=~m![rehtona]!i)) || (($i==3) &amp;&amp; ($k=~m![lrep]!i)) || (($i==4) &amp;&amp; ($k=~m![rekcah]!i))); }}</font></p>
<p><font face="courier new">for (1..4){$m=&#8221;h2&#8243;.$_;$ms=&#8221;hs&#8221;.$_; print sort {${$ms}{ord $a} &lt;=&gt; ${$ms}{ord $b}} keys %{$m}, &#8221; &#8220;;}</font></p>
<p>I particularly don&#8217;t like two parts of the above code -</p>
<p>1) The 4 hashes at the top &#8211; they are used to sort the letters in the words (It took most of my time)</p>
<p>2) The big if ( ) {  } block &#8211; it kinda gives the code a very amateurish look.</p>
<p>So while I work on improving myself, do give in some suggestions if you may please <img src='http://journal.naveeng.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>And if you think that was smart, then have a look at  <a href="http://www.cpan.org/misc/japh" target="_blank">http://www.cpan.org/misc/japh</a> or <a href="http://en.wikipedia.org/wiki/JAPH" target="_blank">http://en.wikipedia.org/wiki/JAPH</a> for some of the most astonishing piece of coding across any language on this planet.</p>
]]></content:encoded>
			<wfw:commentRss>http://journal.naveeng.com/2007/10/15/my-first-japh/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Multiple Yahoo Messengers simultaneously</title>
		<link>http://journal.naveeng.com/2007/10/01/multiple-yahoo-messengers-simultaneously/</link>
		<comments>http://journal.naveeng.com/2007/10/01/multiple-yahoo-messengers-simultaneously/#comments</comments>
		<pubDate>Mon, 01 Oct 2007 05:31:34 +0000</pubDate>
		<dc:creator>Naveen</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Yahoo]]></category>

		<guid isPermaLink="false">http://journal.naveeng.com/2007/10/01/multiple-yahoo-messengers-simultaneously/</guid>
		<description><![CDATA[I just received this forwarded email with instructions on how to activate multiple instances of Yahoo! Messenger on the same machine without the use of any software. I tried it out and its awesome! Working really fine. Just follow the instructions below and you are all set: Go to Start &#8212;-&#62; Run . Type regedit, [...]]]></description>
			<content:encoded><![CDATA[<p>I just received this forwarded email with instructions on how to activate multiple instances of <strong>Yahoo! Messenger</strong> on the same machine without the use of any software. I tried it out and its awesome! Working really fine. Just follow the instructions below and you are all set:</p>
<ol>
<li><strong>Go to Start &#8212;-&gt; Run . Type regedit, then enter</strong></li>
<li><strong>Navigate to HKEY_CURRENT_USER &#8212;&#8212;&#8211;&gt; Software &#8212;&gt; Yahoo!  &#8212;&#8211;&gt;pager&#8212;-&gt;Test</strong></li>
<li><strong>On the right pane , right-click and choose new Dword value</strong></li>
<li><strong>Rename it as Plural</strong></li>
<li><strong>Double click and assign a decimal value of 1</strong></li>
<li><strong>Now close registry and restart Yahoo! messenger .For signing in with new id open another messenger. Open as many messengers u need</strong></li>
</ol>
<p>The above has been tested on Windows XP and Yahoo! Messenger Version 8.1.</p>
<p>Cheers</p>
]]></content:encoded>
			<wfw:commentRss>http://journal.naveeng.com/2007/10/01/multiple-yahoo-messengers-simultaneously/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax Yahoo! Mail for FireFox!</title>
		<link>http://journal.naveeng.com/2006/01/04/ajax-yahoo-mail-for-firefox/</link>
		<comments>http://journal.naveeng.com/2006/01/04/ajax-yahoo-mail-for-firefox/#comments</comments>
		<pubDate>Wed, 04 Jan 2006 11:49:00 +0000</pubDate>
		<dc:creator>Naveen</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Yahoo]]></category>

		<guid isPermaLink="false">http://journal.naveeng.com/2006/01/04/ajax-yahoo-mail-for-firefox/</guid>
		<description><![CDATA[Another Ajax Wonder we have for our disposal. For all Yahoo! Mail+Firefox users theres this cool plugin that saves you from entering the inbox for every message. All you need is to click on the &#8216;+&#8216; sign beside every mail, which is put by this plugin, and wow..! you have a drop-down preview of that [...]]]></description>
			<content:encoded><![CDATA[<p>Another Ajax Wonder we have for our disposal. For all <span style="color: #ff0000;">Yahoo! Mail</span>+<span style="color: #ff0000;">Firefox</span> users theres this cool plugin that saves you from entering the inbox for every message. All you need is to click on the &#8216;<span style="font-weight: bold;">+</span>&#8216; sign beside every mail, which is put by this plugin, and wow..! you have a drop-down preview of that mail right outside your inbox! However big that mail might be, and whatever it contains, it shows up everything. Just click on the sign again to close the preview and proceed with the next. Referred to me by <a href="http://anantsancheti.blogspot.com">Anant</a> , i&#8217;m finding it quite handful. You can download it from  <a href="https://addons.mozilla.org/extensions/moreinfo.php?application=firefox&amp;category=Website%20Integration&amp;numpg=10&amp;id=1127">HERE</a> .</p>
<p><span style="font-weight: bold;">Screenshots </span>-</p>
<p><a href="http://photos1.blogger.com/blogger/5121/757/1600/4.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/5121/757/400/4.jpg" border="0" alt="" /></a><br />
<a href="http://photos1.blogger.com/blogger/5121/757/1600/new.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/5121/757/400/new.jpg" border="0" alt="" /></a><br />
<span style="font-size:100%;"><span style="font-style: italic;">PS-Will soon be putting up a list of great FF Extensions I use, in the sidebar. Keep Watching</span></span><br />
<a href="https://addons.mozilla.org/extensions/moreinfo.php?application=firefox&amp;category=Website%20Integration&amp;numpg=10&amp;id=1127"></a><a href="https://addons.mozilla.org/extensions/moreinfo.php?application=firefox&amp;category=Website%20Integration&amp;amp;amp;numpg=10&amp;id=1127"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://journal.naveeng.com/2006/01/04/ajax-yahoo-mail-for-firefox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
