<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kamibu</title>
	<atom:link href="http://blog.kamibu.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.kamibu.com</link>
	<description></description>
	<lastBuildDate>Sat, 14 Nov 2009 10:51:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Gentoo Portage: libxcb and broken libraries</title>
		<link>http://blog.kamibu.com/2009/11/14/gentoo-portage-libxcb-and-broken-libraries/</link>
		<comments>http://blog.kamibu.com/2009/11/14/gentoo-portage-libxcb-and-broken-libraries/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 10:46:01 +0000</pubDate>
		<dc:creator>abresas</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.kamibu.com/?p=103</guid>
		<description><![CDATA[When using the Gentoο distribution, updating all your installed packages should be as easy as:
# emerge -avDuN world
But, when I tried it yesterday, It wouldn&#8217;t work: It could not emerge media-libs/xine-lib.
I tried running revdep-rebuild to find any broken libraries and it found a lot of them, all missing files from libxcb. I tried to emerge [...]]]></description>
			<content:encoded><![CDATA[<p>When using the Gentoο distribution, updating all your installed packages should be as easy as:<br />
# emerge -avDuN world</p>
<p>But, when I tried it yesterday, It wouldn&#8217;t work: It could not emerge media-libs/xine-lib.</p>
<p>I tried running revdep-rebuild to find any broken libraries and it found a lot of them, all missing files from libxcb. I tried to emerge it, but I realized it was part of the packages &#8220;emerge world&#8221; had already emerged.</p>
<p>After doing some googling, I found <a href="http://www.gentoo.org/proj/en/desktop/x/x11/libxcb-1.4-upgrade-guide.xml">Gentoo libxcb 1.4 Upgrade Guide</a>. It says you have to manually run a bash script, then revdep-rebuild and finally remove an outdated shared library file.</p>
<p>So, be careful when you upgrade libxcb, world or any package that depends on libxcb (I think the new Xorg >= 1.6 is one of them).</p>
<p>However, when things like this happen, I always wonder: Why do I have to read upgrade guides and run things manually? Isn&#8217;t emerge supposed to do this for me? I&#8217;m sure there is some kind of explanation, but isn&#8217;t there some way to get around this? Maybe an option on emerge?</p>
<p>Even the annoying &#8220;eselect news&#8221; doesn&#8217;t inform you about this important guide. Instead, it keeps popping up every time it finds an article that you will surely not be interested to read (an exception was the new article about KDE 3.5 and the sunset overlay).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kamibu.com/2009/11/14/gentoo-portage-libxcb-and-broken-libraries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bring functional programming to IEEExtreme!</title>
		<link>http://blog.kamibu.com/2009/09/01/bring-functional-programming-to-ieeextreme/</link>
		<comments>http://blog.kamibu.com/2009/09/01/bring-functional-programming-to-ieeextreme/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 10:29:08 +0000</pubDate>
		<dc:creator>abresas</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.kamibu.com/?p=84</guid>
		<description><![CDATA[IEEExtreme 2009 competition registration opens today, 1st of September.
This competition seems very interesting, and some kamibu members are thinking about participating!
Languages supported are: Microsoft Visual C++/C#, C/C++, C# and some &#8220;surprises&#8221;.
I would really like to see some functional programming language getting on to that list, like Common Lisp, Haskell or my favourite: Scheme!
Functional programming may [...]]]></description>
			<content:encoded><![CDATA[<p>IEEExtreme 2009 competition registration <a href="http://www.ieee.org/web/membership/students/xtreme/logistics.html">opens today</a>, 1st of September.</p>
<p>This competition seems very interesting, and some kamibu members are thinking about participating!</p>
<blockquote><p>Languages supported are: Microsoft Visual C++/C#, C/C++, C# and some &#8220;surprises&#8221;.</p></blockquote>
<p>I would really like to see some functional programming language getting on to that list, like Common Lisp, Haskell or my favourite: Scheme!</p>
<p>Functional programming may be very handy some times, and a lot of fun!</p>
<p>For example, I tried solving last year&#8217;s &#8220;Merging IP&#8217;s&#8221; problem (see <a href="http://www.ieee.org/portal/cms_docs_iportals/iportals/membership/students/scholarshipsawardscontests/IEEEXtreme2008_Competition_Booklet.pdf">IEEEXtreme 2008 Competition booklet</a>, pdf) using Scheme.</p>
<p>The goal is to merge a list of IP intervals (e.g. 192.168.1.1 &#8211; 192.168.1.60), so that you only keep a list of the minimum required intervals.</p>
<p>Example Input:<br />
3.0.0.0 &#8211; 3.100.0.0<br />
3.99.0.0 &#8211; 3.255.0.0<br />
10.1.0.0 &#8211; 10.200.0.0<br />
10.2.0.1 &#8211; 10.5.99.99<br />
10.200.0.1 &#8211; 10.225.225.0</p>
<p>Example Output:<br />
3.0.0.0 &#8211; 3.255.0.0<br />
10.1.0.0 &#8211; 10.225.225.0</p>
<p>Let&#8217;s build the main loop for the program (without input and output functions).</p>
<p>Suppose we have 2 functions ready: (should-merge int1  int2) that is true only if intervals int1 and int2 should be merged (one of them starts in the middle of the other and ends after it), and (precedes int1 int2) only if both addresses of interval1 &#8220;precede&#8221; interval2 (e.g. 5.0.0.0 &#8211; 6.0.0.0 precedes 6.0.0.5-7.0.0.0).</p>
<p>Now, we can write a function (merge-intervals intervals merged) that will recursively merge all intervals. Intervals parameter should be a list of intervals that have to be merged, sorted by their first address.<br />
Merged should be a list of intervals that are always totally merged. In the beginning it should be an empty list, and in the end the solution of the problem.</p>
<p><pre class="php"><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/define"><span style="color: #000066;">define</span></a> <span style="color: #66cc66;">&#40;</span>merge-intervals intervals merged<span style="color: #66cc66;">&#41;</span>
  ; important! intervals must be sorted
  <span style="color: #66cc66;">&#40;</span>cond <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span>? intervals<span style="color: #66cc66;">&#41;</span> merged<span style="color: #66cc66;">&#41;</span> ; all intervals are merged. <span style="color: #b1b100;">return</span> merged <a href="http://www.php.net/list"><span style="color: #000066;">list</span></a>
          <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span>? merged<span style="color: #66cc66;">&#41;</span>
            ; just started, merged is <a href="http://www.php.net/empty"><span style="color: #000066;">empty</span></a>
            ; remove first of intervals and add it to the merged <a href="http://www.php.net/list"><span style="color: #000066;">list</span></a>
            merge-intervals <span style="color: #66cc66;">&#40;</span>cdr intervals<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/list"><span style="color: #000066;">list</span></a> <span style="color: #66cc66;">&#40;</span>car intervals<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
          <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>should-merge <span style="color: #66cc66;">&#40;</span>car intervals<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>car merged<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> 
            ; the two intervals should be merged
            <span style="color: #66cc66;">&#40;</span>merge-intervals <span style="color: #66cc66;">&#40;</span>cdr intervals<span style="color: #66cc66;">&#41;</span> 
              <span style="color: #66cc66;">&#40;</span>cons 
                <span style="color: #66cc66;">&#40;</span>merge <span style="color: #66cc66;">&#40;</span>car intervals<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>car merged<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> 
                <span style="color: #66cc66;">&#40;</span>cdr merged<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
          <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>precedes <span style="color: #66cc66;">&#40;</span>car merged<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>car intervals<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
            ; add the first of intervals to the top of merged
            <span style="color: #66cc66;">&#40;</span>merge-intervals <span style="color: #66cc66;">&#40;</span>cdr intervals<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>cons <span style="color: #66cc66;">&#40;</span>car intervals<span style="color: #66cc66;">&#41;</span> merged<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
          <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">else</span>
            ; the first of intervals starts after the last merged
            ; and ends before the last merged ends
            ; ignore it
            <span style="color: #66cc66;">&#40;</span>merge-intervals <span style="color: #66cc66;">&#40;</span>cdr intervals<span style="color: #66cc66;">&#41;</span> merged<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
; We also used the merge <span style="color: #000000; font-weight: bold;">function</span>, that has a pretty straightforward definition
; returns an interval that starts at the start of int1 and ends at the <a href="http://www.php.net/end"><span style="color: #000066;">end</span></a> of int2
<span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/define"><span style="color: #000066;">define</span></a> <span style="color: #66cc66;">&#40;</span>merge int1 int2<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>interval-create
    <span style="color: #66cc66;">&#40;</span>interval-start int1<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>interval-<a href="http://www.php.net/end"><span style="color: #000066;">end</span></a> int2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></p>
<p>Of course, there are no built-in functions to handle intervals in Scheme, you have to write them (interval-create etc) on your own.  A pair is perfect for representing an interval.</p>
<p>Notice that an iterative implementation would not (or at least it shouldn&#8217;t) be faster than the recursive impementation used here, as Scheme implements <a href="http://en.wikipedia.org/wiki/Tail_recursion">tail-recursion</a>.</p>
<p>For those not familiar with Scheme or Lisp,<br />
(car l) can be interpreted as returning the first item of list l<br />
(cdr l) as returning all the items but the first of list l, and<br />
(cons item l) as pushing item to the beginning of the list l,<br />
although that&#8217;s not exactly what they do.</p>
<p>Implementing should-merge and precedes function is a piece of cake if you represent the IP addresses as an integer (like ip2long of <a href="http://php.net/ip2long">PHP</a> or <a href="http://code.google.com/p/python-iptools/">python iptools</a>).</p>
<p>Bring Scheme to IEEExtreme 2009!<br />
Bring functional programming to IEEExtreme 2009!</p>
<p>P.S.: Thanks to <a href="http://ted.zino.gr">Ted</a> for pointing out IEEExtreme to the team <img src='http://blog.kamibu.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kamibu.com/2009/09/01/bring-functional-programming-to-ieeextreme/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Change default permission modes on Linux servers</title>
		<link>http://blog.kamibu.com/2009/03/28/change-default-permission-modes-on-linux-servers/</link>
		<comments>http://blog.kamibu.com/2009/03/28/change-default-permission-modes-on-linux-servers/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 21:46:01 +0000</pubDate>
		<dc:creator>ch-world</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://blog.kamibu.com/?p=81</guid>
		<description><![CDATA[For our Kamibu projects we use Subversion for versioning of our code. As we aren&#8217;t only one person each other user on our server has to be able to modify files created by the svn command. Thus files need to get created with 0660 as their permission modes. The default permission modes on a debian [...]]]></description>
			<content:encoded><![CDATA[<p>For our Kamibu projects we use Subversion for versioning of our code. As we aren&#8217;t only one person each other user on our server has to be able to modify files created by the svn command. Thus files need to get created with 0660 as their permission modes. The default permission modes on a debian system seem to be 0644. To change this behavior you&#8217;ve to edit /etc/profile. Search for the umask line.</p>
<p>On our fresh installed server it looked like this:</p>
<blockquote><p>umask 022</p></blockquote>
<p>This means 777 &#8211; 022 = 755. For directorys this is correct, to get the permission modes of a file you&#8217;ve to subtract 111. So after editing this line and saving the file you should logout and with your next login you will benefit from your new default permission modes.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kamibu.com/2009/03/28/change-default-permission-modes-on-linux-servers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some critique by GreekWebWatch</title>
		<link>http://blog.kamibu.com/2008/12/03/some-critique-by-greekwebwatch/</link>
		<comments>http://blog.kamibu.com/2008/12/03/some-critique-by-greekwebwatch/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 10:53:51 +0000</pubDate>
		<dc:creator>dionyziz</dc:creator>
				<category><![CDATA[Excalibur]]></category>

		<guid isPermaLink="false">http://blog.kamibu.com/?p=76</guid>
		<description><![CDATA[We recently received some press coverage on Zino by the popular Greek blog GreekWebWatch, a blog concerning news on the Greek Internet. Here&#8217;s our official response.
]]></description>
			<content:encoded><![CDATA[<p>We recently received some <a href="http://greekwebwatch.blogspot.com/2008/12/zinogr.html">press coverage</a> on Zino by the popular Greek blog GreekWebWatch, a blog concerning news on the Greek Internet. Here&#8217;s <a href="http://oniz.zino.gr/journals/Merikes_skepseis_apo_to_GreekWebWatch">our official response</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kamibu.com/2008/12/03/some-critique-by-greekwebwatch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Vilundo Chat Protocol</title>
		<link>http://blog.kamibu.com/2008/10/08/the-vilundo-chat-protocol/</link>
		<comments>http://blog.kamibu.com/2008/10/08/the-vilundo-chat-protocol/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 20:42:01 +0000</pubDate>
		<dc:creator>dionyziz</dc:creator>
				<category><![CDATA[Excalibur]]></category>

		<guid isPermaLink="false">http://blog.kamibu.com/?p=71</guid>
		<description><![CDATA[A while ago, we developed a simple chat protocol to-be-used for Zino. It&#8217;s still not in use, but we decided it would be a good idea to publish the specification so that other people could use it. It&#8217;s available under Creative Commons.
The Vilundo Chat Protocol Specification
]]></description>
			<content:encoded><![CDATA[<p>A while ago, we developed a simple chat protocol to-be-used for Zino. It&#8217;s still not in use, but we decided it would be a good idea to publish the specification so that other people could use it. It&#8217;s available under Creative Commons.</p>
<p><a href="http://www.dionyziz.com/Vilundo">The Vilundo Chat Protocol Specification</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kamibu.com/2008/10/08/the-vilundo-chat-protocol/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RabbitEdit</title>
		<link>http://blog.kamibu.com/2008/10/04/rabbitedit/</link>
		<comments>http://blog.kamibu.com/2008/10/04/rabbitedit/#comments</comments>
		<pubDate>Sat, 04 Oct 2008 19:37:40 +0000</pubDate>
		<dc:creator>Indy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.kamibu.com/?p=65</guid>
		<description><![CDATA[RabbitEdit is a nifty tool that allows easier Rabbit development and saves you quite some time and effort.
Its purpose is to automatically do particular common things for you, like writing pieces of code, creating parent directories for your new source files, and add the newly created files (and directories) into the SVN repository.
It can be [...]]]></description>
			<content:encoded><![CDATA[<p>RabbitEdit is a nifty tool that allows easier Rabbit development and saves you quite some time and effort.<br />
Its purpose is to automatically do particular common things for you, like writing pieces of code, creating parent directories for your new source files, and add the newly created files (and directories) into the SVN repository.<br />
It can be found in rabbit/etc/rabbitedit/ and its installation is as simple as:</p>
<p><pre class="php"><span style="color: #808080; font-style: italic;"># make install </span></pre><br />
You can uninstall it similarly, running:</p>
<p><pre class="php"><span style="color: #808080; font-style: italic;"># make uninstall </span></pre><br />
Its configuration file can be found at /etc/rabbitedit/rabbitedit.conf and follows the common configuration rules used by the most programs.<br />
You can see how it works, by issuing:</p>
<p><pre class="php">$ rabbitedit --help</pre><br />
A simple example of its usage, could be the following:</p>
<p><pre class="php">$ rabbitedit --parents --svn libs/customer/settings.php</pre><br />
Let&#8217;s assume you are in the root directory of your rabbit project. By running the above, RabbitEdit creates libs/customer/ if it does not exist (this is indicated by the &#8220;&#8211;parents&#8221; option), adds that directory into the SVN repository (indicated by &#8220;&#8211;svn&#8221;) as well as libs/customer/settings.php, and if settings.php did not exist before, it creates it and writes a standard piece of code in it (having the information that the file is a lib, and is about the settings of customers). If the file existed before, it leaves it as it was. Then, it opens the file with the source code editor of your choice.</p>
<p>RabbitEdit is written in Python, and is designed with the hope it fastens up the development of Rabbit projects and gives developers the chance to avoid drudgery, and focus on really important things, like actually coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kamibu.com/2008/10/04/rabbitedit/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#8220;echo&#8221; and &#8220;md5sum&#8221;</title>
		<link>http://blog.kamibu.com/2008/10/04/echo-and-md5sum/</link>
		<comments>http://blog.kamibu.com/2008/10/04/echo-and-md5sum/#comments</comments>
		<pubDate>Sat, 04 Oct 2008 18:37:24 +0000</pubDate>
		<dc:creator>Indy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.kamibu.com/?p=53</guid>
		<description><![CDATA[A problem I faced when I attempted to manually set a password for my user in Water, was that I could not login. I created the md5 sum of my password, running:
$ echo mypassword&#124;md5sum
and pasted it into the MySQL field of phpMyAdmin. After many login failures and enough searching about what is to blame, Kostis90gr [...]]]></description>
			<content:encoded><![CDATA[<p>A problem I faced when I attempted to manually set a password for my user in Water, was that I could not login. I created the md5 sum of my password, running:</p>
<p><pre class="php">$ <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> mypassword|md5sum</pre></p>
<p>and pasted it into the MySQL field of phpMyAdmin. After many login failures and enough searching about what is to blame, Kostis90gr found out that &#8220;echo&#8221;, is outputting a newline at the end of the string, so the md5 sum produced from the command above, was different than the one produced from PHP&#8217;s md5() function, simply because they were given different input. So, the right thing to do, is to pass &#8220;echo&#8221; the &#8220;-n&#8221; option, like:</p>
<p><pre class="php">$ <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> -n mypassword|md5sum</pre></p>
<p>which prevents &#8220;echo&#8221; from outputting a newline at the end of the string.<br />
I hope this post is helpful, because my unawareness of this &#8220;echo&#8221;&#8217;s little &#8220;particularity&#8221;, caused me quite enough frustration.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kamibu.com/2008/10/04/echo-and-md5sum/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>A Brief History of Comments</title>
		<link>http://blog.kamibu.com/2008/10/01/a-brief-history-of-comments/</link>
		<comments>http://blog.kamibu.com/2008/10/01/a-brief-history-of-comments/#comments</comments>
		<pubDate>Wed, 01 Oct 2008 16:16:41 +0000</pubDate>
		<dc:creator>kostis90gr</dc:creator>
				<category><![CDATA[Excalibur]]></category>
		<category><![CDATA[comment system v.0]]></category>

		<guid isPermaLink="false">http://blog.kamibu.com/?p=50</guid>
		<description><![CDATA[A quick first try to draw the commenting system of http://www.zino.gr
]]></description>
			<content:encoded><![CDATA[<p>A quick first try to draw the commenting system of <a title="Zino" href="http://www.zino.gr" target="_blank">http://www.zino.gr</a></p>
<div id="attachment_51" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.kamibu.com/wp-content/uploads/2008/10/commenting.jpg"><img class="size-medium wp-image-51" title="commenting" src="http://blog.kamibu.com/wp-content/uploads/2008/10/commenting-300x225.jpg" alt="Commenting" width="300" height="225" /></a><p class="wp-caption-text">Commenting</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.kamibu.com/2008/10/01/a-brief-history-of-comments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>vim regexp magic</title>
		<link>http://blog.kamibu.com/2008/09/23/vim-regexp-magic/</link>
		<comments>http://blog.kamibu.com/2008/09/23/vim-regexp-magic/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 14:12:42 +0000</pubDate>
		<dc:creator>dionyziz</dc:creator>
				<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://blog.kamibu.com/?p=44</guid>
		<description><![CDATA[Input, this one big liner:
function UnitUserSettingsSave( tInteger $dobd, tInteger $dobm, tInteger $doby, tText $gender, tInteger $place, tInteger $education, tInteger $school, tInteger $mood, tText $sex, tText $religion, tText $politics, tText $slogan, tText $aboutme, tText $favquote, tText $haircolor, tText $eyecolor, tInteger $height, tInteger $weight, tText $smoker, tText $drinker, tText $email, tText $msn, tText $gtalk, tText $skype, tText [...]]]></description>
			<content:encoded><![CDATA[<p>Input, this one big liner:</p>
<p>function UnitUserSettingsSave( tInteger $dobd, tInteger $dobm, tInteger $doby, tText $gender, tInteger $place, tInteger $education, tInteger $school, tInteger $mood, tText $sex, tText $religion, tText $politics, tText $slogan, tText $aboutme, tText $favquote, tText $haircolor, tText $eyecolor, tInteger $height, tInteger $weight, tText $smoker, tText $drinker, tText $email, tText $msn, tText $gtalk, tText $skype, tText $yahoo, tText $web, tText $oldpassword, tText $newpassword, tText $emailprofilecomment, tText $notifyprofilecomment, tText $emailphotocomment, tText $notifyphotocomment, tText $emailpollcomment, tText $notifypollcomment, tText $emailjournalcomment, tText $notifyjournalcomment, tText $emailreply, tText $notifyreply, tText $emailfriendaddition, tText $notifyfriendaddition, tText $emailtagcreation, tText $notifytagcreation, tText $emailfavourite, tText $notifyfavourite ) {</p>
<p>Output, this beautifully spaced multiliner:</p>
<p><pre class="php"><span style="color: #000000; font-weight: bold;">function</span> UnitUserSettingsSave<span style="color: #66cc66;">&#40;</span> tInteger <span style="color: #0000ff;">$dobd</span>, tInteger <span style="color: #0000ff;">$dobm</span>,
          tInteger <span style="color: #0000ff;">$doby</span>, tText <span style="color: #0000ff;">$gender</span>,
          tInteger <span style="color: #0000ff;">$place</span>, tInteger <span style="color: #0000ff;">$education</span>,
          tInteger <span style="color: #0000ff;">$school</span>, tInteger <span style="color: #0000ff;">$mood</span>,
          tText <span style="color: #0000ff;">$sex</span>, tText <span style="color: #0000ff;">$religion</span>,
          tText <span style="color: #0000ff;">$politics</span>, tText <span style="color: #0000ff;">$slogan</span>,
          tText <span style="color: #0000ff;">$aboutme</span>, tText <span style="color: #0000ff;">$favquote</span>,
          tText <span style="color: #0000ff;">$haircolor</span>, tText <span style="color: #0000ff;">$eyecolor</span>,
          tInteger <span style="color: #0000ff;">$height</span>, tInteger <span style="color: #0000ff;">$weight</span>,
          tText <span style="color: #0000ff;">$smoker</span>, tText <span style="color: #0000ff;">$drinker</span>,
          tText <span style="color: #0000ff;">$email</span>, tText <span style="color: #0000ff;">$msn</span>,
          tText <span style="color: #0000ff;">$gtalk</span>, tText <span style="color: #0000ff;">$skype</span>,
          tText <span style="color: #0000ff;">$yahoo</span>, tText <span style="color: #0000ff;">$web</span>,
          tText <span style="color: #0000ff;">$oldpassword</span>, tText <span style="color: #0000ff;">$newpassword</span>,
          tText <span style="color: #0000ff;">$emailprofilecomment</span>, tText <span style="color: #0000ff;">$notifyprofilecomment</span>,
          tText <span style="color: #0000ff;">$emailphotocomment</span>, tText <span style="color: #0000ff;">$notifyphotocomment</span>,
          tText <span style="color: #0000ff;">$emailpollcomment</span>, tText <span style="color: #0000ff;">$notifypollcomment</span>,
          tText <span style="color: #0000ff;">$emailjournalcomment</span>, tText <span style="color: #0000ff;">$notifyjournalcomment</span>,
          tText <span style="color: #0000ff;">$emailreply</span>, tText <span style="color: #0000ff;">$notifyreply</span>,
          tText <span style="color: #0000ff;">$emailfriendaddition</span>, tText <span style="color: #0000ff;">$notifyfriendaddition</span>,
          tText <span style="color: #0000ff;">$emailtagcreation</span>, tText <span style="color: #0000ff;">$notifytagcreation</span>,
          tText <span style="color: #0000ff;">$emailfavourite</span>, tText <span style="color: #0000ff;">$notifyfavourite</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></pre></p>
<p>How? With one command, in vim:</p>
<p><pre class="php">:s/\<span style="color: #66cc66;">&#40;</span>.\<span style="color: #66cc66;">&#123;</span><span style="color: #cc66cc;">-1</span>,<span style="color: #66cc66;">&#125;</span>\<span style="color: #66cc66;">&#41;</span>,\<span style="color: #66cc66;">&#40;</span>.\<span style="color: #66cc66;">&#123;</span><span style="color: #cc66cc;">-1</span>,<span style="color: #66cc66;">&#125;</span>\<span style="color: #66cc66;">&#41;</span>,/\<span style="color: #cc66cc;">1</span>,\<span style="color: #cc66cc;">2</span>,\r        /ig</pre></p>
<p>What does it do? </p>
<p>First off, :s/<em>needle</em>/<em>replacement</em>/g searches the current line for regular expression <em>needle</em> and replaces it with expression <em>replacement</em>. The current line is being searched because we didn&#8217;t specify a range before the &#8220;s&#8221;. &#8220;s&#8221; is the extended command that we&#8217;re running, which stands for &#8220;search and replace&#8221;. The &#8220;g&#8221; modifier after the final slash stands for &#8220;global&#8221;, meaning it should feel free to replace several occurrences in the same line, not just the first.</p>
<p>Now, for the <em>needle</em> expression. It can be essentially split into two parts:<br />
1) \(.\{-1,}\),<br />
2) \(.\{-1,}\),</p>
<p>These two expressions match exactly the same thing. They match anything they want, denoted with a dot, followed by a comma (the one that you see at the end of each expression). The &#8220;anything they want part&#8221; denoted with a single dot is just one character, so we&#8217;re modifying it to be able to match more than just one character (as many as it needs to satisfy the comma at the end) by adding the lazy quantifier \{-1,} after the dot.</p>
<p>The expression .\{-1,} means: match as many of any characters as you need to match the whole expression. In reality, because this is a lazy quantifier, it matches as less characters as possible providing it can find a comma right afterwards (but not the comma itself).</p>
<p>So both expressions tied together match anything followed by a comma followed by anything followed by a comma. Translation? They match two of the arguments of those provided in the function argument list.</p>
<p>The parentheses around each of them denoted \( and \) capture what is within, to be used in the replacement string. Our replacement string is simply &#8220;\1,\2,\r        &#8220;. It will replace \1 with the first parenthesized match, then add a comma, then replace the \2 with the second parenthesized match, then add yet another comma. Finally it will add a new line (\r) and some whitespace.</p>
<p>Repeating this pattern with the &#8220;global&#8221; modifier applies the regular expression several times on the line, yielding to new lines being added after every second argument.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kamibu.com/2008/09/23/vim-regexp-magic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kamibu Workroom</title>
		<link>http://blog.kamibu.com/2008/09/17/kamibu-workroom/</link>
		<comments>http://blog.kamibu.com/2008/09/17/kamibu-workroom/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 09:21:20 +0000</pubDate>
		<dc:creator>dionyziz</dc:creator>
				<category><![CDATA[Excalibur]]></category>

		<guid isPermaLink="false">http://blog.kamibu.com/?p=41</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p><img src="http://images.zino.gr/media/1/117270/117270_full.jpg" alt="Kamibu Workroom" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kamibu.com/2008/09/17/kamibu-workroom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
