Posted by kev Tue, 30 Oct 2007 01:16:00 GMT

I haven’t yet decided if this is a good idea or not.

I’ll be at RubyConf this weekend. Say hello, if you get the urge.

require "test/unit"
require 'rubygems'
require 'mocha'
require 'stubba'

module ForwardsToEnumerable
  def self.included(klass)

  module ClassMethods
    def forward_to_enum(instance_var, *meths)
      meths.each do |meth|
        class_eval <<-METH
          def #{meth}(*args, &block)
            #{instance_var.to_s}.each do |i|
              i.send(:#{meth}, *args, &block)


class ForwardsToArray
  include ForwardsToEnumerable
  forward_to_enum :@array, :foo, :bar, :baz

  def initialize(array)
    @array = array

class TestForwardsToArray < Test::Unit::TestCase
  def test_forward_to_enum
    items = [mock(), mock(), mock()]
    items.each {|i| i.expects(:foo); i.expects(:bar); i.expects(:baz) }
    f =

Posted in ,  | no comments

RPM Version Comparison Revisited

Posted by kev Fri, 21 Sep 2007 20:21:00 GMT

# Equivalent to rpmvercmp in librpm, eccentricities and all
def <=>(other)
  return 0 if self.version == other.version and self.rel == other.rel

  versions = self.version.split(/[^[:alnum:]]/).push self.rel
  other_versions = other.version.split(/[^[:alnum:]]/).push other.rel

  return  1 if versions.size > other_versions.size
  return -1 if versions.size < other_versions.size

  versions.size.times do |n|
    if versions[n] =~ /[^\d]/ && other_versions[n] =~ /[^\d]/
      comparison = (versions[n] <=> other_versions[n])
    elsif versions[n] !~ /[^\d]/ && other_versions[n] !~ /[^\d]/
      comparison = (versions[n].to_i <=> other_versions[n].to_i)
      comparison = -1
    return comparison unless

  return 0 

Original version sort was here.

Posted in ,  | no comments

<3 rpm version comparison

Posted by kev Wed, 19 Sep 2007 21:19:00 GMT

/* take care of the case where the two version segments are */
/* different types: one numeric and one alpha */
if (one == str1) return -1; /* arbitrary */
if (two == str2) return -1;

– rpm/lib/misc.c

Posted in ,  | no comments

Johnathan Coultan

Posted by kev Wed, 19 Sep 2007 18:23:00 GMT

Geeky, catchy music. So awesome. If you’ve heard “Areas of My Expertise”, this is Hodgeman’s buddy. (via Wanstrath)

Posted in  | no comments


Posted by kev Wed, 19 Sep 2007 07:35:00 GMT


git daemon --verbose --reuseaddr --export-all --base-path='.'
sisyphus:~/code/god kev$ git quickserver
sisyphus:~ kev$ git clone git://localhost/ somethin
Initialized empty Git repository in /Users/kev/somethin/.git/
remote: Generating pack...
remote: Done counting 1469 objects.
remote: Deltifying 1469 objects...
 100% (1469/1remote: 469) done
Indexing 1469 objects...
remote: Total 1469 (delta 905), reused 1461 (delta 902)
 100% (1469/1469) done
Resolving 905 deltas...
 100% (905/905) done

(via KirinDave)

Posted in  | no comments

Code Personified

Posted by kev Thu, 13 Sep 2007 20:31:00 GMT

if self.stillHopeful:
    # oh, cruel reality cuts deep. no joy for you. This is the
    # first failure. This flunks the overall BuildSet, so we can
    # notify success watchers that they aren't going to be happy.
    self.stillHopeful = False

– Buildbot Source

Posted in  | no comments

Snippet: SVN Info Parsing with YAML

Posted by kev Fri, 17 Aug 2007 23:44:00 GMT

require 'yaml'
require 'pp'
pp YAML.load(`svn info`) # =>
# {"Node Kind"=>"directory",
#  "Last Changed Author"=>"nzkoz",
#  "URL"=>"",
#  "Schedule"=>"normal",
#  "Last Changed Rev"=>7332,
#  "Repository UUID"=>"5ecf4fe2-1ee6-0310-87b1-e25e094e27de",
#  "Repository Root"=>"",
#  "Last Changed Date"=>"2007-08-16 18:11:11 -0700 (Thu, 16 Aug 2007)",
#  "Revision"=>7340,
#  "Path"=>"."}

Posted in  | 5 comments

Ruby Syslog README

Posted by kev Wed, 25 Jul 2007 18:21:00 GMT

I hate the fact that googling syslog ruby didn’t turn up anything useful, and the rdoc doesn’t seem to be there. So, I’m posting the README from the extension in Ruby’s source. This is as much for me as for you. Using PageRank for good is.. well.. good I’d assume.


Posted in ,

Powerset to Launch Front-end on Ruby

Posted by kev Thu, 21 Jun 2007 16:41:00 GMT

Spread the word on digg

Powerset is fairly well-known in the Ruby community, but there’s a certain amount of confusion as to what we use it for. As a consequence, I’m regularly asked what the front end is going to be written in, and just as regularly have to leave the question unanswered. But today I’m happy to announce that we are, in fact, launching our front-end on Ruby.

Cool, huh? For everyone’s sanity (and in avoidance of some of the flame wars to ensue), do note that we are going to be using Ruby (the language) but not necessarily Ruby on Rails (the web framework).

In the spirit of Powerset’s new found openness, I’d like to take some time to explain why we’re making this decision where others might not.

Why Ruby?

1. We’ve already got the brains

One thing we haven’t kept secret is that we’ve hired some of the best Ruby developers around. Our total number of day in day out Ruby developers is somewhere around 10, and I’m constantly humbled to be working with this team. We’ve got the people and they have the skills, so it makes sense to apply them.

The part of Powerset Ruby we could round up

2. Ruby is already being used throughout the company

We’ve always spoken in general terms about how much Ruby is being used internally, but let’s get specific: a substantial part of our infrastructure is being written in Ruby or being accessed through Ruby services. Our scientists use Ruby to interact with our core language technology. Our packaging infrastructure is Ruby. A big portion of our system administration work is all done with Ruby. Frankly, we as an organization use Ruby a whole heck of a lot.

Additionally, all of our product demos and prototypes are also in Ruby. We’ve got an interesting mix of Rails, Merb and Camping apps (depending on the scope of the project) connecting to tiny Ruby services which hook into our various back-end systems. Day to day, the majority of the product team is hacking in Ruby in some capacity.

3. We’re not worried about scaling

So, inevitably, whenever we talk about Ruby or Rails scaling these days someone brings up Twitter and its scaling problems in the past. Twitter is right down the block from our offices and I know several of the devs personally, so before we made a final decision I arranged a sit down with Twitter’s lead developer, Blaine Cook, to talk about the situation. Blaine was kind enough to let me bring along our Search Architect (and former search architect at Yahoo!) Chad Walters , our Head of Product Scott Prevost, and our COO Steve Newcomb, to poke and prod and get their questions answered. The simple fact is that Ruby wasn’t the source of Twitter’s woes. As it often happens with rapidly growing sites, they ran into architectural problems. Some design decisions don’t hurt until they reach a massive scale and at that point you have to rethink your approach. In an email he writes:

For us, it’s really about scaling horizontally - to that end, Rails and Ruby haven’t been stumbling blocks, compared to any other language or framework. The performance boosts associated with a “faster” language would give us a 10-20% improvement, but thanks to architectural changes that Ruby and Rails happily accommodated, Twitter is 10000% faster than it was in January

This is great news for Twitter, but even better for us because we don’t have the bottle necks that they’ve struggled with – databases, instant messaging servers, and regularly recycling cache systems – which makes scaling horizontally much much smoother. At that point, our scaling issue doesn’t concern Ruby. For a search engine, the front-end is largely just a templating system and the real work happens in the back when we process your query.

What does this mean for the community?

When writing this article, at some point I had to sit down and ask myself why anyone should care we’re adopting Ruby for the front-end. For me, it comes down to the fact that we’re good for the community as a whole.

First off, the fact that Powerset is deploying on Ruby means you’ve got one more high traffic site (potentially very high traffic) using Ruby in production. It’s one more case study, and one more example that Ruby as a whole is ready for the big show.

Personally, I think the more interesting and useful thing to take away from this is that as we do the heavy lifting, building up infrastructure around all the aspects of Ruby development and deployment in the company, we’re selecting large chunks to be open-sourced. I’ve got a list of things I’d love to put out into the wild (which is encouraged, and actually suggested by my manager. Man, I love this place) as soon as I can find the time. Already Tom Werner and Dave Fayram have pushed out Ruby to Erlang bindings and a sweet little (in-development) web server called Fuzed, I’ve gotten to hack at Merb, and a fair about of Rails patches have come directly from work in-house. Hopefully the community will be able to benefit from our code as much as we have.

Obviously we don’t have a search product open to the public yet, but we’ll be launching Powerlabs in September. In Powerlabs, you’ll be able to play with our products and give us feedback. If you want to keep track of what Powerset is doing, sign up.

Posted in ,  | 4 comments

Ruby Gotcha of the Day: String Ranges

Posted by kev Wed, 20 Jun 2007 19:05:00 GMT

Spot the pattern?

# => ["1", "2", "3", "4", ..... "10"]

# => []

# => ["2", "3", "4", "5", ..... "20"]

# => []

# => ["3", "4", "5", "6", ..... "30"]

# => []

# => ["4", "5", "6", "7", ..... "40"]

# => [2, 3, 4, 5, 6, 7, 8, 9, 10]

('2'.to_i .. '10'.to_i).to_a
# => [2, 3, 4, 5, 6, 7, 8, 9, 10]

Posted in ,  | 5 comments

Older posts: 1 2 3 4 ... 17