Skip to content

Instantly share code, notes, and snippets.

View sterrym's full-sized avatar

Tim Glen sterrym

  • Shopify Inc
  • Ontario, Canada
View GitHub Profile
@sterrym
sterrym / auto_token.rb
Created January 23, 2012 16:03
auto-create a unique youtube-like token to uniquely identify a records
class Foo < ActiveRecord::Base
before_create :make_token
private
TOKEN_SYMBOLS = (('A'..'Z').to_a + ('a'..'z').to_a + (0..9).to_a)
def make_token
self.token = (1..12).inject(""){|token, num| token += TOKEN_SYMBOLS.rand.to_s }
make_token if self.class.find_by_token(self.token)
self.token
end
@sterrym
sterrym / facebook.rb
Created June 8, 2011 21:40
facebook posting
class Facebook
attr_accessor :user
def initialize(user)
self.user = user
end
def post(user, params={})
params = normalize_params(params, %w(message picture link name caption description source))
client = OAuth2::Client.new(app_id, app_secret, :site => 'https://graph.facebook.com/', :parse_json => true)
I, [2010-12-06T09:33:27.030001 #27061] INFO -- : unlinking existing socket=/tmp/.unicorn-socket
I, [2010-12-06T09:33:27.030259 #27061] INFO -- : listening on addr=/tmp/.unicorn-socket fd=3
I, [2010-12-06T09:33:27.030806 #27061] INFO -- : Refreshing Gem list
/usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler/runtime.rb:27:in `setup': You have already activated rack 1.0.1, but your Gemfile requires rack 1.2.1. Consider using bundle exec. (Gem::LoadError)
from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler/spec_set.rb:12:in `each'
from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler/spec_set.rb:12:in `each'
from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler/runtime.rb:17:in `setup'
from /usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler.rb:100:in `setup'
from /var/www/releases/20101206173428/config/boot.rb:8
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
@sterrym
sterrym / _blog_post.html.erb
Created November 16, 2010 15:15
app/views/partials/_blog_post.html.erb
<%
# _counter is defined only if we pass :collection to the partial
if defined?(blog_post_counter)
showing_individual_post = false
else
showing_individual_post = true
blog_post_counter = 0
end
%>
<div id="blog_post_<%= blog_post.id %>" class="blog_post">
class TheatresController < ApplicationController
def index
@theatre = Theatre.all
end
def new
@theatre = Theatre.new(params[:theatre])
end
def create
class CreateRoles < ActiveRecord::Migration
def self.up
create_table :roles do |t|
t.string :name
t.string :role
t.timestamps
end
create_table :user_roles do |t|
t.references :user
# Don't change this file!
# Configure your app in config/environment.rb and config/environments/*.rb
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
module Rails
class << self
def boot!
unless booted?
preinitialize
# Edit this Gemfile to bundle your application's dependencies.
source 'http://rubygems.org'
gem "rails", "2.3.7"
#gem "mysql"
gem "sqlite3-ruby", :require => "sqlite3"
gem "authlogic", '2.1.4'
gem "aws-s3", "0.6.2", :require => "aws/s3"
# Use Bundler (preferred)
begin
require File.expand_path('../../.bundle/environment', __FILE__)
rescue LoadError
require 'rubygems'
require 'bundler'
Bundler.setup
# To use 2.x style vendor/rails and RubyGems
#
class Charge < ActiveRecord::Base
CHARGE_TYPES = ["upload", "storage", "deposit"]
belongs_to :member
default_scope :order => "charges.updated_at DESC"
validates_presence_of :name, :unit_price, :quantity
validates_inclusion_of :charge_type, :in => CHARGE_TYPES
validates_inclusion_of :chargeable_type, :in => %w(Payment VideoUpload)