Autotest 100% CPU solution

Posted by Bart ten Brinke Wed, 06 Feb 2008 08:48:27 GMT

Autotest is great, but when it is waiting for test, my MacBook turns into a whirlwind as autotest takes 100% CPU. After looking at autotest.rb, we easily find the waiting function:

def wait_for_changes
  hook :waiting
  Kernel.sleep self.sleep until find_files_to_test
end

As self.sleep is defaulted to 1 it means that my laptop does not sleep at all. Changing this is quite easy, as you can just add this to your .autotest file in your home directory:

Autotest.add_hook :initialize do |at|
  at.sleep = 5
end

Experiment with the amount to determine what works for you. Offcourse autotest will now react slower to you changes, but hey: you can't have everything. Enjoy the silence!

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

The new programmers excuse for slacking of

Posted by Bart ten Brinke Thu, 31 Jan 2008 13:40:26 GMT

Original by XKCD.

Posted in , ,  | Tags ,  | 4 comments

Cha-Ching and dutch banks

Posted by Andre Foeken Wed, 23 Jan 2008 19:38:23 GMT

Like lots of you I bought the incredible MacHeist app bundle last week. One of the appz was Cha-Ching, a finance program to keep track of your money.

One of the most useful features is the import. You can simply import all of your bank's records and be done with it. Unfortunately the dutch banks (or at least the Rabobank and Postbank) don't support the same formats Cha-Ching supports (like OFX/QIF).

I wrote a small ruby script to convert the banks CSV files to OFX files. There are two separate files below (one for each bank):

CSV convertor - Postbank (Ruby)

CSV convertor - Rabobank (Ruby)

Before you can run the files you need two additional gems (if you haven't got them already).

sudo gem install extensions
sudo gem install builder

After this you can use the scripts like this:

ruby csv_convert.rb [CSV FILE] > export.ofx
ruby csv_rabo_convert.rb [CSV FILE] > export.ofx

Update: Now supports Tiger using PHP version of script and (optional) automator

For the next files you don't need anything else than a vanilla Tiger install of OSX.

CSV convertor - Postbank (PHP)

CSV convertor - Rabobank (PHP)

You can use them like this:

php csv_convert.php [CSV FILE] > export.ofx
php csv_rabo_convert.php [CSV FILE] > export.ofx

For the simple version, use the automator zip file! Read the README to get it to work.

CSV convertor - Postbank/Rabobank (PHP/Automator)

Posted in ,  | Tags , , , , ,  | 15 comments

Testing your Application Controller with rSpec

Posted by Bart ten Brinke Wed, 23 Jan 2008 13:35:15 GMT

I was trying to create a function that would check the enforcement of the before filters in my application controller. After going through a lot of rspec documentation and examples, I found nothing that really suited my needs. After a long google, I found a mention in the rspec mailing list and a hint to a solution for this. This is a working example of this idea.

I have in my application controller the following code:

class ApplicationController < ActionController::Base
  before_filter :check_authorization
   ....
  # Checks if a user is authorized
  def check_authorization
    User.check_authorization(controller_name, action_name)
  end
end

And in spec/controllers/application/application_spec.rb the following description.

describe "an authorized controller", :shared => true do

  it "should have the check_authorization set in the before filter" do
    ApplicationController.before_filters.should \
      include(:check_authorization)
  end   
end

In all other controller specs I can now do this:

require 'application_controller_spec'

describe UnitsController, "in general" do
  it_should_behave_like "an authorized controller"
end

By doing this I now have a spec that ensures that every controller checks authorizations before doing anything else. How cool is that :)!

It would be nicer if the test handled skip before_filters in some nice way like: it_should_behave_like "a monkey".except_for_action('show'). Has anyone got any ideas for that?

Special thanks to Matthijs Langenberg for his insights.

Posted in  | Tags , ,  | 13 comments

Rspec plain text stories

Posted by Andre Foeken Tue, 06 Nov 2007 14:54:06 GMT

Simply said. They are great. We've been using them since they came out and have been following the trunk ever since.

They are so easy and elegant, they just needed a little TextMate love. So here you go: A language grammer and an adapted Vibrant Ink theme. (Download here)

P.S If anyone can tell me how to include stories in autotest runs I would be very happy!

Posted in , ,  | Tags , , ,  | 4 comments

Moving to 2.0

Posted by Andre Foeken Thu, 18 Oct 2007 13:27:19 GMT

