<?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>LolocoJr &#187; rails</title>
	<atom:link href="http://www.railsguru.com/articles/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.railsguru.com</link>
	<description>Andy Lo-A-Foe&#039;s blog</description>
	<lastBuildDate>Thu, 21 Jul 2011 13:31:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Snow Leopard + MySQL + Ruby + 64-bit = #fail</title>
		<link>http://www.railsguru.com/articles/2010/07/09/snow-leopard-mysql-ruby-64-bit-fail/</link>
		<comments>http://www.railsguru.com/articles/2010/07/09/snow-leopard-mysql-ruby-64-bit-fail/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 12:08:16 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/?p=4618</guid>
		<description><![CDATA[Running into the following error after your Snow Leopard upgrade? uninitialized constant MysqlCompat::MysqlRes Then the following build line for the mysql gem might fix it for you: ARCHFLAGS="-arch i386 -arch x86_64" \ gem install --no-rdoc --no-ri mysql ]] \ -- &#8230; <a href="http://www.railsguru.com/articles/2010/07/09/snow-leopard-mysql-ruby-64-bit-fail/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Running into the following error after your Snow Leopard upgrade?</p>
<pre>uninitialized constant MysqlCompat::MysqlRes</pre>
<p>Then the following build line for the mysql gem might fix it for you:</p>
<pre>ARCHFLAGS="-arch i386 -arch x86_64"  \</pre>
<pre>  gem install --no-rdoc --no-ri mysql ]] \</pre>
<pre>  -- --with-mysql-dir=/opt/local/lib/mysql5 \</pre>
<pre>  --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config</pre>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-6322765154114793";
/* 300x250, created 7/3/11 */
google_ad_slot = "6228709946";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2010/07/09/snow-leopard-mysql-ruby-64-bit-fail/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing new Ruby postgresql adapter on Leopard</title>
		<link>http://www.railsguru.com/articles/2009/06/05/installing-new-ruby-postgresql-adapter-on-leopard/</link>
		<comments>http://www.railsguru.com/articles/2009/06/05/installing-new-ruby-postgresql-adapter-on-leopard/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 12:04:51 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[postgresql ruby gem leopard]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/?p=4547</guid>
		<description><![CDATA[I need to fix a project which uses PostgreSQL. On a fresh Leopard install with postgresql 8.3 installed from ports I ran into this problem: $ sudo gem install pg Building native extensions.  This could take a while... ERROR:  Error &#8230; <a href="http://www.railsguru.com/articles/2009/06/05/installing-new-ruby-postgresql-adapter-on-leopard/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I need to fix a project which uses PostgreSQL. On a fresh Leopard install with postgresql 8.3 installed from ports I ran into this problem:</p>
<pre>$ sudo gem install pg
Building native extensions.  This could take a while...
ERROR:  Error installing ruby-pg:
ERROR: Failed to build gem native extension.</pre>
<p>The solution is quite simply. Just make sure pg_config can be found by the gem installer.</p>
<pre>$ mdfind pg_config|grep bin|uniq
/opt/local/lib/postgresql83/bin/pg_config</pre>
<p>In this case make sure /opt/local/lib/postgresql/bin is available in the path when executing the gem command</p>
<pre>$ PATH=/opt/local/lib/postgresql83/bin:$PATH sudo gem install pg</pre>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-6322765154114793";
/* 300x250, created 7/3/11 */
google_ad_slot = "6228709946";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2009/06/05/installing-new-ruby-postgresql-adapter-on-leopard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Passenger with RACK apps</title>
		<link>http://www.railsguru.com/articles/2009/01/18/pasenger-with-rack-app/</link>
		<comments>http://www.railsguru.com/articles/2009/01/18/pasenger-with-rack-app/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 18:16:42 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2008/11/17/pasenger-with-rack-app</guid>
		<description><![CDATA[I started converting various apps running on mongrel clusters over to Apache + Passenger. One component of our production system is implemented as as mongrel plugin so it kind of sucks tot keep mongrel around just for this part. The &#8230; <a href="http://www.railsguru.com/articles/2009/01/18/pasenger-with-rack-app/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I started converting various apps running on mongrel clusters over to Apache + Passenger. One component of our production system is implemented as as mongrel plugin so it kind of sucks tot keep mongrel around just for this part. The reason I&#8217;m looking to abandon mongrel is because it requires all sorts of crappy monitoring tools to keep working properly. Luckily Passenger implements a RACK adapter so converting the mongrel plugin to a full blown RACK app should allow us to host it righ inside Passenger as well.</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-6322765154114793";
/* 300x250, created 7/3/11 */
google_ad_slot = "6228709946";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2009/01/18/pasenger-with-rack-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Passenger makes Apache relevant again</title>
		<link>http://www.railsguru.com/articles/2008/10/11/passenger-makes-apache-relevant-again/</link>
		<comments>http://www.railsguru.com/articles/2008/10/11/passenger-makes-apache-relevant-again/#comments</comments>
		<pubDate>Sat, 11 Oct 2008 06:28:00 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[nginx apache rails passenger mongrel]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2008/10/11/passenger-makes-apache-relevant-again</guid>
		<description><![CDATA[After stearing clear of Apache2 for the last year for all production servers I&#8217;m now ready to give it another try, thanks to Phusion&#8217;s Passenger. I&#8217;ve grown really tired of setting up god scripts for all environments and fighting mongrel&#8217;s &#8230; <a href="http://www.railsguru.com/articles/2008/10/11/passenger-makes-apache-relevant-again/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After stearing clear of Apache2 for the last year for all production servers I&#8217;m now ready to give it another try, thanks to <a href="http://www.modrails.com" target="_blank">Phusion&#8217;s Passenger</a>. I&#8217;ve grown really tired of setting up god scripts for all environments and fighting mongrel&#8217;s pidfile suckage.</p>
<p>Far too many times have things failed because of a dead worker in the cluster or some stale or (even worse!) non-existent pidfiles on the system. Mongrel has served well, but it&#8217;s time to look for something better.</p>
<p>A typical setup I use is nginx as the front-end server doing all static content while a pack of mongrels is handling the Rails requests through reverse proxy. nginx is also very important for reproxying requests, where content is streamed from another internal server over the front facing servers. In most of the Rails app I&#8217;m writing I have to deal with very large files (audio, video) so reproxy is essential if you want to have any sort of performance on a reasonable budget. Since Apache2 lacks reproxy support (AFAIK, please prove me wrong!) I really want to keep nginx as the front-end server and then do the Rails handling with Apache2 + Passenger through reverse proxy.</p>
<p>I&#8217;ve come a cross <a href="http://blog.kovyrin.net/2006/05/18/nginx-as-reverse-proxy/" target="_blank">a couple</a> of <a href="http://wiki.joyent.com/accelerators:nginx_apache_proxy" target="_blank">posts</a> on this very topic.</p>
<p>I&#8217;ll be doing some heavy development and testing over the next couple of days with this setup, will post my findings&#8230;</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-6322765154114793";
/* 300x250, created 7/3/11 */
google_ad_slot = "6228709946";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2008/10/11/passenger-makes-apache-relevant-again/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rails&#8217; end_of_month fixed</title>
		<link>http://www.railsguru.com/articles/2008/06/01/rails-end_of_month-fixed/</link>
		<comments>http://www.railsguru.com/articles/2008/06/01/rails-end_of_month-fixed/#comments</comments>
		<pubDate>Sun, 01 Jun 2008 11:26:00 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[rails end_of_month]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2008/07/14/rails-end_of_month-fixed</guid>
		<description><![CDATA[In Rails 2.0.x the end_of_month now properly gives you the end of month e.g. Mon Jun 30 23:59:59 +0200 2008, instead of Mon Jun 30 00:00:00 +0200 2008, which was the case in Rails 1.2.x (see this previous post). Good &#8230; <a href="http://www.railsguru.com/articles/2008/06/01/rails-end_of_month-fixed/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In Rails 2.0.x the end_of_month now properly gives you the end of month e.g. <strong>Mon Jun 30 23:59:59 +0200 2008</strong>, instead of <strong>Mon Jun 30 00:00:00 +0200 2008</strong>, which was the case in Rails 1.2.x (see <a target="_blank" href="http://www.railsguru.com/articles/2006/2/20/rails-end_of_month">this previous post</a>). Good thing I caught this, since it used to inside the Nota module of <a target="_blank" href="http://www.beldienst.nl">Beldienst</a>. We would be paying out the first of each month twice otherwise <img src='http://www.railsguru.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-6322765154114793";
/* 300x250, created 7/3/11 */
google_ad_slot = "6228709946";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2008/06/01/rails-end_of_month-fixed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Massive memory leak in ruby-gettext 1.90.0</title>
		<link>http://www.railsguru.com/articles/2008/05/08/massive-memory-leak-in-ruby-gettext-1-90-0/</link>
		<comments>http://www.railsguru.com/articles/2008/05/08/massive-memory-leak-in-ruby-gettext-1-90-0/#comments</comments>
		<pubDate>Thu, 08 May 2008 19:38:00 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[gettext leakage]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2008/10/27/massive-memory-leak-in-ruby-gettext-1-90-0</guid>
		<description><![CDATA[Just found out there&#8217;s a massive memory leak in ruby gettext 1.90.0, one of our applications started eating GBs of RAM after a couple of days in use. So If you&#8217;re using gettext for translating your Rails app take note! &#8230; <a href="http://www.railsguru.com/articles/2008/05/08/massive-memory-leak-in-ruby-gettext-1-90-0/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just found out there&#8217;s a massive memory leak in ruby gettext 1.90.0, one of our applications started eating GBs of RAM after a couple of days in use. So If you&#8217;re using gettext for translating your Rails app take note! You can grab the <a href="http://rubyforge.org/scm/?group_id=855" target="_blank">current trunk</a> which has a fix for this.</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-6322765154114793";
/* 300x250, created 7/3/11 */
google_ad_slot = "6228709946";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2008/05/08/massive-memory-leak-in-ruby-gettext-1-90-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Side project: De TV Flat (KRO)</title>
		<link>http://www.railsguru.com/articles/2008/04/30/side-project-de-tv-flat-kro/</link>
		<comments>http://www.railsguru.com/articles/2008/04/30/side-project-de-tv-flat-kro/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 00:16:00 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tvflat rails project video streaming]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2008/04/30/side-project-de-tv-flat-kro</guid>
		<description><![CDATA[My first Rails 2.0.x project has been running in production for a couple of months now. It&#8217;s the website for KRO&#8217;s &#8220;De TV Flat&#8221;, a children/teens program airing every Saturday on dutch national television around 9am (channel Nederland 3) untill &#8230; <a href="http://www.railsguru.com/articles/2008/04/30/side-project-de-tv-flat-kro/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
My first Rails 2.0.x project has been running in production for a couple of months now. It&#8217;s the website for KRO&#8217;s <a href="http://www.tvflat.kro.nl" target="_blank">&#8220;De TV Flat&#8221;</a>, a children/teens program airing every Saturday on dutch national television around 9am (channel Nederland 3) untill the beginning of summer. I&#8217;m very proud to actually get one of my projects on TV! The premise is basically &#8220;Youtube for kids&#8221; with the chance of getting your self-made video&#8217;s broadcasted on TV!
</p>
<p>
<img src="http://railsguru.com/assets/2008/4/30/tvflat.jpg" />
</p>
<p>
I really like the <a href="http://tvflat.nl/frontend/search?query=wvjhw" target="_blank">instructional video&#8217;s</a> made by the TVFlat crew, very  helpfull tips for creating your own video content.
</p>
<p>Technology used:</p>
<ul>
<li>Linux</li>
<li>Nginx HTTP server</li>
<li>Mongrel</li>
<li>MogileFS clustered storage</li>
<li>Rails 2.0.2</li>
<li>Merb 0.54 for critical code paths, beats Rails to a pulp when it comes to roundtrip times</li>
<li>Memcached</li>
<li>MySQL</li>
<li>Lucene</li>
<li>mplayer / ffmpeg / faac for transcoding, direct broadcast quality feeds are generated!</li>
<li>Flash video</li>
</ul>
<p>
Hope I can find some time later on to write a bit about the different parts.. anyway, <a href="http://www.tvflat.kro.nl" target="_blank">go check it out!</a></p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-6322765154114793";
/* 300x250, created 7/3/11 */
google_ad_slot = "6228709946";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2008/04/30/side-project-de-tv-flat-kro/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Torturing Ruby (and laughing at your own code)</title>
		<link>http://www.railsguru.com/articles/2007/08/21/torturing-ruby-and-laughing-at-your-own-code/</link>
		<comments>http://www.railsguru.com/articles/2007/08/21/torturing-ruby-and-laughing-at-your-own-code/#comments</comments>
		<pubDate>Tue, 21 Aug 2007 22:50:00 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[flog ruby pain]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2007/08/21/torturing-ruby-and-laughing-at-your-own-code</guid>
		<description><![CDATA[While cleaning up some code I ran across some obscure code of mine from my Ruby youth. I remembered reading about an ultra cool Ruby tool the other day so I decided to give my code a good flogging. The &#8230; <a href="http://www.railsguru.com/articles/2007/08/21/torturing-ruby-and-laughing-at-your-own-code/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While cleaning up some code I ran across some obscure code of mine from my Ruby youth. I remembered reading about an ultra cool Ruby tool the other day so I decided to <strong><a href="http://ruby.sadi.st/Flog.html">give my code a good flogging</a></strong>. The victim for tonight is a method used to slice ID numbers into chunks of at most 4 characters long. This is required to overcome the typical Linux file system limitation of at most 32000 entries per directory. In this case the project stores roughly a million thumbnail images on disk. We start with the original piece of code:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><span class="r">def</span> <span class="fu">splice_number</span>(number, part_size = <span class="i">4</span>)<tt>
</tt>  n = number.to_s<tt>
</tt>  r = []<tt>
</tt>  <span class="r">return</span> r <span class="r">if</span> n.size.zero?<tt>
</tt>  (n.size / part_size).times { |t| r &lt;&lt; n[(t*part_size)..((t<span class="i">+1</span>)*part_size<span class="i">-1</span>)] }<tt>
</tt>  r &lt;&lt; n[-(n.size % part_size)..n.size] <span class="r">if</span> (n.size % part_size) &gt; <span class="i">0</span><tt>
</tt>  r<tt>
</tt><span class="r">end</span></pre>
</td>
</tr>
</table>
<p>Ah yes, <span class="caps">WTF</span> was I thinking when I wrote this? Who cares, it seemed very clever then! What does Flog think about this?</p>
<pre>
Total score = 28.35

none#splice_number: (28)
     7: size
     3: *
     2: %
     2: []
     2: &lt;&lt;
     1: +
     1: -@
     1: -
     1: /
     1: lit_fixnum
     1: zero?
     1: &gt;
     1: to_s
     1: times
</pre>
<p>Pretty good score. Now it&#8217;s time for some torturing. Say hello to my little friend: unpack!</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><span class="r">def</span> <span class="fu">splice_number</span>(number, part_size = <span class="i">4</span>)<tt>
</tt>  n = number.to_s<tt>
</tt>  n.unpack(<span class="s"><span class="dl">&quot;</span><span class="k">a</span><span class="il"><span class="dl">#{</span>part_size<span class="dl">}</span></span><span class="dl">&quot;</span></span> * (n.size / part_size) + ((n.size % part_size == <span class="i">0</span>) ? <span class="s"><span class="dl">&quot;</span><span class="dl">&quot;</span></span> : <span class="s"><span class="dl">&quot;</span><span class="k">a*</span><span class="dl">&quot;</span></span>))<tt>
</tt><span class="r">end</span></pre>
</td>
</tr>
</table>
<p>Flog?</p>
<pre>
Total score = 13.05

none#splice_number: (13)
     3: size
     1: %
     1: /
     1: ==
     1: *
     1: +
     1: to_s
     1: unpack
     0: lit_fixnum
</pre>
<p>Yeow, well over half the pain gone!! Perhaps we can still improve by being less clever?</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><span class="r">def</span> <span class="fu">splice_number</span>(number, part_size = <span class="i">4</span>)<tt>
</tt>  n = number.to_s<tt>
</tt>  r = n.unpack(<span class="s"><span class="dl">&quot;</span><span class="k">a</span><span class="il"><span class="dl">#{</span>part_size<span class="dl">}</span></span><span class="dl">&quot;</span></span> * (n.size / part_size) + <span class="s"><span class="dl">&quot;</span><span class="k">a*</span><span class="dl">&quot;</span></span>)<tt>
</tt>  r.delete(<span class="s"><span class="dl">&quot;</span><span class="dl">&quot;</span></span>)<tt>
</tt>  r<tt>
</tt><span class="r">end</span></pre>
</td>
</tr>
</table>
<p>More lines, but less code! Hmm?</p>
<pre>
Total score = 9.25

none#splice_number: (9)
     1: size
     1: /
     1: *
     1: +
     1: delete
     1: to_s
     1: unpack
     0: lit_fixnum
</pre>
<p>Weeh, a full 2/3 of the pain flogged out of the code! That&#8217;s all the torture I&#8217;ll do for tonight..</p>
<p>
<strong>Update:</strong> Okay, couldn&#8217;t help myself, last blow:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><span class="r">def</span> <span class="fu">splice_number</span>(number, part_size = <span class="i">4</span>)<tt>
</tt>  n = number.to_s<tt>
</tt>  p = <span class="s"><span class="dl">&quot;</span><span class="k">a</span><span class="il"><span class="dl">#{</span>part_size<span class="dl">}</span></span><span class="dl">&quot;</span></span><tt>
</tt>  t = n.size / part_size<tt>
</tt>  r = n.unpack(p * t + <span class="s"><span class="dl">&quot;</span><span class="k">a*</span><span class="dl">&quot;</span></span>)<tt>
</tt>  r.delete(<span class="s"><span class="dl">&quot;</span><span class="dl">&quot;</span></span>)<tt>
</tt>  r<tt>
</tt><span class="r">end</span></pre>
</td>
</tr>
</table>
<p>With score:</p>
<pre>
Total score = 8.05

none#splice_number: (8)
     1: *
     1: size
     1: +
     1: delete
     1: to_s
     1: /
     1: unpack
     0: lit_fixnum
</pre>
</p>
<p>Done..</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-6322765154114793";
/* 300x250, created 7/3/11 */
google_ad_slot = "6228709946";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2007/08/21/torturing-ruby-and-laughing-at-your-own-code/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Switch from Typo to Mephisto</title>
		<link>http://www.railsguru.com/articles/2007/04/16/switch-from-typo-to-mephisto/</link>
		<comments>http://www.railsguru.com/articles/2007/04/16/switch-from-typo-to-mephisto/#comments</comments>
		<pubDate>Mon, 16 Apr 2007 12:51:00 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[mephisto typo migration]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2007/08/16/switch-from-typo-to-mephisto</guid>
		<description><![CDATA[After the final botched Typo upgrade I gave up on it and am now serving this blog from Mephisto (0.7.3). The migration went fine. Luckily I still had a copy from the old Typo database structure since the Typo SVN &#8230; <a href="http://www.railsguru.com/articles/2007/04/16/switch-from-typo-to-mephisto/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
After the final botched Typo upgrade I gave up on it and am now serving this blog from Mephisto (0.7.3). The migration went fine. Luckily I still had a copy from the old Typo database structure since the Typo SVN version is not compatible with the migrations scripts from Mephisto. So far everything seems to work fine, except for the Sections. But I can now tweak Mephisto without fear. Typo has become such a huge opaque monster making changes felt like gambling. The last Typo version I checked out had over 35.000 files in the trunk!</p>
<p>
The only downside I see so far with using Mephisto is that it&#8217;s even more obscure than Typo so there is no ready-made migration path to anything else <img src='http://www.railsguru.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />
</p>
<p>
With the migration completed I will start posting articles again..&lt;ali_g_accent&gt;for real&lt;ali_g_accent&gt;
</p>
<p>
<strong>Update:</strong> Mephisto&#8217;s SPAM filtering (through Akismet) actually works and the approval process is very well done. I also like the Overview section.</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-6322765154114793";
/* 300x250, created 7/3/11 */
google_ad_slot = "6228709946";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2007/04/16/switch-from-typo-to-mephisto/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Rewriting a (large) PHP application in Rails, part 2</title>
		<link>http://www.railsguru.com/articles/2006/12/19/rewriting-a-large-php-application-in-rails-part-2/</link>
		<comments>http://www.railsguru.com/articles/2006/12/19/rewriting-a-large-php-application-in-rails-part-2/#comments</comments>
		<pubDate>Tue, 19 Dec 2006 18:20:00 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2007/08/16/rewriting-a-large-php-application-in-rails-part-2</guid>
		<description><![CDATA[In my previous post on this topic I described the method we used to convert a legacy MySQL PHP database to a Rails conformant PostgreSQL hosted version. In this article I will tell a bit about how we converted the &#8230; <a href="http://www.railsguru.com/articles/2006/12/19/rewriting-a-large-php-application-in-rails-part-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://railsguru.com/articles/2006/12/13/rewriting-a-large-php-application-in-rails-part-1">previous post</a> on this topic I described the method we used to convert<br />
a legacy MySQL <span class="caps">PHP</span> database to a Rails conformant PostgreSQL hosted version. In this article I will tell a bit about how we converted the <span class="caps">HTML</span> of the application to Rails layout templates and partials.</p>
<h4>Extracting <span class="caps">HTML</span> from Firefox <span class="caps">DOM</span></h4>
<p>We first started out with attempting to rewrite the table heavy design to <span class="caps">CSS</span>. We soon realised that this was a project on itself so we decided to work with what we have. Since most of the <span class="caps">HTML</span> code is intermingled with <span class="caps">PHP</span> logic it was really not an option to examine the numerous .php files and cut &#8216;n paste what we needed.<br />
We basically used the excellent <a href="https://addons.mozilla.org/firefox/697/">Firefox View Formatted Source extension</a> to take snapshots of the <span class="caps">DOM</span> tree of rendered pages (<a href="http://mcuadros.es/2006/10/25/extension-view-formatted-source-en-firefox-20/">look here</a> if you&#8217;re on <span class="caps">FF2</span>).</p>
<p>
<img src="/assets/2007/4/16/vfs_popup.png" /></p>
<p> Getting the <span class="caps">HTML</span> from the Firefox <span class="caps">DOM</span> meant we had properly balanced <span class="caps">HTML</span>! The real work was to extract layout templates and to identify the partials. This turned out to relatively easy. The really hard part was to get the code to display properly in Internet Explorer, which unfortunately still makes up about 70% of all traffic to the site.</p>
<p>
<img src="/assets/2007/4/16/vfs_window.png" />
</p>
</p>
<h4>Writing down business logic</h4>
<p>The original project never had functional or technical specifications so I scheduled 3 sessions spread over 2 weeks with the (back-end) users of the system. We identified the business logic and rules of the system as best as we could during these (1-2 hour) sessions. The whole business logic was then written again from scratch in Ruby. I figured it would have take much longer if I had examined the <span class="caps">PHP</span> code myself. This might not be an option for you though. Anyway, during these 2 weeks at the end of each day a small number of functionalities would be delivered for testing. In practice the user(s) would only test functionality and provide feedback every 3-4 days (busy schedules on both sides, so noone enforced this). Could have been better.</p>
<h4><span class="caps">TDD</span>, or rather <span class="caps">WTAD</span> (Write Test After Developing)</h4>
<p>It was really really hard to bring up the discipline of writing the Test code before Developing the functionality. In practice tests were only written after something was seen working already. What do <strong>you</strong> do, honestly? <img src='http://www.railsguru.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>
The final part will contain details about the deployment (Mongrels, W00t!) and also some interesting statistics on how many lines were left after the rewrite. Stay tuned..</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-6322765154114793";
/* 300x250, created 7/3/11 */
google_ad_slot = "6228709946";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2006/12/19/rewriting-a-large-php-application-in-rails-part-2/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

