Skip to content

Instantly share code, notes, and snippets.

View davidguthu's full-sized avatar

David Guthu davidguthu

View GitHub Profile
@davidguthu
davidguthu / .gitattributes
Created June 14, 2021 13:09 — forked from jeromedalbert/.gitattributes
Automatically resolve Git merge conflicts in Rails schema.rb by picking the most recent date in the conflict (now works with Rails 5 and recent versions of Git). The following files should be in your home ~ directory. Inspired by https://tbaggery.com/2010/10/24/reduce-your-rails-schema-conflicts.html
db/schema.rb merge=railsschema
class Derpbase
def resource=(v)
instance_variable_set(:'@user', v)
end
def resource
instance_variable_get(:'@user')
end
def say_resource
puts resource
end
actionmailer (3.2.14)
actionpack (3.2.14)
active-record-instance-count (0.0.1)
active_link_to (1.0.1)
active_record_query_trace (1.3)
active_scaffold_batch (3.2.2)
active_utils (2.0.1)
activemerchant (1.26.0)
activemodel (3.2.14)
activerecord (3.2.14)
davidguthu-imac:dalli david$ export BUNDLE_GEMFILE=$PWD/gemfiles/rails3.gemfile
davidguthu-imac:dalli david$ gem query --local | grep bundler >/dev/null || gem install bundler
davidguthu-imac:dalli david$ ruby --version
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin11.4.2]
davidguthu-imac:dalli david$ rvm --version
rvm 1.21.3 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
davidguthu-imac:dalli david$ gem --version
2.0.3
@davidguthu
davidguthu / gist:5569892
Created May 13, 2013 17:18
benchmark on heroku
davidguthu-imac:candi david$ heroku run console -a david-qa
Running `console` attached to terminal... up, run.5327
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
Connecting to database specified by
@davidguthu
davidguthu / gist:5569863
Created May 13, 2013 17:15
Local benchmark
1.9.3p194 :001 > u = User.includes(:orders => :line_items).find 9
User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 9 AND (`users`.`deleted_at` IS NULL) LIMIT 1
Order Load (1.9ms) SELECT `orders`.* FROM `orders` WHERE `orders`.`user_id` IN (9)
LineItem Load (2.8ms) SELECT `line_items`.* FROM `line_items` WHERE `line_items`.`order_id` IN (79, 88, 111, 114, 115, 126, 127, 129, 131, 132, 133, 134, 137, 138, 139, 326, 337, 341, 383, 420, 464, 520, 521, 523, 791, 836, 1200, 1201, 1202, 1203, 1574, 1710, 1970, 1971, 2091, 2296, 2482, 2493, 2550, 2651, 3247, 3248, 3250, 3254, 3256, 3606, 3649, 3799, 4081, 4091, 4195, 4565, 4813, 4822, 4904, 4905, 5036, 5131, 5226, 5345, 5570, 5644, 5776, 5890, 6145, 6518, 6535, 7048, 7631, 7632, 7844, 7927, 8249, 8259, 8409, 8498, 8554, 8558, 8559, 8626, 8984, 9041, 9048, 9140, 9241, 9391, 9392, 9773, 9824, 9856, 10989, 11227, 11553, 11801, 12088, 12122, 12140, 12143, 12147, 12162, 12176, 12539, 12541, 12547, 13384, 13920, 16353, 16398, 16399, 16764, 1699
1.9.3p194 :001 > i = Invoice.find 217831
Invoice Load (0.3ms) SELECT `invoices`.* FROM `invoices` WHERE `invoices`.`id` = 217831 LIMIT 1
=> #<Invoice id: 217831, merchandiser_id: 3851, time_period_id: 263, total: #<BigDecimal:7ff919685a50,'0.0',9(18)>, created_at: "2013-01-02 00:02:41", updated_at: "2013-01-02 00:02:41", team_total: #<BigDecimal:7ff919685730,'0.0',9(18)>, returned_total: #<BigDecimal:7ff9196856e0,'0.0',9(18)>, individual_total: #<BigDecimal:7ff919685618,'0.0',9(18)>>
1.9.3p194 :002 > i.return_adjustments.first.return_commission
InvoiceAdjustment::Return Load (0.4ms) SELECT `invoice_adjustments`.* FROM `invoice_adjustments` WHERE `invoice_adjustments`.`type` IN ('InvoiceAdjustment::Return') AND `invoice_adjustments`.`invoice_id` = 217831 LIMIT 1
ReturnCommission Load (0.3ms) SELECT `revoked_commissions`.* FROM `revoked_commissions` WHERE `revoked_commissions`.`type` IN ('ReturnCommission') AND `revoked_commissions`.`id` = 575 LIMIT 1
=> nil
1.9.3p194 :003 > i.return_adjustments.fi
@davidguthu
davidguthu / gist:5463559
Created April 25, 2013 21:57
my life sucking
ActiveRecord::AssociationTypeMismatch in Account::ReturnsController#update
InventoryUnit(#70363758133280) expected, got ActiveSupport::HashWithIndifferentAccess(#70363957256960)
Rails.root: /Users/david/Projects/candi
Application Trace | Framework Trace | Full Trace
app/controllers/account/returns_controller.rb:45:in `update'
lib/middleware/redirect_blog_links.rb:15:in `call'
lib/middleware/redirect_boutique_subdomains.rb:11:in `call'
@davidguthu
davidguthu / service_locator.rb
Created August 14, 2012 13:56
Implementation
require 'active_support/core_ext/string'
class Implementation
@settings = {}
def self.setup(&block)
block.call(self)
end
def self.get(i)
get_implementation(i)
@davidguthu
davidguthu / gist:3349427
Created August 14, 2012 13:54
BaseDomain
require 'active_model/conversion'
module Domain
class BaseDomain
include ActiveModel::Conversion
attr_reader :persistence_object
class_attribute :persistence_class
def to_model
@persistence_object