Skip to content

Instantly share code, notes, and snippets.

@petewarden
petewarden / upgradecassandra.sh
Created December 5, 2011 22:56
How to upgrade a 0.8.1 Datastax Cassandra AMI to 0.8.7
# Grab the 0.8.7 binaries, you may need to use a more current mirror
curl -O "http://mirrors.ibiblio.org/apache//cassandra/0.8.7/apache-cassandra-0.8.7-bin.tar.gz"
tar -xzf apache-cassandra-0.8.7-bin.tar.gz
# Shut down Cassandra before changing anything, may take a minute or two
sudo service cassandra stop
# Make backups of the directories we'll be altering
sudo cp -R /usr/bin /usr/bin_original
sudo cp -R /usr/share/cassandra /usr/share/cassandra_original
@petewarden
petewarden / photoupload.rb
Created November 28, 2011 03:20
A demonstration of uploading images to Facebook using the Graph API from ruby
require 'rubygems' if RUBY_VERSION < '1.9'
require 'net/https'
require 'uri'
require 'multipart'
FACEBOOK_GRAPH_SERVER='https://graph.facebook.com'
def post_https(url, data, header)
@petewarden
petewarden / multipart.rb
Created November 28, 2011 03:14
A module to emulate a multipart form post in Ruby
# Takes a hash of string and file parameters and returns a string of text
# formatted to be sent as a multipart form post.
#
# Author:: Cody Brimhall <mailto:cbrimhall@ucdavis.edu>
# Created:: 22 Feb 2008
# Licensed under the WFTPL - http://stackoverflow.com/questions/184178/ruby-how-to-post-a-file-via-http-as-multipart-form-data
# http://sam.zoy.org/wtfpl/
require 'rubygems'
require 'mime/types'
@petewarden
petewarden / webpage2png.rb
Created November 28, 2011 02:44
An example of using PhantomJS from Ruby to do server-side rendering of a web page into a PNG
require 'rubygems' if RUBY_VERSION < '1.9'
require 'tempfile'
require File.join(ENV['JETPAC_PATH'], 'library/logger')
require File.join(ENV['JETPAC_PATH'], 'library/email')
def image_command(command)
log "IMG: Running '#{command}'"
result = system(command)
if !result
@petewarden
petewarden / extrapermomni.rb
Created November 28, 2011 01:55
Asking for extra permissions dynamically with OmniAuth in Sinatra
# This is called before the external site, so we can add dynamic Facebook permissions
# for example. See http://www.mikepackdev.com/blog_posts/2-dynamically-requesting-facebook-permissions-with-omniauth
get '/auth/:name/setup' do
if session[:extra_permissions]
request.env['omniauth.strategy'].options[:scope] = STANDARD_FACEBOOK_PERMISSIONS+','+session[:extra_permissions]
session.delete(:extra_permissions)
end
# This looks odd, but is the expected way to indicate success to Omniauth!
halt 404, 'Setup complete'
end