Posts tagged Rails

Jun 01, 2008

Presentation: an audience perspective

rails railsconf railsconf08 RailsConf RailsConf ‘08 Rails | comments

Baked NYC
 

This weekend I attended RailsConf. This was my first multi-day conference. It was a great experience that I’m sure to repeat over the coming years. Met a lot of great Rails developers, working on interesting and disparate projects. Met a good number of Harvest users who spoke to me using words like “enjoy,” “love,” and, most surprisingly, “famous.” Even met people doing Important Stuff (tm) who didn’t particularly care to hear about my story.

Watching speaker after speaker is terribly motivating. Soon the realization that this blog has pretty well been dormant in 2008 came to mind. The realization that I’ve not prepared a proper presentation…ever…entered my thoughts. As I sat in sessions, I found myself, with a wide sliver of irony, writing down presentation techniques that pleased and bothered me.

Humor

You have to include humor in your talk. Most presenters are aware of this. However, many presenters front-load their humor. It’s difficult to lace the entire flow of information with engaging humor, but this is one of the most outstanding ways to provide a positive experience for the audience - one that causes them to pursue the topic after the fact.

In the case of technical talks, one must be careful not to make the humor the focus. But generally speaking, presenters tend to err on the opposite end of the spectrum.

A consistent metaphor

Several sessions included an interesting, nerdy metaphor. Don’t meticulously introduce the Star Wars comparison and then drop it for the rest of the presentation. Lace that damn B-wing throughout the slides.

Know your environment

Your super-sexy, light-on-dark TextMate theme is most likely going to cause the audience fits. They will yell at you, especially if it is the cranky third day.

Greater than 15 lines of code is unlikely to be readable by the audience. Know how to zoom or bigify your code or think of other creative ways around the problem.

Slide titles should be mid-screen or higher. Cool MTV banner titles along the bottom of the screen are likely difficult for most of the audience to read, save for the most ideal conference situations.

Unless the presentation calls for frequent interaction with your computer, stand up. Give yourself the air of authority and the confidence that you are qualified to share information with the group. Don’t pace, and get yourself some sleep the day before.

Timing

Don’t hope your talk will fit into the given time slot, know it will fit. Err on the side of too short, please. Don’t promise time for questions unless you’re certain you can deliver. Plan for interruptions (technical issues, in-presentation questions, rambling, etc). You will be refreshing and set yourself apart if you deliver a well-tuned, concise message.

Tell them what they want to hear

Or Pander to the crowd.

Or Tell them what they already know, in a new way.

Or Inspire them to pursue what you know they want to pursue.

Littering your presentation with known community mores will give you at least a knee-jerk positive reaction. The audience wants to laugh, nod, clap, and feel assured in their own choices. Be a catalyst.

Ideally your whole presentation shouldn’t be comprised of such a message. But if you don’t have anything nice to say, reflecting your audience is probably your safest option.

If all else fails, blow their minds

Announce a product, process, tuning, enhancement, iteration or whatever that carries along with it jaw-dropping statistics. The nice thing about this is you don’t have to necessarily give the product in question to anyone to prove your statements - at least not right away. Plan on delivering something within a few months, and deliver something within 50% of the improvements originally touted, or you will be blasted.

This talk can be combined with telling people what they want to hear to make a powerful concoction. It is workable to describe utopian worlds where downfalls are leveled with a Sim-City-like ease. Again, any improvements will be welcomed, and the army of supporters from announcement-time will do all of you defense for you when the rubber meets the road.

It’s not about you

Indeed, some speakers enjoy well-attended presentations due to their niche fame. Still, it is not about them. It is about what the speaker can do for me, the audience member. How do you help me to relate to you? How do you help me fit your perhaps only tangentially applicable message into my situation? How can you generalize the information you have for public consumption? How can you make it all about me?


May 28, 2008

RailsConf '08

rails railsconf railsconf08 RailsConf RailsConf '08 | comments

