Stay Hungry. Stay Foolish.

In 2005 Steve Jobs gave a commencement address at Stanford that ended with these words. Reading it for the first time on the morning after his passing brought me to tears, and led me to a few realizations. One is that I often keep thought to myself that I should share even though some will be offended. Those that are offended likely have the most to gain from hearing another point of view.

So let’s begin with this: I hate my largest current project.

The problem isn’t that it’s difficult, or that my client is a jerk. In fact my client is great, and the modifications I’m making are relatively simple, or at least should be. The real issue is I was handed an existing codebase that was largely written without any consideration given to maintainability. Parts of it are convoluted and fragile, although less so as I gradually clean it up.

The reason I hate it is I’m wasting its potential as a training ground. For all the reasons I find it tedious at times it’s the perfect environment to teach a new developer why maintainability is important. The long term value of a codebase rests on whether future developers understand the function and intent of each part so it can be adapted to ever changing business demands without undue pain and suffering.

Because some day soon you’ll be gone.

Posted in Random Thoughts | Leave a comment

Ruby on Rails on Windows 7 using Cygwin

If you’re already familiar with the terminal window environment on Mac OS or Linux, here is how to setup a similar environment on Windows 7 using Cygwin.

Install Cygwin

  • Download setup.exe from from the Cygwin install page. Make note of where you save it. In fact, life will be easier if you copy it to the desktop.
  • Choose ‘Install from Internet’ on 2nd page of installer dialog.
  • Install for ‘All Users’ and use the default ‘Root Directory’.
  • For ‘Local Package Directory’, you may take the default, but I prefer Downloads over Desktop.
  • Pick an appropriate mirror. No guidance is given on mirror location except some mirrors use country specific domain names. If unsure, US and Canadian users should pick sites ending with ‘com’, ‘net’, ‘org’, or ‘ca’.
  • Use the search dialog to find and add the following packages. This is easier if you use the View button on the right to switch the display mode to full. Use the leftmost column of the display to toggle. Note: Some packages have similar names. Select exactly these packages:
    • git
    • git completion
    • vim
    • rxvt
    • ruby
    • wget
    • patch
    • make
    • gcc
    • libsqlite3-devel
    • libxml2-devel
    • libxslt-devel
  • Allow Cygwin to create a Desktop icon on completion.

Configure Cygwin

  • For reasons that aren’t clear to me, I needed to do the following from a Windows command prompt. Note the prompts are included for clarity.
    C:\>cd \cygwin\bin
    C:\cygwin\bin>ash
    $ /bin/rebaseall
    $ exit
    C:\cygwin\bin>exit
    
  • Right click the Cygwin shortcut and choose edit from the menu. Change the contents to match:
    @echo off
    C:\cygwin\bin\rxvt -sr -sl 1500 -e C:\cygwin\bin\bash.exe --login -i
  • Double click the Cygwin shortcut. It should launch a bash shell which can be maximized to fill the screen. The current directory should be your Cygwin home directory. Most commands after this point should be run from the bash shell. NOTE: The paste function in this window is Shift-LeftMouseClick.
  • Use `vi .vimrc` to edit your vim configuration. Here’s what I use:
    set showcmd
    set showmatch
    set ignorecase
    set smartcase
    set incsearch
    set hidden
    set autoindent
    set backup
    set ruler
    set expandtab
    set tabstop=2
    set shiftwidth=2
    filetype plugin indent on
    set spellfile=~/.vim/spellfile.add
    set spelllang=en_us
    syntax on
  • Use `vi .bashrc` to examine your bash config and uncomment whatever aliases you typically use.
  • Use pwd to check your home dir. If the name contains a space, you may wish to rename it.
    cd /home
    mv <oldname> <newname>
    vi /etc/passwd

    The last line in /etc/passwd should be your account, likely with 3 occurrences of your name. Change the first and last to match the new name from the `mv` command above. I haven’t tested what happens if your change the middle one but I bet it’s something bad. After saving your changes, exit from all terminal pages so the new setting can take effect.

Install Rubygems

wget http://rubyforge.org/frs/download.php/74445/rubygems-1.6.2.tgz
tar -xzf rubygems-1.6.2.tgz
cd rubygems-1.6.2
ruby setup.rb

Install Rails

  • gem install rails

That should be it! I’ll continue to update as I learn better ways to do this.

Posted in Ruby on Rails | Leave a comment

RailsConf 2011 QR Collage

RailsConf 2011 officially ended Thursday, and it was awesome. Knowledge, ideas, and inspiration were in abundance from beginning to end. I left with a lengthy list of tools and techniques to research.

I also flew out Friday morning on zero sleep after a night of coding and fighting Twitter API limits. The immediate result was a handful of command line ruby scripts and a 700KB JPEG. The scripts will become my first 2 gems Real Soon Now™, but the image is ready to share.

Introducing the unofficial RailsConf 2011 QR collage, composed of Twitter avatars from the #railsconf stream. I hope you like it.

Posted in Ruby on Rails | Tagged , | Leave a comment

Opening Keynote

#RailsConf starts for real with Chad Fowler from Living Social and Ben Scofield from Heroku at the podium. They start with a few questions. They discover there are many new attendees, and a few all the way back from 2006. Also, many were sent by their companies. Yay!

A few annoucements… BohConf is said to be the un-conference to end all un-conferences. RSVP for the Change.org happy hour tonight. Later on attend Ruby Heroes awards and Bird of a Feather (BOF) sessions.

Video presentation for DonorsChoose.org, whose mission is to change the world for a child. Every badge holder includes a $25 gift card to get started donating. Not sure how that works yet…

Chad and Ben introduce David Heinemeier Hansson (DHH), creator of Rails. He’ll focus on features new to Rails 3.1, in particular Asset Pipeline.

He was unhappy with the many javascript files used in BaseCamp. They’re useful, but were a javascript junk drawer that needed to be managed better. His rule of thumb “> 13 = :-(“! javascript_include_tag solved the problem of loading the files quickly for the user, but didn’t improve management of the codebase.

The solution in Ruby on Rails 3.1 is to add app/assets, lib/assets, and vendor/assets empty folder. Each contains folders for images, stylesheets, and javascripts. This structure creates a place for everything.

Bundler will assist in management of assets from gems and plugins. For example, the jquery-rails gem version will be managed in Gemfile. Oh BTW, jquery-rails is the new default for Rails, but switching back to Prototype is as easy as saying gem ‘prototype-rails’. Things such as Blueprint CSS could be bundled up and manged this way as well. No mention of if there’s a gem yet.

The change in javascript and the inclusion of CoffeeScript has generated lengthy and passionate discussion on GitHub. DHH recommends reading the thread, but also encourages participants to “chill the fuck out”.

CoffeeScript is a language that compiles into javascript, with somewhat less code written.

Sass is also included in Rails 3.1. It’s a pre-processor for stylesheets, and was created alongside HAML, which DHH has not embraced. Sass looks much like CSS, but includes variable and nesting. It can be combined with erb to use Ruby in Sass to write CSS. Nice!

DHH emphasizes that Rails will continue to include defaults. You don’t have to stay with the defaults! Sass and CoffeeScript are included in the Gemfile, but not in the Rails gem dependencies.

There is a new rake task called assets:precompile to help performance. Compiled assets filenames include an MD5 hash instead of tagging a request with a timestamp. The is less disruptive to deploy and works better with caching. JS and CSS compression now happen automatically.

Rails 3.1 Release Candidate will appear THIS WEEK during RailsConf.

DHH moved quickly through a few other topics.

BaseCamp mobile is now using Cinco. Backend uses Rails as an API. Frontend uses JavaScript with it’s own MVC framework. DHH fears this won’t promote good integration between frontend and backend long term. More to the point, he feels it promotes separate teams. node.js is another possibility, but not attractive to DHH.

Pjax is used to render new content in your page frame without re-rendering the layout, resulting in a speed increase. DHH is already using it, and expects to include it in Rails at some point.

Backbone.js is used for javascript heavy apps to create MVC-ish data structures in the browser and coordinate well with your existing app.

That’s it.

Posted in Ruby on Rails | Tagged | Leave a comment

Tutorial Day Recap

#RailsConf tutorial day was a great success. I’m say it with confidence because unlike my last RailsConf in 2008 almost everyone in on Twitter, and no problem goes unreported. So except for minor wi-fi issues and a few comments on chilly temps, the day went off without a hitch. I’m sure the organizers were scrambling behind the scenes, so good job!

The evening events didn’t disappoint. Ignite RailsConf didn’t get rolling until 7pm, but once the flow started it was one great talk after another. Some talks were technical, some addressed life balance, but the recurring theme was community. We have an amazing group of people who make the Ruby on Rails community what is it today.

After Ignite wrapped up there ensued a mad dash for taxi cabs, as Max’s Taphouse held the promise of an open bar on Engine Yard’s dime. After overfilling the upstairs areas reserved for us, we spread downstairs and took over the entire establishment. I didn’t hear the damage on the tab, but all who attended owe a big thanks to Engine Yard!

As Day 1 begins I’m sure there are some interesting stories to hear from Max’s. There could also be stories of last night from the stage this morning, as rumor has it that DHH’s evening didn’t go entirely according to plan.

The conference begins this morning at 9am. If you aren’t here, you can view the video stream, and of course I’ll be posting updates as well.

Posted in Ruby on Rails | Tagged | Leave a comment

Rails Best Practices

Notes from #RailsConf tutorial by Gregg Pollack from Envy Labs. Great presentation on a sometimes contentious subject, with an easy to follow slide deck. Useful advice for journeyman and above coders, and some great ‘discussion starters’ as well.

Made excellent use of the CodeSchool Ruby Best Practices course, which was free to attendees of the talk. Pretty slick stuff. Worth checking out CodeSchool even if this isn’t the course for you.

Note that many of the techniques presented use new Rails 3 goodness and won’t apply in older version.

An overview, with a few observations:

  • Use fat controller/skinny model to maintain good linkage between model data and methods performed on it.
  • Use named scope to keep complex queries out of controller code, including examples using default_scope, unscoped, and why/when you need to use lambda.
  • Ruby 1.9 block can include defaults, e.g.
    scope :trending, lambda { |num = nil| where('started_trending > ?', 1.day.ago) }
  • Several ways to reduce code duplication for find methods in RESTful controllers. Slides reasoned via circular logic. Needed to use KISS method here.
  • Use accepts_nested_attributes_for to simplify controller logic on nested forms.
  • Example of using a non-Rails class capable of taking the place of an ActiveRecord model for items such as a contact form.
  • Use presenter classes to clean up controllers that must do many different find, by making each find into a presenter method and instantiating the presenter using the ‘master’ object the controller is acting on.
  • Use ActiveSupport::Memoizable instead of things like:
    @cache ||= Model.find_by_foo('bar')
  • Be smart about indexing. Avoid adding unneeded indexes. In fact, I say don’t add them without real-world usage pattern to prove you need it.
  • Use attr_protected, or better yet attr_accessible
  • Let the database handle default value by putting them in your migrations.
  • Gave examples good use of callbacks and more concise validations.
  • Talked about db/seed.rb. He’s a fan. I’m not so sure.
  • Avoid using find in a loop. Use :includes instead.
  • Use counter_cache when needed for performance.
  • Use #find_each to perform long-running tasks in batches of 1000.
  • Override #to_s where appropriate instead of something like #display_name.
  • Getting the queries out of your views and into your controllers.
  • Using helpers to generate proper html in a dry fashion.
  • Good examples of using partials cleanly.
  • Really interesting stuff on use of yield and content_for in layouts and views.

Need to emphasize again the slide deck was outstanding. It doesn’t contain the hilarious sound effects, but well worth reviewing.

Posted in Ruby on Rails | Tagged | 2 Comments

HTML5 – Beyond the Buzzwords

Notes from tutorial by Mike Subelsky. Very hands on as we all work through his examples.

Browsers are more capable than we’re use to them being. Features that used to require external dependencies now can be done easily right in the html. Purpose of tutorial is to explore features many of us are not familiar with and expand our imagination of what’s possible.

Implementation of HTML5 features varies among browsers. The appropriateness of a given feature depends on the scope of your audience. Resources such as Polyfills help you to fallback gracefully.

The Modernizr library performs feature detection and edits the class attribute of the <html> element, allowing you to style your page based on browser capabilities.

Canvas exposes a rich set of drawing tools similar to rmagick. Demonstrated using 4 exercises including animation. Live example of use is Biolab Disaster, a game with Flash-like action but coded in javascript/HTML5.

WebSocket allows open connections for message send/receive in real time. Multi-user gameplay example was used to demonstrate. Firefox and Opera have disabled support for WebSocket due to protocol security concerns.

Embedded Media allow sound and video retrieval with or without immediate display of control. Playback can be initiated as needed.

Geolocation uses external services to make the approximate location of the user available. Requires an affirmative user action due to privacy concerns.

Web Workers allow background tasks to chug away while the UI continues to function normally. Results of a task can take effect when complete.

Offline Apps techniques use an app manifest to inform the browser of all the resources needed. On reload the manifest is checked and no resources are downloaded if the manifest is unchanged. This technique can be used to make an HTML5 app “installable” on a smart phone.

USEFUL URLs

Posted in Ruby on Rails | Tagged , | Leave a comment

Nginx SSL config for PCI Compliance

Our current preferred setup for Ruby on Rails hosting is Phusion Passenger aka mod_rails on the Nginx web server. However, the default configuration of Nginx SSL isn’t PCI compliant. To pass a PCI certification scan requires a couple simple changes to disallow insecure protocols and ciphers.

Default Nginx SSL settings:

ssl                       on;
ssl_certificate           cert.pem;
ssl_certificate_key       cert.key;
ssl_session_timeout       5m;
ssl_protocols             SSLv2 SSLv3 TLSv1;
ssl_ciphers               ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;

Change ssl_protocols and ssl_ciphers like so:

ssl_protocols             SSLv3 TLSv1;
ssl_ciphers               HIGH:!ADH:!EXPORT56;

Seriously, that’s it! But if you’re interest in understanding exactly what these settings mean, see the OpenSSL docs.

Posted in Ruby on Rails | Tagged , , , | Leave a comment

RailsConf 2011 Preview

Monday marks the beginning of RailsConf 2011 in Baltimore. It’s the largest conference of the year for Ruby on Rails developers, with projected attendance of 1200+.

RailsConf 2011

Co-presented by O’Reilly and Ruby Central, the conference features:

  • Four entire days dedicated to Ruby on Rails
  • A program designed around all levels of expertise from beginner to intermediate to advanced
  • The most innovative and successful Rails experts and companies showcased onstage
  • A forum for people seeking to collaborate and solve similar problems
  • A gathering place for the worldwide Rails community, including an important network of experts, alpha geeks, and innovators
  • Hands-on and in-depth guides for learning how to best employ Rails in a variety of situations and tackle common problems
  • Ample opportunities for all participants to connect, contribute, and collaborate throughout the event
  • The chance to hear the latest updates, get information, and meet some of the the Rails core development team

Highlights

Monday

The daytime is primarily devoted to training, with morning and afternoon sessions for novice and experienced developers alike. It also marks the beginning of the parallel BohConf, the official unconference of RailsConf 2011.

At night the fireworks start with Ignite RailsConf. 15 speakers, 5 minutes and 20 slides each, with an after-party sponsored by EngineYard.

Tuesday

The conference begins for real. Morning keynote by David Heinemeier Hansson aka DHH (37 Signals). Evening keynote by Eric Ries (Lessons Learned). The schedule runs from 9am-8pm, followed by Birds of a Feather (BoF) sessions until 10pm.

Social events include the Change.org Happy Hour (free tickets), and the @BlueBox @NewRelic @PivotalLabs gathering at Alewife 9-11pm.

Wednesday

Another solid 9am-8pm day. Morning keynotes by Nic Williams (EngineYard) and Aaron Patterson (AT&T Interactive). Evening plenary with Guy Steele (Oracle Labs) and Richard Gabriel (IBM Research).

The party of the evening is possibly the GitHub drinkup, 8:30pm at Pratt Street Ale House across the street from the convention center.

Thursday

The final day of the conference, from 9am-4pm. Morning plenaries with Aaron Batalion (LivingSocial), Corey Haines (Corey Haines), and Dan Melton (Code for America). Closing keynotes by Glenn Vanderburg (LivingSocial) and Chad Dickerson (Etsy). Today is also the last day of BohConf.

Full Schedule

These are only the highlights, so here’s the full schedule. RailsConf 2011 keeps 5 rooms busy in every time slot, and there are opportunities to learn in every one. Highly recommended if you’re a Ruby on Rails developer.

RailsConf 2011 Live Blog

I’ll be posting frequently throughout the 4 days of RailsConf. Subscribe via Facebook, RSS, or Twitter to hear the latest revelations from DHH and find out which booths give away the coolest swag!

Posted in Ruby on Rails | Tagged | Leave a comment

Agile Management Tip – Stop Hiring Employees

Agile Management illustrated by stick figure on pommel horseAgile management produces fast flexible responses to opportunities and threats. Your company’s structure and culture determine your flexibility. Increase your agility to improve your chances of survival.

Agile Management

Friday’s Techpoint event focused on “Building an Agile Company”. Speaking were Daniel DeHayes, Professor Emeritus of Business Administration at the Kelley School of Business at Indiana University, and Delphia Croft, the Managing Principal of Solution Revolution Consulting. Their talk was both enlightening and thought provoking, and was followed by a lively Q&A session.

Summary: In order to build companies capable of bold, quick, aggressive moves, leadership must foster a culture that embraces change. Hire folks who thrive without rigid structure, and push decision making to the front lines. Resist the temptation to bulk up your payroll, instead using 1099′s project by project. Avoid capital investment in rapidly changing categories; rent/lease/outsource what you need today instead. Keep your processes simple, because speed wins!

Agility Killers

  • Hierarchical decision making will kill you. Witness the paralysis of Tepco while handling the crisis at their Fukushima nuclear power plant.
  • Reliance on long term strategic planning systems rob you of your ability to capitalize on an emerging opportunity.
  • Don’t let budgets become a goal rather than a means to an end. Use rolling projections instead.
  • Detailed job descriptions put your team members in a box.

Steps to take NOW

  • Be a fast adopter.
  • Be intentional all the time — proactive, committed, audacious, focused.
  • Use real-time data in making decisions.
  • Reduce complexity in your processes.
  • Use 1099′s instead of W2′s where possible.
    • Pay for output, not hours.
    • Focus on mastery rather than warm bodies.
    • Move from managing people to managing contracts.
  • Be very wary about taking on debt or growing ‘at any cost’.

Agile Management is about winning tomorrow, not blindly repeating what worked yesterday.

Posted in Process Improvement | Tagged , | Leave a comment