Double Shot #625 »
Created at: 13.01.2010 14:06, source: A Fresh Cup, tagged: Double Shot bombax cms jquery os x sandstone workflow
Next couple of weeks are looking super busy. Better than the alternative by far.
- I Have No Talent - Words well worth reading from John Nunemaker. There are ample ways to succeed in this business without being some sort of uber-coding genius. Trust me, I know.
- I Am Not a Master but a Solutionist - And Rob Bazinet chimes in to promote getting the job done.
- Sandstone - One more approach to CMS in Rails. Looks like there are several active branches with no one merging them though.
- Vote for Barbie's Next Career - "Computer engineer" is in the running.
- TotalFinder - Using SIMBL to make Finder better in Snow Leopard.
- TipTip JjQuery Plugin - A simple custom tooltip plugin.
- Bombax - Objective-C and Cocoa web development framework. No thanks.
- workflow - Another state machine alternative for Ruby.
more »
Planting the seeds »
Created at: 05.09.2009 16:00, source: Robby on Rails, tagged: Ruby on Rails ruby programming PLANET ARGON seeds database development workflow faker github rubyonrails code
Yesterday, the Rails team released 2.3.4, which includes standardized way for loading seed data into your application so that you didn’t have to clutter your database migrations.
I noticed a few comments on some blogs where people were asking how to use this new feature, so here is a quick runthrough a few ways that you can use it.
Populating Seed Data Approaches
The db/seeds.rb file is your playground. We’ve been evolving our seed file on a new project and it’s been great at allowing us to populate a really large data. Here are a few approaches that we’ve taken to diversify our data so that when we’re working on UI, we can have some diversified content.
Basic example
Any code that add to db/seeds.rb is going to executed when you run rake db:seed. You can do something as simple as:
# db/seeds.rb
Article.create(:title => 'My article title', :body => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit')Just create database records like you would in your Rails application or in script/console. Simple enough, right? Let’s play with a few other approaches that we’ve begun to use.
Use the names of real people
We’re using the Octopi gem to connect to github, collect all the names of people that follow me there, and using their names to seed our development database.
@robby_on_github = Octopi::User.find('robbyrussell')
# add a bunch of semi-real users
@robby_on_github.followers.each do |follower|
github_person = Octopi::User.find(follower)
next if github_person.name.nil?
# split their name in half... good enough (like the goonies)
first_name = github_person.name.split(' ')[0]
last_name = github_person.name.split(' ')[1]
new_person = Person.create(:first_name => first_name, :last_name => last_name, :email => Faker::Internet.email,
:password => 'secret', :password_confirmation => 'secret',
:github_username => follower, :website_url => github_person.blog)
# ...
endWe do this with a few sources (twitter, github, etc..) to pull in the names of real people. If you want to be part of my seed data, you might consider following me on Github. ;-)
Use Faker for Fake data
You may have noticed in the previous code sample, that I used Faker in that code. We are using this a bunch in our seed data file. With Faker, you can generate a ton of fake data really easy.
person.links.create(:title => Faker::Lorem.words(rand(7)+1).join(' ').capitalize,
:url => "http://#{Faker::Internet.domain_name}/",
:description => Faker::Lorem.sentences(rand(4)+1).join(' '))We might toss something like that into a method so that we can do the following:
@people = Person.find(:all)
500.times do
generate_link_for(@people.sort_by{rand}[0])
end...and we’ll get 500 links added randomly across all of the people we added to our system. You can get fairly creative here.
For example, we might even wanted random amounts of comments added to our links.
def generate_link_for(person)
link = person.links.create(:title => Faker::Lorem.words(rand(7)+1).join(' ').capitalize,
:url => "http://#{Faker::Internet.domain_name}/",
:description => Faker::Lorem.sentences(rand(4)+1).join(' '))
# let's randomly add some comments...
if link.valid?
rand(5).times do
link.comments.create(:person_id => @people.sort_by{rand}[0].id,
:body => Faker::Lorem.paragraph(rand(3)+1))
end
end
endIt’s not beautiful, but it gets the job done. It makes navigating around the application really easy so that we aren’t having to constantly input new data all the time. As mentioned, it really helps when we’re working on the UI.
Your ideas?
We’re trying a handful of various approaches to seed our database. If you have some fun ways of populating your development database with data, we’d love to hear about it.
more »
Git commit-msg for Lighthouse tickets »
Created at: 16.02.2009 21:51, source: Robby on Rails, tagged: programming git lighthouse github workflow bash
A quick follow-up to a post from a few months ago on how our team has a naming convention for git branches when we’re working on Lighthouse tickets (read previous post).
I’ve just put together a quick git hook for commit-msg, which will automatically amend the commit message with the current ticket number when you’re following the branch naming conventions described here.
Just toss this gist into .git/hooks/commit-msg.
#!/bin/sh
#
# Will append the current Lighthouse ticket number to the commit message automatically
# when you use the LH_* branch naming convention.
#
# Drop into .git/hooks/commit-msg
# chmod +x .git/hooks/commit-msg
exec < /dev/tty
commit_message=$1
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
branch=${ref#refs/heads/}
if [[ $branch =~ LH_(.*) ]]
then
lighthouse_ticket=${BASH_REMATCH[1]}
echo "What is the state of ticket #${lighthouse_ticket}? "
echo "(o)pen "
echo "(h)old"
echo "(r)esolved"
echo "Enter the current state for #${lighthouse_ticket}: (o)"
state="open"
read state_selection
case $state_selection in
"o" )
state="open"
;;
"h" )
state="hold"
;;
"r" )
state="resolved"
;;
esac
echo >&2 "[#${lighthouse_ticket} state:${state}]" >> "$1"
exit 0
fi
Then a quick example of how this works…
➜ bin git:(LH_9912 ♻ ) git ci -m "another test"
What is the state of this ticket?
(o)pen
(h)old
(r)esolved
Enter the current state: (o)
h
Created commit 1ed2713: another test
1 files changed, 3 insertions(+), 1 deletions(-)
Now to see this in action… (screenshot)
Then we’ll check out the git log really quick.
➜ bin git:(LH_9912) git log
commit 1ed271323c4a054fe56e76bddc9ac81d241a1032
Author: Robby Russell <robby@planetargon.com>
Date: Mon Feb 16 12:06:33 2009 -0800
another test
[#9912 state:hold]
Thanks to Andy for helping me figure out how to read user input during a git hook.
more »

