Recent Posts

Planet Argon Podcast, Episode 2: The Letter Scotch

October 30, 2009

Earlier this week our new podcast was approved and is now available in the Apple iTunes Store. We’re also soliciting topic ideas for future episodes on brainstormr.

We posted Episode 2, The Letter Scotch, yesterday for your enjoyment. In this episode, we covered a handful of web browser tools that we use (and detest) to debug HTML, CSS, and JavaScript. This included Web Inspector, Firebug, DebugBar, and a handful of other tools. We all have slightly different preferences, depending on the tasks that we’re working on and the team had an open dialogue about the pros/cons of each of these tools.

You can learn more about and listen to our podcast at http://planetargon.com/podcast.

Thanks in advance for listening!

Tracking AJAX-driven events in Ruby on Rails for Google Analytics conversion goals

October 21, 2009

Tracking your KPI’s is extremely important in your online venture. At a minimum, you should be using something like Google Analytics to track conversions in your application. Setting up goals is actually quite simple, especially if you’re just tracking that specific pages are loaded. However, if some of your conversion points occur through AJAX, you might not be capturing those activities in Google Analytics.

Lucky for you, it’s actually quite simple to update this. I thought I’d show you a fairly simple example to help you along.

On our web site, we have a mini contact form at the bottom of many of our pages. When submitted, if JavaScript is enabled, it’ll perform an Ajax request to submit the form. If you fill out the main Get in Touch form that gets processed and we redirect people to a thank you page. The URL for that is unique and we’re able to track those in Google Analytics quite easily.

However, with the Ajax-form, the URL in the browser isn’t going to change so Google Analytics isn’t going to track that conversion. So, we needed to track that properly.

To do this, we just need to call a JavaScript function that the Google Analytics code provides you.


pageTracker._trackPageview(“/contact_requests/thanks”);{lang=”ruby”}\

Let’s look at some simple code from our controller action. If the request is from JavaScript, we currently replace the form area with the content in a partial. (note: if you’re curious about the _x, read Designers, Developers and the x_ factor)


respond_to do |format|{lang=”ruby”}
format.html { redirect_to :action => :thanks }{lang=”ruby”}
format.js do{lang=”ruby”}
render :update do |page|{lang=”ruby”}
page.replace :x_mini_contact_form_module, :partial => ‘mini_contact_form_thanks’{lang=”ruby”}
end{lang=”ruby”}
end{lang=”ruby”}
end{lang=”ruby”}\

As you can see, the redirect will within the format.html block will lead people to our conversion point. However, the format.js block will keep the user on the current page and it’ll not trigger Google Analytics to track the conversion. To make this happen, we’ll just sprinkle in the following line of code.


page.call ‘pageTracker._trackPageview(“/contact_requests/thanks”);’{lang=”ruby”}\

However, if you need to do something like this in several locations in your application, you might want to just extend the JavaScriptGenerator page. GeneratorMethods. (you could toss this in lib/, create a plugin, etc…)


