INCLUDE_DATA

starling yaml config file

I had a bit of trouble figuring how this should look like. Ended up finding it here. Basically, it should look something like:


starling:
queue_path: spool/starling
pid_file: pids/starling.pid
log_file: logs/starling.log
daemonize: true

Setting up starling on ubuntu

I use Enterprise Ruby for anything ruby. Here is the no none-sense process:

  1. sudo apt-get install build-essential zlib1g-dev libssl-dev libreadline5-dev
  2. Go here http://www.rubyenterpriseedition.com/download.html. Download and install
  3. On your server: sudo ln -s /opt/ruby-enterprise-x.x.x /opt/ruby
  4. sudo rm /usr/bin/ruby /usr/bin/gem
  5. sudo ln -s /opt/ruby/bin/ruby /usr/bin/ruby
  6. sudo ln -s /opt/ruby/bin/gem /usr/bin/gem
  7. sudo gem sources -a http://gems.github.com
  8. sudo gem install starling-starling
  9. Create a /etc/init.d/starling file and put this: http://gist.github.com/28849 in it
  10. sudo chmod +x /etc/init.d/starling

Done! Enjoy :)

Reloading a model during a migration

It’s documented, but I’ve somehow missed it. I was running this migration:

This kept failing with: undefined method `original_name=’ for #<Unit:0x3b61aa4>

After some poking around, comes reset_column_information to the rescue. After adding the columns and before looping, just add Unit.reset_column_information. This will reload the Unit model with the new columns, and all will go well.

metric-fu installation

Installing metric-fu is a really manual process. Copy the following and paste it in your shell:

sudo gem install flay

sudo gem install flog

sudo gem install rcov

sudo gem install railroad

sudo gem install reek

sudo gem install roodi

sudo gem install jscruggs-metric_fu -s http://gems.github.com/

Stopping SPAM and fake signups with mod_defensible and Apache on Ubuntu

Want to stop users from known blacklisted IP’s from accessing your site? Well, mod_definsible is the apache module for you. Here’s how to install it on Ubuntu:

sudo apt-get install libapache2-mod-defensible

then to enable the module do:

a2enmod defensible

Now create a file in /etc/apache2/mods-available/defensible.conf and put the following couple of lines in it:

DnsblUse On
DnsblServers xbl-bl.spamhaus.org. mydnbl.server.org.

Now restart apache and you’re all set. Now whenever a user that’s on spamhaus’s blocklist tries to access your site, they get a 403 Forbidden page.

Rails, passenger, ubuntu and EC2 – Part 1

I’ve been spending the better part of a year working on MoreDating, a dating site with a twist. It was and still is a joy to work on. I was asked to write my experience in deploying to EC2.

Let me start by saying that I am really impressed with EC2. It is super quick, and so far has been very stable. Let’s start with the technicalities.

Technical Specs:

  1. Ubuntu 8.04 Hardy
  2. Passenger 2.06
  3. Enterprise Ruby
  4. Large EC2 instance (8GB of RAM, 900 and change GB storage) @ $0.40/hour
  5. Image storage to S3
  6. MySQL database running off an EBS (Elastic Block Storage) drive

In this installment I will be talking about how I got EC2 up and running, and the preliminary configuration of the environment.

EC2 up and running with Ubuntu

I started out by getting an Amazon account, of course. You sign up by visiting: Amazon AWS. I then headed on to http://alestic.com/ to get the AMI that I need. Note that to use the 64-bit versions, you will need to setup a large EC2 instance. Now when I set it up, there wasn’t a pretty shiny interface for AWS, so I used elastic fox, the EC2 plugin for firefox (ElasticFox).

To spin up a new instance with all the necessary permissions, follow the Amazon EC2 Getting Started Guide . When it comes to the part about running an AMI, put in the ami path from the image you would like to use from alestic.

Once it’s up an running and you’re all connected, you can now start to configure it to your needs. Once we’re done with the configuration, we’ll go through taking an image of your instance so that you can spin other identical instances and to have a backup in case your instance goes haywire.

Configuring the goodies

  1. Install apache. Now, don’t go install any old apache, install the cool mpm-worker version. More information on that on the Apache Documentation Site . Install by running: sudo apt-get install apache2-mpm-worker
  2. Install ruby. Hold on, don’t go installing your vanilla ruby. Go to the good guys at phusion and download and install it. No vanilla ruby to install. Now we just need to make sure that it’s in the path server wide, so create a file in /etc/profile.d/ and call it ruby_path.sh and put this in it: export PATH=/opt/ruby/bin:$PATH. Now for this to work, make sure you have a symlink called /opt/ruby pointing to /opt/ruby/ruby-enterprise-lots-of-numbers-and-stuff-default-enterprise-installation-name. That way, whenever you install a new version of ruby enterprise edition, you just have to update the symlink.
  3. Install mysql (or postgres, or whatever). sudo apt-get install mysql-server (or whatever db server you’re going to use). Make sure you install the headers too.
  4. Little hack, I couldn’t figure out how to get it working properly. Whenever I try to install any gems using sudo, I have to provide the full path, so I made an alias for it in my .bash_profile: alias sgi=”sudo /opt/ruby/bin/gem install”. So now I just go: sgi some_gem
  5. Powered with this little hack, go ahead and run: sgi passenger. The installer is super friendly and will let you know exactly what is missing if you’re missing anything.

In my next post, I’ll be talking about capistrano setup, my deploy.rb script, and the costs of running EC2 full time + our use of S3 so far + our use of EBS.

Here’s a sample of the passenger and worker-specific of my apache2.conf and my bash_profile

jQuery and IE blues

Getting a “Expected identifier, string or number” error in IE using jQuery? Yeah I know, it takes forever to debug. In my case it was because I had one of those in my code:

$(element_id).attr({class: ‘signup_label_err’});

Apparently, class is a reserved keyword and this is what causes the error. Solution? Easy, just replace it with:

$(element_id).addClass(‘signup_label_err’);

Enjoy IE worry-free days.

ActionView::TemplateError (undefined method `adjust’ for #) on line #3 of vendor/plugins/exception_notification/views/exception_notifier/_timestamp.rhtml:

Got that one? Ha! Me too :)

Well apparently, Rails 2.1 doesn’t have TimeZone.adjust anymore, which is being called by vendor/plugins/exception_notification/views/exception_notifier/_timestamp.rhtml. All you have to do is replace those two lines:

time_zone = TimeZone.new(“Eastern Time (US & Canada)”)
timestamp = time_zone.adjust(Time.now)

and replace them with:

time_zone = ActiveSupport::TimeZone.new(“Eastern Time (US & Canada)”)
timestamp = Time.now.in_time_zone(time_zone)

A diff file is attached. Happy updating!

exception_notifier_tz_fix

Hey! Where’s my firebug highlighting??

Just installed firefox 3? Missing firebug highlighting? I guess you probably went to http://getfirebug.com and only saw the link for 1.0?

Fret not, the solution is here: https://addons.mozilla.org/en-US/firefox/addon/1843. Firebug 1.2 beta. The release version should be coming out in a couple of days.

vendor/rails/actionpack/lib/action_view/helpers/date_helper.rb:602:in `date_or_time_select’

Am I the only person in the world with this problem? I searched all over the web for a fix, but no one was even talking about it. The error I get is:

ArgumentError in My/profiles#show
wrong number of arguments (2 for 1)

I am running Rails 2.1, and putting a run-of-the-mill date_select crashes with the error shown in the title. I scratched my head at first, then banged it against the wall. I don’t know how this could be broken, but here is how I monkey-patched it.

Create a file in config/initializers and call it anythingyouwant.rb, and paste this in:

module ActionView
  module Helpers
    class InstanceTag #:nodoc:
      def to_date_select_tag(options = {}, html_options = {})
        date_or_time_select(options.merge(:discard_hour => true))
      end
    end
  end
end

That should fix it.