0
heroku_backups gem: backup and restore Heroku dbs to S3 on YOUR schedule

I’ve just released the gem heroku_backups.

Things you can do with it:
* Run automated backups (via cron, DelayedJob, or Resque)
* Restore your database from a point in time backup
* Move an entire database from one environment to another
* Restore your production database to your development machine

Some things I’m thinking about adding:
* Allow configuration for backups purging, and scheduling. For example, keep 48 hourly backups, 30 daily backups, 12 monthly backups
* MySQL support
* Other storage providers (local filesystem, dropbox, etc…)

Continue...
0
Authlogic token (or any token) based action authentication

I was digging into the single_access_token that AuthLogic provides for token based authentication, and just kinda had a “wow that’s fugly” reaction. It’s also not very well document. Instead I just rolled a method to jam in my ApplicationController. The method allows you to use the user’s single_access_token to authenticate to specific actions, and maintain the token in session for successive calls to token authenticated methods.

Use like this in your controller:

allow_token_access :index, :update

And put this in application_controller.rb:

def self.allow_token_access *attrs
  before_filter do
    session[:access_token] = params[:access_token] if params[:access_token]

    if session[:access_token] and attrs.include?(params[:action].to_sym)
      user = User.where(:single_access_token => session[:access_token]).first
      @current_user = user if user
    end
  end
end

One last bit of maintenance, clear out the token when your user actually logs in. Probably inside user_sessions_controller#create:

session[:access_token] = nil
Continue...
0
Stupid simple jquery field label plugin

Update: Mike L yelled at me for not using the HTML5 placeholder attribute. So I’ve updated the code to run from the placeholder attribute and only if needed by your jank ass browser.

(function( $ ) {
  $.fn.labelize = function() {
    if ('placeholder' in document.createElement("input")) { return; }

    element = this;
    var placeholder = element.attr('placeholder');

    var clearIt = function(){ if (element.val() == placeholder) $(element).val(''); }
    var labelIt = function(){ if (element.val() == '') element.val(placeholder); }
    labelIt();

    element.focus(clearIt).blur(labelIt).parents('form').submit(clearIt);
  }
})( jQuery );

Now just set the ‘placeholder’ attribute on an element and use it:

$('.thingy').labelize();
Continue...
0
Rake Tasks: Create and Delete Facebook Test Users with mini_fb

Here’s a create and delete rake task to create a few test Facebook users. The create just builds three test users, and then makes the necessary requests to friend each other. The delete destroys all users associated with your facebook app.

I just started playing with mini_fb. It’s nice in that it takes care of the nitty gritty authentication logic, and hides some details for you. I can see just hitting the graph api directly in the near future, as it may just encapsulate enough to be painful. We shall see… I’m using settingslogic to access configuration settings, but feel free to hit global config vars (yuck) if you wish…

namespace :facebook do
  desc "Seed test users on facebook"
  task :create_test_users => :environment do
    users = []
    3.times do
      #POST /app_id/accounts/test-users?installed=true&permissions=read_stream
      users << MiniFB.post(app_token, "#{Settings.facebook.id}/accounts/test-users", :installed => true)
    end

    # Create friend connections
    users.each do |u|
      (users - [u]).each do |friend|
        #POST /test_user_id_1/friends/test_user_id_2
        MiniFB.post(u.access_token, "#{u.id}/friends/#{friend.id}")
      end
    end
  end

  desc "Delete all test users on facebook"
  task :delete_test_users => :environment do
    #GET  /app_id/accounts/test-users
    users = MiniFB.get(app_token, "#{Settings.facebook.id}/accounts/test-users").data

    users.each do |u|
      # DELETE  /test_user_id
      success = MiniFB.post(u.access_token, u.id, :method => :delete)
    end
  end

  def app_token
    @token ||= MiniFB.authenticate_as_app(Settings.facebook.key, Settings.facebook.secret)['access_token']
  end
end
Continue...
0
New Application – Packio.com

Rob Walsh and I have launched Packio.com, a fun Rails 3 apps to help you pack based on the weather where you’re going. It hooks into the NOAA for weather data, as well as some geocoding services and bitly.

Continue...
0
Simple Permissions without Authentication / Authorization

Checkout my blog entry at Pathfinder Development.

Continue...
1
Reset a Model Within a Migration

I always have to look this up when running a funky migration that changes a model.  Rails ActiveRecord’s reset_column_information allows you to reset cached column information so you can now manipulate any new columns you may have added (or removed).

remove_column :fees, :fee_type_id
Fee.reset_column_information
Continue...
0
WordPress (or any mysql db) Backup One-Liner

mysqldump -u[your_username] -p[your_password] -h [your_host] [database_name] | bzip2 -c > [backup_path]/db_backup.`date +%Y%m%d-%H%M%S`.bz2

Continue...
0
RSpec2 and TextMate

The existing textmate bundle from David Chelimsky does not work with the latest version of RSpec 2 (currently at 2.0.0.rc). He’s a little busy lately :)

Railsjedi was kind enough to fork and fix the bundle to get it working again.  For now, I’m rolling with his fork.

Continue...