Oh no you didn't...?!

Paul Brown @ 2006-12-21T00:19:56Z

My blog (i.e., this blog) suddenly stopped working today, so I went to the logs to figure out why. The logs provided:

ActionView::TemplateError (undefined method `first' for nil:NilClass) on line #9
  of vendor/plugins/flickr_sidebar/views/content.rhtml:
[... lots and lots of stuff ...]

Ah, OK. I haven't gotten Typo current since I decided to roll my own (which I'm still doing...), so it serves me right if some bug is biting me. Off to look at the Flickr sidebar, and this chestnut is what's choking things:

def image
    description.scan( /(http:\/\/(static|photos).*?\.jpg)/ ).first.first
end

Gah! Using a regular expression to capture a link to an image out of escaped HTML markup passed in the RSS feed... Not something I would recommend. Flickr changed their URLs so that the regular expression no longer matched, and the error was caused by scan returning nil. It's easy enough to fix by adding some namespaces:

@@NS = {"media" => "http://search.yahoo.com/mrss/" }

And then, a couple of tweaks to extract the thumbnail from the appropriate extension element:

picture.thumbnail = XPath.match(elem, "media:thumbnail/@url",
  namespaces=@@NS).to_s

And we're back in business.

(comment bubbles) 2 comments

Feedburnerizing Typo, Part II

Paul Brown @ 2006-07-03T19:49:34Z

Last year, I wrote a rudimentary sidebar to display Feedburner feed links in Typo, but I didn't really get it to the point I wanted at the time. So, I took another fifteen minutes to rewrite the sidebar to work with the enhanced API, ditch the auto-subscribe chiclets, add links for category feeds, and muck with routes.rb. In routes.rb, I mapped a new set of feed URLs for Feedburner onto the controller that currently serves feeds, switched the existing mappings to a two-line controller that 301's to the Feedburner equivalents, and left holes so that people can subscribe directly to article-specific or tag-specific feeds if they wish. (The bonus in this approach is that autodiscovery gets taken care of for free, because the autodiscovery feed is one that gets 301'd.)

Just for grins, here's the two-line controller implementation:

class FbController < ContentController
  def redirect   
    headers["Status"] = "301 Moved Permanently"
    redirect_to "http://feeds.feedburner.com/Multifarious" +
      params[:type].to_s.capitalize + params[:id].to_s.capitalize
  end
end

Sometimes I think that the cornucopia of methods on some of the Ruby core classes (like capitalize on String) is overkill, and sometimes, it's convenient.

I hope that the enhanced setup is useful to any readers (since Feedburner should ensure QoS), but mostly I hope that it's transparent. (FWIW, NetNewsWire did the Right Thing and changed the feed URL for my self-subscription to the new one in response to the 301.) If for some reason you can't see this, let me know...

(comment bubbles) 0 comments

The Joys of Trunk-Surfing

Paul Brown @ 2006-07-02T07:09:00Z

A while back, in order to get the tag functionality in Typo, I upgraded from the stable download to the trunk. Typo is in flagrant and ongoing violation of the “release early, release often” directive for software projects, but it's been a nearly painless experience each time. Except for this last time. To get an update to the Typo sidebar plugin API, I ran svn update on the Typo on my local machine, tweaked a couple of things, and tested; then I ran svn update on the Typo on my remote machine, and... crash. The difference was the theme that I use on the production server, and I resorted to Google before fishing through the theme layouts for issues. Ironically, I found a quick answer on Phil Cryer's blog and had things back to (what passes for) normal in a few minutes.

I say ironically for two reasons. First, it's ironic for me to find the answer on Phil's blog because he just gave up on Typo and went to WordPress over this very issue. And that is ironic because I gave up on Wordpress over a recurring annoyance with incorrectly set Media-type and encoding (see RFC3023 and Mark Pilgrim's discussion for some background) where I had to trace through multiple noodles of PHP spaghetti code to fix it each time Wordpress shipped a new version. (Each time, the upgrade was security related, so I felt obliged to apply it.)

(comment bubbles) 0 comments

Feedburner-izing typo in Fifteen Minutes

Paul Brown @ 2005-12-29T17:35:00Z

I finally got around to signing up with FeedBurner for the main Atom feed for mult.ifario.us; the new preferred feed is http://feeds.feedburner.com/Multifarious, but I'm going to hold off on 301ing aggregators for the time being. It was easier than I thought to get the FeedBurner feed and some auto-subscribe chicklets displayed in typo, thanks to a well-designed sidebar API. In fact, it took all of 15 minutes to read the README on sidebar plugins, fire up a text editor, write the 16 lines of ruby and 46 lines of rhtml for the sidebar, fix some typos, bounce lighttpd, et voilá...

On the downside, the code for autodiscovery is not cleanly modularized in typo, so I stopped at the sidebar. A more thorough integration would require a more thorough refactor (or at least a hack to hard-code the FeedBurner URL), as the autodiscovery feed code is spread between a superclass and a base class in the controllers. (Yuck.)

(comment bubbles) 0 comments