<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Moserei</title>
    <link href="http://moserei.de/atom.xml" rel="self"/>
    <link href="http://moserei.de/"/>
    <updated>2012-01-24T13:00:09+01:00</updated>
    <id>http://moserei.de</id>
    
    <entry>
        <title>Rails 3.1: Access compiled assets</title>
        
        <link href="http://moserei.de/2011/09/16/rails-3.1-access-compiled-assets.html"/>
        <updated>2011-09-16T00:00:00+02:00</updated>
        <id>jduff.github.com:/2011/09/16/rails-3.1-access-compiled-assets</id>
        <content type="html">&lt;p&gt;I use &lt;a href='https://github.com/mileszs/wicked_pdf'&gt;wicked pdf&lt;/a&gt; for PDF generation in my rails app &lt;a href='https://github.com/moser/foxtrot_mike'&gt;foxtrot mike&lt;/a&gt;. Wicked pdf has a helper method which copies the content of CSS files into the generated HTML. This does not work in Rails 3.1 because CSS files are generated by &lt;a href='https://github.com/sstephenson/sprockets'&gt;Sprockets&lt;/a&gt;. Fortunately it is possible to access the compiled asset files. When the asset pipeline is enabled, the application object has an attribute &lt;code&gt;assets&lt;/code&gt; which returns a &lt;a href='http://rubydoc.info/gems/sprockets/2.0.0/Sprockets/Environment'&gt;Sprockets::Environment&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The following code includes the contents of &lt;code&gt;application.css&lt;/code&gt; in my layout which is used for PDF generation.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='haml'&gt;  &lt;span class='nt'&gt;%style&lt;/span&gt;&lt;span class='p'&gt;{&lt;/span&gt; &lt;span class='ss'&gt;:type&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;text/css&amp;quot;&lt;/span&gt; &lt;span class='p'&gt;}&lt;/span&gt;
    &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='no'&gt;Rails&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;application&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;assets&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='s1'&gt;&amp;#39;application.css&amp;#39;&lt;/span&gt;&lt;span class='o'&gt;].&lt;/span&gt;&lt;span class='n'&gt;to_s&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;html_safe&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>Evince with Tabs - Or rather &quot;in Tabs&quot;</title>
        
        <link href="http://moserei.de/2011/02/10/evince-with-tabs.html"/>
        <updated>2011-02-10T00:00:00+01:00</updated>
        <id>jduff.github.com:/2011/02/10/evince-with-tabs</id>
        <content type="html">&lt;p&gt;While I wrote my bachelors thesis a couple of months ago, I really got angry about &lt;a href='http://projects.gnome.org/evince/'&gt;Evince&lt;/a&gt; and the lack of a tab-enabled PDF viewer in Gnome. While I was (trying to) learn for a university course today, this anger returned. The lecturer felt like it was a good idea to arrange the content in more than 15 PDF files.&lt;/p&gt;

&lt;p&gt;I ceased the attempt to learn and again started a search for a tabbed document viewer for Gnome. Several users &lt;a href='http://brainstorm.ubuntu.com/item/15899/'&gt;requested a tab feature in evince&lt;/a&gt; on Ubuntu brainstorm and received - in my opinion - annoyingly arrogant answers. The technical aspects are not an argument, look at Gedit. The design-user-experience-blah reasons for not implementing this feature may be justified, but one could still implement it as an option and let the user decide. But whatever&amp;#8230;&lt;/p&gt;

&lt;p&gt;I did not exactly find a tabbed document viewer. But I found an acceptable workaround:&lt;/p&gt;

&lt;p&gt;It is based on whatever browser you like (as long as it is supported by &lt;a href='http://packages.ubuntu.com/maverick/mozplugger'&gt;mozplugger&lt;/a&gt;, Chromium in my case) and &lt;a href='http://hyperlogos.org/blog/drink/embedding-evince-Chrome'&gt;embedding evince there&lt;/a&gt;. On Ubuntu mozplugger can be installed like so:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo aptitude install mozplugger&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;After you installed mozplugger and restarted your browser it should show up as a plugin. You can then follow the instructions in the blog post linked to above.&lt;/p&gt;

&lt;p&gt;Because Evince has no option to hide the toolbar persistently, I removed it completely. To do this, edit &lt;code&gt;~/.gnome2/evince/evince_toolbar.xml&lt;/code&gt; to look like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;
&amp;lt;toolbars version=&amp;quot;1.0&amp;quot;&amp;gt;
&amp;lt;/toolbars&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I have furthermore configured Gnome to open PDFs in Chromium.&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>Switched to Jekyll</title>
        
        <link href="http://moserei.de/2011/01/15/switched-to-jekyll.html"/>
        <updated>2011-01-15T00:00:00+01:00</updated>
        <id>jduff.github.com:/2011/01/15/switched-to-jekyll</id>
        <content type="html">&lt;p&gt;When I first installed WordPress I really liked it. But keeping it and it&amp;#8217;s plugins up to date is a pain for me. Furthermore, running a PHP application feels kind of strange for me who feels disgust when thinking of this language. While my server does not run anything of great value, it is surely more secure not to run a dynamic application for something that is rather static.&lt;/p&gt;

&lt;p&gt;So I decided to switch my blog to &lt;a href='http://jekyllrb.com'&gt;jekyll&lt;/a&gt;. The import of my old posts worked quite well, I just had to reformat them a bit. My layout just needed minor adaptions.&lt;/p&gt;

