The Zen of updating WordPress

WordPress automatic updates never work.

No matter if it’s a major version change or just a small bump (let’s say… 3.0.4 to 3.0.5, uh?), I always end up downloading the whole thing and updating it manually because the update page stops responding and plainly goes blank.

Instructions for update are here, by the way. And after the steps to update, they include that little snippet of wisdom:

Consider rewarding yourself with a blog post about the update, reading that book or article you’ve been putting off, or simply sitting back for a few moments and letting the world pass you by.

How could anyone be angry at WordPress after that?

Tunalysis – with screenshot

For all of you number junkies out there:

tunalysis screenshot

Tunalysis development is doing good, as sporadic as it may be. The next step is to rework/refine the algorithm giving rankings, in order to achieve better results. I’ll try to include the “Last Played Date” in the mix, and maybe also use the Date Added.

More good news: no need to install gems by yourself anymore, everything’s included by Bundler.

Tunalysis’s on GitHub!

Set up a mail server on Amazon EC2

This post will explain how to set up a Postfix mail server on an EC2 instance.

First, a word of warning: Amazon IPs generally aren’t highly considered, spam-wise. Meaning that even if you take all the precautionary steps, your emails might end up in spam folders. If email is business-critical for you, you might want to consider other options: host your mail server somewhere else? Use something like SendGrid?

This said, let’s dive in!

Prerequisites

I assume you have the following:

  • A domain name, with control over the DNS records
  • An EC2 account

Pick an AMI

Let’s start by creating an EC2 instance. I began with the vanilla AWS Linux micro instance, which seem to be somehow Fedora-based, and it was a pain. Now do yourself a favor and pick a Debian-based OS. It will make things much more easier.

Eric Hammond and Canonical themselves provides Debian and Ubuntu AMIs, which are a great first step. You can even bypass the whole Postfix config by using one of these AMIs.

Assign an elastic IP to the instance you launched. We will need it for the DNS setup.

Configure Postfix

Now’s the time to be very lazy and just redirect you to Ivar Abrahamsen‘s excellent howto on setting up Postfix. Actually, most of what I’m writing right now can be found on his howto, but let’s not stop at technicalities.

Configure your DNS

The most important step in having your email properly delivered is in your DNS configuration.

The first step is to define an A record for your Amazon Elastic IP, for example mail.mydomain.com. This will be used to set up a reverse DNS on your web server, so that other SMTP servers know that you’re not a spam relay.

Then add an MX record to the address you just defined, for example mail.mydomain.com. Now each SMTP server sending mail to mydomain.com will contact mail.domain.com, which in turn points to your EC2 instance. Awesome!

The next step is to modify your SPF record. I’ll let you work out the details with the spec and Ivar’s howto, and as an example here is the SPF record for remaildr:

remaildr.com.        1800    IN    TXT    "v=spf1 mx ip4:50.16.218.96 include:mx.ovh.com ~all"

This SPF allows MX servers and the IP address 50.16.218.96 (i.e. the EC2 instance) to send mail for remaildr.com. Only “MX” should be enough, no need for the IP in particular ? Well, I thought so, but it didn’t work so I added the IP address. Now it works. If anyone has an idea why, I’m all ears.

The include:mx.ovh.com is automatically added by OVH themselves and is not a problem in our case.

You can use the dig command to check if your DNS settings are properly set. For example, the SPF field was retrieved with a:

$ dig remaildr.com in txt

As a bonus, you might be interested in setting up DKIM (cryptographic email signing), a half of which takes place in your DNS. I’ll once again refer you to Ivan’s howto because it’s that good.

Tell Amazon you’ll be sending emails

By default, Amazon limits the amount of email you can send from an instance. You can ask them to remove that limitation very easily though, through that page.

This form also allows you to set up the reverse DNS I was telling you about. Go on, do it! Amazon usually answers to this form within 1-2 days.

Done!

That’s it!

Do you end up in spam folders? Try the test at AllAboutSpam, and check if everything’s alright. It covers about any issue your server might have.

Remaildr – the tech bits

Here are a few small things you might want to know about http://remaildr.com. Or maybe not, but then again, nobody forces you to read, stranger!

“Hardware”

Remaildr is hosted on an Amazon EC2 micro instance, benefiting of the free tier offer. Apart from the static IP that will probably end up costing me something, remaildr should be about free.

— Edit: as of may, remaildr is now hosted on a VPS at OVH. The EBS volume of my EC2 instance blew up on me, and with the free tier coming to end, EC2 would be too costly.

Network

The remaildr.com domain is registered at OVH, because of the low price and the flexibility they allow on DNS. I added an A record for mail.remaildr.com pointing to 50.16.218.96 —the AWS elastic IP—, then modified the MX record for remaildr.com to point to mail.remaildr.com. That way, every email sent to any_address@remaildr.com will be sent to the right mail server. Having an A record also allows reverse DNS on the mail server, often used to flag spam.

