Skip to content

Instantly share code, notes, and snippets.

View notahat's full-sized avatar

Pete Yandell notahat

View GitHub Profile
#include <AikoEvents.h>
using namespace Aiko;
class BlinkHandler : public Handler {
BlinkHandler(int pin) {
pin_ = pin; status_ = LOW;
}
void init() {
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]
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
@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
# 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.
class MessageQueue < ActiveRecord::Base
...
end
module AlternateConnection
MessageQueue = ::MessageQueue.clone
class MessageQueue
establish_connection :test_alternate
end
end
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
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.
class A
def hello
"A#hello"
end
def method_missing(method, *args)
"A#method_missing"
end
protected :hello
# 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