If you want to pass specific options like the table type and the charset to use when creating tabled though Rails migrations, pass an options parameter to the create_table method:

create_table :my_table, :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8', :force => true do |t|
t.column :column1, :string
t.column :column2, :string


In order to set a maintenance page in apache 2 you need:

  1. Enable mod_rewrite. In my debian server I just need to do the following:
    ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
  2. Create the maintenance page somewhere in your disk server. I created it under /srv/www/maintenance
  3. Set up apache2 to redirect all requests to your site to the maintenance page (you will need to comment out the current apache2 directives for your website). In my case I have a /etc/apache2/sites-available/mysite file that is linked from /etc/apache2/sites-enabled/mysite.
    #Maintenance page
    <VirtualHost *:80>
    ServerName mysite.com
    ServerAdmin postmaster@mysite.com
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !/index\.html$
    RewriteCond %{REQUEST_URI} !/logo\.gif$
    RewriteRule ^(.*)$ /index.html [L]
    DocumentRoot “/srv/www/maintenance”
  4. Reload apache2 configuration:
    /etc/init.d/apache2 reload

In my case I only have an index.html and a logo.gif file in the /srv/www/maintenance folder. If you have more files that are needed to render the maintenance page you will need to add some extra “RewriteCond %{REQUEST_URI} !/yourfile\.extension$” rules.

Note if you do not use the rewrite engine, the maintenance page will show up when you users access http://mysite.com or http://mysite.com/index.html, but if they access http://mysite.com/something_else they will get a nice “Page not found error”.

When one of the hard disks in a RAID 1 gets out of the RAID because it is no longer in sync with the other disk, you can easily resynchronize it with the following command:

raidhotadd /dev/mdX /dev/sdY

X and Y should be set to the appropriate values.

‘cat /proc/mdstat’ would tell you if your RAID system is healthy.

The configuration of your RAID is set in the file /etc/raidtab which will tell you the disks in the RAID and you can compare the results with the cat command above to see which disk is missing.

I use this script to verify if all disks in my RAID 1 are working fine:

#Check if both drive are up
if [ `grep [UU] /proc/mdstat | wc -l` != 2 ] || [ `grep "2/2" /proc/mdstat | wc -l` != 2 ]; then
  cat /proc/mdstat
  exit 1
exit 0

More info here.

If you want to a validation rule to be applied only when the corresponding attribute has a value, you can use the :allow_nil => true parameter. I don’t know if this works on any Rails model validation rule, but it might well be. The Rails documentation at http://api.rubyonrails.org/ is not very clear in that respect. For each validation rule it lists the parameters it accepts and for the validates_format rule the :allow_nil parameter was not listed. It is listed at the begining as a default parameter for all validation rules though.

In my case I wanted a column in the table to either be null or have a value that matched a particular regular expression, so I ended up with something like

validates_format_of       :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/, :message => ‘Invalid Email address’, :allow_nil => true

Adding MS fonts to Ubuntu

February 26, 2007

Ubuntu does not install Microsoft fonts like Arial or Trebuchet by default, as I guess they are not free.

However you can get them from the multiverse packages. To install them, enable the multiverse packages in System/Administration/Sofware Sources and go to a terminal and type

sudo apt-get install msttcorefonts

I was very annoyed by the fact that VLC did not keep the playlist when restarted and I was always forced to load the playlist myself. In my case the playlist is in a url (it is supplied by my broadband and TV provider) but it could also be a file.

It turns out that the solution  is very simple:

  1. Open VLC
  2. Go to Settings/Preferences.
  3. Select Playlist
  4. Enter your default playlist in the Default stream field.

Basically you can build your playlist, save it (open the playlist with CTRL+P and then Manage/Save playlist) and then put the full path to the saved playlist in the Default stream field as explained in the steps above.

Have you ever had the need to access an internal CVS repository from the office and from home or any other place outside your organization’s intranet? This is something I have been doing for quite a while now as I work from home from time to time.

We don’t use any kind of VPN as we don’t have the necessary hardware to set it up properly but I have access to an internal machine from home through ssh that then allows me to connect to the CVS machine.

The tip is to create a SSH tunnel to connect to the CVS machine (I use ssh to access CVS). That way, your CVS repository is always accessed through a port opened in your localhost and so it looks the same to applications regardless of how you connect to the CVS repository.

Imagine the following scenario:

My laptop hostname is laptop.domain, the CVS server is cvs.domain and the machine I use to connect to the intranet from home is gateway.domain.

When I am at home I create the following tunnel (replace username with your login name in gateway.domain):
ssh -L2222:cvs.domain:22 username@gateway.domain

When I am in the office I create the following tunnel:
ssh -L2222:cvs.domain:22 laptop.domain

Note that you MUST NOT replace laptop.domain with localhost in the second ssh tunnel. If you do that, the SSH key associated to localhost will be your laptop’s one and this will prevent you from making a ssh connection to cvs.domain through the tunnel because the SSH host key that will be reported will be the cvs.domain’s one that will conflict with the the SSH key already registered (you laptop’s one) and therefore the client will refuse to open the connection.

To make things easier I have created two aliases that I add to my .bashrc or .alias or .bash_aliases depending on your GNU/Linux distribution:

alias cvs_home=’ssh -L2222:cvs.domain:22 username@gateway.domain’
alias cvs_office=’ssh -L2222:cvs.domain:22 laptop.domain’

When you configure the repository in your CVS client specify:

  • host: localhost
  • port: 2222
  • connection protocol: ext:ssh or ssh