module ActionView{lang=”ruby”}
module Helpers{lang=”ruby”}
module PrototypeHelper{lang=”ruby”}
class JavaScriptGenerator #:nodoc:{lang=”ruby”}
module GeneratorMethods{lang=”ruby”}
# Calls the Google Analytics pageTracker._trackPageview function with {lang=”ruby”}[path{lang=”ruby”}]{.underline}.{lang=”ruby”}
#{lang=”ruby”}
# Examples:{lang=”ruby”}
#{lang=”ruby”}
#{lang=”ruby”}
# # Triggers: pageTracker._trackPageview(‘/contact_requests/thanks’);{lang=”ruby”}
# page.track_page_view ‘/contact_requests/thanks’{lang=”ruby”}
#{lang=”ruby”}
def track_page_view(path){lang=”ruby”}
record “pageTracker._trackPageview(‘#{path}’);”{lang=”ruby”}
end{lang=”ruby”}
end{lang=”ruby”}
end{lang=”ruby”}
end{lang=”ruby”}
end{lang=”ruby”}
end{lang=”ruby”}\

This will allow us to do the following:


page.track_page_view “/contact_requests/thanks”

# or using a route/path
page.track_page_view thanks_contact_requests_path\

So, our updated code now looks like:


render :update do |page|{lang=”ruby”}
page.replace :x_mini_contact_form_module, :partial => ‘mini_contact_form_thanks’{lang=”ruby”}
page.track_page_view thanks_contact_requests_path{lang=”ruby”}
end{lang=”ruby”}\

With this in place, we can sprinkle similar code for our various conversion points that are Ajax-driven and Google Analytics will pick it up.

Happy tracking!

RailsOnPg released

October 21, 2009

Hello fellow PostgreSQL and Ruby on Rails geeks,

Alexander Tretyakov (twitter) recently released a plugin for Ruby on Rails, which extends migrations and provides you with the ability to create.

While you can already do something like this with execute in your migrations:


execute(“CREATE VIEW my_tasty_snacks AS SELECT * FROM snacks WHERE food = ‘Tasty’;”){lang=”ruby”}\

With RailsOnPage, you’re provided a DSL so that you can do the following:


create_view :my_tasy_snacks do |view|{lang=”ruby”}
view.select ‘*’{lang=”ruby”}
view.from ‘snacks’{lang=”ruby”}
view.conditions ‘food’ => ‘Tasty’{lang=”ruby”}
end{lang=”ruby”}\

[note: I haven’t tested the above, just a hypothetical example]{.small}

Anyhow, if you’re in the habit of using views, functions, or triggers with your PostgreSQL database and are using Ruby on Rails, you might give RailsOnPg a whirl.

Email twice. Four months later

October 21, 2009

It’s been just over four months since I posted about my experiment, Email. Twice daily. No more, no less. where I shared my plans to restrict myself to checking email only twice a day at designated times. In the post, I had hinted at sharing my lessons months later. So, it’s time to throw my dirty laundry in the street and expose myself.

First off.. the brutal truth. It’s really fucking hard to maintain this. Habits are nearly as hard to make as they are to break. I suspect that I honor my rule 2-3 days each week and it’s completely inconsistent the remainder. Usually, I find myself looking at email at 8:30am and have to slap myself and yell, “what are you doing?!!?”

Guilt sinks in and I hit ⌘-q. Problem solved… for a little while.

So, what has lead to this. Well, one of the biggest hurdles has been that one of our largest clients is now focused more in the United Kingdom. Luckily, I’m an early-morning person, but this means that my 10am PDT rule wouldn’t have me checking for their precious emails until 6pm GMT their time. Not exactly acceptable. So, I’ve been more flexible in the mornings and responding to emails as early as 5-6am PDT. However, I realize that I’m cheating myself of previous focus time and need to recalibrate my email windows.

Given these new constraints, I’m now trying 8:30am and 2:30pm as my primary email times.

I’m curious how this has been working out for you…

The 8-Hour Rails Code Audit

October 20, 2009

While our team is typically focused on larger client and internal projects, we do get an opportunity to assist businesses on a much smaller scale. Whether this be through retainer-based consulting or through code audits, we have seen a lot of Ruby on Rails code over what has nearly been… five years!? We’ve been able to compile a fairly extensive checklist that we use in our code audit process that we’ve decided to streamline it into a smaller product.

Historically, this service has ranged anywhere from $2000-6000, depending the size and scope of the projects, but we want to help smaller startups[^1^](#fn1){#fnref1 .footnote-ref role=”doc-noteref”} and projects outline a roadmap for how they can begin to refactor and optimize their existing code base so that they can be more efficient at the start of 2010. So, we’ve scaled things down into an extremely affordable flat-rate package where we work off of a pre-defined number of hours.[^2^](#fn2){#fnref2 .footnote-ref role=”doc-noteref”}

Through the end of 2009, we’re now offering the 8-Hour Rails Code Audit package for just $1000 USD (details).

We’re currently limiting this service to just two projects per week, so reserve your spot now.


  1. ::: {#fn1} Larger projects are welcome to benefit from this service and custom quotes are available upon request.↩︎{.footnote-back role=”doc-backlink”} :::

  2. ::: {#fn2} As always, we’re happy to discuss longer engagements.↩︎{.footnote-back role=”doc-backlink”} :::

Flash Message Conductor now a Gem

October 13, 2009

We’ve been doing some early (or late… if you’re a half-full kind of person) spring cleaning on some of our projects. One of the small projects, flash_message_conductor, which we released last year as a plugin is now a gem. We’ve been moving away from using plugins in favor of gems as we like locking in specific released versions and being able to specify them in our environment.rb file is quite convenient.

To install, just run the following:

```
  sudo gem install flash-message-conductor --source=http://gemcutter.org
  Successfully installed flash-message-conductor-1.0.0
  1 gem installed
  Installing ri documentation for flash-message-conductor-1.0.0...
  Installing RDoc documentation for flash-message-conductor-1.0.0...
```

You’ll then just need to include the following in your config/environment.rb file.


Rails::Initializer.run do |config|{lang=”ruby”}
# …{lang=”ruby”}
config.gem ‘flash-message-conductor’, :lib => ‘flash_message_conductor’, :source => “http://gemcutter.org”{lang=”ruby”}
end{lang=”ruby”}\

You can take a peak at the README for usage examples.

We’ll be packaging up a handful of our various plugins that we reuse on projects and moving them to gems. Stay tuned… :-)

Oh My Zsh gets an auto-updater

September 30, 2009

I wanted to publically thank everyone for helping me get Oh My Zsh out there and continue to improve it. Many of us spend a lot of time in our terminals throughout the day and I firmly believe that having a well-working shell is nearly as important as having a well-working texteditor.

While Oh My Zsh isn’t a large project, it is my attempt to share what I’ve learned about using zsh with others… but honestly, my goal is to learn from you. I don’t have a lot of time to really dive into the deepend of the zsh-pool so am relying on others to share their tricks, hacks, functions, themes, etc. So, I thought that if I created a basic framework with outlined some conventions so that others could contribute, that perhaps I’d end up with a kickass shell.

So far… Oh My Zsh has been forked on github 25 times and is being watched by over 100 people.

Last week, I pushed out an update that introduces an auto-update feature. I’m quite keen of desktop applications that can auto-update themselves, so our initial version of this feature will ask you no more than once a week if you want to check for updates. This means that as we continue to extend and improve Oh My Zsh, you can keep up-to-date.

::: thumbnail Terminal 2014
zsh
[Uploaded with plasq’s Skitch!]{style=”font-family: Lucida Grande, Trebuchet, sans-serif, Helvetica, Arial; font-size: 10px; color: #808080”} :::

It’s the beginning of a new month… are you still using Bash? Perhaps you’re using your own zsh configuration but want to see what else zsh can offer you? I invite you to install Oh My Zsh today. :-)

Just run this in your terminal and you’ll get setup. Don’t worry… you won’t lose your existing configuration. :-)

wget http://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh

For more infromation, visit http://github.com/robbyrussell/oh-my-zsh/

Planting the seeds

September 05, 2009

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:

  1. 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’)

  1. 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)
