Skip to content

Instantly share code, notes, and snippets.

View scpike's full-sized avatar

Stephen Pike scpike

View GitHub Profile
@scpike
scpike / open_cookie.rb
Created June 28, 2012 00:04
Rails 3 cookie decode
@scpike
scpike / foursquare_push.rb
Created January 31, 2012 16:02
Create checkin from foursquare push
def foursquare_push
# params[:checkin] is a foursquare-provided JSON object
checkin_hash = ActiveSupport::JSON.decode(params[:checkin])
# Look up the user based on foursquare ID
user = User.find_by_foursquare_id(checkin_hash["user"]["id"])
if user
# Create a new checkin, set its parameters from the hash
# foursquare sent us. Check for dups
@scpike
scpike / pull_checkins.rb
Created January 31, 2012 15:59
Pull foursquare checkins
def get_checkins()
foursquare_client = get_foursquare_client()
foursquare_client.user_checkins[:items].each do |checkin|
# Check if checkin already stored for de-dup purposes
next if Checkin.find( :first, :conditions => { :checkin_id => checkin.id })
c = Checkin.new(:user => self, :action => action)
c.set_checkin_data(checkin)
c.save()
end
end
@scpike
scpike / twilio_directions.rb
Created January 27, 2012 15:56
Handle phone input with twilio
def directions
if params["Digits"] == '1'
response = Twilio::TwiML::Response.new do |r|
r.Record :action => '/handle_recording'
end
elsif params["Digits"] == '2'
# Need to return immediately after a redirect
redirect_to :action => 'handle_call'
return
else
@scpike
scpike / handle_call.rb
Created January 27, 2012 15:51
Handle a response from twilio
def handle_call
call_sid = params["CallSid"]
checkin = Checkin.find_by_twilio_call_id(call_sid)
if checkin
response = Twilio::TwiML::Response.new do |r|
r.Pause :length => 1 # Found that people like to say "Hello" when they pick up
# Separate controller action 'directions' handles your button presses
r.Gather :action => directions_path, :numDigits => 1 do |r|
@scpike
scpike / twilio_call.rb
Created January 27, 2012 15:47
Make a phone call with twilio
def twilio_call
twilio_client = Twilio::REST::Client.new(TWILIO_CLIENT_ID, TWILIO_CLIENT_SECRET)
# Make the call
call = twilio_client.account.calls.create( :from => '12018774274', :to => user.mom_phone_number, :url => 'http://hashtagmom.com/handle_call' )
# Store the SID from Twilio for use in later lookups
self.twilio_call_id = call.sid
save
end
@scpike
scpike / Deploy
Created November 23, 2011 00:42 — forked from coop/Deploy
Deploy to S3 - Asset Pipeline, S3 and Heroku
namespace :deploy do
desc "Deploy to Heroku"
task :heroku do
Rake::Task["deploy:precompile_assets_and_upload_to_s3"].invoke
Rake::Task["deploy:push_heroku"].invoke
end
desc "Precompile assets and upload to s3"
task :precompile_assets_and_upload_to_s3 do
storage = Fog::Storage.new :provider => 'AWS', :aws_access_key_id => "123", :aws_secret_access_key => "123"