Feeds:
Posts
Comments

Archive for the ‘Tech’ Category

Alan deLevie posted a useful bit of Sinatra code for documenting the tables in a database in Database documentation in 50 lines of Sinatra.
I built on his code, making it database-agnostic while also turning it into a tool for comparing database structures. In the process the line count nearly doubled, so now we have database documentation in (almost) 100 lines!

It has been tested against Mysql, Postgresql and Sqlite databases.
(more…)

Advertisements

Read Full Post »

All of a sudden Firebug was showing a Javascript error when I clicked on an expanding panel in a page of my Rails app. This had been working for ages and I had done no changes in that area, so it was a bit of a puzzle. I had just upgraded Ubuntu (and Firefox along with it) though.

The error Firebug showed was:
An invalid or illegal string was specified"  code: "12 pointing to line 2844 in prototype.js

Line 2844 in prototype looked inoffensive enough:

results = $A(root.querySelectorAll(e)).map(Element.extend);

The offending line in the application’s javascript didn’t scream “problem” either:

elem.down('img').replace('<img src="/images/panels/active.gif" alt="hide section" />');

After a great deal of head-scratching from poring over the code, I turned to Google and eventually found this page:
perhaps javascript is not ready for xhtml 1.1 yet
The comment from Tobias revealed the issue – an all-numeric id attribute.
The div concerned had an id attribute set to 2009-12-16. Once I changed this to panel-control_2009-12-16 everything worked smoothly again.

I guess Firefox 3.5.x is stricter about these things than Firefox 3.0.x was.
Moral of the story and a mantra for my memorybanks: All id attributes should begin with a letter.

Read Full Post »

Easy grep for Rails projects

As a lazy programmer I wrote grepr to save a bit of time/thinking.
While working on my Rails projects I often use grep in a terminal while I work on my source in Gvim. This typically means running grep on all subfolders of the app and in the lib folder. I almost always use the colour, line numbers and case-insensitive flags.

The process tends to go like this:
Press F12 to drop down the Guake terminal.
Run grep. Refactor (fiddle with the dirs and other arguments in the command) and run some more.
Toggle focus between Gvim and Guake.
Thinking about the nuances of grep’s arguments scatters my focus more than I’d like, so I simplified things a bit.

grepr without arguments displays help:

grepr usage

grepr usage

The options are designed to be easy to remember (m=model, v=view, c=controller etc) and easy to ignore. (more…)

Read Full Post »