This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get links and title for handy html building from xml | |
xml = "Paste your xml here" | |
links = xml.split("</cell>").map do |cell| | |
url_regex = /[^><]*<\/url>/m | |
next unless cell[url_regex] | |
href = cell[url_regex][/[^><]*/m] | |
title = cell[/[^><]*<\/text>/m][/[^><]*/m] | |
[title, href] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |