Some stats about Moves

Posted by Andre Foeken Tue, 11 Sep 2007 14:09:34 GMT

Moves has 45 controllers (4820 lines), 72 models (6457 lines), 121 test classes (4148 lines, still a work in progress...), 19 javascript classes (4560 lines), 176 migrations and only three developers :)

Posted in , ,  | 1 comment

Working with timeranges

Posted by Andre Foeken Fri, 31 Aug 2007 19:23:31 GMT

Everything in moves 'acts_as_placed_on_timeline'. This entails that every object has a valid_from and valid_to field, which specify when they are active.

A simple example is an address, it becomes active (valid_from) when a person starts living there and is deactivated (valid_to) when the person moves to another address.

Looking at the example above it is hard to see why this would ever pose a problem with code readability. Hang in there a moment longer.

Read more...

Posted in ,  | Tags , , , ,  | 1 comment

Gettext Generators 1.2.3 Released

Posted by Bart ten Brinke Tue, 28 Aug 2007 18:43:07 GMT

The longawaited update for the Gettext Generator.

  • First release as plugin
  • Added svn:merge raketask
  • Updated generated resource to mimmick scaffold_generator packaged with rails 1.2.3 tag

So go to RubyForge or take a look here.

I'm currently getting the plugin uploaded to rubyforge. As soon as I have that figured out how that works, I'll post the link here.

ruby script/plugin install svn://rubyforge.org/var/svn/gettextgnrtrs/tags\ /Gettext-Generators-1.2.3/

Posted in , ,  | Tags , ,  | no comments

How to find all those stray y, puts and prints in your code

Posted by Andre Foeken Tue, 28 Aug 2007 15:49:23 GMT

I have it all the time, I add some nasty console output to my ruby and some gets left behind. I wanted this to stop so I built a small regex to solve my problem.

    {   name = 'console.output.ruby';
        match = '^\s*(y|puts|print|printf)[ ].*';
    },

If you add this to the ruby language def in Textmate and then update your style theme with a bright color (scope: console.output.ruby), those nasty buggers will really stand out.

If you just want to get rid of them just run the regex above on your file (replace).

Posted in  | Tags , , , , ,  | 2 comments

Solving some gem install problems

Posted by Andre Foeken Sun, 29 Jul 2007 16:08:14 GMT

Lately we have been having some issues installing gem that have to compile native extensions like libxml-ruby and termios.

The error we got from libxml was: "extconf failure: need libm". Strangely this was all caused by incorrect compile flags in the rbconfig.rb file.

To fix this (and other issues) you can customize the rbconfig.rb file to your specific computer.

Mine was located in:

 /usr/lib/ruby/1.8/universal-darwin8.0/rbconfig.rb

On leopard this is universal-darwin9.0. The file contains a lot of config definitions. I removed all traces of any other architecture then i386 (like -arch x86_64, etc). I also removed the 64 flag that was included.

After altering this in the entire file (quite a few replaces), everything compiled happily.

update

I was also having some issues with the SQLSessionStore plugin. Seems recent changes to ruby have made it a no-no to alter constants (no surprise there). So now in stead of doing

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS. update(:database_manager => SqlSessionStore)

You have to do:

dso = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS dso[:database_manager] = SqlSessionStore ActionController::CgiRequest.send(:remove_const, "DEFAULT_SESSION_OPTIONS") ActionController::CgiRequest.const_set("DEFAULT_SESSION_OPTIONS", dso)

Which is uglier, and still should not be possible :)

To make it work I also had to remove the require 'mysql' line from the plugins MySqlSession.rb file. Else it would crash rails with the following error:

warning: already initialized constant OPTIONS

Posted in ,  | Tags , , , , , , , , , , ,  | no comments

Sort, sort_by and group_by

Posted by Andre Foeken Sun, 29 Jul 2007 14:57:24 GMT

I wanted to put the spotlight on some small but very useful ruby on rails functions: sort, sort_by and group_by.

Let's start with sort and sort_by. Its basic function should not come as a surprise: it sorts a list.

[1,3,2,4].sort => [1,2,3,4]

These functions really shine when you use objects inside the list.

a = { :key => 0, :value => 'a', :extra => 0 }
b = { :key => 1, :value => 'b', :extra => 0 }
c = { :key => 2, :value => 'c', :extra => 1 }
d = { :key => 3, :value => 'd', :extra => 1 }

[a,c,d,b].sort_by{ |i| i[:key] } => [a,b,c,d]

The previous example already contains the correct objects to demonstrate the use of group_by so we just give that example now.

[a,b,c,d].group_by{ |i| i[:extra] } => [ 0=>[a,b], 1=>[c,d] ]

As you can see this gives us the power of the SQL group_by statements right inside ruby. Sure, this cannot beat the speed of the SQL equivalent. But sometimes when speed is not really an issue or when you just can't query the right results, group_by can be a real life-saver.

