Forcing actionmailer to send text based emails

I was very surprised to find out that a user from an un-named large financial services company uses lotus notes (actually the whole company uses lotus notes). The application that I'm working on sends a lot of html email and I received a screenshot of what that user was seeing and wow, that is definitely an email client that can't render html.

Sending out multipart emails (with a text/plain part and a text/html) didn't help me because for some reason lotus notes believes it can render html emails so that won't work.

The work around I found was to actually create the tmail object and then remove the html part from the mime parts:

email = create_email
part = email.parts.detect { |p| p.to_s.include?("Content-Type: text/html;") }
email.parts.delete part

This way your users will get only text email. No chance of crappy html in lotus notes. 

Easy as a YAML Pie

YAML is a fantastic way to store data.

I already new that, but taking a refresher on through the YAML documentation, I remembered how easy it was to create an object graph and serialize it straight to YAML.

Here is some code:

class Project  attr_accessor :name, :client, :peopleendclass Person  attr_accessor :first_name, :last_name, :emailendAnd the YAML document:--- !ruby/object:YAML::Project  name: Build a ruby app  client: Toyota  people:    - !ruby/object:YAML::Phase      email: carl@mail.com      first_name: Carl      last_name: Woodward

Now when you call Yaml.load on that you will get back a project object with all the attributes filled out and an array of people. This is a pretty nice document format. It is much easier to read then json.

 

Querying active record with dates and time zones

Warning: this is a work in progress.

I have been working on an application that has a heavy depency on dates and calendars.

A problem that has been causing us grief is querying records with a date that the user has selected (from a calendar). We were using:

Time.zone.parse

It turns out that this breaks active records utc conversion. Instead if you use:

Date.parse

Then everything works. As I mentioned at the top of this article this is a work in progress and I am happy to be told that I am completely wrong!

I have written a piece of code to test my theory.

Feel free to let me know your thoughts.

Paperclip, cucumber and cucumber bundle

I just spent the last couple of hours trying to figure out why my cucumber feature which uploads a file to s3 using paperclip wasn't working.

It turns out that the path is used when running a textmate command is different to path when you start a terminal session. I haven't found the reason for this but as a quick fix I added:

. /etc/profile

to the run feature and run single scenario commands in my textmate bundles. I will endevour to do some more research into this for a better solution.

Why Programmers Hate Meetings

One reason programmers dislike meetings so much is that they're on a
different type of schedule from other people. Meetings cost them more.

 There are two types of schedule, which I'll call the manager's
schedule and the maker's schedule. The manager's schedule is for
bosses. It's embodied in the traditional appointment book, with each
day cut into one hour intervals. You can block off several hours for a
single task if you need to, but by default you change what you're
doing every hour.

 When you use time that way, it's merely a practical problem to meet
with someone. Find an open slot in your schedule, book them, and
you're done.

 Most powerful people are on the manager's schedule. It's the schedule
of command. But there's another way of using time that's common among
people who make things, like programmers and writers. They generally
prefer to use time in units of half a day at least. You can't write or
program well in units of an hour. That's barely enough time to get
started.

 When you're operating on the maker's schedule, meetings are a
disaster. A single meeting can blow a whole afternoon, by breaking it
into two pieces each too small to do anything hard in. Plus you have
to remember to go to the meeting. That's no problem for someone on the
manager's schedule. There's always something coming on the next hour;
the only question is what. But when someone on the maker's schedule
has a meeting, they have to think about it.

 For someone on the maker's schedule, having a meeting is like throwing
an exception. It doesn't merely cause you to switch from one task to
another; it changes the mode in which you work.

 http://www.paulgraham.com/makersschedule.html