Issues found so far:

  • Lots of small routing changes. Thank god for grep! : addresses_path(@employee) => employee_addresses_path(@employee) . (Don't forget the *_url methods!)

  • Several plugins failed due to extract_options_from_args!. This method has been replaced with the nicer: args.extract_options! (i.e acts_as_paranoid, acts_as_mappable, paginating_find)

  • acts_as_paranoid had minor issues: fix by replacing construct_count_with_legacy_args to construct_count_options_from_args

  • ActiveResource is now part of rails core. Be sure to freeze edge twice if you are upgrading from 1.2.3 or lower. All of our libXML additions had to be redone. (this time through /patches, tnx fngtps)

  • Different behavior of the render method. Before you could call render "addresses/show" if you wanted to, this has been changed to render :template => "addresses/show". This affects several plugins too (like rspec_on_rails)

  • We no longer need the mysql_tasks plugin, since this functionality is now build right in!

  • redhillonrails_core has some issues with connection adapters. Apparently rails 2.0 no longer loads adapters it doesn't need. This creates some issues with the redhills plugin since it tries to include stuff in those adapters. Adding a begin/rescue block around each include solves the issue.

  • The development environment no longer needs the config.breakpoint_server = true setting.

  • Polymorphic models are now saved with the base class as type in external objects.

  • Autocomplete textfields are now a plugin: ./script/plugin install auto_complete

  • If you have overridden the to_json methods, be sure to change that to to_json options={}, else they might fail.

  • Migrations no longer working? Try removing duplicate names. We have two migrations with the same name (but different id) and it just skipped the first one (!)

Benefits so far:

  • Speed! We did expect some speed increase, but this is major! Our pdf generating stuff uses a lot of ActiveRecord and we saw decreases of more than 50% request time.

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

ActiveResource: REST, WSDL, XSD?

Posted by Andre Foeken Mon, 24 Sep 2007 14:28:28 GMT

We love REST. It's simple and clean, and combined with ActiveResource it is certainly the best app to app bridge we've worked with so far. But...

What if you want to have more freedom? Say we want to build a database based on a REST webservice. Now imagine we don't want any info about the service in the ruby program that actually builds the db.

We are facing two major problems:

  • We don't know which resources are available.
  • We don't know the fields and types of the resource in advance.

The first problem will eventually be solved with WSDL 2.0 or if you need a solution right now: by a default listing resource.

 # Our default object is called a Resource, on the server we have 
 # a Resource object that just returns each resource we have in 
 # a string array.
 resources = Resource.find(:all)
   => ["address","person","country"]
 # Now we can do all kinds of crazy stuff :)
 resources.each do |resource|
   name = resource.capitalize.to_sym
   new_resource = Object.const_set(name, Class.new(ActiveResource::Base))
   new_resource.site = Resource.site
 end

After this little piece of code we have a full dynamic set of ActiveResource classes ready to be used :)

The second problem we face is much more interesting. Normally some kind of resource definition would be applied like XSD. But native ruby XSD support is kind of lacking (it sucks) and more importantly it doesn't feel like a rails solution.

We wanted a cleaner, simpler and more elegant (more RESTy) solution. How about Person.schema?

It returns an ActiveResourceSchema object:

Person.schema.fields
   => { :name => FixNum, :date_of_birth => DateTime, 
:parents => [{ :id => FixNum }] }

What happens is actually quite simple. When the Resource objects receives the schema method call it calls find(:first, :params => { :schema => true }).

The server responds to this param with a sample record, with just the field names and types. We build an ActiveResourceSchema object to wrap those and return a nice array of fields :)

Note: These code snippets are just examples, we are currently building this. If there's enough interest we might submit it as a plugin/patch for ARes.

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

Rails Security

Posted by Bart ten Brinke Thu, 20 Sep 2007 17:30:54 GMT



After a security presentation at RailsConfEurope 2007, I found a lot was missing, so I made this. I didn’t finish it in time for reject conf, so I posted it here. Now it's time for me to go on vacation! See you next week!

Posted in  | Tags , , , , ,  | 8 comments

Solving PO translation conflicts

Posted by Bart ten Brinke Mon, 17 Sep 2007 17:11:24 GMT

If your using gettext in an svn environment, you probable have had the following problem: You and your colleague add some code and some translations. Now you check in your work. What will happen is that the last one o the two who checked in has a major problem. He has a conflict in the po and mo, as they differ. But his mo and po are also completely wrong, as they are based on a now old version of your application. To make things worse, subversion does an extremely bad job in resolving this, as it tries to juggle the three versions.

Luckally I added something to the latest version of my gettext generators plugin: the svnmerge rake task. It works as follows:

 rake gettext:pomerge FOLDER=/po/nl-NL/ APP=moves VER1=mine VER2=r318

What this does is create a new po and mo file so that they reflect you current mess. It then fills the new po translation with translations coming from the two conflicting versions (the mine and the r.318) in this example. It does this by using msgmerge in a smart way (so you need msgmerge for this).

After this is done, mark your po, pot and mo as resolved, run rake gettext:makemo and check your source in with a smile.

This was brought to you live from the lounge of Railsconf europe 2007 :).

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

RailsConf Europe is near!

Posted by Bart ten Brinke Thu, 13 Sep 2007 07:19:19 GMT

Sunday we will be travelling to Berlin, to attend Bratwurst on Rails :) Yeah! And after that three days of rails enthusiasts, crammed into a Hotel for RailsConf Europe 2007. Apperantly it is completely sold out.

If you're going too: See you there! If you are not... well ... you're an idiot! Go to the next one!

See you next week!

PS: We are also going to bratwurst on rails Sunday. We will not be easily recognizable in our cool baseball long leeves with YIELD on the back, as we were to late in getting them printed :).

Posted in  | Tags , , ,  | 3 comments

Older posts: 1 2 3 4 5