Sunday, September 6, 2009

BucketWise + Heroku => Profit!

I've been working with Jamis Buck's BucketWise and enjoying the control I exercise over my spending. But... I started with a local installation and it was good, but not so shareable. So... I tried installing at DreamHost, but things were not so compatible. Finally, I was messing with Heroku and found interesting info about how to install BucketWise there.

It seems that BucketWise uses git external references to pull in its plugin dependencies. Heroku uses git to manage applications, as in doing a git push (or similar) to deploy an application from a local repository to its Heroku location. Unfortunately, Heroku doesn't handle the external references. and leaves the plugins out of the deploy.

I found a fork by Tony Eichelberger (http://github.com/watkyn) that pulls out the git externals stuff and includes the plugins directly in the repository. doing a git clone from there and doing the Heroku setup stuff in the clone directory results in a working Heroku app.

There's a bit of a problem setting up the application once it's running. Heroku doesn't seem to support interactive Rake commands so I got into the Heroku console and directly created a new user and subscription to use.
  1. Clone the repository
    git clone git://github.com/watkyn/bucketwise.git bucketwise
  2. Create the Heroku app
    heroku create my-bucketwise-app
    git push heroku
    heroku rake db:schema:load
  3. Setup BucketWise
    heroku console
    >> user = User.create({:name => 'Full Name', :email => 'email@server.com', :user_name => 'username', :password => 'FancyPass234'})
    >> sub = Subscription.create(:owner => user)
    >> user.subscriptions << sub
  4. Login & Profit!

BTW, I haven't tried it but the plugin changes here probably make the system work in DreamHost.

Thursday, August 27, 2009

autotest and rails 2.x => NOP

One of the recent rails upgrades killed off autotest for me. My next door neighbor in training at RubyConf suggested the autotest-rails gem. It did the trick and got me running again.

Sunday, August 23, 2009

imgur - Totally simple image hosting

Go to imgur

Choose an image to upload and press 'Continue'

Once uploaded, have links to the original image plus small and large thumbnails. Choose the size you want and copy the proper text for your type of link to paste somewhere.

How simple can it be?

Images are kept for three months after last viewing.

Sunday, August 2, 2009

Necessary bits to make Control.Tabs work

When making Control.Tabs ( http://livepipe.net/control/tabs ) work, it is necessary to put the "new Control.tabs('classname');" javascript at the bottom of the page. The header just doesn't cut it.

Turn off auto-dating for ActiveRecord in tests

Fixtures have one nice characteristic. setting updated_at and created_at in them overrides what ActiveRecord would normally record. When using Factories (like factory_girl), want to have a way to turn the auto-dating off and on.

Michał Szajbe at Code Tunes provides this useful tidbit.

Add a small bit of code to test_helper.rb inside TestCase
  def without_timestamping_of(*klasses)
if block_given?
klasses.delete_if { |klass| !klass.record_timestamps }
klasses.each { |klass| klass.record_timestamps = false }
begin
yield
ensure
klasses.each { |klass| klass.record_timestamps = true }
end
end
end
After that, just wrap Factory calls in without_timestamping_of to turn off dating.
  without_timestamping_of Article, Comment, User do
Factory(:article, :created_at => 1.week.ago, :updated_at => 1.week.ago)
Factory(:comment, :created_at => 1.day.ago)
Factory(:user, :updated_at => 5.hours.ago)
end
Simple and very useful. Many thanks again to Michał Szajbe at Code Tunes

How to tell if a ruby variable is already set.

Use the 'defined?' command to determine if a variable has already been set in a ruby script.

e.g. alpha = 'A' unless (defined?(alpha))

set the value of alpha to be 'A' unless it's already set. Yes, there are other shorter ways to do this particular. But, the example is still relevant.

Monday, February 9, 2009

Debugging -or- Lose the "Print Variable" Mentality

Thanks to Mischa Fierer at The Momoro Hoax for getting me off my duff to try out debugging with rails again. I'd not done anything since it didn't work for me in RadRails and XP/Vista. Now I'm on Linux and have no excuses.

Specifically, Use rails debugger ! A tutorial walked through the steps to get started. Look to the Rails Debugging Guide for more detailed learning when the time comes.

Friday, February 6, 2009

Force Exceptions in Migrations

A couple of times now, I've run a data update migration that failed and didn't throw an Exception. So I ended up with bad data in the system and no knowledge of the problem until the application bombed out in production.

Instead, use the '!' version of save when you do the updates. g.save! throws an exception on failure where g.save does not.

Thursday, February 5, 2009

Two Buttons - One Form

Create a form with two submit buttons. Label them each differently and Rails passes the name of the one that was pressed back in params['commit'].

Useful to have one button return to the listing view while having the other button save, but leave the input form open for more data.

Act to Advance

Try the new thing just when I read it. It will stay when it's a good thing.

Ten minutes with each of Autotest, FlexMock, Factory Girl, and Shoulda improved my testing immeasurably.

And not half as painful as I ever expected.

rubygems proxy URL

The proper format to set the proxy for 'gem' inside my corporate firewall is:

gem install xyz --http-proxy http://user:pass@proxy.domain.com:8080/

Must have the port for anything to work. Probably can put this in ".gemrc".