Skip to content

Instantly share code, notes, and snippets.

View prakashmurthy's full-sized avatar

Prakash Murthy prakashmurthy

View GitHub Profile
@prakashmurthy
prakashmurthy / my_object.rb
Last active August 29, 2015 14:10
Active record find method over-ride
class MyObject < ActiveRecord::Base
...
protected
def self.find(*args)
if results = super(*args)
# Code to add stuff to the my_object.extra_data object
...
end
@prakashmurthy
prakashmurthy / 97things.md
Last active November 29, 2019 14:03
Links to the pages on the `97 Things Every Programmer Should Know` wiki. Maintaining this gist to keep track of the ones I have read.
  1. [Act with Prudence](http://programmer.97things.oreilly.com/wiki/index.php/Act with Prudence)

    Notes: Act with prudence and not accrue technical debt by accomplishing things in a quick and dirty manner.

  2. Apply Functional Programming Principles

  3. Ask "What Would the User Do?" (You Are not the User)

    Notes: We as programmers don't see things the same way as the users do. Need to get better at seeing past one's own experience / perceptions, and learn to see things the way users do. Best way to gather requirements is to watch users do the same activity - better than asking them about it.

  4. [Automate Your Coding Standard](http://programmer.97things.oreilly.com/wiki/index.php/Automate Your Coding Standard)

An ActionController::InvalidAuthenticityToken occurred in user_sessions#create:
ActionController::InvalidAuthenticityToken
-------------------------------
Stack Trace
-------------------------------
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
actionpack (4.2.0) lib/action_controller/metal/request_forgery_protection.rb:181:in `handle_unverified_request'
actionpack (4.2.0) lib/action_controller/metal/request_forgery_protection.rb:209:in `handle_unverified_request'
@prakashmurthy
prakashmurthy / gist:476423678fa517537445
Created May 5, 2015 16:30
catching ActionController::InvalidAuthenticityToken
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
rescue_from ActionController::InvalidAuthenticityToken, with: :show_errors
before_filter { |c| User.current_user = c.current_user }
...
private
def show_errors
@prakashmurthy
prakashmurthy / diff.md
Last active October 28, 2015 17:47
add_foreign_key inconsistent behavior

add_foreign_key seems to be behaving inconsistently when it is called with rake db:rollback.

When called from rake db:migrate, a custom name built with table name & column name is used for the index name. When called from rake db:rollback, the name used for the index is a generic one.

Here is the diff from the above behavior in my db/schema.rb file:

-  add_index "line_items", ["location_id"], name: "index_line_items_on_location_id", using: :btree
+  add_index "line_items", ["location_id"], name: "fk_rails_4335959382", using: :btree
@prakashmurthy
prakashmurthy / example_mailer.rb
Created June 18, 2016 00:05
blind copy all emails sent by a rails system to a specific email account
class ExampleMailer < ActionMailer::Base
default bcc: "[email protected]"
...
end

[master] $ git bisect start

[master] $ git bisect good fd65a9000b550509358dfdcd557c0bb882630d4e

[master] $ git bisect bad 4e961ca184d39bcc3755d017e94bf03c6e656b29

Bisecting: a merge base must be tested [ee614af6fa6c9e8cac70bcfd7d3583d0b4ff907b] Merge pull request #17812 from jonatack/patch-8 [(no branch, bisect started on master)] $ git bisect good

@prakashmurthy
prakashmurthy / cap_error.rb
Created August 12, 2016 16:31
Capistrano incompatibility with rake
cap aborted!
NoMethodError: undefined method `already_invoked' for <Rake::Task load:defaults => []>:Rake::Task
/home/current_user/shared/bundle/ruby/2.2.0/gems/capistrano-3.6.0/lib/capistrano/dsl.rb:16:in `invoke'
/home/current_user/shared/bundle/ruby/2.2.0/gems/capistrano-3.6.0/lib/capistrano/application.rb:91:in `load_imports'
/home/current_user/shared/bundle/ruby/2.2.0/gems/rake-10.5.0/lib/rake/application.rb:697:in `raw_load_rakefile'
/home/current_user/shared/bundle/ruby/2.2.0/gems/rake-10.5.0/lib/rake/application.rb:94:in `block in load_rakefile'
/home/current_user/shared/bundle/ruby/2.2.0/gems/rake-10.5.0/lib/rake/application.rb:176:in `standard_exception_handling'
/home/current_user/shared/bundle/ruby/2.2.0/gems/rake-10.5.0/lib/rake/application.rb:93:in `load_rakefile'
/home/current_user/shared/bundle/ruby/2.2.0/gems/rake-10.5.0/lib/rake/application.rb:77:in `block in run'
/home/current_user/shared/bundle/ruby/2.2.0/gems/rake-10.5.0/lib/rake/application.rb:176:in `standard_exception_handling'
##############################################################################
# decimal_rounding_error.rb
# Script for https://github.com/rails/rails/issues/26108
##############################################################################
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
@prakashmurthy
prakashmurthy / decimal_rounding_test.rb
Last active August 17, 2016 13:54
Files for adding a new test in rails codebase
# activerecord/test/cases/decimal_rounding_test.rb
require "cases/helper"
require "models/thing"
class DecimalRoundingTest < ActiveRecord::TestCase
ActiveRecord::Schema.define do
create_table :things, force: true do |t|
t.decimal :price, precision: 4, scale: 4
end
end