Categories
Coding How-To ruby ruby on rails WebApps

Upgrade Your Rails Facebook App to SSL

On October 1st of this year, Facebook will be requiring that all apps on Facebook must support HTTPS (SSL).

I’ve provided a guide below which I’ve used for apps I’ve worked on that are Rails based.

This guide shows you how to change your Rails Facebook App into an app that supports SSL using Passenger and Apache2.

Step 1: Get an SSL cert or roll your own.

Dreamhost.com made it very easy to add an SSL cert for just $15.00 / year.

I tried out my app out using a locally signed certificate which seemed to work just fine:

openssl genrsa -des3 -out server.key 2048
openssl req -new -key server.key -out server.csr
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Step 2: Install and compile Apache 2

Get the latest version of Apache: http://httpd.apache.org/download.cgi.

Configure and compile Apache:
./configure –prefix=/usr/local/apache2 –enable-rewrite –enable-so –enable-ssl
make && make install

Step 3: Configure your Rails app

gem install passenger
passenger-install-apache2-module

Step 4: Edit your Apache 2 config files:

Edit httpd.conf. For example:

LoadModule fcgid_module modules/mod_fcgid.so
LoadModule passenger_module /Users/jimbarcelona/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.8/ext/apache2/mod_passenger.so
PassengerRoot /Users/jimbarcelona/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.8
PassengerRuby /Users/jimbarcelona/.rvm/wrappers/ruby-1.9.2-p290/ruby


    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all


Include conf/extra/httpd-vhosts.conf
Include conf/extra/httpd-ssl.conf


IPCCommTimeout 40
IPCConnectTimeout 10

# TODO: change this to production if you are on production
DefaultInitEnv RAILS_ENV development
SocketPath /tmp/fcgidsock

Edit extra/httpd-vhosts.conf:


  ServerName berkeley.l33tcave.com
  ServerAdmin wwwadmin@berkeley.l33tcave.com
  DocumentRoot /Users/jimbarcelona/rails_apps/github/hipsterhookups.com/public
  ErrorLog /usr/local/apache2/logs/rails_error_log
  RewriteEngine On
  
    AllowOverride All
    Options -MultiViews
  
  RailsEnv development

Edit extra/httpd-ssl.conf:

#   General setup for the virtual host
DocumentRoot "/Users/jimbarcelona/rails_apps/github/hipsterhookups.com/public"
ServerName berkeley.l33tcave.com:443
ServerAdmin you@example.com
ErrorLog "/usr/local/apache2/logs/error_log"
TransferLog "/usr/local/apache2/logs/access_log"

# needed for rails
Options Indexes ExecCGI FollowSymLinks
RewriteEngine On
RailsEnv development


AddHandler fcgid-script .fcgi

  
    AllowOverride All
    Options -MultiViews
  

Be sure to add your SSL certs in the httpd-ssl.conf too!

Step 5: Start Apache

# check syntax
apachectl configtest
# start apache
apachectl start

Step 6: Go to facebook and use https for canvas URLs

Categories
How-To ruby WebApps

Setting Up Cucumber and RSpec on Padrino

This is a quick guide on how to set up Cucumber and RSpec on Padrino.

I’ve created a simple test app on github that reflects the steps written down here.

1. Create the app:

padrino g project todo -t cucumber -d sequel -b

2. In the Gemfile use rake 0.8.7:

gem 'rake', "0.8.7"

3. In features/support/env.rb comment out “require ‘spec/expectations'” so it looks like:

# require 'spec/expectations'

At this point ‘cucumber features’ should work and should return a failed test for adding two numbers.

Also at this point, if you create any models, then bare specs for them will be created in the ‘spec/models’ folder.

Please feel free to leave questions or comments if you’ve got a different way of setting things up on Padrino.

Categories
How-To ruby WebApps

How To Test Image Uploads With MiniTest On Padrino

This week I got to pair program with Oren Golan whose last high profile job was at Border Stylo. While there, he wrote a series of excellent blog posts that I highly recommend reading. The one that caught my eye was his post on MiniTest, that’s a lighter version of RSpec.

We created a Padrino app that uses the Sequel gem as an ORM for SQLite.

We tested a raw file upload and the uploading capabilities of Carrierwave.

The working test is on http://github.com/barce/test, and to run it just clone the repo and type the following:

cd test
bundle install
padrino sq:migrate:up

Here’s the test:

# put this into the test/test.rb file
require 'rubygems'
gem 'minitest'
require 'minitest/autorun'
require 'rack/test'
require '../config/boot.rb'

class TestManualBadgeType < MiniTest::Unit::TestCase
  include Rack::Test::Methods

  FILE2UPLOAD  = "/Users/jimbarcelona/pink-pony.jpg"
  UPLOADEDFILE = "/Users/jimbarcelona/repos/oren/forks/test/test/pink-pony.jpg"

  def app() Test end

  def setup
    if File.exist?(UPLOADEDFILE)
      File.delete(UPLOADEDFILE)
    end
  end

  def test_opload
    post '/', 'file' => Rack::Test::UploadedFile.new(FILE2UPLOAD, 'image/jpeg')

    assert_equal last_response.status, 201
  end

  def test_carrierwave_201
    post '/carrierwave', 'file' => Rack::Test::UploadedFile.new(FILE2UPLOAD, 'image/jpeg')

    assert_equal last_response.status, 201
  end

  def test_carrierwave_file_exist
    post '/carrierwave', 'file' => Rack::Test::UploadedFile.new(FILE2UPLOAD, 'image/jpeg')
    assert_equal last_response.status, 201
  end
end

Now you’re ready to run the test upload:

cd test
ruby test.rb
Categories
ruby TechBiz

Jim Barcelona, Ruby Rockstar

