iOS 5 has been out for a while, but it seems most people missed out one of my favorite new features. Buried in your settings are your Keyboard Shortcuts. If you’re familiar with TextExpander, this is a light version of that. Otherwise, it’s a simple way to type a couple of characters which are then converted into a larger, harder to type string. Even though typing on an iOS device works, this streamlines some tedious typing.
The Setup
First, you need to find the menu. Open Settings, go to General, then Keyboard and scroll to the bottom. You’ll notice a default one, which I deleted. Click the Add New Shortcut… button at the bottom. You’re presented with two options: Phrase and Shortcut. Phrase is the full, final text you want to be displayed. Shortcut is the short phrase that you want converted.

Below is what I use. I prepend an “s” for “Stephen”:
- Phrase: my email address, Shortcut: se-
- Phrase: my phone number, Shortcut: sp-
- Phrase: my home address, Shortcut: sa-
Now, when you’re in Safari and you need to submit your phone number or email address, you just type se- and the autocorrect field comes up with the full email address.

A Bonus
As a bonus, if you leave the Shortcut field blank, the word in Phrase will be considered spelled correctly. This eliminates the “ducking” problem, if you know what I mean.
The Down Side
There are a couple down sides to Apple’s implementation.
- Your shortcuts are not portable. If you have an iPhone and an iPad, you have to put the shortcuts into each device separately. Maybe this will be fixed with iCloud at some point.
- You can’t put line breaks in to your Phrase. This means that my address is all on one line.
Since the first post on this topic, I have migrated my app from Rails 2.3.11 to Rails 3.0.6. See the first post if you still need the solution for Rails 2.
I had a need at work to send email out of our Rails application which met the following criteria:
- It has both a plain text and HTML part.
- It may have embedded images in the HTML part.
- It may have attachments.
Below is the code, which you can put in your app/models directory.
class EmbeddedMailer < ActionMailer::Base
def embedded_mail(to, from, subject, html_message, text_message, files = {}, embeds = {})
mail(:to => to, :from => from, :subject => subject) do |format|
format.text { render :text => text_message }
format.html { render :text => html_message }
end
# Embeds
embeds.each do |key, embed|
attachments.inline[key] = {
:content => File.read(embed[:path]),
:content_id => "<#{key}>"
}
end
# Attachments
files.each do |key, embed|
attachments[key] = File.read(embed[:path])
end
end
end
A Quick Explanation
Rails 3 has made this a lot easier. The only real hack is handling dynamic inline Content-ID’s. ActionMailer will dynamically generate a Content-ID for each inline attachment. We override that with the :content_id => "<#{key}>" line. The brackets are required.
The format of the files and embeds hashes is as follows. The key is the file name of the attached file. The value is another hash with content_type set to the content type of the attachment and path is the full path to the file. For example:
{ 'image.png' =>
'content_type' => 'image/png',
'path' => '/tmp/image.png'
}
I always forget to turn off my chat accounts at work at the end of the day. Below is a script to take my accounts offline when it’s time to go home. This is for Ubuntu 10.10 using Empathy for my Jabber accounts.
#!/usr/bin/env ruby
require 'rubygems'
require 'dbus'
# Get the proper DBus session address
pid = nil
programs = %w( gnome-session )
programs.each do |program|
pid = `pidof -s #{program}`
break unless pid.nil?
end
# Fail if we can't find the pid
exit if pid.nil?
# Get the address
info = IO.readlines("/proc/#{pid.strip}/environ").first.split("\0")
info.reject! { |x| !x.include? 'DBUS_SESSION_BUS_ADDRESS' }
address = info.first.split('=', 2)[1]
# Set the address
ENV['DBUS_SESSION_BUS_ADDRESS'] = address
# Get the objects
bus = DBus::SessionBus.instance
service = bus.service('org.freedesktop.Telepathy.AccountManager')
service.introspect
account_manager = service.object('/org/freedesktop/Telepathy/AccountManager');
account_manager.introspect
iface = account_manager['com.nokia.AccountManager.Interface.Query']
accounts = iface.FindAccounts []
accounts.first.each do |account|
account_object = service.object(account);
account_object.introspect
account_iface = account_object['org.freedesktop.DBus.Properties']
account_iface.Set 'org.freedesktop.Telepathy.Account', 'RequestedPresence', ['(uss)', [1,'offline','']]
end
You’ll need the ruby-dbus gem to use this. I just placed it in a file and call it from a cron job. The script finds all of your accounts via D-Bus and and then sends them a new presence.
Update 2011-01-31: Added code to find the correct DBus Session Address, since the cron job does not have it.