Just wanted to drop a note in my blog, here, that I will be attending RailsConf from Friday through Sunday. If any lurkers out there are gonna be in attendance, do drop me a note. Let’s meet each other!

If you want to stay up-to-date on any Barry-meets-RailsConf information, please check me out on Twitter.


Mar 31, 2008

A Rails way to track additional schema info

Rails ActiveRecord | comments

Baked NYC
 
Photo by rachel is ...

Right now at Harvest we are baking a few pans of Twitter integration. We’re not sure if they’ll turn out moist and delicious, but hopefully they stop short of dry and forgettable. It’s been a fun, and somewhat frustrating, process getting this feature cooking.

The key interaction Harvest is using is Twitter’s direct message. Send Harvest a message and we’ll pick it up and do something with it. Through the Twitter API, one can grab all direct messages since a certain direct_message.id. In this case, direct_message.id is used as a chronology identifier - the larger the id, the newer the message.

In order to go out and grab a batch of messages, the previous max direct_message.id needed to be tracked somewhere. To me, this felt similar to Rails’ schema_info table - direct_message_info we’ll call it. So with all of those Rails opinions, how do you set up such a schema-tracking table? First, you migrate:

class CreateDirectMessageInfo < ActiveRecord::Migration
  def self.up
    create_table :direct_message_info, :id => false do |t|
      t.column :last_id, :integer
    end
    ActiveRecord::Base.connection.insert("INSERT INTO direct_message_info VALUES(28700000)")
  end

  def self.down
    drop_table :twitter_direct_message_info
  end
end

This migration is fairly simple. When creating the table, we specify that there is no need for the Rails-default id column. Also, insert an initial starting value. I suggest playing with the API and selecting a value reasonably close to the latest id numbers for Twitter’s direct messages.

Then, throw your ActiveRecord model out the window for models/direct_message_info.rb:

class DirectMessageInfo
  
  class << self
    def get_most_recent_id
      ActiveRecord::Base.connection.select_one("SELECT last_id FROM direct_message_info")["last_id"].to_i
    end
    
    def set_recent_id(last_id)
      ActiveRecord::Base.connection.update("UPDATE direct_message_info SET last_id = #{last_id}") if last_id
    end
  end
  
end

Two pretty simple class methods for getting and setting your new schema info value.


Mar 29, 2008

ActiveResource HTTP basic auth with email address

ActiveResource Rails authorization | comments

As I’ve started to play around here and there with ActiveResource, I’ve noticed lots of complaints about how ActiveResource’s implementation of HTTP basic auth leaves a lot to be desired. Specifically with regard to its lack of support for email addresses as usernames. This won’t work:

class Expense < ActiveResource::Base
  self.site = "https://barry@bjhess.com:password@website.com"
end

Turns out it’s fairly simple to authorize via email address in ActiveResource. Just send the header:

class Expense < ActiveResource::Base
  self.site = "https://website.com"
  @headers  = { 'Authorization' => "Basic (#{Base64.encode64('barry@bjhess.com:password').strip})" }
end

Feb 28, 2008

Move server configuration files into your repository

capistrano rails ruby scm svn Ruby Rails SVN SCM Capistrano | comments

Dung repository
 
Photo by Chambo25

Are you a programmer? Do you hate any process that involves SSH’ing into a server and editing files directly in production? Would you like to get rid of this non-source controlled hackery? Damn right you would!

If you’re deploying an application to a server, get those app-specific configuration files in your source control system! I happen to be a Ruby on Rails programmer, so the two files I’m looking to control are the Apache and Mongrel configuration files. Here are two sample locations:

Maruku could not parse this XML/HTML: 
<pre>/usr/local/apache2/conf/apps/appname.conf
/etc/mongrel_cluster/appname.yml

Meat

Via terminal, browse into your local Rails app directory. Then, create a couple directories to store this configuration:

mkdir ./config/apache
mkdir ./config/mongrel