The term “rockstar” is much maligned in tech circles when applied to job descriptions.

Another sentiment told with utter sarcasm:

Any job description which contains the word, “rockstar,” must also disclose the salary offer.

-Steve

@jangosteve
And to round things out:
There’s nothing more ridiculous than job ads requesting a Ruby rock star. — Giles Bowkett
Since the term is so maligned, I’ve decided to take it. Like a day trader attracted to something at it’s lowest buy point, I’m attracted to the term, “Rockstar.”
My guitar skills aren’t that great. If anybody should be worthy of the term of Ruby rockstar it should be Zed Shaw for meeting the terms figuratively and literally. He plays guitar in an awesome way in the streets and he’s a great coder.
I wrote an email to the SF Ruby Meetup List in jest that was written in the alter ego of a Ruby rockstar. I was poking fun of a combination of stereotypes dealing with coders with egos and rockstars with egos.
The businessman in me thinks it’s such a shame that folks don’t own up to the moniker. Since others won’t; I will. I’m Jim Barcelona, Ruby rockstar.
Categories
Coding ruby ruby on rails

Upgrading To Rails 3

Here’s how I upgraded Sitebeagle.net to Rails 3.

1. Go into your site’s Rails directory and install rails_upgrade:

script/plugin install git://github.com/rails/rails_upgrade.git

Run the following commands and follow the instructions:

rake rails:upgrade:check
rake rails:upgrade:backup
rake rails:upgrade:routes
rake rails:upgrade:gems
rake rails:upgrade:configuration

2. Make sure that your version of Ruby 1.9+ has iconv working.

Mine didn’t, so I went through this process:

rvm package install readline
rvm package install iconv
rvm remove 1.9.2
rvm install –trace 1.9.2 -C –with-iconv-dir=$HOME/.rvm/usr

to test:
irb
require ‘iconv’ # should return true

3. Upgrade to Rails 3: gem install rails

4. Start migrating to Rails 3: I branched my site using git and went into my Rails root directory and typed:

rails `pwd`

Use your best judgment on what can and cannot be over-written. Here’s my list:

* let rails overwrite?
* overwrite rake file
* overwrite application_controller.rb? yes but copy
* application_helper.rb ? yes
* routes.rb ? yes but copy
* environment.rb ?
* make new initializer for contants
* config.gem? copy and put into a Gemfile
* application.js ? only if confident in js
* scripts? overwrite all

5. See if stuff works:

rails server

Twitter-auth broke for me, so I had to update it to work on Rails 3 using this guide:

https://github.com/benders/twitter-auth/compare/master…rails_3

How’s your upgrade to Rails 3 go? Let me know in the comments below.

Update (14 January 2011):

Chris Laco wrote up this great guide to upgrading Rails 3 on Dreamhost. It solves path problem issues with gems.

Categories
php Questions ruby TechBiz WebApps

My Favorite Coder Interview Question

What is your favorite algorithm?

My favorite algorithm right now is the merge sort.

v1: Nuno Nogueira (Nmnogueira), v2: edited by Daniel Miller (cobaltBlue)
v1: Nuno Nogueira (Nmnogueira), v2: edited by Daniel Miller (cobaltBlue)

I like it so much that I’ve implemented it in PHP and Ruby.

The problem is that as a web developer I’ve never had to use a merge sort. Back in the old days when pagination was tricky, I’ve had to use a linked list, but you really don’t have to use the merge sort anymore.

So at this point it’s really just academic.

What interview question should really count now?

More on that in my next post. As a clue, I’d like to say it has to do with Leibniz’s statement, “The present is big with the future.” A techie who believes that and the principle of sufficient reason is the kind of techie you want.

Categories
command-line How-To ruby WebApps

A Quick Guide to Noobwatcher

curl -O http://svn.collab.net/repos/svn/trunk/tools/client-side/showchange.pl
mv showchange.pl $HOME/bin
svn co http://codebelay.com/noobwatcher
mkdir watched_repositories
cd watches_repositories
cp $HOME/noobwatcher/trunk/noobwatcher.rb .
svn co

Create and edit a settings.yml file. Mine looksl like this:

path: /Users/barce/nooblive/trunk
repo: http://www.example.com/the_repo_I_am_watching
diffs: /Users/barce/nooblive/diffs
twitter_email: the_twitter_email_that_notifies_you@example.com
twitter_password: the_password_to_the_twitter_email_that_notifies_you
twitter_recipient: your_twitter_account
sleepseconds: 60

Start noobwatcher:

./noobwatcher.rb
Categories
ruby

Part II of NoobWatcher: Automatically Reporting Server File Changes

With Noobwatcher, I’m now able to be really on top of subversion commits. But now it’s time to start working on part II, the part that keeps track of my server configuration and makes sure that it’s correct for all the servers that I want to use.

I’m taking a look at Tripwire. Are there any libraries that you use for automatically checking if files have changed?

Categories
ruby Social Media TechBiz

Yahoo’s BOSS API Example and Notes on Yahoo’s Hackday

For Yahoo’s hackday, I was able to finish up this script in Ruby that returns back search results from yelp and chowhound from Yahoo’s BOSS API. The great thing about it is that you can hit the API an unlimited number of times!

Here are a few notes that should help anybody the next time they attend a hackday – Yahoo’s or anyone else’s:

  • The night before install libraries you think you won’t need. I really wish that I had prawnto installed. I got mired in prawnto idiosyncracies, and was out of the race pretty quick.
  • Good coders are fast. According to Eran Lahav-Hammer, one of the authors of OAuth, good coders can code an OAuth implementation in the language of their choice in less than one day. Are you a good coder?
  • Have fun! It’s a pretty rare opportunity to have so many folks in the industry in one spot.