This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MessageQueue < ActiveRecord::Base | |
... | |
end | |
module AlternateConnection | |
MessageQueue = ::MessageQueue.clone | |
class MessageQueue | |
establish_connection :test_alternate | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <AikoEvents.h> | |
using namespace Aiko; | |
class BlinkHandler : public Handler { | |
BlinkHandler(int pin) { | |
pin_ = pin; status_ = LOW; | |
} | |
void init() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/interrupt.h> | |
union TimerCounter { | |
struct { | |
unsigned int interval_count_lo, interval_count_hi; | |
unsigned char overflow_countdown; | |
}; | |
unsigned long interval_count; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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* |