Wanted: office space in Te Aro

March 3rd, 2009

We’re on the lookout for some office space in Te Aro. Somewhere between 75 and 125 square meters.

Our wish list includes:

  • Character
  • Earthquake safe
  • Showers
  • Cycle parking

Would appreciate a call if you’re aware of anything like this.

Clean restarts with Mongrel

January 22nd, 2009

The default init.d mongrel script lacked a setting which means that if your server lost power/crashed or you had a mongrel crash, the stale PID files remain and the mongrel_cluster_ctl start command will fail.

This simple fix works great.

Thanks Paul!

Javascript speed test results [UPDATED to include Google Chrome]

November 2nd, 2008

Test case: sorting a table containing 750 rows of data. Using the table-kit library.

Browser Time
Internet Explorer 6.0 (using an XP virtual machine) 19 seconds
Internet Explorer 8.0b2 (using an XP virtual machine) 5 seconds
Firefox 3.0 8 seconds
Firefox 3.1b1 pre 8 seconds
Safari 3.1.2 4 seconds
Webkit trunk (31 Aug 2008) 4 seconds
Google Chrome 9 seconds

It’s great to see modern browsers executing Javascript so fast. It will be interesting to see how Safari 4.0 compares, which is due to be released shortly.

test_fixtures plugin for Ruby on Rails

August 13th, 2008

Want to ensure that your test fixtures are valid? Use the test_fixtures plugin to validate each of your fixtures against the validations defined in your model.

It simply adds a TestFixtures unit test class to your ./test/units directory in your project.

More details are available on github

To install, run:

Breadcrumb trail – Rails plugin

July 28th, 2008

This plugin adds a breadcrumb trail to your Rails application.

In your action:

In your layout or view:

Generates something like:

You should use CSS to style the breadcrumb trail. See the example in public/stylesheets.

Sharesight article in the Herald

May 24th, 2008

There was a great article in the Herald about Sharesight today. Shame it didn’t mention me or Marcus, but it did explain what we’ve been up to.

Check out Kiwi-made online share trading system hits the market.

2008 Budget Calculators

May 22nd, 2008

We’ve just put together a calculator to work out your savings from Michael Cullen’s Budget 2008. It’s on the Sharesight website here:

http://www.sharesight.co.nz/tools/budget_2008_calculators/

Increment Ruby on Rails migration number

May 1st, 2008

We recently needed to create a new database migration, and needed to insert it into at certain position. Normally what I have done in the past is to alter the migration index of an existing file or two.

But this time, it needed to go in at 003. I was going to have to manually increment about 30 or 40 migration scripts. So, it was time to apply my Ruby skills to do it automatically.

Here is the result:

So when you run it, you will get output such as:

Instructions

  1. Cut and paste the file, or download it from increment_migrations.rb.
  2. Save it somewhere
  3. Make it executable chmod 755 /path/to/increment_migrations.rb
  4. The change directory to ./db/migrations
  5. then run /path/to/increment_migrations.rb 3
  6. and if the output looks as expected
  7. finally run /path/to/increment_migrations.rb 3 RUN

Finally, thanks to the client for permission to publish. Thanks for giving back to the community!

Work-around for running Rails/Apache in a subdirectory

April 11th, 2008

I’ve just configured Rails to run in a subfolder on a client’s website. Ran into a few issues, that are worth documenting:

In this configuration, you can visit the Rails site by visiting something like http://www.hostname.com/coolsite/

1. There is a Rails bug (ticket 10913) that effects links to assets. I have a link to our combined stylesheets defined as:

The bug is that Rails looks for all of your stylesheets in /public/coolsite/stylesheets/*.css, where ‘coolsite’ is the name of your subdirectory. Obviously, it should not be including the ‘coolsite’ folder in the path.

The workaround I use, is to create a soft link after capistrano deploys the code to our production server. I added this to my /config/deploy.rb file.

Now, whenever you do a cap:deploy, a soft link will be created in your public software, and this will allow Rails to resolve the stylesheet (and other asses files) in the faulty path. When the ticket is fixed, just remove the capistrano task.

Thoughts on Java and Ruby/Rails

April 4th, 2008

Over the last four months, I’ve been doing both Java and Ruby work.

Inland Revenue are building an external authentication system in Java Portlets on Websphere Portal. And, Sharesight are building an online share portfolio manager in Ruby on Rails.

I’ve noticed how different the two environments are when using 3rd party libraries. Take these two examples:

Using Display-tag for rendering multi-page tables

Display-tag is a Java library that has been around for a long time. I remember using it back at Westpac in 2005. It provides a JSP tag that you can use to render large collections – either on a single page, or over multiple pages. And provides the ability to switch between each of those pages with the expected next/previous and page 1/2/3/etc links. It also can sort the collection by clicking on the column headings.

Anyway, we ran into a problem. The functional specification document wanted the paging link positioned in a specific manner. This differed from what display-tag generated by default. The developer writing the tag spent a lot of time poring over the (good) documentation trying to find out how to make the links appear in the desired position.

Eventually, he came to the conclusion that the Display-tag library wouldn’t do it. The only way the achieve the desired outcome would be to use some CSS magic.

Using Mail queue for asynchronous email

Mail Queue is a Ruby on Rails plugin that converts the normally synchronous mail sending capability of Rails to an asynchronous queue. The emails get stored in a database table, and you use a background process such as cron or Backgroundrb to send the stored email.

It was all going very well, but we wanted to enhance the plugin to add the ability to archive the sent emails, rather than delete them. This would allow us to diagnose problems a lot easier.

In a Rails plugin, you have direct access to the source code. The plugin is stored in the vendor/plugins/mail_queue directory of your Rails project. We opened the mail_queue.rb file, found the code we needed to change, made the enhancement, and saved the file.

The differences

With Java 3rd party libraries, they are packaged into a standard JAR file. Inside the JAR file are all the pre-compiled class files. It’s difficult to see how the library is coded. If I wanted to change how a Java library worked, I’d have to:

  1. Download the “source” distrubution
  2. Unzip the distribution to a temp directory
  3. Find the code, and make the change
  4. Search for the build instructions
  5. Download Ant, or Maven, or similar
  6. Do I have the correct JDK version
  7. Hopefully the build works
  8. Replace the old JAR with the new build

Contrast that with the Rails approach:

  1. Find the plugin code and make the change
  2. Restart your server

It’s the dynamic nature of the Ruby language that contributes to the ease-of-modification. Being able to replace the change/build/package steps with just a change step makes a huge difference to productivity.

Conclusions

  1. Ease of modification means greater use of plugins
  2. Dynamic languages are the future