<?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</title>
	<atom:link href="http://www.railsguru.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.railsguru.com</link>
	<description>Andy Lo-A-Foe's weblog</description>
	<lastBuildDate>Tue, 28 Jul 2009 03:31:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>EngineYard takes over the JRuby team</title>
		<link>http://www.railsguru.com/articles/2009/07/28/engineyard-takes-over-the-jruby-team/</link>
		<comments>http://www.railsguru.com/articles/2009/07/28/engineyard-takes-over-the-jruby-team/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 03:29:17 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[sun jruby ruby]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/articles/2009/07/28/engineyard-takes-over-the-jruby-team/</guid>
		<description><![CDATA[<p>Wow, EngineYard is really stepping up! Have to wonder though what&#8217;s going on at Sun, is the whole thing now imploding?! Crazy!</p>
]]></description>
			<content:encoded><![CDATA[<p>Wow, EngineYard is really stepping up! Have to wonder though what&#8217;s going on at Sun, is the whole thing now imploding?! <a href="http://blog.headius.com/">Crazy!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2009/07/28/engineyard-takes-over-the-jruby-team/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scala scripting continued</title>
		<link>http://www.railsguru.com/articles/2009/07/13/scala-scripting-continued/</link>
		<comments>http://www.railsguru.com/articles/2009/07/13/scala-scripting-continued/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 13:08:45 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/?p=4593</guid>
		<description><![CDATA[<p>It took a day or two of blog reading and scala console try outs but I managed to create my first usable Scala script.</p>

import scala.xml._

/**
  Sequence number fix script. See http://fugamusic.com/docs/ingestion/ingestion.xsd
**/

object FixSequence {
	var seq: List[Pair[Int,Int]] = List()
	var working_vol = 0

	def main(args: Array[String]) {
		val pp = new PrettyPrinter(80, 2)
		val fuga = XML.loadFile(args(0))(0)
		loadSeq(fuga)
		println(pp.format(fixSeq(fuga)))
	}

	def loadSeq(xml: Node) {
		for [...]]]></description>
			<content:encoded><![CDATA[<p>It took a day or two of blog reading and scala console try outs but I managed to create my first usable Scala script.</p>
<pre class="brush:scala">
import scala.xml._

/**
  Sequence number fix script. See http://fugamusic.com/docs/ingestion/ingestion.xsd
**/

object FixSequence {
	var seq: List[Pair[Int,Int]] = List()
	var working_vol = 0

	def main(args: Array[String]) {
		val pp = new PrettyPrinter(80, 2)
		val fuga = XML.loadFile(args(0))(0)
		loadSeq(fuga)
		println(pp.format(fixSeq(fuga)))
	}

	def loadSeq(xml: Node) {
		for (t <- xml \ "tracks" \ "track")
			seq = ((t \ "on_disc" text).toInt, (t \ "sequence_number" text).toInt) :: seq
	}

	def maxSeq(vol:Int) = {
		seq.foldLeft(0){(s,v) => if(v._1 == vol &#038;&#038; v._2 > s) v._2 else s}
	}

	def maxVol: Int = {
		seq.foldLeft(0){(m,v) => if (v._1 > m) v._1 else m }
	}

	def baseVal(vol: Int): Int = {
		(for (t <- 1 to vol-1) yield maxSeq(t)).foldLeft(0) {_+_}
	}

	def fixSeq(xml: Node): Node = {
		def updateSeq(ns: Seq[Node]): Seq[Node] = {
			for (n <- ns) yield n match {
				case <on_disc>{ disc_nr }</on_disc> => {
					working_vol = disc_nr.text.toInt
					<on_disc>{ disc_nr }</on_disc>
				}
				case <sequence_number>{ seq_nr }</sequence_number> => {
					<sequence_number>{ seq_nr.text.toInt + baseVal(working_vol) }</sequence_number>
				}
				case Elem(prefix, label, attribs, scope, children @ _*) =>
					Elem(prefix, label, attribs, scope, updateSeq(children) : _*)
				case other => other
			}
		}
		updateSeq(xml.theSeq)(0)
	}
}

FixSequence.main(args)
</pre>
<p>While working on the script I rewrote several methods to be more Scala-like as I got more feeling for some of the functional traits of Scala. For instance the method:</p>
<pre class="brush:scala">
def baseVal(vol: Int): Int = {
	var base_val = 0
	for (t <- 1 to vol-1) base_val += maxSeq(t)
	base_val
}
</pre>
<p>was rewritten to be var'less:</p>
<pre class="brush:scala">
def baseVal(vol: Int): Int = {
	(for (t <- 1 to vol-1) yield maxSeq(t)).foldLeft(0) {_+_}
}
</pre>
<p>(the { } can even be omitted in this case). Thanks for the foldLeft tip <a href="http://log4p.com" target="_blank">p3t0r</a>!</p>
<p>But the hardest part was figuring out how to modify the XML structure in Scala without using DOM. Scala's XML support is quite amazing, especially the pattern matching and the ability to mix XML constructs with code!<br />
I did cheat a bit IMHO by keeping some of the state in a var while using the recursion to walk through the XML, but it seems to work quite well. See my <a href="http://www.railsguru.com/articles/2009/07/10/first-stab-at-scala-scripting-filters-do-not-work-like-my-ruby-brain-thinks-they-do/">previous post</a> for a problem description. Basically I need to modify the contents of the &lt;sequence_number&gt; based on the &lt;on_disc&gt; values. So first all (vol,sequence_number) pairs are parsed and based on the (max) values the &lt;sequence_numbers&gt; are modified.<br />
While thinking about it some more there is an issue where the script will break down if the &lt;on_disc&gt; comes after the &lt;sequence_number&gt; but this is not the case for the XML batch that needed fixing. That could be solved by doing a element lookup in the case match of &lt;sequence_number&gt;. Anyway, tastes like more.. So I'll definitely be doing more Scala coding.. I've already registered <a href="http://scalaguru.com">scalaguru.com</a>, so watch out! <img src='http://www.railsguru.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2009/07/13/scala-scripting-continued/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>First stab at Scala scripting.. filters do not work like my Ruby brain thinks they do</title>
		<link>http://www.railsguru.com/articles/2009/07/10/first-stab-at-scala-scripting-filters-do-not-work-like-my-ruby-brain-thinks-they-do/</link>
		<comments>http://www.railsguru.com/articles/2009/07/10/first-stab-at-scala-scripting-filters-do-not-work-like-my-ruby-brain-thinks-they-do/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 15:36:23 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/?p=4551</guid>
		<description><![CDATA[<p>So I decided to pick up the Scala language. Having done Ruby for a couple of years now Scala is one of the few, if not the only language that&#8217;s gotten me excited. Being a first class citizen on the JVM has many advantages and I&#8217;m really liking LiftWeb.</p>
<p>I also suspect I&#8217;ll be doing a [...]]]></description>
			<content:encoded><![CDATA[<p>So I decided to pick up the Scala language. Having done Ruby for a couple of years now Scala is one of the few, if not the only language that&#8217;s gotten me excited. Being a first class citizen on the JVM has many advantages and I&#8217;m really liking <a href="http://liftweb.net">LiftWeb</a>.</p>
<p>I also suspect I&#8217;ll be doing a bit more Java related stuff in the very near future (stay tuned for that one <img src='http://www.railsguru.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ) so it&#8217;s a good idea to dive  into the J world again, and what better way then with Scala!</p>
<p>Problem definition: there is an issue with some XML files which came with a large batch ingest for one of our clients. In short there are a bunch of track elements in the XML which each element having a on_disc and sequence_number (think audio CDs) . However, the sequence_numbers should always be incremented e.g. if you have 2 tracks on disc 1 and 3 tracks on disc 2 the tracks on disc 2 should be have sequence numbers 3,4 and 5 respectively. The XML files we got have reset the sequence_number to 1 whenever a new disc begins.The fix is thus a simple matter of adding the highest sequence number of the previous disc to the sequence number of the current disc. Easy enough.</p>
<p>I tried to implement this in Scala and one of the helper methods calculates the highest sequence number of a given disc. This is the odd part though</p>
<pre class="brush:scala">
// The XML is first parsed to read all tracks
// These are stored in a tuple list
// Note the order of the tuples!
// Tuple values are (on_volume, sequence_number)

val sequence = List((1,2),(1,1),(2,1),(2,2),(2,3))

// Find the max value given a volume
def maxVal(vol: Int): Int = {
  var max = 1
  for (t <- sequence
    if t._1 == vol;
    if t._2 > max) max = t._2
 max
}

println(maxVal(1))
</pre>
<p>Now my Ruby brain would expect this to print out <b>2</b>, however when you run this code the result will be <b>1</b>! That&#8217;s because the filters are actually creating a new list before feeding that to for clause  so max is always 1 in the test. I did not expect this <img src='http://www.railsguru.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2009/07/10/first-stab-at-scala-scripting-filters-do-not-work-like-my-ruby-brain-thinks-they-do/feed/</wfw:commentRss>
		<slash:comments>3</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[Uncategorized]]></category>
		<category><![CDATA[postgresql ruby gem leopard]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/?p=4547</guid>
		<description><![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>
$ sudo gem install pg
Building native extensions.  This could take a while...
ERROR:  Error installing ruby-pg:
ERROR: Failed to build gem native extension.
<p>The solution is quite simply. Just make sure pg_config can be [...]]]></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>
]]></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>Suriname</title>
		<link>http://www.railsguru.com/articles/2009/02/09/suriname/</link>
		<comments>http://www.railsguru.com/articles/2009/02/09/suriname/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 15:18:05 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[suriname vacation]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/articles/2009/02/09/suriname/</guid>
		<description><![CDATA[<p>Currently enjoying some vacation in  Suriname.</p>
<p>Update: and back again (2009-03-06)</p>
]]></description>
			<content:encoded><![CDATA[<p>Currently enjoying some vacation in  <a href="http://en.wikipedia.org/wiki/Suriname">Suriname</a>.</p>
<p><strong>Update</strong>: and back again (2009-03-06)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2009/02/09/suriname/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Typo -&gt; Mephisto -&gt; Wordpress</title>
		<link>http://www.railsguru.com/articles/2009/01/21/typo-mephisto-wordpress/</link>
		<comments>http://www.railsguru.com/articles/2009/01/21/typo-mephisto-wordpress/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 16:19:01 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[mephisto]]></category>
		<category><![CDATA[typo]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/?p=4486</guid>
		<description><![CDATA[<p>First I tried Typo, then Mephisto and now this blog is running Wordpress. As a Ruby fan I really wanted to use Ruby everywhere, 2 years ago. I&#8217;m now at the point where I just want working stuff (kids will do that to you I guess). The migration from Mephisto to Wordpress was very very [...]]]></description>
			<content:encoded><![CDATA[<p>First I tried Typo, then Mephisto and now this blog is running Wordpress. As a Ruby fan I really wanted to use Ruby everywhere, 2 years ago. I&#8217;m now at the point where I just want working stuff (kids will do that to you I guess). The migration from Mephisto to Wordpress was very very smooth, thanks to <a href="http://jayunit.net/2008/04/16/mephisto-to-wordpress/" target="_blank">this excellent article</a>. The Mephisto version I was running was producing a Rails error based on some spam message which was posted. I really didn&#8217;t want to dig into the error and upgrading to the latest Mephisto was going to be quite a bit of work. All in all the switch to Wordpress took about 2 hours in total, including customizing the theme a bit and making sure the old permalinks kept working. Cool!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2009/01/21/typo-mephisto-wordpress/feed/</wfw:commentRss>
		<slash:comments>5</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[Home]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2008/11/17/pasenger-with-rack-app</guid>
		<description><![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 [...]]]></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>
]]></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>Sold!</title>
		<link>http://www.railsguru.com/articles/2008/11/11/sold-2/</link>
		<comments>http://www.railsguru.com/articles/2008/11/11/sold-2/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 09:50:00 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[sold moving]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2008/11/12/sold</guid>
		<description><![CDATA[<p>

</p>
<p>
We sold our apartment a few weeks before the credit crunch hit hard, phew! We already purchased a new house (new construction) last year. Last week we had to move out of apartment. Unfortunately the new house is not yet finished. Well it is, but the utility companies still need to their stuff and the [...]]]></description>
			<content:encoded><![CDATA[<p>
<img src="http://railsguru.com/assets/2008/11/11/kk_56_1.jpg" />
</p>
<p>
We sold our apartment a few weeks before the credit crunch hit hard, phew! We already purchased a new house (new construction) last year. Last week we had to move out of apartment. Unfortunately the new house is not yet finished. Well it is, but the utility companies still need to their stuff and the municipality needs to finish the roads, in that order.  the new location is just 1 block away because we really like Osdorp and wanted to stay in or around Amsterdam.
</p>
<p>
<img src="http://railsguru.com/assets/2008/11/11/js_17.jpg" />
</p>
<p>
In the meantime we&#8217;ll be moving between my sis and brother-in-law. c&#8217;mon <a href="http://www.waternet.nl" target="_blank">waternet</a>, move!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2008/11/11/sold-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting rid of KPN</title>
		<link>http://www.railsguru.com/articles/2008/11/10/getting-rid-of-kpn/</link>
		<comments>http://www.railsguru.com/articles/2008/11/10/getting-rid-of-kpn/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 11:40:00 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[kpn suckage]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2008/11/10/getting-rid-of-kpn</guid>
		<description><![CDATA[<p>So, we moved and I canceled all our subscriptions at the old address. So I thought, it turns out KPN has /dev/null&#8217;d my cancellation request for the fixed line twice in a row. Each time customer relations assured me it would take 5 working days for the request to be processed. I just called them [...]]]></description>
			<content:encoded><![CDATA[<p>So, we moved and I canceled all our subscriptions at the old address. So I thought, it turns out KPN has /dev/null&#8217;d my cancellation request for the fixed line <strong>twice</strong> in a row. Each time customer relations assured me it would take 5 working days for the request to be processed. I just called them a third time now, because the line was active. The kind lady  gave me a reference number for the cancellation order. So, whenever you deal with KPN I think it&#8217;s a good idea to ask for the reference number of the case or order.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2008/11/10/getting-rid-of-kpn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving in 3 weeks!</title>
		<link>http://www.railsguru.com/articles/2008/10/12/moving-in-3-weeks/</link>
		<comments>http://www.railsguru.com/articles/2008/10/12/moving-in-3-weeks/#comments</comments>
		<pubDate>Sun, 12 Oct 2008 18:16:42 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[house moving]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2008/10/12/moving-in-3-weeks</guid>
		<description><![CDATA[<p>Earlier in the year we sold our appartement and bought a new house.  With 2 kids it was simply not fun anymore in our cosy appartement on the 4th floor. We won&#8217;t get the keys of our new house, which is in the final stages of construction, for another month or two. In the [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier in the year we sold our <a href="http://www.funda.nl/WoningAanbod/Koop/Detail/?id=f746f946-4935-4c8a-ab8f-58454ffb917a&amp;objecttype=">appartement</a> and bought a new house.  With 2 kids it was simply not fun anymore in our cosy appartement on the 4th floor. We won&#8217;t get the keys of our new house, which is in the final stages of construction, for another month or two. In the meantime we have to make room for the new owners so the next couple of weeks are gonna be extra hectic and very interesting to say the least.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2008/10/12/moving-in-3-weeks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
