Skip to content

Instantly share code, notes, and snippets.

View ReganRyanNZ's full-sized avatar

Regan Ryan ReganRyanNZ

  • Contractor
  • Wellington, New Zealand
View GitHub Profile
@ReganRyanNZ
ReganRyanNZ / factory_bot.rb
Created March 8, 2021 03:50
find_or_create for FactoryBot
# initializers/factory_bot.rb
# This needs to be extended in any factory you want its methods in, e.g.:
# factory :my_factory do
# extend FactoryBotEnhancements
# change_factory_to_find_or_create
# end
# FactoryBot.create(:my_factory) # creates with default attributes
# FactoryBot.create(:my_factory) # finds with the same default attributes
@ReganRyanNZ
ReganRyanNZ / cal.rb
Created February 18, 2020 08:24
Ruby implementation of Cal (printing calendar)
# This was a fun exercise to recreate the bash tool `cal`, which prints a calendar of the current month in your terminal
require 'minitest/autorun'
require 'date'
class Cal
def print_calendar(date = Date.today)
puts calendar(date)
end
@ReganRyanNZ
ReganRyanNZ / links_from_xml.rb
Last active November 13, 2018 01:17
Grep href and title out of XML
@ReganRyanNZ
ReganRyanNZ / calc_solver.rb
Created November 6, 2018 11:34
Calculator: The Game (solver)
# This runs through all possible moves for the app "Calculator: The Game"
#
# Note that in the app the buttons keep changing their functions,
# so you will need to edit the functions according to your level.
def calc
moves = 6
start = 111
goal = 126
def up(input)
input * 3