# …
end\

We 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,{lang=”ruby”}
:url => “http://#{Faker::Internet.domain_name}/”,{lang=”ruby”}
:description => Faker::Lorem.sentences(rand(4)+1).join(’ ’)){lang=”ruby”}\

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
end\

It’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.

Oh My Zsh gets theme support

August 31, 2009

I just pushed a small change to Oh My Zsh, which gives it rudimentary support for themes. What I’m hoping to do is collect prompts from tons of people and make it simple for others to find a PROMPT that works well for them.

::: thumbnail robbyrussell's oh-my-zsh at
2c9f74b5c3f6910e7c66601008e9ddd0444b70c7 -
GitHub :::

As of right now, there are only three for you to choose from. So, please head over to github, fork Oh My Zsh, add your theme, and send a pull request. :-)

::: thumbnail zsh /Users/robbyrussell/Projects/development/planetargon/brainstorm
2014
zsh :::

Once I get it merged in, we’ll get a screenshot of it added to the Oh My Zsh wiki. (see themes)

I know that many of you have some really sweet prompts configured as I got a lot of response with my post, Show me your and I’ll show you mine (terminal prompts with git branches).

..and on the seventh day, Science created zsh

August 30, 2009

Inspired by some recent posts from Tom on zsh, I decided that I’d do my part to help people give it a whirl. I’ve been using zsh for a few years now and haven’t found myself missing bash.

If you’re interested in taking a few minutes to give zsh a while, you’re in luck. I recently reorganized all of my zsh config into a package and tossed it on github to share. My goal was to create a reusable tool that would allow people to get up and running quickly with some of the fun configuration that I’ve come to rely on on a daily basis.

For example:

  • Auto-complete rake and capistrano tasks
  • Git branch names when you’re in a git project directory structure
  • Tons of color highlighting (grep, git, etc.)
  • Sexy prompts.. (so say me)
  • much much more…

I invite you to give Oh My Zsh a whirl, which should take you less than a minute. Just follow the instructions.

Also, Oh My Zsh is Snow Leopard compatible. ;-)

So long and thanks for all the hoodwinks

August 20, 2009

_why,

If you’re out there and come across this… know that one of my fondest memories on the internet was with you. Hoodink.d was one of the greatest things on the internet four years ago and I suspect that a very tiny fraction of the Ruby community has even heard of it.

Thanks
hoodwink'd{width=”421” height=”199”}

Fortunately for me, I have a copy of the hoodwink git repository and was able to get it running tonight in hopes that I might find you lurking in the mousehole. I’m convinced that you are in a parallel internetverse. Perhaps you might send me an invite.

Hoodwink'd. do you
remember?{width=”465” height=”500”}

I miss hoodwink… and if you stay missing, I’ll just miss hoodwink more.

In the meantime, I wonder how hard it’ll be to get hoodwink to run on rack.

the winker's satellite office »
login{width=”500” height=”368”}

Wink you on the other side,
Robby

s. you can find me in my own mousehole… should you want to send me an invite and/or feed me cheese.