Skip to content

Instantly share code, notes, and snippets.

@gma
gma / card_creator.rb
Created July 6, 2012 17:29
Exceptions and the observer pattern
class CardCreator
include Publisher
def create(iteration, attributes)
card = iteration.cards.build(attributes)
card.save!
rescue ActiveRecord::RecordInvalid
notify_subscribers(:create_failed, card)
else
notify_subscribers(:created, card)
@gma
gma / card_creator.rb
Created July 6, 2012 17:00
Moving response callbacks out of controller
class CardCreator < Struct.new(:listener)
def create(iteration, attributes)
card = iteration.cards.build(attributes)
if card.save
listener.created(card)
else
listener.create_failed(card)
end
end
end
/* Multiget web service, written in Node
http://127.0.0.1:9001/?urls=http://example.com/,http://example.net/
Will fetch all URLs in parallel, then return a JSON response containing
the fetched content from them.
*/
var DEFAULT_TIMEOUT = 10000;