Skip to content

Instantly share code, notes, and snippets.

View gabeodess's full-sized avatar

Gabe Odess gabeodess

  • RigUp
  • Austin TX
  • 08:46 (UTC -05:00)
View GitHub Profile
@gabeodess
gabeodess / create_shippo_transaction_job_test.rb
Last active August 29, 2015 14:21
Overriding classes for test cases.
require 'test_helper'
class CreateShippoTransactionJobTest < ActiveJob::TestCase
test "the truth" do
@order = FactoryGirl.create(:order)
assert_enqueued_with(:job => CreateShippoTransactionJob) do
@shipment = @order.create_shipment!
@gabeodess
gabeodess / address.rb
Created May 13, 2015 02:38
Class Inheritance
class Shippo::Address < Shippo::TestBase
@@store = {:test => 'Address'}
cattr_reader :store
end
@gabeodess
gabeodess / data-structure.txt
Created May 18, 2015 21:25
Form builder data structure.
Form
employer:belongs_to
name:string
review_required:boolean
signature_required:boolean
Question (has_many :question_answers; multiple choice; text; multiple answer)
text:text
type:string (MultipleAnswerQuestion, MultipleChoiceQuestion, OpenQuestion)
@gabeodess
gabeodess / job.rb
Created June 1, 2015 23:52
Building PDF with Prawn
class CollapseLabelsJob < ActiveJob::Base
queue_as :default
def perform(tracking_sheet)
pdf_paths, destination = tracking_sheet.pdf_paths, File.join(Rails.root, "tmp/#{SecureRandom.hex}.pdf")
paths = pdf_paths.map{ |i| open(i).path }.join(' ')
options = "-q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite"
@gabeodess
gabeodess / Procfile-dev
Last active August 29, 2015 14:22
Start Frontend, API, and Sidekiq in 1 command
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker: bundle exec sidekiq -C config/sidekiq.yml -v -e $RAILS_ENV
web: ~/Sites/api/bin/rails s
#<HelloSign::Resource::SignatureRequest:0x007fe1d729c640
@data=
{"signature_request_id"=>"051eb2733453faf3fb0c2703ffd9aaf7237c8df8",
"title"=>"test4",
"original_title"=>"test4",
"subject"=>"test4",
"message"=>nil,
"test_mode"=>true,
"metadata"=>#<HelloSign::Resource::BaseResource:0x007fe1d729c438 @data={}, @raw_data={}>,
"is_complete"=>false,
$bundle exec rake
Run options: --seed 62924
# Running:
................autoprefixer: /home/rof/src/bitbucket.org/sharecoffee/share/app/assets/stylesheets/application.scss:6859:5: Gradient has outdated direction syntax. New syntax is like "to left" instead of "right".
autoprefixer: /home/rof/src/bitbucket.org/sharecoffee/share/app/assets/stylesheets/application.scss:6868:5: Gradient has outdated direction syntax. New syntax is like "to left" instead of "right".
........................................autoprefixer: /home/rof/src/bitbucket.org/sharecoffee/share/app/assets/stylesheets/coming_soon.scss:6859:5: Gradient has outdated direction syntax. New syntax is like "to left" instead of "right".
autoprefixer: /home/rof/src/bitbucket.org/sharecoffee/share/app/assets/stylesheets/coming_soon.scss:6868:5: Gradient has outdated direction syntax. New syntax is like "to left" instead of "right".
@gabeodess
gabeodess / test.rb
Last active September 27, 2015 21:08
class User < ActiveRecord::Base
after_initialize do
def addresses.<<(val)
push(val)
user.save!
end
end
def addresses
Subscription Load (0.9ms) SELECT "subscriptions".* FROM "subscriptions" WHERE (subscriptions.away @> 'away_action => NULL')
=> 0
Subscription Load (1.2ms) SELECT "subscriptions".* FROM "subscriptions" WHERE (subscriptions.away @> 'away_action => NULL' OR away ? 'away_action')
=> 34
Subscription Load (2.4ms) SELECT "subscriptions".* FROM "subscriptions" WHERE ((away -> 'away_action') IS NULL)
=> 140
ActiveAdmin.register User do
scope("all", :default => true)
scope("setup a subscription"){ |scope| scope.where("(SELECT COUNT(*) FROM subscriptions WHERE subscriptions.user_id = users.id LIMIT 1) = 1") }
scope("canceled"){ |scope| scope.where("
(SELECT COUNT(*) FROM subscriptions WHERE subscriptions.user_id = users.id LIMIT 1) = 1 AND
(SELECT COUNT(*) FROM subscriptions WHERE subscriptions.user_id = users.id AND subscriptions.archived_at IS NULL) = 0
") }
scope("active"){ |scope| scope.where(:id => Subscription.find_active.select(:user_id)) }
# scope("30 days +"){ |scope| scope.where(:id => Subscription.find_active.where("subscriptions.created_at < ?", 30.days.ago).select(:user_id)) }