Skip to content

Instantly share code, notes, and snippets.

Avatar

Joël Quenneville JoelQ

  • Thoughtbot
  • Boston
View GitHub Profile
@JoelQ
JoelQ / hamming_benchmark_classic.rb
Created Jun 29, 2018
Hamming Benchmark - Classic
View hamming_benchmark_classic.rb
class Hamming
def self.eager(s1, s2)
s1.chars.
zip(s2.chars).
count { |c1, c2| c1 != c2 }
end
def self.half_lazy(s1, s2)
s1.each_char.
zip(s2.each_char).
@JoelQ
JoelQ / hamming_benchmark_take.rb
Created Jun 29, 2018
Hamming Lazy/Eager benchmarks
View hamming_benchmark_take.rb
class Hamming
def self.eager(s1, s2)
s1.chars.take(10).
zip(s2.chars.take(10)).
count { |c1, c2| c1 != c2 }
end
def self.half_lazy_args(s1, s2)
s1.each_char.take(10).
zip(s2.each_char.take(10)).
@JoelQ
JoelQ / inter-group-edges.md
Created Jun 20, 2018
Edges to different groups
View inter-group-edges.md

Problem

You have a graph where the nodes are in groups. You want to create edges between all nodes that are in different groups.

For example, given the following groups:

[[1, 2], [3], [4, 5]]
@JoelQ
JoelQ / MapZero.elm
Created May 30, 2018
A look at mapN functions in Elm. The `map0` function is just the constructor function! Haskell folks would call this pure/return.
View MapZero.elm
-- Maybe
map2 f v1 v2 = Just f |> andMap v1 |> andMap v2
map f v1 = Just f |> andMap v1
map0 f = Just f
-- List
map2 f v1 v2 = singleton f |> andMap v1 |> andMap v2
map f v1 = singleton f |> andMap v1
@JoelQ
JoelQ / Folding.elm
Created Mar 20, 2018
Folding a list is like replacing the cons and empty constructors
View Folding.elm
-- GIVEN
type MyList a
= Cons a (MyList a)
| Empty
add : Int -> Int -> Int
add a b =
a + b
@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
View railsconf-2018-mutation.md

A Darwinian Nightmare

It seemed to have stepped right out of the pages of a horror novel. The mutant shape-shifter struck without warning, defying a mere mortal's attempts to detect it. It seemed to distort the fabric of reality itself. And it was going to ruin my job interview.

We've all encountered this monster at some point. Like many classic monsters, it is our own creation. Every year it devastate projects worldwide. The fearsome mutation bug is an expert at hiding and altering your programs in subtle and

@JoelQ
JoelQ / empty_list.rb
Created Jan 18, 2018
Linked-list (cons list) implementation in Ruby
View empty_list.rb
class EmptyList
def prepend(value)
List.new(value, self)
end
def inspect
"()"
end
def map(&block)
@JoelQ
JoelQ / square-sum.md
Last active Jan 12, 2018
Attempted solution to the square-sum challenge
View square-sum.md

Square-Sum Challenge

Write out the numbers 1-15 such that any two numbers in the series add up to a square number

Inspired by https://www.youtube.com/watch?v=G1m7goLCJDY

Possible squares

There are 6 possible squares that can be made by adding two numbers under 16: