Skip to content

How to drive interest in Computer Science

Obviously we’ve been doing it wrong. Which would you rather read?

  

Check out the other alternative book covers. [via Dave Thomas's blog]

Integrating Timeline with Google Spreadsheets

You’ve just finished learning all about Timeline, you have a working example on your own website, and you’re dreading having to manage an XML or JSON eventsource file.

timeline

One good solution is Google Spreadsheets – you can manage your events in a standard spreadsheet, then export them in JSON format to Timeline.

google_docs_spreadsheet_values

Even better, Google Spreadsheets allows custom forms to be created to simplify the entry of events (you can even embed this form in your own webpage alongside Timeline).

Create a Google Spreadsheet

Go to Google Docs and select New -> Spreadsheet

Google Docs: New Spreadsheet

Add columns for each eventsource field you want to populate. I recommend the following:

  • start
  • end
  • duration
  • title
  • description
  • link
  • icon
  • category (not an actual eventsource field, it’ll be used for automatic styling)

It should look something like this:

Google Docs: Spreadsheet Columns

Publish your spreadsheet

Now you need to make your spreadsheet accessible to the public by publishing it. Go to the Share tab and select Share with the world:

google_docs_publish_spreadsheet

Make sure Let people view without signing in is selected, copy the provided link & click Save:

google_docs_publish_spreadsheet_dialog

The link should look something like this:

http://spreadsheets.google.com/ccc?key=pu1JqzPKsipKl2H7e9EmmRA

Get your spreadsheet data as a feed

To incorporate your spreadsheet data with Timeline, you’ll need to retrieve the feed as JSON formatted data. Thankfully the Google Docs API now supports this, use the key value from the previous step and build the feed URL:

http://spreadsheets.google.com/feeds/list/pu1JqzPKsipKl2H7e9EmmRA/od6/public/basic

More information: Google Spreadsheets Data API

It’s helpful to be able to view the data from the JSON feed, but in a format prettier than the actual raw feed data. Check out JSON Inspector (Firefox only) for a nice solution.

Integrate your spreadsheet data with Timeline

Ok, this is where it gets dirty. You’ll need to write some Javascript to process the JSON data from the spreadsheet feed & create event sources for Timeline to display. Here’s what I did: timeline.js

Breaking it down, these are the important excerpts from timeline.js:

At the end of tl_init(), after Timeline is configured, the feed is processed using a callback (tl_loadWorksheetJSON):

  // JSON feed for google spreadsheet, will load events internally
  var feedUrl = "http://spreadsheets.google.com/feeds/list/pu1JqzPKsipKl2H7e9EmmRA/od6/public/values";
  feedUrl += "?alt=json-in-script&callback=tl_loadWorksheetJSON";
 
  var scriptTag = document.createElement('script');
  scriptTag.src = feedUrl;
  document.body.appendChild(scriptTag);

Taking a look at tl_loadWorksheetJSON, you’ll see that it iterates through the rows from the spreadsheet feed, converting each row to an event based on the column name. The list of events is then added to Timeline:

  eventSource.addMany(timelinerEntries);

You’re welcome to reuse the code, it’s under a Creative Commons license.

Create a webform for your spreadsheet

Google Spreadsheets supports the creation of forms, this really simplifies your data entry and allows others to help enter data without exposing your spreadsheet. You can even embed the form into a website, allowing others to update the Timeline interactively.

google_docs_spreadsheet_form

Don’t edit the titles of the questions in the form – those are the column names, and if you edit the titles they’ll update the spreadsheet and break your spreadsheet/javascript parsing.

Credits

Many thanks to the blog entry here: http://kiyo.wordpress.com/2007/04/29/google-spreadsheet-json-to-timeline/ where I was able to see the original Javascript in action and everything I’d been reading about the Google Docs API and Timeline references all finally made sense.

Fix Apache on Mac OS X Leopard (10.5.x)

The Apache installed on Mac OS X Leopard (10.5.x) is initially configured extremely conservatively, at first glance it appears broken when you try to visit your user account directory and you get:

Apache 403 Forbidden

This is supposed to display the contents of /Users/jpeacock/Site To fix this you need to add a directory configuration for your user account directories.

Open a terminal and edit the Apache configuration file /etc/apache2/httpd.conf as root, adding the new directory configuration as shown below the existing comment block:

  #
  # Note that from this point forward you must specifically allow
  # particular features to be enabled - so if something's not working as
  # you might expect, make sure that you have specifically enabled it
  # below.
  #
 
  # open up permissions for user dirs
  <directory "/Users/*/Sites">
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      Allow from all
  </directory>

Save your changes, then restart Apache to reload the new configuration:

sudo /usr/sbin/apachectl restart

Now everything should be working:

Apache Success

RoR: acts_as_versioned

I’m jump-starting this new blog by copying over the one tech post I have from my personal site. Enjoy!

acts_as_versioned is pretty awesome..but it lacks documentation regarding how it interacts with optimistic locking.

If you have a column named lock_version, then ActiveRecord will use optimistic locking. (yay!) But it also means that acts_as_versioned will not automatically create the version column that it uses, nor will it use it even if you create it yourself. Instead, you need to tell it to use the lock_version column instead:

class Message < ActiveRecord::Base
    validates_uniqueness_of :register_name
 
    acts_as_versioned :version_column => :lock_version
end

Update

Some feedback from Eric Harris-Braun:

Thanks Jason, but be warned there are more issues too. Namely that the version numbers so created will not necessarily be sequential, especially if you have set some :if_changed conditions. This is because the lock_version will be updated even if you don’t make a change, but the version in the your_model_version won’t be saved.

Which is a very good point, only do this if your code can handle non-consecutive version numbers!