Skip to content

Instantly share code, notes, and snippets.

View arfon's full-sized avatar
:shipit:

Arfon Smith arfon

:shipit:
View GitHub Profile
@arfon
arfon / S3 uploader
Created December 10, 2009 15:51
Upload all files in directory to S3
require "rubygems"
require "net/http"
require "uri"
require "aws/s3"
AWS::S3::Base.establish_connection!(
:access_key_id => 'ACCESS KEY',
:secret_access_key => 'SECRET KEY'
)
def new_method
puts "YEAH"
end
@arfon
arfon / create_table_composite_primary.rb
Created January 21, 2012 02:35
AWS DynamoDB table creation (composite primary_key)
require 'aws-sdk'
AWS_ACCESS_KEY = 'your_aws_access_key'
AWS_SECRET_KEY = 'your_aws_secret_key'
dynamo_db = AWS::DynamoDB.new(:access_key_id => AWS_ACCESS_KEY, :secret_access_key => AWS_SECRET_KEY)
# create a table (50 read and 50 write capacity units)
# create composite index using hash_key (:user_id) and range_key (:created_at)
@arfon
arfon / create_table_hash_key.rb
Created January 21, 2012 02:44
AWS DynamoDB table creation (simple primary_key)
require 'aws-sdk'
AWS_ACCESS_KEY = 'your_aws_access_key'
AWS_SECRET_KEY = 'your_aws_secret_key'
dynamo_db = AWS::DynamoDB.new(:access_key_id => AWS_ACCESS_KEY, :secret_access_key => AWS_SECRET_KEY)
# create a table (50 read and 50 write capacity units)
# create primary key index using hash_key (:id)
@arfon
arfon / gop_simple.rb
Created January 21, 2012 03:37
Simple Twitterstream example
require 'tweetstream'
TweetStream.configure do |config|
config.consumer_key = 'consumer_key'
config.consumer_secret = 'consumer_secret'
config.oauth_token = 'oauth_token'
config.oauth_token_secret = 'oauth_token_secret'
config.auth_method = :oauth
config.parser = :json_pure
end
@arfon
arfon / twitterstream_dynamodb.rb
Created January 21, 2012 03:45
Simple Twitterstream writing to DynamoDB
require 'aws-sdk'
require 'eventmachine'
require 'tweetstream'
AWS_ACCESS_KEY = 'your_aws_access_key'
AWS_SECRET_KEY = 'your_aws_secret_key'
dynamo_db = AWS::DynamoDB.new(:access_key_id => AWS_ACCESS_KEY, :secret_access_key => AWS_SECRET_KEY)
table = dynamo_db.tables['tweets']
@arfon
arfon / tweet_counter.rb
Created January 21, 2012 12:42
Tweet counter
require 'aws-sdk'
AWS_ACCESS_KEY = 'your_aws_access_key'
AWS_SECRET_KEY = 'your_aws_secret_key'
dynamo_db = AWS::DynamoDB.new(:access_key_id => AWS_ACCESS_KEY, :secret_access_key => AWS_SECRET_KEY)
table = dynamo_db.tables['tweets']
# don't forget to load the schema
table.load_schema
@arfon
arfon / em_tweetstreamer.rb
Created January 21, 2012 12:54
Tweet parsing with EventMachine
require 'aws-sdk'
require 'eventmachine'
require 'tweetstream'
AWS_ACCESS_KEY = 'your_aws_access_key'
AWS_SECRET_KEY = 'your_aws_secret_key'
dynamo_db = AWS::DynamoDB.new(:access_key_id => AWS_ACCESS_KEY, :secret_access_key => AWS_SECRET_KEY)
table = dynamo_db.tables['tweets']
@arfon
arfon / sample_queries.rb
Created January 21, 2012 15:41
Sample queries
require 'aws-sdk'
AWS_ACCESS_KEY = 'your_aws_access_key'
AWS_SECRET_KEY = 'your_aws_secret_key'
dynamo_db = AWS::DynamoDB.new(:access_key_id => AWS_ACCESS_KEY, :secret_access_key => AWS_SECRET_KEY)
table = dynamo_db.tables['tweets']
table.load_schema
results = ActiveRecord::Base.connection.execute("select light_curve_id from classifications where zooniverse_user_id=#{user.id}")
results.each { |r| ids << r.first }
ids_to_process = ids.flatten.uniq
require 'enumerator'
unless ids.empty?
ids.each_slice(1000) do |a|
RedisConnect.redis.sadd("zooniverse_user_#{user.id}", *a)
end
end