Requiring SSL Using Route Constraints in Rails 3

The new router in Rails 3 makes it super easy to require SSL for certain routes. Just use the following in your config/routes.rb:

MyApp::Application.routes.draw do
  class SslConstraint
    def self.matches?(request)
      request.ssl?
    end
  end

  scope :constraints => SslConstraint do
    resources :payments
    # Other SSL routes go in here
  end
end

Now, this is a pretty simple example–you’ll likely want to also have routes to redirect if a user tries to access without SSL, but it definitely shows off the power of the new router.

Posted on August 13, 2010 Leave a Comment
Tagged with: , , ,

GitHub Introduces Organizations

This is just awesome. Prices feel a little high (for private repositories, the plans start at $100/mo), but if you’re a business that needs this, you’re likely able to afford it.

Posted on June 29, 2010 Leave a Comment
Tagged with: ,

Install LAMP stack from source with Homebrew

A quick tutorial on installing PHP from source using Homebrew. I needed to recompile PHP and could not get things to work, until Ben Bleikamp pointed me towards Homebrew, and this tutorial worked great. One thing to note: the tutorial is a bit out of date, as it uses newer versions of the software, so make sure to check the versions in the commands. For me, I had to change this line:

sudo ln -s /usr/local/Cellar/php52/5.2.12/libexec/apache2/libphp5.so /usr/libexec/apache2/libphp5.2.so

I updated it to 5.2.13:

sudo ln -s /usr/local/Cellar/php52/5.2.13/libexec/apache2/libphp5.so /usr/libexec/apache2/libphp5.2.so

Posted on June 7, 2010 Leave a Comment
Tagged with: , , ,

Gruber's Google I/O Thoughts

The big loser this week, though, was Microsoft. They’re simply not even part of the game. RIM looms large, as BlackBerrys continue to reign as the best-selling smartphones in the U.S. But Microsoft? They’ve got nothing. No interesting devices, weak sales, and a shrinking user base. Microsoft’s irrelevance is taken for granted.

As usual, John Gruber nails it. Microsoft really has no chance at catching up with either Apple or Google at this point, and it’s pretty stunning. They entered the game way too late, and, as far as I know, it’s still going to be a while before the first Windows Phone 7 handsets come out. They’ve already lost the mobile war.

However, as Gruber mentions, things between Apple and Google are getting very interesting. While I admittedly have not been all that satisfied with my Droid experience so far, it’s a promising platform, and I really love how much Google is pushing cloud technology. A cell phone should operate completely separate from a computer, and that’s something Apple just hasn’t done right yet.

Posted on May 23, 2010 Leave a Comment
Tagged with: , , , , ,

Photos of Space Shuttle Atlantis' Final Launch

The end of an era. It will be a sad day when the final space shuttle mission is completed.

Posted on May 14, 2010 Leave a Comment
Tagged with: , , ,

Lazy Loading Asynchronous Javascript

A great summary of how to build a non-blocking JS widget.

Posted on May 7, 2010 1 Comment
Tagged with: , ,

Using Git Branches as Patches

At Viddler, we’re now using Git for projects, and it’s going really well so far. While we haven’t figured out the perfect workflow just yet, we’re doing some things I really like, and one of them is treating branches like patches.

Often, people think of Git branches as a full copy of the parent branch, but it’s better to treat them as a simple collection of new commits, to be applied to the parent branch later. This might not seem too revolutionary, but this small change in thinking can really improve your workflow.

For example, at Viddler we use Trac to manage tickets, and in Git. For each ticket in Trac, we create a branch, called something like 3241-fix-embed-codes. We have two permanent branches: dev, which reflects current development, and master, which is considered always production-ready. So, dev and master are going to have different code to reflect their reflective stability. To get started with a fix, we first create a feature branch from master:

git checkout -b 3241-fix-embed-codes master

This simply creates a new branch of master called 3241-fix-embed-codes and checks it out. When the ticket is completed and the code has been committed, the patch thinking really comes into play. Since this now needs to be tested in the dev environment, the branch first gets applied to the dev branch:

git checkout dev
git merge —no-ff 3241-fix-embed-codes

Using the —no-ff option on git merge is important for this patch mindset: it creates a separate commit for the merge itself, which allows you to git revert the entire thing (if necessary), rather than having to undo each individual commit within it.

Once we’ve decided this fix is read for production, it’s time to move the code over to master. Without the patch mindset, you might consider merging dev into master, but that means you’d be copying anything that’s applied to dev, some of which might not yet be ready. When you think of your feature branch as a patch, however, it’s easy to only apply the one you need. To apply this patch to master, just use a similar method as before:

git checkout master
git merge --no-ff 3241-fix-embed-codes

Now you’ve only moved the safe commits over, leaving any buggy code safely in dev.

This method may seem obvious, but the mindset has really changed the way I use Git, and I think it makes it a much more powerful tool, especially when you’re working across multiple environments (like production and staging). I’ve skipped over some additional considerations, like merging master/dev into your feature branch, but those are topics for a future post.

Posted on May 6, 2010 2 Comments
Tagged with: , , , ,

Marco Arment on iPhone vs. Android

Apple’s feeling threatened by Android, as they should be. So they’re systematically targeting and eliminating major reasons why someone would choose Android over iPhone.

But they haven’t yet hit the biggest one: availability on different U.S. carriers, specifically a CDMA edition for Verizon.

Bingo. If the iPhone came to Verizon tomorrow, I would seriously consider ditching my Droid and paying full price for it.

Posted on April 27, 2010 Leave a Comment
Tagged with: , , , ,

Flot

A jQuery library for easy graphs using the <canvas> tag. It even works in IE6!

Posted on April 23, 2010 Leave a Comment
Tagged with: , , , , , ,

Git Autocompletion in OS X

Add the source line to your ~/.profile or ~/.bash_profile to enable tab autocompletion of branch names, remotes, etc.

Posted on April 23, 2010 1 Comment
Tagged with: , , ,

Henge Docks

Super simple docking station for your MacBook or MacBook Pro.

Reblogged from: Engadget
Posted on April 19, 2010 Leave a Comment
Tagged with: , , , , ,

Canable: The Flesh Eating Permission System

John Nunemaker releases his super-simple way to implement permissions in a Rails app. I love how this does away with a complicated role system and just deals with whether or not a user can do specific action. Simplicity at its finest.

Posted on February 28, 2010 Leave a Comment
Tagged with: , , , ,