Skip to content

Instantly share code, notes, and snippets.

View dsshap's full-sized avatar

Dave Shapiro dsshap

View GitHub Profile
@chaslemley
chaslemley / dynamoDB_example.rb
Created January 23, 2012 15:17
Example of using Amazon's DynamoDB to store user activity
require "aws-sdk"
class Dynamo
attr_accessor :attributes
def initialize(hash)
raise ArgumentError, "argument passed to .new must be a Hash" unless hash.is_a? Hash
raise ArgumentError, "hash must contain key :#{self.class.hash_key}" unless hash.has_key? self.class.hash_key.to_sym
raise ArgumentError, "hash must contain key :#{self.class.range_key}" unless self.class.has_range_key? && hash.has_key?(self.class.range_key.to_sym)
@attributes = {}
@jwo
jwo / registrations_controller.rb
Created September 30, 2011 23:11
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else