Programming

Why I Decided To Use FSFS Over Berkeley DB With Subversion

I've had enough dealing with permission errors and corrupted database issues in the Subversion repository I use in one of my development servers. Most problems came from using the default Berkeley database as my repository store so I decided to move to FSFS.

Even if the Subversion book has a section explaining how to setup users and permissions and create wrapper scripts to use the correct umask, I didn't feel safe running a repository store that even the Subversion development team perceives as very sensible to interruptions.

Some advantages of FSFS over Berkeley database include:

  • Can be used from a read only mount and doesn't depend on umask settings
  • It's platform independent
  • Repository size is slightly smaller
  • It can be used on network filesystems
  • Quite insensitive to interruptions

So, I've created a new repository specifying FSFS. You just need to add the --fs-type fsfs parameter, like this:

$ svnadmin create --fs-type fsfs /path/to/repos

I'd recommend not wasting your time with Berkeley database for your Subversion setup, just go for FSFS and you'll be cool.

More about Subversion and how I use it on all my web projects coming soon.

Open Source Applications For Database Modelling

Are there any open source applications to model my database? Many developers have asked me that question quite often lately.

When coding Drupal modules having a good picture of the database model can help a lot to write the right queries, well, actually this applies to any programming project that uses a database with more than a few tables.

Even if there are many commercial applications, many of them quite stable and complete, I think their prices are way too much for most developers, specially for open source developers like most of us Drupal dudes. Want numbers? I got numbers: CA Erwin Data Modeler costs US$ 3995. With that much dough I'd prefer to complete my list of gadgets I want for 2007 and add another laptop with Linux to my arsenal.

So, what are the options to model your database with an open source tool?

Some years ago I found DBDesigner 4 and used it in a few projects to model on MySQL, the only RDBMS it handles. I was quite happy to know that MySQL had taken over the product to relaunch it as MySQL Workbench, however, MySQL has focused on other tools and Workbench progress has been slow. I've recently read in their forum that they were almost finished with other tasks and would return to work with MySQL Workbench. Good to know.

DBDesigner 4 is still available and is a good choice if all you need is MySQL support. The installation is a little difficult in Ubuntu, although I didn't have any trouble with Fedora..

And what happens if, like me, you also need to model PostgreSQL databases? The only application I found for that some months ago was Mogwai ER-Designer, which works with MySQL, PostgreSQL, Oracle and a few other commercial RDBMS. Mogwai ER-Designer is written in Java, so it runs in most operating systems with a JVM.

Unfortunately Mogwai's interface still needs some work and creating models is not too user friendly, even when they correctly use domain dictionaries. I also think development progress is going a little slow.

What I'm using now, and recommend, is Power*Architect, which, like Mogwai, is a Java application and works with PostgreSQL, Mysql, Oracle and others.

I think Power*Architect has a better interface than Mogwai, creating models and generating SQL is quite easy and takes just a few clicks. Power*Architect has been declared open source just a few months ago, way to go guys!, and there are still many features to add and improve (like support for native auto increment fields in both MySQL and PostgreSQL) but it seems the development team is right on track and version 1.0 is coming.

So there you have it, there's still hope and we'll be seeing more mature database modelling tools in the open source arena soon.

Oh, and if you know of any other let us know.

Update September 19: Sean just told me that native types auto_increment in MySQL and serial in PostgreSQL are supported in the latest versions of Power*Architect.

Programming Facebook Applications in a DSL Based Server

I recently posted a few ideas on the opportunities for web developers in Facebook.

I decided to use DynDNS for creating a host name for my local DSL connected Ubuntu box, it's easier editing and making changes that way instead of using the other servers I have in a couple of data centers. I used the hostname as a callback url for a Facebook test application. Facebook saw my host and the application worked as expected.

A couple of hours later I disconnected from the Net to take a break, when I got back received a new IP address from my ISP's DHCP server and DynDNS updated my host information to point to the new IP. Unfortunately now Facebook can't find my callback url anymore. I tried editing settings and changed the host name to the new public IP address to discard, still no luck and I'm getting this error:

