<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Brain Dump</title>
	<atom:link href="http://balajirrao.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://balajirrao.wordpress.com</link>
	<description>My Official blog</description>
	<lastBuildDate>Thu, 24 Feb 2011 15:55:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='balajirrao.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Brain Dump</title>
		<link>http://balajirrao.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://balajirrao.wordpress.com/osd.xml" title="Brain Dump" />
	<atom:link rel='hub' href='http://balajirrao.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Evaluating memory bandwidth</title>
		<link>http://balajirrao.wordpress.com/2010/01/31/evaluating-mem-bandwidth/</link>
		<comments>http://balajirrao.wordpress.com/2010/01/31/evaluating-mem-bandwidth/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 15:12:06 +0000</pubDate>
		<dc:creator>balajirrao</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[memcpy]]></category>
		<category><![CDATA[memory]]></category>

		<guid isPermaLink="false">http://balajirrao.wordpress.com/?p=126</guid>
		<description><![CDATA[&#8220;So, how fast can memory to memory copy can get ?&#8221; I asked myself. And the result, a simple program that does that and I was surprised to see the graphed results. Here&#8217;s what I did, allocated 2 x 1.6 GB or buffers and mlocked them (yes, I have 4 GB of physical RAM) and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=126&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&#8220;So, how fast can memory to memory copy can get ?&#8221; I asked myself. And the result, a simple program that does that and I was surprised to see the graphed results. Here&#8217;s what I did, allocated 2 x 1.6 GB or buffers and <a href="http://linux.die.net/man/2/mlock">mlocked</a> them (yes, I have 4 GB of physical RAM) and did a memcpy across them, with varying block sizes and the result is,</p>
<div id="attachment_127" class="wp-caption alignnone" style="width: 650px"><a href="http://balajirrao.files.wordpress.com/2010/01/plot.png"><img class="size-full wp-image-127 " title="memcpy performance" src="http://balajirrao.files.wordpress.com/2010/01/plot.png?w=640&#038;h=480" alt="" width="640" height="480" /></a><p class="wp-caption-text">Plot of Bandwidth vs Block Size for memcpy between two 1600 MB buffers</p></div>
<p>Here&#8217;s data from another machine of mine, with ~2G physical RAM. I had to limit myself to using 2 x 800 MB buffers here.</p>
<div id="attachment_128" class="wp-caption alignnone" style="width: 650px"><a href="http://balajirrao.files.wordpress.com/2010/01/plot1.png"><img class="size-full wp-image-128 " title="memcpy performance" src="http://balajirrao.files.wordpress.com/2010/01/plot1.png?w=640&#038;h=480" alt="" width="640" height="480" /></a><p class="wp-caption-text">Plot of Bandwidth vs Block Size for memcpy between two 800 MB buffers</p></div>
<p>From these two it seems that the maximum bandwidth is achieved by using a block size which is around half, though not exactly but definitely not less than half (see the huge drop in bandwidth to it&#8217;s left). I guess this behaviour is due to the implementation of memcpy in glibc (v2.11.1-1.x86_64). I haven&#8217;t looked at the sources yet, so I don&#8217;t know how to explain this, yet.</p>
<p>I&#8217;m including the program source here, please do leave a comment!</p>
<pre class="brush: cpp;">
/* Dumb memory bandwidth measurer
   Best run in runlevel 1
*/

#include &lt;stdio.h&gt;
#include &lt;sys/time.h&gt;

#define MB * (1024 * 1024)
#define KB * (1024)
int main()
{
 int i, j;
 struct timeval t1, t2, t3;
 char *a, *b;
 int nsteps, max;
 int mem = 1500;

 a = malloc(mem MB);
 b = malloc(mem MB);

 mlock(a, mem MB);
 mlock(b, mem MB);

 nsteps = 160;
 max = mem;

 for (j = 1; j &lt;= max; j += max / nsteps) {
   gettimeofday(&amp;t1, NULL);

   for (i = 0; i &lt; mem / j; i++)
     memcpy(a + i * j MB, b + i * j MB, j MB);

   gettimeofday(&amp;t2, NULL);

   timersub(&amp;t2, &amp;t1, &amp;t3);

   printf(&quot;%d %f\n&quot;, j, mem / ((t3.tv_usec / 1000000.0) + t3.tv_sec * 1.0));
 }
}
</pre>
<p>Credit : Data visualization using <a href="http://gnuplot.info/">gnuplot</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/balajirrao.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/balajirrao.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/balajirrao.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/balajirrao.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/balajirrao.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/balajirrao.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/balajirrao.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/balajirrao.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/balajirrao.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/balajirrao.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/balajirrao.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/balajirrao.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/balajirrao.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/balajirrao.wordpress.com/126/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=126&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://balajirrao.wordpress.com/2010/01/31/evaluating-mem-bandwidth/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7e6c0aafc452a933d1dee3a040b05744?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">balajirrao</media:title>
		</media:content>

		<media:content url="http://balajirrao.files.wordpress.com/2010/01/plot.png" medium="image">
			<media:title type="html">memcpy performance</media:title>
		</media:content>

		<media:content url="http://balajirrao.files.wordpress.com/2010/01/plot1.png" medium="image">
			<media:title type="html">memcpy performance</media:title>
		</media:content>
	</item>
		<item>
		<title>Input validation in C</title>
		<link>http://balajirrao.wordpress.com/2009/05/06/input-validation-in-c/</link>
		<comments>http://balajirrao.wordpress.com/2009/05/06/input-validation-in-c/#comments</comments>
		<pubDate>Tue, 05 May 2009 22:14:09 +0000</pubDate>
		<dc:creator>balajirrao</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://balajirrao.wordpress.com/?p=118</guid>
		<description><![CDATA[Just today I found a stable and powerful way to validate inputs in C, using regular expressions. Gnulib provides a header called regex.h and doing man regex.h will help you find more. Here&#8217;s how you use it. First, the regular expression should be &#8216;compiled&#8217; &#8211; not in the usual sense, but it&#8217;s converted to a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=118&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just today I found a stable and powerful way to validate inputs in C, using regular expressions. Gnulib provides a header called regex.h and doing man regex.h will help you find more. Here&#8217;s how you use it.</p>
<p>First, the regular expression should be &#8216;compiled&#8217; &#8211; not in the usual sense, but it&#8217;s converted to a format which increases the speed of pattern matching.</p>
<p>Here&#8217;s a simple example, which is used to validate rectangular dimension inputs.</p>
<pre class="brush: cpp;">

#include &lt;regex .h&gt;

int main()
{
 char *regex  = &quot;[1-9][0-9]\\{1,\\}x[1-9][0-9]\\{1,\\}&quot;;
 regex_t regc;

 regcomp(&amp;regc, regex, 0);

 /* Does it match ? */
 return regexec(&amp;regc, &quot;800x500&quot;, 0, 0, 0) == 0;
}
</pre>
<p></regex></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/balajirrao.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/balajirrao.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/balajirrao.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/balajirrao.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/balajirrao.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/balajirrao.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/balajirrao.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/balajirrao.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/balajirrao.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/balajirrao.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/balajirrao.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/balajirrao.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/balajirrao.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/balajirrao.wordpress.com/118/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=118&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://balajirrao.wordpress.com/2009/05/06/input-validation-in-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7e6c0aafc452a933d1dee3a040b05744?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">balajirrao</media:title>
		</media:content>
	</item>
		<item>
		<title>Cricket mostly about batting ?</title>
		<link>http://balajirrao.wordpress.com/2008/12/20/cricket-mostly-about-batting/</link>
		<comments>http://balajirrao.wordpress.com/2008/12/20/cricket-mostly-about-batting/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 11:49:35 +0000</pubDate>
		<dc:creator>balajirrao</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[batsmen]]></category>
		<category><![CDATA[batting]]></category>
		<category><![CDATA[bowlers]]></category>
		<category><![CDATA[cricket]]></category>

		<guid isPermaLink="false">http://balajirrao.wordpress.com/?p=115</guid>
		<description><![CDATA[I had a chance, while at the barber&#8217;s shop, to watch the test match going on between India and England. India had lost some 8 wickets then and Zaheer Khan juusst got dismissed. &#8216;Ah, he doesn&#8217;t know to bat. He just wastes deliveries.. &#8216;  were the kind of comments floating around.. Is this justified ?? [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=115&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I had a chance, while at the barber&#8217;s shop, to watch the test match going on between India and England. India had lost some 8 wickets then and Zaheer Khan juusst got dismissed. &#8216;Ah, he doesn&#8217;t know to bat. He just wastes deliveries.. &#8216;  were the kind of comments floating around.. Is this justified ?? This led to a chain of thoughts..</p>
<p>Is the comment justified ? &#8211; I thought.. It felt to me if Cricket was totally batsmen centric ? Is cricket all about batting ? Batsmen don&#8217;t need to give a damn about bowling. When the regular bowlers get hit badly, do we ever shout &#8216;Why doesn&#8217;t xxx (a great batsmen) take the ball ?&#8221;. But see, the bowlers &#8211; They have to be able to decently bat and when all of the top order batsmen are gone, they are expected to bat well and save the game! No matter how exceptional bowler he may be he&#8217;s still a target of our criticism if he doesn&#8217;t..</p>
<p>Thinking more &#8211; It may not be all that bad! Bowlers kinda get an opportunity to correct their mistakes which means they don&#8217;t get OUT! But see the batsmen &#8211; they&#8217;re screwed if they lose concentration for a split second! Well, now it makes sense about why things are the way they are now..</p>
<p>Now, here&#8217;s something interesting. How about have a game in which the roles are reversed. Batsmen get to play for an over each, and Bowlers keep bowling till they get out (??) and .. ? .. ? Looking forward to your ideas..</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/balajirrao.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/balajirrao.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/balajirrao.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/balajirrao.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/balajirrao.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/balajirrao.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/balajirrao.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/balajirrao.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/balajirrao.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/balajirrao.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/balajirrao.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/balajirrao.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/balajirrao.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/balajirrao.wordpress.com/115/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=115&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://balajirrao.wordpress.com/2008/12/20/cricket-mostly-about-batting/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7e6c0aafc452a933d1dee3a040b05744?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">balajirrao</media:title>
		</media:content>
	</item>
		<item>
		<title>clrscr in linux!</title>
		<link>http://balajirrao.wordpress.com/2008/12/06/clrscr-in-linux/</link>
		<comments>http://balajirrao.wordpress.com/2008/12/06/clrscr-in-linux/#comments</comments>
		<pubDate>Sat, 06 Dec 2008 09:21:40 +0000</pubDate>
		<dc:creator>balajirrao</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[clear]]></category>
		<category><![CDATA[clrscr]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://balajirrao.wordpress.com/?p=111</guid>
		<description><![CDATA[Along the lines of the previous post One command called ‘clear’, I wrote a small C program that does clrscr(). Disclaimer : May not work!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=111&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="content_wrapper"></div>
<p>Along the lines of the previous post <a title="Permanent Link to One command called ‘clear’" rel="bookmark" href="http://balajirrao.wordpress.com/2008/12/05/one-command-called-clear/">One command called ‘clear’</a>, I wrote a small C program that does clrscr().</p>
<pre class="brush: cpp;">

/* clrscr in linux! */

#include &lt;stdio .h&gt;

void clrscr(void)
{
	char str[] = &quot; [H [2J&quot;;
	str[3] = str[0] = 27;
	write(1, str, 7);
}

int main(int argc, char **argv)
{
	clrscr();
	printf(&quot;Hello World\n&quot;);

	return 0;
}
</pre>
<p>Disclaimer : May not work! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </stdio></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/balajirrao.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/balajirrao.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/balajirrao.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/balajirrao.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/balajirrao.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/balajirrao.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/balajirrao.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/balajirrao.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/balajirrao.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/balajirrao.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/balajirrao.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/balajirrao.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/balajirrao.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/balajirrao.wordpress.com/111/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=111&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://balajirrao.wordpress.com/2008/12/06/clrscr-in-linux/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7e6c0aafc452a933d1dee3a040b05744?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">balajirrao</media:title>
		</media:content>
	</item>
		<item>
		<title>One command called &#8216;clear&#8217;</title>
		<link>http://balajirrao.wordpress.com/2008/12/05/one-command-called-clear/</link>
		<comments>http://balajirrao.wordpress.com/2008/12/05/one-command-called-clear/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 21:22:15 +0000</pubDate>
		<dc:creator>balajirrao</dc:creator>
				<category><![CDATA[Fedora]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[terminal clear]]></category>
		<category><![CDATA[terminal hacks]]></category>

		<guid isPermaLink="false">http://balajirrao.wordpress.com/?p=99</guid>
		<description><![CDATA[You must have used the command &#8216;clear(1)&#8217; to clear your terminal. Well, if you haven&#8217;t, please try it out. For those who know what it is, do you know how it works ? If you do, you can stop reading. Others, continue! Well, I wanted to find out how it works. So the first thing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=99&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>You must have used the command &#8216;clear(1)&#8217; to clear your terminal. Well, if you haven&#8217;t, please try it out. For those who know what it is, do you know how it works ? If you do, you can stop reading. Others, continue!</p>
<p>Well, I wanted to find out how it works. So the first thing I did was an strace to see what syscalls it did..</p>
<pre>[root@cff ~]# strace clear</pre>
<p>and I was left with..</p>
<pre>)              = 7
exit_group(0)                           = ?
[root@cff ~]#</pre>
<p>Well, it did clear the screen! I tried to redirect the output to a file. No use. An interesting idea struck me. What will happen if I redirect output of clear, I thought..</p>
<pre>[root@cff ~]# clear &gt; out
[root@cff ~]#</pre>
<p>Wow! It didn&#8217;t clear the screen.. Let me see what&#8217;s in the file.. vim didn&#8217;t work out well. I used od.</p>
<pre>[root@cff ~]# od -bc out
0000000 033 133 110 033 133 062 112
        033   [   H 033   [   2   J
0000007
[root@cff ~]#</pre>
<p>Some weird ascii characters. Now, I did &#8216;cat out&#8217; and I was surprised to see the terminal cleared! Wow! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now even better, I wanted to use echo and clear the screen. Going through the echo manual, I found out how to do it. Here it is. Please replace &lt;zero&gt; with a 0. This damn wordpress for an unknown reason does not allow me to put a 0 in there.</p>
<pre> echo -e "\&lt;zero&gt;33[H\&lt;zero&gt;33[2J"</pre>
<p>Execute this, and your terminal will be cleared.</p>
<p>If it didn&#8217;t, you have to do all the steps I performed and find out the byte sequence that will clear your terminal. Good luck!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/balajirrao.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/balajirrao.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/balajirrao.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/balajirrao.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/balajirrao.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/balajirrao.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/balajirrao.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/balajirrao.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/balajirrao.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/balajirrao.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/balajirrao.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/balajirrao.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/balajirrao.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/balajirrao.wordpress.com/99/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=99&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://balajirrao.wordpress.com/2008/12/05/one-command-called-clear/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7e6c0aafc452a933d1dee3a040b05744?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">balajirrao</media:title>
		</media:content>
	</item>
		<item>
		<title>What&#8217;s the point ?</title>
		<link>http://balajirrao.wordpress.com/2008/11/24/whats-the-point/</link>
		<comments>http://balajirrao.wordpress.com/2008/11/24/whats-the-point/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 10:20:13 +0000</pubDate>
		<dc:creator>balajirrao</dc:creator>
				<category><![CDATA[Philosophy]]></category>
		<category><![CDATA[Chandrayan]]></category>
		<category><![CDATA[Hunger]]></category>
		<category><![CDATA[india]]></category>
		<category><![CDATA[Nuke]]></category>
		<category><![CDATA[Pakistan]]></category>
		<category><![CDATA[Poverty]]></category>
		<category><![CDATA[Religion]]></category>

		<guid isPermaLink="false">http://balajirrao.wordpress.com/?p=95</guid>
		<description><![CDATA[This news headline &#8216;Pakistan won&#8217;t be first in nuclear strike&#8216;, made me slip into my own world of thoughts. Is it meaningful at all ? Isn&#8217;t it rubbish ?, I thought. Dude!, using a nuclear weapon is going to wipe out human race for sure and hey! and we still talk about it, as if [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=95&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This news headline &#8216;<a href="http://news.yahoo.com/s/ap/20081123/ap_on_re_as/as_pakistan_india_nuclear">Pakistan won&#8217;t be first in nuclear strike</a>&#8216;, made me slip into my own world of thoughts. Is it meaningful at all ? Isn&#8217;t it rubbish ?, I thought. Dude!, using a nuclear weapon is going to wipe out human race for sure and hey! and we still talk about it, as if it were a solution. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Every big country spends so many billions of $$ on researching and acquiring armaments. What are we trying to solve by this ? I was wondering why no one even talks about hunger, illiteracy, health and various other problems plaguing the world ?</p>
<p>What we know of, is this one earth, this one family of Humans. Imagine if, in a family, the members started thinking about his/her security/welfare when others in the same family are dying out of malnutrition. What other than fools are we ?</p>
<p>One the same note, India&#8217;s most talked about space mission &#8211; Chandrayan came to my mind. India had produced thinkers, who were great astronomers, scientists, mathematicians etc. There are even accounts of having discovered the &#8216;Pythogoras theorem&#8217; centuries before Pythogoras did etc. If the same trend continued, we should have landed on the moon, centruries before anyone else did. But it did not happen. Why ?</p>
<p>One can appreciate the answer if he can understand the very existence of &#8216;science&#8217;. Science is nothing but a study, an attempt to find about ourselves, our environment, and answer questions such as &#8216;Who are we ?&#8217;, &#8216;What are we doing here ?&#8217;. &#8216;What is death ? Where happens after that ?&#8217; etc. In the east, men started searching for answers outside, but they quickly discovred its futility and started looking for, inside and this gave birth to Religion. It evolved continuously for centuries, till they found the truth, and thereafter they had no need of going out anymore as they had realised that what is within is without. But the west started and still continue to search outside. And, India where the eternal trurth was known for centuries, is trying to &#8216;keep up&#8217; pace with the west, dumping all our treasure, as it were. Hey, do we need to keep up at all ? The bazillions spent on such programs could well be spent in solving India&#8217;s poverty, education and so many other problems.</p>
<p>Let&#8217;s make our brothers and sisters happy first. Jai Hind.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/balajirrao.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/balajirrao.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/balajirrao.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/balajirrao.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/balajirrao.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/balajirrao.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/balajirrao.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/balajirrao.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/balajirrao.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/balajirrao.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/balajirrao.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/balajirrao.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/balajirrao.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/balajirrao.wordpress.com/95/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=95&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://balajirrao.wordpress.com/2008/11/24/whats-the-point/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7e6c0aafc452a933d1dee3a040b05744?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">balajirrao</media:title>
		</media:content>
	</item>
		<item>
		<title>End of September&#8217;s quota</title>
		<link>http://balajirrao.wordpress.com/2008/09/14/end-of-septembers-quota/</link>
		<comments>http://balajirrao.wordpress.com/2008/09/14/end-of-septembers-quota/#comments</comments>
		<pubDate>Sat, 13 Sep 2008 21:31:20 +0000</pubDate>
		<dc:creator>balajirrao</dc:creator>
				<category><![CDATA[Fedora]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[bsnl]]></category>
		<category><![CDATA[yum]]></category>
		<category><![CDATA[yum-updatesd]]></category>

		<guid isPermaLink="false">http://balajirrao.wordpress.com/?p=90</guid>
		<description><![CDATA[I have the habit of keeping my computer on when I go out for a couple of hours. Something really, really weird happened today. A sad thing. Back home I see that my BSNL broadband utilization stands at 3.1 GB out of 2.5 GB and its still 13th of the month. I was extremely shocked [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=90&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have the habit of keeping my computer on when I go out for a couple of hours. Something really, really weird happened today. A sad thing.</p>
<p>Back home I see that my BSNL broadband utilization stands at 3.1 GB out of 2.5 GB and its still 13th of the month. I was extremely shocked to see this.I quickly went to see the running processes and I see yum-updatesd taking up 200% of my CPU. I killed it right away! I believe that it is responsible for this notoriously large download. If you have to object, please comment!</p>
<p>I&#8217;ve disabled yum-updatesd for good. Damn it! I even once considered changing over to yum. But it was only in a fit of rage. Now I&#8217;m sticking to Fedora <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/balajirrao.wordpress.com/90/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/balajirrao.wordpress.com/90/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/balajirrao.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/balajirrao.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/balajirrao.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/balajirrao.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/balajirrao.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/balajirrao.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/balajirrao.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/balajirrao.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/balajirrao.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/balajirrao.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/balajirrao.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/balajirrao.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/balajirrao.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/balajirrao.wordpress.com/90/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=90&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://balajirrao.wordpress.com/2008/09/14/end-of-septembers-quota/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7e6c0aafc452a933d1dee3a040b05744?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">balajirrao</media:title>
		</media:content>
	</item>
		<item>
		<title>Red Hat buys Qumranet</title>
		<link>http://balajirrao.wordpress.com/2008/09/05/rh_qumranet/</link>
		<comments>http://balajirrao.wordpress.com/2008/09/05/rh_qumranet/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 13:00:09 +0000</pubDate>
		<dc:creator>balajirrao</dc:creator>
				<category><![CDATA[KVM]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[XEN]]></category>
		<category><![CDATA[kvm]]></category>
		<category><![CDATA[novell]]></category>
		<category><![CDATA[qumranet]]></category>
		<category><![CDATA[redhat]]></category>
		<category><![CDATA[vdi]]></category>

		<guid isPermaLink="false">http://balajirrao.wordpress.com/?p=87</guid>
		<description><![CDATA[After seeing another virtualization.info feed in my inbox, I was going through it leisurely just glancing through the topics and I came across a news line which read &#8220;Red Hat acquires Qumranet, suddenly becoming a key virtualization player&#8221; and I sprang to my feet with surprise. Red Hat already had adopted KVM as the main [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=87&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After seeing another <a href="http://www.virtualization.info/">virtualization.info</a> feed in my inbox, I was going through it leisurely just glancing through the topics and I came across a news line which read <strong>&#8220;Red Hat acquires Qumranet, suddenly becoming a key virtualization player&#8221;</strong> and I sprang to my feet with surprise. Red Hat already had adopted KVM as the main VMM that it would ship in its products. But I never expected this to happen <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>This has may implications and my brain started thinking what they could be.. One thing is certain. Since its rival Novell is investing in XEN, Red Hat probably wanted to do something different. One more thing is that Red Hat did not have great influence on XEN, more less after XenSource was acquired by Citrix. So, KVM was one thing which Red Hat could potentially influence. An important thing to note is that, Red Hat already had expressed interest in Qumranet&#8217;s VDI solution a few months earlier.</p>
<p>The main consequence of this, I believe is that Red Hat products will have solid support for KVM. With the popularity of KVM growing by leaps and bounds, this could mean more customers and hence more revenue to Red Hat. This might also bring newer customers to KVM who might be now willing to invest in it seeing that it will be backed by Red Hat. All in all I see it as a very good move.</p>
<p>Another thing that surprises me is the money involved. Red Hat paid $107M in cash. Quite a big amount I feel. I feel that its not because of how much KVM is valuable <em>now</em>, but how much KVM will be valuable in a few years from now.</p>
<p>It&#8217;ll be indeed interesting to watch how things will go from here..</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/balajirrao.wordpress.com/87/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/balajirrao.wordpress.com/87/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/balajirrao.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/balajirrao.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/balajirrao.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/balajirrao.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/balajirrao.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/balajirrao.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/balajirrao.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/balajirrao.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/balajirrao.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/balajirrao.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/balajirrao.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/balajirrao.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/balajirrao.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/balajirrao.wordpress.com/87/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=87&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://balajirrao.wordpress.com/2008/09/05/rh_qumranet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7e6c0aafc452a933d1dee3a040b05744?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">balajirrao</media:title>
		</media:content>
	</item>
		<item>
		<title>My LZ77 implementation</title>
		<link>http://balajirrao.wordpress.com/2008/09/02/lz77/</link>
		<comments>http://balajirrao.wordpress.com/2008/09/02/lz77/#comments</comments>
		<pubDate>Tue, 02 Sep 2008 17:09:40 +0000</pubDate>
		<dc:creator>balajirrao</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[dictionary encoding]]></category>
		<category><![CDATA[lz77 implementation]]></category>
		<category><![CDATA[zip]]></category>

		<guid isPermaLink="false">http://balajirrao.wordpress.com/?p=80</guid>
		<description><![CDATA[I began reading about dictionary compression in Solomon, a reference book for data compression. I came across the LZ77 method and I was amazed at it! I decided to write one implementation quickly, in C. Here&#8217;s what I have come up with. I used to compress sched.c (the linux scheduler source file) from 221K to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=80&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I began reading about dictionary compression in Solomon, a reference book for data compression. I came across the LZ77 method and I was amazed at it! I decided to write one implementation quickly, in C. Here&#8217;s what I have come up with. I used to compress sched.c (the linux scheduler source file) from 221K to 142K. Not bad I say <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>LZ77 is a very simple compresison method. It&#8217;s available almost everywhere. Do read about it.</p>
<pre class="brush: cpp;">

/* compress.c - compression using LZ77 */
#include &lt;stdio .h&gt;
#include &lt;stdint .h&gt;
#include &lt;string .h&gt;
#include &lt;sys /stat.h&gt;
#include &lt;unistd .h&gt;
#include &lt;sys /types.h&gt;
#include &lt;stdlib .h&gt;

#define LBSIZE 8
#define SBSIZE 1024
#define WINDOWSIZE (LBSIZE + SBSIZE)

struct token {
	uint16_t pos:10;
	uint8_t len:3;
	char next;
} __attribute__((packed));

int main()
{
	struct token t = {0, 0, 0};
	int i = 0, len;
	char *str;
	char *sb;
	int sb_len = 0;
	char *lb, *p;
	struct stat buff;

	int match_len = 0, match_pos = 0;

	(void) fstat(0, &amp;buff);

	str = malloc(buff.st_size);
	fread(str, 1, buff.st_size, stdin);
	len = buff.st_size;

	lb = str;
	i = 0;

	do {
		lb += (match_len + 1);
		i += (match_len + 1);

		t.pos = match_pos; t.len = match_len; t.next = *(lb - 1);
		fwrite(&amp;t, 1, sizeof(t), stdout);		

		if ( i &gt;= SBSIZE) {
			sb += (match_len + 1);
		}

		else
			sb = str;

		match_len = match_pos = 0;

		/* Matching code */
		for(p = lb - 1; p &gt;= sb; p--) {
			int j = 0;
			while (*(p + j) == *(lb + j) &amp;&amp; j &lt; LBSIZE - 1)
				j++;

			if (j &gt; match_len) {
				match_len = j;
				match_pos = lb  -p;
			}
		}
	} while ( i &lt; len);
}
</pre>
<p>And, here&#8217;s the uncompressing part. Its smaller and simpler than the compressor..</p>
<pre class="brush: cpp;">

/* uncompress.c - */
#include &lt;stdio.h&gt;
#include &lt;stdint .h&gt;
#include &lt;string .h&gt;

#define LBSIZE 10
#define SBSIZE 30
#define WINDOWSIZE (LBSIZE + SBSIZE)

struct token {
	uint16_t pos:10;
	uint8_t len:3;
	char next;
} __attribute__((packed));

	char buf[1024 * 1024];

int main()
{
	struct token *t;
	char *sb;
	unsigned int k = 0, len, i = 0, j, k1;
	char str[81];

	while((len = fread(str, sizeof(struct token), 2, stdin))) {

	t = (struct token *)str;

	for (i = 0; i &lt; len ; i ++) {
		if ((t + i)-&gt;pos == 0) {
			buf[k++] = (t+i)-&gt;next;
		}
		else {
			strncpy(buf + k, buf + k - (t+i)-&gt;pos, (t+i)-&gt;len);

			k+= (t+i)-&gt;len;

			buf[k++] = (t + i)-&gt;next;
		}
	}
	}
	puts(buf);
}
</pre>
<p>Now on to better ones like LZ78, LZSS, LZRW1, gzip and so on. I was really amazed at what compression offers. What do you think ?</string></stdint></stdlib></sys></unistd></sys></string></stdint></stdio></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/balajirrao.wordpress.com/80/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/balajirrao.wordpress.com/80/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/balajirrao.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/balajirrao.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/balajirrao.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/balajirrao.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/balajirrao.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/balajirrao.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/balajirrao.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/balajirrao.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/balajirrao.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/balajirrao.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/balajirrao.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/balajirrao.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/balajirrao.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/balajirrao.wordpress.com/80/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=80&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://balajirrao.wordpress.com/2008/09/02/lz77/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7e6c0aafc452a933d1dee3a040b05744?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">balajirrao</media:title>
		</media:content>
	</item>
		<item>
		<title>Fun with BSNL Modem and SNMP</title>
		<link>http://balajirrao.wordpress.com/2008/08/16/snmp-fun/</link>
		<comments>http://balajirrao.wordpress.com/2008/08/16/snmp-fun/#comments</comments>
		<pubDate>Sat, 16 Aug 2008 02:29:05 +0000</pubDate>
		<dc:creator>balajirrao</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[bsnl]]></category>
		<category><![CDATA[net-snmp]]></category>
		<category><![CDATA[pygtk]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[snmp]]></category>
		<category><![CDATA[snmp statistics]]></category>
		<category><![CDATA[tkmib]]></category>

		<guid isPermaLink="false">http://balajirrao.wordpress.com/?p=61</guid>
		<description><![CDATA[When surfing my ADSL modem&#8217;s web console, I came across a page on SNMP daemon, which read Simple Network Management Protocol (SNMP) allows a management application to retrieve statistics and status from the SNMP agent in this device. Immediately the phrase &#8220;allows a management application to retrieve statistics&#8221; caught my attention. &#8220;How about a nice [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=61&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When surfing my ADSL modem&#8217;s web console, I came across a page on SNMP daemon, which read</p>
<blockquote><p>Simple Network Management Protocol (SNMP) allows a management application to              retrieve statistics and status from the SNMP agent in this device.</p></blockquote>
<div id="attachment_62" class="wp-caption alignnone" style="width: 554px"><a href="http://balajirrao.files.wordpress.com/2008/08/screenshot-dsl-router-mozilla-firefox.png"><img class="size-full wp-image-62" src="http://balajirrao.files.wordpress.com/2008/08/screenshot-dsl-router-mozilla-firefox.png?w=544&#038;h=519" alt="ADSL Router - SNMP Agent" width="544" height="519" /></a><p class="wp-caption-text">ADSL Router - SNMP Agent</p></div>
<p>Immediately the phrase &#8220;allows a management application to              retrieve statistics&#8221; caught my attention. &#8220;How about a nice GNOME panel applet that reports the unaccounted statistics dirrectly from the browser ?&#8221; &#8211; I thought.. Sounds exciting for sure. I decided to do it.</p>
<p>The first step is to read about SNMP. I began searching for a book, and finally got one linux administration book in my hand which seemed to have a couple of pages long description about SNMP, but I skimmed through them quickly, as I wanted a quick and dirty solution!.</p>
<p>I figured out that I need to install net-smp packages and did a yum install. I god a utility called tkmib which  is GUI for net-snmp.</p>
<p><a href="http://balajirrao.files.wordpress.com/2008/08/screenshot-tkmib.png"><img class="alignnone size-full wp-image-63" src="http://balajirrao.files.wordpress.com/2008/08/screenshot-tkmib.png?w=544&#038;h=603" alt="" width="544" height="603" /></a></p>
<p>I figured out from the list below that the interface I am interested in is No.5, as shown from .iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifDescr.5 = br0</p>
<p>I now decieded to hack up a shell script that prints the unaccounted usage accounted in the router.</p>
<pre>#!/bin/bash
out=`snmpget -v1 -c public  modem interfaces.ifTable.ifEntry.ifOutOctets.5 -Oq | cut -d " " -f 2`
in=`snmpget -v1 -c public  modem interfaces.ifTable.ifEntry.ifInOctets.5 -Oq | cut -d " " -f 2`
tot1=`expr \( $in + $out \)`
out=`snmpget -v1 -c public  modem interfaces.ifTable.ifEntry.ifOutOctets.3 -Oq | cut -d " " -f 2`
in=`snmpget -v1 -c public  modem interfaces.ifTable.ifEntry.ifInOctets.3 -Oq | cut -d " " -f 2`
tot2=`expr \( $in + $out \)`
echo -e "Ashwin : \t" $tot2 "MB"
tot=`expr $tot1 - $tot2`
echo -e "Balaji : \t" $tot "MB"
echo -e "Total : \t" $tot1 "MB"</pre>
<p>It worked very well. Now, how about writing a gnome applet to display the utilization in real time ?  Here&#8217;s how I did it.</p>
<pre class="brush: python;">
#!/usr/bin/env python

import pygtk
pygtk.require('2.0' )

import gtk
import gnomeapplet
import time
from pysnmp import role, v1, asn1
from fpformat import fix
from string import Template
import gobject

tr = role.manager(('modem', 161))

req = v1.GETREQUEST()
rsp = v1.GETRESPONSE()

msg = Template(' Ashwin = $ash Balaji = $bal' )

class ModemApplet(gnomeapplet.Applet):

lbl = None
def __init__ (self, applet, iid):
self.lbl = gtk.Label(&quot;Please Wait..&quot; )
applet.add(self.lbl)
xx = gobject.timeout_add(10000, self.update)
applet.show_all()

def update (self):
req['encoded_oids'] = [ asn1.OBJECTID().encode('1.3.6.1.2.1.2.2.1.10.5' ) ]
(rawrsp, src) = tr.send_and_receive(req.encode())
rsp.decode(rawrsp)
vals = map(lambda x: x[0](), map(asn1.decode, rsp['encoded_vals']))
ino = vals[0]

req['encoded_oids'] = [ asn1.OBJECTID().encode('1.3.6.1.2.1.2.2.1.16.5 ' ) ]
(rawrsp, src) = tr.send_and_receive(req.encode())
rsp.decode(rawrsp)
vals = map(lambda x: x[0](), map(asn1.decode, rsp['encoded_vals ']))
outo = vals[0]
wan_tot = (ino + outo) / (1024.0 * 1024.0)

req['encoded_oids'] = [ asn1.OBJECTID().encode('1.3.6.1.2.1.2.2.1.10.3' ) ]
(rawrsp, src) = tr.send_and_receive(req.encode())
rsp.decode(rawrsp)
vals = map(lambda x: x[0](), map(asn1.decode, rsp['encoded_vals']))
ino = vals[0]
req['encoded_oids'] = [ asn1.OBJECTID().encode('1.3.6.1.2.1.2.2.1.16.3' ) ]
(rawrsp, src) = tr.send_and_receive(req.encode())
rsp.decode(rawrsp)
vals = map(lambda x: x[0](), map(asn1.decode, rsp['encoded_vals' ]))

outo = vals[0]
wlan_tot = (ino + outo) / (1024.0 * 1024.0)
self.lbl.set_label(msg.substitute(ash = str(fix(wlan_tot, 3)), bal = str(fix(wan_tot - wlan_tot, 3))))
return True

def modem_factory(applet, iid):
ModemApplet(applet, iid);
return gtk.TRUE

gobject.type_register(ModemApplet)

if __name__ == '__main__':
gnomeapplet.bonobo_factory(&quot;OAFIID:GNOME_ModemSNMP_Factory&quot;, ModemApplet.__gtype__, &quot;modem&quot;, &quot;1&quot;, modem_factory)
</pre>
<p>Its now a applet at the top. Doesn&#8217;t it look cool ? <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<a href="http://balajirrao.files.wordpress.com/2008/08/snap1.jpeg"><img class="alignnone size-full wp-image-75" src="http://balajirrao.files.wordpress.com/2008/08/snap1.jpeg?w=544&#038;h=77" alt="" width="544" height="77" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/balajirrao.wordpress.com/61/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/balajirrao.wordpress.com/61/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/balajirrao.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/balajirrao.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/balajirrao.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/balajirrao.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/balajirrao.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/balajirrao.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/balajirrao.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/balajirrao.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/balajirrao.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/balajirrao.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/balajirrao.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/balajirrao.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/balajirrao.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/balajirrao.wordpress.com/61/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=balajirrao.wordpress.com&amp;blog=3108137&amp;post=61&amp;subd=balajirrao&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://balajirrao.wordpress.com/2008/08/16/snmp-fun/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7e6c0aafc452a933d1dee3a040b05744?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">balajirrao</media:title>
		</media:content>

		<media:content url="http://balajirrao.files.wordpress.com/2008/08/screenshot-dsl-router-mozilla-firefox.png" medium="image">
			<media:title type="html">ADSL Router - SNMP Agent</media:title>
		</media:content>

		<media:content url="http://balajirrao.files.wordpress.com/2008/08/screenshot-tkmib.png" medium="image" />

		<media:content url="http://balajirrao.files.wordpress.com/2008/08/snap1.jpeg" medium="image" />
	</item>
	</channel>
</rss>
