Skip to content

Instantly share code, notes, and snippets.

View jmccaffrey's full-sized avatar

John McCaffrey jmccaffrey

View GitHub Profile
@r00k
r00k / q1.md
Last active January 29, 2017 03:00
Quizzy Question 1

Question 1

What object-oriented programming advice is this code violating?

def check_for_overheating(system_monitor)
  if system_monitor.temperature > 100
    system_monitor.sound_alarms
  end
end
@peterc
peterc / methods_returning.rb
Last active October 29, 2023 03:10
Object#methods_returning - to work out which method on an object returns what we want
require 'stringio'
require 'timeout'
class Object
def methods_returning(expected, *args, &blk)
old_stdout = $>
$> = StringIO.new
methods.select do |meth|
Timeout::timeout(1) { dup.public_send(meth, *args, &blk) == expected rescue false } rescue false
@elarkin
elarkin / gist:4709748
Last active December 12, 2015 03:48
Handling Parsing errors using Rack middleware in Rails 3.2
#in application.rb
module YourApp
class Application < Rails::Application
config.middleware.insert_before ActionDispatch::ParamsParser, "ParsingFailureToJSON"
...
end
end
#The Parsing failure middleware
class ParsingFailureToJSON