A daughter!

It has been very quiet on this blog, but not so much here at home. On March 2th 2008 our daughter Mia Morena Elisabeth Lo-A-Foe was born. Mia is a healthy baby girl who regularly eats every 3 hours, around the clock. After 6 weeks we’re completely comfortable with the new schedule. Andrew loves his baby sister very much but still pokes here once in a while just to see what’s she’s made of :)

Posted in Home | Leave a comment

A baby girl!!!

It has been very quiet on this blog, but not so much here at home. On March 2nd 2008 our daughter Mia Morena Elisabeth Lo-A-Foe was born.

Mia is a healthy baby girl who regularly eats every 3 hours, around the clock. After 6 weeks we’re completely comfortable with the new schedule. Andrew loves his baby sister very much but still pokes here once in a while just to see what’s she’s made of :)

Posted in Home | Tagged | 4 Comments

has_many_polymorphs tagging snafu

I’m working on a Rails 2.0.x project which is a port of a 1.2.x based one. Since acts_as_taggable was obsoleted in 2.0.x I’m using the ultra wicked has_many_polymorphs plugin which comes with a neat Tagging generator. I ran in a bit of problem when I tried tagging an object with the tags “cool mac 2008″. It turned out the “2008″ is the culprit since the tag_with method that’s introduced tries to be really smart about things. I.e. it assumes that if you pass a number in the tag_with string you actually want to use the Tag object with ID=2008. Of course we don’t have 2008 tags yet so it breaks down with an exception. The solution was really simple. Just remove the Fixnum check in the lib/lagging_extensions.rb ..

P.S. Better late than never: Happy 2008!!!

Posted in Home | Tagged , , , | Leave a comment

JRuby saves the day

So I’m rewriting yet another subsystem which consists of a mismash of several languages and programmer ego’s (hardcore C being the largest one, aargh) to what else .. Ruby. Everythings going smoothly. Every line of Ruby code replaces about 10 lines of “put other language here” cruft. Life couldn’t be more beautiful. But then I hit the wall, the Java wall. Here I’m confronted with a full enterprisy Service Manager complete with dependencies on Java-only libs. Now what? I could rewrite the whole thing in Ruby. But then there would be 2 implementations of the same thing to maintain, not to mention reading through Java code, bad.

Enter JRuby. Since the main code blob of this project is captured in a Mongrel plugin I thought about just deploying the whole of Mongrel on JRuby. Unfortunately JRuby Mongrel support was not there yet (Mongrel 1.1 supports JRuby). So the next best thing was to build some kind bridge between JRuby and Ruby + Mongrel + Plugin. Distributed Ruby (DRb) is a perfect fit:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#
# server.rb (this)
# jars/big-bad-service.jar
#
APP_ROOT = File.join(File.dirname(__FILE__), '.')

require 'java'
require 'drb'

require "#{APP_ROOT}/jars/big-bad-service.jar"

BigBadService = com.blah.BigBadService

class JRubyServer
  def initialize
    @bbs = BigBadService.new
    @bbs.initialize_service
  end

  def bbs_call(param) 
     @bbs.bbs_call(param)
  end
end

if __FILE__ == $0
  DRb.start_service 'druby://127.0.0.1:6666', JRubyServer.new
  DRb.thread.join
end

Execute like ruby server.rb, and then you’ll have the server listening on port 6666 of localhost. Nice, we can now call our Java service from other Ruby code with this simple snippet:

1
2
3
4
5
6
require 'drb'
DRb.start_service

java_bbs = DRbObject.new(nil, 'druby://127.0.0.1:6666')

puts  java_bbs.bbs_call("Whack!") #=> "Whacked!"

Kewl! Except for one big caveat. As of JRuby 1.0.x Java objects cannot be marshalled correctly so passing them to your Ruby code will cause all sorts of interesting hangs and crashes when you access them concurrently (see JRUBY-1235). Untill JRuby 1.1 is out you can synchronize all your calls to JRuby and making sure you convert any results to proper Ruby objects before using them elsewhere in your Ruby code.

This hack saved me loads of (Java hacking) time!

Posted in Home, ruby | Tagged | Leave a comment

GMail expanded

Today I noticed the following:

