Articles

Uniq for Array or Hash with a Deeply Nested Structure

Most people have had some experience with ruby’s built in #uniq method for Arrays. Internally, this method finds the unique items in the array by creating a hash internally, and this internal comparison is done with the #eql? method. If an item in the array is a Hash, then #eql? simply uses the object_id, generated by the #hash method, to determine whether it is equal to another object in the array. There are many solutions online each with s light variations and goals.

reboot

My blog had been running on an ancient web host account for years without incident, when one day, my mongrels collapsed. However, I was extremely busy, and even a little apathetic towards the site. The holiday break gave me a chance to move it the content over to a modern install of Mephisto. If you’re actually visiting the site, you’ll notice I even barreled through a new CSS setup with Blueprint as my wingman. However, I’m still missing some things:

is LOST on yet?

I needed to know, so I wrote one of those trendy single page apps: is LOST on yet?. Naturally, the source is on github. It’s really pretty amazing actually:

def is_lost_on_yet?
  @is_lost_on_yet ||= {:answer => "no", :reason => "returns on Jan 21st, 9PM ET"}
end

I have about 20 days to finish the site :)

Update: I forgot to mention, it even has JSON support!

Blog focus

I'm going to change the focus of this blog. Not that it ever really had much focus before, but it was called 'Rails Tales' and my plan was to talk about developing applications with Ruby on Rails. But lately, at Entertonement (where I'm a web developer), I've been more interested on understanding our users and decreasing bounce rate. This has revealed some interesting things that I want to

Integrating Mint and Mephisto

John Nunemaker, top ruby blogger of 2008, just posted about RailsTips.org’s awesomely expanded footer. If you click through to the full post, you’ll see his custom plugin pulling the most popular articles from his Mint stats.

Welcome to the New Site

I’ve maintained a blog since sometime in May of 2005. As with many blogs, posting regularity varied. Sometimes it was daily, sometimes a month or two would go by with nothing new at all.

This is something different.

The content on the old site changed over time, just like it’s author. Interests come and go, technologies that were once shiny and new have lost some of their shine. I stopped writing short posts that were mostly links to other people’s content, and starting writing longer articles. I did some interviews, and a bunch of book reviews.

Refreshed, realigned and ready for 2009

It was over 2.5 years ago I did anything major to toolmantim.com. For the last 2.4 years I’ve wanted to redesign it and the past 1.5 years I’ve wanted to re-code it.

Wrapping a Method in Ruby

Let’s say you have a Ruby class with a method you’d like to wrap—for debugging or performance timing—and, since you don’t control where the class is instantiated (think overriding a method in Rails’ ActionPack), just creating a subclass and using super isn’t going to work.

Let’s take a look at two mixin patterns; one a ubiquitous naming hack and one a bit of esoteric Ruby inheritance trickery.

First, let’s set the scene. Let’s say we have a method, Widget#render_on:

router plugin released, hacking, and magic

Today I (finally) released my Rails router implementation as a plugin named krauter (all apologies to any German citizen who may be offended!  I didn't mean to be a racis– er...nationalist?).   Take a look at the code over at my Github account: http://github.com/jeremymcanally/krauter

I'm also hacking on a few other projects you should be looking for soon if you're interested...

Rspec domination

Wycats is pushing this poll everywhere. As of Jan 02, RSpec is dominating at 53%

Wonder if this means anything for the future of the Rails default test framework…?

How Ruby Manages Memory and Garbage Collection | Rails Fire

How Ruby Manages Memory and Garbage Collection

garbage.jpgGarbage Collection and the Ruby Heap is a presentation given by Joe Damato and Aman Gupta at the recent LA Ruby Conference. You only get the slides for now (all 70 of them!), but they're very detailed and can almost work as a standalone concise e-book on Ruby's garbage collection system.

Joe and Aman take a look at C memory management vs Ruby and show the difference between the stack and the heap. As a garbage collected language, Ruby takes the easy route by putting everything on the heap and the presentation demonstrates how the MRI (Matz's Ruby 1.8) does this, as well as how objects are tracked within memory (right down to the underlying C structs).

cvsruby.png

MRI's garbage collection scheme isn't particularly well optimized (though Phusion's Ruby Enterprise Edition has made some tweaks) and the presentation demonstrates the viability of some other garbage collection schemes (as always, the issue is compatibility with native extensions).

The presentation finishes off with a interesting walkthrough of using memprof (a Ruby memory profiler) to debug a memory leak in Rails 3.

[e-book] The Rails 3 Upgrade Handbook by Jeremy McAnally is a 120 page guide on migrating your apps from Rails 2.x to Rails 3.0. There's a review of it on Rails Inside if you want to learn more.