Martin Ström
my-domain.se

Ruby on Rails, UTF-8 & Heroku

I’m in the middle of moving some sites over from a self hosting VPS to Heroku and had some problems with the text encodings. Everything worked fine on the old site and on my local machine, but after a heroku db:push (copying my local MySQL database to Heroku’s Postgres), all special UTF-8 characters were not displaying correctly.

After some googling and some testing I found this solution (that is, make sure Rails and MySQL is all UTF-8), but it wasn’t enough to properly import the old data. After more googling, this worked for me:


ℂ◉℗⒴ ℘ⓐṨͲℰ Ⓒℌ◭ℝ◬ℂ⒯℮ℛ

A few weeks ago we (me & Konst & Teknik) finally released the long taking new version of CopyPasteCharacter.com — a website to help people find and copy symbols and characters that are not very easily accessible from the keyboard.

The main new thing, featurewise, is that we included many more characters than the previous version had. More characters has been the top #1 feature request the past three years the site has been online. To make the site easy to use with all new characters, we have divided everything into different sets/collections such as “Numerals”, “Symbols” and “Graphic shapes”.
We also made it possible to create your own set with characters and some smaller things like sharing sets and decide what set that should be the start set on CopyPasteCharacter.com.

www.copypastecharacter.com


Paperclip processor to turn images into grayscale

We wanted to automatically create a grayscale version of the uploaded images for a current project. Here’s the Paperclip processor we’re using:


RailsTerm 0.3

Terminal + RailsTerm

Just a quick note that RailsTerm, my AppleScript to automatically open the tabs (in OS X 10.5 Terminal) needed for Rails development), is bumped to version 0.3.

Since I use Passenger (mod_rails) and Passenger.prefpane for my local development the script will now auto detect the virtual hosts available on your system (in /etc/apache2/passenger_pane_vhosts/*.vhost.conf). I use the script daily and is a real time-saver for me.

RailsTerm or browse source is on GitHub.


My Terminal Setup for Rails Development

I’m quite happy with my Terminal.app setup right now for the Rails projects I’m working on and wanted to share the bits and pieces I use.

First, I found a SIMB plugin for Terminal that’ll show the tab’s title in the tab instead of the running process. I use the plugin with a simple title helper in my .bash_profile to set the title simply.

function title () {
  unset PROMPT_COMMAND # more on this later
  echo -ne "\e]0;$1\a"
}

# Usage:
# title 'my title'

Second, I use a technique I saw on how to automatically set the title to display the current working directory as title, but since I use the plugin and helper function above, I could simplify the PROMPT_COMMAND a bit:

function set_window_and_tab_title {
  local title="$1"
  [[ -z "$title" ]] && title="root"
  echo -ne "\e]0;${title}\a"
}

PROMPT_COMMAND='set_window_and_tab_title "${PWD##*/}"'

That’s why I unset PROMPT_COMMAND in my title function, so it won’t auto update when I choose to set it manually using the title function.

The last piece is an updated version of my old Rails Term-script for iTerm which has been updated (and improved) for the Terminal in Mac OS X Leopard instead of iTerm.

It will open the tabs I usually use when doing Rails development and set the title of each tab using the above mentioned functions. You need to enter you projects root directory and the projects you want to have easy access to. I’ve added some comments to the AS code to help you out.

Download a zipped version of the AppleScript. Just drag the script to the Script Editor (/Applications/Utilities) to edit it.

All source code for these scripts can also be viewed on Pastie. Let me know if you have any improvements.


./script/server with automatic port finder

This is the script I’m using when I start my local Rails development server. It will automatically detect the next available port starting at the default port 3000 so I can have multiple servers running without remembering what ports that are already busy.

#!/usr/bin/env ruby

DEFAULT_PORT = 3000

puts (`ps aux | grep [r]uby | grep script/server`.split("\n").map { |l|
  server = l.split(/\s+/)[11..-1]
  (port = server.index('-p')) ? server[port.next].to_i : DEFAULT_PORT
}.max || DEFAULT_PORT - 1).next

I aliased it to ss in .bash_profile like this:

alias ss='./script/server -p `~/bin/available_rails_port`'

(Btw, Happy 2008! I haven’t updated this site for a while)


Modernize Rails (or: get rid of Verdana)

Verdano

Tired of see the the soooo 1999-ish font “Verdana” every time you get a local error page in Rails?
Now you don’t have to. With this plugin the error pages will use Arial or Helvetica instead—finally!

To install:
./script/plugin install http://burnfield.com/svn/martin/rails/plugins/verdano

or as svn:external:

./script/plugin install -x http://burnfield.com/svn/martin/rails/plugins/verdano

I’ve moved to git so the new instructions are:

git clone git://github.com/haraldmartin/verdano.git

or just braid it

Happy new year!


AppleScript to open iTerm tabs for Rails development

Update: This script is ported (and improved) to work with OSX Leopards’ Terminal.app.

I never really liked iTerm because of slow redrawing, ugly text anti aliasing and not reflowing text when resizing the window.

After reading some interviews on a Rails site today and saw that a lot of people are using iTerm i wanted to give one more try (because I’d really like a tabbed terminal).

It has improved a lot the latest months and seems really usable now. To make Rails development easier, I hacked together a small AppleScript what will ask you for the path to the Rails directory you want to use and then open four new tabs with Server/Mongrel, Console, Autotest and the directory itself. I thought it could be useful for others as well so here you go:

Save as an .app and run from Quicksilver:


global rails_dir

tell application "iTerm"
    activate
    set rails_dir to the text returned of (display dialog ¬
        "Please Enter the Path to Your Rails Directory" default answer ¬
        "~/Projects/" as text)

    if (count of terminal) = 0 then make new terminal

    my open_tab("Server", "&& ./script/server")
    my open_tab("Console", "&& ./script/console")
    my open_tab("Autotest", "&& autotest")
    my open_tab("Rails Directory", "")
end tell

on open_tab(title, command)
    tell application "iTerm" to tell first terminal
        launch session "Default"
        tell last session
            write text "cd " & rails_dir & command
            set name to title
        end tell
    end tell
end run_command

CSS is in progress