Sunday, October 19, 2008


This is an interesting article on telecommuting from WIRED.

Basically - saves $15,000 on office space, $1200 on gas, most managers think employees are more productive at home. Unlike the office where a typical office worker is interrupted or switches tasks every three minutes.

Personally, I love telecommuting - not only do you save the gas, but also the hour getting ready for work and commuting to and from seems like a waste. I've found that I can get a lot more done at home in a shorter period of time.

There's other benefit - you can get a little house work resolved, too. In fact, doing a little laundry at home even has a meditative quality.

It's a good diversion for those times when you need to think out a solution before you get started.

Thursday, October 16, 2008

Adding Memcached to a Rails 2.1 Application in Mac OSX 10.5

I just couldn't find anything explicit on the web about this, but it turns out to be really easy.

Install libevent:

cd to libevent directory
Run: ./configure; sudo make; sudo make install;

Install memcache:

cd to memcached directory
Run: ./configure; sudo make; sudo make install;

I don't know if all the sudo's are required, but it failed do to permissions without it. I suspect it's just required on the 'make'.

The run memcache:

> memcache

It is started with defaults for the ip and port of

In my environment.rb - I added

config.cache_store = :mem_cache_store, 'localhost', ''

Then - restarted my web app and started using Rails.cache.

To use it, in the controller do something like this:

@list_of_items = Rails.cache.fetch('list_of_items', :expires_in => 60*60 ) { Item.find(:all, :conditions => ['column = ?', @value]) }

Wednesday, August 06, 2008


This is the sound of steak in the griddle.

Thursday, June 26, 2008

Rails Javascript Widget

At Entertonement (I know, the name sounds like a old appliance, but that's the retro cool thing about it), we're building a rails app to upload and work with sound clips. You can add a clip - then we'll convert it - allow you to make a ring tone out of it, embed it in a blog, etc. Here's the first test of the javascript widget that we're making. Sorry - it'll probably break if you're not logged into our dev site.

Some details about the Rails Javascript Widget:

I have a simple .rhtml file that looks like so:

<% style = params[:style]; size = params[:size] || 'medium' %> <br /><% width = (size == 'large') ? '200px' : '100px' %> <br />(function(){ <br />document.write('<div style="border:solid 1px grey; width:<%= width %>;overflow:hidden;text-align:center;font:normal 11pt verdana;padding:3px;<%= style %>">'); <br />document.write('<%= image_tag( @clip.image_file(size.to_sym || :medium), :style => "width:#{width};padding:0px;border:0px") %><br>'); <br />document.write('<object align="top" data="&lt;%= DOMAIN %&gt;/embed/button/musicplayer.swf?&amp;song_url=&lt;%= @clip.audio_path %&gt;&amp;" height="17" style="margin:5px" type="application/x-shockwave-flash" width="17">'); <br />document.write('<param name="movie" value="/embed/button/musicplayer.swf?&song_url=<%= @clip.audio_path %>&" />'); <br />document.write('<img alt="" height="17" src="noflash.gif" width="17" />'); <br />document.write('</object>'); <br />document.write('<div style="border-top:solid 1px #EEE;padding:5px 0px;line-height:19px;">'); <br />document.write('<a href="<%= escape_javascript @clip.url %>" style="color:#888;font-size:8pt"><strong><%= escape_javascript(h( %></strong><br>Sound clip on<br><span style="color:#C4222B;white-space:nowrap">ENTER<span style="color:#418CC5">TONE</span>MENT</span></a>'); <br />document.write('</div></div>'); <br />})()

Mainly a bunch of document.write calls to display the appropriate html.

When you add it to a website - you simple add this kind of code:

<script type="text/javascript" src=""></script>

This will be on the live site soon enough to test for real.

Monday, June 09, 2008

Paperclip - uploads, attachments, and thumbnails in Rails

I tend to use image upload and resizing on most of the apps I create. Even my latest KidFlick - where it's easy to share photos privately.

Paperclip is a great new plugin that just works the way it's supposed to.

Check it out at: Paperclip - uploading files, no hassle

Thursday, March 13, 2008

Cool Rails SVN tidbit - showing the revision #

If you want to show the SVN Revision number on your page - this helps the test team - add this code to your site:

<%= `svn info #{RAILS_ROOT}`.match('Revision.*') %>

Those are back-quotes. This will cause a shell command to be run.

If you add it to your environment.rb like so:

$svn_revision = `svn info #{RAILS_ROOT}`.match('Revision.*')

Then it is run when the server starts and you can access it on any page...

<%= $svn_revision %>

Monday, February 11, 2008

A Ruby on Rails application with no database

If you have a project that has no database (it may be hitting a web service), you will want to remove ActiveRecord, ActiveResource, and ActionMailer.

To do this, uncomment the line in environment.rb

19 # Skip frameworks you're not going to use (only works if using vendor/rails).
20 # To use Rails without a database, you must remove the Active Record framework
21 config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

It took me a little while to find why I was getting the mysql error as I didn't have an ActiveRecord model and the stack trace for the error isn't helpful.

Mysql::Error (#28000Access denied for user 'root'@'localhost' (using password: NO)):
/vendor/rails/activerecord/lib/active_record/vendor/mysql.rb:523:in `read'
/vendor/rails/activerecord/lib/active_record/vendor/mysql.rb:153:in `real_connect'
/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:471:in `connect'
/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:165:in `initialize'
/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:88:in `mysql_connection'
/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:291:in `connection='
/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:259:in `retrieve_connection'
/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in `connection'
/vendor/rails/activerecord/lib/active_record/query_cache.rb:8:in `cache'
/vendor/rails/actionpack/lib/action_controller/caching.rb:677:in `perform_action'
/vendor/rails/actionpack/lib/action_controller/base.rb:524:in `process_without_filters'
/vendor/rails/actionpack/lib/action_controller/filters.rb:685:in `process_without_session_management_support'
/vendor/rails/actionpack/lib/action_controller/session_management.rb:123:in `process'
/vendor/rails/actionpack/lib/action_controller/base.rb:388:in `process'
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:171:in `handle_request'
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:115:in `dispatch'
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:126:in `dispatch_cgi'
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:9:in `dispatch'
/vendor/rails/railties/lib/fcgi_handler.rb:101:in `process_request'
/vendor/rails/railties/lib/fcgi_handler.rb:149:in `with_signal_handler'
/vendor/rails/railties/lib/fcgi_handler.rb:99:in `process_request'
/vendor/rails/railties/lib/fcgi_handler.rb:77:in `process_each_request'
/usr/local/lib/ruby/site_ruby/1.8/fcgi.rb:612:in `each_cgi'
/usr/local/lib/ruby/site_ruby/1.8/fcgi.rb:609:in `each_cgi'
/vendor/rails/railties/lib/fcgi_handler.rb:76:in `process_each_request'
/vendor/rails/railties/lib/fcgi_handler.rb:50:in `process!'
/vendor/rails/railties/lib/fcgi_handler.rb:24:in `process!'

Thursday, February 07, 2008

Why companies adopt Ruby on Rails

This is a great thesis from Michael Barbosa, a bachelor student at the Erasmus Universiteit Rotterdam in the Netherlands. It was written in July, 2007.

The last half of the document is his findings. Companies were surveyed, here's some of the results. Go to his site and download the pdf to see all the results. It's interesting and reinforcing to what you probably already know.

97.9% Increase in productivity
92.5% Rails enables faster development of web applications than competing frame-works
91.8% Joy in development
90.4% With rails, web applications are structured well