Rails

Code blocks with optional arguments in Ruby 1.8.x

Ruby 1.9 has some cool new features. One of them is the ability to define default values for the arguments passed to code blocks, like in the following example:

pow = proc { |a, b = 2| a**b }
 
pow.call 3, 3
# 27
 
pow.call 3
# 9

This is very useful, for instance, when we dynamically create new methods using metaprogramming and want some of the arguments for these methods to be optional.

class MyMath
  class < < self
    define_method

Continue reading

How long will it take to understand Rails 3 in and out?

Brad Midgley

According to David Heinemeier Hansson, you will never understand it all. Case in point? David himself.

That was the gist of his answer to how a new change to the way rails 3 renders actions in the browser would be handled for older browsers.

DHH gets involved in the parts he cares about and doesn’t worry about the exact details that have been delegated to someone else. He says we should not worry about knowing the whole framework because he doesn’t either.

Continue reading

Linux kiosk

Brad Midgley

I recently did some maintenance on a linux-based kiosk project. It runs linux and has a rails application serving content. Firefox is running in a kiosk mode and there is no keyboard or mouse present.

In adding a touchscreen from a different vendor, I found some details that can help make a kiosk application more responsive to touchscreen taps.

If you use linux in a touchscreen implementation, I recommend staying away from linux drivers offered by the vendor if possible. These were

Continue reading

processing large xml data files

Brad Midgley

Getting to Railsconf 2009-26XML is often used to convey very large data sets. A perfect example is wikipedia’s data. The full wikipedia datasets are available in several different slices.

This dataset is about 24GB uncompressed for all articles in English. This is an excellent set to push the limits on your parser. Clearly, you can’t load a file like this into memory to process it. To handle a

Continue reading

rails app producing “error or missing database”

Brad Midgley

You see an error like this in your logs: ActiveRecord::StatementInvalid (SQLite3::SQLException: SQL logic error or missing database: INSERT INTO…). The statement it prints out is working fine when you run it directly.

First, one thing you can tell from this error is you are running the application using a different user id than you are testing with. Are you completely sure you want to run sqlite3 on some kind of production system? :)

If you really are sure, then address the problem. The other identity can’t read/write the database file AND folder.

Continue reading

New graphing options for metric_fu

Output from reek code smell metric in metric_fu

Metric-fu is a handy set of rake tasks for running various metrics on your project’s ruby code and tracking the overall health of your code base. It can give you some interesting insights into things like how good the code coverage of your tests is and how well-designed your code is. It can also track the progress of your code over

Continue reading

Using cucumber and webrat for remote web testing

Cucumber and webrat serve as a powerful combination of tools for testing your web applications, but in its most common mode webrat can only test your application locally. Is it possible, you may ask, to use webrat to test a remote web site? The answer is yes, with a little tweaking. Webrat has a configuration option that tells it to use mechanize (a screen-scraping tool for ruby) instead of the built-in rails view testing system.

Continue reading

RadiantCMS customized

Brad Midgley

Kolob Canyon greenery

We are working on a very interesting project right now that allows us to adapt RadiantCMS to serve several different functions in a big picture system.

Radiant is a powerful content management system that has very good design for factoring out redundancy in your web content. Think of the Don’t-Repeat-Yourself principle applied to the web content, where we unfortunately put up with duplication far too often.

I was impressed with

Continue reading

best railsconf title

Brad Midgley

The best title had to be When to Tell Your Kids About Client Caching. Parents might identify more with this. Interesting stuff in any case.

Continue reading

Ruby performance work

Brad Midgley

Railsconf had several performance-related talks. This one went over a lot of interesting territory.

  • Who knew the Date class performed so badly?? Use equivalent ops in Time or get date::performance
  • Use String::<< instead of String::+=
  • Tune your custom sql with virtual attributes

It’s surprising that things we might not think are performance issues are problematic in ruby. One reason to optimize after you gather metrics that identify problem areas.

rowing

(Image courtesy of rowingbike.com)

Continue reading