Skip to content

Monthly Archives: January 2014

String Formatting The Ancient Way: How To Interpolate in (s)printf

Recently, while mentoring a couple of kids who are starting to learn programming (using Ruby), I encountered the challenge of explaining the %f/d/g notation for formatting data in a string.

The notation is used in converting data into representations that can be printed as (part of) a string. The operation is called string interpolation. The format is used in commands like printf, and the syntax is typically like this:

printf(<string with format specs>, data value 1, data value 2, …)

Read More →

The Unsolved Mysteries Of The World

I was inspired by this blog post by Keir Clarke 1)who incidentally has more map visualizations of Google Auto Suggest behavior on how Google Auto Suggest was completing the query Why Is X So… for various state names (in the United States), to wonder what equivalent wisdom of the crowds Google had gathered for other placenames associated with where people live.

I thought it’d be a simple matter of feeding a list of city or country names to a Google API, and realized that there isn’t one – turns out that unlike Bing, Google isn’t so happy for the common consumer to share in all its indexy goodness. Well, no matter, I figured I wasn’t trying to build a commercial-grade application, so I could do just as well by scraping the contents of a browser, via Selenium and Ruby.

Read More →

References   [ + ]

Silent Failures With Resque::Mailer

I was using Resque::Mailer, and couldn’t get it to work. I had what I thought was the simplest possible configuration –  in my mailer – app/mailers/user_mailer.rb – I had this:

class UserMailer < ActionMailer::Base
  include Resque::Mailer

  def alert_developers(u)
    mail(:to => "#{} <#{}>", :subject => "Hello").deliver

But I was getting nothing – no new queue being created in Redis, and certainly no mails being sent.

It wasn’t until I removed the Resque::Mailer that I realized what was going on. The Mailer was in fact failing because no SMTP from field had been set, but that error is eaten up by Resque::Mailer. When you are not using Resque::Mailer, the error shows up in the resque-web application and it’s easier to debug.

When I put in a default From field in my config/application.rb file, everything worked great:

config.action_mailer.default_options = {from: ""}

Now you know!