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 Order < ActiveRecord::Base | |
SECRET = '3a9392e86049546fcff5e21e3c89564deb8bd9d4' | |
def self.find_by_token(token) | |
id, sig = token.split('-') | |
record = find(id) | |
if record.nil? || token != record.token | |
raise ActiveRecord::RecordNotFound, "invalid sig" | |
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
class JobQueue | |
def initialize(name, options={}) | |
@key = [:job_queue, Merb.env, name].join | |
@queue = SQS.queue(@key, true, 200) | |
@cache = options[:cache] || CACHE | |
@logger = options[:logger] || Merb.logger | |
end | |
def push(options={}) |
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 WebHook < ActiveRecord::Base | |
class << self | |
# Pushes a job onto a queue | |
def visit!(visit) | |
JobQueue.new(:events).push({ | |
:type => 'visit', | |
:visit_id => visit.id, | |
:user_id => visit.user_id, |
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
# Lo-fi client for the Facebook API. E.g.: | |
# | |
# fb = FacebookClient.new(:api_key => 'api-key', :secret => 'secret') | |
# fb.call 'users.getInfo', :session_key => 'session-key', :uids => 'user-id', :fields => 'birthday' | |
# | |
# by Scott Raymond <[email protected]> | |
# Public Domain. | |
# | |
class FacebookClient | |
def initialize(default_params={}) |
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 'memcached' | |
# Provides a hybrid of memoization and memcacheing. Designed for storing an entire (small) | |
# table in memory, in every instance of the app. Works well for reference-type tables | |
# (e.g., Category) which won't ever get big or change often, but are read-heavy. This | |
# allows you to avoid joins, but also avoid the n+1 queries antipattern. | |
# | |
# A pure memoization solution fails when the data *does* change -- all app instances have | |
# to be restarted for the in-memory caches to be correct. A pure memcached solution solves | |
# that, but requires a largish amount of data to be retrieved from memcached for every |
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
// | |
// StompService.h | |
// Objective-C Stomp Client | |
// | |
// Implements the Stomp Protocol v1.0, as described here: http://stomp.codehaus.org/Protocol | |
// Requires the AsyncSocket library: http://code.google.com/p/cocoaasyncsocket/ | |
// | |
// This class is in the public domain. | |
// by Scott Raymond <[email protected]>. | |
// |
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 'net/http' | |
require 'rubygems' | |
require 'json' | |
# Mimics the interface of RightAws::SdbInterface, using CouchDB for persistence. | |
# | |
# FS = FakeSimpleDB.new('myapp') | |
# FS.create_domain('mydb') | |
# FS.put_attributes('mydb', 'myitem', { 'Jon' => ['foo', 'bar'] }) | |
# FS.get_attributes('mydb', 'myitem') |