Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

Author Archives: Peter Cooper

By Peter Cooper / October 9, 2006

Irbvideo

This is going to be child’s play to most of you, but Eric Lake has a cool video up about how to enable a simple prompt and tab completion in IRB. I’d never thought of having that feature in IRB before so I found it interesting at least. Still not sure I need it, but if you do.. Read More

By Peter Cooper / October 8, 2006

Following on from his original interview with Charles Nutter and Thomas Enebo of the JRuby team, Pat Eyler has interviewed the team again (read part 1 then part 2), with the addition of Ola Bini. Both parts are quite long and go into a lot of detail about JRuby and Ruby’s existence under the Java umbrella.

In Part 1, Ola comments:

I’m tackling performance from my side, by creating extensions in Java instead of Ruby (YAML and ZLib, for example).

JRuby might feel like an alternate bizarro reality, but these guys are doing a great job while staring one giant mountain in the face. Read More

By Peter Cooper / October 8, 2006

Rjscheatsheet

Amy Hoy has put together a PDF that’s a cross between a very basic cheatsheet and an introduction to RJS (the AJAX / JavaScript DSL included with Rails). It’s extremely colorful and cute with good illustration and layout, although only particularly useful to beginners as it’s not really a cheat sheet in the traditional sense. Read More

By Peter Cooper / October 7, 2006

Rubyforrailscover

Rob Sanheim (one of the Ajaxians) has put together a great review of Ruby For Rails by David Black. It’s a great book, and if you haven’t got it yet, let Rob’s review convince you. I personally found it an interesting read and it’s really easy to get stuck into. It’s an ideal book if you’ve made it through Agile Web Development for Ruby on Rails and are hankering for more as it dives into the Ruby side of things a lot more. Read More

By Peter Cooper / October 5, 2006

Austrian development agency, Sparkling Studios, look at how to use the Akismet anti-spam system to check data submitted to your site and protect your application from spam. It works by signing up for a key from Akismet and using a Ruby Akismet library. Then whenever you want to check your data, you make a simple call and Akismet returns a true or false based on whether the system believes the data to be spam.

It should be noted that this method is primarily useful for blog comment and trackback related spam, but could be useful on other data that fits the same structure. Read More

By Peter Cooper / October 2, 2006

SessionTimeout is a Rails plugin by Luke Redpath that makes enforcing short session times easy, like so:

class ApplicationController
session_times_out_in 600, :after_timeout => :do_something

def do_something
logger.info "HELLO, IVE TIMED OUT!"
end
end

Luke explains:

With Rails built-in session options, you can set a specific session expiry time however in production mode this expiry time is set just the once. This is fine if you are setting your expiry time far in the future (and therefore you are likely to restart your server processes by that time) but if you want to set your timeout in the near future, your session expiry will soon be a date/time in the past – this will cause a new session to be created for every new request resulting in disaster. Read More

By Peter Cooper / October 2, 2006

James Edward Gray II laments:

Every so often a person asks the question on Ruby Talk, “How can I get just one character from the keyboard (without needing the user to hit return)?” Everyone is always quick to post solutions, but sadly there are some issues with almost every one of them.

He moves on to look at a reasonably cross-platform solution called HighLine. This isn’t very useful if you’re just a Rails developer, but if you’re creating Ruby apps to be used at the command line, it’s gold.

(Update January 8, 2008: Thanks to Michael Fellinger for pointing out the above URL was broken. Read More

By Peter Cooper / September 30, 2006

Rubyinsidelcd
BetaBrite is a Ruby LCD sign library developed by Aaron Patterson. Since few people have LCD signs to play with, Aaron has set up a test-bed installation that you can use via DRb. Ingenious! Next I expect a Ruby blinkenlights library and DRb hookup.
(First seen at why‘s) Read More

By Peter Cooper / September 30, 2006

Youtuberuby

Shane Vitarana has put together a Ruby library for accessing YouTube videos and metadata. All that’s needed is a simple gem install youtube, and you can put together great examples like the above. Shane cites Scott Raymond’s Flickr Ruby library as an inspiration. Read More

By Peter Cooper / September 27, 2006

Jon Maddox was inspired by Ruby Inside’s previous post about init.d startup scripts, and has put together a UNIX init.d script that can start, stop, and restart all of your Rails apps’ Mongrel clusters automatically. The benefit of Jon’s approach is that unlike with the startup script supplied with Mongrel, you don’t need to manually copy in each Mongrel configuration file to make it work. Instead, you tell the script under which folder your apps are hosted, and it looks for your Mongrel cluster configuration files automatically. This is an ideal script if you have multiple Rails apps on a single machine and want to stop and start the entire set at once. Read More

By Peter Cooper / September 25, 2006

Most init.d start-up scripts seem to be bash scripts, but you can write them with any language. Here’s some template code I use to create my own Linux services. You can even add them to chkconfig to be started properly on startup, and they’ll also work with RedHat / CentOS’s service system straight off.

(Update: January 2007, John Dewey warns me that this will not work on Solaris as it forces scripts to be run using /sbin/sh .. I guess a way around it would be to have a script in the middle that then calls Ruby, but it’s your call :)) Read More

#!/usr/bin/env ruby
#
# app_name This is a startup script for use in /etc/init.d
#
# chkconfig: 2345 80 20
# description: Description of program / service
APP_NAME = ‘app_name’
case ARGV.first
when ‘status’:
status = ‘stopped’

puts “#{APP_NAME} is #{status}”
when ‘start’: # Do your thang
when ‘stop’: # Do your thang
when ‘restart’: # Do your thang
end unless %w{start stop restart status}.include?

By Peter Cooper / September 25, 2006

It’s not a common pursuit but some developers would like to look through the source code to Ruby itself. It’s a great way to start if you ultimately want to get involved with helping develop Ruby itself, but it’s heavy stuff. Mauricio Fernandez, however, has put together a brief guide to the different source files you should read relating to different elements of functionality within Ruby. Experts only. Read More

By Peter Cooper / September 23, 2006

Metaprogrammingfun

Ola Bini, a Ruby developer from Stockholm, Sweden, has put together an excellent article about Ruby Metaprogramming Techniques. He looks at singleton classes, writing DSLs, dynamic class and module generation, fun with method_missing, method-pattern dispatchers, method replacement, null object refactoring, instance variable introspection, Procs and blocks, and bindings. It’s heavy stuff but presented in a surprisingly light and interesting way. Read More

By Peter Cooper / September 23, 2006

Mysqlanalyzerplugin

Bob Silva has put together a fine MySQL query analyzer plugin for Ruby on Rails. It uses MySQL’s EXPLAIN command to analyze all of the different SQL queries made by your Rails application (or, more accurately, by ActiveRecord!) and gives you the information you need to add better indexes (or add any extra indexes at all!) and could help show where a little custom SQL could silence a squeaky wheel. Read More

By Peter Cooper / September 21, 2006

Eric Hodel has looked at a new feature provided by Ruby 1.8.5 called Process::setrlimit. It makes it easy to limit the memory usage of your Ruby processes.. ideal if you’re experiencing memory leaks! Eric shows an example that’s as simple as adding this to your application’s environment.rb file:

Process.setrlimit Process::RLIMIT_RSS, 1024*1024*150, Process::RLIM_INFINITY

Of course, this isn’t a Rails only feature. Read More