Blog

2 2

Open Source Wedding

Posted by Chris Barnes Tue, 16 Mar 2010 12:37:00 GMT

I'm getting Married this October and so I've created a wedding site for my personal use (http://www.fairbarneswedding.com). I thought, why should I use it once and leave it to rot in source control somewhere? So I'm releasing it under the GNU GPL.

At the time of this writing the project has news articles, events calendar with rsvp, paypal integrated donation meter, wedding party members, wedding stories, and static pages. If you fork the project and make it better, send me a push request. You can find the source at http://github.com/randomutterings/wedding

2 2

Changing images with JQuery and the fade effect 2

Posted by Chris Barnes Sun, 15 Feb 2009 15:14:00 GMT


Photo by me!

It took me a bit of digging to figure out how to fade out a picture, change the src, then fade it back in. I started out trying to use Scriptaculous but I got stuck trying to get the queue setup to wait until the image was faded out to change the src. I ended up using jQuery which also gave me a bonus, the solution is unabtrusive.

Here are the application.js and show.html.haml files from my project.

2 2

Pool-party, Auto-scaling with EC2 1

Posted by Chris Barnes Sat, 31 May 2008 16:03:00 GMT


Photo by hrlndspnks

Having a great time at Railsconf08. Meeting some great people and learning a lot. I plan to post in more detail about a lot of this after the conference but I wanted to go ahead and mention one of the coolest presentations I've seen so far.

Ari Lerner has created a ruby gem called pool-party. It auto-scales your ec2 cluster based on criteria you set in the config file like average requests per second. Set your minimum requests per second and if the average of all the servers on your cluster goes over the maximum, pool-party will launch another instance for you. It scales down in the same way. It doesn't care what you're using your cluster for and a its going to support plugins soon so you can add in your own hook like functionality. Pool-party is using s3fuse to mount an s3 bucket on the instance at startup. Specify a bucket in pool-party and it gets mounted at /data on each instance. This solves the data persistence issue with ec2. You're not required to use it though, just don't specify a bucket in pool-party and nothing gets mounted.

Ari open-sourced Pool Party as of 2 days ago. Check it out at poolpartyrb.com. If you want to contribute, its on github at http://github.com/auser/pool-party.
2 2

Subversion script for Rails developers 3

Posted by Chris Barnes Wed, 19 Sep 2007 19:15:00 GMT

I read somewhere that good developers use version control. There's a good article on HowtoUseRailsWithSubversion.

So why should I repeat those steps for every new project I work on.

There is another article which attempted to tackle this problem. However, you still have to do the initial steps and then copy this script into your project directory and execute it.

The following script takes it a bit farther. You call it like this.

rails-svn app_dir repository username

So if I wanted to create a new rails project called toejam, I would execute:

rails-svn toejam svn://randomutterings.com/projects/toejam/trunk chris

Here's what happens under the hood.

  1. After checking to make sure the directory doesn't already exist, your rails app is created with the standard rails command. (If the directory already exists, you will be asked if you want to continue. Choosing yes will allow the script to continue but if this script has been run on the same app twice, all of the svn commits will be duplicated.)

  2. Your new app is imported to the subversion repository specified. Authentication is done with the username provided. You may be prompted for a password from your repository.

  3. The original app directory is deleted and a working copy is checked out from the repository into that directory.

  4. All the default rails log files are removed and subversion is instructed to ignore those files. (Log files can get large and we definitely don't need them in version control.)

  5. The database.yml is moved to database.example to serve as a template for anyone who checks out the code and any newly created database.yml files are ignored by subversion. (Doing this will help if you have multiple developers working on the same project in different environments. It also prevents you from overwriting the database.yml file on the production server, oops!

  6. Subversion is told to ignore everything in the tmp folder, the .htaccess files, and the dispatch.fcgi file.

Without further ado, here's the script. Just copy it and save it somewhere in your path. /usr/bin is a good choice. Don't forget to chmod 755 so you can execute it.

    #!/bin/bash

    if [ "$#" != "3" ]; then
      echo "Usage: rails-svn app_dir repository username"
      exit 1
    fi

    APPDIR=./$1
    SVN_TRUNK=$2
    SVN_USER=$3

    function check_if_exist () {
      if [[ -e $1 ]]; then
        echo ""
        echo "$1 already exists, overwrite? y or n"
        echo ""
        read OVERWRITE
        case "$OVERWRITE" in
        y)
          echo "Overwriting..."
          ;;
        *)
          echo "Action canceled"
          exit 1
          ;;
        esac
      fi
    }

    check_if_exist ${APPDIR}
    rails $APPDIR
    svn import $APPDIR $SVN_TRUNK -m "Import" --username $SVN_USER
    sudo rm -r $APPDIR
    svn checkout $SVN_TRUNK $APPDIR
    cd $APPDIR

    svn remove log/*
    svn commit -m "removing log files" 
    svn propset svn:ignore "*.log" log/
    svn update log/
    svn commit -m "Ignoring all files in /log/ ending in .log"
    svn move config/database.yml config/database.example
    svn commit -m "Moving database.yml to database.example to provide a template for anyone who checks out the code"
    svn propset svn:ignore "database.yml" config/
    svn update config/
    svn commit -m "Ignoring database.yml"
    svn remove tmp/*
    svn propset svn:ignore "*" tmp/
    svn update tmp/
    svn commit -m "ignore tmp/ content from now" 
    svn propset svn:ignore ".htaccess" public/
    svn update public/
    svn commit -m "Ignoring .htaccess"
    svn propset svn:ignore "dispatch.fcgi" public/
    svn update public/
    svn commit -m "Ignoring dispatch.fcgi"

I'm interested in converting this into a gem and possibly rewriting it in ruby. If anyone has the skills and wants to contribute, leave a comment or email me.

2 2

Rapt error during peepcodes test first development tutorial 7

Posted by Chris Barnes Thu, 13 Sep 2007 16:47:00 GMT

OK, let me start off by saying, I love the tutorials from peepcode, you guys are doing a great job so keep doing it.

Alas, I got stuck while watching the Test-first-development tutorial. They were using Rapt as an alternative to script/plugin and when I tried to run it I kept getting an error.

Error: RaPT currently does not work outside of a Rails application directory. Please change to the top level of a Rails application and try again.

This error is misleading but at least it was obviously misleading, after all I know I'm in my Rails application directory.

After some googling, I found a post describing a work around for the problem, but it basically gave instructions on installing the plugin with script/plugin. But the guys at peepcode had a reason for using rapt over script/plugin (its faster). So I Google some more. I finally find a bug on the Rapt Trac posted in 2006 that explains that the user must first add repositories by executing the following.

rapt discover

If anyone knows how to have it default to yes without prompting you for every repository, please post a comment.

Alternatively, you can add only the repositories you want to use by executing the following.

rapt source http://path-to-repository