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
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
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
# 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
# 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
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 a note stemming from a Twitter conversation with Alexis Richardson (@monadic). I was | |
complaining that the message queueing software I'd looked at solved a performance problem I | |
didn't have, and ignored an admin problem I did have. He challenged me to write up my | |
particular use case for the RabbitMQ engineers to think about. | |
This is very much a wish-list. Ideally I'd like a queueing solution to massage my back, and | |
make me hot chocolate too. The practical solution, however, probably lies somewhere between | |
this document and current message queueing systems. | |
# Message Queueing Meets SMS |
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
if RUBY_VERSION.starts_with?("1.8") | |
# This is a partial implementation of Fibers for Ruby 1.8 (they're normally | |
# a 1.9 only feature.) | |
# | |
# It does just enough to let me use it for testing some communications code. | |
# In particular, you can only have one Fiber alive at any given time! | |
# | |
# It uses continuations, so is probably pretty slow and memory hungry. | |
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 A | |
def hello | |
"A#hello" | |
end | |
def method_missing(method, *args) | |
"A#method_missing" | |
end | |
protected :hello |
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
# Here's some more hints at what's coming in Machinist 2. | |
Machinist::Collection.blueprint(:stuff) do | |
user | |
posts 3, :author => user | |
posts.each do |post| | |
comments 3, :post => post | |
end | |
end |