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 Apr 6, 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
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 / 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 / knuth_arrows.rb
Last active Jun 30, 2021
Exploration of Knuth Arrows as monoids
View knuth_arrows.rb
class Add
def self.mempty
new(0)
end
def initialize(number)
@number = number
end
attr_reader :number
@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 😉

@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 / build-deploy
Created Mar 21, 2019
Netlify + Parcel deployment
View build-deploy
#!/bin/sh
set -e
echo "== BUILDING THE APP =="
yarn parcel build src/index.html
echo "== CONFIGURING REDIRECTS =="
if [ "$CONTEXT" = "production" ]; then
cp production_redirects dist/_redirects
@JoelQ
JoelQ / conditionals_to_booleans_ruby.md
Created Dec 5, 2018
Common Ruby conditionals refactored to boolean expressions
View conditionals_to_booleans_ruby.md

Redundant if/else - identity

def can_edit?
  if admin?
    true
  else
    false
  end
end
@JoelQ
JoelQ / four_line_repl.rb
Last active Nov 10, 2018
4-line Ruby REPL (read eval print loop)
View four_line_repl.rb
puts "4 line REPL (read eval print loop)"
$stdin.each_line do |line| # READ
return_value = eval(line.chomp) # EVAL
puts return_value # PRINT
end # LOOP
@JoelQ
JoelQ / MagicStrings.elm
Created Aug 10, 2018
Refactoring magic strings in Elm views
View MagicStrings.elm
view : Model -> Html Msg
view model =
div []
[ div [ class "icon" ] [ span [class "icon-profile" ] [] ]
, div [ class "icon" ] [ span [ class "icon-clock" ] [] ]
]
-- REFACTOR TO
view : Model -> Html Msg