Skip to content

Instantly share code, notes, and snippets.

@JoelQ
JoelQ / 10-blog-posts.md
Last active July 29, 2025 00:06
This History of Rails in 10 Blog posts

The History of Rails in 10 Blog Posts

Here are the notes for my RailsConf 2025 talk The History of Rails in 10 Blog Posts (video, slides)

Calling nostalgic veterans and newbies alike! We’re traveling through time on a tour of some of the most influential blog posts to hit the Rails community over the past two decades. With stops at iconic locations including in testing, service objects, and JavaScript, you won't want to miss it! Bring your chrono-passport and see you in 2003!

List of Articles

  1. FatModel, Skinny Controller - Foundational, refined what MVC means in the context of Rails
  2. Waiting for a Factory Girl - Changed the way the Rails community writes tests to this day
@JoelQ
JoelQ / fibonnacci.rb
Created February 4, 2025 01:18
Recursive cached fibonnacci
fib = Hash.new do |hash, n|
puts "calculating fib #{n}"
# base case
if n == 0 || n == 1
hash[n] = 1
else
# recursive case
hash[n] = hash[n - 1] + hash[n - 2]
end
@JoelQ
JoelQ / anamorphism.rb
Created January 2, 2025 19:19
Attempting to implement an anamorphism in Ruby to generate a series of squares
# This imagines `.unfold` to be an alternate constructor for `Enumerator` that's
# more complex than `.produce` but not as custom as the full `.new`. It follows the rules
# of anamorphisms (at least for arrays, not sure if this genericises to other structures)
class CustomEnumerator
def self.unfold(seed, &block)
Enumerator.new do |yielder|
loop do
seed, value = block.call(seed)
raise StopIteration if value.nil?
@JoelQ
JoelQ / tally.rb
Last active April 13, 2024 16:27
Demonstration of using a rich object to represent a composite count and how it makes the math easier to deal with
class Tally
def self.empty
new({})
end
def initialize(raw)
@raw = empty_hash.merge raw.slice(:small, :medium, :large)
end
# Accessors

How not to implement a multi-step form

"That ticket touches the wizard code? Why don't YOU take that one". The wizard in question is so gnarly my colleagues are afraid to touch it.

Looking at the code through the lens of conditional cardinality reveals what went wrong and how we can make things better. This mental model will change the way you think about structuring logic and help you take your conditional code from scary to delightful.

Description

This talk is aimed at an intermediate to advanced audience. While it will driven by a practical example (refactoring a multi-step form), it will mainly be about some more theoretical principles and mental models for structuring conditional code.

The Math Every Programmer Needs

Abstract

Leave your fear of math behind along with the equations and symbols, we're headed to Ruby-land! On this whirlwind tour, we’ll explore how to write better conditionals with Boolean algebra, figure out how many test cases we need with combinatorics, a mental model for breaking down large tasks with graph theory, and more.

You’ll leave this talk equipped to better do your job with some ideas, techniques, and mental models from the wonderfully practical world of discrete math.

Details

@JoelQ
JoelQ / tree_enumerator.rb
Created August 21, 2022 22:15
Demonstration of how using `Enumerator` makes it nicer to work with a data structure that has multiple valid traversals such as a binary tree
class Tree
attr_reader :val, :left, :right
def self.empty
EmptyTree.new
end
def self.leaf(val)
new(val, empty, empty)
end
@JoelQ
JoelQ / dollar.rb
Last active September 23, 2024 03:02
Implementing value object semantics as an RSpec shared_example.
class Dollar
attr_reader :cents
def initialize(cents:)
@cents = cents
end
def hash
[self.class, cents].hash
end
@JoelQ
JoelQ / month.rb
Last active September 2, 2024 18:44
require "date"
class Month
include Comparable
MONTHS_PER_YEAR = 12
def self.from_date(date)
self.from_parts(date.year, date.month)
end
@JoelQ
JoelQ / tree.rb
Last active January 27, 2022 15:11
A Ruby implementation of a binary tree and its catamorphism
class Tree
attr_reader :value, :left, :right
def initialize(value, left, right)
@value = value
@left = left
@right = right
end
def reduce(initial, &block)