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

<channel>
	<title>A Tempest of Thoughts &#187; Ruby</title>
	<atom:link href="http://tempe.st/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://tempe.st</link>
	<description>aka blog.to_int(:inig)</description>
	<lastBuildDate>Thu, 07 Apr 2011 08:24:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>Cookies in iFrames: how bashing my head on the table made them work in Internet Explorer</title>
		<link>http://tempe.st/2010/11/cookies-in-iframes-how-bashing-my-head-on-the-table-made-them-work-in-internet-explorer/</link>
		<comments>http://tempe.st/2010/11/cookies-in-iframes-how-bashing-my-head-on-the-table-made-them-work-in-internet-explorer/#comments</comments>
		<pubDate>Fri, 12 Nov 2010 16:31:46 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Random Stuff]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[apache2]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[etags]]></category>
		<category><![CDATA[explorer]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://tempe.st/?p=329</guid>
		<description><![CDATA[While working on our TTGPassport our valiant team hit a wall that most programmers hit sooner or later when working with iframes: cookies won&#8217;t work with Internet Explorer, and you will lose your session. The internet is full or remedies for this unnerving problem, most of them revolving on pseudo-magically setting the P3P header. I [...]]]></description>
			<content:encoded><![CDATA[	<p>While working on our <a href="http://ttgincontri.it">TTGPassport</a> our valiant team hit a wall that most programmers hit sooner or later when working with iframes: cookies won&#8217;t work with Internet Explorer, and you will lose your session.</p>
	<p>The internet is full or remedies for this unnerving problem, most of them revolving on pseudo-magically setting the <em>P3P</em> header. I don&#8217;t believe in pseudo-magic, so I kept googling for answers, until I found <a href="http://stackoverflow.com/questions/389456/cookie-blocked-not-saved-in-iframe-in-internet-explorer">this informing post</a>.</p>
	<p>I diligently ran through the suggestions but we had random session losses, with no reasonable explanation. We were setting our <em>P3P</em> header in a before filter (Rails application), like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> ApplicationController <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>
  before_filter <span style="color:#ff3333; font-weight:bold;">:set_p3p</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> set_p3p
    response.<span style="color:#9900CC;">headers</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;P3P&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>=<span style="color:#996600;">'CP=&quot;NOI DSP LAW NID&quot;'</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>  
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

	<p>Fearing Rails could be the culprit I changed our Apache configuration to set the header on every request, using the following directive:</p>

<div class="wp_syntax"><div class="code"><pre class="httpd" style="font-family:monospace;">Header set P3P &quot;CP=\&quot;NOI DSP LAW NID\&quot;&quot;</pre></div></div>

	<p>Unfortunately even bypassing Rails didn&#8217;t help. I was even unsure of why sometimes it worked and sometimes it didn&#8217;t (basically when explorer shows the evil red eye on the bottom of the page it means it&#8217;s blocking your cookies).</p>
	<p>I started playing around with Firebug to see what could be the problem, and finally a little lightbulb lit on top of my head: the pages that broke the session didn&#8217;t have the <em>P3P</em> header, and instead they had an <em>ETag</em> header. That means something was adding the ETag and that the browser recalled the content of the page from its cache, thus bypassing <em>P3P</em> and upsetting explorer. I disabled <em>ETags</em> in Apache:</p>

<div class="wp_syntax"><div class="code"><pre class="apache2" style="font-family:monospace;">Header unset ETag
FileETag None</pre></div></div>

	<p>Guess what? It didn&#8217;t work. Something was still setting the <em>ETag</em> header and bypassing my beloved and much needed <em>P3P</em>. The only culprit could be Ruby on Rails. I googled some more but nothing really told me how to disable <em>ETags</em> so I had to resort to some monkey patching:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> ActionController
  <span style="color:#9966CC; font-weight:bold;">class</span> Request
    <span style="color:#9966CC; font-weight:bold;">def</span> etag_matches?<span style="color:#006600; font-weight:bold;">&#40;</span>etag<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0000FF; font-weight:bold;">false</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">class</span> Response
    <span style="color:#9966CC; font-weight:bold;">def</span> etag?
      <span style="color:#0000FF; font-weight:bold;">true</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

	<p>I asked our strong, silent project manager to test it because I was crossing my fingers too hard, and, finally, it worked, no <em>ETags</em> and our <em>P3P</em> header where we expected it.</p>
	<p>I hope you are reading this article because you had the same problem we had, and I hope it will help you as it helped us!</p>

 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2010/11/cookies-in-iframes-how-bashing-my-head-on-the-table-made-them-work-in-internet-explorer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Continous Integration with RunCodeRun</title>
		<link>http://tempe.st/2010/02/continous-integration-with-runcoderun/</link>
		<comments>http://tempe.st/2010/02/continous-integration-with-runcoderun/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 14:09:36 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[mikamai]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[rsc]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby social club]]></category>
		<category><![CDATA[runcoderun]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://tempe.st/?p=308</guid>
		<description><![CDATA[Last thursday MIKAMAI hosted a Ruby Social Club meeting. Here&#8217;s the slides for my presentation. Continous Integration For The Lazy ProgrammerView more presentations from intinig.]]></description>
			<content:encoded><![CDATA[	<p>Last thursday MIKAMAI hosted a Ruby Social Club meeting. Here&#8217;s the slides for my presentation. </p>
<div style="width:425px;text-align:left" id="__ss_3074998"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/intinig/continous-integration-for-the-lazy-programmer" title="Continous Integration For The Lazy Programmer">Continous Integration For The Lazy Programmer</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=continousintegrationforthelazyprogrammer-100204174823-phpapp02&#38;rel=0&#38;stripped_title=continous-integration-for-the-lazy-programmer" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=continousintegrationforthelazyprogrammer-100204174823-phpapp02&#38;rel=0&#38;stripped_title=continous-integration-for-the-lazy-programmer" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object><div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">presentations</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/intinig">intinig</a>.</div></div>

 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2010/02/continous-integration-with-runcoderun/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Updated Language Redirect Extension for Radiant</title>
		<link>http://tempe.st/2009/08/updated-language-redirect-extension-for-radiant/</link>
		<comments>http://tempe.st/2009/08/updated-language-redirect-extension-for-radiant/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 10:41:34 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Radiant]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[extensions]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[language redirect]]></category>

		<guid isPermaLink="false">http://tempe.st/?p=301</guid>
		<description><![CDATA[Thanks to the great work of netzpirat, the good old Language Redirect Extension has been updated to work with Radiant 0.8.0. Thanks netzpirat!]]></description>
			<content:encoded><![CDATA[	<p>Thanks to the great work of <a href="http://github.com/netzpirat">netzpirat</a>, the good old <a href="http://github.com/intinig/radiant_language_redirect_extension/tree/master">Language Redirect Extension</a> has been updated to work with Radiant 0.8.0.</p>
	<p>Thanks netzpirat!</p>

 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2009/08/updated-language-redirect-extension-for-radiant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache Vhost Templating</title>
		<link>http://tempe.st/2009/04/apache-vhost-templating/</link>
		<comments>http://tempe.st/2009/04/apache-vhost-templating/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 12:24:06 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apache2]]></category>

		<guid isPermaLink="false">http://tempe.st/?p=288</guid>
		<description><![CDATA[In Mikamai our deployment platform of choice is Ubuntu Linux. I like a lot the way Apache is set up on Debian based distributions, with the sites-available directory, but nonetheless creating new virtual hosts is a royal PITA. Today I finally solved the problem once and for all via a super simple ruby templating script. [...]]]></description>
			<content:encoded><![CDATA[	<p>In <a href="http://mikamai.com">Mikamai</a> our deployment platform of choice is Ubuntu Linux. I like a lot the way Apache is set up on Debian based distributions, with the sites-available directory, but nonetheless creating new virtual hosts is a royal PITA.</p>
	<p>Today I finally solved the problem once and for all via a super simple ruby templating script. Here it is, it uses a nice gem, optiflags, to parse the commandline arguments:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'optiflag'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">module</span> MyOptions extend OptiFlagSet
  flag <span style="color:#996600;">&quot;d&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    description <span style="color:#996600;">&quot;The domain name the vhost should serve&quot;</span>
    long_form <span style="color:#996600;">&quot;domain&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  optional_flag <span style="color:#996600;">&quot;a&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    description <span style="color:#996600;">&quot;Email of the admin. If not specified defaults to info@domain&quot;</span>
    long_form <span style="color:#996600;">&quot;admin&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  optional_switch_flag <span style="color:#996600;">&quot;w&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    description <span style="color:#996600;">&quot;Adds www to non www redirection&quot;</span>
    long_form <span style="color:#996600;">&quot;www_redirect&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  and_process!
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
flags = MyOptions.<span style="color:#9900CC;">flags</span>
&nbsp;
admin = flags.<span style="color:#9900CC;">a</span> ? flags.<span style="color:#9900CC;">a</span> : <span style="color:#996600;">&quot;info@#{flags.d}&quot;</span>
domain = flags.<span style="color:#9900CC;">d</span>
quoted_domain = flags.<span style="color:#9900CC;">d</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>\.<span style="color:#006600; font-weight:bold;">/</span>, <span style="color:#996600;">&quot;<span style="color:#000099;">\\</span>.&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
TEMPLATE=<span style="color:#006600; font-weight:bold;">&lt;&lt;-</span>EOT
<span style="color:#006600; font-weight:bold;">&lt;</span>VirtualHost <span style="color:#006600; font-weight:bold;">*</span>:<span style="color:#006666;">80</span><span style="color:#006600; font-weight:bold;">&gt;</span>
        ServerName <span style="color:#008000; font-style:italic;">#{domain}</span>
        ServerAdmin <span style="color:#008000; font-style:italic;">#{admin} </span>
&nbsp;
        DocumentRoot <span style="color:#006600; font-weight:bold;">/</span>var<span style="color:#006600; font-weight:bold;">/</span>apps<span style="color:#006600; font-weight:bold;">/</span><span style="color:#008000; font-style:italic;">#{domain}</span>
        <span style="color:#006600; font-weight:bold;">&lt;</span>Directory <span style="color:#006600; font-weight:bold;">/&gt;</span>
                Options FollowSymLinks
                AllowOverride None
        <span style="color:#006600; font-weight:bold;">&lt;/</span>Directory<span style="color:#006600; font-weight:bold;">&gt;</span>
        <span style="color:#006600; font-weight:bold;">&lt;</span>Directory <span style="color:#006600; font-weight:bold;">/</span>var<span style="color:#006600; font-weight:bold;">/</span>apps<span style="color:#006600; font-weight:bold;">/</span><span style="color:#008000; font-style:italic;">#{domain}&gt;</span>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All 
                Order allow,deny
                allow from all
        <span style="color:#006600; font-weight:bold;">&lt;/</span>Directory<span style="color:#006600; font-weight:bold;">&gt;</span>
&nbsp;
        ErrorLog <span style="color:#006600; font-weight:bold;">/</span>var<span style="color:#006600; font-weight:bold;">/</span>log<span style="color:#006600; font-weight:bold;">/</span>apache2<span style="color:#006600; font-weight:bold;">/</span><span style="color:#008000; font-style:italic;">#{domain}.log</span>
&nbsp;
        <span style="color:#008000; font-style:italic;"># Possible values include: debug, info, notice, warn, error, crit,</span>
        <span style="color:#008000; font-style:italic;"># alert, emerg.</span>
        LogLevel warn
&nbsp;
        CustomLog <span style="color:#006600; font-weight:bold;">/</span>var<span style="color:#006600; font-weight:bold;">/</span>log<span style="color:#006600; font-weight:bold;">/</span>apache2<span style="color:#006600; font-weight:bold;">/</span><span style="color:#008000; font-style:italic;">#{domain}.log combined</span>
&nbsp;
<span style="color:#006600; font-weight:bold;">&lt;/</span>VirtualHost<span style="color:#006600; font-weight:bold;">&gt;</span>
EOT
&nbsp;
REDIRECTION=<span style="color:#006600; font-weight:bold;">&lt;&lt;-</span>EOT
<span style="color:#006600; font-weight:bold;">&lt;</span>VirtualHost <span style="color:#006600; font-weight:bold;">*</span>:<span style="color:#006666;">80</span><span style="color:#006600; font-weight:bold;">&gt;</span>
  ServerName www.<span style="color:#008000; font-style:italic;">#{domain}</span>
  ServerAdmin <span style="color:#008000; font-style:italic;">#{admin} </span>
&nbsp;
  RewriteEngine On
  RewriteCond <span style="color:#006600; font-weight:bold;">%</span><span style="color:#006600; font-weight:bold;">&#123;</span>HTTP_HOST<span style="color:#006600; font-weight:bold;">&#125;</span> ^www\\.<span style="color:#008000; font-style:italic;">#{quoted_domain}</span>
  RewriteRule <span style="color:#006600; font-weight:bold;">&#40;</span>.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span> http:<span style="color:#006600; font-weight:bold;">//</span><span style="color:#008000; font-style:italic;">#{domain}/$1 [R=301,L]</span>
<span style="color:#006600; font-weight:bold;">&lt;/</span>VirtualHost<span style="color:#006600; font-weight:bold;">&gt;</span>
EOT
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> TEMPLATE
<span style="color:#CC0066; font-weight:bold;">puts</span> REDIRECTION <span style="color:#9966CC; font-weight:bold;">if</span> flags.<span style="color:#9900CC;">w</span>?</pre></div></div>

	<p>I use it like this:</p>
<pre>
$ vhgen -d domain.com -w &gt; /etc/apache2/sites-available/my_vhost
$ a2ensite my_vhost
</pre>

 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2009/04/apache-vhost-templating/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The unrestful programmer</title>
		<link>http://tempe.st/2009/04/the-unrestful-programmer/</link>
		<comments>http://tempe.st/2009/04/the-unrestful-programmer/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 14:21:08 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[couchdb]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[rspec]]></category>

		<guid isPermaLink="false">http://tempe.st/?p=285</guid>
		<description><![CDATA[Yesterday in Mikamai we had a Ruby Social Club meeting. I did a small presentation about the need to never stop learning. Here&#8217;s the slides: New TechsView more presentations from intinig.]]></description>
			<content:encoded><![CDATA[	<p>Yesterday in <a href="http://mikamai.com">Mikamai</a> we had a Ruby Social Club meeting. I did a small presentation about the need to never stop learning. Here&#8217;s the slides:</p>
<div style="width:425px;text-align:left" id="__ss_1301945"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/intinig/new-techs?type=powerpoint" title="New Techs">New Techs</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=newtechs-090416162943-phpapp02&#38;stripped_title=new-techs" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=newtechs-090416162943-phpapp02&#38;stripped_title=new-techs" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object><div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">presentations</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/intinig">intinig</a>.</div></div>

 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2009/04/the-unrestful-programmer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Combinatorics for fun and profit</title>
		<link>http://tempe.st/2008/11/combinatorics-for-fun-and-profit/</link>
		<comments>http://tempe.st/2008/11/combinatorics-for-fun-and-profit/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 08:53:11 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[combinatorics]]></category>

		<guid isPermaLink="false">http://tempe.st/?p=258</guid>
		<description><![CDATA[During my programming for fun moments I tend to always encounter a problem that needs to find combinations without repetitions for a set of data (numbers, objects, strings, letters, ...). I have never been able to solve that problem in a way that satisfied me, and the languages I used didn&#8217;t have libraries for combinatorics [...]]]></description>
			<content:encoded><![CDATA[	<p>During my programming for fun moments I tend to always encounter a problem that needs to find combinations without repetitions for a set of data (numbers, objects, strings, letters, ...).</p>
	<p>I have never been able to solve that problem in a way that satisfied me, and the languages I used didn&#8217;t have libraries for combinatorics that had a way to generate combinations without repetitions.</p>
	<p>Yesterday a good friend of mine introduced me to the <a href="http://www.setgame.com">Set Puzzle</a>, and, like I did for <a href="http://tempe.st/2008/10/word-cheat-a-simple-anagram-engine">Word Challenge</a> I had to try and attack the problem from a programming angle. </p>
	<p>To do that I had to find once and for all a reusable way to generate combinations without repetitions. I did this time, and <a href="http://github.com/intinig/setsolver/tree/master">SetSolver</a> was born.</p>
	<p>You can check it out on <a href="http://github.com/intinig/setsolver/tree/master">GitHub</a>, but I can&#8217;t help myself and not post the combinatorics code on this blog <img src='http://tempe.st/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> ArrayExtensions
  <span style="color:#9966CC; font-weight:bold;">def</span> combinations_without_repetitions<span style="color:#006600; font-weight:bold;">&#40;</span>k<span style="color:#006600; font-weight:bold;">&#41;</span>
    combine<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>, k<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  private
  <span style="color:#9966CC; font-weight:bold;">def</span> combine<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">array</span>, k<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC0066; font-weight:bold;">array</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">if</span> k == <span style="color:#CC0066; font-weight:bold;">array</span>.<span style="color:#9900CC;">size</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#CC0066; font-weight:bold;">array</span>.<span style="color:#9900CC;">collect</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>e<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">&#91;</span>e<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">if</span> k == <span style="color:#006666;">1</span>  
    results = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#CC0066; font-weight:bold;">array</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span>..<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">array</span>.<span style="color:#9900CC;">size</span> <span style="color:#006600; font-weight:bold;">-</span> k<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">each_with_index</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>val, idx<span style="color:#006600; font-weight:bold;">|</span>
      results <span style="color:#006600; font-weight:bold;">+</span>= combine<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">array</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#40;</span>idx<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>..<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>, k <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">collect</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>e<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">&#91;</span>val, e<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">flatten</span><span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    results
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">Array</span>.<span style="color:#9900CC;">class_eval</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#9966CC; font-weight:bold;">include</span> ArrayExtensions
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>



 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2008/11/combinatorics-for-fun-and-profit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Word Cheat, a simple anagram engine</title>
		<link>http://tempe.st/2008/10/word-cheat-a-simple-anagram-engine/</link>
		<comments>http://tempe.st/2008/10/word-cheat-a-simple-anagram-engine/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 08:56:26 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[anagrams]]></category>

		<guid isPermaLink="false">http://tempe.st/?p=256</guid>
		<description><![CDATA[Those of you who follow this blog since its inception will be aware of my obsession with word games, and specifically algorithms that solve word games. Yesterday I was playing Word Challenge on Facebook, a simple game where you have to find all the words that can be composed with six random letters. After a [...]]]></description>
			<content:encoded><![CDATA[	<p>Those of you who follow this blog since its inception will be aware of my obsession with word games, and specifically <a href="http://giovanniintini.it/anagrams/">algorithms that solve word games</a>.</p>
	<p>Yesterday I was playing Word Challenge on Facebook, a simple game where you have to find all the words that can be composed with six random letters. After a couple of trials I decided to try and solve it with a ruby program, but since I didn&#8217;t want to use my previous code I decided to try a new approach to solve this problem.</p>
	<p>First of all I took an extensive <a href="http://www.yorku.ca/lbianchi/italian.html">list of Italian words</a> and filtered it to suit my needs, leaving only the words ranging from three to six letters.</p>
	<p>Once I had my wordlist I had to build a data structure that could be used for fast anagrams retrieval, thus the <em>WordHash</em> class was born.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> WordHash
  attr_reader <span style="color:#ff3333; font-weight:bold;">:words</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>wordlist<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@words</span> = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
    wordlist.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>word<span style="color:#006600; font-weight:bold;">|</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@words</span>.<span style="color:#9900CC;">has_key</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>w = word.<span style="color:#9900CC;">strip</span>.<span style="color:#9900CC;">signature</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#0066ff; font-weight:bold;">@words</span><span style="color:#006600; font-weight:bold;">&#91;</span>w<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> word.<span style="color:#9900CC;">strip</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>
        <span style="color:#0066ff; font-weight:bold;">@words</span><span style="color:#006600; font-weight:bold;">&#91;</span>w<span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#006600; font-weight:bold;">&#91;</span>word.<span style="color:#9900CC;">strip</span><span style="color:#006600; font-weight:bold;">&#93;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> get_anagrams<span style="color:#006600; font-weight:bold;">&#40;</span>word<span style="color:#006600; font-weight:bold;">&#41;</span>
    result = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    wordlist = <span style="color:#0066ff; font-weight:bold;">@words</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>k,w<span style="color:#006600; font-weight:bold;">|</span>
      result <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> w <span style="color:#9966CC; font-weight:bold;">if</span> word.<span style="color:#9900CC;">contains</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>k<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    result
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

	<p>This class makes use of two helper methods I added to <em>String</em>, that I think should be really part of the Ruby standard library:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> StringExtensions
  <span style="color:#9966CC; font-weight:bold;">def</span> signature
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">sort</span>.<span style="color:#9900CC;">join</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> contains?<span style="color:#006600; font-weight:bold;">&#40;</span>search<span style="color:#006600; font-weight:bold;">&#41;</span>
   !<span style="color:#CC00FF; font-weight:bold;">Regexp</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>search.<span style="color:#9900CC;">signature</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;.*&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">signature</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">String</span>.<span style="color:#9900CC;">class_eval</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#9966CC; font-weight:bold;">include</span> StringExtensions
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

 
The way it all works is quite simple, I build a Hash whose keys are the different signatures of words in the wordlist and whose values are arrays made up by the words with the same signature, so fetching all the anagrams for a word means just accessing word_hash[word.signature].
	<p>The <em>get_anagrams</em> method is used to also get anagrams with a length less than that of the original word.</p>
	<p>The whole project, complete with tests and a helper script is available on <a href="http://github.com/intinig/word_cheat/tree/master">GitHub</a>, feel free to contribute.</p>
	<p>Also, big thanks to Stefano Cobianchi, who contributed with the <em>contains?</em> method, that I really couldn&#8217;t code <img src='http://tempe.st/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2008/10/word-cheat-a-simple-anagram-engine/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Two improvements to your Capfiles</title>
		<link>http://tempe.st/2008/10/two-improvements-to-your-capfiles/</link>
		<comments>http://tempe.st/2008/10/two-improvements-to-your-capfiles/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 17:45:36 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[capfile]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[recipes]]></category>

		<guid isPermaLink="false">http://tempe.st/?p=251</guid>
		<description><![CDATA[I have lately started using a pattern that has become quite common among capistrano users: setting the server names and locations in a task. Doing this allows you to have multiple deployment environments, like development, staging, production, and so on. desc &#34;deploy to development environment&#34; task :development do set :deploy_to, &#34;/var/apps/#{application}&#34; &#160; role :web, &#34;servername.mikamai.com&#34;, [...]]]></description>
			<content:encoded><![CDATA[	<p>I have lately started using a pattern that has become quite common among capistrano users: setting the server names and locations in a task. Doing this allows you to have multiple deployment environments, like <em>development</em>, <em>staging</em>, <em>production</em>, and so on.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">desc <span style="color:#996600;">&quot;deploy to development environment&quot;</span>
task <span style="color:#ff3333; font-weight:bold;">:development</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  set <span style="color:#ff3333; font-weight:bold;">:deploy_to</span>, <span style="color:#996600;">&quot;/var/apps/#{application}&quot;</span>
&nbsp;
  role <span style="color:#ff3333; font-weight:bold;">:web</span>, <span style="color:#996600;">&quot;servername.mikamai.com&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:primary</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
  role <span style="color:#ff3333; font-weight:bold;">:app</span>, <span style="color:#996600;">&quot;servername.mikamai.com&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:primary</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
  role <span style="color:#ff3333; font-weight:bold;">:db</span>, <span style="color:#996600;">&quot;servername.mikamai.com&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:primary</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
&nbsp;
  set <span style="color:#ff3333; font-weight:bold;">:user</span>, <span style="color:#996600;">&quot;username&quot;</span>
  set <span style="color:#ff3333; font-weight:bold;">:password</span>, <span style="color:#996600;">&quot;secr3t&quot;</span>
  set <span style="color:#ff3333; font-weight:bold;">:remote_mysqldump</span>, <span style="color:#996600;">&quot;/usr/bin/mysqldump&quot;</span>
&nbsp;
  set <span style="color:#ff3333; font-weight:bold;">:db_user</span>, <span style="color:#996600;">&quot;username&quot;</span>
  set <span style="color:#ff3333; font-weight:bold;">:db_password</span>, <span style="color:#996600;">&quot;secre7&quot;</span>
  set <span style="color:#ff3333; font-weight:bold;">:db_name</span>, <span style="color:#996600;">&quot;db_name&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

	<p>This technique has proven itself to be really useful, especially when clients start to ask for deployments on their test servers, and you still want to be able to deploy to your development servers.</p>
	<p>While refactoring my Capfiles I also took the time to rewrite the <strong>drupal:db</strong> namespace, adding the much needed tasks that allow you dump the remote databases and download them to your development box.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  namespace <span style="color:#ff3333; font-weight:bold;">:db</span> <span style="color:#9966CC; font-weight:bold;">do</span>    
    namespace <span style="color:#ff3333; font-weight:bold;">:dump</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      desc <span style="color:#996600;">&quot;Deletes old database dumps, leaves only the latest on the server&quot;</span>
      task <span style="color:#ff3333; font-weight:bold;">:cleanup</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:db</span> <span style="color:#9966CC; font-weight:bold;">do</span>
        dumps = capture<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;ls -xt #{shared_path}/dumps&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0066; font-weight:bold;">split</span>.<span style="color:#9900CC;">reverse</span>
        run <span style="color:#996600;">&quot;cd #{shared_path}/dumps; rm #{dumps[0..-2].join(&quot;</span> <span style="color:#996600;">&quot;)}&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      desc <span style="color:#996600;">&quot;Dumps the local database&quot;</span>
      task <span style="color:#ff3333; font-weight:bold;">:local</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:db</span> <span style="color:#9966CC; font-weight:bold;">do</span>
        <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#CC00FF; font-weight:bold;">RuntimeError</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;failed dump&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#CC0066; font-weight:bold;">system</span> <span style="color:#996600;">&quot;#{local_mysqldump} -u #{local_db_user} --password=#{local_db_password} #{local_db_name} &gt; dump.sql&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      namespace <span style="color:#ff3333; font-weight:bold;">:remote</span> <span style="color:#9966CC; font-weight:bold;">do</span>
        desc <span style="color:#996600;">&quot;Dumps the remote database&quot;</span>
        task <span style="color:#ff3333; font-weight:bold;">:default</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:db</span> <span style="color:#9966CC; font-weight:bold;">do</span>
          filename = <span style="color:#996600;">&quot;#{Time.now.to_i.to_s}.dump.sql&quot;</span>
          run <span style="color:#996600;">&quot;cd #{shared_path}/dumps; #{remote_mysqldump} -u #{db_user} --password=#{db_password} #{db_name} &gt; #{filename}&quot;</span>
          run <span style="color:#996600;">&quot;cd #{shared_path}/dumps; bzip2 #{filename}&quot;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>          
&nbsp;
        namespace <span style="color:#ff3333; font-weight:bold;">:download</span> <span style="color:#9966CC; font-weight:bold;">do</span>
          desc <span style="color:#996600;">&quot;Dumps and downloads the remote database&quot;</span>
          task <span style="color:#ff3333; font-weight:bold;">:default</span> <span style="color:#9966CC; font-weight:bold;">do</span>
            drupal::db::dump::remote::default
            latest
          <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
          desc <span style="color:#996600;">&quot;Downloads the latest database dump&quot;</span>
          task <span style="color:#ff3333; font-weight:bold;">:latest</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:db</span> <span style="color:#9966CC; font-weight:bold;">do</span>
            dumps = capture<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;ls -xt #{shared_path}/dumps&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0066; font-weight:bold;">split</span>.<span style="color:#9900CC;">reverse</span>
            get<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{shared_path}/dumps/#{dumps.last}&quot;</span>, <span style="color:#996600;">&quot;./#{dumps.last}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
          <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
        <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>



 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2008/10/two-improvements-to-your-capfiles/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Legacy Path Handler, a Radiant Extension</title>
		<link>http://tempe.st/2008/09/legacy-path-handler-a-radiant-extension/</link>
		<comments>http://tempe.st/2008/09/legacy-path-handler-a-radiant-extension/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 23:42:58 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Radiant]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[extensions]]></category>

		<guid isPermaLink="false">http://tempe.st/?p=245</guid>
		<description><![CDATA[We&#8217;re preparing to deploy the new Mikamai site (not up at the time of this post), that runs on the wonderful Rails-based RadiantCMS. The VPS we&#8217;re deploying to runs on Phusion Passenger, and that means we can&#8217;t use mod_alias or mod_rewrite to 301-redirect the old URLs, already indexed by Google, to their new locations. To [...]]]></description>
			<content:encoded><![CDATA[	<p>We&#8217;re preparing to deploy the new <a href="http://mikamai.com">Mikamai</a> site (not up at the time of this post), that runs on the wonderful Rails-based <a href="http://radiantcms.org">RadiantCMS</a>.</p>
	<p>The VPS we&#8217;re deploying to runs on <a href="http://modrails.com">Phusion Passenger</a>, and that means we can&#8217;t use mod_alias or mod_rewrite to 301-redirect the old URLs, already indexed by Google, to their new locations.</p>
	<p>To solve this problem I wrote a little Radiant Extension, called <a href="http://github.com/intinig/legacy_path_handler/tree/master">LegacyPathHandler</a>, that reads a simple list of URLs from a text file and does a 301 redirection on them before handling the control to Radiant&#8217;s default SiteController.</p>
	<p>It works quite fine for us, but it has no specs/tests or documentation. Please feel free to contribute to the project if you feel you can improve it.</p>

 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2008/09/legacy-path-handler-a-radiant-extension/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deploying Drupal with Capistrano</title>
		<link>http://tempe.st/2008/07/deploying-drupal-with-capistrano/</link>
		<comments>http://tempe.st/2008/07/deploying-drupal-with-capistrano/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 21:02:48 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://tempe.st/?p=230</guid>
		<description><![CDATA[Mikamai, the company I work for, has just released Montalbano.tv, the companion site to one of the most successful TV shows in Italy. I was the technical director of this Drupal based project, and while I was happy we chose Drupal, because it allowed us to deliver all the features they needed on time, I [...]]]></description>
			<content:encoded><![CDATA[	<p><a href="http://mikamai.com">Mikamai</a>, the company I work for, has just released <a href="http://montalbano.tv">Montalbano.tv</a>, the companion site to one of the most successful TV shows in Italy.</p>
	<p>I was the technical director of this Drupal based project, and while I was happy we chose Drupal, because it allowed us to deliver all the features they needed on time, I almost panicked when they told us the production setup would have two servers, both with database and web serving duties.</p>
	<p>The database replication was standard MySql master-master setup, but I had to develop a strategy to keep the two code-bases on the two servers synchronized. </p>
	<p>Being a Ruby programmer at heart, I selected the only tool that never fails me in circumstances like the one we had: <a href="http://capify.org">Capistrano</a>.</p>
	<p>Unfortunately, while Capistrano is all easy to use with Rails, I had to write a custom Drupal-tailored Capfile.</p>
	<p>Here it is, in its entirety, in case you ever need to  deploy Drupal with cap (now I always deploy Drupal with cap, since I have the recipe ready <img src='http://tempe.st/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ):</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">'deploy'</span> <span style="color:#9966CC; font-weight:bold;">if</span> respond_to?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:namespace</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># cap2 differentiator</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Standard configuration</span>
set <span style="color:#ff3333; font-weight:bold;">:user</span>, <span style="color:#996600;">&quot;username&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:password</span>, <span style="color:#996600;">&quot;password&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:application</span>, <span style="color:#996600;">&quot;application.name&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># I like to deploy the code in /var/apps</span>
<span style="color:#008000; font-style:italic;"># and then link it to the webserver directory</span>
set <span style="color:#ff3333; font-weight:bold;">:deploy_to</span>, <span style="color:#996600;">&quot;/var/apps/#{application}&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># SCM Stuff configure to taste, just remember the repository</span>
<span style="color:#008000; font-style:italic;"># here I used github as main repository</span>
set <span style="color:#ff3333; font-weight:bold;">:repository</span>,  <span style="color:#996600;">&quot;git@github.com:username/project.git&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:scm</span>, <span style="color:#ff3333; font-weight:bold;">:git</span>
set <span style="color:#ff3333; font-weight:bold;">:branch</span>, <span style="color:#996600;">&quot;master&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:repository_cache</span>, <span style="color:#996600;">&quot;git_master&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:deploy_via</span>, <span style="color:#ff3333; font-weight:bold;">:remote_cache</span>
set <span style="color:#ff3333; font-weight:bold;">:scm_verbose</span>,  <span style="color:#0000FF; font-weight:bold;">true</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Two servers, double fun</span>
<span style="color:#008000; font-style:italic;"># You really don't need app, web and db here,</span>
<span style="color:#008000; font-style:italic;"># but I used all of them just to be sure.</span>
<span style="color:#008000; font-style:italic;"># Usually only web is ok.</span>
role <span style="color:#ff3333; font-weight:bold;">:app</span>, <span style="color:#996600;">&quot;first.server.address.com&quot;</span>
role <span style="color:#ff3333; font-weight:bold;">:app</span>, <span style="color:#996600;">&quot;second.server.address.com&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:primary</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
role <span style="color:#ff3333; font-weight:bold;">:web</span>, <span style="color:#996600;">&quot;first.server.address.com&quot;</span>
role <span style="color:#ff3333; font-weight:bold;">:web</span>, <span style="color:#996600;">&quot;second.server.address.com&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:primary</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
role <span style="color:#ff3333; font-weight:bold;">:db</span>, <span style="color:#996600;">&quot;first.server.address.com&quot;</span>
role <span style="color:#ff3333; font-weight:bold;">:db</span>, <span style="color:#996600;">&quot;second.server.address.com&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:primary</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
&nbsp;
after <span style="color:#996600;">'deploy:setup'</span>, <span style="color:#996600;">'drupal:setup'</span> <span style="color:#008000; font-style:italic;"># Here we setup the shared files directory</span>
after <span style="color:#996600;">'deploy:symlink'</span>, <span style="color:#996600;">'drupal:symlink'</span> <span style="color:#008000; font-style:italic;"># After symlinking the code we symlink the shared dirs</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Before restarting the webserver we fix all the </span>
<span style="color:#008000; font-style:italic;"># permissions and then symlink it to production</span>
before <span style="color:#996600;">'deploy:restart'</span>, <span style="color:#996600;">'mikamai:permissions:fix'</span>, <span style="color:#996600;">'mikamai:symlink:application'</span>
&nbsp;
&nbsp;
namespace <span style="color:#ff3333; font-weight:bold;">:drupal</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#008000; font-style:italic;"># shared directories</span>
  task <span style="color:#ff3333; font-weight:bold;">:setup</span>, <span style="color:#ff3333; font-weight:bold;">:except</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:no_release</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    sudo <span style="color:#996600;">&quot;mkdir -p #{shared_path}/files&quot;</span>
    sudo <span style="color:#996600;">&quot;chown -R #{user}:#{user} #{deploy_to}&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># symlink shared directories</span>
  task <span style="color:#ff3333; font-weight:bold;">:symlink</span>, <span style="color:#ff3333; font-weight:bold;">:except</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:no_release</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    sudo <span style="color:#996600;">&quot;ln -s #{shared_path}/files #{latest_release}&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
namespace <span style="color:#ff3333; font-weight:bold;">:deploy</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#008000; font-style:italic;"># adjusted finalize_update, removed non rails stuff</span>
  task <span style="color:#ff3333; font-weight:bold;">:finalize_update</span>, <span style="color:#ff3333; font-weight:bold;">:except</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:no_release</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    sudo <span style="color:#996600;">&quot;chmod -R g+w #{latest_release}&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> fetch<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:group_writable</span>, <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  task <span style="color:#ff3333; font-weight:bold;">:restart</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#008000; font-style:italic;"># nothing to do here since we're on mod-php</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
namespace <span style="color:#ff3333; font-weight:bold;">:mikamai</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#008000; font-style:italic;"># symlinking to production</span>
  namespace <span style="color:#ff3333; font-weight:bold;">:symlink</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    task <span style="color:#ff3333; font-weight:bold;">:application</span>, <span style="color:#ff3333; font-weight:bold;">:except</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:no_release</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      sudo <span style="color:#996600;">&quot;rm -rf /var/www/montalbano&quot;</span>
      sudo <span style="color:#996600;">&quot;ln -s #{latest_release} /var/www/montalbano&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># change ownership</span>
  namespace <span style="color:#ff3333; font-weight:bold;">:permissions</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    task <span style="color:#ff3333; font-weight:bold;">:fix</span>, <span style="color:#ff3333; font-weight:bold;">:except</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:no_release</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      sudo <span style="color:#996600;">&quot;chown -R www-data:www-data #{latest_release}&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>



 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2008/07/deploying-drupal-with-capistrano/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

