Older blog entries for fxn (starting at number 458)

20 Jan 2007 (updated 20 Jan 2007 at 09:17 UTC) »

model_auto_completer

I think a company that takes as much from open source as mine has to contribute back somehow. In this line, this week we extracted, polished, and published as Rails plugin a widget we wrote for a project. That's model_auto_completer.

In Rails there's a builtin textfield with autocompletion (via Ajax, you know). With that textfield you are able to offer autocompletion of strings. But sometimes you'd like to be able to autocomplete something to select a model.

Say you are implementing a bookstore backoffice. In the form for book edition you want the user to be able to assign an author to the book, but there are hundreds of authors in the database, so a select is not usable. With this plugin you can offer a textfield that autocompletes by author name and manages a hidden field with the corresponding database ID under the hood.

In its most basic use case the usage is:


  <%= belongs_to_auto_completer :book, :author, :fullname %>

Things are defined in such a way that you don't need to do anything special in the action that processes the form, update_attributes(params[:book]) will work out of the box.

There are some options available, a much more generic helper, and the ubiquitous class method for controllers that generates an action dynamically.

We wrote the widget on top of the builtin autocompletion facilities provided by Rails, so the contract with the action is the same, except list items are expected to have an ID attribute. By default, any trailing integer there is assumed to be the ID of the corresponding model. That's a configurable regexp and it is a weak contract on purpose, so users can easily avoid HTML ID collisions.

The generated HTML elements have a trailing random suffix as well in their IDs, so that you can include more than one widget for the same completion in the same page.

7 Jan 2007 (updated 7 Jan 2007 at 15:30 UTC) »

The DPie E-Bike

I bought last summer a Monty DPie. Think Segway with three wheels, much less sophistication, but great fun and just 400 €. This e- bike is made by Monty, a world-class bike manufacturer.

This thing has an outstanding stability, you can go down and up the sidewalks at any speed and approaching them at any angle, go off-road, and even jump. It has a maximum speed of 18 km/h, and a theoretic autonomy of 25 km. The autonomy depends a lot on the weight of the driver and the driving style. With my 91 kg and funny driving style the battery gives me barely 12 km, and performance decreases a lot there.

It's a very amusing toy, and when I enjoy it the most is taking walks with my little daughter, who is two years and a half old. She sits on that yellow cover in the middle, puts her hands around that curved yellow bar, some doll in her lap that enjoys the walk with her, and you can imagine, what a great time! I even bring her to the kindergarten in the e-bike, that's 3 km away from home. Going there early in the morning, having so much shared fun with my daughter while we go to the kindergarten is a marvelous way to start a day.

There's a demo video of the e-bike here.

3 Jan 2007 (updated 3 Jan 2007 at 13:11 UTC) »

Race conditions in the Bundled Resource Rails plugin

The Bundled Resource Rails plugin bundles some extensions and copies resources to public/bundles when the server starts. The code that copies those files has race conditions, and so if you launch a multiprocess server like mongrel_cluster it often happens that some instance just crashes at startup.

To fix that and still leverage the plugin it is enough to do this:


    $ cd app_root
    $ svn export vendor/plugins/bundled_resource/bundles public/bundles
    $ svn add public/bundles

Then comment lines 54 to 57 in vendor/plugins/bundled_resource/ init.rb and commit.

26 Dec 2006 (updated 26 Dec 2006 at 03:11 UTC) »

Home Page moved to Dreamhost

I have moved my until now static home page to Dreamhost. I have changed a bit the style and have rewritten it as a Rails application.

17 Dec 2006 (updated 17 Dec 2006 at 18:16 UTC) »

Good Deal

After almost two years of usage, most of it in my Goldwing, the hard disk of my 3G iPod 20GB died this summer. Apple's warranty covers only one year, but since in Spain you get necesseraly two years by law that hard-disk was still covered.

Indeed, Pixmania would replace the unit, but since they had no longer a model like that one they gave me the option to get my money back as credit in their shop. And so, for just about 20€ I have bought a gorgeous black iPod Video 80GB. Now that's a good deal!

26 Nov 2006 (updated 27 Nov 2006 at 08:42 UTC) »

Giving a talk with TextMate

My talk at the Conferencia Rails 2006 delved into Rails internals and so the content was mainly source code. I tried several approaches to writing it, from Keynote to a quick and dirty script to run text slides in Terminal.app. But the place where code lives is the editor, and so that was the final choice. You get syntax highlighting, scroll bars, and no need to copy and paste with style between applications. It feels like the right place to show code.

The editor of choice was TextMate, I use it practically since it was available. I prepared the talk in a project that contained the Rails source tree, a dummy Rails application to try stuff, and the very slides. To trace code execution in Rails I used plain old Find in Project most of the time. The actual presentation was in a different project, groups were used to structure the presentation in sections and allow for slide ordering within them.

To start the talk all files are opened beforehand, one by one. The easiest way to do that is to select the first one, focus on the editor, type ⌥⌘> (or ⌥⌘` depending on your keymap), and go down the drawer. With that trick Allan told me in the mailing list you go down the project opening files because the focus remains in the drawer.

When I give a talk or a class I always like to freely walk around, and so I normally use some kind of remote control. How could I use one here? I played around with Salling Clicker to no avail, but finally discovered Mira provides a way to assign keystrokes to Apple Remote buttons (why are Apple Remotes white for black laptops?). It was trivial to map play/menu to ⌥⌘⇢/⇠ to move to the next/ prev tab. I could even map increase/ decrease font size and scroll up/down to the rest of buttons. Very handy.

As a final touch, you can get full screen mode with megazoomer. All in all the presentation took the form I exactly wanted for this talk.

26 Nov 2006 (updated 26 Nov 2006 at 11:07 UTC) »

Back from a very successful Conferencia Rails 2006. We were about 150 people in Madrid, plus a few people in Mexico and Argentina connected via teleconference. The organization was excellent.

There were different kind of talks, most of them technical as usual, but there was an interesting round table of Spanish Rails-based companies, and a very good talk about Rails seen from the point of view of the salesman, given by Agustín Cuenca, the CEO of my company. To close the conference there was a session of questions for DHH, who kindly attended the session via teleconference.

It was nice to match names and faces, the Rails community in Spain is just taking shape as in any other place. I think this event will be an inflection point here.

I have been working in my talk about Rails internals for the Conferencia Rails 2006. Rails is about 55K LOCs, aproximately 34K in libs and 19K in tests. In the talk we explore just a corner of that, tracing the execution of code behind some particular feature like class reloading. Working on this talk is being a good exercise.

Alive

I have been very busy lately, and this will last until the end of the year probably. $work is taking a lot of time, we are already ten people in the company. Additionally, in my non-existent free-time I am giving a semester on Perl at the University of Barcelona.

I am preparing a talk for the upcoming Conferencia Rails 2006, to be held in Madrid. There we will have a walk through the source code of Rails, to understand from the very source how are core classes extended, what happens when Rails boots, how are classes reloaded, which is the flow of a request, etc. This is a good way to exercise your Ruby.

miguel gave a talk about Mono in my faculty this week. People who wanted went out to dinner afterwards, I think we were 16. We had a good time.

449 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!