Skip to content

Instantly share code, notes, and snippets.

@awls99
awls99 / random_correctness.rb
Last active July 21, 2017 13:23
Some math 4 4's thinggy
math_methods = Math.methods(false).each do |m|
self.class.send(:define_method, m, Proc.new do |x| Math.method(m).(x); end )
end
math_methods.delete_if{|m| %I[atan2 hypot acos asin atan atanh frexp lgamma ldexp].include? m}
def sqrt x
Math.sqrt x
end
ops = [' + 4.0 ', ' - 4.0 ', ' * 4.0', ' / 4.0 ',]
mixer = %w[* - + /]
@awls99
awls99 / errorclasses
Created January 29, 2015 11:21
Error classes for lazy bums like myself example
#The following two examples are equivalent
#Example 1, explicit error classe declaration
class MyMainNamespace
module Errors
class Error1 < StandardError; end
class Error2 < StandardError; end
end
end
require 'thwait'
Then /^all links are valid$/ do
errors = []
threads = []
@links.each do |link|
threads << Thread.new do
last_response = get link.url
errors.push "#{link.url} LINK IS BROKEN" unless last_response.success?
end
@awls99
awls99 / gist:8440770
Created January 15, 2014 17:41
Notes on having more then one browser supported in cucumber at the same time.
########## CUCUMBER SAMPLE ###########
Given user "jon" goes to "google.com"
#turns into:
Given /^user "([^"]*)" goes to "([^"]*)"/ do |user_key, url|
@users[user_key].browse do |browser|
browser.goto url
end
end
######## HOOKS SAMPLE ###############