Skip to content

Instantly share code, notes, and snippets.

View mkreyman's full-sized avatar
🏃‍♂️
Building cool stuff, serving customers, and enjoying every moment of it...

Mark Kreyman mkreyman

🏃‍♂️
Building cool stuff, serving customers, and enjoying every moment of it...
View GitHub Profile
Class Dog
def speak
"Bark"
end
end
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@mkreyman
mkreyman / .irbrc
Created April 20, 2014 02:25 — forked from adamcrown/.irbrc
require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8
def unbundled_require(gem)
loaded = false
if defined?(::Bundler)
Gem.path.each do |gems_path|
gem_path = Dir.glob("#{gems_path}/gems/#{gem}*").last
@mkreyman
mkreyman / enigma_machine.rb
Created March 9, 2016 21:11 — forked from albertstill/enigma_machine.rb
Understand how the Enigma machine works with 30 lines of Ruby
Plugboard = Hash[*('A'..'Z').to_a.sample(20)]
Plugboard.merge!(Plugboard.invert)
Plugboard.default_proc = proc { |_, key| key }
def build_a_rotor
Hash[('A'..'Z').zip(('A'..'Z').to_a.shuffle)]
end
ROTOR_1, ROTOR_2, ROTOR_3 = build_a_rotor, build_a_rotor, build_a_rotor
@mkreyman
mkreyman / Gemfile
Last active July 18, 2017 20:54 — forked from hopsoft/Gemfile
ruby-prof: Add profiling to your rake tasks.
group :development do
gem "ruby-prof"
end
@mkreyman
mkreyman / rspec_model_testing_template.rb
Created August 15, 2017 16:40 — forked from SabretWoW/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@mkreyman
mkreyman / ruby_benchmark_examples.rb
Created August 15, 2017 16:41 — forked from SabretWoW/ruby_benchmark_examples.rb
Three examples showing three of the main methods of Ruby's Benchmark class that's used to profile your code. Benchmark.measure at the most basic, Benchmark.benchmark allows you to run trials of different code blocks, and Benchmark.bmbm that helps you establish a baseline for your tests.
# http://www.ruby-doc.org/stdlib-2.0/libdoc/benchmark/rdoc/Benchmark.html
require 'benchmark'
# http://www.ruby-doc.org/stdlib-2.0.0/libdoc/bigdecimal/rdoc/BigMath.html
require 'bigdecimal/math'
# Set the number of iterations to run. The underscore here is used as a substitute for normal comma so Ruby interprets the number correctly.
iterations = 10
puts "\nCalculating pi #{iterations} times.\n\n"
module Enumerable
def to_histogram
inject(Hash.new(0)) { |h, x| h[x] += 1; h}
end
end
p [1, 2, 2, 2, 3, 3].to_histogram
# => {1=>1, 2=>3, 3=>2}
p ["a", "b", nil, "c", "b", nil, "a"].to_histogram
# spec/spec_helper.rb
def permutations(num)
[true, false].repeated_permutation(num)
end
# spec/models/welcome_email_logic_spec.rb
require 'spec_helper'
describe WelcomeEmail do
module Enumerable
def to_histogram
inject(Hash.new(0)) { |h, x| h[x] += 1; h}
end
end
class Bag
def initialize
@bag_of_objects = []
end