IR_Black on MacOS X Lion

Just upgraded to GM developer release of MacOS X Lion and noticed SIMBL TerminalColour plugin hack I use to get the right colors on the popular IR_Black theme was broken. The new terminal however finally allows you to actually pick your own colors for the ANSI set. This means no more struggling with SIMBL or 32/64-bit TerminalColour installations or .plist tweaking for every dot release.

Download the IR_Black.terminal exported file.

And just use the “Import…” menu item as seen below. Done!

Screenshot:

Posted in Apple | Tagged | 2 Comments

Snow Leopard + MySQL + Ruby + 64-bit = #fail

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 ]] \
  -- --with-mysql-dir=/opt/local/lib/mysql5 \
  --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config
Posted in rails, ruby | 1 Comment

Microblogging FTW?

Haven’t updated this blog in quite a while. On the other hand I’ve been very active on Twitter. Going to hunt for a WordPress plugin that ‘reblogs’ the microblogging activity

Posted in Uncategorized | Tagged | Leave a comment

EngineYard takes over the JRuby team

Wow, EngineYard is really stepping up! Have to wonder though what’s going on at Sun, is the whole thing now imploding?! Crazy!

Posted in Uncategorized | Tagged | Leave a comment

Scala scripting continued

It took a day or two of blog reading and scala console try outs but I managed to create my first usable Scala script.

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 && 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 { disc_nr } => {
					working_vol = disc_nr.text.toInt
					{ disc_nr }
				}
				case { seq_nr } => {
					{ seq_nr.text.toInt + baseVal(working_vol) }
				}
				case Elem(prefix, label, attribs, scope, children @ _*) =>
					Elem(prefix, label, attribs, scope, updateSeq(children) : _*)
				case other => other
			}
		}
		updateSeq(xml.theSeq)(0)
	}
}

FixSequence.main(args)

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:

def baseVal(vol: Int): Int = {
	var base_val = 0
	for (t <- 1 to vol-1) base_val += maxSeq(t)
	base_val
}

was rewritten to be var'less:

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

(the { } can even be omitted in this case). Thanks for the foldLeft tip p3t0r!

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!
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 previous post for a problem description. Basically I need to modify the contents of the <sequence_number> based on the <on_disc> values. So first all (vol,sequence_number) pairs are parsed and based on the (max) values the <sequence_numbers> are modified.
While thinking about it some more there is an issue where the script will break down if the <on_disc> comes after the <sequence_number> 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 <sequence_number>. Anyway, tastes like more.. So I'll definitely be doing more Scala coding.. I've already registered scalaguru.com, so watch out! :-D

Posted in scala | 3 Comments

First stab at Scala scripting.. filters do not work like my Ruby brain thinks they do

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’s gotten me excited. Being a first class citizen on the JVM has many advantages and I’m really liking LiftWeb.

I also suspect I’ll be doing a bit more Java related stuff in the very near future (stay tuned for that one :-) ) so it’s a good idea to dive into the J world again, and what better way then with Scala!

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.

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

// 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))

Now my Ruby brain would expect this to print out 2, however when you run this code the result will be 1! That’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 :-)

Posted in scala | Tagged | 3 Comments

Installing new Ruby postgresql adapter on Leopard

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 installing ruby-pg:
ERROR: Failed to build gem native extension.

The solution is quite simply. Just make sure pg_config can be found by the gem installer.

$ mdfind pg_config|grep bin|uniq
/opt/local/lib/postgresql83/bin/pg_config

In this case make sure /opt/local/lib/postgresql/bin is available in the path when executing the gem command

$ PATH=/opt/local/lib/postgresql83/bin:$PATH sudo gem install pg
Posted in rails, ruby | Tagged | Leave a comment

Suriname

Currently enjoying some vacation in  Suriname.

Update: and back again (2009-03-06)

Posted in Misc | Tagged | 1 Comment

Typo -> Mephisto -> WordPress

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’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 this excellent article. The Mephisto version I was running was producing a Rails error based on some spam message which was posted. I really didn’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!

Posted in ruby | Tagged , , | 5 Comments

Passenger with RACK apps

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’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.

Posted in rails, ruby | Leave a comment