Other DNS modifications included the SPF record, which allows the mail server to actually send emails in behalf of remaildr.com, and a TXT record for DKIM — cryptographically signing outgoing emails.

OVH provides a free 1MB web storage for each domain name subscription, which is more than enough to host the remaildr.com website, weighing about 30KB.

The mail server

The email server at OVH is a run-of-the-mill Debian Squeeze. It runs a Postfix server, configured to forward a few specific email addresses (for example abuse, postmaster and info) to my account, and let everything else go to a catch-all account called remind.

A set of two Daemonized Ruby scripts will then do all the work:

  • receivr.rb will fetch the emails in POP, compute the send date, then put the remaildr to send back into a PostgreSQL database as a Base64-encoded marshalled ruby object (akin to how DelayedJobs works as far as I understand)
  • sendr.rb will read the database and send all the emails who need to be sent

Of course, the code is on GitHub.

That’s about it! Feel free to ask any questions, and I’ll answer as well as I can. :)

So what could I get at McDonalds? (.com)

I’ve been meaning to try and learn Ruby for a few months now, since I’ve discovered _why’s (poignant) guide. As often when it comes to programming (and about everything, really), nothing replaces practice. Combine that with an idea that floated in my head, and here’s what gives:

http://sowhatcouldigetatmcdonalds.com/

The concept

The idea for this website popped up as I was chatting with fellow students; something along the lines of “hey, wouldn’t it be cool if you had a website that’d told you, like, you know, say, for $24 you can have a bunch of big macs, 12 large fries and a sundae? hu? pretty neat, heh?”.

Their answers, mostly “hmm yeah I guess” and related lukewarm comments were not that encouraging of a feedback; so if you don’t think it’s that neat, don’t worry.

But really, as you probably noticed, the concept of the website is pretty simple. I have some money, you have a McDonalds menu: let’s make that work!

NP-completeness

Well it turned out that this problem is actually NP-complete, as in an O(n^errr okay that shit is hard) kind of complexity – XKCD sums it pretty well. To be more formal, it’s a problem that cannot be solved both fast (in polynomial time) and accurately. A long line of people attempted to maximize their bang for the buck at any restaurant (I only remembered the XKCD strip after starting to code, did I unvolontarily plagiarized it?), and it’s called the ‘knapsack problem‘ – or ‘unbounded knapsack problem’, if you really want to shine at parties.

Algorithm

The best (known) ways of solving the knapsack problem involves some heavy and interesting stuff, like dynamic programming, or even what wikipedia calls a “fully polynomial-time approximation scheme” (I didn’t even check that out, search at your own risks). Considering developing that would already take a great deal of time, I opted for a quite simpler approach, to begin with at least: my algorithm tries to stuff random McDonalds items in until there’s not enough money left. Complex algorithms? To-mah-to, to-mae-to.

Prices

Prices at McDonalds aren’t the same everywhere in the US (let alone the world), considering it’s a franchisee system. Being a truly conscientious and precise man, I decided to use the prices from someone’s picture of a McDonalds menu found randomly on Flickr (I’ll give props if I ever find the original source again).

Behind the scenes

Programming langage: Ruby

Not a lot to say here — I wanted to learn Ruby (because all the cool kids use Ruby!) so I did it in Ruby.

Framework: Sinatra

At first I wanted to use Ruby on Rails, but a bit of digging showed that Rails doesn’t really make sense for a project that small. I still plan on learning it, but Sinatra is incredible to quickly design and launch websites.

Templates: Haml & Sass

Haml and Sass are really great templating engines. Following Ruby’s approach of simplicity, minimalism and DRY, they allow you to write darn clean code that will be interpreted in HTML and CSS at runtime by Ruby (using the haml gem).

Hosting: Heroku / OVH

Heroku is hands down the simplest way to have your Sinatra app online. I would gladly repeat their sales pitch, but their website looks cooler than mine (damn pro infographists): http://heroku.com/

I also list OVH here because I registered http://sowhatcouldigetatmcdonalds.com/ through OVH’s registrar. 7€ for a year is perfect for me, and apparently even cheaper than GoDaddy.

Deployment: Git

If it’s on Heroku, it’s on Git.

I wish I used Git more during the development itself (it’s designed for source control after all), but I ended up not using it much before actually pushing the application on Heroku and GitHub.

Show me the code!

Sure! Here it is: http://github.com/Pluies/sowhatcouldigetatmcdonalds

Misc

The XHTML Transitional code generated by Haml is all neat (yay!) and passes the W3C validator (yay!) – same for the CSS (yay!). The CSS code is a little messy in my opinion though because the parens are closed inline, but I guess it’s a matter of taste.

The little bit of Javascript used to highlight the divs and generate the whole “not lovin’ it” part uses jQuery (through Google’s CDN).

I’ll post more about the process of getting used with all the tools in a quite-near future. In the meantime, I’m looking for any comment, criticism or advice on that project. Tell me everything!