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 'sinatra' | |
class Main < Sinatra::Base | |
enable :static | |
set :public, 'public' | |
get '/' do | |
content_type 'application/xml' | |
twiml = %{<?xml version="1.0" encoding="UTF-8"?> | |
<Response> |
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 'rubygems' | |
require 'tweetstream' | |
require 'mongo' | |
CAMPUS_BBOX='39.447025911738,-0.35662933148245,39.470136313596,-0.33659356733534' | |
puts "Opening Mongo connection..." | |
conn = Mongo::Connection.new | |
db = conn.db("testdb") | |
tweets = db.collection("campus_tweets") |
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 'rubygems' | |
require 'sinatra' | |
require 'oauth' | |
require 'json' | |
require 'haml' | |
require 'ruby-debug' | |
enable :sessions | |
TWITTER_CONSUMER_KEY = "asac8z2Tw9XR2LflFmNVsw" |
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 ProcessTimeline | |
def perform(tweet, user) | |
log "received #{tweet.id} for user #{user}" | |
# if tweet.id was not stored before, store tweet in all_tweets_for process collection | |
# store pair [tweet.id, user.id] in tweets_for_user collection | |
end | |
end | |
class ProcessTweet | |
def perform(tweet) |
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
/* euclidean GCD (feel free to use any other) */ | |
function gcd(a,b) {if(b>a) {temp = a; a = b; b = temp} while(b!=0) {m=a%b; a=b; b=m;} return a;} | |
/* ratio is to get the gcd and divide each component by the gcd, then return a string with the typical colon-separated value */ | |
function ratio(x,y) {c=gcd(x,y); return ""+(x/c)+":"+(y/c)} | |
/* eg: | |
> ratio(320,240) | |
"4:3" | |
> ratio(360,240) |