Skip to content

Instantly share code, notes, and snippets.

View mustmodify's full-sized avatar

Johnathon "jw" Wright mustmodify

View GitHub Profile
module Enumerable
def first_result
self.each do |item|
out = yield item
return out if out
end
end
end
@mustmodify
mustmodify / gist:6f47e70f8b49ca82141c
Last active August 29, 2015 14:09
What is requiring iconv?
! Unable to load application: LoadError: no such file to load -- iconv
An exception occurred running /home/jw/.rvm/gems/rbx-2.2.10/bin/ruby_executable_hooks:
no such file to load -- iconv (LoadError)
Backtrace:
Rubinius::CodeLoader#load_error at kernel/common/code_loader.rb:441
Rubinius::CodeLoader#resolve_require_path at kernel/common/code_loader.rb:425
{ } in Rubinius::CodeLoader#require at kernel/common/code_loader.rb:103
class Numeric
def stuff=(value)
@stuff=value
end
end
x = 7
x.stuff='hello'
# EXPLOSION!
class Person
def say(message)
puts "Some people would say '#{message}'"
end
def hey_do_something_for_me( proc )
proc.call
end
end
@mustmodify
mustmodify / warden.rb
Created November 20, 2014 15:19
my config/initializers/warden.rb file with comments.
# config/initializers/warden.rb
Rails.application.config.middleware.use Warden::Manager do |manager|
manager.default_strategies :password, :perishable_token
manager.failure_app = lambda { |env|
# Just to be clear, I'm not actually sold on failure apps. The intent
# here is that if an authentication strategy fails and a failure app is
# defined, then it controls the flow. I now think this should be handled
# on the controller level... don't define a failure app, and have your
# controllers test to see whether there is a current_user. Because sometimes
@mustmodify
mustmodify / actual_if_redacted_results
Last active August 29, 2015 14:10
the blind man's cucumber resutls
expected to find text "Search by patient name" in "[menu] [breadcrumbs] [tabs:] History Import Manual Entry [tab content:] Search by patient name: Enter the name of the patient for whom you are searching. We'll show any matching messages we've received in the last few months. [more content]
def metaclass
class << self; self; end
end
def has_list( name, attributes={} )
metaclass.instance_eval do
define_method( name ) do
[]
end
end
<% cache( @presenter.cache_key ) do %>
<%= cloud.to_svg %>
<% end %>
<% cache( @presenter.cache_key ) do %>
<%= String.random(10) %>
<% end %>
def gap_weight_for( age )
difference = (value_of(age) - patient_age).abs
( difference * 0.1 ) ** 1.07
end
intermittently results in:
in `**': #<Class:0x0000000a693110> can't be coerced into BigDecimal (TypeError)
def gap_weight_for( age )