Skip to content

Instantly share code, notes, and snippets.

@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"
@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 / 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_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 / 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 / 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 / open_cookie.rb
Created June 28, 2012 00:04
Rails 3 cookie decode
@scpike
scpike / copy-s3-bucket.rb
Created September 18, 2012 20:26 — forked from scharfie/copy-s3-bucket.rb
Copy contents of an S3 bucket to a another bucket using an EC2 instance and a simple Ruby script. Useful for transferring large amounts of data and will work across geographic regions.
require 'rubygems'
require 'right_aws'
require 'yaml'
filename = ENV['FILE'].to_s
source = ENV['FROM'].to_s
destination = ENV['TO'].to_s
dry_run = true
puts "Please provide filename of s3 configuration" and exit(1) if filename == ""
@scpike
scpike / copy-s3-bucket.rb
Created September 18, 2012 20:26 — forked from scharfie/copy-s3-bucket.rb
Copy contents of an S3 bucket to a another bucket using an EC2 instance and a simple Ruby script. Useful for transferring large amounts of data and will work across geographic regions.
require 'rubygems'
require 'right_aws'
require 'yaml'
filename = ENV['FILE'].to_s
source = ENV['FROM'].to_s
destination = ENV['TO'].to_s
dry_run = true
puts "Please provide filename of s3 configuration" and exit(1) if filename == ""
@scpike
scpike / copy-s3-bucket.rb
Created September 18, 2012 20:29 — forked from scharfie/copy-s3-bucket.rb
Copy contents of an S3 bucket to a another bucket using an EC2 instance and a simple Ruby script. Maintains acl
require 'rubygems'
require 'right_aws'
aws_access_key_id = ''
aws_secret_access_key = ''
target_bucket = 'bucket_with_data_to_copy'
destination_bucket = 'to_copy_into'
s3 = RightAws::S3Interface.new(aws_access_key_id, aws_secret_access_key)