Archive for September 19th, 2008

19
Sep
08

NTS: id xhtml attribute

 <td id="text_data">  <- Bad
 <td id="data">  <- Good

If you store a record’s Id into an xhtml id attribute, store it directly and don’t decorate it with any text, especially when the text is only a decoration.

This obviates the need to do javascript substring manipulation when you need the number.

Cheers!

19
Sep
08

NTS: Benchmark.measure

$> script/console
>> require 'benchmark'
>> result = Benchmark.measure { [your stuff here] }
>> puts result
>> xxx / 60

Divide the last number printed (the one in the parentheses) to get a rough idea of how many minutes the operation took.

I’ve had to, on a couple of occasions, fire of script/console in production and massage some data, basically apply some business logic on some Models. Sometimes this process can take a while, so, in order to provide some idea of the length of execution I can now execute this in my development environment and the staging environment.

You can also use this in scripts that you may use with script/runner.

Cheers!