Skip to content

Instantly share code, notes, and snippets.

View sco's full-sized avatar

Scott Raymond sco

View GitHub Profile
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,
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={})
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
#import "UINavigationBar+AFExtensions.h"
@implementation UINavigationBar (AFExtensions)
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
UIImage *image = [UIImage imageNamed:@"navbackground.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss" xmlns:activity="http://activitystrea.ms/spec/1.0">
<id>tag:gowalla.com,2009:/visits/all</id>
<title>Gowalla Checkins</title>
<updated>2010-02-02T09:59:14+00:00</updated>
<link rel="self" href="http://gowalla.com/visits/all.atom"/>
<link rel="alternate" href="http://gowalla.com/visits/all"/>
<author>
<name>Gowalla</name>
</author>
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss" xmlns:activity="http://activitystrea.ms/spec/1.0">
<id>tag:gowalla.com,2009:/visits/all</id>
<title>Gowalla Checkins</title>
<updated>2010-02-02T09:59:14+00:00</updated>
<link rel="self" href="http://gowalla.com/visits/all.atom"/>
<link rel="alternate" href="http://gowalla.com/visits/all"/>
<author>
<name>Gowalla</name>
</author>
class VisitorStats
def initialize
@redis = Redis.new
end
# every time there's a hit, increment a counter for the
# day and week, and add the session id to a set of unique
# vistitors for the day/week
def hit(session_id)
today = Date.today
"Beer To Beer Networking"
@sco
sco / gist:832414
Created February 17, 2011 19:13
Simple chronologic example
# Get an instance of the Chronologic client
chronologic = Chronologic::Client.new
# Cache metadata for users, spots, etc.
chronologic.object(:user_1, {:name => 'Scott Raymond'})
chronologic.object(:user_2, {:name => 'Josh Williams'})
chronologic.object(:spot_1, {:name => 'Gowalla HQ'})
# Create subscriptions when one user follows another, etc.
chronologic.subscribe(:user_2_friends, :user_1)
@sco
sco / gist:832499
Created February 17, 2011 19:48
Using XAuth to exchange username/password credentials for a OAuth access token
// UITextFieldDelegate method, called when the "Return" key is pressed.
// Either advance the cursor to the next empty field, or submit the form.
//
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if([usernameField.text length] == 0) {
[usernameField becomeFirstResponder];
} else if ([passwordField.text length] == 0) {
[passwordField becomeFirstResponder];
} else {