Skip to content

Instantly share code, notes, and snippets.

Avatar

Joël Quenneville JoelQ

  • Thoughtbot
  • Boston
View GitHub Profile
@JoelQ
JoelQ / dollar.rb
Last active Aug 9, 2022
Implementing value object semantics as an RSpec shared_example.
View dollar.rb
class Dollar
attr_reader :cents
def initialize(cents:)
@cents = cents
end
def hash
[self.class, cents].hash
end
@JoelQ
JoelQ / elm-maybe-map-compose.md
Created Feb 9, 2018
Refactoring a pipeline of Maybe.map functions in Elm
View elm-maybe-map-compose.md

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

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 😉

View README.md

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.

View month.rb
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-types-glossary.md
Last active Mar 12, 2022
Elm Type Glossary
View elm-types-glossary.md

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 / tree.rb
Last active Jan 27, 2022
A Ruby implementation of a binary tree and its catamorphism
View tree.rb
class Tree
attr_reader :value, :left, :right
def initialize(value, left, right)
@value = value
@left = left
@right = right
end
def reduce(initial, &block)
@JoelQ
JoelQ / list-pattern-matching-elm.md
Last active Dec 5, 2021
What does `x :: xs` pattern matching mean in Elm?
View list-pattern-matching-elm.md

What does x :: xs pattern matching mean in Elm?

:: is the list prepend operator in Elm.

3 :: 2 :: 1 :: []

is equivalent to

@JoelQ
JoelQ / RandomToTask.elm
Last active Sep 30, 2021
Turn an Elm random generator into task, allowing it to be chained with other side effects.
View RandomToTask.elm
-- 0.19
randomToTask : Generator a -> Task x a
randomToTask generator =
Time.now
|> Task.map (Tuple.first << Random.step generator << Random.initialSeed << Time.posixToMillis)
-- 0.18
@JoelQ
JoelQ / ellie_examples.md
Last active Jul 28, 2021
List of helpful Ellie's I've written
View ellie_examples.md