Posted by Kasper Tidemann on Monday 22nd of March 2010 10:51:59 PM
With file uploads in Ruby on Rails, e.g. an upload of a 2 KB CSV file, you’ll often run into trouble trying to decipher the encoding of the Tempfile string data stored in params[:my_upload_form][:uploaded_file] or whatever you’ve named your input field.
If you want to keep everything to one encoding, you could make use of Iconv.conv(‘UTF-8′, <whatever encoding>, string) to convert the data from the input field to UTF-8. But to make the iconv() wrapper work properly, it needs to know what to convert from… So how do you acquire this knowledge?
Try to use the Ruby gem rchardet by Jeff Hodges. Here is an example of how to use it:
require ‘rchardet’
[...]
cd = CharDet.detect(params[:my_upload_form][:uploaded_file])
encoding = cd['encoding']
converted_string = Iconv.conv(‘UTF-8′, encoding, params[:my_upload_form][:uploaded_file])
The above is not bullet proof, but it’ll get you going. If you have alternative ideas in this regard, please comment to let us all know.
Posted by Kasper Tidemann on Wednesday 17th of March 2010 10:35:06 PM
You might come across the following error when trying to drop a database in your PostgreSQL:
ERROR: cannot drop the currently open database
This is because you are trying to delete the database that you are currently connected to (or in MySQL jargon: the database you are current USEing). To fix the problem, try to issue the following command:
\connect postgres
This will connect you to the postgres database in PostgreSQL, sometimes referred to as the maintenance database. From here, try to issue your drop command again – it will now work out for you as expected.
Posted by Kasper Tidemann on Wednesday 17th of March 2010 09:13:50 AM
If you have SSH access to a UNIX/Linux based system somewhere and want to copy a file located on the server to your computer via SSH, you can use the scp command found in most UNIX/Linux systems, including Mac OS X.
Say you want to copy a file from the remote server to your own computer, a file called my_file.txt. In this case, you would issue the following command in your terminal:
scp your_login@addres.of.remote.server:my_file.txt .
This makes your computer connect to the server with the login you provide, and copy the my_file.txt file to the directory you are currently working (using the exact same file name locally on your computer, that’s why there is a dot in the end of the command).
Posted by Kasper Tidemann on Wednesday 10th of March 2010 02:35:30 AM
In relation to the previous post about a couple of free fonts, Mark Barner tipped us about another good place to download some fresh fonts for your next web project. Go here to download the karabinE font along with the rest of the exhibited ones.

An example of the karabinE font.