Code Worrier

Teaching myself to RTFM

Facebook Graph API v2.0: Building ‘Find Friends’ and Related Features

| Comments

In an earlier post, I detailed some important differences between version 2.0 of Facebook’s graph API and the old version. These include the replacement of global user ids with application-specific ids, and the new restriction of friend data to friends that have connected to the client application. If you’re not familiar with these differences but would like to read on, I recommend reading that post first. In this post, I turn my attention to building features with the restricted data that v2.0 affords us. I will walk through three related features:

  1. Finding your users’ Facebook friends who are already using your app.
  2. Notifying existing users of your app when their Facebook friends register.
  3. Allowing existing users to invite their Facebook friends to join.

Facebook Graph API v2.0: What’s Changed?

| Comments

Facebook recently introduced major changes to its Graph API. Despite the existence of an official upgrade guide, these changes have caused a lot of confusion for some developers, myself among them. In this post, I explore in detail the key differences between v1.0 and v2.0 of the API that cause the most frustration. In a follow-up post, I discuss how to use v2.0 to build some common features involving finding and inviting Facebook friends.

Git Bisect: Your Friend in Times of Need

| Comments

Git bisect is like CPR or a fire extinguisher: You shouldn’t need it very often, but when you, it might just save a life.

In case you are not familiar with its splendor, git bisect is a tool for pinpointing the commit that caused a change. Usually, the change you’re interested in is the introduction of a bug. Bisect is handy when, for instance, you discover a regression and you don’t know what caused it or exactly how long it’s been around. Bisect isolates the offending commit with logarithmic efficiency. It accomplishes this by performing a binary search of the commits on your branch, dividing and conquering until only one commit remains.

How to Checkout the Last Git Branch You Were On

| Comments

Checking out the last branch you were on is as simple as git checkout -.

11:13:14-hoffm~/src/food52 (develop)$ git checkout master
Switched to branch 'master'
11:13:21-hoffm~/src/food52 (master)$ git checkout -
Switched to branch 'develop'
11:13:23-hoffm~/src/food52 (develop)$ git checkout -
Switched to branch 'master'


3 Surprises From My First Open Source Contribution

| Comments

I recently submitted my first (tiny!) patch to an open source project. It’s something I’d wanted to do for a long time, but couldn’t figure out how to initiate. Here are some things that surprised me about the process.

1. Most of the work is not coding.

This, as I understand it, is the lifecycle of a garden-variety open source contribution:

  • Find a problem.
  • Muster your courage.
  • Describe the problem to the project owners in excruciating detail.
  • Convince them it’s a problem worth solving.
  • Fork the app and get it up and running locally.
  • Solve the problem (write production code and tests).
  • Document the solution (docs, commit messages, changelogs).
  • Propose, explain, and defend your solution (pull request).
  • Iterate on your solution and its documentation.

404 and 500 Error Pages in Rails

| Comments

There are many approaches to responding to failed requests in Rails. Here I offer the way I currently favor setting things up. I’m hoping that this might start a conversation about best practices; I’m sure I could do better!

The default way Rails handles requests to which your application does not have a contentful response is to serve up static HTML documents stored in the public directory. In particular, 500 (server error) and 404 (not found) responses result in the application’s rendering 500.html and 404.html, respectively.

Try Out Routes in the Rails Console

| Comments

How do you quickly check what path a certain route helper maps to?

One method I use a lot is to grep rake routes. So, let’s say I’m looking for a route that has to do with comment approval. In that case, I might run rake routes | grep approve. And there’s my answer:

approve_comment POST  /comments/:id/approve(.:format)  {:action=>"approve", :controller=>"comments"}

There’s one problem with this, though: It’s slooooow.

Custom Slugs in Rails Without Gems

| Comments

There are some nice gems out there to help you create and manage human-readable slugs in Rails. However, our requirements at Food52 were simple enough—and different enough from the standard case—that I thought I’d have a go at building a slugging system from scratch.

The Problem

As an example of the desired behavior, given that we want to use the attribute name to generate slugs for users, and given that my user id is 784 and my name is “Michael Hoffman”, the slug for my user page should be:


(We leave the id in because we like it there! It makes debugging easier and it allows us to use Active Record find to look up objects from params.)

Furthermore, we want our slugs to adapt gracefully to changing circumstances. So, if my name changes, the slug should do…something smart.

Getting a little more abstract, our requirements are as follows: