/#!

Using Jinja2 in Django with Coffin: The Easy Way

There is a lot of old, incorrect and just plain bad documentation on how to use the Jinja2 templating language in Django. Here’s how to do it The Easy Way.

  1. Install Jinja2, Pygments and Coffin with easy_install Jinja2 Pygments Coffin or by editing your Pip requirements.txt file.

Fix Facebook Like button for IE6 and IE7

You may have noticed in your server logs or analytics a significant number of requests to pages on your site with the query string ?fb_xd_fragment=. This behaviour is a symptom of the Facebook Like button working improperly in IE6 and IE7. In order to correct this bug, you must set a channelUrl for your Facebook Like button, following Facebook’s documentation on FB.init.

Google News Search parameters (The Missing Manual)

There is a severe lack of documentation of Google News Search’s query parameters. Here is the most comprehensive list I am aware of. A number of these overlap with Google Search’s query parameters. I exclude any Google Search parameters that don’t make sense in the context of Google News Search. These parameters are primarily of interest to anyone querying Google News for articles using its RSS and Atom output formats.

Google Refine fingerprint clustering algorithm in Ruby

If you’ve used Google Refine, you know how useful its clustering algorithms are for finding and merging alternative representations of the same thing, e.g. “Gödel, Escher, Bach”, “Godel, Escher, Bach” (accents), “Gödel Escher Bach” (punctuation), “gödel, escher, bach” (case).

Remove all accents and diacritics from string in Ruby

As a follow-up to this post, if you want to remove all accents and diacritics from a text string in Ruby, while preserving case, use this snippet:

http://gist.github.com/1374687

Reserved methods in Rails

I occasionally waste many hours debugging code that fails because I accidentally redefine a method inherited from a Rails class. For future reference:

ActionMailer

How to cache an internationalized site with Rack::Cache in Rails 3

I have bilingual and international websites that serve different translated content depending on the current locale. The current locale may be set according to the domain, subdomain, path, query string, or a cookie. If it is set according to a cookie, read on! If it is set using anything in the URL, Rails 3 (using Rack::Cache internally) will cache pages correctly for you.

How to safely create friendly From addresses including name and email

You have a contact form that collects a person’s name and email address. When sending their email, you want to get these two pieces of information from looking like this:

Name: John Doe
Email: john@example.com

to this:

From: John Doe <john@example.com>

or:

Reply-To: John Doe <john@example.com>

If you simple concatenate strings, then you will either send a malformed email or introduce a security risk. Here’s a safe, proper way of doing it using the Mail gem: