From Nuby on Rails, 1 year ago,
0 comments
An interview at RubyInside recently suggested that Rails developers who want to be hired should maintain a Rails-related blog.
I’ll add to this and say that every beginning Rails developer should write their own blog software. It’s a great learning experience and you can try things that aren’t possible with just an app running on localhost. It’s also a great environment for learning without the pressure of a mission-critical app. When you’re working for a client and deploying an important application, you’ll have made all the beginner mistakes on your own time (hopefully).
This blog started on shared hosting with Typo software. I later switched to a VPS with 128 MB RAM and currently run on a RailsMachine VPS with 512 MB RAM.
In the process, I’ve learned a lot about
Running Rails on a shared host (don’t do it!) Deployment and automation with Capistrano (do it!) Unix server administration Process monitoring and uptime Rails development Merb development Application design and asynchronous processes Optimizing for speed Reporting and log parsingIf you need a blog for your business or for a client, I would definitely check out Mephisto, Radiant, or Simplelog. But if you’re thinking about starting a blog for yourself, you should write your own from scratch. It only requires 2 controllers (Articles and Comments) and apparently some guy even filmed a screencast showing you how to start one in only 15 minutes.
Every developer’s favorite topic: PerformanceA Wordpress lecture mentioned the fact that a standard Wordpress install on a given server only achieves about 8 requests per second. The way they get it up to 300 req/sec is not by profiling loops and optimizing method calls, but by caching as much as possible.
The biggest speed benefit you can get is from page caching. However, that entails writing a bunch of code to expire the cached pages when articles are edited, comments are made, or templates are changed.
Expiration by Key Name with MemcachedRecently, I decided to try out some caching strategies I had read about1. The idea is to use memcached to store objects with keys that will automatically expire when the item changes.
For example, this page you are reading needs to expire if the article is edited or if new non-SPAM comments are posted.

So I’m caching the entire rendered page in memcached, with the article’s ID, timestamp, and number of comments in the key. In memory, that’s something like
"Articles:show:11097:1197661574:11"

This way, there’s no need to explicitly delete cached items. The application will ask for a new page when the data changes, and if memcached is full it will clear out the older, unused items.

NOTE: You’ll need to have a memcached server running. I wrote a previous article about how to do that.
I’m using this technique both on my blog and at PeepCode.
First, I’ve put most of the key logic into the Article model.
class Article < ActiveRecord::Base
def cache_key
"#{self.class.name}:#{id}:#{updated_at.to_i}:#{ham_comments.length}"
end
For this blog (using Merb), the controller is pretty simple since render returns the HTML that was generated.
# Articles controller
def show
@article = Article.find params[:id]
Cache.get("Articles:show:#{@article.cache_key}", 1.hour) do
render
end
end
I’ve also wrapped it in some extra logic that doesn’t use the cached version if there is a flash message to display.
For PeepCode (using Rails), I wrote a render_cached method in the ApplicationController that handles more of this automatically. It takes a key, an expiration time, and a Hash of options that will be sent to the Rails render method.
Here’s how it’s called:
render_cached(@article.cache_key, 1.hour, :action => "show")
The render_cached method does several things:
It builds a key that includes the controller name, action name, and format being rendered. This ensures that HTML is cached separately from XML. It uses the render_to_string method to generate the template as a string, or render :text to send back the cached version. If checks a should_cache? method to see if caching should happen. This is different from Rails’ internal development/production caching. Instead, it’s a controller-specific method that can turn off caching in some circumstances. By default, I use no caching if someone is logged in or if there is a flash message to display.def render_cached(key, expiration, render_options)
return unless perform_caching
if should_cache?
combined_key = [
'controller',
controller_name,
action_name,
params[:format] || 'html',
key
].join(':')
output = Cache.get(combined_key, expiration) do
render_to_string render_options
end
render :text => output
else
render render_options
end
end
The should_cache? method looks like this:
def should_cache? (current_user.nil? && current_order.nil? && flash[:notice].blank?) endSummary
Overall, this has worked quite well. The most frequently accessed pages turn out to be pretty responsive. The cached versions perform much faster and there’s not a single line of cache-expiring code.
Raw performance numbers from pl_analyze (requests per second, controller and action names omitted):

I’ve got several authors working on some great PeepCode PDF books. They will be published in the next few months.
Currently, many people have found Ryan Daigle’s Rails2 PDF to be useful for getting up to speed with Rails 2.0.1. It’s even available in Español and will soon be available in a few other languages, too.
I refilmed the Capistrano 2 screencast from scratch. It’s mostly the same content as the first Capistrano screencast, but is up to date for the new namespaces, callbacks, and other features of Capistrano 2.
The Rails from Scratch series has been updated with code and notes about Rails 2.0.1 compatibility. It’s a free update if you purchased it in the past.
Finally, I published a screencast on Git a while ago. I’m using Git wherever possible and really love the speed, easy branching, and flexibility in areas that were frustrating in Subversion.
Resources1 Articles about auto-expiring memcached keys:
The secret to memcached Clever caching Caching makes your brain explode Intelligent fragment cache PeepCode Screencasts – Learn Ruby on Rails and Javascript! Hour-long screencasts for $9.
From Nuby on Rails, 1 year ago,
0 comments
RubyConf 2007 was even better than last year. Unfortunately, Adam Keys couldn’t make it, so I brought a larger-than-life sized poster of him (via Wallhogs).
Several Rubyists were game to be photographed in their favorite death metal pose.










And finally, Wilson Bilkovich with the Kama Sutra of death metal poses.





From Nuby on Rails, 1 year ago,
0 comments
Last week I made a spontaneous trip to the Future of Web Apps conference in London. I wasn’t planning to go, but I’m glad I did…there were many great talks and I learned a lot about the greater web development community, especially people’s impressions about Ruby on Rails.
It had the highest ratio of quality talks of any conference I’ve been to. Here are my notes from a few of the most useful talks.
Steve Souders, Yahoo, High Performance Web SitesYahoo’s performance expert (and recent author) talked about performance. Not a word was said about MySQL optimization or profiling your server-side code…it was all about increasing the subjective page load on the client.
As server-side web developers, we would like to think that performance is all about making SQL queries more efficient and making our Ruby code faster. The theory presented was that a user’s impression of the speed of a site depends much more on things like compressed content, placement of script include tags, and the geographic location of the content being served. He also mentioned using a content delivery network, but this is quite expensive for a small site (I’ve heard that an introductory account with Akamai starts at US$10k per month).
Over the past year or two, I’ve used some of these techniques on this blog and other sites. Rails-specific resources:
Nginx config file with gzip compression turned on Scott Becker’s Asset Packager (a subset of this functionality will be available in Rails 2.0). Ezra Zygmuntowicz’s balanced assets (something similar will be in Rails 2.0).The YSlow plugin for FireBug can also help analyze a site for the issues mentioned.
Matt Mullenweg, WordpressThe author of Wordpress talked about scaling their blog-hosting service to the point of being one of the top 25 most visited sites on the net.
Notable points:
They use software load balancers exclusively. Pound and Whackamole (I couldn’t find a url), Varnish for caching assets. The also use the Spread messaging server, which I need to learn more about. He mentioned a video from a Wordpress conference that is well worth a watch. Summary: On a given dedicated server, a default Wordpress installation only does 8 requests per second. VM-based caching can bring that to 12, but other caching plugins pull it up to 300 requests per second. Lesson: Fragment caching and page caching can provide a much greater benefit than even database optimization. The HyperDB database adapter. This thing is a drop-in replacement for the PHP database adapter and does things like sharding content and tables among database servers and connecting to backup databases when the master is unavailable. Most sites don’t need anything this robust, but it seems that it would be very possible to implement for ActiveRecord. The code is only about 600 lines long and is open source. The Wordpress.com database is split into 4096 databases on 8 physical servers. They take an MD5 hash of the blog name and map the first 3 characters to a database. Although he admitted that 4096 was a bit of overkill, they will be able to spread the databases to more physical hardware with only a minor configuration change in their application. HyperDB also does a fair amount of benchmark logging as well. Rails equivalents for logging: query_trace, query_analyzer. I committed some code to the current Merb trunk so it can report the time run for each before filter. It would be nice to have something similar for Rails, too. Their deployment system is just a script that runs svn update on all 300 of their servers. At one point they had to replicate their repository because it couldn’t stand up to that many hits at once.Interestingly, Matt answered a question about client-side optimization and felt that a content delivery network advocated by Steve Souders was not worth the work. They serve Wordpress.com assets from three servers in Texas, and also from Amazon S3.
Matt Biddulph, DopplrMatt Biddulph gave a useful talk on implementing Dopplr. A few interesting points:
Amazon S3 is fairly cheap for storage, but expensive for bandwidth. They use this rake task to backup the database to S3. I’ve been using the same script to backup PeepCode and to offer an alternate download for PeepCode files. Last month I stored 9 GB and transferred 50 GB and paid US$10, so it was quite affordable. Dopplr has been experimenting with using S3 and EC2 to mirror their database as an instant backup solution. He advocated configuring a slave database with MySQL replication even if your web application never touches that database. They wrote and open sourced identity matcher for slurping in lists of friends from other social networking sites. Unfortunately, this requires users to give you their name and password for third party sites, but he’s hoping to solve that with oAuth and OpenID. He suggested running both an OpenID client and server application on your site in order to let users access their data (I recently implemented OpenID signup and login at PeepCode). I’m confused about how this would work, but I guess that it would be something like: Login to Dopplr with OpenID Enter my OpenID url for another site, i.e. topfunky.somesocialnetwork.com Use sreg from Dopplr to send you to SomeSocialNetwork, which sends back a list of your friends or other data that you have approved of. Unobtrusive Javascript Widgets. Instead of doing a document.write, Dopplr uses the shortloaded Javascript snippet to load Javascript-generated content into a div on the client’s site. So you can use the ideas mentioned above and speed up client-side load time by including the Dopplr widget anywhere on your page.On another note, I was surprised to see S3 download speeds in excess of 250kb/second from London. I thought they would limit the speed at which files are served, but apparently that’s not the case. Even so, I’ve bought a small VPS in Australia and am nearly ready to launch a Merb-based asset server for serving PeepCode downloads to Australia and Asia.
You Are P.R.On the Rails front, it was shocking to hear that Yahoo is using Rails for their code-named “FireEagle” geotracking service after their commitment to use PHP for everything. Maybe it’s just for the prototype? It’s sure to get a ton of traffic when it launches.
The most frequent Rails-related comment I heard from people at the conference was about Derek Silvers’ post on Why I Switched back to PHP. Most people probably read the title, concluded that Rails wasn’t worth learning, and went about their business (at least that’s the content of most of the comments I heard at the conference).
I have a ton of respect for Derek and I think the article hasn’t been properly understood by most people. However, as a developer for an open source product, you are the only public relations department available. In an upcoming interview for the Rails podcast, James Cox talks about how PHP had to intentionally think about the public image of the language. They actually took steps to make sure that accurate information was being communicated instead of only the headline-worthy news.
Where will this come from for Rails? The author of Rails is unlikely to become a calm, diplomatic advocate in a way that non-Ruby web developers can appreciate. Heck, even the Seattle.rb has a reputation for promoting their projects in an offensive way.
At one point there was something called MINASWAN, but I don’t think that is very well known inside the Rails community (not to mention outside of it).
So is there hope for the Rails PR machine? Is it possible for us to reverse the popular opinion of it as an unscalable, offensively-promoted niche framework?
PeepCode Screencasts – Learn Ruby on Rails and Javascript! Hour-long screencasts for $9.
From Nuby on Rails, 1 year ago,
0 comments
Presented at RailsConf 2007 in Berlin
Rails provides many built-in mime types that you can generate in your application. Unfortunately, CSS was forgotten!

Why would you want to generate CSS dynamically? As a programmer, it annoys me to repeat the same hex values all over my CSS documents. Even worse, I have to make notes to remind myself what colors I’m using.

Not only colors, but HTML tags themselves are repeated inside CSS documents when I need to specify a style for a child element. For example, if I want to set a style for a link inside a list item, I have to repeatedly mention the li tag.
li {
color: blue;
}
li a {
color: green;
}
li a:hover {
color: yellow;
}
Generating CSS dynamically also gives you the ability to make your web applications smarter. For example, here are two columns. Normally, your Rails application would have no way to find out how wide they are. But if you store the column widths in a database table and generate the CSS, then other parts of your application can query the database for that information.

I worked on a site where we used this technique. PNN gives you the option of dragging a photo between columns of a layout. When you do, the photo is dynamically resized to fit the column. You could do this by squishing the image with CSS, but instead, we sent back a photo that was perfectly sized for the column.
→ Short PNN Columns Screencast
But I don’t do CSS! My designer does!CSS controls many aspects of a page’s appearance. You may want to generate only a part of the CSS, while leaving the rest to a designer. In the example above, we generated a small snippet of CSS to control the layout. The rest was accomplished with static CSS.

There are several plugins for working with CSS in Rails. The easiest way is to just use the ERb templates that are built into Rails already.
→ Short CSS with ERb Screencast
The benefits of this approach are:
Database-driven Familiar No plugins needed How? SassI use the HAML plugin for my templates and it comes with the Sass engine for generating CSS. It’s much more powerful than ERb because it was built specifically for CSS. Fortunately, most of the elements mirror standard CSS syntax, so it’s easy to learn.

Sass works outside of the normal Rails controller system. Put your .sass files into public/stylesheets/sass and they will be converted to CSS when your application starts up.

Sass also solves the nesting problem. Just indent a declaration and it will generate the appropriate CSS for nested items (inside the menu element here).

↓

The best thing about it is…variables! You can define a color once and reuse it. Variables start with an exclamation mark, and you can reuse variables by putting an equals sign in the attribute declaration.

And you can do math! Add or subtract colors to generate darker or lighter shades.

There are many other features in Sass. You can split your code into separate files and they will be combined into a single document for production. You can even put variable declarations in one file and reuse those variables in other files.

This very blog is using Sass with Merb. I wrote a Stylesheet controller that looks something like this:

In other news, I’ll be in London this next week, attending the Future of Web Apps Conference.
I’m also going to be at the George Pub on Tuesday night, handing out PeepCode t-shirts! Several dozen Rubyists have already replied and will be there, too.
http://lrug.org/nights/2007/09/26/episode-4-deadly-vision/
I’ve also published the third part of the RSpec Screencast at PeepCode. The next is one on the git SCM and was edited by Git maintainer Junio C Hamano. I hope to publish it shortly after I return from London (week of October 10).
PeepCode Screencasts – Learn Ruby on Rails and Javascript! Hour-long screencasts for $9.
From Nuby on Rails, 1 year ago,
0 comments
Don’t know the words / Kids already hummin’ with it. —Buck 65
Or more accurately, “Is Free, Community-Driven Open Source Documentation Possible?”
A few times a month, I receive an email directing my attention to a new plugin repository or Rails documentation site.
They are usually beautifully designed, but painfully bereft of actual plugins or useful documentation. They are a blank wall, waiting for a kid with a spray can to supply decoration. So far, that hasn’t happened.
Why not?
The ProblemPeople want to help the community, and it seems that the best way is to build a site where people can contribute. The problem is that the people who need the information aren’t able to give it, and the people who have the knowledge are too busy to write it down.
A beautiful looking site is good for attracting visitors, but it isn’t necessarily good for attracting workers. Programmers don’t visit empty sites because they are nice to look at (but graphic designers do!).
What these sites need is content! They need knowledgeable people who are willing to document the finer points of Rails for the benefit of those who are learning it. So mostly, they need a way to attract experienced developers.
In many cases, the founders want to run a job board or Google ads and make a bit of cash from the traffic to their (currently empty) site. Financial motivation is not the problem. (It has worked for me, and people thank me daily for it!) The problem is how it is implemented. It’s a “business plan” that provides no sustaining benefit for those who are actually doing the work (i.e. writing the documentation).
These sites will continue to go up and stay empty unless there is a different kind of “business plan” behind them, one that provides a tangible motivation for people to come and write documentation. Documentation is often boring to write and time-consuming. People don’t do it for fun!
Solutions Existing Sites http://agilewebdevelopment.com/plugins/ The original plugin directory. Over 700+ plugins. Don’t launch unless you can start your site with at least this many. I love the look of Railsify, but I have no reason to search a site with 30 plugins when another one with 700 is available. Official Rails API Docs Submit a documentation patch and add to this. Also available in searchable format at RaisBrain, Noobkit, and probably a dozen other places. Wiki. Official, but often spammed and frequently out of date. Also RailsLodge, the straw that caused the camel to write the blog post you are reading now. Commentable API docs. Rannotate, one of the original commentable RDoc apps. Seems to only be available in source since the example sites were down when I last checked. RailsManual is also available but most of the comments in the last 6 weeks are SPAM. For free video, there’s Ryan Bates’ RailsCasts. I’ve supported RailsCasts financially from day one and he publishes some great information there. There’s also the beautiful looking Rails Documentation Project. But most of the pages are pleas for contributions. A Different ApproachAlthough there are many aggregators (Planet, Corner) and great news portals (Ruby Inside), no one has tried to organize existing blog articles. What about a system that rates posts and assembles a list of classic blog posts on various topics? (such as Jamis Buck’s classic posts)
Organize it topically, not chronologically. Treat it like a library. Use the information that people are already writing and reward them by sending traffic to their blog.
What if the proprietors could dedicate an hour or two a day toward hunting down and rating top blog posts? There is already great documentation on some topics, but it’s scattered all over the place.
Maybe the Google Ad or job board revenue could even be paid back to blog authors for writing quality posts on requested topics.
If you build it well, I would even consider buying advertising space there each month.
Your ThoughtsWhy have documentation projects failed? Am I right in thinking that continuing documentation is impossible without financial backing or a self-supporting business plan of some sort?
PeepCode Screencasts – Learn Ruby on Rails and Javascript! Hour-long screencasts for $9.
From Nuby on Rails, 1 year ago,
0 comments
During a brief 2 years of writing Rails applications, I’ve learned many things that have become part of my normal workflow.
I recently published a draft of the first PeepCode PDF minibook. It’s called Ruby on Rails Code Review.
It currently contains 16 chapters of tips for building a solid Rails application and I thought it would be useful to briefly mention them here (I’ll be adding one or two more chapters for the final release). They are written as combinations of common mistakes and better implementations. If you like the term, you could call them “Best Practices.”
Are you doing these things in your applications? What would you add to this list?
Full Chapters Store sessions in the database (or at least not on disk, which is the default). Use a custom configuration file for passwords and API keys instead of storing them in your Subversion repository. I use YAML and mirror the style of database.yml. Use constants where needed. Instead of repeating strings like the address of your customer service reply email, set it once in a constant (in environment.rb or the appropriate environment file) and use that throughout your application. Keep time in UTC. A no brainer, and easy to do. Don’t loop through ActiveRecord models inside other models. Use eager loading if you need to work with multiple associated models. Better yet, write a custom SQL query and let the database do the work for you. Beware of binary fields. By default, all fields are returned with queries, including the full contents of any binary fields. Use :select to pull out only the fields you need. Write tables to cache data for reports that span months and years. It’s much faster than re-generating a year’s worth of reports every time a page is loaded. Create a table with a list of country names. By default, Rails uses strings for selects and lists of countries, which doesn’t work well for reporting or database consistency between models. Avoid bloated controllers. Instead of piling actions into a controller, limit yourself to 10 actions per controller, then rethink your design. Keep your controllers and views skinny. In general, most of your code should be in your models, not your controllers or views. Don’t store objects in the session. Use integers or short strings if necessary, then pull the appropriate object out of the database for the duration of a single request. Avoid heavy response processing. Can you mark a record as needing to be processed, then use a cron job or a messaging server to do the long-running work? BackgroundRB is also an option. (I use this technique for filtering SPAM comments on this blog). Use ar_mailer to queue bulk emails instead of sending them during the Rails response cycle. Monitor your servers with the exception_notification plugin, munin, monit, or other tools. Don’t cut costs on hardware. You’ll quickly lose the money you thought you were saving if your developers have to spend even one day a month on unexpected server maintenance due to poor backups or cheap hardware. Test-drive your development. Mentioned in Passing Use database indexes to speed up queries. Rails only indexes primary keys, so you’ll have to find the spots that need more attention. Profile your code. The ruby-prof gem and plugin helped me make an application three times faster with only minimal changes to the code. Minimize graphic-related dependencies. If your application only needs to make a few thumbnails, don’t waste memory by importing large graphics libraries. Look at mini-magick or image_science for lightweight thumbnailing. Avoid excessive repeated rendering of small partials. Use CSS instead of inline tags to apply selective styling. Don’t use ActiveRecord’s serialize option to store large objects in database fields. Use attr_protected :fieldname in models to keep database fields from being manipulated from forms (or from any calls to Model.update_attributes(params[:model])). Use Ruby classes and inheritance to refactor repeated controller code. Use unobtrusive Javascripting techniques to separate behavior from markup. Package self-sufficient classes and modules as plugins or RubyGems. Cache frequently accessed data and rendered content where possible. Write custom Test::Unit assertions or rSpec matchers to help with debugging test suite errors. Rotate the Rails and Mongrel logfiles using the logrotate daemon on Linux. Build a reliable backup system. Automate deployment and maintenance with Capistrano or Vlad. Keep method bodies short. If a method is more than 10 lines long, it’s time to break it down and refactor. Run flog to determine overly complex methods and clases. Don’t use too many conditionals. Take advantage of case statements and Ruby objects to filter instead of multiply-nested if statements. Don’t be too clever. Ruby has great metaprogramming features, but they are easy to overuse (such as eval and method_missing). Become familiar with the most popular plugins. Instead of re-implementing the wheel, save yourself some time by using well tested, popular plugins.(Thanks to Courtenay Gasking for many of these guidelines).
Several people have written to say that they have put together blank Rails projects that include all the plugins and defaults that they use on new projects. Maybe I should put one together that uses all the suggestions you see here?
In Other NewsOver a year and a half ago, I signed on to write two chapters in a book about Rails Deployment. That book is now available for pre-purchase as a Pragmatic Beta PDF!
Deploying Rails ApplicationsI’ll be speaking at RailsConf in Berlin! I’m up against Twitter, JRuby, and Amazon, but I doubt any of them will be giving away random PeepCode t-shirts, PeepCode coupons, or have their own marching band.
The Forgotten Child: CSS in RailsAnd there are a few hours left in the PeepCode one-year anniversary sale! Buy a 10-pack and get 12 credits instead of 10!
PeepCode Screencasts – Learn Ruby on Rails and Javascript! Hour-long screencasts for $9.
From Nuby on Rails, 1 year ago,
0 comments
autotest is a fantastic tool. If you’re not using it, you’re missing out on a large part of the joy that life has to offer.
Ryan Davis and Eric Hodel can stop reading this article now.
For everyone else,
Customizable File Watching With rstakeout!Mike Clark wrote a ruby implementation of a tool to watch files, then run any arbitrary command.
I modified it to look for Test::Unit or rSpec output and pop up a growl notification also. (Apparently the original author of the Mac OS X native app also did the same.)
In any case, this is a really useful tool. Autotest won’t run in Test::Unit mode if you have a spec directory, but rstakeout can be told to run any command when files change. It’s not as smart as autotest (it won’t match the command to the name of the file that changed).
DownloadGet rstakeout from one of my Subversion repositories.
http://svn.topfunky.com/public/scripts/rstakeout.rbUsage
rstakeout "command to run" 'files to watch' 'more files to watch'
It’s most useful when you can use Ruby’s file globbing instead of the shell’s. If you do something like '**/*.rb', Ruby will recurse into all subdirectories. The shell will only go down a single directory, so quote the final arguments so they will be passed to Ruby.
ExamplesRerun a single unit test when the implementation or test file is saved:
rstakeout "ruby test/unit/user_test.rb" 'app/models/user.rb' 'test/unit/user_test.rb'
Run the unit tests when model files are saved:
rstakeout "rake test:units" 'app/models/*.rb' 'test/unit/*.rb'
Run a single functional test, then run flog and filter the output with grep. This will show if your code is becoming more complicated or less.
rstakeout "ruby test/functional/orders_controller_test.rb && \
flog -a app/controllers/orders_controller.rb | \
grep 'OrdersController#checkout'" 'app/**/*' 'test/**/*'
Loaded suite test/functional/orders_controller_test
Started
..............................
Finished in 3.536267 seconds.
30 tests, 74 assertions, 0 failures, 0 errors
OrdersController#checkout: (56.5)
OrdersController#checkout_with_google: (17.6)
OrdersController#checkout_with_paypal: (15.9)
Lather, rise, repeat with Heckle or any other testing tool.
I’m using this to generate PDF documents using my automated system for PeepCode Press.
rstakeout "ruby script/generate code_review" '**/*.textile'
I use a shell shortcut to reuse the previous command.
$ some --long shell command $ rstakeout "!!" 'files/**/*'Or with autotest…
Ryan Davis pointed out that you can do something similar with flog and autotest by hard-coding this into your ~/.autotest file:
Autotest.add_hook :green do |at| system "flog app/controllers/users_controller.rb | grep \\#update" endIncomprehensible Statistics
For completeness:
rstakeout = 73.7304101610032
autotest = 909.440236256987
ratio = autotest / rstakeout
= 12.3346694297654 # <-- zomg! look here!!!
# I have no idea what these numbers are here for,
# or what they mean.
ratio - Math::PI
= 9.19307677617561
target = autotest / Math::PI
= 289.483818093921
target - rstakeout
= 215.753407932918
A Year of PeepCode!
Somehow, it’s been a year of PeepCode!
Yes, I’ll stop these self-congratulatory posts soon. In the meantime, buy a 10-pack and get 2 free screencasts, or a 5-pack and get one free. Offer good through Friday, September 7.
And the first PeepCode Press PDF is now available for purchase in draft form. Rails Code Review is seventeen chapters of common mistakes in Rails apps, and examples of how to write better code instead.
Finally, I have about 15 PeepCode t-shirts that were printed with an experimental process. Early users have reported that the printing washes off after the first laundering. But hey, at least you’ll have a nice black t-shirt! I’ll send you one at my expense, anywhere in the world.
Send an email to peepcode@topfunky.com with FREE SHIRT in the subject. Include your shirt size, and male or female Include your mailing address (which will only be used to send you the shirt) PeepCode Screencasts – Learn Ruby on Rails and Javascript! Hour-long screencasts for $9.
From Nuby on Rails, 1 year ago,
0 comments
I received a lot of feedback, humor, and creativity in response to my article about an alternate community logo for Rails.
I received an official reply but don’t want to distort the ideas that were communicated, so I’ll let the people in question speak for themselves. However, the end result is that if you use Rails, you should be aware of the fact that the graphical logo representing Rails is trademarked. Developing an alternate logo isn’t going to be a worthwhile pursuit.
There are also some erroneous ideas that have been circulating. The good news is that you won’t be forced to pay any royalty to use the words “Ruby on Rails.”
Philosophical ReactionsAs someone who appreciates graphic design, I think this is an interesting commentary on the power of visuals. People rally behind country flags, sports team mascots, and even company logos.
Even in the unemotional field of computer science, we want to be emotionally attached to a concept and a community. A visual logo is often the focus and expression of our enthusiasm for a technology. We want to wear it like a shield on our t-shirts and build our own company logos, blogs, and domain names around it (possibly in denial of how fast technologies change, or possibly in admission of how fast companies go out of business).
Maybe it was the more emotional among us who were disappointed to hear about restrictions on the use of a visual we had invested our hopes, dreams, and aspirations into. We think of open source software as a guerilla, anti-corporate endeavor and trademarks as a protective, corporate measure, so it’s hard to understand the two coming together.
In the end, we still value the seal of approval just as people have for thousands of years (both the owners and the recipients of the seal).
The Ruby LogoSo if you need a visual to rally around or tattoo on your ankle1, try the beautiful Creative Commons-licensed Ruby logo designed by the talented John Long.
David Black pointed me at the site for the Ruby Visual Identity Team which even includes a downloadable kit with copies of the logo in many known bitmap and vector formats.
There’s even a mailing list where you can ask Matz personally for permission to use the logo, which is often granted.
1 The Ruby logo is liberally licensed under the Creative Commons Attribution Share-Alike license. In my understanding of the license, this only applies to modifications on the logo itself and would not extend to your body after being tattooed with it.
PeepCode Screencasts – Learn Ruby on Rails and Javascript! Hour-long screencasts for $9.
From Nuby on Rails, 1 year ago,
0 comments
...you’re always free to fork and call it Pete’s Swanky Framework, design a logo for PSF, and invite everyone to use that for whatever they like. – DHH
Just to get the conversation started…
Ring theme



From Nuby on Rails, 1 year ago,
0 comments
Scottie Project by Agile Dovadi and the Waag Society
At the Ruby en Rails conference in June, I spoke with Frank Oxener of Agile Dovadi who is working on some interesting hardware projects with Ruby.
Article about the project in Dutch English translation via BabelfishThey are using the small, inexpensive Arduino microcontroller boards together with some high-tech fabrication to build a non-verbal interface for children hospitalized with long-term illnesses to communicate with their parents.
The handheld unit communicates with a Mac mini via Bluetooth and notifies the parent over the internet.
I did a bit of circuit board fabrication in college and have been fascinated with projects like this. It’s great to see people taking innovative approaches and using technology to provide a meaningful benefit to people who need it.
Resources Arduino and Ruby Arduino and Ruby Demo Video Waag Scottie Project Agile Dovadi PeepCode Screencasts – Learn Ruby on Rails and Javascript! Hour-long screencasts for $9.
From Nuby on Rails, 1 year ago,
0 comments
Most people are curious / and want to get dirt on / the Centaur, I’m famous / I walk around with no shirt on. – Buck 65
Somehow, I’ve managed to make a name for myself over the past few years. It’s a little freaky to casually mention on Twitter that I bought a new office chair, then to see people on an IRC channel on the other side of the world debating the positive and negative aspects of my chair.
I love meeting people at conferences and collaborating on interesting projects. But I get a lot of email and I’m not always able to respond to all of it.
If you’re hoping to write to me or any other microcelebrity, here are some suggestions that improve your chances of getting a response.
EmailGeneral props, compliments, and thumbs up are always appreciated. Every other day I get an email with a thumbs up, which makes my job awesome. It’s one thing to have a boss pat you on the back, and another to get an email from an actual customer or fan who appreciates you. So thank you to all the people who have taken the time to pat me on the back!
For all other email, keep it short and include a specific action item. I received a wonderful email from someone about their history of learning Rails, their plans for the future, and about 6 other long paragraphs. I appreciate that someone took the time to write to me, but a long letter like that takes a while to read and it’s likely that I’ll put it aside and never come back to it.
Social NetworksWhen friending someone, include a short note about who you are. LinkedIn, Facebook, and other apps give you a spot to add a personal note when you add someone to your network. This puts things in context and helps me figure out if you’re an old college roommate or a friend of my mechanic. For readers of this blog, it could be as simple as the one word “Rubyist.”
This is even more important if your screen name doesn’t match your email address and your real name is even different from the other nickname you go by in the real world. I try to keep these things straight, but sometimes it’s like tracking down a con artist with 17 aliases. (If Jason Crane is reading this, I didn’t mean to call you a con artist!)
And if you are writing a social networking application, give your users a place to do that when they invite friends.
ConsultingI’m currently putting my full effort into PeepCode. If you’re trying to hire me for a long-term project, you’ll get a stock rejection letter, unfortunately.
However, I love to travel and am interested in the occasional on-site training session. I also love to speak at conferences and love it when a conference is organized well enough to pay for my plane ticket to the event.
BooksIf you’ve recently published a book and want me to review it here or interview you on the Rails Podcast, I’d love to receive a copy of your book. My mailing address is in the footer of my blog.
Again, I’m putting my effort into my own publishing company right now, but I sometimes take the time to review other books in process. However, I’d much rather be part of the initial process before you even start the book. It’s awkward to send a critical letter of condemnation after reading a book that was poorly researched and badly implemented. I would much rather talk to you for an hour or two before you write your book to get you going on the right track. I’m saying this mostly for authors of anthologies who are going to cover Rails in a single chapter and want to cover only the basics.
Props to O’Reilly for Supporting Developers of All GendersOn a completely unrelated note, I want to give a thumbs up to O’Reilly for listening to the community. On the Rails Podcast, several women decried the lack of gender-specific t-shirts being printed and given out at conferences.
Thanks to unflagging internal advocacy by Rob Orsini, O’Reilly have tentatively announced that they will be printing women’s t-shirts for RailsConf in Berlin. I think this will be the first O’Reilly conference to do this.
Also, it pains me every time I go to the excellent DevChix blog and see that there are only a few hundred subscribers. Carmelyne Thompson, Ana Nelson, Desi McAdam, and others are writing some great articles there and you need to subscribe to their RSS feed if you haven’t already.
PeepCode Screencasts – Learn Ruby on Rails and Javascript! Hour-long screencasts for $9.
From Nuby on Rails, 1 year ago,
0 comments
At the table, left to right: John Downer, Spyros Zevelakis, Matthew Carter, Akira Kobayashi
I’ve been at TypeCon for the past three days (photos). I appreciate great type design, it was located here in Seattle, and I wanted to see how a non-tech conference was run.
It was satisfying on all accounts. Here are a few reactions of technical and non-technical interest.
Re-introducing unpredictabilityOne of the most provocative and mind-blowing lectures was by Robert Bringhurst, author of the classic Elements of Typographic Style (also being interpreted for the web).
His lecture on Typography as Quantum Mechanics explored the contrast of the predictability we get from mechanized systems with the unpredictability of reality. If you look at a handwritten document, you’ll see that not every instance of the letter ‘a’ is written in exactly the same way. This difference isn’t random but is part of the human element that distinguishes calligraphy from the output of a typewriter.
We’ve gotten into the habit of programming computers to reproduce the same result time after time, and in 99% of cases this is a good idea. But reality is not always predictable. The beauty of the situation is that current technologies such as OpenType make it possible to embed multiple variations of a letter into a font, and software can take advantage of this when rendering a document. For example, he showed an Arabic-language plugin for the InDesign page layout program that allows a designer to specify the probability with which different variations of a letter will be used.
How does this apply to website development? I’m not quite sure. We wouldn’t want to show random search results or pull a random article from a database. And, the point of the lecture was to achieve better aesthetic representation, not to change content.
Right now the concept that I’m chewing on is how to get the human element back into programmatically-generated content.
DRM deemed too costly by AdobeIn an afternoon panel, directors from Microsoft and Adobe answered a question about DRM. Apparently Adobe has tried three times to develop a copy protection system for fonts, but they have never completed it. The reason? They weighed the financial benefits against the user experience and determined that it was better to keep selling fonts without DRM.
A type designer who asked not to be named said that he knew his fonts were being pirated, but they also served as a sort of free advertising. People who did the pirating were probably not likely purchasers of his fonts anyway, and a person who discovered him via file-sharing networks might end up becoming a large-scale corporate licensee of his typefaces.
I believe in paying for quality software that I use. I paid US$1,600 for the Adobe suite that I use daily. The last font family I purchased cost about $400 and I would have gladly paid more.
I know that some episodes of PeepCode are being pirated, but I’ve chosen to sell screencasts without any DRM. Legitimate purchasers have converted the videos for their own use on other devices such as the Sony PSP, and Linux users who have subscribed have converted them to Flash video or other formats so they can view them more easily. I don’t want to punish legitimate users by restricting their ability to use content that they have paid for. It’s affirming to hear that the second largest software company in the world has also made the same decision.
Speaking of which, I’m now offering Team Licenses of PeepCode. Several companies have bought licenses for their development team or even their entire company. Each developer will receive a license code and can maintain an account at PeepCode, or you can choose specific screencasts and distribute them to your employees on your local network. Email peepcode@topfunky.com with the number of developers you would like to buy for, and how many screencast credits you would like to purchase.
Presentations, with audio!As I hoped, most of the presentations communicated clearly and were delivered with style. Technically, the most amazing thing was the fact that every speaker had access to both video and audio amplification. Even more amazing was the fact that they actually used it!
The founder of P22 talked about the hand-printed covers for their companion record label, and he was able to play clips of the music he was talking about. John Downer impersonated one of his fonts for 20 minutes and used music to accompany the dramatization.
I’m taking bets on how long it will be until I attend a tech conference that provides every lecturer with audio amplification in addition to a video connector. In the meantime, people will continue to detach their lapel mic and press it against their laptop’s speaker anytime they want to show a video clip or play any audio. Or if you’re Adam Keys, you bring a live musician with you.
I’m putting together a separate article on how to create a top-notch presentation and will post it before RailsConf in Berlin.
MikifikiThe F-bomb was surprisingly popular. It was dropped twice before lunch on the first day of lectures, and was presented to the audience 5 times by a single speaker on Saturday.
I’m not sure if David Heinemeier Hansson is into typography, but I can only guess that his single slide would have been a non-event at this conference.
ConclusionI haven’t mentioned much about the rest of the artistic inspiration or personal conversations I had at the conference. Overall, it was a great experience. Next year’s will be in Buffalo, NY. There is also a related conference coming up this fall in Brighton.
I spoke with the conference organizers and I may be able to donate bandwidth to serve the audio recordings of the lectures. I’ll post here if that happens.
PeepCode Screencasts – Learn Ruby on Rails and Javascript! Hour-long screencasts for $9.
From Nuby on Rails, 1 year ago,
0 comments

It’s time again for a Seattle.rb event at my house. Last year we proved the existence of why the lucky stiff when he showed up for the last 30 minutes just as it was getting dark.
Technically this won’t be a barbeque since I don’t own one UPDATE Ryan Davis will be bringing a BBQ machine, so bring meat with you. I will provide drinks and probably pizza in my backyard.
It will happen on this Tuesday, July 17. You can come as early as 6 pm, and the sun goes down at about 9 or 9:30 pm.
If you are in the Seattle area or can catch a flight from the land of Greenlid, please come!
PeepCode Screencasts – Learn Ruby on Rails and Javascript! Hour-long screencasts for $9.
From Nuby on Rails, 1 year ago,
0 comments
Two years ago today, Scott Barron published the first episode of the Ruby on Rails Podcast.
A few episodes later I stormed onto the scene and have added another 50+ interviews to the mix. I’ve learned a ton in the process and I’d like to think that the audio quality has improved, and hopefully my journalistic chops as well.
Oh, the Places We’ve GoneI’ve interviewed people onsite in London, Norway (twice), Australia, Canada, Amsterdam, and several cities in the United States.
My friend Stephen Munday translated two Japanese-language interviews with Matz and Shugo Maeda.
I’ve interviewed Ruby experts and broke the news that RubyConf 2006 would be limited to only 240 attendees, causing widespread panic on the day tickets went on sale. There was a flood of email after the interview with Zed Shaw.
Photo by Thijs van der Vossen
The show currently has about 5,500 subscribers plus other occasional listeners, but some episodes get more attention. The interview with Adrian Holovaty of Django was popular with both Rubyists and Pythonists, and the recent Women in Development show was downloaded over 40,000 times. There is also an upcoming and uncut page (and feed) in addition to the main feed.
The source code for the Rails app that powers the site is available.
Interrogate the InquisitorThere are many people who are a huge part of my daily interactions, blog-reading, and coding, but have not appeared on the show yet. I hope to be able to continue doing the Rails Podcast for a long time, but now it’s your turn. My friend Dan Benjamin will be interviewing me for the next show. He wants you to send questions to him that you would like to ask me. Don’t post them here in the comments…he wants to keep me on my feet. Put RAILS PODCAST in the subject.
ThanksThanks to Samson Audio for providing awesome microphones, pre-amps, and recording devices that I take everywhere I travel.
Thanks to Sam Aaron, Robert Stephenson and Obie Fernandez for contributing interviews.
The podcast was also a launching pad for PeepCode Screencasts which now constitutes my full time employment and funds the expenses of the podcast. Thanks to everyone who has listened and who has supported PeepCode! (New screencasts are out now on rSpec and Rails from Scratch.)
PeepCode Screencasts – Learn Ruby on Rails and Javascript! Hour-long screencasts for $9.
From Nuby on Rails, 1 year ago,
0 comments
One of the dirty secrets of computer programming is Repetitive Stress Injury. It affects a surprisingly large percentage of people (even prominent Rails developers!), but few talk about it.
I experienced about a year of intense, dull pain at the end of my college years that went away after 6 months of self (and dotcom) induced unemployment. I’m still not exactly sure what I did to solve the problem, but I have learned a few things that have helped me since then.
Much of the medical advice I received was generic and vague. It might work for the average office worker, but a fulltime computer programmer has different needs. Developers also have more options if they are willing to experiment with some drastic changes.
Summary: Pay attention to your body. Build a comfortable workstation for yourself. Stretch. Learn Dvorak if you can commit a month to it. Type softly.
DISCLAIMER: This is not medical advice.
Pay Attention to Your BodyWe don’t think of typing as a physical experience. Pushing a few tiny keys barely seems like work! But it is when you do it thousands of times.
One’s first reaction is usually to deny and plow forward. “Surely those small pains will soon disappear on their own!” Instead, trust your body and listen to it. It knows more than you do.
One of the easiest and best things you can do for yourself is to stretch your arms. Reach them out like airplane wings and point your fingers at the sky with your palms facing away from you. For extra credit, rotate your hands backward so your fingers are pointing behind you.
You can do this while seated, so you don’t even have to get up from your chair.
Years ago I also tried more exotic treatments such as acupuncture and therapeutic massage, but I’ve done as well with just basic stretching.
Comfortable WorkstationObtaining a comfortable workstation is an iterative process. You can’t just run out and buy the first chair, desk, keyboard, or mouse that has an “ergonomic” label on it. I’ve tried a few different combinations and have arrived at a setup that works well for me.
Many developers use laptops exclusively. Here’s a tip: Buy a cheap ($300) 20” Dell monitor and use it instead of your laptop’s monitor. You’ll be able to run at a higher resolution and you can adjust the monitor’s height to a more comfortable level.
I use a desk from Anthro (console unit). Most parts can be bolted at your choice of height. The keyboard platter moves up to about 4 feet high on demand (I do most of my voiceovers and podcasts standing). I also tried the Biomorph for a while but it was too wobbly for my taste.
My monitors are on movable arms from Ergotron (although current iMacs are unfortunately not VESA-mountable).
It’s not crucial that everything be adjustable on demand. You might do well enough by finding a comfortable height and using hardware that bolts to that height permanently. However, adjustable equipment gives you the option of standing or sitting on demand.
Keyboards and MiceAfter trying many keyboards, I’ve settled on the TypeMatrix. I love the feel of a laptop keyboard and wanted something that had light key pressure. I’m not opposed to exotic solutions, and I actually appreciate the extra enter and delete key in the middle of the keyboard. I rock a model without any labeling, but you can buy one with the standard QWERTY letters printed on.
The important thing for me is the nipples. Ten of the keys have a physical dot in the middle that gives your fingers something to hunt for without requiring visual confirmation. I haven’t found any other keyboard that provides so much useful feedback.
Previously I used the Microsoft Natural for a few years. Eventually, I got tired of the key pressure needed to depress the keys. The TypeMatrix is surprisingly comfortable to me even though it isn’t split like most natural keyboards.
I’ve never tried the Kinesis, but have heard good reviews. I used a split keyboard that mounted separately on the arms of the chair but it wasn’t very comfortable in the long run.
I tried a few exotic mice, like the 3M Renaissance Mouse and a foot-driven one. I returned to the standard Microsoft optical mouse.
Having a workflow that doesn’t require much mousing is a big deal. I’ve setup a ton of TextMate snippets and use other macros to keep me from touching the mouse unless absolutely necessary. It ends up being faster, too.
TechniqueHere’s a free tip: Type softly. Sometimes I don’t realize how hard I’m hammering my fingers on the keys. You may have to intentionally train yourself to press more lightly.
Take breaks. It’s hard to remember, but it will give your mind a break, too.
DvorakThis section may be controversial, so I’ll keep it short. I went cold turkey to the Dvorak keyboard layout about a year and a half ago. I’ve never regretted it and my hands are much more comfortable because of it. The layout of the keys means that one’s hands travel a shorter distance when reaching for the keys.
My recommendation is to go cold turkey and type nothing but Dvorak for a month. Tape a printout of the keys on your monitor and use that as a reference. After a few days you’ll feel like quitting altogether. After a week or two you’ll start to feel a bit more confident, but your mind will still be in Qwerty mode. If you can stick with it until week 4, you’ll be home free.
If you’re on Windows it’s a little bit tricky since every application can have its own layout. The TypeMatrix keyboard can be flipped to Dvorak mode which makes things easier (but it isn’t necessary that you buy a special keyboard to learn it).
I’ll close with a word from Miles Forrest
I stuck with it, and happy that I did. My fingers do a whole lot less travelling than with Qwerty, and it just feels more comfortable. Even some things I miss like having CUT, COPY, PASTE grouped aren’t a big deal anymore, and I’m starting to get muscle memory back in programs like vi.
PeepCode Screencasts – Learn Ruby on Rails and Javascript! Hour-long screencasts for $9.I’m glad my hands were starting to hurt under QWERTY, otherwise I wouldn’t have stuck with learning Dvorak. One thing I’d recommend to people who want to learn it, just tape a picture of the layout on your monitor (I had one on my MBP) and don’t switch the keys around—you’re not supposed to look anyhow.