Skip to content

Instantly share code, notes, and snippets.

Avatar

Joël Quenneville JoelQ

  • Thoughtbot
  • Boston
View GitHub Profile
@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 May 26, 2020
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 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
@JoelQ
JoelQ / non_empty_array.rb
Created Aug 9, 2018
Creating a non-empty array in Ruby
View non_empty_array.rb
class NonEmptyArray
include Enumerable
def initialize(first, rest)
@first = first
@rest = rest
end
def first
@first
@JoelQ
JoelQ / math.rb
Last active Jun 30, 2021
Derive addition, multiplication, and exponentiation from from `Integer#next`
View math.rb
def add(number1, number2)
number2.times.reduce(number1) { |total| total.next }
end
add(2,3)
# => 5
def subtract(number1, number2)
number2.times.reduce(number1) { |total| total.pred }
end
@JoelQ
JoelQ / hamming_benchmark_styles.rb
Created Jun 29, 2018
Hamming benchmarks - Style comparisons
View hamming_benchmark_styles.rb
class Hamming
def self.zip_count(s1, s2)
s1.chars.
zip(s2.chars).
count { |c1, c2| c1 != c2 }
end
def self.for_loop(s1, s2)
distance = 0