Just Another Monday Morning

Posted by Trejkaz Mon, 14 May 2007 00:13:00 GMT

Monday morning came with a request to change the company web site to American “English”.

My first thought was that we’re not a US company, so we shouldn’t need to conform to US spelling. The reasoning I got back was that US companies got scared off by British spelling.

This reasoning sounds pretty ludicrous to me, and besides, if we switch to American spelling, won’t that “scare off” the entire rest of the English speaking world?

So I thought, OK… maybe we can do this and yet not do this.

#!/usr/bin/ruby
#
# Breaks proper English spelling for the benefit of yanks.
# Word list is incomplete, but covers enough to be useful for now.

ARGF.each_line do |line|
    line.sub!(/\b(amort|apolog|author|capital|critic|emphas|general|harmon|initial|maxim|minim|optim|real|recogn|visual)is(e|ed|es|er|or|ation)\b/, '\1iz\2')
    line.sub!(/\b(anal|catal|paral)ys(e|ed|es|er|or)\b/, '\1yz\2')
    line.sub!(/\b(arm|behavi|col|flav|harb|hon|hum|neighb|sav|savi)our(s?)\b/, '\1or\2')
    line.sub!(/\b(defen|licen|offen|preten)ce(s?)\b/, '\1se\2')
    line.sub!(/\b(calib|cent|fib|kilomet|lit|meag|met|theat)re(s?)\b/, '\1er\2')
    line.sub!(/\bpractis(e|ed|ing)\b/, 'practic\1')
    puts line;
end

My only concern is that it might match an ID somewhere in the HTML which will mess the CSS up, but otherwise, it’s looking like a damn good idea.

Tags , , , ,  | no comments

Action Messenger 0.2.0

Posted by Trejkaz Fri, 23 Mar 2007 09:04:00 GMT

Today’s new version of Action Messenger makes things slightly easier to read when sending messages:

def prod(user)
  recipient user.jid
  subject   'Prod'
  body      'You told me to give you a prod when I updated...'
end

You can send to multiple recipients too, just add them like this:

def spam
  recipients User.find_all.map { |u| u.jid }
  subject    'Buy chunky bacon'
  body       'Do I have a deal for you!'
end

These changes have been in trunk for some time, however someone recently made me aware that the documentation doesn’t describe basic things like where the config file should be. This has been properly documented now, and hence the new version being pushed out.

Tags , , , ,  | no comments

Directions for Action Messenger

Posted by Trejkaz Mon, 22 May 2006 12:16:00 GMT

Well, the first highly experimental release of Action Messenger experienced a small amount of success, and a couple of people spotted some bugs which have been fixed in version 0.1.1.

So now that everything works for small apps, how does it grow? I do want to integrate into Typo, and the default deployment for Typo uses FastCGI. Whereas each FastCGI process is relatively long-lived, there are multiple instances, and they can’t all be logged in at once [with the same resource.]

Read more...

Tags , , , ,  | no comments

Jabbering with Action Messenger

Posted by Trejkaz Mon, 08 May 2006 13:24:00 GMT

Want to send instant messages from your Ruby on Rails app with the minimum amount of code and the maximum amount of testability?

Then say hello to… Action Messenger

Read more...

Tags , , , ,  | no comments

Higher Order Messages for Mapping

Posted by Trejkaz Thu, 03 Nov 2005 23:29:00 GMT

Say you want to convert an array of strings to uppercase. You could write

result = names.map { |name| name.upcase }

PragDave suggests an alternative which uses the Ruby Extensions Project’s Symbol#to_proc method to pass a symbol.

result = names.map(&:upcase)

This is all well and good, but can you really call it elegant? Suppose you want to add 1 to all elements in a list. How can this method let you pass in that parameter? It seems that it can’t.

Higher Order Messages (HOM) provide a better way, although a way which seems even more like magic.

The Homer project offers HOM for Ruby, and although it didn’t have a method which did something like map, it was relatively simple to whip something together.

My own version of the above functionality:

result = names.map_using.upcase

Isn’t that better? I couldn’t call it map without causing a little mayhem, having to alias the old version and still provide complete compatibility was a bit much for me at this point in time.

But better yet, this version does permit you to use parameters:

costs_with_gst = costs.map_using * 1.1

Don’t bother asking for the source code for this… I’ll be shuffling it up to the Homer project as soon as I hit submit. ;-)

Tags ,