As a bonus, when you want to group_by or sort_by functions on objects, you can use this pretty shorthand:

[a,b,c,d].group_by(&:length) => [ 3 => [a,b,c,d] ]

If you are wondering why the above works, it is just basic ruby. Any function that is defined to receive a &block can be called by either giving it a block of code in parenthesis or by passing it a proc object. The &:length is just shorthand for &proc{ |i| i.length }. Too bad you can't pass it arguments using the shorthand, then you'd be able to write:

[a,b,c,d].group_by(&:fetch, :key)

Hope you find this useful, if anyone knows if the above code is indeed possible in another form, please comment!

Update: I recently found out you can also use arrays in combination with these functions. So you can sort by multiple values. If you pass array [a,b] to a sort function it will sort by a and then sort by b. Very handy!

Posted in ,  | Tags , , ,  | 5 comments

Building a database logger

Posted by Bart ten Brinke Wed, 18 Jul 2007 07:30:38 GMT

Sometimes you don't want to log to a file, but to your database. A quick and somewhat dirty way for this:

 script/generate scaffold_resource LogEntry severity:string, \
  time_stamp:datetime, progname:string, msg:string

With the following logger:

class MovesLogger < Logger

  def format_message(severity, timestamp, progname, msg)
    logEntry = LogEntry.new({:severity  =>  severity,
                           :timestamp  =>  timestamp,
                           :progname   =>  progname, 
                           :msg        =>  msg})
    logEntry.save
    return nil
  end  
end

Now you can use logger = MovesLogger.new($stdout) and everything will be neatly logged to the database!

Posted in  | Tags , , ,  | 3 comments

Rails OSX Problems

Posted by Bart ten Brinke Tue, 03 Jul 2007 08:57:16 GMT

After updating my MacBook yesterday, I found myself with a broken rails. I reinstalled Rubygems, but this gave me some strange problems when installing gems:

   bart$ sudo gem install mongrel
   Building native extensions.  This could take a while...
   Successfully installed mongrel-0.3.3
   Installing ri documentation for mongrel-0.3.3...
   Installing RDoc documentation for mongrel-0.3.3...
   bart$ sudo gem install mongrel_cluster
   Install required dependency mongrel? [Yn]  Y
      ERROR:  While executing gem ... (Gem::GemNotFoundException)
       Could not find mongrel (>= 0.3.13.4) in any repository

But when I looked at the versions, it said 1.0.1 of mongrel was available. After some help of Andre, we found out the problem: Ruby. As the OSX update had trashed my .bashrc path settings, I got the old ruby version packed with darwin (1.8.2) instead of the fink version (1.8.5). This causes the strange problems like the one above, as mongrel requires a newer version of ruby. Making the path look in /usr/local/bin before anything else cleared up everything nicely.

Posted in ,  | Tags , , ,  | no comments

RubyEnRails is over...

Posted by Andre Foeken Fri, 08 Jun 2007 07:59:08 GMT

It was fun! It was our first talk at a techy conference and we enjoyed it very much.

We had a nice chat with Dr Nic and some guys from fingertips and learned some new tricks :)

We hope the movies from the presentations will become available shortly so everyone can enjoy.

Here are the first set of movies, with special thanks to Byte Internet for the Bandwidth and for being our Rails hosting partner :).

1. Mac Style Login

How a simple prototype shake can be a lot more effective then an error popup.

2. Helping users made easy

Form validations in Rails are automatically uniform and centralized in your Model. Great functionality for free! Yes I know there is something weird with the gettext translation. This is fixed in the trunk :)

For some nice pictures, point your browser to Flicker. The podcast of the presentation should be comming soon!

This was brought to you by both Andre Foeken and Bart ten Brinke. Cheers!

Posted in ,  | Tags , , ,  | no comments

SOAP hell? ARes Heaven?

Posted by Andre Foeken Mon, 04 Jun 2007 16:44:31 GMT

Linking Ruby to Ruby was no problem. Even Java to Ruby seemed to work just fine. But the problems started as we grew past the infant stage and tried to send more that say a thousand records over the SOAPy connection.

The amount of XML was just to big to handle, the speed became unacceptable. Our first instinct was Gzipping the files, but that made almost no difference. Finally we tried SWA, SOAP with Attachments. SWA worked flawlessly...in Java...and in Ruby. Just not together. We tried everything but no luck.

Finally we decided we needed a fresh start, we threw the SOAP away (with the bathwater) and took a look at ActiveResource (Ruby) and RESTLets (Java).

ARes is wonderful, it worked (almost) out of the box and there was a lot less overhead. Combined with Zlib::Deflate this proved to be a good alternative. Sure it still doesn't win any speed races, but it is functional, easy to set up and simple to maintain.

The definition of almost:

Ticket 8563

Ticket 8566

Ticket 8567

Ticket 8568

Posted in ,  | Tags , , ,  | no comments

Older posts: 1 2 3