Skip to content

Instantly share code, notes, and snippets.

View jmccaffrey's full-sized avatar

John McCaffrey jmccaffrey

View GitHub Profile
r00k /
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
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 = $>
$> = do |meth|
Timeout::timeout(1) { dup.public_send(meth, *args, &blk) == expected rescue false } rescue false
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"
#The Parsing failure middleware
class ParsingFailureToJSON