The URL http://xx.xx.xx.xx/facebook/application-name/ did not respond.

There are still a few kinks Facebook and the makers of application-name are trying to iron out. We appreciate your patience as we try to fix these issues. Your problem has been logged - if it persists, please come back in a few days. Thanks!

Is Facebook caching my older IP address? That was my first thought but even putting the actual public IP of my box in the callback url didn't work.

Is this a temporal glitch in the Facebook Platform or am I missing something else?

I'll keep testing but if you have any ideas I'd love to know.

Fixed: I'm an idiot! I forgot changing the IP address of my database server, also in my local box. Now everything's working again.

What A Geek Wears?

I prefer to be as light and comfortable as possible, underwear when the weather allows.

what a geek wears

So, what do you use while programming?

Tomboy, Notes for Web Developers

Have you seen those persons that stick post-its on the borders of their computer screens? I know this is just too much but you know what they say about images and words. Sometimes they are ocassional users that use their boxes for simple stuff and I guess they find the whole post-it thing normal but, for a web developer managing so many pieces of data everyday, this is just a cause of disorder. Why using paper when there's software for taking notes?

During my years as a KDE user I was ok with Knotes, now a component of KDE Kontact, but a few months ago I made the jump from KDE on Fedora to Gnome on Ubuntu. Using a KDE app on Gnome didn't seem right so I moved all my notes to Tomboy and boy it was an excellent choice!

Tomboy comes pre-installed with Feisty Fawn and integrates perfectly with your desktop. It's very easy to create notes, link (wiki style) and search them.

