<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Technically Unnecessary</title>
    <link rel="alternate" type="text/html" href="http://tu.wesolek.net/" />
    <link rel="self" type="application/atom+xml" href="http://tu.wesolek.net/atom.xml" />
    <id>tag:tu.wesolek.net,2009-08-20://2</id>
    <updated>2011-03-05T13:03:28Z</updated>
    
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.261</generator>

<entry>
    <title>Getting started with jEdit hacking: plugin compilation</title>
    <link rel="alternate" type="text/html" href="http://tu.wesolek.net/2011/03/getting-started-with-jedit-hacking-plugin-compilation.html" />
    <id>tag:tu.wesolek.net,2011://2.15</id>

    <published>2011-03-05T11:30:14Z</published>
    <updated>2011-03-05T13:03:28Z</updated>

    <summary>In the first installment of jEdit hacking series I described how to get jEdit running from the repo. However, jEdit wouldn&#8217;t be what it is without plugins. So, this time I&#8217;ll try to add a plugin. Compiled on our own,...</summary>
    <author>
        <name>Przemek Wesołek</name>
        
    </author>
    
        <category term="jEdit" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="java" label="Java" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="jedit" label="jEdit" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://tu.wesolek.net/">
        <![CDATA[<p>In <a href="http://tu.wesolek.net/2011/02/getting-started-with-jedit-hacking.html">the first installment of jEdit hacking series</a> I described how to get jEdit running from the repo. However, jEdit wouldn&#8217;t be what it is without plugins. So, this time I&#8217;ll try to add a plugin. Compiled on our own, of course, not from the Plugin Central!</p>

<p>As described on the mailing list, <a href="http://sourceforge.net/mailarchive/message.php?msg_id=26971918">there&#8217;s a problem with Sessions plugin</a> in recent compilations of jEdit. The cause is probably API changes. The bug is fixed in the repo. I wanted the plugin, so plugin compilation happened.</p>

<p>First, let&#8217;s obtain the plugin. No surprise here, as the plugin is in the same repo, as jEdit itself:</p>

<pre class='brush: bash'>
mkidr plugins
cd plugins
svn co http://jedit.svn.sourceforge.net/svnroot/jedit/plugins/Sessions/trunk Sessions
</pre>

<p>The only thing we need to do to compile Sessions is to know the location of <code>jedit.jar</code>. After successful compilation of basic jEdit it should be in its <code>build</code> directory. If you followed the structure of directories presented in my tutorials (<code>jEdit</code> next to <code>plugins</code>), relative path is <code>../../jEdit/build/jedit.jar</code>. For one-shot compilation the required property can be given on the command line:</p>

<pre class='brush: bash'>
ant -Djedit.install.dir=../../jEdit/build/
</pre>

<p>And&#8230; that&#8217;s it! One level above (in <code>plugins</code>) you should have <code>Sessions.jar</code>. After installation of Sessions from Plugins Central, close jEdit (make sure it is not running in the background!) and put the compiled JAR into <code>~/.jEdit/jars</code> (see http://plugins.jedit.org/install.php for details, also on Windows), replacing the downloaded one (you can make backup if you want). Start jEdit again and check in Plugin Manager if the version is greater than the one in the repo (1.5.1 vs. 1.4.3 from the repo, at the time of writing).</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Getting started with jEdit hacking</title>
    <link rel="alternate" type="text/html" href="http://tu.wesolek.net/2011/02/getting-started-with-jedit-hacking.html" />
    <id>tag:tu.wesolek.net,2011://2.14</id>

    <published>2011-02-23T13:36:50Z</published>
    <updated>2011-02-24T12:58:53Z</updated>

    <summary>I really like jEdit. It&#8217;s not my choice for the environment of multi-file, complicated projects, but I use it very often for ad-hoc text, code and XML editing. So I decided to give back to the community a little and...</summary>
    <author>
        <name>Przemek Wesołek</name>
        
    </author>
    
        <category term="jEdit" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="eclipse" label="Eclipse" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="java" label="Java" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="jedit" label="jEdit" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://tu.wesolek.net/">
        <![CDATA[<p>I really like jEdit. It&#8217;s not my choice for the environment of multi-file, complicated projects, but I use it very often for ad-hoc text, code and XML editing. So I decided to give back to the community a little and hack jEdit a bit.</p>

<p>In a few articles I&#8217;ll write my way through the mysteries of jEdit hacking, from the point of view of a newcomer.</p>

<p>In this article we will download, compile and debug with Eclipse the basic jEdit, without plugins.</p>

<h2>Fetching the sources</h2>

<p>Because I prefer Git to SVN, I decided to convert jEdit repo to local Git repos. So <code>git svn</code> to the rescue!</p>

<pre class='brush: bash'>
git svn init http://jedit.svn.sourceforge.net/svnroot/jedit --branches=jEdit/branches/ --tags=jEdit/tags/ --trunk=jEdit/trunk/
git svn fetch
</pre>

<p>Well, because SourceForge likes to drop connection randomly on large SVN transfers, it&#8217;ll be much easier to wrap the last line in a <code>while</code> loop:</p>

<pre class='brush: bash'>
while ! git svn fetch; do
    echo &quot;*** Retrying ***&quot;
done
</pre>

<p>If you&#8217;re OK with only SVN, just checkout the repo:</p>

<pre class='brush: bash'>
svn co http://jedit.svn.sourceforge.net/svnroot/jedit/jEdit/trunk jEdit
</pre>

<p>The docs says you&#8217;ll also need <code>build-support</code> module, but for building plain jEdit (without modules), you don&#8217;t need it. If you ever need it, use the above instructions for fetching jEdit, replacing <code>jEdit</code> in the URL and path with <code>build-support</code>. Make sure to put <code>build-support</code> dir next to <code>jEdit</code> one.</p>

<h2>Building</h2>

<p>jEdit build system is based on Ant. In Ubuntu required packages can be installed with:</p>

<pre class='brush: bash'>
aptitude install ant ant-optional
</pre>

<p>plus you will need a Java compiler &#8212; I won&#8217;t go into details here, leave a comment if you have problems.</p>

<p><code>README.SRC.txt</code> is pretty straight-forward about the required steps to build the system. First, you must configure jEdit build system. Copy <code>build.properties.sample</code> to <code>build.properties</code> and set up what necessary. Most defaults are fine, at the first shot I only setup the deprecation and warning policy (jEdit compilation gives <em>a lot</em> of warnings&#8230;):</p>

<pre class='brush: bash'>
# warning settings
build.nowarn=true
build.deprecation=false
build.compilerarg=     
</pre>

<p>Now, just compile:</p>

<pre class='brush: bash'>
ant build
# or just ant
</pre>

<h2>Running</h2>

<p>If you want to run the just-compiled code, do it with</p>

<pre class='brush: bash'>
ant run
</pre>

<p>For serious hacking you will probably need debugger set up. I prefer Eclipse for my daily programming jobs, so we&#8217;ll use that.</p>

<p>In Eclipse, create new Java project, name it &#8216;jEdit&#8217; (surprise!) and place it anywhere you want. Now, remove the default <code>src</code> folder and create a linked folder to the place where jEdit lives.</p>

<p>jEdit doesn&#8217;t use a separate source folder, sources are scattered in the main folder. Fortunatelly, there are not so many top-level packages, so not so many sub-folders.</p>

<p>Configure the project builder to use the just linked folder as the source folder. Configure inclusion/exclusion filter &#8212; we only need <code>org.*</code> packages. Resulting setting look like this:</p>

<p><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><img alt="eclipse-project-settings.png" src="http://tu.wesolek.net/2011/02/24/eclipse-project-settings.png" width="739" height="512" class="mt-image-none" style="" /></span></p>

<p>This will allow us to setup breakpoints, navigate and read the code easily. I don&#8217;t care about Eclipse compilation as long as there are no errors.</p>

<p>The easiest way to debug jEdit is to run it outside Eclipse, with debugging agent, and to run remote debugging in Eclipse. To run jEdit with debugging server use:</p>

<pre class='brush: bash'>
ant run-debug
</pre>

<p>jEdit virtual machine will stop waiting for a connection from Eclipse (with one minute timeout). In Eclipse, create debug configuration (<em>Run</em> &#8212; <em>Debug Configurations&#8230;</em> &#8212; <em>Remote Java Application</em> &#8212; <em>New launch configuration</em>) and point to <code>localhost</code> on port <code>5005</code>. Click <em>Debug</em> and here you go, debugging jEdit. Good luck!</p>
]]>
        

    </content>
</entry>

<entry>
    <title>The power of sets</title>
    <link rel="alternate" type="text/html" href="http://tu.wesolek.net/2011/02/the-power-of-sets.html" />
    <id>tag:tu.wesolek.net,2011://2.13</id>

    <published>2011-02-09T21:30:00Z</published>
    <updated>2011-02-10T22:29:43Z</updated>

    <summary>A few weeks ago I&#8217;ve participated in Code Retreat in Poznań. The main theme of the workshop was not to learn some specific programming techniques, but rather to try working in pairs, in fact in many pairs, five or six,...</summary>
    <author>
        <name>Przemek Wesołek</name>
        
    </author>
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="coding" label="coding" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="conway" label="Conway" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="Perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="sets" label="sets" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://tu.wesolek.net/">
        <![CDATA[<p>A few weeks ago I&#8217;ve participated in <a href="http://www.jug.poznan.pl/materialy-ze-spotkan/materialy/1-poznanski-code-retreat">Code Retreat in Poznań</a>. The main theme of the workshop was not to learn some specific programming techniques, but rather to try working in pairs, in fact in many pairs, five or six, each for less than an hour.</p>

<p>The goal was to program <a href="http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life">Conway&#8217;s Game of Life</a>, where each cell on rectangular board is born, lives or dies depending on the number of live neighbors (the live cell with 2 or 3 live neighbors survives, the dead cell with 3 live neighbors becomes alive).</p>

<p>The most common model is a two dimensional array. However, this approach has a drawback of the need to expand the array in all directions when new cells are to be born. Coding it correctly, with all test cases in less than an hour is not easy.</p>

<p>A friend in one of the pairs had a great idea: forget about an array and keep a set of live cells. Then, in each evolution step, expand this set with newly born cells and remove the ones which don&#8217;t survive.</p>

<p>We coded the solution in Ruby (without tests) and Java (with tests, in later session). Below is my personal try in Perl.</p>

<p>The concept can be neatly described in set theory. Let <em>S</em> be the set of live cells, neigh(<em>c</em>) is a function returning all neighbors of cell <em>c</em>. The set of candidates (potentially live cells in next round) is</p>

<p>$$ C = \bigcup_{c\in S} \mathrm{neigh}(c) $$</p>

<p>then the live set in the next round is</p>

<p>$$ S&#8217; = \{ c\in C : |\mathrm{lneigh}(c)|=3 \vee c\in S \wedge |\mathrm{lneigh}(c)|=2 \} $$</p>

<p>\( \mathrm{lneigh}(c) \) being the set of live neighbors of <em>c</em></p>

<p>$$ \mathrm{lneigh}(c) = \mathrm{neigh}(c) \cap S $$</p>

<p>The first version of code used plain hashes as sets, but using <a href="http://search.cpan.org/dist/Set-Scalar">Set::Scalar</a> gives cleaner code. There are some caveats, however.</p>

<pre class='brush: perl'>
use warnings;
use strict;

use Test::More;
use Set::Scalar;

# well, this should be default...
*Set::Scalar::Base::_strval  = sub { &quot;$_[0]&quot; };

my @D = (
    [ -1, -1 ], [ -1, 0 ], [ -1, 1 ],
    [  0, -1 ],            [  0, 1 ],
    [  1, -1 ], [  1, 0 ], [  1, 1 ]
);

my $h_rod = Set::Scalar-&gt;new(Seq::from_arr([-1,0], [0,0], [1,0]));
my $v_rod = Set::Scalar-&gt;new(Seq::from_arr([0,-1], [0,0], [0,1]));

my $set = Set::Scalar-&gt;new(Seq::from_arr([1, 2], [3, 4]));
ok $set-&gt;has(Seq-&gt;new(1,2));  # this wouldn't work without _strval redefinition

$set = $h_rod;

$set = step($set);
is $set, $v_rod;

$set = step($set);
is $set, $h_rod;

done_testing;


sub step {
    my ($live) = @_;
    my $candid = Set::Scalar-&gt;new(map { neigh($_) } $live-&gt;members);

    return Set::Scalar-&gt;new(grep {
        my @c_live_neigh = grep { $live-&gt;has($_) } neigh($_);
        @c_live_neigh == 3 || @c_live_neigh == 2 &amp;&amp; $live-&gt;has($_);
    } $candid-&gt;members);
}

sub neigh {
    my ($o) = @_;
    map { Seq-&gt;new($o-&gt;[0] + $_-&gt;[0], $o-&gt;[1] + $_-&gt;[1]) } @D;
}


package Seq;
use overload '&quot;&quot;' =&gt; sub {
    return join &quot;,&quot;, @{$_[0]};
};

sub new {
    my $class = shift;
    return bless [ @_ ], $class;
}
sub from_arr {
    return map { Seq-&gt;new(@$_) } @_;
}
</pre>

<p>As Jarkko writes in the docs of Set::Scalar:</p>

<blockquote>
  <p>Using references (or objects) as set members has not been extensively tested. The desired semantics are not always clear: what should happen when the elements behind the references change? Especially unclear is what should happen when the objects start having their own stringification overloads.</p>
</blockquote>

<p>Well, this is the case here. As we insert into the set the array refs, we need to convince Set::Scalar that two different refs are the same set element, if only the referred arrays have the same content.</p>

<p>However, stringification overload is not enough, as Set::Scalar additionally uses the refs addresses in its own stringification sub, _strval. So we need to redefine the sub to provide the set with our way of comparing things.</p>

<p>In fact, this was a big surprise to me: none of checked CPAN set distributions allowed the use of own identity methods. Even plain old hash-as-a-set is better in this regard, as stringification is performed to check for key presence:</p>

<pre class='brush: perl'>
my %hsh = map { $_ =&gt; $_ } ( Seq-&gt;new(1,2), Seq-&gt;new(3,4), Seq-&gt;new(1,2) );
is values(%hsh), 2;
</pre>

<script type="text/javascript" src="http://wesolek.net/mathjax/mathjax/MathJax.js"></script>
]]>
        

    </content>
</entry>

<entry>
    <title>From sound to notes</title>
    <link rel="alternate" type="text/html" href="http://tu.wesolek.net/2010/11/from-sound-to-notes.html" />
    <id>tag:tu.wesolek.net,2010://2.12</id>

    <published>2010-11-20T11:40:15Z</published>
    <updated>2011-02-27T17:09:13Z</updated>

    <summary>Some time ago I was given a link to a nice youtube video. Around 00:04 I recognized &#8220;Stairway to heaven&#8221; intro. Friends told me I was wrong, they just sound alike. Challenge accepted! Let&#8217;s analyze it. First of all, let&#8217;s...</summary>
    <author>
        <name>Przemek Wesołek</name>
        
    </author>
    
    <category term="audacity" label="Audacity" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="guitar" label="guitar" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="music" label="music" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="sound" label="sound" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://tu.wesolek.net/">
        <![CDATA[<p>Some time ago I was given a link to a nice youtube video. Around 00:04 I recognized &#8220;Stairway to heaven&#8221; intro. Friends told me I was wrong, they just sound alike. Challenge accepted! Let&#8217;s analyze it.</p>

<p>First of all, let&#8217;s download the video from youtube. Visit e.g. <a href="http://keepvid.com">http://keepvid.com</a> and enter video URL: http://www.youtube.com/watch?v=_erQi563tTU. Download the result (I chose MP4 480x360).</p>

<p>Extract the sound with</p>

<pre class='brush: bash'>
ffmpeg -t 10 -i video.flv suspected.wav
</pre>

<p>First 10 secs is enough.</p>

<p>Then load the file into Audacity and begin the sound processing.</p>

<p>Because we are interested in a very specific sounds, let&#8217;s filter out frequencies which are above the scale of a guitar. We&#8217;ll use &#8220;Low-pass filter&#8221; with rolloff of 48dB/octave, filter quality of 0.7 and cutoff frequency of 700Hz. This will allow us to better hear where the guitar plays.</p>

<p>Now, the hard work. What I want to do is to find beginning of the notes, and for every suspected fragment analyze its&#8217; spectrum. Looking at the spectrum peeks, I&#8217;ll assume the biggest ones (in guitar tune frequencies) are the tones we are looking for.</p>

<p>The good practical method to find the beginning of a tone is to listen to a fragment in slow motion. Also you may try to capture the correct moment by selecting a fragment and lowering its end until you hear no tone change at the end of this fragment. E.g. select a fragment from 3.4s to 3.9s and play it. You will hear two tones. Then, lower the end of the fragment until you hear only the first note. For me it was around 3.7s (a hint: text input for selection is very recommended). This is the beginning of the second tone.</p>

<p>Proceed with all the following sounds. Take into account, that previously played tones can co-sound, so analyze changes in spectrum for adjacent fragments.</p>

<p>My choices for times of the beginnings of tones, found peek frequencies and corresponding notes are:</p>

<pre class='brush: plain'>
3.44    293     D4
3.70    348     F4
3.95    441     A4
4.24    587     D5
4.48    662+277 E5 + C#4
4.74    350     F4
5.02    443     A4
5.36    659     E5  
5.65 701        F5
6.05    440     A4
6.35    396     G4
6.60    357     F4
</pre>

<p>Then the guitar player goes to another theme. But this certainly IS &#8220;Stairway to heaven&#8221;! You can play it like this:</p>

<pre class='brush: plain'>
E|----------------10---|-12-------------12---|-13------------------|
B|-----------10--------|-----------10--------|------10-------------|
G|------10-------------|------10-------------|-----------10--------|
D|-12------------------|-11------------------|----------------10---|
A|---------------------|---------------------|---------------------|
E|---------------------|---------------------|---------------------|
</pre>

<p>while the common version you will find on the internet goes like:</p>

<pre class='brush: plain'>
E|----------5--7--------7-8--------8--2--------2-0---------0-
B|-------5--------5----------5-----------3---------1-----1---
G|----5--------------5----------5-----------2---------2------
D|-7-----------6----------5-----------4----------------------
A|-----------------------------------------------------------
E|-----------------------------------------------------------
</pre>

<p>Beside the transposition and a small variance in 2nd tact (2 notes reversed), they are the same.</p>

<p>Now, it would be very nice, if the computer could do the whole analysis. E.g. analyze the changes in spectrum in time and draw conclusions, when new sounds appear and what tones they are. Do you know such a tool, or should I start writing my own?</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Mapping terminal colors</title>
    <link rel="alternate" type="text/html" href="http://tu.wesolek.net/2010/10/mapping-terminal-colors.html" />
    <id>tag:tu.wesolek.net,2010://2.10</id>

    <published>2010-10-26T12:16:18Z</published>
    <updated>2010-10-27T14:02:13Z</updated>

    <summary>Recently I started to work more intensively under Windows. Being a Linux convert, I installed MSYS to have bash and other UN*X tools. Although MSYS works nice, I had problems with proper console behavior. Both the Windows default one (cmd.exe)...</summary>
    <author>
        <name>Przemek Wesołek</name>
        
    </author>
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="colors" label="colors" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="ironman" label="Ironman" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="linux" label="Linux" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="msys" label="MSYS" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="Perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="rxvt" label="rxvt" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="windows" label="Windows" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://tu.wesolek.net/">
        <![CDATA[<p>Recently I started to work more intensively under Windows. Being a Linux convert, I installed MSYS to have bash and other UN*X tools. Although MSYS works nice, I had problems with proper console behavior. Both the Windows default one (<code>cmd.exe</code>) and Console2 lack some terminal capabilities, so I stick with MSYS&#8217; rxvt.</p>

<p>One thing I didn&#8217;t like about rxvt was the colors. I have Tango colors set in Gnome Terminal, so I tried to copy the palette.</p>

<p>Rxvt allows you to set an ANSI color with  <code>-colorX</code> options, but accepts only X11 color names, while Gnome Terminal gives you RGB values.</p>

<p>So I wrote a simple script which reads an RGB triple from the input and finds the closest matching colors in the palette. Here it is:</p>

<pre class='brush: perl'>
use warnings;
use strict;

use 5.010;
use Color::Similarity::HCL qw( distance );

my ($fname) = @ARGV;
die &quot;Usage: $0 /etc/X11/rgb.txt&quot; unless defined $fname;

my @palette;
open my $xcol_fh, '&lt;', $fname or die &quot;Can't open $fname: $!&quot;;
while (&lt;$xcol_fh&gt;) {
    chomp;
    next if /^\s*!/;
    my ($r, $g, $b, $name) = $_ =~ /^\s*(\d+)\s+(\d+)\s+(\d+)\s+(.*)/;
    push @palette, { name =&gt; $name, r =&gt; $r, g =&gt; $g, b =&gt; $b };
}
close $xcol_fh;

while (my $l = &lt;STDIN&gt;) {
    chomp $l; 

    my @triple = $l =~ /^\s*(\d+)\s+(\d+)\s+(\d+)/;
    $_-&gt;{dist} = distance([ @triple ], [ @$_{qw( r g b )} ]) for (@palette);

    say &quot;Best matches for (&quot;, join(qq(, ), @triple), &quot;) are: &quot;;
    my @srt = sort { $a-&gt;{dist} &lt;=&gt; $b-&gt;{dist} } @palette;
    for my $col (@srt[0..9]) {
        say &quot;$col-&gt;{name} (&quot;, join(qq(, ), @$col{qw( r g b )}), &quot;): $col-&gt;{dist}&quot;;
    }   
}
</pre>

<p>or even simpler, using <code>Convert::Color::X11</code>, as suggested by LeoNerd:</p>

<pre class='brush: perl'>
use warnings;
use strict;

use 5.010;
use Convert::Color::X11;
use Color::Similarity::HCL qw( distance );

my @palette = map { { name =&gt; $_, rgb =&gt; [ Convert::Color::X11-&gt;new($_)-&gt;rgb8 ] } } Convert::Color::X11-&gt;colors;                                                                                                                              

while (my $l = &lt;STDIN&gt;) {
    chomp $l; 

    my @triple = $l =~ /^\s*(\d+)\s+(\d+)\s+(\d+)/;
    $_-&gt;{dist} = distance([ @triple ], $_-&gt;{rgb}) for (@palette);

    say &quot;Best matches for (&quot;, join(qq(, ), @triple), &quot;) are: &quot;;
    my @srt = sort { $a-&gt;{dist} &lt;=&gt; $b-&gt;{dist} } @palette;
    for my $col (@srt[0..9]) {
        say &quot;$col-&gt;{name} (&quot;, join(qq(, ), @{$col-&gt;{rgb}}), &quot;): $col-&gt;{dist}&quot;;
    }   
}
</pre>

<p>For me, rxvt best emulates Tango palette with the following options:</p>

<pre class='brush: plain'>
-color0 black -color1 red3 -color2 chartreuse4 -color3 gold3 -color4 DodgerBlue4 -color5 plum4 -color6 turquoise4 -color7 honeydew3 -color8 gray34 -color9 firebrick2 -color10 chartreuse2 -color11 khaki -color12 SkyBlue3 -color13 plum3 -color14 cyan3 -color15 gray93
</pre>
]]>
        

    </content>
</entry>

<entry>
    <title>Per-tags feeds in MovableType</title>
    <link rel="alternate" type="text/html" href="http://tu.wesolek.net/2009/11/per-tags-feeds-in-movabletype.html" />
    <id>tag:tu.wesolek.net,2009://2.7</id>

    <published>2009-11-21T19:54:01Z</published>
    <updated>2010-07-27T07:45:15Z</updated>

    <summary>In Movable Type it is possible to generate a feed for entries matching a given tag only. For this to happen, just select some tag, e.g. from tags cloud and take a look at link named &#8220;Feed of results tagged...</summary>
    <author>
        <name>Przemek Wesołek</name>
        
    </author>
    
        <category term="Movable Type" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="ironman" label="Ironman" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="movabletype" label="Movable Type" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="Perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="ubuntu" label="Ubuntu" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://tu.wesolek.net/">
        <![CDATA[<p>In Movable Type it is possible to generate a feed for entries matching a given tag only. For this to happen, just select some tag, e.g. from tags cloud and take a look at link named &#8220;Feed of results tagged &#8230;&#8221;. For example, for this blog&#8217;s Perl tag, the link looks like:</p>

<p><code>
http://tu.wesolek.net/cgi-bin/mt/mt-search.cgi?tag=Perl&amp;Template=feed&amp;IncludeBlogs=2&amp;limit=20
</code></p>

<p>and you can use this URL as a feed, e.g. for <a href="http://www.enlightenedperl.org/ironman.html">Ironman challenge</a>.</p>

<p>There is a problem with Ubuntu package, however (Karmic at least). Packaged MT is missing <code>search_templates</code> link in <code>/usr/lib/cgi-bin/movabletype</code>. I <a href="https://bugs.launchpad.net/ubuntu/+source/movabletype-opensource/+bug/486402">reported this bug</a>, and you can apply the simple solution on your own.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Perlmonks on giving ready solutions</title>
    <link rel="alternate" type="text/html" href="http://tu.wesolek.net/2009/11/perlmonks-on-giving-ready-solutions.html" />
    <id>tag:tu.wesolek.net,2009://1.6</id>

    <published>2009-11-18T12:52:54Z</published>
    <updated>2009-11-21T20:29:10Z</updated>

    <summary>I read Perlmonks irregularly, sometimes I even post something. I give hints, thoughts or bigger chunks of code. But for the first time I got as much as 40% of downvotes on an entry that I think is rather neutral....</summary>
    <author>
        <name>Przemek Wesołek</name>
        
    </author>
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="perl" label="Perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perlmonks" label="PerlMonks" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://tu.wesolek.net/">
        <![CDATA[<p>I read <a href="http://perlmonks.org">Perlmonks</a> irregularly, sometimes I even post something. I give hints, thoughts or bigger chunks of code. But for the first time I got as much as 40% of <a href="http://perlmonks.org/?node_id=5938">downvotes</a> on an <a href="http://perlmonks.org/?node_id=807809">entry that I think is rather neutral</a>.</p>

<p>I understand that some people don&#8217;t like to give others ready solutions, they prefer &#8220;to teach others to fish than to give them a fish&#8221;. But is it really something that bothers them so much to give thumbs down to the ones who don&#8217;t mind? No feelings hurt, I&#8217;m just curious&#8230;</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Compiling Perl 5.10.1 under Ubuntu</title>
    <link rel="alternate" type="text/html" href="http://tu.wesolek.net/2009/10/compiling-perl-5101-under-ubuntu.html" />
    <id>tag:tu.wesolek.net,2009://1.5</id>

    <published>2009-10-11T19:03:52Z</published>
    <updated>2009-11-21T20:28:37Z</updated>

    <summary> Note: Since 5.10.1 is not upstream, there might be changes in packages versions, so downloading patches as described below might not work. I&#8217;ll try to update this entry to reflect the correct links, but in case of problems just...</summary>
    <author>
        <name>Przemek Wesołek</name>
        
    </author>
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="debian" label="Debian" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="Perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="ubuntu" label="Ubuntu" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://tu.wesolek.net/">
        <![CDATA[<hr />

<p><strong>Note:</strong> Since 5.10.1 is not upstream, there might be changes in packages versions, so downloading patches as described below might not work. I&#8217;ll try to update this entry to reflect the correct links, but in case of problems just go to <a href="http://patch-tracker.debian.org/package/perl">http://patch-tracker.debian.org/package/perl</a>, select the current version of Perl 5.10.1 and download <code>mod_paths.diff</code> manually.</p>

<hr />

<p>After reading encouragingly simple <a href="http://oylenshpeegul.vox.com/library/post/perl-5101.html">instructions on compiling Perl 5.10.1</a>, I decided to compile Perl &#8212; for the first time &#8212; on my own.</p>

<p>Everything went fine, but after installation it occurred that the order of directories on <code>@INC</code> is &#8220;core, vendor, site&#8221;, where the expected &#8212; after using Debian&#8217;s Perl for years &#8212; was &#8220;site, vendor, core&#8221;. Apparently a bug (for most), with no chance to be corrected due to backward compatibility.</p>

<p>So, I applied <a href="http://patch-tracker.debian.org/patch/series/dl/perl/5.10.1-7/debian/mod_paths.diff">a patch from Debian</a>, which corrects the order. Note, that besides correcting the order, the patch adds <code>/etc/perl</code> at the beginning of <code>@INC</code> and <code>/usr/local/lib/site_perl</code> at the end. This is fine with me, but you can remove it from the code if you wish.</p>

<p><code>mod_paths.diff</code>:</p>

<pre class='brush: diff'>
Subject: Tweak @INC so that the ordering is:

    etc (for config files)
    site (5.8.1)
    vendor (all)
    core (5.8.1)
    site (version-indep)
    site (pre-5.8.1)

The rationale being that an admin (via site), or module packager
(vendor) can chose to shadow core modules when there is a newer
version than is included in core.


---
 perl.c |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/perl.c b/perl.c
index 94f2b13..5a6744a 100644
--- a/perl.c
+++ b/perl.c
@@ -4879,9 +4879,14 @@ S_init_perllib(pTHX)
     incpush(APPLLIB_EXP, TRUE, TRUE, TRUE, TRUE);
 #endif

+#ifdef DEBIAN
+    /* for configuration where /usr is mounted ro (CPAN::Config, Net::Config) */
+    incpush(&quot;/etc/perl&quot;, FALSE, FALSE, FALSE, FALSE);
+#else
 #ifdef ARCHLIB_EXP
     incpush(ARCHLIB_EXP, FALSE, FALSE, TRUE, TRUE);
 #endif
+#endif
 #ifdef MACOS_TRADITIONAL
     {
    Stat_t tmpstatbuf;
@@ -4906,11 +4911,13 @@ S_init_perllib(pTHX)
 #ifndef PRIVLIB_EXP
 #  define PRIVLIB_EXP &quot;/usr/local/lib/perl5:/usr/local/lib/perl&quot;
 #endif
+#ifndef DEBIAN
 #if defined(WIN32)
     incpush(PRIVLIB_EXP, TRUE, FALSE, TRUE, TRUE);
 #else
     incpush(PRIVLIB_EXP, FALSE, FALSE, TRUE, TRUE);
 #endif
+#endif

 #ifdef SITEARCH_EXP
     /* sitearch is always relative to sitelib on Windows for
@@ -4954,6 +4961,61 @@ S_init_perllib(pTHX)
     incpush(PERL_VENDORLIB_STEM, FALSE, TRUE, TRUE, TRUE);
 #endif

+#ifdef DEBIAN
+    incpush(ARCHLIB_EXP, FALSE, FALSE, TRUE, FALSE);
+    incpush(PRIVLIB_EXP, FALSE, FALSE, TRUE, FALSE);
+
+    /* Non-versioned site directory for local modules and for
+       compatability with the previous packages' site dirs */
+    incpush(&quot;/usr/local/lib/site_perl&quot;, TRUE, FALSE, FALSE, FALSE);
+
+#ifdef PERL_INC_VERSION_LIST
+    {
+   struct stat s;
+
+   /* add small buffer in case old versions are longer than the
+      current version */
+   char sitearch[sizeof(SITEARCH_EXP)+16] = SITEARCH_EXP;
+   char sitelib[sizeof(SITELIB_EXP)+16] = SITELIB_EXP;
+   char const *vers[] = { PERL_INC_VERSION_LIST };
+   char const **p;
+
+   char *arch_vers = strrchr(sitearch, '/');
+   char *lib_vers = strrchr(sitelib, '/');
+
+   if (arch_vers &amp;&amp; isdigit(*++arch_vers))
+       *arch_vers = 0;
+   else
+       arch_vers = 0;
+
+   if (lib_vers &amp;&amp; isdigit(*++lib_vers))
+       *lib_vers = 0;
+   else
+       lib_vers = 0;
+
+   /* there is some duplication here as incpush does something
+      similar internally, but required as sitearch is not a
+      subdirectory of sitelib */
+   for (p = vers; *p; p++)
+   {
+       if (arch_vers)
+       {
+       strcpy(arch_vers, *p);
+       if (PerlLIO_stat(sitearch, &amp;s) &gt;= 0 &amp;&amp; S_ISDIR(s.st_mode))
+           incpush(sitearch, FALSE, FALSE, FALSE, FALSE);
+       }
+
+       if (lib_vers)
+       {
+       strcpy(lib_vers, *p);
+       if (PerlLIO_stat(sitelib, &amp;s) &gt;= 0 &amp;&amp; S_ISDIR(s.st_mode))
+           incpush(sitelib, FALSE, FALSE, FALSE, FALSE);
+       }
+   }
+    }
+#endif
+#endif
+
 #ifdef PERL_OTHERLIBDIRS
     incpush(PERL_OTHERLIBDIRS, TRUE, TRUE, TRUE, TRUE);
 #endif
-- 
tg: (daf8b46..) debian/mod_paths (depends on: upstream)
</pre>

<p>So, my modified compilation instructions with Ubuntu&#8217;s &#8220;taste&#8221; look like:</p>

<pre class='brush: plain'>
wget http://www.cpan.org/modules/by-authors/id/D/DA/DAPM/perl-5.10.1.tar.bz2
wget http://patch-tracker.debian.org/patch/series/dl/perl/5.10.1-7/debian/mod_paths.diff
tar xjf perl-5.10.1.tar.bz2
cd perl-5.10.1
patch -b -p1 &lt;../mod_paths.diff
perl Configure -de -Dprefix=${HOME}/local -Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Doptimize=-O2
make
make test
make install
</pre>
]]>
        

    </content>
</entry>

<entry>
    <title>Perl test in MT</title>
    <link rel="alternate" type="text/html" href="http://tu.wesolek.net/2009/09/perl-test-in-mt.html" />
    <id>tag:tu.wesolek.net,2009://1.4</id>

    <published>2009-09-07T10:21:15Z</published>
    <updated>2009-09-07T10:28:59Z</updated>

    <summary><![CDATA[Here&#8217;s a little test of Perl formatting with SyntaxHighlighter. #!/usr/bin/perl use strict; print &quot;Hello there!&quot;; I&#8217;ll write a bit more on my Movable Type config soon, as there are some interesting quirks....]]></summary>
    <author>
        <name>Przemek Wesołek</name>
        
    </author>
    
    <category term="movabletype" label="Movable Type" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="Perl" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://tu.wesolek.net/">
        <![CDATA[<p>Here&#8217;s a little test of Perl formatting with SyntaxHighlighter.</p>

<pre class='brush: perl'>
#!/usr/bin/perl

use strict;

print &quot;Hello there!&quot;;
</pre>

<p>I&#8217;ll write a bit more on my Movable Type config soon, as there are some interesting quirks.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Compiling with distcc and ccache</title>
    <link rel="alternate" type="text/html" href="http://tu.wesolek.net/2009/09/compiling-with-distcc-and-ccache.html" />
    <id>tag:tu.wesolek.net,2009://1.3</id>

    <published>2009-09-04T14:15:32Z</published>
    <updated>2009-10-11T19:00:34Z</updated>

    <summary>In my working environment a firewall is set up that prevents connecting with remote server do do distributed computing with distcc. Here&#8217;s a short note on how I work around it and generally, how my compilation chain is constructed. First,...</summary>
    <author>
        <name>Przemek Wesołek</name>
        
    </author>
    
    <category term="c" label="C" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="c" label="C++" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="ccache" label="ccache" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="distcc" label="distcc" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://tu.wesolek.net/">
        <![CDATA[<p>In my working environment a firewall is set up that prevents connecting with remote server do do distributed computing with <code>distcc</code>. Here&#8217;s a short note on how I work around it and generally, how my compilation chain is constructed.</p>

<p>First, I setup SSH tunnel to avoid firewall restrictions:</p>

<pre class='brush: bash'>
ssh SERVER -L 3633:localhost:3632
</pre>

<p>and run a build on the local machine</p>

<pre class='brush: bash'>
DISTCC_HOSTS='localhost:3633' CCACHE_PREFIX='distcc' CXX='ccache g++' make -j8
</pre>

<p>The compilation chain is as follow:</p>

<ol>
<li><code>ccache</code> is run instead of <code>g++</code>.</li>
<li><code>ccache</code> checks if it has a locally (on the client) cached version of compilation result. If so, the result is returned.</li>
<li>If not, <code>distcc</code> is called and performs compilation on the <code>SERVER</code>.</li>
<li>Compilation result is stored in <code>ccache</code>&#8217;s cache and &#8220;returned back&#8221;.</li>
</ol>
]]>
        

    </content>
</entry>

<entry>
    <title>Auto-connecting signal handlers in glademm</title>
    <link rel="alternate" type="text/html" href="http://tu.wesolek.net/2009/08/auto-connecting-signal-handlers-in-glademm.html" />
    <id>tag:tu.wesolek.net,2009://1.2</id>

    <published>2009-08-20T13:24:16Z</published>
    <updated>2009-10-11T19:01:45Z</updated>

    <summary>libglade has the possibility to automatically connect all signal handlers specified in a Glade XML file. However, it is not directly possible in libglademm (C++). Although you find some results when you search the Net for &#8220;libglademm autoconnect&#8221;, either no...</summary>
    <author>
        <name>Przemek Wesołek</name>
        
    </author>
    
    <category term="c" label="C" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="c" label="C++" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="gtk" label="GTK+" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://tu.wesolek.net/">
        <![CDATA[<p>libglade has the possibility to automatically connect all signal handlers specified in a Glade XML file. However, it is not directly possible in libglademm (C++).</p>

<p>Although you find some results when you search the Net for &#8220;libglademm autoconnect&#8221;, either no solution is given, or the posters mention that &#8220;wrapping functions with extern works for them&#8221;. No code. So here is a simple example working for me.</p>

<p><code>minimal.cc</code>:</p>

<pre class='brush: cpp'>
#include &lt;gtkmm.h&gt;
#include &lt;libglademm.h&gt;
#include &lt;iostream&gt;
#include &lt;glade/glade-xml.h&gt;

extern &quot;C&quot; {
    void on_button1_clicked() {
        std::cout &lt;&lt; &quot;Clicked&quot; &lt;&lt; std::endl;
    }
}

int main(int argc, char *argv[]) {
    Gtk::Main kit(argc, argv);

    Glib::RefPtr&lt;Gnome::Glade::Xml&gt; refXml = Gnome::Glade::Xml::create(&quot;minimal.glade&quot;);
    glade_xml_signal_autoconnect(refXml-&gt;gobj());

    Gtk::Window *mainWnd = 0;
    refXml-&gt;get_widget(&quot;window1&quot;, mainWnd);
    Gtk::Main::run(*mainWnd);

    return 0;
}
</pre>

<p><code>minimal.glade</code>:</p>

<pre class='brush: xml'>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;
&lt;!DOCTYPE glade-interface SYSTEM &quot;glade-2.0.dtd&quot;&gt;
&lt;!--Generated with glade3 3.4.5 on Thu Aug 20 15:37:26 2009 --&gt;
&lt;glade-interface&gt;
  &lt;widget class=&quot;GtkWindow&quot; id=&quot;window1&quot;&gt;
    &lt;child&gt;
      &lt;widget class=&quot;GtkButton&quot; id=&quot;button1&quot;&gt;
        &lt;property name=&quot;visible&quot;&gt;True&lt;/property&gt;
        &lt;property name=&quot;can_focus&quot;&gt;True&lt;/property&gt;
        &lt;property name=&quot;receives_default&quot;&gt;True&lt;/property&gt;
        &lt;property name=&quot;label&quot; translatable=&quot;yes&quot;&gt;click me&lt;/property&gt;
        &lt;property name=&quot;response_id&quot;&gt;0&lt;/property&gt;
        &lt;signal name=&quot;clicked&quot; handler=&quot;on_button1_clicked&quot;/&gt;
      &lt;/widget&gt;
    &lt;/child&gt;
  &lt;/widget&gt;
&lt;/glade-interface&gt;
</pre>

<p><code>Makefile</code>:</p>

<pre class='brush: plain'>
CXXFLAGS = $(shell pkg-config gtkmm-2.4 libglademm-2.4 --cflags)
LDLIBS = $(shell pkg-config gtkmm-2.4 libglademm-2.4 --libs)
LDFLAGS = -export-dynamic

minimal: minimal.o

clean:
    rm minimal minimal.o
</pre>

<p>And then</p>

<pre class='brush: bash'>
make minimal
</pre>

<p>produces something like</p>

<pre class='brush: bash'>
g++ -D_REENTRANT -I/usr/include/gtkmm-2.4 -I/usr/lib/gtkmm-2.4/include -I/usr/include/glibmm-2.4 -I/usr/lib/glibmm-2.4/include -I/usr/include/giomm-2.4 -I/usr/lib/giomm-2.4/include -I/usr/include/gdkmm-2.4 -I/usr/lib/gdkmm-2.4/include -I/usr/include/pangomm-1.4 -I/usr/include/atkmm-1.6 -I/usr/include/gtk-2.0 -I/usr/include/sigc++-2.0 -I/usr/lib/sigc++-2.0/include -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/lib/gtk-2.0/include -I/usr/include/cairomm-1.0 -I/usr/include/pango-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/directfb -I/usr/include/libpng12 -I/usr/include/atk-1.0 -I/usr/include/libglademm-2.4 -I/usr/lib/libglademm-2.4/include -I/usr/include/libglade-2.0 -I/usr/include/libxml2     -c -o minimal.o minimal.cc
cc -export-dynamic  minimal.o  -lglademm-2.4 -lgtkmm-2.4 -lglade-2.0 -lgiomm-2.4 -lgdkmm-2.4 -latkmm-1.6 -lpangomm-1.4 -lcairomm-1.0 -lglibmm-2.4 -lsigc-2.0 -lgtk-x11-2.0 -lxml2 -lgdk-x11-2.0 -latk-1.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lgio-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lglib-2.0   -o minimal
</pre>

<p>Running the <code>minimal</code> program and clicking the &#8220;click me&#8221; button should produce a message on stdout.</p>
]]>
        

    </content>
</entry>

</feed>

