Skip to content

Instantly share code, notes, and snippets.

View prakashmurthy's full-sized avatar

Prakash Murthy prakashmurthy

View GitHub Profile
@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
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 / 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)

@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 / gist:9086679
Created February 19, 2014 05:46
Tried generating the rails guides and validating them for the first time. The validation step throws up a bunch of errors messages. Wonder if these error messages are significant? And how do I fix them?
/Users/prakash/.rvm/rubies/ruby-1.9.3-p327/bin/ruby w3c_validator.rb
EEE
Could not validate ./output/3_1_release_notes.html because of 502 "Proxy Error"
EEE
Could not validate ./output/_license.html because of 502 "Proxy Error"
EE
Could not validate ./output/action_mailer_basics.html because of 502 "Proxy Error"
EEEE
Could not validate ./output/active_record_querying.html because of 502 "Proxy Error"
@prakashmurthy
prakashmurthy / guanggun.rb
Created August 15, 2012 04:26
runtime_error?
## Why would the following code give run time error?
## Inputs to the program:
## up to 100 entries from STDIN, values range : 1 ≤ n ≤ 10**18
##
inputs = []
while true
input = $stdin.gets.chomp
break if input.empty?
inputs << input.to_i
end
@prakashmurthy
prakashmurthy / My attempt at repeating this exercise
Created December 13, 2010 03:16
First code example in section 7.2.4 of Rails Tutorial
$ rails console --sandbox
ruby-1.9.2-rc1 > User.create( :name => "Prakash Murthy", :email => "prakblr@yahoo.com", :password => "abcdefgh", :password_confirmation => "abcdefgh" )
=> #<User id: nil, name: "Prakash Murthy", email: "prakblr@yahoo.com", created_at: nil, updated_at: nil, encrypted_password: nil, salt: nil>
ruby-1.9.2-rc1 > user = User.find_by_email("prakblr@yahoo.com")
=> #<User id: 1, name: "Prakash Murthy", email: "prakblr@yahoo.com", created_at: "2010-12-12 01:42:44", updated_at: "2010-12-12 01:42:44", encrypted_password: nil, salt: nil>
ruby-1.9.2-rc1 > user.has_password?('abcdefgh')
=> false
@prakashmurthy
prakashmurthy / heroku.log
Created November 30, 2010 00:49
output of heroku rake db:migrate on #PPP
$ heroku logs
/home/app/9493b3e5-40a4-4860-bd6c-da4e8664e69e/vendor/require-profiler/lib/require-profiler.rb:90:in `rescue in <top (required)>': (RuntimeError)
You need to install the term-ansicolor gem to see colorized reports.
from /home/app/9493b3e5-40a4-4860-bd6c-da4e8664e69e/vendor/require-profiler/lib/require-profiler.rb:87:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from /home/app/9493b3e5-40a4-4860-bd6c-da4e8664e69e/config/environment.rb:1:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
@prakashmurthy
prakashmurthy / gist:661447
Created November 3, 2010 18:11
nokogiri - rails 3.0.0 / rails 3.0.1 - ruby 1.9.2-p0 / ruby - doesn't work on my macbook
prakash-murthys-macbook-air:xmltoy prakashmurthy$ rails g scaffold Feed name:string url:string
/Users/prakashmurthy/.rvm/gems/ruby-1.9.2-p0@xmltoy/gems/nokogiri-1.4.3.1/lib/nokogiri/nokogiri.bundle: [BUG] Segmentation fault
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]
-- control frame ----------
c:0022 p:-541184440 s:0064 b:0064 l:000063 d:000063 TOP
c:0021 p:---- s:0062 b:0062 l:000061 d:000061 CFUNC :require
c:0020 p:0186 s:0058 b:0058 l:000057 d:000057 TOP /Users/prakashmurthy/.rvm/gems/ruby-1.9.2-p0@xmltoy/gems/nokogiri-1.4.3.1/lib/nokogiri.rb:13
c:0019 p:---- s:0056 b:0056 l:000055 d:000055 FINISH
c:0018 p:---- s:0054 b:0054 l:000053 d:000053 CFUNC :require
@prakashmurthy
prakashmurthy / output
Created October 28, 2010 15:11
Returns NaN when dealing with large numbers
Percentage of combinations with only one defect per chip = NaN.