I use Tomboy all day, everyday, to save pieces of code, SQL queries, simple reminders (for things needing immediate attention, for everything else there's Evolution) or any other thing requiring a paper and a pen, items that I hope to eliminate from home as soon as possible.

Thanks to Tomboy my desk is free of papers, just got gadgets on it.

Here's a shot of Woodcarver with Tomboy, vim and a cute lady on the background.

Taking note with Tomboy on Feisty Fawn

Snipplr: A del.icio.us-like Code Repository

While searching for ideas to limit how many characters an HTML textarea could accept using Javascript, I found Snipplr, a service that reminds me how easy to use is del.icio.us. By the way, the del.icio.us guys are working on a new platform and trying (is possible?) to improve their UI.

Snippler allows you to save, search and tag those small pieces of code that we use so many times in our projects, snippets.

I know this may not be the first site doing it but it helped me and possibly would help you. Worth taking a look.

Better Control Over Drupal Modules Running Order

If you've been a Drupal developer for a while you know that modules run according to the value of the weight field in the system table. You can update this table using an install file so your module runs exactly when you need it. This is what community tags does to run after tagadelic and the method I've used to make sure some form_alter code runs after everything else when I needed to modify event forms.

But the change in the module's weight affect all the hooks in it. What happens if you want to control the runnning order in a per hook basis? I needed to do this to run some nodeapi operations in a custom module before event_nodeapi and form_alter stuff, in the same module, after event_form_alter. Believe me, you may need this some time (unless you opt for using before and after modules).

This idea inspired me to code a bit and individually override the operations in event_nodeapi with some code in my custom module. It worked nice. Now I can run operations load and view in event_nodeapi and override insert and update with code from my module.

The concept is quite simple. I added an event_nodeapi_overriders table with two fields: module and op. My module just needs to use its install file to insert values in this table. If I want mymodule to provide overriders for insert and update operations in event_nodeapi I should add the following module/op pairs to the table: mymodule/insert and mymodule/update.

Then I added a few select boxes to show the values from event_nodeapi_overriders table in the event settings page where I can choose which module should override which operation and used some conditions with variable_get() in event_nodeapi and mymodule_nodeapi to decide which code to run.

Perhaps the concept could be extended to eventually have a matrix of all hooks in all modules or a hook_weight parameter to allow developers to decide the running order. Or maybe is too much overhead?

Anyway, this was some kind of experiment and even if after talking to Gerhard we decided to update the event module to use Form API in the submission process instead, the idea of having better control over hooks running order could deserve some more thinking.

Newsletter Checkbox in Campaign Monitor Blog

I just got a message from David Greiner telling me he had posted about Newsletter Checkbox in Campaign Monitor's blog.

Newsletter Checkbox is a very simple module but gets the job done and has received good feedback from many users so I'm looking for the time to improve it and release a new version soon.

If you have some suggestion please add your comments.

Redirecting Users After Submitting a Form in Drupal 5

If you create web sites based on Drupal you know that controlling forms, how they are themed, validated and processed, is a highly valued skill for any serious developer. This article will discuss a few ways to redirect your users to another page after they've submitted a form, overriding Drupal's defaults.

Drupal 5 provides developers with a Forms API, a clever way to craft HTML forms using logical and extremely flexible arrays.

Drupal Forms API also allows developers to theme every little detail of a form. For simpler cases using the #prefix and #suffix properties can be enough, but if you need extreme power, and sooner or later you will, then you can use forms-exclusive theme functions and drupal_render().

I'll explain the basics of Forms API in a future article, if you can't wait I suggest taking a look at the Forms API Quickstart Guide, for now let's focus in redirecting users after form submission in Drupal.

In the beginning was the form function

Every form in Drupal starts as a function that creates an array, usually named $form. Then the function's name is passed to drupal_get_form().

As every function in a module, a form creation function should start with the name of the module, for example:

boogeeks_notify_form()

First, this assumes my module is named boogeeks, the first word in my function's name. I'm separating each word with an underscore and I suggest you do the same.

Second, I've chosen the verb notify to have a clear idea of what the form will do. I used something like this in a recent project for hacking a form where users opt-in to receive email alerts.

Third, I added form, helpful when you have many functions in your module and need a quick way to tell apart the ones creating forms.

Notice that the only requirement for naming your form function is the first one, starting with your module name, the other two are my suggestions for cleaner and easier to understand code.

Theme, validate and submit

Now that we have boogeeks_notify_form() taking charge of form creation we need a few additional functions, all of them named based on the original.

  • theme_boogeeks_notify_form(): Will take care of the looks of your form, this is the theming function.
  • boogeeks_notify_form_validate(): Will check if user entered information that validates according to rules established here.
  • boogeeks_notify_form_submit(): Will process the form and redirect the user to other page.

For this article's purposes we are interested in the third function, the one ending in _submit.

Where to go now?

Every form submission function, boogeeks_notify_form_submit() in our example, needs to return a value, this value is the url where the user will go after successfully submitting a form.

So, if you want to thank your user after opting in to receive email alerts then you can finish boogeeks_notify_form_submit() with something like:

return 'thankyou-for-subscribing';

That's the url of some page with the usual thank-you-we-love-you-dear-visitor stuff.

All Drupal provided forms have pre-defined values in their submit functions. Two well known and often used ones are user_login() and user_register(), used to create new accounts, both are created in user.module.

How to override default form redirection in Drupal

There are two ways to override default form redirection, with a destination parameter in a url and using the #redirect property of Forms API. After some testing, I know this could be obvious to hardcore Drupal developers but it's still useful for new comers, I determined the redirection processing flow is as follows:

  • The url returned from the form submit function,
  • which is overriden by #redirect,
  • which is overriden by destination passed in the url.

You'll need to modify a form using hook_form_alter() to use #redirect.

If you want to work with destination you'll have to include it in the url used to call the page showing your form.

Now you can take your users whenever you want after submitting a form, no matter if it's a Drupal provided form or one that you've coded.

Bonus: got a headache with redirection after registration?

Yeah, me too, at least until finding a small bug in user.module, maybe that's your case.

How To Find Next Result When Searching With Firebug

There's no need to add reasons why you should be using Firebug while creating your web applications, specially if you are into DOM scripting. I'd just like to add a small detail that we may miss when using Firebug to search in our code: how to find the next result?

It's simple, just press Enter; for previous results use Shift + Enter.

Many of us are used to F3 and Shift + F3 in Firefox but may get a little confused when we start to search with Firebug.