Skip to content

Instantly share code, notes, and snippets.

View bear454's full-sized avatar

James Mason bear454

View GitHub Profile
class Person < ActiveRecord::Base
has_many :orders
has_many :lines, :through => :products
has_many :products, :through => :lines
end
class Order < ActiveRecord::Base
has_many :lines
has_many :products, :through => :lines
end
def class Cart < ActiveRecord::Base
#...
def installation_instructions_pdf(pdf = nil)
pdf ||= Prawn::Document.new
eval(IO.read("app/views/cards/installation.pdf.prawn"))
pdf
end
#...
@bear454
bear454 / some_random_view.html.erb
Created August 27, 2009 19:17
Bare example of link_to_remote: clicking the "Update" link in the view will change the text in the update_me span to 'Updated text.'
<span id="update_me">Some text that needs to be updated.</span>
<%=link_to_remote "Update", :url => "/update/something", :update => 'update_me' %>
#!/usr/bin/ruby
require 'rubygems'
require 'sinatra'
require 'haml'
require 'gdata'
PROJECT_PATH = "/your/project/path"
DOMAIN = 'your_google_apps_domain_or_blank_for_any_google_account.com'
@bear454
bear454 / active_record_steps.rb
Created September 22, 2009 00:05
Some generic rspec steps I use for unit testing ActiveRecord models with cucumber.
# clear a table
Given /^I have no (\S+)$/ do |table|
ActiveRecord::Base.connection.execute "DELETE FROM `#{table.tableize}`"
end
# create a new instance, as an @underscore_named_var, and @it.
Given /^I have a new (\S+)$/ do |model|
eval "@#{model.underscore} = #{model.classify}.new"
eval "@it = #{model.classify}.new"
end
class Core < ActiveResource::Base
self.site = case Rails.env
when 'production'
"http://core.yamatoengines.com"
else
"http://localhost:3005"
end
end
@bear454
bear454 / Frank's Movie Player.rb
Created March 22, 2010 20:49
sinatra media browser
#! /usr/bin/ruby
require 'rubygems'
require 'sinatra'
require 'haml'
require 'thin'
set :public, File.dirname(__FILE__)
get '/' do
@bear454
bear454 / sinatra-features_in_gdocs.rb
Created April 5, 2010 21:30
Store cucumber features in gdocs; fetch & run with sinatra
#!/usr/bin/ruby
require 'rubygems'
require 'sinatra'
require 'haml'
require 'gdata'
PROJECT_PATH = "/your/project/path"
DOMAIN = 'your_google_apps_domain_or_blank_for_any_google_account.com'
@bear454
bear454 / _tango_palette.less
Created June 4, 2010 06:29
Tango Palette as LESS CSS
//Tango Palette: http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines#Color_Palette
//Licensed as Public Domain
//LESS'd by James Mason ([email protected])
//Butter
@light_butter: #fce94f;
@butter: #edd400;
@dark_butter: #c4a000;
//Orange
@bear454
bear454 / set-matching.rb
Created April 20, 2011 18:33
Filter a set of attributes on a collection to only show the varying attributes
#! /usr/bin/ruby
# data set:
# id | name | score | postal | color
# 1 | john | 14 | 12345 | blue
# 2 | jane | 10 | 12345 | blue
# 3 | jeff | 6 | 12345 | green
# define a simple class for holding the dataset