Roseanne - in browser comparison between two files

I telecommute 100% of the time at my current company. We make use of git and skype to communicate. If we need to share a bunch of code, we use remote branches (grb makes this super easy).

But when its only one file, the overhead is too much.

“Wait, wait. Let me create a remote branch - now I’m committing, now I’m pushing to the origin - there you go! Go ahead and pull.”

This can really break up the work flow.

To highlight what’s changed in the file and share it with my coworker, is this too much to ask? Now, of course, we could just pipe the diff into a file but then how do we transfer it? Use email? Ugh.

Definitely not.

Instead, let’s use a nice web service and paste two files. (On mac os x, check out cat some_file_name | pbcopy. very nifty). With one url, we can both insure we’re looking at the exact same diff.

Enter roseanne. If you’re a solo user, roseanne allows you to run a pure javascript diff (thanks to Chas Emrick. I “ported” it to use prototype). Or, you can submit the diff to the server.

Since Chas based his js diff lib off of Python’s sequence matcher and Test::Unit::Diff::SequenceMatcher is based off the same for the server side, I generate the JSON and store it in a couchdb at cloudant to save the view for later and share with others.

The app is hosted at heroku and is a rails app. Try it yourself.

Since the app is basically a simple proxy, I’m thinking of replacing it with a Sinatra app. Any thoughts? Is there something I could do to make it better?

Leave the first comment

Updating to Rails 2-3-stable

Here are the steps I followed to upgrade our flagship product.

Steps I had to take on the git repos:

verify that rake version is 0.8.4 and rubygems is 1.3.1
rm -rf vendor/rails
gem update rails rack
cd vendor && git clone git://github.com/rails/rails.git
cd rails && grb track 2-3-stable
git checkout 2-3-stable
rm -rf .git
cd ~/
modify environment.rb to user rails 2.3.2
rake rails:update
git add -A

Upgrade issues I ran into:

# check plugins/gems that need to be updated
# mocha
5076 rollbook:master+! % rake test:units
rake aborted!
can't activate mocha (= 0.9.4, runtime), already activated mocha-0.9.5
# move "require 'mocha'" from test/test_helper.rb into config/environments/test.rb
# http://gist.github.com/111060 -- solution: remove "require 'ar-extensions" from config/initializers/.rb
# remove all references to Test::Unit http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/f90ecdba834c2ef8/f204e834e5e0303c?lnk=raot in test dir
# replace Test::Unit w/ActiveRecord or ActionController as appropriate
# replace CGI::Session.generate_unique_id w/ActiveSupport::SecureRandom.hex(16)
# updated hoptoad and shoulda
# add xmlsimple to be required
# updated new_relic agent
# install country_select plugin

Steps to be take on the production server:

# update passenger 2.2.2
# gem update rails rack
Leave the first comment

Monitoring BackgrounDRb workers with God

Updated 2008/09/24 for latest version of backgroundrb 1.0.4

The other day on our staging server, I noticed that the BackgrounDRb queue worker had died. As it turned out, the queue worker had died over 3 months ago!!

There was no cause for alarm as the staging server isn’t critical but this did start me to worrying. We needed to implement a monitoring solution which not only verified that BackgrounDRb was running but also that particular workers were running.

As we had just implemented god monitoring with a custom condition for another issue, its a slam dunk to do the same again. (Thanks to Jesse Newland and his god tutorial at AtlRUG.)

Here’s the configuration file that got it done for us.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#run on command line with 'god -c backgroundrb.god -D' 
RAILS_ROOT = '/var/www/rails/rollbook/current'
 
#load required rails and backgroundrb files
require File.dirname(__FILE__) + '/../boot'
require File.dirname(__FILE__) + '/../environment'
require 'erb'
$LOAD_PATH << "#{RAILS_ROOT}/vendor/plugins/backgroundrb/lib"
require "#{RAILS_ROOT}/vendor/plugins/backgroundrb/lib/backgroundrb.rb"
 
#create custom condition for checking that QueryProcessingWorker is running
MiddleMan = BackgrounDRb::ClusterConnection.new
module God 
  module Conditions
    class Backgroundrb < PollCondition
      def initialize; super; end 
      def valid?; true; end 
 
      def test
        begin
          queue_worker = MiddleMan.all_worker_info.values.flatten.select { |w| :queue_processing_worker == w[:worker] }
          queue_worker.empty?
        rescue #if all_worker_info raises exception, then bdrb isn't running and we were unable to connect
          true
        end 
      end 
    end 
  end 
end
 
God.watch do |w| 
  w.name      = 'backgroundrb'
  w.interval  = 1.minute
  w.restart   = "cd #{RAILS_ROOT} && #{RAILS_ROOT}/script/backgroundrb -e production stop && #{RAILS_ROOT}/script/backgroundrb -e production start"
  w.stop      = "cd #{RAILS_ROOT} && #{RAILS_ROOT}/script/backgroundrb -e production stop"
  w.start     = "cd #{RAILS_ROOT} && #{RAILS_ROOT}/script/backgroundrb -e production start"
  w.grace     = 1.minute
  w.pid_file  = "#{RAILS_ROOT}/tmp/pids/backgroundrb_11000.pid"
 
  w.start_if do |start|
    start.condition(:process_running) do |c| 
      c.running  = false
    end 
  end 
 
  w.restart_if do |restart|
    restart.condition(:backgroundrb) do |c| 
      #just restart it
    end 
  end 
end

In the select call on line 21, you can modify the condition to access :job_key or :status as well. Obviously, you need to modify RAILS_ROOT for your situation.

If you have suggestions for improvement or questions, hit me up in the comments. Enjoy!

3 comments so far, add yours

Ack, a better grep for coders in 3 easy steps

Ack has this nice colorized output when searching code files. Some may say that grep can do the same thing (it can), but there’s no need for arg’ing it up with ack. There’s a similar ruby version, rak, but I’ve heard it isn’t quite as fast as ack. Ack works well enough for me and the install process isn’t that painful.

There’s two ways to install listed over at ack; I chose the CPAN route (since I never know when I’ll need to install some more perl goodies).

How to install ack on Mac OS X leopard in 3 easy steps.

  1. install mac ports
  2. sudo port install perl5.8
  3. sudo cpan -i App::Ack
One comment so far, add another