Skip to content

Instantly share code, notes, and snippets.

View karledurante's full-sized avatar

Karle Durante karledurante

  • CustomInk.com
  • Ashburn, VA
View GitHub Profile
@karledurante
karledurante / gist:407eb172079e75aec2d5
Created June 17, 2015 11:26
No private inner class in ruby!
class A
def method_one
"A: method_one"
end
private
class B
def method_one
"A::B: method_one"
@karledurante
karledurante / gist:6215387
Created August 12, 2013 21:19
RubyLoco Hack Night: Sphero!
require 'sphero'
require 'pry'
FORWARD = 0
RIGHT = 90
BACKWARD = 180
LEFT = 270
SLOW = 100
FAST = 200
@karledurante
karledurante / gist:3557828
Created August 31, 2012 19:24
gem management of rails version specific code
####
## super_gem.rb
module SuperGem
require 'super_gem/rails/patches'
# super stuff you couldn't even imagine ...
end
####
@karledurante
karledurante / gist:3513710
Created August 29, 2012 14:48
has_and_belongs_to_many SecondBase issue
class Student < SecondBase::Base
has_and_belongs_to_many :courses
end
class Course < SecondBase::Base
has_and_belongs_to_many :students
end
student = Student.first
module ImSoConfused
def some_method; end
private
def another_method; end
end
public
def last_method; end
@karledurante
karledurante / gist:2581543
Created May 2, 2012 23:18
webdriver path config
# If capybara cannot find your browser executable, you can give it a hint like so:
Selenium::WebDriver::Firefox.path='/Applications/Firefox.app/Contents/MacOS/firefox-bin'
Selenium::WebDriver::Chrome.path = "/opt/google/chrome/google-chrome"
@karledurante
karledurante / gist:2558804
Created April 30, 2012 14:29
controller if blocks
class SomeController
def service
resource = Locator.find(params[:id])
if resource.blank?
render :status => 404, :text => "Resource could not be found"
else
render :json => resource
end
end
@karledurante
karledurante / gist:2502669
Created April 26, 2012 20:06
ruby alias method chain in ruby
# The intention is to reduce boiler plate code by globally adding
# behavior to any of the defined CLASS LEVEL methods.
#
# Chained.foo => "first I was like: base foo, but then I was: chained foo
# Chained.foo_bar => "first I was like: base foo_bar, but then I was: chained foo_bar
#
# This is useful for, say, finder methods that you want to add global behavior
# too. Like if you want to always decorate a result set.
#
# This seems a bit crazy...ideas for improvement??
@karledurante
karledurante / gist:2421364
Created April 19, 2012 14:38
Alternative to alias_method_chain
class Something
module Base
def my_method
# (A) original functionality
end
end
module PreExtension
def my_method
# (B) before the original
@karledurante
karledurante / gist:1555451
Created January 3, 2012 15:51
Rails 3 Functional Test: assert_select finds nothing on XHR requests
setup do
xhr :post, :summarize
end
should "find a tag" do
# FAILS in Rails3, SUCCEEDS in Rails2
assert_select :span, :text => "some content"
# SUCCEEDS in Rails3 & Rails2
assert_match /\<span\>some content<\/span\>/, @response.body