Skip to content

Instantly share code, notes, and snippets.

@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
@JoelQ
JoelQ / elm-types-glossary.md
Last active February 14, 2024 14:29
Elm Type Glossary

Elm Types Glossary

There's a lot of type terminology and jargon going around when discussing types in Elm. This glossary attempts to list some of the most common type terms along with synonyms, terms from other language communities, examples, and links to more detailed articles on each topic.

@JoelQ
JoelQ / dollar.rb
Last active January 10, 2024 01:14
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 November 10, 2023 04:17
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 / elm-maybe-map-compose.md
Created February 9, 2018 15:52
Refactoring a pipeline of Maybe.map functions in Elm

Refactoring maybe code in Elm

Given this ugly series of cases:

optionalFormattedFriendAddress : Maybe Friend -> Maybe String
optionalFormattedFriendAddress maybeFriend =
  let
    maybeAddress = case maybeFriend of
      Just friend -> Just friend.address
@JoelQ
JoelQ / README.md
Created October 15, 2015 13:50
Using Shell Scripts for a Better User Experience (source for https://robots.thoughtbot.com/improving-user-experience-with-shell-scripts)

Server scripts

This is the source for the scripts discussed in https://robots.thoughtbot.com/improving-user-experience-with-shell-scripts

Both scripts are in the bin/ directory of the repo that contains all the markdown documents for blog posts. Users run bin/server and everything is automatically set up for them to view a local preview of the blog. bin/server-setup is a dependency of bin/server and is never run directly by users.

Maitre-d is the name of the "blog engine" discussed in the article.

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 / elm-generic-types-exercises.md
Last active June 14, 2022 21:22
Short exercises to learn how generic types and type variables work in Elm.

Generic Elm types exercises

A series of exercises to get a feel for how generic types and type variables work in Elm. For each of these, you are given some code that is not compiling. Your task is to get it compiling. You can change the body of the function but not the signature. No cheating with Debug.todo or infinite recursions either 😉