&lt;p&gt;Permalinks of my WP blog were formatted according to the pattern &lt;code&gt;moserei.de/index.php/:id/:slug&lt;/code&gt;. I could have generated a similar directory structure with jekyll, but I like the default format (&lt;code&gt;moserei.de/:year/:month/:day/:slug&lt;/code&gt;). So I crafted a little &lt;a href='http://rack.rubyforge.org/'&gt;rack&lt;/a&gt; app which redirects requests to old permalink URLs to the new ones.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='k'&gt;class&lt;/span&gt; &lt;span class='nc'&gt;RedirectPermalinks&lt;/span&gt;
  &lt;span class='no'&gt;Mapping&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;0&amp;#39;&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;/&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
              &lt;span class='s1'&gt;&amp;#39;3&amp;#39;&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;/2008/09/15/started.html&amp;#39;&lt;/span&gt; 
               &lt;span class='c1'&gt;#... &lt;/span&gt;
            &lt;span class='p'&gt;}&lt;/span&gt;
  &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;call&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;env&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='nb'&gt;id&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;0&amp;quot;&lt;/span&gt;
    &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='n'&gt;env&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;QUERY_STRING&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='o'&gt;=~&lt;/span&gt; &lt;span class='sr'&gt;/p=([0-9]+)/&lt;/span&gt; &lt;span class='o'&gt;||&lt;/span&gt; 
       &lt;span class='n'&gt;env&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;REQUEST_URI&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='o'&gt;=~&lt;/span&gt; &lt;span class='sr'&gt;/\/([0-9]+)\//&lt;/span&gt;
      &lt;span class='nb'&gt;id&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='vg'&gt;$1&lt;/span&gt;
    &lt;span class='k'&gt;end&lt;/span&gt;
    &lt;span class='o'&gt;[&lt;/span&gt; &lt;span class='mi'&gt;301&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; 
      &lt;span class='p'&gt;{&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;Content-Type&amp;quot;&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;text/plain&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; 
        &lt;span class='s2'&gt;&amp;quot;Location&amp;quot;&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;http://moserei.de&lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='nb'&gt;id&lt;/span&gt; &lt;span class='o'&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class='no'&gt;Mapping&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='nb'&gt;id&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='o'&gt;||&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;&lt;/span&gt; &lt;span class='p'&gt;},&lt;/span&gt; 
      &lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='o'&gt;]&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;It is deployed inside a directory called &lt;code&gt;index.php&lt;/code&gt; and redirects requests to the abovementioned permalink URLs and to &lt;code&gt;index.php/?p=:id&lt;/code&gt; to the corresponding articles. All other requests are redirected to &lt;code&gt;/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Comments are now managed by &lt;a href='http://disqus.com'&gt;Disqus&lt;/a&gt;. Disqus has awesome tools for import and migration. I imported comments from a WXR file exported from WP and migrated the post URLs using a CSV file I extracted from WP&amp;#8217;s database.&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>N-Body fun</title>
        
        <link href="http://moserei.de/2010/12/14/n-body-fun.html"/>
        <updated>2010-12-14T00:00:00+01:00</updated>
        <id>jduff.github.com:/2010/12/14/n-body-fun</id>
        <content type="html">&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Replaced the GIF by a video.&lt;/p&gt;

&lt;p&gt;We currently have to do a simple two-dimensional &lt;a href='http://en.wikipedia.org/wiki/N-body_simulation'&gt;n-body simulation&lt;/a&gt; of gravitation for a university course in practical parallel programming. It uses &lt;a href='http://en.wikipedia.org/wiki/Message_Passing_Interface'&gt;MPI&lt;/a&gt; and &lt;a href='http://en.wikipedia.org/wiki/Openmp'&gt;OpenMP&lt;/a&gt; for parallelism. For benchmarks we were supplied with a model of a spiral galaxy which (in the original example) was passed by by an massive object. I tweaked the system so that this object now rather goes through the galaxy:&lt;/p&gt;
&lt;iframe frameborder='0' height='500' src='http://player.vimeo.com/video/17800450?byline=0&amp;amp;portrait=0' width='500'&gt; 
video
&lt;/iframe&gt;
&lt;p&gt;Some numbers: The model consists of 402 objects, a step of simulation is 1000 years long, the loop consists of 1.4M steps, a frame was generated every 2500 steps. This took about 25 minutes using 14 MPI processes (no OpenMP).&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>Find GnuPG revocation certificate on unmountable partition</title>
        
        <link href="http://moserei.de/2010/07/06/find-gnupg-revocation-certificate-on-unmountable-partition.html"/>
        <updated>2010-07-06T00:00:00+02:00</updated>
        <id>jduff.github.com:/2010/07/06/find-gnupg-revocation-certificate-on-unmountable-partition</id>
        <content type="html">&lt;p&gt;When you encounter a hard disk crash like I did recently (my fault - dropped my laptop), one of the most important files to restore is your GnuPG private key ring or at least a revocation certificate for your public key(s). I did not have any backup :-(. But at least I had created a revocation certificate, which was now hidden somewhere on my unmountable partition. &lt;a href='https://help.ubuntu.com/community/DataRecovery#Scalpel'&gt;Scalpel&lt;/a&gt;, a file carving tool, helped me out. There is a Ubuntu package (and I believe there should be packages for most distributions):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo apt-get install scalpel&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It&amp;#8217;s configuration is in /etc/scalpel/scalpel.conf. It offers some GPG related rules, but none for a revocation certificate. I used these rules:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;revoc	y	100000	-----BEGIN\040PGP\040PUBLIC\040KEY\040BLOCK-----\x0aVersion:\040GnuPG\040v1.4.10\040(GNU/Linux)\x0aComment:\040A\040revocation\040certificate\040should\040follow
revoc	y	100000	-----BEGIN\040PGP\040PUBLIC\040KEY\040BLOCK-----\x0aVersion:\040GnuPG\040v1.4.9\040(GNU/Linux)\x0aComment:\040A\040revocation\040certificate\040should\040follow
revoc	y	100000	-----BEGIN\040PGP\040PUBLIC\040KEY\040BLOCK-----\x0aVersion:\040GnuPG\040v1.4.8\040(GNU/Linux)\x0aComment:\040A\040revocation\040certificate\040should\040follow&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I wasn&amp;#8217;t quite sure which version of GPG I had installed at the time I created the keys, so I created rules for all possible versions. (See &lt;a href='http://manpages.ubuntu.com/manpages/lucid/man1/scalpel.1.html'&gt;manpage&lt;/a&gt; for syntax explanation.)&lt;/p&gt;

&lt;p&gt;It took about 2 hours to scan the image of my 250 GB hard drive and scalpel successfully restored my revocation certificate.&lt;/p&gt;

&lt;p&gt;I also tried some of the supplied rules but I think they are not suitable for restoring files from an image of a whole hard drive. (Most of them just look for two bytes that mark the beginning of the file.)&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>slow, slower, activerecord-jdbcsqlite3-adapter</title>
        
        <link href="http://moserei.de/2010/02/09/slow-slower-activerecord-jdbcsqlite3-adapter.html"/>
        <updated>2010-02-09T00:00:00+01:00</updated>
        <id>jduff.github.com:/2010/02/09/slow-slower-activerecord-jdbcsqlite3-adapter</id>
        <content type="html">&lt;p&gt;I did a little performance test to find out which database to use in a JRuby desktop application. To have a comparison value I also ran the test (insert, find+update, destroy each 500 times) with MRI and the native sqlite3 driver. It revealed that the jdbcsqlite3 adapter is really sloooooooooow:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ ruby test.rb sqlite3

                 user     system   total     real
insert           0.4500   0.0900   0.5400 (  7.303116)
find and update  0.4900   0.1400   0.6300 (  6.984390)
destroy          0.3300   0.1100   0.4400 (  7.261199)

$ jruby test.rb jdbcsqlite3

                 user     system   total     real
insert          17.2500   0.0000  17.2500 ( 17.250000)
find and update 16.3270   0.0000  16.3270 ( 16.327000)
destroy         15.0900   0.0000  15.0900 ( 15.089000)

$ jruby test.rb h2

                 user     system   total     real
insert           1.9320   0.0000   1.9320 (  1.932000)
find and update  0.7800   0.0000   0.7800 (  0.780000)
destroy          0.3180   0.0000   0.3180 (  0.318000)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That&amp;#8217;s what I call an easy decision. My setup can be downloaded &lt;a href='http://moserei.de/files/ruby/h2_vs_sqlite3.zip'&gt;here&lt;/a&gt;.&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>Difference between do-end and {} blocks</title>
        
        <link href="http://moserei.de/2010/02/07/difference-between-do-end-and-curly-blocks.html"/>
        <updated>2010-02-07T00:00:00+01:00</updated>
        <id>jduff.github.com:/2010/02/07/difference-between-do-end-and-curly-blocks</id>
        <content type="html">&lt;p&gt;There is a important difference between the two block syntaxes in Ruby: Their precedence. Consider following code:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;method1&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='n'&gt;args&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
  &lt;span class='nb'&gt;puts&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;method1 got a block&amp;quot;&lt;/span&gt; &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='nb'&gt;block_given?&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;

&lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;method2&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='n'&gt;args&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
  &lt;span class='nb'&gt;puts&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;method2 got a block&amp;quot;&lt;/span&gt; &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='nb'&gt;block_given?&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;

&lt;span class='n'&gt;method1&lt;/span&gt; &lt;span class='n'&gt;method2&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;

&lt;span class='n'&gt;method1&lt;/span&gt; &lt;span class='n'&gt;method2&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You would expect both method calls to produce the same result, wouldn&amp;#8217;t you? Output:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;method1 got a block
method2 got a block&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Obviously the do-end block is passed to the first method in the expression while the {} block is passed to the method called directly before it. Another example shows that the assignment does not count as a method call here:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='c1'&gt;#[...]&lt;/span&gt;
&lt;span class='k'&gt;class&lt;/span&gt; &lt;span class='nc'&gt;Foo&lt;/span&gt;
  &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;bar&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;o&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='nb'&gt;puts&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;Foo#bar= got a block&amp;quot;&lt;/span&gt; &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='nb'&gt;block_given?&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;span class='n'&gt;foo&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='no'&gt;Foo&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;new&lt;/span&gt;

&lt;span class='n'&gt;foo&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;bar&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;method1&lt;/span&gt; &lt;span class='n'&gt;method2&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt; 
&lt;span class='c1'&gt;#method1 got a block&lt;/span&gt;

&lt;span class='n'&gt;foo&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;bar&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;method1&lt;/span&gt; &lt;span class='n'&gt;method2&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt; 
&lt;span class='c1'&gt;#method2 got a block&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>Accessing DeviceKit with DBus and Python</title>
        
        <link href="http://moserei.de/2010/01/08/accessing-devicekit-with-dbus-and-python.html"/>
        <updated>2010-01-08T00:00:00+01:00</updated>
        <id>jduff.github.com:/2010/01/08/accessing-devicekit-with-dbus-and-python</id>
        <content type="html">&lt;p&gt;Under the impression of loosing some really important data because of a damaged partition table on a USB flash drive I am developing a backup strategy for my system. I know myself and so I decided that I need to automate this. While trying to figure out how one can run a script as soon as a specific drive is mounted, I came across &lt;a href='http://en.wikipedia.org/wiki/DeviceKit'&gt;DeviceKit&lt;/a&gt;. It&amp;#8217;s the planned &lt;a href='http://www.freedesktop.org/wiki/Software/hal'&gt;replacement of HAL&lt;/a&gt; and is used in Ubuntu Karmic. Udev is not an option for me, because I don&amp;#8217;t want to mess around with mounting myself (and I hate running stuff as root&amp;#8230;). So here is what I found out about using DBus and DeviceKit in Python:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='python'&gt;&lt;span class='kn'&gt;import&lt;/span&gt; &lt;span class='nn'&gt;dbus&lt;/span&gt;

&lt;span class='n'&gt;bus&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;dbus&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;SystemBus&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt;

&lt;span class='n'&gt;proxy&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;bus&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;get_object&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;org.freedesktop.DeviceKit.Disks&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; 
                       &lt;span class='s'&gt;&amp;quot;/org/freedesktop/DeviceKit/Disks&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
&lt;span class='n'&gt;iface&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;dbus&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Interface&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;proxy&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;org.freedesktop.DeviceKit.Disks&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
&lt;span class='c'&gt;#enumerates all devices&lt;/span&gt;
&lt;span class='k'&gt;print&lt;/span&gt; &lt;span class='n'&gt;iface&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;EnumerateDevices&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt;

&lt;span class='c'&gt;#gets the device kit path of a specific device&lt;/span&gt;
&lt;span class='n'&gt;path&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;iface&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;FindDeviceByDeviceFile&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;/dev/sdc1&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; 
&lt;span class='c'&gt;#= &amp;quot;/org/freedesktop/DeviceKit/Disks/devices/sdc&amp;quot;&lt;/span&gt;

&lt;span class='c'&gt;#gets an object representing the device specified by the path&lt;/span&gt;
&lt;span class='n'&gt;device&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;bus&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;get_object&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;org.freedesktop.DeviceKit.Disks&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;path&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; 

&lt;span class='c'&gt;#prints some XML that shows you the available methods, signals and properties&lt;/span&gt;
&lt;span class='k'&gt;print&lt;/span&gt; &lt;span class='n'&gt;device&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Introspect&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt;

&lt;span class='c'&gt;#gets a proxy for getting properties&lt;/span&gt;
&lt;span class='n'&gt;device_prop&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;dbus&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Interface&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;device&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;org.freedesktop.DBus.Properties&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;

&lt;span class='c'&gt;#you need to specify an interface (properties could be ambiguous)&lt;/span&gt;
&lt;span class='k'&gt;print&lt;/span&gt; &lt;span class='n'&gt;device_prop&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Get&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;org.freedesktop.DeviceKit.Disks.Device&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;device-mount-paths&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;

&lt;span class='c'&gt;#gets a proxy you can call methods on&lt;/span&gt;
&lt;span class='n'&gt;device_iface&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;dbus&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Interface&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;device&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;org.freedesktop.DeviceKit.Disks.Device&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;

&lt;span class='c'&gt;#unmounts the partition&lt;/span&gt;
&lt;span class='n'&gt;device_iface&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;FilesystemUnmount&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;dbus&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Array&lt;/span&gt;&lt;span class='p'&gt;([],&lt;/span&gt; &lt;span class='s'&gt;&amp;#39;s&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The DBus API of DeviceKit is documented &lt;a href='http://hal.freedesktop.org/docs/DeviceKit-disks/ref-dbus.html'&gt;here&lt;/a&gt;. Now we want to be notified when a drive is mounted:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='n'&gt;import&lt;/span&gt; &lt;span class='n'&gt;dbus&lt;/span&gt;
&lt;span class='n'&gt;import&lt;/span&gt; &lt;span class='n'&gt;gobject&lt;/span&gt;
&lt;span class='n'&gt;from&lt;/span&gt; &lt;span class='n'&gt;dbus&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;mainloop&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;glib&lt;/span&gt; &lt;span class='n'&gt;import&lt;/span&gt; &lt;span class='no'&gt;DBusGMainLoop&lt;/span&gt;

&lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;device_added_callback&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;device&lt;/span&gt;&lt;span class='p'&gt;):&lt;/span&gt;
    &lt;span class='nb'&gt;print&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;Device %s was added&amp;#39;&lt;/span&gt; &lt;span class='o'&gt;%&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;device&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;

&lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;device_changed_callback&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;device&lt;/span&gt;&lt;span class='p'&gt;):&lt;/span&gt;
    &lt;span class='nb'&gt;print&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;Device %s was changed&amp;#39;&lt;/span&gt; &lt;span class='o'&gt;%&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;device&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;

&lt;span class='c1'&gt;#must be done before connecting to DBus&lt;/span&gt;
&lt;span class='no'&gt;DBusGMainLoop&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;set_as_default&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='no'&gt;True&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;

&lt;span class='n'&gt;bus&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;dbus&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;SystemBus&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt;

&lt;span class='n'&gt;proxy&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;bus&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;get_object&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;org.freedesktop.DeviceKit.Disks&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; 
                       &lt;span class='s2'&gt;&amp;quot;/org/freedesktop/DeviceKit/Disks&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
&lt;span class='n'&gt;iface&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;dbus&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Interface&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;proxy&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;org.freedesktop.DeviceKit.Disks&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;

&lt;span class='c1'&gt;#addes two signal listeners&lt;/span&gt;
&lt;span class='n'&gt;iface&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;connect_to_signal&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s1'&gt;&amp;#39;DeviceAdded&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;device_added_callback&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
&lt;span class='n'&gt;iface&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;connect_to_signal&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s1'&gt;&amp;#39;DeviceChanged&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;device_changed_callback&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;

&lt;span class='c1'&gt;#start the main loop&lt;/span&gt;
&lt;span class='n'&gt;mainloop&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;gobject&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;MainLoop&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt;
&lt;span class='n'&gt;mainloop&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;run&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;A typical output when a flash drive is plugged in looks like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Device /org/freedesktop/DeviceKit/Disks/devices/sdc was added
Device /org/freedesktop/DeviceKit/Disks/devices/sdc1 was added
Device /org/freedesktop/DeviceKit/Disks/devices/sdc1 was changed&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With this knowledge I&amp;#8217;m currently working on a little python script that runs in background and executes a shell script when a file system is mounted. I&amp;#8217;ll post it, when it&amp;#8217;s finished :-)&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>Sequel single table inheritance</title>
        
        <link href="http://moserei.de/2009/10/20/sequel-single-table-inheritance.html"/>
        <updated>2009-10-20T00:00:00+02:00</updated>
        <id>jduff.github.com:/2009/10/20/sequel-single-table-inheritance</id>
        <content type="html">&lt;p&gt;&lt;a href='http://sequel.rubyforge.org/'&gt;Sequel&lt;/a&gt;&amp;#8217;s STI is not so well documented as ActiveRecord&amp;#8217;s is. Because it cost me about 20 minutes to find out about it&amp;#8217;s syntax, I post a little example.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='k'&gt;class&lt;/span&gt; &lt;span class='nc'&gt;A&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;&lt;/span&gt; &lt;span class='no'&gt;Sequel&lt;/span&gt;&lt;span class='o'&gt;::&lt;/span&gt;&lt;span class='no'&gt;Model&lt;/span&gt;
  &lt;span class='n'&gt;plugin&lt;/span&gt; &lt;span class='ss'&gt;:single_table_inheritance&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:object_type&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;

&lt;span class='k'&gt;class&lt;/span&gt; &lt;span class='nc'&gt;B&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;&lt;/span&gt; &lt;span class='n'&gt;A&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The second argument is the name of the column to be used to store the class name in DB. Don&amp;#8217;t use &amp;#8216;type&amp;#8217; here, it collides with Ruby&amp;#8217;s Object#type. This works with version 3.5.0 and should work with any version &amp;gt;= 2.12.0.&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>Monkeybars - Little bug</title>
        
        <link href="http://moserei.de/2009/09/10/monkeybars-little-bug.html"/>
        <updated>2009-09-10T00:00:00+02:00</updated>
        <id>jduff.github.com:/2009/09/10/monkeybars-little-bug</id>
        <content type="html">&lt;p&gt;For a little side project I am currently evaluating different ways of GUI programming using Ruby. &lt;a href='http://monkeybars.rubyforge.org/'&gt;Monkeybars&lt;/a&gt; is one of the most interesting candidates. There is a really good &lt;a href='http://www.ibm.com/developerworks/library/j-monkeybars/index.html'&gt;article&lt;/a&gt; about it, if you want to learn more. Version 1.0.4 has a little, but annoying bug: If you generate a new application skeleton it won&amp;#8217;t compile/run:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;manifest.rb:32:in `require&amp;#39;: no such file to load -- monkeybars (LoadError)
    from manifest.rb:32
    from manifest.rb:21:in `require&amp;#39;
    from main.rb:21&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To fix it, you got to change line 21 of manifest.rb:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='n'&gt;add_to_classpath&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;../lib/java/monkeybars-1.0.2.jar&amp;#39;&lt;/span&gt;
&lt;span class='c1'&gt;#to&lt;/span&gt;
&lt;span class='n'&gt;add_to_classpath&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;../lib/java/monkeybars-1.0.4.jar&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>First time &gt; 500 km</title>
        
        <link href="http://moserei.de/2009/08/13/first-time-500-km.html"/>
        <updated>2009-08-13T00:00:00+02:00</updated>
        <id>jduff.github.com:/2009/08/13/first-time-500-km</id>
        <content type="html">&lt;p&gt;On last Wednesday I had to write my last test for this semester. As the long term soaring forecast looked quite good I decided to skip the party on the evening and to drive home (i.e. the airfield) instead. The weather report for Thursday promised us good but blue (no &lt;a href='http://en.wikipedia.org/wiki/Cumulus_cloud'&gt;clouds&lt;/a&gt; that mark the upper ends of thermals) conditions. I don&amp;#8217;t really like flying on blue days as you can never be sure if there is still thermal activity where you are heading, but I was quite motivated because I did not fly cross country for nearly two months. On Thursday morning Daniel and I assembled the &lt;a href='http://en.wikipedia.org/wiki/Schempp-Hirth_Ventus_2'&gt;Ventus 2cx&lt;/a&gt; (Thanks btw) and I put in 58 liters of water ballast. At 11 AM me and some of our guests from Hamburg were ready for tow. Fortunately the weather forecast was not entirely correct: We already saw some clouds develop.&lt;/p&gt;

&lt;p&gt;At 11.47 AM (local) I released the tow rope a little north western of Cham in about 700 m AGL (above ground level). My first thermal wasn&amp;#8217;t good (or I just did not get it the right way). So I proceeded a little further north, lost some more height and found myself in weak, narrow thermal. I decided to drop my water ballast which probably was wrong. Afterwards the thermal improved and I could fly on to the north. Within the first hour I seldom was higher than 1000 m AGL. When I passed Weiden the altitude of the cloud base and the thermals&amp;#8217; strength improved and I got faster. The Fichtelgebirge provided me with some strong lift and soon I passed Kulmbach.&lt;/p&gt;
&lt;a href='http://www.zooomr.com/photos/moser/7959501/' title='Sonneberg'&gt;&lt;img alt='Sonneberg' height='375' src='http://static.zooomr.com/images/7959501_91fc592428.jpg' width='500' /&gt;&lt;/a&gt;
&lt;p&gt;&lt;em&gt;Sonneberg&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Overhead Sonneberg I entered the Thuringian Forest. Some kilometers before Suhl I turned back southward. All in all I had to thermal too much for my taste on the first leg.&lt;/p&gt;
&lt;a href='http://www.zooomr.com/photos/moser/7959516/' title='Bridge'&gt;&lt;img alt='New Railway bridge' height='375' src='http://static.zooomr.com/images/7959516_1f4f74a60c.jpg' width='500' /&gt;&lt;/a&gt;
&lt;p&gt;&lt;em&gt;Bridge construction site on the &lt;a href='http://en.wikipedia.org/wiki/Nuremberg%E2%80%93Erfurt_high-speed_railway#Ebensfeld.E2.80.93Erfurt_new_line'&gt;Nuremberg–Erfurt high-speed railway&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;On the way back south I did a better job and did not thermal much until I was south of Tirschenreuth. A &lt;a href='http://www.onlinecontest.org/olc-2.0/gliding/flightinfo.html?dsId=1004623'&gt;Janus&lt;/a&gt; joined me in close formation for some 40 Km. In order to stretch the flight a little I went on to the south east of Cham and turned near Bischofsmais.&lt;/p&gt;

&lt;p&gt;From there I planned my final glide which was quite tight and got tighter due to some strong downdrafts in the area where I turned. But I was lucky and hit some thermals on the glide home. The second one was quite strong and I decided to gain any height I could get in order to make some extra kilometers. I again passed Cham and flew on to the north west. I could use some calm evening thermals, turned at Neunburg vorm Wald for the last time and went home fast.&lt;/p&gt;

&lt;p&gt;With a distance of 529 Km and a duration of 6 hours and 37 minutes this was my farthest and longest flight. Because of the high amount of traffic and the sometimes rough thermals I only took a few pictures today.&lt;/p&gt;

&lt;p&gt;Here is the flight on the &lt;a href='http://www.onlinecontest.org/olc-2.0/gliding/flightinfo.html?flightId=-257703970'&gt;OLC&lt;/a&gt;.&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>xkcd rocks</title>
        
        <link href="http://moserei.de/2009/07/20/xkcd-rocks.html"/>
        <updated>2009-07-20T00:00:00+02:00</updated>
        <id>jduff.github.com:/2009/07/20/xkcd-rocks</id>
        <content type="html">&lt;a href='http://xkcd.com/612/'&gt;&lt;img alt='Estimation (xkcd)' src='http://imgs.xkcd.com/comics/estimation.png' /&gt;&lt;/a&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>massage passing as means of coordination</title>
        
        <link href="http://moserei.de/2009/07/01/massage-passing-as-means-of-coordination.html"/>
        <updated>2009-07-01T00:00:00+02:00</updated>
        <id>jduff.github.com:/2009/07/01/massage-passing-as-means-of-coordination</id>
        <content type="html">&lt;p&gt;A nice quote found on the slides of our distributed systems lecture: &lt;blockquote&gt;massage passing as means of coordination&lt;/blockquote&gt; One should try massaging each other to improve a team&amp;#8217;s coordination. ;-)&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>ActiveRecord: write_attribute and UTC conversion</title>
        
        <link href="http://moserei.de/2009/06/23/activerecord-write_attribute-and-utc-conversion.html"/>
        <updated>2009-06-23T00:00:00+02:00</updated>
        <id>jduff.github.com:/2009/06/23/activerecord-write_attribute-and-utc-conversion</id>
        <content type="html">&lt;p&gt;A little gotcha with custom setters for datetime attributes is, that when setting an attribute through &amp;#8216;write_attribute&amp;#8217; it is not converted to UTC (or whatever else your default time zone is). This problem can easily be reproduced:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;./script/generate model Thing a:datetime b:datetime&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;My model:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='k'&gt;class&lt;/span&gt; &lt;span class='nc'&gt;Thing&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;&lt;/span&gt; &lt;span class='no'&gt;ActiveRecord&lt;/span&gt;&lt;span class='o'&gt;::&lt;/span&gt;&lt;span class='no'&gt;Base&lt;/span&gt;
  &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;b&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;d&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='n'&gt;write_attribute&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='ss'&gt;:b&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;d&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;My tests:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='nb'&gt;require&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;test_helper&amp;#39;&lt;/span&gt;

&lt;span class='k'&gt;class&lt;/span&gt; &lt;span class='nc'&gt;ThingTest&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;&lt;/span&gt; &lt;span class='no'&gt;ActiveSupport&lt;/span&gt;&lt;span class='o'&gt;::&lt;/span&gt;&lt;span class='no'&gt;TestCase&lt;/span&gt;
  &lt;span class='nb'&gt;test&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;a and b&amp;quot;&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt;
    &lt;span class='n'&gt;d&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='no'&gt;DateTime&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;now&lt;/span&gt;
    &lt;span class='n'&gt;t&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='no'&gt;Thing&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;new&lt;/span&gt;
    &lt;span class='n'&gt;t&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;a&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;d&lt;/span&gt;
    &lt;span class='n'&gt;t&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;b&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;d&lt;/span&gt;
    &lt;span class='n'&gt;t&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;save&lt;/span&gt;
    &lt;span class='n'&gt;assert_equal&lt;/span&gt; &lt;span class='n'&gt;t&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;a&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;t&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;b&lt;/span&gt;
    &lt;span class='n'&gt;t&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;reload&lt;/span&gt;
    &lt;span class='n'&gt;assert_equal&lt;/span&gt; &lt;span class='n'&gt;t&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;a&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;t&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;b&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The second assertion will fail. Is this intended or a bug? Quick fix:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;  &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;b&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;d&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='n'&gt;d&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;d&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;utc&lt;/span&gt;
    &lt;span class='n'&gt;write_attribute&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='ss'&gt;:b&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;d&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>jQuery, jRails and the Accept header</title>
        
        <link href="http://moserei.de/2009/06/18/jquery-jrails-and-accept-header.html"/>
        <updated>2009-06-18T00:00:00+02:00</updated>
        <id>jduff.github.com:/2009/06/18/jquery-jrails-and-accept-header</id>
        <content type="html">&lt;p&gt;I included jQuery by installing the &lt;a href='http://ennerchi.com/projects/jrails'&gt;jRails&lt;/a&gt; plugin, which seems nice because you can continue using rails&amp;#8217; ajax helpers. But when I tried to implement a more special functionality by using the $.ajax function it proved impossible to set the Accept header for my request. Neither using the dataType option nor by setting it directly in a beforeSend function. The Accept header always read:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;text/javascript, text/html, application/xml, text/xml, */*&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I was about to uninstall and hate jQuery for the rest of my life. By coincidence I took a look at jrails.js which is a part of the jRails plugin:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;    &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='kd'&gt;function&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nx'&gt;$&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='p'&gt;{&lt;/span&gt;
      &lt;span class='nx'&gt;$&lt;/span&gt;&lt;span class='p'&gt;().&lt;/span&gt;&lt;span class='nx'&gt;ajaxSend&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;
        &lt;span class='kd'&gt;function&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nx'&gt;a&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='nx'&gt;xhr&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='nx'&gt;s&lt;/span&gt;&lt;span class='p'&gt;){&lt;/span&gt;
          &lt;span class='nx'&gt;xhr&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nx'&gt;setRequestHeader&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;Accept&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;text/javascript, text/html, application/xml, text/xml, */*&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
        &lt;span class='p'&gt;}&lt;/span&gt;
      &lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='p'&gt;}&lt;/span&gt;
    &lt;span class='p'&gt;)(&lt;/span&gt;&lt;span class='nx'&gt;jQuery&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt; 
    &lt;span class='p'&gt;[...]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;WTF? Is that documented anywhere? This hard coded &lt;del&gt;shit&lt;/del&gt; stuff breaks rails&amp;#8217; respond_to functionality, doesn&amp;#8217;t it?t To be fair, it works if you use extensions to determine what datatype you expect. (Like /things/1.js) But I don&amp;#8217;t do that when I build a custom ajax request where I can set the Accept header directly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Some research on the topic &amp;#8220;accept header vs. extension&amp;#8221; showed that in terms of cross browser compatibility I should favor the extension approach. And I&amp;#8217;m not surprised it&amp;#8217;s &lt;a href='http://geminstallthat.wordpress.com/2008/05/14/ie6-accept-header-is-faulty/'&gt;Microsoft&amp;#8217;s&lt;/a&gt; &lt;a href='http://intertwingly.net/blog/2007/08/23/Intermittent-IE-failures'&gt;fault&lt;/a&gt; :-)&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>ActiveRecord: Overwrite attribute setter</title>
        
        <link href="http://moserei.de/2009/06/17/activerecord-overwrite-attribute-setter.html"/>
        <updated>2009-06-17T00:00:00+02:00</updated>
        <id>jduff.github.com:/2009/06/17/activerecord-overwrite-attribute-setter</id>
        <content type="html">&lt;p&gt;It&amp;#8217;s somehow trivial, but I found out about &amp;#8217;&lt;a href='http://api.rubyonrails.org/classes/ActiveRecord/Base.html'&gt;write_attribute&lt;/a&gt;&amp;#8217; only just: (another case of rtfm)&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='k'&gt;class&lt;/span&gt; &lt;span class='nc'&gt;Thing&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;&lt;/span&gt; &lt;span class='no'&gt;ActiveRecord&lt;/span&gt;&lt;span class='o'&gt;::&lt;/span&gt;&lt;span class='no'&gt;Base&lt;/span&gt;
  &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;name&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;str&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='n'&gt;str&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;upcase!&lt;/span&gt; &lt;span class='k'&gt;unless&lt;/span&gt; &lt;span class='n'&gt;str&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;nil?&lt;/span&gt;
    &lt;span class='n'&gt;write_attribute&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='ss'&gt;:name&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;str&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Be careful if you use this with &lt;a href='http://moserei.de/index.php/113/activerecord-write_attribute-and-utc-conversion'&gt;Datetime attributes&lt;/a&gt;.&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>Force a USB device to use OHCI</title>
        
        <link href="http://moserei.de/2009/04/21/force-a-usb-device-to-use-ohci.html"/>
        <updated>2009-04-21T00:00:00+02:00</updated>
        <id>jduff.github.com:/2009/04/21/force-a-usb-device-to-use-ohci</id>
        <content type="html">&lt;p&gt;As I described in my previous post I built a cheap USB wireless adapter into my NSLU2. It finds my network and connects without problems. But when I transfer bigger loads of data, it sometimes stops working. The log showed that it disconnects from the USB hub. Other people experiencing similar problems indicated that this was a problem with the ehci_hcd kernel module and &amp;#8220;solved&amp;#8221; by removing this module. But thats definitely not a good idea when your only mass storage device is connected via USB too.&lt;/p&gt;

&lt;p&gt;So I needed to disable the EHCI for the wireless adapter only. That should have no big impact because I don&amp;#8217;t think my network really offers speeds above 12 Mbit/s. Fortunately there is a &lt;a href='http://ernis.prophp.org/b2evo/blogs/index.php?title=usb_device_that_dosn_t_like_ehci_on_linu&amp;amp;more=1&amp;amp;c=1&amp;amp;tb=1&amp;amp;pb=1'&gt;script&lt;/a&gt; by Ernestas Vaiciukevičius that does exactly this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Seems like the link is dead. You can find the script &lt;a href='http://moserei.de/files/linux/force_ohci.sh'&gt;here&lt;/a&gt;. Usage: Create a &lt;a href='http://en.wikipedia.org/wiki/Udev'&gt;udev&lt;/a&gt; &lt;a href='http://www.reactivated.net/writing_udev_rules.html'&gt;rule&lt;/a&gt; that runs it:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;SUBSYSTEM==&amp;quot;usb&amp;quot;, ENV{PRODUCT}==&amp;quot;xxxx/yyyy/*&amp;quot; RUN+=&amp;quot;/usr/local/bin/force_ohci.sh&amp;quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;xxxx and yyyy can be found in lsusb&amp;#8217;s output:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ lsusb
Bus 001 Device 001: ID xxxx:yyyy Device name
[...]&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;For testing reasons you can also run it from the command line:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ ./force_ohci.sh &amp;quot;xxxx:yyyy&amp;quot;&lt;/code&gt;&lt;/pre&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>Wireless NSLU2</title>
        
        <link href="http://moserei.de/2009/04/20/wireless-nslu2.html"/>
        <updated>2009-04-20T00:00:00+02:00</updated>
        <id>jduff.github.com:/2009/04/20/wireless-nslu2</id>
        <content type="html">&lt;p&gt;I bought a &lt;a href='http://en.wikipedia.org/wiki/NSLU2'&gt;NSLU2&lt;/a&gt; some weeks ago. I will use it as printer and scanner server and as an ever running torrent client. As I don&amp;#8217;t want to run a ethernet cable through the walls of our flat, I need wireless network on it. There is a nice &lt;a href='http://www.nslu2-linux.org/wiki/HowTo/AddInternalWireless'&gt;HowTo&lt;/a&gt; on NSLU2-Linux. I got my hands on a wireless usb stick for 15 €, warmed up the soldering iron and got started: You really need a steady hand for soldering onto these tiny contacts.&lt;/p&gt;
&lt;a href='http://www.zooomr.com/photos/moser/7288977/' title='Photo Sharing'&gt;&lt;img alt='IMG_0527' height='375' src='http://static.zooomr.com/images/7288977_fa4ca03fe6.jpg' width='500' /&gt;&lt;/a&gt;
&lt;p&gt;But to my own surprise I managed to:&lt;/p&gt;
&lt;a href='http://www.zooomr.com/photos/moser/7288934/' title='done with soldering'&gt;&lt;img alt='done with soldering' height='375' src='http://static.zooomr.com/images/7288934_e60b2a7965.jpg' width='500' /&gt;&lt;/a&gt;
&lt;p&gt;Inside the case of the NSLU2 there is enough space, so i just taped the new part on top of some capacitors:&lt;/p&gt;
&lt;a href='http://www.zooomr.com/photos/moser/7288959/' title='completed'&gt;&lt;img alt='completed' height='375' src='http://static.zooomr.com/images/7288959_8d96413032.jpg' width='500' /&gt;&lt;/a&gt;
&lt;p&gt;5 minutes later I was really glad to see the device in lsusb.&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>Photos online</title>
        
        <link href="http://moserei.de/2009/04/14/photos-online.html"/>
        <updated>2009-04-14T00:00:00+02:00</updated>
        <id>jduff.github.com:/2009/04/14/photos-online</id>
        <content type="html">&lt;p&gt;I just finished uploading some photos taken during my recent flights. &lt;a href='http://de.zooomr.com/photos/moser/'&gt;See them here&lt;/a&gt;. And I got a new &lt;a href='http://xkcd.com/559/'&gt;hobby&lt;/a&gt;.&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>Multi-line comments in ruby</title>
        
        <link href="http://moserei.de/2009/04/07/multi-line-comments-in-ruby.html"/>
        <updated>2009-04-07T00:00:00+02:00</updated>
        <id>jduff.github.com:/2009/04/07/multi-line-comments-in-ruby</id>
        <content type="html">&lt;p&gt;I keep forgetting how to do them, so I post myself a little reminder here.&lt;/p&gt;

&lt;p&gt;Just put&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='cm'&gt;=begin&lt;/span&gt;
&lt;span class='cm'&gt;...&lt;/span&gt;
&lt;span class='cm'&gt;=end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;around the stuff to be commented out. &lt;strong&gt;There must not be whitespaces before these keywords.&lt;/strong&gt;&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>dm-optlock now on github</title>
        
        <link href="http://moserei.de/2009/03/03/dm-optlock-now-on-github.html"/>
        <updated>2009-03-03T00:00:00+01:00</updated>
        <id>jduff.github.com:/2009/03/03/dm-optlock-now-on-github</id>
        <content type="html">&lt;p&gt;dm-optlock is on &lt;a href='http://github.com/moser/dm-optlock/tree/master'&gt;github&lt;/a&gt; now. It can still be installed as gem:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gem install moser-dm-optlock&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you haven&amp;#8217;t done before, you need to add github to your gem sources:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gem sources -a http://gems.github.com&lt;/code&gt;&lt;/pre&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>dm-optlock v 0.1.4</title>
        
        <link href="http://moserei.de/2009/01/10/dm-optlock-v-014.html"/>
        <updated>2009-01-10T00:00:00+01:00</updated>
        <id>jduff.github.com:/2009/01/10/dm-optlock-v-014</id>
        <content type="html">&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; &lt;a href='http://moserei.de/index.php/80/dm-optlock-now-on-github'&gt;dm-optlock now on github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I released a new version of &lt;a href='http://moserei.de/index.php/27/optimistic-locking-for-datamapper'&gt;dm-optlock&lt;/a&gt;. It is &lt;em&gt;NOT&lt;/em&gt; compatible with v 0.1.2&amp;#8217;s code, because replaced the set_locking_column method by a method called add_locking_column. Your DB should be compatible.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='k'&gt;class&lt;/span&gt; &lt;span class='nc'&gt;Model&lt;/span&gt;
  &lt;span class='kp'&gt;include&lt;/span&gt; &lt;span class='no'&gt;DataMapper&lt;/span&gt;&lt;span class='o'&gt;::&lt;/span&gt;&lt;span class='no'&gt;Resource&lt;/span&gt;
  &lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;.&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;
  &lt;span class='n'&gt;add_locking_column&lt;/span&gt; &lt;span class='ss'&gt;:my_version_col&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;It takes a options hash just like DataMapper&amp;#8217;s property method does. I added it to enforce some options on the locking column.&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>Yahoo! or better Oh-no!</title>
        
        <link href="http://moserei.de/2008/12/21/yahoo-or-better-oh-no.html"/>
        <updated>2008-12-21T00:00:00+01:00</updated>
        <id>jduff.github.com:/2008/12/21/yahoo-or-better-oh-no</id>
        <content type="html">&lt;p&gt;I forgot my Yahoo!-ID for my flickR account. I know it&amp;#8217;s nothing to be proud of&amp;#8230; But what really annoys me is what Yahoo calls their customer support. I sent in their contact form with a description of my problem which I though to be easy to solve. One day later (!) they replied by a standard email describing how to get your lost password (!) and what mistakes one can make when typing one&amp;#8217;s ID.&lt;/p&gt;

&lt;p&gt;That was on Wednesday. Since then I got the same email four times signed by four different employees. Each time I replied with a description of my problem and ~24 hours later the same dumb email reached me.&lt;/p&gt;

&lt;p&gt;In the meantime I already found out my ID using the english help pages (the german copy doesn&amp;#8217;t seem to be complete), but I think I will continue playing mail ping pong with Yahoo for some time.&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>shared git repo + ssh = umask problems </title>
        
        <link href="http://moserei.de/2008/12/19/shared-git-repo-ssh-umask-problems.html"/>
        <updated>2008-12-19T00:00:00+01:00</updated>
        <id>jduff.github.com:/2008/12/19/shared-git-repo-ssh-umask-problems</id>
        <content type="html">&lt;p&gt;When you want to share a little git repository on your own server the first thing that comes to your mind is SSH. It&amp;#8217;s installed virtually everywhere, secure and easy to configure. In the beginning there are no problems, because everyone can clone your repo and if they don&amp;#8217;t change files concurrently even pushing works. About one day latter you get umask problems and start to search the web for solutions. To make it short, here it is:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git repo-config core.sharedRepository true&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This option makes git care about the permission stuff. I wasted about 10 hours of my lifetime for this one and found an odd thing about ~/.ssh/rc:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;umask 002
date &amp;gt; ~/sshrc-executed&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I added the second line, because I wasn&amp;#8217;t sure if it was executed. It was (look at the file permissions):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;...
-rw-rw-r--  1 moser git     29 Dec 19 18:41 sshrc-executed&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But my umask didn&amp;#8217;t last:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;moser@HellAgent:~$ ssh xxx.net -n &amp;#39;umask&amp;#39;
Password: 
0022&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Don&amp;#8217;t know why, if anyone knows tell me please.&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>Waste Separation 2.0</title>
        
        <link href="http://moserei.de/2008/11/03/waste-separation-20.html"/>
        <updated>2008-11-03T00:00:00+01:00</updated>
        <id>jduff.github.com:/2008/11/03/waste-separation-20</id>
        <content type="html">&lt;p&gt;I just went through the pictures I took during our holiday in Barcelona and found this one:&lt;/p&gt;
&lt;a href='http://www.zooomr.com/photos/moser/6702780/' title='Photo Sharing'&gt;&lt;img alt='Waste separation 2.0' height='375' src='http://static.zooomr.com/images/6702780_ef68b40aa9.jpg' width='500' /&gt;&lt;/a&gt;
&lt;p&gt;To be fair I got to say that all the other bins had 3 bags in them :-)&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>How to use IGC data to geotag your photos</title>
        
        <link href="http://moserei.de/2008/10/07/use-igc-data-to-geotag-photos.html"/>
        <updated>2008-10-07T00:00:00+02:00</updated>
        <id>jduff.github.com:/2008/10/07/use-igc-data-to-geotag-photos</id>
        <content type="html">&lt;p&gt;When taking photos on a cross-country flight it&amp;#8217;s not always easy to remember where they were taken. And wouldn&amp;#8217;t it be cool to look at your photos on &lt;a href='http://www.flickr.com/photos/31026828@N04/map/'&gt;flickr's map&lt;/a&gt;? Either you buy a camera with an integrated GPS receiver which automatically stores a geotag in your picture file&amp;#8217;s meta data or you use GPS data that&amp;#8217;s gathered anyway: Your IGC files. What do you need?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='http://freefoote.dview.net/linux_gpscorr.html'&gt;GPS Photo Correlator&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://www.gpsbabel.org/'&gt;GPSBabel&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both programs are available for both Linux and Windows. My article is focused on Linux but the commands on windows will be quite similar. If you are running Debian or Ubuntu you can install these via&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;apt-get install gpscorrelate gpscorrelate-gui gpsbabel&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The GPS Photo Correlator accepts GPS data in the GPX format. So you will need to convert your data into that format:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gpsbabel -i igc -o gpx &amp;lt;infile&amp;gt;.igc &amp;lt;outfile&amp;gt;.gpx&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now lets geotag your files:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gpscorrelate -g &amp;lt;gpxfile&amp;gt; -z +2:00 --show file(s)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&amp;#8220;-z +/-XX:XX&amp;#8221; is needed because the timestamp on your photos is probably not UTC. file(s) is either a list of files (&amp;#8220;DSC2131.JPG DSC2322.JPG&amp;#8221;) or a wildcard expression (&amp;#8221;&lt;em&gt;&amp;#8221; for all photos in the directory or something like &amp;#8220;DSC12&lt;/em&gt;.JPG&amp;#8221;). If you add &amp;#8221;&amp;#8211;no-write&amp;#8221; no EXIF data will be written and you can check if your photos would have been tagged right.&lt;/p&gt;

&lt;p&gt;If you want flickr to use your photos&amp;#8217; EXIF geotags you have to &lt;a href='http://www.flickr.com/account/geo/exif/?from=privacy'&gt;change your account settings&lt;/a&gt;.&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>Optimistic Locking for Datamapper</title>
        
        <link href="http://moserei.de/2008/10/01/optimistic-locking-for-datamapper.html"/>
        <updated>2008-10-01T00:00:00+02:00</updated>
        <id>jduff.github.com:/2008/10/01/optimistic-locking-for-datamapper</id>
        <content type="html">&lt;p&gt;&lt;strong&gt;Update(2009-3-3):&lt;/strong&gt; &lt;a href='http://moserei.de/index.php/80/dm-optlock-now-on-github'&gt;dm-optlock now on github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update(2009-1-10):&lt;/strong&gt; &lt;a href='http://moserei.de/index.php/64/dm-optlock-v-014'&gt;New version&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I should be learning for my test on next tuesday, but coding helps keeping me in a good mood. Here is a little gem I will need in a future project for which I&amp;#8217;ve choosen merb + datamapper. &lt;a href='http://datamapper.org/'&gt;Datamapper&lt;/a&gt; doesn&amp;#8217;t support any row level locking. My code checks if the record you want to save was changed since you loaded it. If it was changed it raises an exception (DataMapper::StaleObjectError). It works quite like &lt;a href='http://ar.rubyonrails.com/classes/ActiveRecord/Locking/Optimistic.html'&gt;ActiveRecord&amp;#8217;s optimistic locking&lt;/a&gt;. You need to define this column in your model you want to be locked:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='n'&gt;property&lt;/span&gt; &lt;span class='ss'&gt;:lock_version&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='nb'&gt;Integer&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:default&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Anywhere in your code where you update your objects you should be prepared to handle the exception:&lt;/p&gt;

&lt;p&gt;&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;  &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='vi'&gt;@obj&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;update_attributes&lt;/span&gt;&lt;span class='p'&gt;({&lt;/span&gt;&lt;span class='ss'&gt;:dummy&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='mi'&gt;123&lt;/span&gt;&lt;span class='p'&gt;})&lt;/span&gt;
    &lt;span class='c1'&gt;#successful&lt;/span&gt;
  &lt;span class='k'&gt;else&lt;/span&gt;
    &lt;span class='c1'&gt;#validation errors?&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;
&lt;span class='k'&gt;rescue&lt;/span&gt; &lt;span class='no'&gt;DataMapper&lt;/span&gt;&lt;span class='o'&gt;::&lt;/span&gt;&lt;span class='no'&gt;StaleObjectError&lt;/span&gt;
  &lt;span class='c1'&gt;#tell the user that he was too slow&lt;/span&gt;
  &lt;span class='c1'&gt;#or even better: show him the conflicts and let him merge the changes&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;The gem can be downloaded here: &lt;a href='http://moserei.de/files/ruby/datamapper/dm-optlock-0.1.0.gem'&gt;dm-optlock-0.1.0.gem&lt;/a&gt; Please let me know what you think of it. I&amp;#8217;ll try and put it on RubyForge, too.&lt;/p&gt;

&lt;p&gt;(00:27) &lt;strong&gt;Little update:&lt;/strong&gt; I added a &amp;#8216;set_locking_column&amp;#8217; method. &lt;a href='http://moserei.de/files/ruby/datamapper/dm-optlock-0.1.2.gem'&gt;dm-optlock-0.1.2.gem&lt;/a&gt;&lt;/p&gt;
&lt;del datetime='2009-03-03T19:13:31+00:00'&gt;
&lt;strong&gt;Update:&lt;/strong&gt;
[dm-optlock is on Rubyforge](http://rubyforge.org/projects/dm-optlock/).
Now you can get it like this:
    gem install dm-optlock
&lt;/del&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>Stable Array Sorting in Ruby</title>
        
        <link href="http://moserei.de/2008/09/18/stable-array-sorting-in-ruby.html"/>
        <updated>2008-09-18T00:00:00+02:00</updated>
        <id>jduff.github.com:/2008/09/18/stable-array-sorting-in-ruby</id>
        <content type="html">&lt;p&gt;Ruby uses some kind of &lt;a href='http://en.wikipedia.org/wiki/Quicksort'&gt;Quicksort&lt;/a&gt; to sort its arrays. Unfortunately Quicksort is not &lt;a href='http://en.wikipedia.org/wiki/Sorting_algorithm#Classification'&gt;stable&lt;/a&gt;. When you get sorted data from your database, which almost certainly sorts faster than anything in Ruby, you sometimes may want the data to be resorted in a stable way.&lt;/p&gt;

&lt;p&gt;I found following &lt;a href='http://codesnippets.joyent.com/posts/show/19'&gt;snippet&lt;/a&gt;:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='k'&gt;class&lt;/span&gt; &lt;span class='nc'&gt;Array&lt;/span&gt;
  &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;stable_sort&lt;/span&gt;
    &lt;span class='n'&gt;n&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;
    &lt;span class='n'&gt;sort_by&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;&lt;span class='o'&gt;|&lt;/span&gt;&lt;span class='n'&gt;x&lt;/span&gt;&lt;span class='o'&gt;|&lt;/span&gt; &lt;span class='n'&gt;n&lt;/span&gt;&lt;span class='o'&gt;+=&lt;/span&gt; &lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt; &lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='n'&gt;x&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;n&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt;&lt;span class='p'&gt;}&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;I extended it to accept a block like the original sort method does:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='k'&gt;class&lt;/span&gt; &lt;span class='nc'&gt;Array&lt;/span&gt;
  &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;stable_sort&lt;/span&gt;
    &lt;span class='n'&gt;n&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;
    &lt;span class='n'&gt;c&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='nb'&gt;lambda&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt; &lt;span class='o'&gt;|&lt;/span&gt;&lt;span class='n'&gt;x&lt;/span&gt;&lt;span class='o'&gt;|&lt;/span&gt; &lt;span class='n'&gt;n&lt;/span&gt;&lt;span class='o'&gt;+=&lt;/span&gt; &lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt; &lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='n'&gt;x&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;n&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt;&lt;span class='p'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='nb'&gt;block_given?&lt;/span&gt;
      &lt;span class='n'&gt;sort&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt; &lt;span class='o'&gt;|&lt;/span&gt;&lt;span class='n'&gt;a&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;b&lt;/span&gt;&lt;span class='o'&gt;|&lt;/span&gt;
        &lt;span class='k'&gt;yield&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;c&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;call&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;a&lt;/span&gt;&lt;span class='p'&gt;),&lt;/span&gt; &lt;span class='n'&gt;c&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;call&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;b&lt;/span&gt;&lt;span class='p'&gt;))&lt;/span&gt;        
      &lt;span class='p'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;else&lt;/span&gt;
      &lt;span class='n'&gt;sort_by&lt;/span&gt; &lt;span class='o'&gt;&amp;amp;&lt;/span&gt;&lt;span class='n'&gt;c&lt;/span&gt;
    &lt;span class='k'&gt;end&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>Mergesort in Ruby</title>
        
        <link href="http://moserei.de/2008/09/18/mergesort-in-ruby.html"/>
        <updated>2008-09-18T00:00:00+02:00</updated>
        <id>jduff.github.com:/2008/09/18/mergesort-in-ruby</id>
        <content type="html">&lt;p&gt;While playing around with stable sorting I implemented &lt;a href='http://en.wikipedia.org/wiki/Merge_sort'&gt;Mergesort&lt;/a&gt;.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='k'&gt;class&lt;/span&gt; &lt;span class='nc'&gt;Array&lt;/span&gt;
  &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;mergesort&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;&amp;amp;&lt;/span&gt;&lt;span class='n'&gt;cmp&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='n'&gt;cmp&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; &lt;span class='kp'&gt;nil&lt;/span&gt;
      &lt;span class='n'&gt;cmp&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='nb'&gt;lambda&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt; &lt;span class='o'&gt;|&lt;/span&gt;&lt;span class='n'&gt;a&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;b&lt;/span&gt;&lt;span class='o'&gt;|&lt;/span&gt; &lt;span class='n'&gt;a&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;=&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;b&lt;/span&gt; &lt;span class='p'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;end&lt;/span&gt;
    &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='n'&gt;size&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;=&lt;/span&gt; &lt;span class='mi'&gt;1&lt;/span&gt;
      &lt;span class='nb'&gt;self&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;dup&lt;/span&gt;
    &lt;span class='k'&gt;else&lt;/span&gt;
       &lt;span class='n'&gt;halves&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='nb'&gt;split&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;map&lt;/span&gt;&lt;span class='p'&gt;{&lt;/span&gt; &lt;span class='o'&gt;|&lt;/span&gt;&lt;span class='n'&gt;half&lt;/span&gt;&lt;span class='o'&gt;|&lt;/span&gt;
        &lt;span class='n'&gt;half&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;mergesort&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;&amp;amp;&lt;/span&gt;&lt;span class='n'&gt;cmp&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
      &lt;span class='p'&gt;}&lt;/span&gt;
      &lt;span class='n'&gt;merge&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='o'&gt;*&lt;/span&gt;&lt;span class='n'&gt;halves&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='o'&gt;&amp;amp;&lt;/span&gt;&lt;span class='n'&gt;cmp&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='k'&gt;end&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;

 
  &lt;span class='kp'&gt;protected&lt;/span&gt;
  &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;split&lt;/span&gt;
    &lt;span class='n'&gt;n&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;length&lt;/span&gt; &lt;span class='o'&gt;/&lt;/span&gt; &lt;span class='mi'&gt;2&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;floor&lt;/span&gt; &lt;span class='o'&gt;-&lt;/span&gt; &lt;span class='mi'&gt;1&lt;/span&gt;
    &lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='nb'&gt;self&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;.n&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='nb'&gt;self&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='n'&gt;n&lt;/span&gt;&lt;span class='o'&gt;+&lt;/span&gt;&lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;.&lt;/span&gt;&lt;span class='o'&gt;-&lt;/span&gt;&lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='o'&gt;]]&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;

  &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;merge&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;first&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;second&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='o'&gt;&amp;amp;&lt;/span&gt;&lt;span class='n'&gt;predicate&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='n'&gt;result&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='o'&gt;[]&lt;/span&gt;
    &lt;span class='k'&gt;until&lt;/span&gt; &lt;span class='n'&gt;first&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;empty?&lt;/span&gt; &lt;span class='o'&gt;||&lt;/span&gt; &lt;span class='n'&gt;second&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;empty?&lt;/span&gt;
     &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='n'&gt;predicate&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;call&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;first&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;first&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;second&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;first&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;=&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;
        &lt;span class='n'&gt;result&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class='n'&gt;first&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;shift&lt;/span&gt;
      &lt;span class='k'&gt;else&lt;/span&gt;
        &lt;span class='n'&gt;result&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class='n'&gt;second&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;shift&lt;/span&gt;
      &lt;span class='k'&gt;end&lt;/span&gt; 
    &lt;span class='k'&gt;end&lt;/span&gt;
    &lt;span class='n'&gt;result&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;concat&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;first&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;concat&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;second&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
  &lt;span class='k'&gt;end&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;It is not suitable for productive use as it&amp;#8217;s quite slow. It&amp;#8217;s about ten times slower than the stable_sort method from my &lt;a href='http://moserei.de/2008/09/18/stable-array-sorting-in-ruby.html'&gt;another post&lt;/a&gt;. A little benchmark sorting an array of 2,000,000 random integers:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;                user     system      total        real
Original Sort 0.630000   0.010000   0.640000 (  0.639860)
Stable Sort  12.780000   0.700000  13.480000 ( 13.477982)
Mergesort   109.170000  13.420000 122.590000 (122.617323)&lt;/code&gt;&lt;/pre&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>Advanced Array Sorting in Ruby</title>
        
        <link href="http://moserei.de/2008/09/16/advanced-array-sorting-in-ruby.html"/>
        <updated>2008-09-16T00:00:00+02:00</updated>
        <id>jduff.github.com:/2008/09/16/advanced-array-sorting-in-ruby</id>
        <content type="html">&lt;p&gt;While developing a member management application for my soaring club I found out quite a little about sorting arrays in Ruby. Rubys &lt;a href='http://www.ruby-doc.org/core/classes/Array.html#M002208'&gt;sort&lt;/a&gt; uses the operator &amp;lt;=&amp;gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;irb(main):001:0&amp;gt; 1 &amp;lt;=&amp;gt; 2
=&amp;gt; -1
irb(main):002:0&amp;gt; 1 &amp;lt;=&amp;gt; 0
=&amp;gt; 1
irb(main):003:0&amp;gt; 1 &amp;lt;=&amp;gt; 1
=&amp;gt; 0&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;By implementing it on your class you can specify a way in which an array of instances should be sorted. Here is a fragment of my Member class:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;&amp;lt;=&amp;gt;&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;b&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
  &lt;span class='nb'&gt;name&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;=&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;b&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;name&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;My members will be sorted by their name. But sometimes you need a special sorting. Thats why the sort method accepts a block to specify a way of sorting&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='n'&gt;arr&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;sort!&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt; &lt;span class='o'&gt;|&lt;/span&gt;&lt;span class='n'&gt;a&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;b&lt;/span&gt;&lt;span class='o'&gt;|&lt;/span&gt;
  &lt;span class='n'&gt;a&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;birthdate&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;yday&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;=&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;b&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;birthdate&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;yday&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This is the sorting I needed for a list of birthdays. Sure enough you can do anything inside the block as long as it returns -1, 0 or 1. It&amp;#8217;s no problem to sort by 2 attributes:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='n'&gt;arr&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;sort!&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt; &lt;span class='o'&gt;|&lt;/span&gt;&lt;span class='n'&gt;a&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;b&lt;/span&gt;&lt;span class='o'&gt;|&lt;/span&gt;
  &lt;span class='n'&gt;r&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;a&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;birthdate&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;yday&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;=&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;b&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;birtdate&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;yday&lt;/span&gt;
  &lt;span class='n'&gt;r&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;a&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;name&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;=&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;b&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;name&lt;/span&gt; &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='n'&gt;r&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;
  &lt;span class='n'&gt;r&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
    <entry>
        <title>Started!</title>
        
        <link href="http://moserei.de/2008/09/15/started.html"/>
        <updated>2008-09-15T00:00:00+02:00</updated>
        <id>jduff.github.com:/2008/09/15/started</id>
        <content type="html">&lt;p&gt;The rainy weather should actually encourage me to study analysis, but it rather made me go through old email. I found one reminding me of this domain I registered some time ago, which I never really used. So I thought I could finally join the community of bloggers and kill some time by installing Wordpress and playing around.&lt;/p&gt;</content>
        <author>
            <name></name>
            <uri></uri>
        </author>
    </entry>
    
</feed>

