<?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:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Muharem Hrnjadovic</title>
	<atom:link href="http://muharem.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://muharem.wordpress.com</link>
	<description>Cool ideas revolving around computers and programming</description>
	<lastBuildDate>Mon, 17 Aug 2009 16:22:44 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='muharem.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/f16fa0f2317b3f05b1957dc6ed3e58d4?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Muharem Hrnjadovic</title>
		<link>http://muharem.wordpress.com</link>
	</image>
			<item>
		<title>Handy bash function for merge conflicts</title>
		<link>http://muharem.wordpress.com/2009/06/26/handy-bash-function-for-merge-conflicts/</link>
		<comments>http://muharem.wordpress.com/2009/06/26/handy-bash-function-for-merge-conflicts/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 11:16:11 +0000</pubDate>
		<dc:creator>muharem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[colordiff]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[diff]]></category>
		<category><![CDATA[merge conflict]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[xclip]]></category>

		<guid isPermaLink="false">http://muharem.wordpress.com/?p=73</guid>
		<description><![CDATA[I have been merging packages from debian unstable to ubuntu karmic lately and every so often I need to look at a merge conflict.
Sometimes it&#8217;s not so obvious why a conflict occurred at all. Here&#8217;s an example conflict from the libsepol package: 

  1 &#60;&#60;&#60;&#60;&#60;&#60;&#60; libsepol-2.0.32-1ubuntu1 (ubuntu)
  3     /* [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=73&subd=muharem&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have been merging packages from <a href="http://www.debian.org/releases/unstable/">debian unstable</a> to <a href="https://merges.ubuntu.com/main.html">ubuntu karmic</a> lately and every so often I need to look at a merge conflict.</p>
<p>Sometimes it&#8217;s not so obvious why a conflict occurred at all. Here&#8217;s an example conflict from the <a href="https://merges.ubuntu.com/libs/libsepol/REPORT">libsepol</a> package: </p>
<pre>
 <span style="color:#7f7f7f;"> 1 </span>&lt;&lt;&lt;&lt;&lt;&lt;&lt; libsepol-2.0.32-1ubuntu1 (ubuntu)
 <span style="color:#7f7f7f;"> 3 </span>    /* Get the scope info for this boolean to see if this is the declaration,
 <span style="color:#7f7f7f;"> 4 </span>     * if so set the state */
 <span style="color:#7f7f7f;"> 5 </span>    scope = hashtab_search(state-&gt;cur-&gt;policy-&gt;p_bools_scope.table, id);
 <span style="color:#7f7f7f;"> 6 </span>    if (!scope)
 <span style="color:#7f7f7f;"> 7 </span>        return SEPOL_ERR;
 <span style="color:#7f7f7f;"> 8 </span>    if (scope-&gt;scope == SCOPE_DECL)
 <span style="color:#7f7f7f;"> 9 </span>        base_bool-&gt;state = booldatum-&gt;state;
 <span style="color:#7f7f7f;">10 </span>
 <span style="color:#7f7f7f;">11 </span>=======
 <span style="color:#7f7f7f;">13 </span>    /* Get the scope info for this boolean to see if this is the declaration,
 <span style="color:#7f7f7f;">14 </span>     * if so set the state */
 <span style="color:#7f7f7f;">15 </span>    scope = hashtab_search(state-&gt;cur-&gt;policy-&gt;p_bools_scope.table, id);
 <span style="color:#7f7f7f;">16 </span>    if (!scope)
 <span style="color:#7f7f7f;">17 </span>        return SEPOL_ERR;
 <span style="color:#7f7f7f;">18 </span>    if (scope-&gt;scope == SCOPE_DECL)
 <span style="color:#7f7f7f;">19 </span>        base_bool-&gt;state = booldatum-&gt;state;
 <span style="color:#7f7f7f;">20 </span>
 <span style="color:#7f7f7f;">21 </span>&gt;&gt;&gt;&gt;&gt;&gt;&gt; libsepol-2.0.36-1 (debian)
</pre>
<p>In order to avoid staring at the screen until my eyes start to bleed <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I came up with the following bash function:</p>
<pre>
 <span style="color:#7f7f7f;"> 1 </span><span style="color:#008b8b;">function</span> <span style="color:#008b8b;">dsec() {</span>
 <span style="color:#7f7f7f;"> 2 </span>    xclip -selection clipboard -o <span style="color:#a52a2a;font-weight:bold;">&gt;</span> /tmp/patch-seg-to-diff.txt
 <span style="color:#7f7f7f;"> 3 </span>    <span style="color:#a52a2a;font-weight:bold;">rm</span> -f /tmp/ubuntu-snippet.txt /tmp/debian-snippet.txt
 <span style="color:#7f7f7f;"> 4 </span>    ed /tmp/patch-seg-to-diff.txt <span style="color:#a52a2a;font-weight:bold;">&gt;</span> /dev/null <span style="color:#008b00;">2</span><span style="color:#a52a2a;font-weight:bold;">&gt;&amp;1</span> <span style="color:#a52a2a;font-weight:bold;">&lt;&lt;-EOUBUNTU</span>
 <span style="color:#7f7f7f;"> 5 </span><span style="color:#008b00;">        1 d</span>
 <span style="color:#7f7f7f;"> 6 </span><span style="color:#008b00;">        /^===/,$ d</span>
 <span style="color:#7f7f7f;"> 7 </span><span style="color:#008b00;">        wq /tmp/ubuntu-snippet.txt</span>
 <span style="color:#7f7f7f;"> 8 </span><span style="color:#a52a2a;font-weight:bold;">EOUBUNTU</span>
 <span style="color:#7f7f7f;"> 9 </span>    ed /tmp/patch-seg-to-diff.txt <span style="color:#a52a2a;font-weight:bold;">&gt;</span> /dev/null <span style="color:#008b00;">2</span><span style="color:#a52a2a;font-weight:bold;">&gt;&amp;1</span> <span style="color:#a52a2a;font-weight:bold;">&lt;&lt;-EODEBIAN</span>
 <span style="color:#7f7f7f;">10 </span><span style="color:#008b00;">        1,/^===/d</span>
 <span style="color:#7f7f7f;">11 </span><span style="color:#008b00;">        $ d</span>
 <span style="color:#7f7f7f;">12 </span><span style="color:#008b00;">        wq /tmp/debian-snippet.txt</span>
 <span style="color:#7f7f7f;">13 </span><span style="color:#a52a2a;font-weight:bold;">EODEBIAN</span>
 <span style="color:#7f7f7f;">14 </span>    <span style="color:#a52a2a;font-weight:bold;">echo</span><span style="color:#008b00;"> </span><span style="color:#a52a2a;font-weight:bold;">&#39;</span><span style="color:#008b00;">diff -Nru /tmp/ubuntu-snippet.txt /tmp/debian-snippet.txt | colordiff | less</span><span style="color:#a52a2a;font-weight:bold;">&#39;</span>
 <span style="color:#7f7f7f;">15 </span>    diff -Nru /tmp/ubuntu-snippet.txt /tmp/debian-snippet.txt <span style="color:#a52a2a;font-weight:bold;">|</span> colordiff <span style="color:#a52a2a;font-weight:bold;">|</span> <span style="color:#a52a2a;font-weight:bold;">less</span>
 <span style="color:#7f7f7f;">16 </span><span style="color:#008b8b;">}</span>
</pre>
<p>I can now use my favourite editor to copy the conflicting code to the clipboard. When invoked on the command line the <code>dsec</code> function reads the clipboard content and chops it apart (using the <code>ed</code> utility) into a debian and an ubuntu snippet respectively. Subsequently it invokes the <code>diff</code> utility on the two snippets showing me how they differ.</p>
<pre>
 <span style="color:#7f7f7f;">1 </span><span style="color:#6a5acd;">--- /tmp/ubuntu-snippet.txt 2009-06-26 12:42:04.000000000 +0200</span>
 <span style="color:#7f7f7f;">2 </span><span style="color:#008b8b;">+++ /tmp/debian-snippet.txt 2009-06-26 12:42:04.000000000 +0200</span>
 <span style="color:#7f7f7f;">3 </span><span style="color:#a52a2a;font-weight:bold;">@@ -1,5 +1,5 @@</span>
 <span style="color:#7f7f7f;">4 </span>    /* Get the scope info for this boolean to see if this is the declaration,
 <span style="color:#7f7f7f;">5 </span><span style="color:#6a5acd;">-    * if so set the state */</span>
 <span style="color:#7f7f7f;">6 </span><span style="color:#008b8b;">+    * if so set the state */</span>
 <span style="color:#7f7f7f;">7 </span>    scope = hashtab_search(state-&gt;cur-&gt;policy-&gt;p_bools_scope.table, id);
 <span style="color:#7f7f7f;">8 </span>    if (!scope)
 <span style="color:#7f7f7f;">9 </span>        return SEPOL_ERR;
</pre>
<p>Hmm .. this looks like a white space issue. Since the <code>dsec</code> function printed the actual <code>diff</code> command to the terminal, I can copy and paste that to the command line and add the </code>-b</code> parameter so that the <a href="http://man.cx/diff(1)"><code>diff</code> utility</a> ignores changes in the amount of white space and ..</p>
<pre>
 <span style="color:#7f7f7f;">1 </span>$ <span style="font-weight:bold;">diff -Nrub /tmp/ubuntu-snippet.txt /tmp/debian-snippet.txt</span>
 <span style="color:#7f7f7f;">2 </span>$ <span style="font-weight:bold;">echo $?</span>
 <span style="color:#7f7f7f;">3 </span>0
</pre>
<p>.. voila! the diff output this time around is empty.</p>
<p>In order for this to work the utilities used must be installed, so e.g. on a ubuntu system run:</p>
<p><code>sudo apt-get install xclip colordiff</code></p>
<p>And .. don't forget to have fun <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/muharem.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/muharem.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/muharem.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/muharem.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/muharem.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/muharem.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/muharem.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/muharem.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/muharem.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/muharem.wordpress.com/73/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=73&subd=muharem&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://muharem.wordpress.com/2009/06/26/handy-bash-function-for-merge-conflicts/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8865e662a10b169a0571acf2ee737537?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">muharem</media:title>
		</media:content>
	</item>
		<item>
		<title>My new favourite book</title>
		<link>http://muharem.wordpress.com/2008/12/18/my-favourite-book/</link>
		<comments>http://muharem.wordpress.com/2008/12/18/my-favourite-book/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 10:49:22 +0000</pubDate>
		<dc:creator>muharem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[search/replace]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://muharem.wordpress.com/?p=65</guid>
		<description><![CDATA[I was attending the UDS in Mountain View last week and it proved to be one of those fascinating albeit somewhat exhausting events (please see either of these resources for UDS reports and commentary).
Anyway, while being there I managed to get my hands on a paper copy of  Real World Haskell. Being busy with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=65&subd=muharem&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I was attending the UDS in Mountain View last week and it proved to be one of those fascinating albeit somewhat exhausting events (please see <a href="http://www.google.de/search?q=uds+jaunty&amp;ie=utf-8&amp;oe=utf-8&amp;aq=t&amp;rls=com.ubuntu:en-US:unofficial">either of these resources</a> for UDS reports and commentary).</p>
<p>Anyway, while being there I managed to get my hands on a paper copy of  <a href="http://book.realworldhaskell.org/">Real World Haskell</a>. Being busy with the UDS I only started reading it on the plane back to Frankfurt. Despite being very, very tired I enjoyed it thoroughly and have to say it&#8217;s one of the best technical books I have ever perused.</p>
<p>All successful (technical) projects have a vibrant community and great documentation. This book makes <a href="http://www.haskell.org/">Haskell</a> so accessible, it may well be the last bit that&#8217;s needed for a great break-through for Haskell and functional programming in general!</p>
<p>Whether you are interested in functional programming or merely seeking to broaden your horizon, don&#8217;t delay, go out and grab a copy of this book. You won&#8217;t be disappointed.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/muharem.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/muharem.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/muharem.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/muharem.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/muharem.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/muharem.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/muharem.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/muharem.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/muharem.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/muharem.wordpress.com/65/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=65&subd=muharem&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://muharem.wordpress.com/2008/12/18/my-favourite-book/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8865e662a10b169a0571acf2ee737537?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">muharem</media:title>
		</media:content>
	</item>
		<item>
		<title>This *is* much better indeed :)</title>
		<link>http://muharem.wordpress.com/2008/12/04/this-is-much-better-indeed/</link>
		<comments>http://muharem.wordpress.com/2008/12/04/this-is-much-better-indeed/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 13:34:12 +0000</pubDate>
		<dc:creator>muharem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[PEP 3132]]></category>
		<category><![CDATA[python3]]></category>

		<guid isPermaLink="false">http://muharem.wordpress.com/?p=55</guid>
		<description><![CDATA[My moaning about Python(2) was apparently &#8220;snow of yesterday&#8221;. Python3 just came out featuring extended iterable unpacking.

  1 Python 3.0rc1+ (py3k, Oct 28 2008, 09:22:29)
  2 [GCC 4.3.2] on linux2
  3 Type &#34;help&#34;, &#34;copyright&#34;, &#34;credits&#34; or &#34;license&#34; for more information.
  4  &#62;&#62;&#62; def f(a, b, c):
  5  ... [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=55&subd=muharem&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>My <a href="http://muharem.wordpress.com/2008/12/04/why-is-consistency-so-difficult-to-achieve/">moaning about Python(2)</a> was apparently &#8220;snow of yesterday&#8221;. <a href="http://docs.python.org/dev/3.0/whatsnew/3.0.html">Python3 just came out</a> featuring <a href="http://www.python.org/dev/peps/pep-3132/">extended iterable unpacking</a>.</p>
<pre>
 <span style="color:#7f7f7f;"> 1 </span>Python 3.0rc1+ (py3k, Oct 28 2008, 09:22:29)
 <span style="color:#7f7f7f;"> 2 </span>[GCC 4.3.2] on linux2
 <span style="color:#7f7f7f;"> 3 </span>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
 <span style="color:#7f7f7f;"> 4 </span> &gt;&gt;&gt; <span style="font-weight:bold;">def f(a, b, c):</span>
 <span style="color:#7f7f7f;"> 5 </span> ... <span style="font-weight:bold;">  print(&#39;%s, %s, %s&#39; % (a, b, c))</span>
 <span style="color:#7f7f7f;"> 6 </span>...
 <span style="color:#7f7f7f;"> 7 </span> &gt;&gt;&gt; <span style="font-weight:bold;">f(1,2,3)</span>
 <span style="color:#7f7f7f;"> 8 </span>1, 2, 3
 <span style="color:#7f7f7f;"> 9 </span> &gt;&gt;&gt; <span style="font-weight:bold;">f(1,*(2,3))</span>
 <span style="color:#7f7f7f;">10 </span>1, 2, 3
 <span style="color:#7f7f7f;">11 </span> &gt;&gt;&gt; <span style="font-weight:bold;">f(*(1,2),3)</span>
 <span style="color:#7f7f7f;">12 </span>  File &quot;&lt;stdin&gt;&quot;, line 1
 <span style="color:#7f7f7f;">13 </span>SyntaxError: only named arguments may follow *expression
 <span style="color:#7f7f7f;">14 </span> &gt;&gt;&gt; <span style="font-weight:bold;">f(*(1,2),c=3)</span>
 <span style="color:#7f7f7f;">15 </span>1, 2, 3
</pre>
<p>Hmm, not ideal but it does the job <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/muharem.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/muharem.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/muharem.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/muharem.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/muharem.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/muharem.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/muharem.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/muharem.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/muharem.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/muharem.wordpress.com/55/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=55&subd=muharem&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://muharem.wordpress.com/2008/12/04/this-is-much-better-indeed/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8865e662a10b169a0571acf2ee737537?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">muharem</media:title>
		</media:content>
	</item>
		<item>
		<title>Why is consistency so difficult to achieve?</title>
		<link>http://muharem.wordpress.com/2008/12/04/why-is-consistency-so-difficult-to-achieve/</link>
		<comments>http://muharem.wordpress.com/2008/12/04/why-is-consistency-so-difficult-to-achieve/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 10:24:40 +0000</pubDate>
		<dc:creator>muharem</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[consistency]]></category>

		<guid isPermaLink="false">http://muharem.wordpress.com/?p=49</guid>
		<description><![CDATA[
  1 Python 2.5.2 (r252:60911, Oct  5 2008, 19:29:17)
  2 [GCC 4.3.2] on linux2
  3 Type &#34;help&#34;, &#34;copyright&#34;, &#34;credits&#34; or &#34;license&#34; for more information.
  4 
  5  &#62;&#62;&#62; def f(*args):
  6  ...   print &#39; &#39;.join([str(a) for a in args])
  7 ...
  8 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=49&subd=muharem&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><pre>
 <span style="color:#7f7f7f;"> 1 </span>Python 2.5.2 (r252:60911, Oct  5 2008, 19:29:17)
 <span style="color:#7f7f7f;"> 2 </span>[GCC 4.3.2] on linux2
 <span style="color:#7f7f7f;"> 3 </span>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
 <span style="color:#7f7f7f;"> 4 </span>
 <span style="color:#7f7f7f;"> 5 </span> &gt;&gt;&gt; <span style="font-weight:bold;">def f(*args):</span>
 <span style="color:#7f7f7f;"> 6 </span> ... <span style="font-weight:bold;">  print &#39; &#39;.join([str(a) for a in args])</span>
 <span style="color:#7f7f7f;"> 7 </span>...
 <span style="color:#7f7f7f;"> 8 </span> &gt;&gt;&gt; <span style="font-weight:bold;">f(1,2,3)</span>
 <span style="color:#7f7f7f;"> 9 </span>1 2 3
 <span style="color:#7f7f7f;">10 </span> &gt;&gt;&gt; <span style="font-weight:bold;">f(1,*(2,3))</span>
 <span style="color:#7f7f7f;">11 </span>1 2 3
 <span style="color:#7f7f7f;">12 </span> &gt;&gt;&gt; <span style="font-weight:bold;">f(*(1,2),3)</span>
 <span style="color:#7f7f7f;">13 </span>  File &quot;&lt;stdin&gt;&quot;, line 1
 <span style="color:#7f7f7f;">14 </span>    f(*(1,2),3)
 <span style="color:#7f7f7f;">15 </span>             ^
 <span style="color:#7f7f7f;">16 </span>SyntaxError: invalid syntax
</pre>
<p>Sigh.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/muharem.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/muharem.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/muharem.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/muharem.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/muharem.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/muharem.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/muharem.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/muharem.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/muharem.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/muharem.wordpress.com/49/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=49&subd=muharem&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://muharem.wordpress.com/2008/12/04/why-is-consistency-so-difficult-to-achieve/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8865e662a10b169a0571acf2ee737537?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">muharem</media:title>
		</media:content>
	</item>
		<item>
		<title>Minor scriptutil enhancements</title>
		<link>http://muharem.wordpress.com/2008/06/16/47/</link>
		<comments>http://muharem.wordpress.com/2008/06/16/47/#comments</comments>
		<pubDate>Mon, 16 Jun 2008 10:03:06 +0000</pubDate>
		<dc:creator>muharem</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[scriptutil]]></category>
		<category><![CDATA[search/replace]]></category>

		<guid isPermaLink="false">http://muharem.wordpress.com/?p=47</guid>
		<description><![CDATA[I have cleaned up the documentation for the scriptutil module which is available on the web now. If you happen to run ubuntu you can also install it as a package straight from my PPA.
Please have a look at this tutorial in case you&#8217;re interested in scriptutil usage examples.
Enjoy!
       [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=47&subd=muharem&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have cleaned up the documentation for the scriptutil module which is <a href="http://hrnjad.net/src/scriptutil/scriptutil-module.html">available on the web now</a>. If you happen to run <a href="http://www.ubuntu.com">ubuntu</a> you can also install it as a package straight from <a href="https://edge.launchpad.net/~al-maisan/+archive">my PPA</a>.</p>
<p>Please have a look at <a href="http://muharem.wordpress.com/2007/05/20/python-find-files-using-unix-shell-style-wildcards/">this tutorial</a> in case you&#8217;re interested in scriptutil usage examples.</p>
<p>Enjoy!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/muharem.wordpress.com/47/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/muharem.wordpress.com/47/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/muharem.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/muharem.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/muharem.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/muharem.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/muharem.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/muharem.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/muharem.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/muharem.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/muharem.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/muharem.wordpress.com/47/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=47&subd=muharem&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://muharem.wordpress.com/2008/06/16/47/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8865e662a10b169a0571acf2ee737537?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">muharem</media:title>
		</media:content>
	</item>
		<item>
		<title>Wrap-up: mergesort in haskell</title>
		<link>http://muharem.wordpress.com/2008/06/10/wrap-up-mergesort-in-haskell/</link>
		<comments>http://muharem.wordpress.com/2008/06/10/wrap-up-mergesort-in-haskell/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 18:42:30 +0000</pubDate>
		<dc:creator>muharem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[mergesort]]></category>

		<guid isPermaLink="false">http://muharem.wordpress.com/?p=45</guid>
		<description><![CDATA[I have to admit that I didn’t fully understand the apfelmus example code. Nevertheless, I made an effort to address both of his criticisms:

The merge() function does not use an accumulator argument any more and is indeed much simpler now.
The recursive mergesort_ function now does not use the haskell list length operator any more. Instead, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=45&subd=muharem&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have to admit that I didn’t fully understand the <a href="http://article.gmane.org/gmane.comp.lang.haskell.general/15010">apfelmus example code</a>. Nevertheless, I made an effort to address both of <a href="http://muharem.wordpress.com/2008/06/05/finger-exercises-in-haskell/#comment-5117">his criticisms</a>:</p>
<ol>
<li>The merge() function does not use an accumulator argument any more and is indeed much simpler now.</li>
<li>The recursive <code>mergesort_</code> function now does not use the haskell list <code>length</code> operator any more. Instead, the length of the list to be sorted is passed down the recursive chain.</li>
</ol>
<p>Please see the <a href="http://hrnjad.net/src/s/optimized-mergesort.hs.html">optimised mergesort implementation</a> for details.</p>
<p>These improvements reduced the RAM utilisation and improved the run-time performance by another 20% respectively.</p>
<p>Nothing to scoff at, eh?</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/muharem.wordpress.com/45/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/muharem.wordpress.com/45/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/muharem.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/muharem.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/muharem.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/muharem.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/muharem.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/muharem.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/muharem.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/muharem.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/muharem.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/muharem.wordpress.com/45/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=45&subd=muharem&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://muharem.wordpress.com/2008/06/10/wrap-up-mergesort-in-haskell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8865e662a10b169a0571acf2ee737537?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">muharem</media:title>
		</media:content>
	</item>
		<item>
		<title>Haskell byte strings to the rescue!</title>
		<link>http://muharem.wordpress.com/2008/06/06/haskell-byte-strings-to-the-rescue/</link>
		<comments>http://muharem.wordpress.com/2008/06/06/haskell-byte-strings-to-the-rescue/#comments</comments>
		<pubDate>Fri, 06 Jun 2008 08:17:49 +0000</pubDate>
		<dc:creator>muharem</dc:creator>
				<category><![CDATA[functional programming]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[mergesort]]></category>

		<guid isPermaLink="false">http://muharem.wordpress.com/?p=44</guid>
		<description><![CDATA[After my (naive) mergesort implementation from yesterday used around 730 MB of RAM to sort a (26 MB) file containing approx. 400,000 strings I consulted the good folks on the #haskell IRC channel.
Their advice was to use byte strings as opposed to normal strings since the former perform much better.
I tried that and observed that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=44&subd=muharem&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>After my (naive) mergesort <a href="http://muharem.wordpress.com/2008/06/05/finger-exercises-in-haskell/">implementation from yesterday</a> used around 730 MB of RAM to sort a (26 MB) file containing approx. 400,000 strings I consulted the good folks on the <code>#haskell</code> IRC channel.</p>
<p>Their advice was to use <a href="http://www.haskell.org/ghc/docs/latest/html/libraries/bytestring/Data-ByteString.html">byte strings</a> as opposed to normal strings since the former perform much better.</p>
<p>I tried that and observed that the RAM utilisation and run-time went down by approximately 85% !</p>
<p>The reduced RAM utilisation was attributed to the more efficient byte strings and the improved run-time performance to the reduced garbage collection overhead respectively.</p>
<p>The <a href="http://hrnjad.net/src/s/bytestring.diff.html">difference</a> between the source files (<a href="http://hrnjad.net/src/s/byte-mergesort.hs.html">mergesort.hs</a>, <a href="http://hrnjad.net/src/s/byte-Scaffolding.hs.html">Scaffolding.hs</a>) is minimal and switching over to byte strings was facilitated by the fact that they expose the same interface as normal strings.</p>
<p>Nice!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/muharem.wordpress.com/44/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/muharem.wordpress.com/44/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/muharem.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/muharem.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/muharem.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/muharem.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/muharem.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/muharem.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/muharem.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/muharem.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/muharem.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/muharem.wordpress.com/44/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=44&subd=muharem&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://muharem.wordpress.com/2008/06/06/haskell-byte-strings-to-the-rescue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8865e662a10b169a0571acf2ee737537?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">muharem</media:title>
		</media:content>
	</item>
		<item>
		<title>Finger exercises in haskell</title>
		<link>http://muharem.wordpress.com/2008/06/05/finger-exercises-in-haskell/</link>
		<comments>http://muharem.wordpress.com/2008/06/05/finger-exercises-in-haskell/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 07:49:30 +0000</pubDate>
		<dc:creator>muharem</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[mergesort]]></category>

		<guid isPermaLink="false">http://muharem.wordpress.com/?p=43</guid>
		<description><![CDATA[I have been reading about haskell for a while now and felt that it&#8217;s time to &#8220;get my hands dirty&#8221; by (re-)implementing some of the well known algorithms in computer science. For my first exercise I chose merge sort.
The resulting code (sans command line parameter handling, auxiliary I/O functions etc.) is quite neat and was [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=43&subd=muharem&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have been reading about <a href="http://www.haskell.org/">haskell</a> for a while now and felt that it&#8217;s time to &#8220;get my hands dirty&#8221; by (re-)implementing some of the well known algorithms in computer science. For my first exercise I chose <a href="http://en.wikipedia.org/wiki/Merge_sort">merge sort</a>.</p>
<p>The <a href="http://hrnjad.net/src/s/mergesort.hs.html">resulting code</a> (sans command line parameter handling, <a href="http://hrnjad.net/src/s/Scaffolding.hs.html">auxiliary I/O functions</a> etc.) is quite neat and was written in little time. Haskell is very expressive and its attractiveness immediately obvious when formulating pseudo-mathematical problem solutions.</p>
<pre> <span style="color:#7f7f7f;"> 1 </span><span>module</span> Main(main) <span>where</span>
 <span style="color:#7f7f7f;"> 2 </span>
 <span style="color:#7f7f7f;"> 3 </span><span style="color:#cd00cd;">import</span> <span style="color:#cd00cd;">qualified</span> IO
 <span style="color:#7f7f7f;"> 4 </span><span style="color:#cd00cd;">import</span> System(getArgs)
 <span style="color:#7f7f7f;"> 5 </span><span style="color:#cd00cd;">import</span> Monad(mapM_)
 <span style="color:#7f7f7f;"> 6 </span><span style="color:#cd00cd;">import</span> <span style="color:#cd00cd;">qualified</span> Scaffolding
 <span style="color:#7f7f7f;"> 7 </span>
 <span style="color:#7f7f7f;"> 8 </span>mergesort l <span style="font-weight:bold;color:#00008b;">=</span>
 <span style="color:#7f7f7f;"> 9 </span>    <span style="font-weight:bold;color:#00008b;">if</span> (length l) <span style="font-weight:bold;color:#00008b;">&lt;=</span> <span style="color:#008b00;">1</span> <span style="font-weight:bold;color:#00008b;">then</span> l <span style="color:#7f7f7f;">-- The list is already sorted.</span>
 <span style="color:#7f7f7f;">10 </span>    <span style="font-weight:bold;color:#00008b;">else</span> <span style="color:#7f7f7f;">-- Split the list into two halves and sort these.</span>
 <span style="color:#7f7f7f;">11 </span>        merge (mergesort lpart) (mergesort rpart) []
 <span style="color:#7f7f7f;">12 </span>        <span>where</span> llen_half <span style="font-weight:bold;color:#00008b;">=</span> (length l) <span style="font-weight:bold;color:#00008b;">`div`</span> <span style="color:#008b00;">2</span>
 <span style="color:#7f7f7f;">13 </span>              (lpart, rpart) <span style="font-weight:bold;color:#00008b;">=</span> splitAt llen_half l
 <span style="color:#7f7f7f;">14 </span>
 <span style="color:#7f7f7f;">15 </span><span style="color:#7f7f7f;">-- Case #1: the right list is empty; just append the left list to the</span>
 <span style="color:#7f7f7f;">16 </span><span style="color:#7f7f7f;">-- accumulator. The latter is reversed because we were prepending</span>
 <span style="color:#7f7f7f;">17 </span><span style="color:#7f7f7f;">-- to it in case #3.</span>
 <span style="color:#7f7f7f;">18 </span>merge lpart [] acc <span style="font-weight:bold;color:#00008b;">=</span> (reverse acc) <span style="font-weight:bold;color:#00008b;">++</span> lpart
 <span style="color:#7f7f7f;">19 </span>
 <span style="color:#7f7f7f;">20 </span><span style="color:#7f7f7f;">-- Case #2: the left list is empty; just append the right list to the</span>
 <span style="color:#7f7f7f;">21 </span><span style="color:#7f7f7f;">-- (reversed) accumulator list.</span>
 <span style="color:#7f7f7f;">22 </span>merge [] rpart acc <span style="font-weight:bold;color:#00008b;">=</span> (reverse acc) <span style="font-weight:bold;color:#00008b;">++</span> rpart
 <span style="color:#7f7f7f;">23 </span>
 <span style="color:#7f7f7f;">24 </span><span style="color:#7f7f7f;">-- Case #3: neither of the left/right lists to be merged is empty;</span>
 <span style="color:#7f7f7f;">25 </span><span style="color:#7f7f7f;">-- prepend the lesser head element to the accumulator list.</span>
 <span style="color:#7f7f7f;">26 </span>merge (l<span style="font-weight:bold;color:#00008b;">:</span>ls) (r<span style="font-weight:bold;color:#00008b;">:</span>rs) acc <span style="font-weight:bold;color:#00008b;">=</span>
 <span style="color:#7f7f7f;">27 </span>    <span style="font-weight:bold;color:#00008b;">if</span> l <span style="font-weight:bold;color:#00008b;">&lt;=</span> r <span style="font-weight:bold;color:#00008b;">then</span> merge ls (r<span style="font-weight:bold;color:#00008b;">:</span>rs) (l<span style="font-weight:bold;color:#00008b;">:</span>acc)
 <span style="color:#7f7f7f;">28 </span>    <span style="font-weight:bold;color:#00008b;">else</span> merge (l<span style="font-weight:bold;color:#00008b;">:</span>ls) rs (r<span style="font-weight:bold;color:#00008b;">:</span>acc)
 <span style="color:#7f7f7f;">29 </span>
 <span style="color:#7f7f7f;">30 </span><span style="color:#7f7f7f;">-- The main method, handles command line arguments, input and output.</span>
 <span style="color:#7f7f7f;">31 </span>main <span style="font-weight:bold;color:#00008b;">=</span> <span style="font-weight:bold;color:#00008b;">do</span>
 <span style="color:#7f7f7f;">32 </span>    args <span style="font-weight:bold;color:#00008b;">&lt;-</span> getArgs
 <span style="color:#7f7f7f;">33 </span>    fileh <span style="font-weight:bold;color:#00008b;">&lt;-</span> <span style="font-weight:bold;color:#00008b;">case</span> head args <span style="font-weight:bold;color:#00008b;">of</span>
 <span style="color:#7f7f7f;">34 </span>                <span style="color:#7f7f7f;">-- The text to be sorted is to be read from stdin.</span>
 <span style="color:#7f7f7f;">35 </span>                <span style="color:#008b00;">"-"</span> <span style="font-weight:bold;color:#00008b;">-&gt;</span> <span style="font-weight:bold;color:#00008b;">do</span> return (Just IO.stdin)
 <span style="color:#7f7f7f;">36 </span>                <span style="color:#7f7f7f;">-- The text to be sorted is to be read from the file</span>
 <span style="color:#7f7f7f;">37 </span>                <span style="color:#7f7f7f;">-- specified.</span>
 <span style="color:#7f7f7f;">38 </span>                <span style="color:#008b00;">"-f"</span> <span style="font-weight:bold;color:#00008b;">-&gt;</span> <span style="font-weight:bold;color:#00008b;">do</span> Scaffolding.openFile (head (tail args))
 <span style="color:#7f7f7f;">39 </span>                <span style="color:#7f7f7f;">-- Just sort the command line parameters.</span>
 <span style="color:#7f7f7f;">40 </span>                _ <span style="font-weight:bold;color:#00008b;">-&gt;</span> <span style="font-weight:bold;color:#00008b;">do</span> <span style="font-weight:bold;color:#00008b;">let</span> sorted_args <span style="font-weight:bold;color:#00008b;">=</span> mergesort args
 <span style="color:#7f7f7f;">41 </span>                        IO.putStrLn (<span style="color:#008b00;">"mergesort("</span> <span style="font-weight:bold;color:#00008b;">++</span> show args <span style="font-weight:bold;color:#00008b;">++</span>
 <span style="color:#7f7f7f;">42 </span>                                     <span style="color:#008b00;">") = "</span> <span style="font-weight:bold;color:#00008b;">++</span> show sorted_args)
 <span style="color:#7f7f7f;">43 </span>                        return Nothing
 <span style="color:#7f7f7f;">44 </span>    <span style="font-weight:bold;color:#00008b;">case</span> fileh <span style="font-weight:bold;color:#00008b;">of</span>
 <span style="color:#7f7f7f;">45 </span>        <span style="color:#7f7f7f;">-- Read text from file handle, sort it and print to stdout.</span>
 <span style="color:#7f7f7f;">46 </span>        Just fileh <span style="font-weight:bold;color:#00008b;">-&gt;</span> <span style="font-weight:bold;color:#00008b;">do</span> text_to_sort <span style="font-weight:bold;color:#00008b;">&lt;-</span> Scaffolding.readLines fileh []
 <span style="color:#7f7f7f;">47 </span>                         mapM_ IO.putStrLn (mergesort text_to_sort)
 <span style="color:#7f7f7f;">48 </span>        <span style="color:#7f7f7f;">-- We failed to open the file specified (if any).</span>
 <span style="color:#7f7f7f;">49 </span>        Nothing <span style="font-weight:bold;color:#00008b;">-&gt;</span> <span style="font-weight:bold;color:#00008b;">do</span> return ()</pre>
<p>I also liked the fact that the <a href="http://www.haskell.org/ghc/docs/latest/html/libraries/">haskell standard library</a> is rich and nicely documented.</p>
<p>Just to get an idea of how my naive <code>mergesort</code> implementation performs I created a file listing all the files on my Dell D630 laptop running <a href="http://www.ubuntu.com">Hardy Heron</a> (please ignore the recursive nature of this problem <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ).</p>
<pre> <span style="color:#7f7f7f;">1 </span>u804: haskell $ <span style="font-weight:bold;">ghc --version</span>
 <span style="color:#7f7f7f;">2 </span>The Glorious Glasgow Haskell Compilation System, version 6.8.2
 <span style="color:#7f7f7f;">3 </span>u804: haskell $ <span style="font-weight:bold;">ls -l all-files.txt</span>
 <span style="color:#7f7f7f;">4 </span>-rw-r--r-- 1 mhr mhr 26245382 2008-05-31 17:18 all-files.txt
 <span style="color:#7f7f7f;">5 </span>u804: haskell $ <span style="font-weight:bold;">wc -l all-files.txt</span>
 <span style="color:#7f7f7f;">6 </span>399754 all-files.txt
 <span style="color:#7f7f7f;">7 </span>u804: haskell $ <span style="font-weight:bold;">uname -a</span>
 <span style="color:#7f7f7f;">8 </span>Linux u804 2.6.24-18-generic #1 SMP Wed May 28 20:27:26 UTC 2008 i686 GNU/Linux</pre>
<p>I then let loose the compiled haskell binary on that file (<code>all-files.txt</code>) and compared how it performed against <code>/usr/bin/sort</code>.</p>
<pre> <span style="color:#7f7f7f;"> 1 </span>u804: haskell $ <span style="font-weight:bold;">time ./mergesort -f all-files.txt &gt;/dev/null</span>
 <span style="color:#7f7f7f;"> 2 </span>
 <span style="color:#7f7f7f;"> 3 </span>real    0m12.994s
 <span style="color:#7f7f7f;"> 4 </span>user    0m12.349s
 <span style="color:#7f7f7f;"> 5 </span>sys 0m0.632s
 <span style="color:#7f7f7f;"> 6 </span>u804: haskell $ <span style="font-weight:bold;">time sort all-files.txt &gt;/dev/null</span>
 <span style="color:#7f7f7f;"> 7 </span>
 <span style="color:#7f7f7f;"> 8 </span>real    0m10.675s
 <span style="color:#7f7f7f;"> 9 </span>user    0m10.613s
 <span style="color:#7f7f7f;">10 </span>sys 0m0.052s
 <span style="color:#7f7f7f;">11 </span>u804: haskell $ <span style="font-weight:bold;">time sort all-files.txt &gt;/dev/null</span></pre>
<p>The difference in performance was moderate (22%) given that I did not tune the haskell implementation in any way.</p>
<p>However, I gasped when I observed the RAM utilisation while the haskell program  was running: it used 726 MB of RAM!</p>
<p>Compare this to 34 MB that were used by the standard <code>sort</code> program.</p>
<p>I guess it&#8217;s time to get acquainted with <a href="http://www.haskell.org/ghc/docs/latest/html/users_guide/profiling.html"><code>ghc -prof</code></a> and friends <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Last but not least I&#8217;d like to point to a great haskell resource, the <a href="http://book.realworldhaskell.org/beta/index.html">Real World Haskell</a> beta book.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/muharem.wordpress.com/43/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/muharem.wordpress.com/43/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/muharem.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/muharem.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/muharem.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/muharem.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/muharem.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/muharem.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/muharem.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/muharem.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/muharem.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/muharem.wordpress.com/43/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=43&subd=muharem&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://muharem.wordpress.com/2008/06/05/finger-exercises-in-haskell/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8865e662a10b169a0571acf2ee737537?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">muharem</media:title>
		</media:content>
	</item>
		<item>
		<title>Text filtering with erlang</title>
		<link>http://muharem.wordpress.com/2008/04/30/text-filtering-with-erlang/</link>
		<comments>http://muharem.wordpress.com/2008/04/30/text-filtering-with-erlang/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 16:34:40 +0000</pubDate>
		<dc:creator>muharem</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[search/replace]]></category>
		<category><![CDATA[functional programming]]></category>

		<guid isPermaLink="false">http://muharem.wordpress.com/?p=42</guid>
		<description><![CDATA[Introduction
After a long break I picked up the Erlang book again and my appetite for writing some erlang code was soon kindled.
A small Python component I produced at work seemed like a good candidate for my (sequential) erlang exercises. It is a fairly simple component that removes user/password data embedded in URLs.
Just so you know [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=42&subd=muharem&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h3>Introduction</h3>
<p>After a long break I picked up the <a href="http://www.pragprog.com/titles/jaerlang/programming-erlang">Erlang book</a> again and my appetite for writing some erlang code was soon kindled.</p>
<p>A small Python <a href="http://hrnjad.net/src/p/filter_url.py.html">component</a> I produced <a href="https://launchpad.net/~al-maisan">at work</a> seemed like a good candidate for my (sequential) erlang exercises. It is a fairly simple component that removes user/password data embedded in URLs.</p>
<p>Just so you know where I am coming from:</p>
<ul>
<li>my main/favourite programming language is Python</li>
<li>my exercises are mainly about <em>sequential</em>, <em>non-distributed</em> and <em>non-telecoms-related</em> problems whereas erlang&#8217;s main strength and appeal lies in the area of parallel/distributed telecoms/networking systems</li>
<li>I have played with erlang a little bit before (<a href="http://muharem.wordpress.com/2007/07/31/erlang-vs-stackless-python-a-first-benchmark/">ring benchmark</a>, <a href="http://muharem.wordpress.com/2007/08/21/processing-xml-in-erlang/">XML parsing</a>) and liked it in general although IMHO it lacks severely when it comes to the availability and quality of standard library components.</li>
</ul>
<p>Now that my particular set of preconceptions is clear and in the open, let&#8217;s look at the stuff below <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h3>File processing with erlang&#8217;s regexp module</h3>
<p>The <a href="http://hrnjad.net/src/p/regex.erl.html">initial implementation</a> of the URL filter in erlang used its <a href="http://www.erlang.org/doc/man/regexp.html">regexp library</a>.</p>
<pre> <span style="color:#7f7f7f;"> 1 </span><span>-module</span>(regex)<span style="color:#ff1493;">.</span>
 <span style="color:#7f7f7f;"> 2 </span><span>-export</span>([main<span style="font-weight:bold;color:#00008b;">/</span><span style="color:#008b00;">1</span>])<span style="color:#ff1493;">.</span>
 <span style="color:#7f7f7f;"> 3 </span>
 <span style="color:#7f7f7f;"> 4 </span>isalphanum(C) <span style="font-weight:bold;color:#00008b;">when</span> C <span style="font-weight:bold;color:#00008b;">&gt;</span> 47, C <span style="font-weight:bold;color:#00008b;">&lt;</span> 58; C <span style="font-weight:bold;color:#00008b;">&gt;</span> 64, C <span style="font-weight:bold;color:#00008b;">&lt;</span> 91; C <span style="font-weight:bold;color:#00008b;">&gt;</span> 96, C <span style="font-weight:bold;color:#00008b;">&lt;</span> 123 <span style="font-weight:bold;color:#00008b;">-&gt;</span> <span style="font-weight:bold;color:#00008b;">true</span>;
 <span style="color:#7f7f7f;"> 5 </span>isalphanum(<span style="color:#ff1493;">_</span>) <span style="font-weight:bold;color:#00008b;">-&gt;</span> <span style="font-weight:bold;color:#00008b;">false</span><span style="color:#ff1493;">.</span>
 <span style="color:#7f7f7f;"> 6 </span>
 <span style="color:#7f7f7f;"> 7 </span><span style="color:#7f7f7f;">%% Generate a temporary file name of length N</span>
 <span style="color:#7f7f7f;"> 8 </span>genname(<span style="color:#008b00;">0</span>, L) <span style="font-weight:bold;color:#00008b;">-&gt;</span> L;
 <span style="color:#7f7f7f;"> 9 </span>genname(N, L) <span style="font-weight:bold;color:#00008b;">-&gt;</span>
 <span style="color:#7f7f7f;">10 </span>    R <span style="font-weight:bold;color:#00008b;">=</span> <span style="color:#008b8b;">random</span><span style="color:#ff1493;">:</span><span style="color:#008b8b;">uniform</span>(123),
 <span style="color:#7f7f7f;">11 </span>    <span style="font-weight:bold;color:#00008b;">case</span> isalphanum(R) <span style="font-weight:bold;color:#00008b;">of</span>
 <span style="color:#7f7f7f;">12 </span>        <span style="font-weight:bold;color:#00008b;">true</span> <span style="font-weight:bold;color:#00008b;">-&gt;</span> genname(N-1, [R|L]);
 <span style="color:#7f7f7f;">13 </span>        <span style="font-weight:bold;color:#00008b;">false</span> <span style="font-weight:bold;color:#00008b;">-&gt;</span> genname(N, L)
 <span style="color:#7f7f7f;">14 </span>    <span style="font-weight:bold;color:#00008b;">end</span><span style="color:#ff1493;">.</span>
 <span style="color:#7f7f7f;">15 </span>
 <span style="color:#7f7f7f;">16 </span><span style="color:#7f7f7f;">%% Returns a randomly generated temporary file path where the basename is</span>
 <span style="color:#7f7f7f;">17 </span><span style="color:#7f7f7f;">%% of length N</span>
 <span style="color:#7f7f7f;">18 </span>mktemppath(Prefix, N) <span style="font-weight:bold;color:#00008b;">-&gt;</span> Prefix <span style="font-weight:bold;color:#00008b;">++</span> <span style="color:#008b00;">"/"</span> <span style="font-weight:bold;color:#00008b;">++</span> genname(N, [])<span style="color:#ff1493;">.</span>
 <span style="color:#7f7f7f;">19 </span>
</pre>
<p>Please note how I had to implement functionality absent from the standard library above.</p>
<pre> <span style="color:#7f7f7f;">20 </span><span style="color:#7f7f7f;">%% Removes passwords embedded in URLs from a log file.</span>
 <span style="color:#7f7f7f;">21 </span>scrub_file(Tmpdir, F) <span style="font-weight:bold;color:#00008b;">-&gt;</span>
 <span style="color:#7f7f7f;">22 </span>    <span style="color:#7f7f7f;">%% make a temporary directory if it does not exist yet.</span>
 <span style="color:#7f7f7f;">23 </span>    <span style="font-weight:bold;color:#00008b;">case</span> <span style="color:#008b8b;">file</span><span style="color:#ff1493;">:</span><span style="color:#008b8b;">make</span><span style="color:#ff1493;">_</span><span style="color:#008b8b;">dir</span>(Tmpdir) <span style="font-weight:bold;color:#00008b;">of</span>
 <span style="color:#7f7f7f;">24 </span>        ok <span style="font-weight:bold;color:#00008b;">-&gt;</span> ok;
 <span style="color:#7f7f7f;">25 </span>        {error,eexist} <span style="font-weight:bold;color:#00008b;">-&gt;</span> ok;
 <span style="color:#7f7f7f;">26 </span>        <span style="color:#ff1493;">_</span> <span style="font-weight:bold;color:#00008b;">-&gt;</span> <span style="font-weight:bold;color:#00008b;">exit</span>({error, failed_to_make_tmpdir})
 <span style="color:#7f7f7f;">27 </span>    <span style="font-weight:bold;color:#00008b;">end</span>,
 <span style="color:#7f7f7f;">28 </span>
 <span style="color:#7f7f7f;">29 </span>    <span style="color:#7f7f7f;">%% Move the original file out of the way.</span>
 <span style="color:#7f7f7f;">30 </span>    T <span style="font-weight:bold;color:#00008b;">=</span> mktemppath(Tmpdir, 16),
 <span style="color:#7f7f7f;">31 </span>    <span style="font-weight:bold;color:#00008b;">case</span> <span style="color:#008b8b;">file</span><span style="color:#ff1493;">:</span><span style="color:#008b8b;">rename</span>(F, T) <span style="font-weight:bold;color:#00008b;">of</span>
 <span style="color:#7f7f7f;">32 </span>        ok <span style="font-weight:bold;color:#00008b;">-&gt;</span> ok;
 <span style="color:#7f7f7f;">33 </span>        <span style="color:#ff1493;">_</span> <span style="font-weight:bold;color:#00008b;">-&gt;</span> <span style="font-weight:bold;color:#00008b;">exit</span>({error, failed_to_move_file})
 <span style="color:#7f7f7f;">34 </span>    <span style="font-weight:bold;color:#00008b;">end</span>,
 <span style="color:#7f7f7f;">35 </span>
 <span style="color:#7f7f7f;">36 </span>    <span style="color:#7f7f7f;">%% Now open it for reading.</span>
 <span style="color:#7f7f7f;">37 </span>    {<span style="color:#ff1493;">_</span>, In} <span style="font-weight:bold;color:#00008b;">=</span> <span style="color:#008b8b;">file</span><span style="color:#ff1493;">:</span><span style="color:#008b8b;">open</span>([T], read),
 <span style="color:#7f7f7f;">38 </span>    <span style="color:#7f7f7f;">%% Open the original path for writing.</span>
 <span style="color:#7f7f7f;">39 </span>    {<span style="color:#ff1493;">_</span>, Out} <span style="font-weight:bold;color:#00008b;">=</span> <span style="color:#008b8b;">file</span><span style="color:#ff1493;">:</span><span style="color:#008b8b;">open</span>([F], write),
 <span style="color:#7f7f7f;">40 </span>
 <span style="color:#7f7f7f;">41 </span>    <span style="color:#7f7f7f;">%% Call the function that will scrub the lines.</span>
 <span style="color:#7f7f7f;">42 </span>    scrub_lines(In, Out),
 <span style="color:#7f7f7f;">43 </span>
 <span style="color:#7f7f7f;">44 </span>    <span style="color:#7f7f7f;">%% Close the file handles and return the path to the original file.</span>
 <span style="color:#7f7f7f;">45 </span>    <span style="color:#008b8b;">file</span><span style="color:#ff1493;">:</span><span style="color:#008b8b;">close</span>(Out),
 <span style="color:#7f7f7f;">46 </span>    <span style="color:#008b8b;">file</span><span style="color:#ff1493;">:</span><span style="color:#008b8b;">close</span>(In),
 <span style="color:#7f7f7f;">47 </span>    T<span style="color:#ff1493;">.</span>
 <span style="color:#7f7f7f;">48 </span>
</pre>
<p>The code that scrubs the URLs is below, the <code>scrub_lines()</code> function is tail recursive.</p>
<pre> <span style="color:#7f7f7f;">49 </span><span style="color:#7f7f7f;">%% This is where the log file is actually read linewise and where</span>
 <span style="color:#7f7f7f;">50 </span><span style="color:#7f7f7f;">%% the scrubbing function is invoked for lines that contain URLs.</span>
 <span style="color:#7f7f7f;">51 </span>scrub_lines(In, Out) <span style="font-weight:bold;color:#00008b;">-&gt;</span>
 <span style="color:#7f7f7f;">52 </span>    L <span style="font-weight:bold;color:#00008b;">=</span> <span style="color:#008b8b;">io</span><span style="color:#ff1493;">:</span><span style="color:#008b8b;">get</span><span style="color:#ff1493;">_</span><span style="color:#008b8b;">line</span>(In, <span>''</span>),
 <span style="color:#7f7f7f;">53 </span>    <span style="font-weight:bold;color:#00008b;">case</span> L <span style="font-weight:bold;color:#00008b;">of</span>
 <span style="color:#7f7f7f;">54 </span>        eof <span style="font-weight:bold;color:#00008b;">-&gt;</span> ok;
 <span style="color:#7f7f7f;">55 </span>        <span style="color:#ff1493;">_</span> <span style="font-weight:bold;color:#00008b;">-&gt;</span>
 <span style="color:#7f7f7f;">56 </span>            <span style="color:#7f7f7f;">%% Does the line contain URLs?</span>
 <span style="color:#7f7f7f;">57 </span>            <span style="font-weight:bold;color:#00008b;">case</span> <span style="color:#008b8b;">string</span><span style="color:#ff1493;">:</span><span style="color:#008b8b;">str</span>(L, <span style="color:#008b00;">"://"</span>) <span style="font-weight:bold;color:#00008b;">of</span>
 <span style="color:#7f7f7f;">58 </span>                <span style="color:#008b00;">0</span> <span style="font-weight:bold;color:#00008b;">-&gt;</span> <span style="color:#008b8b;">io</span><span style="color:#ff1493;">:</span><span style="color:#008b8b;">format</span>(Out, <span style="color:#008b00;">"</span><span style="color:#ff1493;">~s</span><span style="color:#008b00;">"</span>, [L]);
 <span style="color:#7f7f7f;">59 </span>                <span style="color:#ff1493;">_</span> <span style="font-weight:bold;color:#00008b;">-&gt;</span>
 <span style="color:#7f7f7f;">60 </span>                    <span style="font-weight:bold;color:#00008b;">case</span> <span style="color:#008b8b;">regexp</span><span style="color:#ff1493;">:</span><span style="color:#008b8b;">gsub</span>(L, <span style="color:#008b00;">"://[^:]+:[^@]+@"</span>, <span style="color:#008b00;">"://"</span>) <span style="font-weight:bold;color:#00008b;">of</span>
 <span style="color:#7f7f7f;">61 </span>                        {ok, S, <span style="color:#ff1493;">_</span>} <span style="font-weight:bold;color:#00008b;">-&gt;</span> <span style="color:#008b8b;">io</span><span style="color:#ff1493;">:</span><span style="color:#008b8b;">format</span>(Out, <span style="color:#008b00;">"</span><span style="color:#ff1493;">~s</span><span style="color:#008b00;">"</span>, [S]);
 <span style="color:#7f7f7f;">62 </span>                        {R, S, <span style="color:#ff1493;">_</span>} <span style="font-weight:bold;color:#00008b;">-&gt;</span> <span style="color:#008b8b;">io</span><span style="color:#ff1493;">:</span><span style="color:#008b8b;">format</span>(<span style="color:#008b00;">"Failed: {</span><span style="color:#ff1493;">~p</span><span style="color:#008b00;">,</span><span style="color:#ff1493;">~p</span><span style="color:#008b00;">}"</span>, [R,S])
 <span style="color:#7f7f7f;">63 </span>                    <span style="font-weight:bold;color:#00008b;">end</span>
 <span style="color:#7f7f7f;">64 </span>            <span style="font-weight:bold;color:#00008b;">end</span>,
 <span style="color:#7f7f7f;">65 </span>            <span style="color:#7f7f7f;">%% Continue with next line.</span>
 <span style="color:#7f7f7f;">66 </span>            scrub_lines(In, Out)
 <span style="color:#7f7f7f;">67 </span>    <span style="font-weight:bold;color:#00008b;">end</span><span style="color:#ff1493;">.</span>
 <span style="color:#7f7f7f;">68 </span>
 <span style="color:#7f7f7f;">69 </span><span style="color:#7f7f7f;">%% Main function.</span>
 <span style="color:#7f7f7f;">70 </span>main([A]) <span style="font-weight:bold;color:#00008b;">-&gt;</span>
 <span style="color:#7f7f7f;">71 </span>    {A1,A2,A3} <span style="font-weight:bold;color:#00008b;">=</span> <span style="color:#008b8b;">now</span>(),
 <span style="color:#7f7f7f;">72 </span>    <span style="color:#008b8b;">random</span><span style="color:#ff1493;">:</span><span style="color:#008b8b;">seed</span>(A1, A2, A3),
 <span style="color:#7f7f7f;">73 </span>
 <span style="color:#7f7f7f;">74 </span>    <span style="color:#7f7f7f;">%% A single argument (the name of the file to be scrubbed) is expected.</span>
 <span style="color:#7f7f7f;">75 </span>    F <span style="font-weight:bold;color:#00008b;">=</span> <span style="color:#008b8b;">atom_to_list</span>(A),
 <span style="color:#7f7f7f;">76 </span>    T <span style="font-weight:bold;color:#00008b;">=</span> scrub_file(<span style="color:#008b00;">"tmp"</span>, F),
 <span style="color:#7f7f7f;">77 </span>
 <span style="color:#7f7f7f;">78 </span>    <span style="color:#7f7f7f;">%% The scrubbed file content will be written to a new file that's</span>
 <span style="color:#7f7f7f;">79 </span>    <span style="color:#7f7f7f;">%% in the place of the original file. Where was the latter moved to?</span>
 <span style="color:#7f7f7f;">80 </span>    <span style="color:#008b8b;">io</span><span style="color:#ff1493;">:</span><span style="color:#008b8b;">format</span>(<span style="color:#008b00;">"</span><span style="color:#ff1493;">~s~n</span><span style="color:#008b00;">"</span>, [T]),
 <span style="color:#7f7f7f;">81 </span>
 <span style="color:#7f7f7f;">82 </span>    <span style="color:#008b8b;">init</span><span style="color:#ff1493;">:</span><span style="color:#008b8b;">stop</span>()<span style="color:#ff1493;">.</span>
</pre>
<p>The cursory benchmarks performed (on log files of varying size) using the <a href="http://hrnjad.net/src/p/filter_url.py.html">python</a> and the <a href="http://hrnjad.net/src/p/regex.erl.html">erlang</a> code confirmed <a href="http://www.tbray.org/ongoing/When/200x/2007/09/21/Erlang">other people&#8217;s experiences with erlang&#8217;s regex performance</a> (but see also this <a href="http://www.findinglisp.com/blog/2007/10/stupid-programming-language-tricks.html">interesting &#8220;rebuttal&#8221;</a>).</p>
<table border="0" cellspacing="8">
<tbody>
<tr>
<th>Log file size</th>
<th>Python times</th>
<th>Erlang times</th>
</tr>
<tr>
<td align="right">1 MB</td>
<td align="right">0m0.230s</td>
<td align="right">0m1.896s</td>
</tr>
<tr>
<td align="right">10 MB</td>
<td align="right">0m1.510s</td>
<td align="right">0m8.766s</td>
</tr>
<tr>
<td align="right">100 MB</td>
<td align="right">0m14.793s</td>
<td align="right">1m17.662s</td>
</tr>
<tr>
<td align="right">1 GB</td>
<td align="right">2m55.012s</td>
<td align="right">13m54.588s</td>
</tr>
</tbody>
</table>
<h3>The do-it-yourself construction</h3>
<p>Curious to learn whether the performance can be improved by abstaining from regular expressions I came up with an <a href="http://hrnjad.net/src/p/noregex.erl.html">alternative implementation</a> that does not use <code>regexp</code>.</p>
<p>As you can see below the do-it-yourself construction is indeed performing slightly better at the expense of being very specialized and requiring 60% more code.</p>
<table border="0" cellspacing="8">
<tbody>
<tr>
<th>Log file size</th>
<th>Python times</th>
<th>Erlang regexp</th>
<th>Erlang do-it-yourself</th>
</tr>
<tr>
<td align="right">1 MB</td>
<td align="right">0m0.230s</td>
<td align="right">0m1.896s</td>
<td align="right">0m1.969s</td>
</tr>
<tr>
<td align="right">10 MB</td>
<td align="right">0m1.510s</td>
<td align="right">0m8.766s</td>
<td align="right">0m8.459s</td>
</tr>
<tr>
<td align="right">100 MB</td>
<td align="right">0m14.793s</td>
<td align="right">1m17.662s</td>
<td align="right">1m12.448s</td>
</tr>
<tr>
<td align="right">1 GB</td>
<td align="right">2m55.012s</td>
<td align="right">13m54.588s</td>
<td align="right">13m3.360s</td>
</tr>
</tbody>
</table>
<h3>In conclusion</h3>
<p>Every couple of months or so I develop a euphoria towards erlang which is consistently dampened by using the language to tackle problems for which the language admittedly was not designed in first place.</p>
<p>I guess most people start using a language for simple programming exercises first as opposed to building something like a <a href="http://www.ejabberd.im/">Jabber/XMPP instant messaging server</a> straightaway.</p>
<p>I hate to repeat myself but improving the standard library (by adding common functionality and making sure it performs decently) would do a lot to attract fresh talent to the erlang community and I hear that a certain rate of influx of &#8220;fresh blood&#8221; is a necessary prerequisite for success.</p>
<p>Ah, and no, you were not supposed to grok the sentence above unless you read it three times <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/muharem.wordpress.com/42/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/muharem.wordpress.com/42/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/muharem.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/muharem.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/muharem.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/muharem.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/muharem.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/muharem.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/muharem.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/muharem.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/muharem.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/muharem.wordpress.com/42/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=42&subd=muharem&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://muharem.wordpress.com/2008/04/30/text-filtering-with-erlang/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8865e662a10b169a0571acf2ee737537?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">muharem</media:title>
		</media:content>
	</item>
		<item>
		<title>My new &#8220;baby laptop&#8221;</title>
		<link>http://muharem.wordpress.com/2008/01/26/my-new-baby-laptop/</link>
		<comments>http://muharem.wordpress.com/2008/01/26/my-new-baby-laptop/#comments</comments>
		<pubDate>Sat, 26 Jan 2008 20:52:36 +0000</pubDate>
		<dc:creator>muharem</dc:creator>
				<category><![CDATA[BSD]]></category>
		<category><![CDATA[akoya]]></category>
		<category><![CDATA[hard disk encryption]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[medion]]></category>
		<category><![CDATA[subnotebook]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[vista]]></category>

		<guid isPermaLink="false">http://muharem.wordpress.com/?p=40</guid>
		<description><![CDATA[I am using a MacBook Pro for roughly 10 months now and I am generally very happy with it. Nevertheless, I like experimenting and playing with other operating systems, primarily with various linux distributions and with members of the *BSD family.
Running Ubuntu or FreeBSD in a virtual machine (using VMWare&#8217;s fusion or Parallels desktop) is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=40&subd=muharem&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I am using a MacBook Pro for roughly 10 months now and I am generally very happy with it. Nevertheless, I like experimenting and playing with other operating systems, primarily with various linux distributions and with members of the *BSD family.</p>
<p>Running <a href="http://www.ubuntu.com">Ubuntu</a> or <a href="http://www.freebsd.org">FreeBSD</a> in a virtual machine (using <a href="http://www.VMware.com/Mac">VMWare&#8217;s fusion</a> or <a href="http://www.parallels.com/en/products/desktop/">Parallels desktop</a>) is a good way to get a first impression of such a system but at some point you <i>will</i> want real hardware. I reached that point with Ubuntu when I took an interest in hard disk encryption (<a href="http://events.ccc.de/congress/2005/fahrplan/attachments/586-paper_Complete_Hard_Disk_Encryption.pdf">why you should encrypt your hard disk</a>).</p>
<p>It just so happened that around that time Aldi (a German retailer) had a <a href="http://www.medion.de/md96360/sued/flash.html">nice 12 inch subnotebook on offer</a>. Aldi was targeting the female clientele (the notebook was even adorned with <a href="http://en.wikipedia.org/wiki/Rhinestone">rhinestones</a> etc.) which resulted in a 100 Euro price markup. The system was still a very good value for the money, however, and I even managed to get my hands on the black model <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>I booted the system up (it had Windows Vista Home Premium pre-installed)  in order to take a backup of the system in case I had to restore the original state (prior to sending in it for service for example).</p>
<p>Vista was atrocious, totally crippling the poor thing. I mean, it was horrible, even the simplest interactions or commands took a ridiculous amount of time to complete.<br />
Anyway, I managed to take a snapshot of the hard disk, wiped it clean and installed Ubuntu-7.10.</p>
<p>After running Vista on the box for a few hours, Ubuntu was a relief <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  it felt very snappy and was generally performing very well. I could do all my development work on the notebook without any problems.</p>
<p>I thought that was very cool <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  I finally had a second box, a &#8220;baby laptop&#8221;, I could use for my experiments. Having two laptops may sound a little bit excessive unless you tamper frequently with all sorts of operating systems. You can keep one machine in a &#8220;stable&#8221; condition and do all the proper (money generating) work on it while totally rebuilding the other.</p>
<p>I am a slightly paranoid person <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  and like to have as much security on my machines as I can get. I hence wanted to install Ubuntu with full hard disk encryption but more on that topic in a forthcoming article..</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/muharem.wordpress.com/40/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/muharem.wordpress.com/40/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/muharem.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/muharem.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/muharem.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/muharem.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/muharem.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/muharem.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/muharem.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/muharem.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/muharem.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/muharem.wordpress.com/40/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=muharem.wordpress.com&blog=484506&post=40&subd=muharem&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://muharem.wordpress.com/2008/01/26/my-new-baby-laptop/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8865e662a10b169a0571acf2ee737537?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">muharem</media:title>
		</media:content>
	</item>
	</channel>
</rss>