2009-01-20

Look how smart I am!

Update: Original problem was solved with hirb. Good job Gabriel!

Recently I was analysing data on production server. Problem domain I worked with is quite complex and consists of several different models. Rails provides great tools to easily cherry-pick interesting data using named_scope, conditions, includes, through. I ended up with a list of records I wanted to inspect.

I worked using console, through screen. List was too long to use 'pp', scrolling with screen is also not too great. What I needed was a simple table with a few columns (and not full list of model's properties). Something among the lines of:


+----+----------------+-------+-------------+
| id | job_posting_id | state | published_at|
+----+----------------+-------+-------------+
| 1  | 20             | del   | 2008-01-01  |
| 2  | 23             | del   | 2008-01-01  |
| ...| 24             | act   | 2008-01-01  |
+----+----------------+-------+-------------+

Recently I have noticed Ruport which at glance looked like a perfect tool for a job. But it wasn't.

After a few hours of skimming through examples, documentation, and even a book (now free as in beer! - recon that) I failed to find a single concise example of how can I achieve my goal.

Rather, Ruport authors assume that you will be willing to use their CSV loading code, or maybe their acts_as_reportable plugin and surely rewrite half of your application, including record selecting logic, possibly ignoring any goodies Rails provides in this area.

Now do not get me wrong. I'm not saying that Ruport is a bad software. I actually have no idea if it's good or bad. But it does not provide quick solution for the simplest case possible.

Both documentation and API focus on how great Ruport is and how great it manages your reports. It fails to show how Ruport can easily aid you in your daily tasks.

It's a perfect example of Ruport's authors 'Look how smart I am' approach. Personally I prefer to use software which is written in 'Look how easy it is' manner.

Update: While looking for solution to my problem I encountered official ruport discussion group. To post there you need to apply for membership, which I did. After two days my admission was rejected... Good job in helping your users, guys!

Enumerate lists AND single items

So far when I wanted to make sure I have something to iterate over I used following snippet:


[variable].flatten

This is not accurate in case variable is an array of arrays but was enough for most of my cases.

Today I have found a nice trick on Ruby Inside:


[*variable]

Not only it's fully accurate, it also has speed advantage over previous solution (benchmark code):


Rehearsal ------------------------------------------------------------
Single element flatten     0.110000   0.000000   0.110000 (  0.118731)
Single element splat       0.190000   0.000000   0.190000 (  0.196618)
Multiple element flatten   6.800000   0.090000   6.890000 (  7.115833)
Multiple element splat     0.070000   0.000000   0.070000 (  0.076305)
--------------------------------------------------- total: 7.260000sec

                               user     system      total        real
Single element flatten     0.260000   0.000000   0.260000 (  0.270906)
Single element splat       0.320000   0.010000   0.330000 (  0.338638)
Multiple element flatten   6.450000   0.060000   6.510000 (  6.665572)
Multiple element splat     0.070000   0.000000   0.070000 (  0.072873)

Not like micro-optimizations matter...

2009-01-11

Metadata for your Rails based site

I have recently found a link to Rails plugin that allows to simply add meta tags to your views and layouts.

In my projects however I do not need the kind of flexibility that plugin uses. Rather my needs are quite simple: provide description and keyword meta tags. In most cases generic, but customized for some views.

I have decided to create a plugin that is a complete rewrite of ideas used in my current projects. In addition it's my first attempt to publish the gem through github.

Plugin is called site_meta and allows to easily add description and keyword meta tags to Rails applicaitons. In addition it simplifies title handling - both in head and in body part of the page.

See site_meta github page for installation and usage instructions, and site_meta documentation

2009-01-08

Stupid web developer

Some web developers should be shot. Remainings should be shot again:

Stupid web developer
Uploaded with plasq's Skitch!

How stupid do you have to be to:

  • print out text of appeal
  • hand it over to city president to sign
  • scan the document to 100k JPG
  • put it on the web page as an overlay that covers the whole page

Because the web developer is stupid, right? It sure is impossible that city president may be as stupid to request that!