The easiest way to diff two strings in ruby

November 26, 2010

I just released version 2.0 of Diffy.

I wanted to make it dead simple to generate attractive diff output from within a ruby application.

Here’s how you use it:

$ sudo gem install diffy
$ irb
>> string1 = <<-TXT
>" Hello how are you
>" I'm fine
>" That's great
>" TXT
=> "Hello how are you\nI'm fine\nThat's great\n" 
>> string2 = <<-TXT
>" Hello how are you?
>" I'm fine
>" That's swell
>" TXT
=> "Hello how are you?\nI'm fine\nThat's swell\n" 
>> puts Diffy::Diff.new(string1, string2)
-Hello how are you
+Hello how are you?
 I'm fine
-That's great
+That's swell

It also will generate nice html for you:

>> Diffy::Diff.new(string1, string2).to_s(:html)
  • We were all having a good time.
  • Soon it was very late.
  • Time flies like an arrow” said I.
  • Fruit flies like a banana” I said.
  • Then I left.

You can find out more in the README

Adding Failover and Load Balancing to Thinking Sphinx

November 09, 2010

After we set up AboutUs’s search feature our (awesome) sysadmin wanted a redundant setup. He doesn’t like having to cancel his weekend if a box goes down. We talked about running an instance of HAProxy on all our app servers to load balance between two Sphinx servers, but that seemed heavy handed.

It turned out to be really easy to add this functionality to ThinkingSphinx (and the Riddle client it uses to talk to Sphinx).