Then copy the configuration files you have sitting on your server into the local directory (I’m using SCP and assuming you know the rest). Again, locally:

scp bjhess@server_or_ip:/usr/local/apache2/conf/apps/appname.conf ./config/apache/
scp bjhess@server_or_ip:/etc/mongrel_cluster/appname.yml ./config/mongrel/

Potatoes

Now you’re all ready to commit these configuration repositories to your SVN/git/mercurial repository. But wait, you also want to actually use these versions of the configuration files in production, no? Well, let’s do it. Rename the original configuration files on the remote server:

mv /usr/local/apache2/conf/apps/appname.conf /usr/local/apache2/conf/apps/appname.conf.bak
mv /etc/mongrel_cluster/appname.yml /etc/mongrel_cluster/appname.yml.bak

Then simply update your deployment script to create symlinks from the expected configuration file location to the new location. I’m using Capistrano (version OLD), so adjust accordingly:

desc "Tasks to complete after code update"
task :after_update_code do
  #            LINK TARGET                                   LINK SOURCE
  run "ln -nfs #{current_release}/config/apache/appname.conf /usr/local/apache2/conf/apps/appname.conf"
  run "ln -nfs #{current_release}/config/mongrel/appname.yml /etc/mongrel_cluster/appname.yml"
end

Conclusion

This is great, isn’t it? The programmer in you loves having limitless history of configuration changes, not to mention the ability to use whatever local editor you choose. Wonderful day!

But what about the whole-server configuration files? Unless you commit to one app per server, I don’t think base Apache config files or server-level logrotate config files should be in a specific app’s repository. Perhaps a new repository could be setup to deal with these files? I imagine Capistrano could even be used for the bare-bones deployment.

Or maybe just backing up these general files is enough to keep your mind at ease. Just be sure to think about it. That’ll put you one step ahead of the rest

Update: Be sure to deal with symlinks upon rollbacks, something I just got burnt by:

desc "Tasks to complete after code rollback"
task :after_rollback do
  run "ln -nfs #{previous_release}/config/apache/appname.conf /usr/local/apache2/conf/apps/appname.conf"
end

Jan 02, 2008

Integrating Rails and WordPress

WordPress Ruby on Rails | comments

Mad code rewrite
 
Photo by zhartley

Scrawlers, an online writing workshop I helped build, includes a blog. Rather than build the blog from scratch, or even use a Rails solution, I chose to stick with the familiarity of WordPress. I’d read enough about Rails-lovers switching to a Rails-based engine and back to WordPress that I wasn’t even going to bother leaving The WP.

Scrawlers sits on an Ubuntu server with Apache and Mongrel running. Unfortunately I have little to no server admin skill, and that includes Apache mod_rewrite. Ilya Grigorik posted an excellent HOWTO on integrating WordPress and Rails. Unfortunately it didn’t quite work for Scrawlers, and I put off figuring out my special mod_rewrite secret sauce for quite a while.

Eventually I figured out what I needed beyond Ilya’s original technique and posted it in the comments section of his blog. The completist in me needs to post the solution on my blog as well. What follows is pretty much word-for-word from Ilya’s comment section. Be sure to read his post. It’s an easier solution, if it works for you, and it provides background information for what follows.

I’m dealing with Apache configuration that I do not understand. So it turns out I have AllowOverride disabled on my server, even explicitly in my app-specific Apache configuration for the public directory. This is why .htaccess wasn’t working for me.

After reading up a bit on .htaccess/AllowOverride, I decided there was really no reason to turn it on and eat the overhead involved. Instead I made a Directory directive in my app-specific config file and placed it before my initial WordPress redirects.

Once these things were in place, the one-line RewriteRule worked in every instance except one. The URL http://www.scrawlers.com/blog (or /blog/) failed with an access denied error. Looking at the rules it sure appeared like it should work. In the end I needed to include a couple rules specific to these situations. Here is, essentially, the bit of configuration code I needed to make my blog start working naturally: