Deploying Discourse With Capistrano

With the recent release of Discourse, an excellent piece of forum software by Jeff Atwood, Robin Ward and Sam Saffron, I was eager to get an installation up and running myself. With a simple layout it seemed like just what I needed as support and discussion forums for goodbre.ws. Discourse is still considered to be squarely in the beta phase, so I had a hard time finding any guides or tutorials that fit my needs for deploying Discourse to a VPS. I did find a nice tutorial by Christopher Baus, but I wanted to get a setup using Capistrano rather than init.d because that feels much more Railsy to me. Read on for how I got a Digital Ocean droplet running Discourse on thin with zero-downtime deployments.

Read on →

From 1.5 GB to 50 MB: The Story of My Redis Database

It’s been a while since I updated anybody on the current state of goodbre.ws. To make a long story short, I am in the midst of rewriting the site entirely. There are (or were) mainly two large problems for me. One big, niggling problem is that managing the database of beers on my own is impossible. My solution to this is to delegate that out to BreweryDB. They have so much more information on their beers than I do that it actually warrants a large rewrite of goodbre.ws. People have consistently asked for a more browsing-oriented experience as opposed to the current search-oriented experience. I’m going to deliver on that. The other big problem was how much memory my Redis instance was taking. Well, I have a small story about that. Yesterday, I reduced that memory usage from 1.5 GB to just 50 MB.

Read on →

The State of Recommendations in goodbre.ws

NOTE: This post has been updated. Please click through to read that.

Hello, friends and new faces. I want to take a moment to address a question that many of you have had on your mind since you came to goodbre.ws.

Where are my recommendations?

Pretty Much Everybody
Read on →

The Fox in the Snow (Belle and Sebastian)

Well, friends, this is where it all began. This was my first foray into singing while playing the piano, and it’s still one of my favorite songs to play. Everything I’ve done on the piano for the past few years has stemmed from this one song and, in a way, has led to this song.

This song is “The Fox in the Snow”, off of Belle and Sebastian’s album If You’re Feeling Sinister. It was their second album, released back in 1996. So it’s an “old” one, but a great one. Hope you guys enjoy it.

Read on →

Stop Validating Email Addresses With Your Complex Regex

Just stop, guys. It’s a waste of your time and your effort. Put down your Google search for an email regular expression, take a step back, and breathe. There’s a famous quote that goes:

Some people, when confronted with a problem, think, “I know, I’ll use regular expressions.”
Now they have two problems.

Here’s a fairly common code sample from Rails Applications with some sort of authentication system:

1
2
3
4
5
class User < ActiveRecord::Base
  # This regex is from https://github.com/plataformatec/devise, the most
  # popular Rails authentication library
  validates_format_of :email, :with => /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/
end

This seems fairly simple (unless you don’t know Regex), but it can get way worse…

1
2
3
class User < ActiveRecord::Base
  validates_format_of :email, :with => /^(|(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6})$/i
end

Or even worse still…

Read on →

Edge Rails 4.0: A Multilingual Inflector

Here’s a sneak peak at an upcoming enhancement for ActiveSupport::Inflector in Rails 4.0. The Inflector is the part of Rails responsible for a good amount of the cool stuff you can do with Strings: pluralization, singularization, titleization, humanization, tableization… The list goes on. Rails uses these methods extensively to map between, say, Model names, Controller names, and the Model’s table name.

Currently, the Inflector can handle only one set of rules at a time. Rails provides a lengthy list of singularization and pluralization rules for English, but what if somebody wants to specify how certain words in a foreign language (say Spanish) should be pluralized? In Rails 3, they have two options: they can define the words as irregularities in config/initializers/inflections.rb or put them into locale files. The former is bad because it involves mixing two languages into one set of rules, and the latter can lead to large, cluttered locale files when internationalizing a website. In Rails 4, however, I’m happy to offer a better solution for Rails developers in the process of internationalization: the Inflector is now multilingual. It can manage a complete set of inflection rules for each locale!

Read on →

The Current State of Rails Inflections

UPDATE: I’ve provided a better set of inflections in the form of a gem. If you agree with my sentiment here, check it out at the end of this post.

Ah, the Rails Inflector; we all know and love it. This little part of ActiveSupport has a lot of responsibility in our Rails applications, after all. It affects table names, class names, our resourceful routes, foreign keys… It’s a great part of ActiveSupport. Not only does much of Rails depend on the Inflector, but it provides useful mechanisms for string manipulation to users.

But how does the Inflector actually handle singularization and pluralization? English is not a regular language. There are a lot of grammatical rules to consider when converting between the two, so what does the Inflector consider? There must be some magic involved, right? According to the documentation, Rails defines these inflections directly in ActiveSupport… lib/active_support/inflections.rb to be exact. Let’s take a looksy, shall we?

Read on →

Collaborative Filtering With Likes and Dislikes

Ah, caught your attention, did I? Well, now that I have it, I’d like to sit down and have a chat. We need to talk, friend, and we need to talk about collaborative filtering. It’s a technique used in recommendation engines. Please repeat the following:

This is collaborative filtering. There are many different kinds of collaborative filtering, but mine is memory-based. Memory-based collaborative filtering is my best friend.

Gunnery Seargeant Hartman Full Metal Jacket

Okay, so I may be taking some creative liberty with this one. You shouldn’t be best friends with any one form of collaborative filtering. They all deserve love and they all have their uses. I’m sure the gunnery seargeant would agree with me! However, I would like to focus on memory-based collaborative filtering today as the algorithms that fall into this category are used often in recommender systems. Additionally, I’m going to go ahead and shift us into the context of a binary rating system: likes and dislikes. Okay? Okay!

Read on →

Why I Hate Five-Star Ratings

A question I get often when discussing goodbre.ws and, more recently, recommendable, is why I chose to implement a system based on Likes and Dislikes rather than the more standard five-star rating scale. Usually, I’m short and succinct: I think that star rating systems suck. Sometimes, I do go into a bit more detail: I think that star rating systems really suck. However, I’m starting to think that people may be asking this question and expecting some sort of “actual answer”, so today I would like to go into just why I think that the five-star rating scale is terrible, and why I decided to use the binary system of likes and dislikes.

Read on →

Recommendable

A small side-project that I’ve had conceptualized for several months has finally come to fruition! I’m speaking of Recommenable, a Rails Engine that I have been hard at work on for the past couple of days. Some of you may be familiar with a website I run called Goodbre.ws. Goodbre.ws is a recommendation engine for beer that operates using Likes and Dislikes rather than the more traditional ★★★★★ rating system. If you’re curious as to why I chose likes and dislikes, I’m planning a post soon that goes more into depth on this. Since I wrote Goodbre.ws, I’ve wanted to strip the logic for the recommendation engine itself out and make it available as an easily-includeable plugin for others. Late last night, I did just that, and the first working version is available for all to use. So, I would like to present you with…

Recommendable

Recommendable is an engine that, when installed, will insert a recommendation engine into your existing Ruby on Rails application. This will give a specified User class the immediate ability to being liking and disliking other Models in your application. Once your users have liked or disliked even a single thing, they’ll start to receive personalized recommendations!

Read on →