GMail’s mailbox growth rate is still faster than my fill one, sweeeeeet!

Posted in Home | Tagged | Leave a comment

Keeping things in perspective

Someone pointed out an article on How programming can ruin your life. I really enjoyed reading it and could definitely find myself in some (but not all) of the conclusions. The best remedy is IMHO replication. Nothing like your own version 2.0 to keep things in perspective:

:-)

Posted in Home, Misc | Tagged | 2 Comments

4 years in the making: SCO Group Files Chapter 11

Not much to add, except mwuhaha.

Posted in Home | Tagged | Leave a comment

NuSOAP together with PHP5-SOAP

Every once in a while I get to fix/add stuff from my PHP days. Today I installed php5 on a fresh Ubuntu Feisty install I need to host a NuSOAP based service API to a client. However, the Ubuntu php module comes with SOAP support built in. The PHP bundled SOAP implementation is far from complete and I guess most folks still prefer the good ‘ol NuSOAP. The problem is this:



Cannot redeclare class soapclient



Both NuSOAP and PHP’s SOAP use the same class name for the client implementation. Instead of uninstalling Feisty’s PHP module and rolling my own I decided to simply patch the NuSOAP 0.7.2 .php file and rename the class to nusoapclient. Saves a boatload of time IMHO. Patch to NuSOAP 0.7.2

Posted in Home | Tagged | 2 Comments

Torturing Ruby (and laughing at your own code)

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 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:

1
2
3
4
5
6
7
8
def splice_number(number, part_size = 4)
  n = number.to_s
  r = []
  return r if n.size.zero?
  (n.size / part_size).times { |t| r << n[(t*part_size)..((t+1)*part_size-1)] }
  r << n[-(n.size % part_size)..n.size] if (n.size % part_size) > 0
  r
end

Ah yes, WTF was I thinking when I wrote this? Who cares, it seemed very clever then! What does Flog think about this?

Total score = 28.35

none#splice_number: (28)
     7: size
     3: *
     2: %
     2: []
     2: <<
     1: +
     1: -@
     1: -
     1: /
     1: lit_fixnum
     1: zero?
     1: >
     1: to_s
     1: times

Pretty good score. Now it’s time for some torturing. Say hello to my little friend: unpack!

1
2
3
4
def splice_number(number, part_size = 4)
  n = number.to_s
  n.unpack("a#{part_size}" * (n.size / part_size) + ((n.size % part_size == 0) ? "" : "a*"))
end

Flog?

Total score = 13.05

none#splice_number: (13)
     3: size
     1: %
     1: /
     1: ==
     1: *
     1: +
     1: to_s
     1: unpack
     0: lit_fixnum

Yeow, well over half the pain gone!! Perhaps we can still improve by being less clever?

1
2
3
4
5
6
def splice_number(number, part_size = 4)
  n = number.to_s
  r = n.unpack("a#{part_size}" * (n.size / part_size) + "a*")
  r.delete("")
  r
end

More lines, but less code! Hmm?

Total score = 9.25

none#splice_number: (9)
     1: size
     1: /
     1: *
     1: +
     1: delete
     1: to_s
     1: unpack
     0: lit_fixnum

Weeh, a full 2/3 of the pain flogged out of the code! That’s all the torture I’ll do for tonight..

Update: Okay, couldn’t help myself, last blow:

1
2
3
4
5
6
7
8
def splice_number(number, part_size = 4)
  n = number.to_s
  p = "a#{part_size}"
  t = n.size / part_size
  r = n.unpack(p * t + "a*")
  r.delete("")
  r
end

With score:

Total score = 8.05

none#splice_number: (8)
     1: *
     1: size
     1: +
     1: delete
     1: to_s
     1: /
     1: unpack
     0: lit_fixnum

Done..

Posted in Home, rails | Tagged | 10 Comments

Old new job

I accepted a job offer 2 months ago at IndependentIP as “technical teamleader”. My “proefperiode” just finished and I’ll definitely be staying on, really love the way the company works. Lots of smart and funny (as in: haha) people working there too, time flies when you’re having fun!!!! And we’re definitely going to change the face of music distribution, keep watching!!

Posted in Home, Misc | Tagged | Leave a comment