Integrate Google Event Tracking with JavaScript

This post discusses easy ways to integrate Google Analytics Event Tracking in your website. Event Tracking is a tool that broadens your ability to track user interaction with your website. Prior to event tracking, using Google Analytics gave you rich information about your page views. With Event Tracking you now have a wealth of information about usage on your non-page reloading events such as AJAX calls, hover events, mouseovers -- anything you would like to define and track. (Just make sure you have an account first).

It's dead simple and, after setup, takes a one-line call to a JavaScript method supplied by Google:

pageTracker._trackEvent(category, action, opt_label, opt_value);

You just have to get the right arguments to that method, so you know what you're tracking. In the Google tutorial the example is predicated around sending the arguments to the _trackEvent method inline on an onclick event. Instead of doing that, which will create redundant script tags in our views, let's label our markup in such a way that we can grab a collection of trackable elements via JavaScript and submit them automatically, on a click (or other) event.

Read the rest of this post »

How to set up Cucumber and RSpec for a non-Rails project

Often times when we use Cucumber and RSpec (and by 'we' I refer to Rails developers, sorry for the narrow focus here), we use them from within a Rails environment.

Here are some instructions on how to set up Cucumber and RSpec for a multi-file Ruby project in a non-Rails environment. Note: if you're here because you want to make your own gem, stop reading and check out jeweler instead. Jeweler will take care of it all for you with one command:

jeweler name_of_gem --cucumber --rspec

If you are not making a gem and just want to bootstrap your own project, here are instructions -- with explanations of what is what. Some may be obvious, but I find that when we are used to using generators it can be easy to overlook what they generate and why. It's the old "the gui made me dumb" syndrome. Therefore, I choose to both err on the side of verbosity in this post and include a link to a bash script that does it for you, at the bottom.

Read the rest of this post »

Upgrading to Snow Leopard from Leopard

The process was pretty straightforward, though I went through it twice. I thought a quick write up might be helpful for someone else since there were a couple points that gave me pause.

I bought the Snow Leopard CD from Apple for $29. I decided to reformat my drive entirely rather than simply upgrade -- my mac is coming on three years old, why keep around all that cruft that's gathered over the years.

A few posts I read said you needed restart the computer while holding down "c" with the CD installed in order to reformat: I did not need to do this the first time (when I was still on Leopard). I did need to do this the second time, when I had already upgraded to Snow Leopard and wanted to repeat the process.

Read the rest of this post »

Setting up multiple branches from a github repository

This is a quick writeup about getting started with git branching via github.com. It covers creating a github repository then branching and pushing changes to it from multiple machines (work computer and a laptop).

While I have had a github account for a while, I hadn't explored branching until recently when I wanted the ability to branch our Rails app. Because the company where I work is redesigning and adding features to our application, we need the ability to maintain a master branch for the next few months that can be deployed to production on a moments notice but at the same time be able to do new development safely in a separate location (with its own deploy environment). This was enough to merit switching the app from subversion to git and figuring out how to do the basic branching that I would need to do.

Read the rest of this post »

Early Cucumber impressions

I've used Cucumber a few times before. For one, I coded the Mastermind puzzle in the RSpec book, adding a few extra features for my own game-playing edification. This was done initially in the service of an assignment and became a learning exercise.

Secondly, in my first venture into pair programming, we used Cucumber to drive out some features of a Rails project I am working on. I had already set up a few scenarios, but they were basically languishing until this pairing session. It was a pretty smooth session: not only were the features easy (essentially basic CRUD and view logic), but my partner was an expert at Cucumber, quickly pointing out a bunch of time-saving features like tags and inline tables to pass data. Learning from doing, with someone else, is so much more thorough than learning from a book. Also, since I'm a one-key aliasing fetishist, we set up aliases to run the features: u for all the features; and f for those tagged @focus. I love that. The session made Cucumber feel intuitive and easy to use.

But, still. It's a new framework and new to me and I'm still in the slog-through phase -- "getting" some of it and furrowing my brow at other parts. As well as having a bunch of opinions and an earful of opinions from other users on both sides of the fence. So I've decided to use it this week to drive out a rewrite of the authentication process on an existing site. I am also using it for as-yet unwritten features on a new app. So as I start the process, I thought I'd write down some of my existing impressions, and then track how they change (if they do) during the next week or so.

Read the rest of this post »

Pair Programming Firsts

I had a great time pair programming last weekend. It was the first time I had done this in a formal, our-computers-are-connected-and-we're-typing-at-the-same-time kind of way. I've programmed with people at the same computer, collaborated with people on different computers in a casual throw-ideas-back-and-forth kind of way, and done the passing-the-laptop-around thing, as well. But, a lot of my development time has been alone. For instance, I had a job for six years where I not only worked alone, but I telecommuted. During this time I lived in Brooklyn, Austin, Denver and Chicago (though not all at the same time). This was great and terrible at once: I had wonderful freedoms and benefits (cross-country travel and NY salary with TX income tax rates, to name a few), but I missed having other developers to learn from and play with.

Read the rest of this post »

Integrating the MIT / SIMILE timeline with Rails

This is a brief entry on how to populate the MIT / SIMILE timeline with dynamic data culled from a Rails application via a controller action that returns JSON. There is a plenty of existing solid information on the timeline itself, as well as a tutorial on integrating it with Rails and one focused on a simple html implementation. All these sources are clearly written and give basic usage tips. I recommend them and will not duplicate them here.

However, none of the sources demonstrated how to get dynamic data into the timeline via URL (they focused instead on creating the JSON / XML inline in the view via iterating through collections, or having it pre-existing as an external text file), I'm adding that information here in the hopes that someone else building in Rails finds it helpful.

Read the rest of this post »

Multiple File Upload using SWFUpload on Rails. Part II

This part of the tutorial covers getting the files that you select via your swfupload setup to upload into your Rails application. Part I covers the setup: getting the external libraries, markup, and JavaScript all in place. You can find that here. This tutorial assumes you are using attachment_fu. The Flash / Rails principles would be the same if you are using Paperclip, but the syntax for the upload itself would vary. However, since the main sticking point is the fact that Flash doesn't send the session_id to Rails when it posts data, thereby denying Rails access to current_user or a valid session, it is my hope that this article will be helpful regardless of which attachment plugin you are using.

Read the rest of this post »

If you're not pending, flunk.

I've inherited a Rails project from a big design firm. My job is to stabilize it in its new environment, maintain it, and eventually grow and improve it. Today was a bit traumatic: I deleted 47 files from the project. These were unit tests and functional tests that were either completely empty, like so:

class ModelTest < ActiveSupport::TestCase
# crickets
end

Or functionally empty, a result of leaving scaffolding in place, like so:

class OtherModelTest < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end

Forty Seven Files.

The problem here is not only that much of the app is not tested (nor documented by well-written specs), but the presence of the 47 passing test files gives a false sense of security to anyone eyeballing the project before they realize that the coverage is in name only. Certainly there were many (ok, some) files with active tests in them (I'd say I pulled a little more than half the files from the project) but it left me a bit shell-shocked to realize not only how little was covered, but that this cruft had been passed back to the client.

Read the rest of this post »

Acts As Followed

I released my first Rails plugin today. Acts_as_followed allows you to set up "followships" between users and other resources in your domain. It's fairly simple as these things go, but it was an instance where I felt that encapsulating the logic would make this pattern easier to implement across many projects -- and an opportunity to become more familiar with writing a plugin. Naming-wise, acts_as_followship is a little dry; I actually prefer acts_as_celebrity_stalker, but didn't feel like changing all the names. Perhaps in the future.

Read the rest of this post »