Skip to content

Instantly share code, notes, and snippets.

View notahat's full-sized avatar

Pete Yandell notahat

View GitHub Profile
class MessageQueue < ActiveRecord::Base
...
end
module AlternateConnection
MessageQueue = ::MessageQueue.clone
class MessageQueue
establish_connection :test_alternate
end
end
# This is my home-grown solution for implementing the model end of
# a multi-step form in Rails.
#
# There's a step attribute on the model, and the after_step method
# lets me limit validations to only occur after a particular step.
#
# I have to be careful in the controller to make sure the right
# attributes are set at each step, and that the step attribute can't
# be hacked.
@notahat
notahat / gist:124652
Created June 6, 2009 02:59
Example of how Machinist handles model associations
# Let's say we have some really simple models for a blog. (I'm using
# DataMapper here, but Machinist works exactly the same way with ActiveRecord.)
class Person
include DataMapper::Resource
property :id, Serial
property :name, String
end
class Post
it "should support single-table inheritance" do
Person.blueprint { name "Fred" }
Admin.blueprint { name "Bill" }
person = Person.make
person.should_not be_new_record
person.name.should == "Fred"
person.type.should == nil
admin = Admin.make
module SExpression
def self.parse(s)
result, _ = scan(s, 0)
result
end
def self.scan(s, i)
i = skip_whitespace(s, i)
case s[i,1]
#include <AikoEvents.h>
using namespace Aiko;
class BlinkHandler : public Handler {
BlinkHandler(int pin) {
pin_ = pin; status_ = LOW;
}
void init() {
require 'test/unit'
require 'enumerator'
class Array
def in_chunks_of(size_of_chunks)
enum_slice(size_of_chunks).to_a
end
end
class TestArrayInChunks < Test::Unit::TestCase
#include <avr/interrupt.h>
union TimerCounter {
struct {
unsigned int interval_count_lo, interval_count_hi;
unsigned char overflow_countdown;
};
unsigned long interval_count;
};
My traceroute [v0.75]
maxwell.local (0.0.0.0) Fri Mar 27 20:56:20 2009
Keys: Help Display mode Restart statistics Order of fields quit
Packets Pings
Host Loss% Snt Last Avg Best Wrst StDev
1. 192.168.1.254 0.0% 70 1.9 2.9 1.8 12.4 2.1
2. loop0.lns10.mel4.internode.on.ne 0.0% 70 12.0 8.8 7.3 14.7 1.6
3. vl13.cor3.mel4.internode.on.net 0.0% 70 7.8 9.1 7.5 16.3 1.8
4. pos8-0.bdr1.syd7.internode.on.ne 0.0% 70 179.6 185.3 177.6 327.6 24.7
5. pos5-0.bdr1.sjc2.internode.on.ne 0.0% 70 180.2 179.4 177.3 205.0 3.8
The Ruby daemons gem, as used by daemontools, does this to restart daemons:
@group.stop_all
sleep 1
@group.start_all
The stop_all method does not wait for the daemon to exit before returning.
Anyone see the huge glaring problem here? *grumble*