Skip to content

Instantly share code, notes, and snippets.

def braintree_create
result = Braintree::TransparentRedirect.confirm(request.query_string)
customer = IsotopeSubscriptions.customer_create.call(customer_hash(result.customer))
if customer
redirect_to customer_path(customer)
else
render action: 'new'
end
end
# First, set up a customer_create method.  This tells us how to create the
# customer in your persistence layer.
IsotopeSubscriptions.customer_create = lambda do |hash|
  customer = Customer.new(hash)
  if customer.save
    customer
  else
    false
  end

end

# First, set up a customer_create method.  This tells us how to create the
# customer in your persistence layer.
IsotopeSubscriptions.customer_create = lambda do |hash|
  customer = Customer.new(hash)
  if customer.save
    customer
  else
    false
  end

end

require 'fnordmetric'
require 'fnordmetric/logger'
# This is a quickie ruby script to set up some base data for the dashboard
income_billing_keys = [:weekly_billing_external, :weekly_income_quickbooks, :weekly_break_even]
bank_account_keys = [:bank_account_checking, :bank_account_money_market, :bank_account_bonus_employee, :bank_account_bonus_boardmembers, :quickbooks_receivables, :quickbooks_payables]
website_traffic_keys = [:visitors_daily]
jenkins_keys = [:jenkins_build_success_daily, :jenkins_build_failure_daily]
demo_data = {
class WorkUnit
scope :on_estimated_ticket, lambda{ include(:ticket).where("tickets.estimated_hours IS NOT NULL AND tickets.estimated_hours > 0") }
end
def project_completion_metric(project)
work_unit_hours_array = Array.new # Empty array to work with
# Take the summation of estimated_hours on a ticket from the project
estimated_hours = Ticket.for_project(project).sum(:estimated_hours)
@knewter
knewter / work.rb
Created January 12, 2012 17:24 — forked from rthbound/work.rb
Hot products
PartNumber.ordered_between(7.days.ago, Time.zone.now)
class PartNumber
named_scope :ordered_between, lambda{|start_time, end_time| { :conditions => ["orders.created_at BETWEEN ? AND ?", start_time, end_time], :include => [:order] }
end
@knewter
knewter / order.rb
Created December 22, 2011 21:05 — forked from rthbound/order.rb
def self.statuses
Order.all.collect{|x| x.status}.uniq
end
# Currently : STATUSES = ["SHIPPED", "PROCESSING", "RECEIVED", "INCOMPLETE", "VOIDED", "REFUNDED", "FRAUDULENT", "ON HOLD"]
validates_inclusion_of :status, :in => statuses
statuses.map{|x| x.downcase.gsub(" ", "_")}.each { |s| named_scope s, :conditions => { :status => s } }
### JOSH PREFERS
named_scope :with_status, lambda{|s| { :conditions => { :status => s } } }
class Foo < ActiveRecord::Base
scope :bar, lambda{|a| where(a: a) }
scope :baz, lambda{|b| where(b: b) }
end
# Foo.bar(a).baz(b) works fine.
class Foo < ActiveRecord::Base
class << self
def bar(a)
tester.rb:114:in `validate_output_from': Command does not match output! (RuntimeError)
Expected content contained within ch01/tests/ch01_3 to match this:
/home/jadams/.rvm/gems/ruby-1.9.2-p290@saas_book/gems/bundler-1.0.21/lib/bundler/resolver.rb:280:in `resolve': Could not find gem 'turn (= 0.8.2) ruby' in any of the gem sources listed in your Gemfile. (Bundler::GemNotFound)
from /home/jadams/.rvm/gems/ruby-1.9.2-p290@saas_book/gems/bundler-1.0.21/lib/bundler/resolver.rb:160:in `start'
from /home/jadams/.rvm/gems/ruby-1.9.2-p290@saas_book/gems/bundler-1.0.21/lib/bundler/resolver.rb:128:in `block in resolve'
from /home/jadams/.rvm/gems/ruby-1.9.2-p290@saas_book/gems/bundler-1.0.21/lib/bundler/resolver.rb:127:in `catch'
from /home/jadams/.rvm/gems/ruby-1.9.2-p290@saas_book/gems/bundler-1.0.21/lib/bundler/resolver.rb:127:in `resolve'
from /home/jadams/.rvm/gems/ruby-1.9.2-p290@saas_book/gems/bundler-1.0.21/lib/bundler/definition.rb:151:in `resolve'
from /home/jadams/.rvm/gems/ruby-1.9.2-p290@saas
Scenario: After cloning, I should receive notifications when the document is updated
Given there are global documents:
| title | slug |
| homepage | / |
| Newsroom | /newsroom |
And there are global documents:
| title | slug |
| eClipboard | eclipboard |
And I have cloned documents:
| title | global title | slug |