Skip to content

Instantly share code, notes, and snippets.

View anthonylebrun's full-sized avatar

Pierre Lebrun anthonylebrun

View GitHub Profile

Keybase proof

I hereby claim:

  • I am anthonylebrun on github.
  • I am anthonylebrun (https://keybase.io/anthonylebrun) on keybase.
  • I have a public key ASAqMVPS4JbHuvp4BmNIWPExwKYGZsfH2uUabDfcJsGAHgo

To claim this, I am signing this object:

https://www.alltrails.com/trail/us/north-carolina/stone-mountain-loop-trail
https://www.alltrails.com/trail/us/virginia/the-great-channels-via-brumley-mountain-trail
- Caramel Pork and eggs
- Fish tomato pineapple soup
- Amok
- Nom Banh Chok
- Prahok
- Khmer BBQ
@anthonylebrun
anthonylebrun / spycraft.rb
Created May 21, 2017 23:59
A function that allows spying on ruby objects
class Watchable
def do_something(foo, bar)
puts "Did something with #{foo} and #{bar}"
end
end
module Spycraft
def self.spy(instance)
instance.instance_eval do
public_methods(false).each do |meth|
defmodule PubSub do
@name __MODULE__
use GenServer
# API
def start_link(default \\ %{}) do
GenServer.start_link(__MODULE__, default, name: @name)
end

Elixir Conf 2014 - Keynote: Think Different by Dave Thomas

https://www.youtube.com/watch?v=5hDVftaPQwY

My Rating: 10/10

This talk is mainly about the paradigm shift in thinking that happens when you apply elixir-style pattern matching, pipes and functional programming thought (i.e. data transformation) to problem solving.

# Ok, so popping an immutable list is like cutting off the head of a hydra:
# it doesn't really get rid of the head :) See -> Enum.take/2.
defmodule ListUtils do
def pop(list, n, acc \\ [])
def pop([], _n, acc), do: Enum.reverse(acc)
def pop(_list, 0, acc), do: Enum.reverse(acc)
def pop([head | tail], n, acc) do
pop(tail, n - 1, [head | acc])
end
# Really good explanation of FP vs OOP
http://scott.sauyet.com/Javascript/Talk/FunctionalProgramming
defmodule MapToFunction do
defmacro functionalize(map) do
map |> Enum.map(fn {key, val} ->
quote do: def unquote(key)(), do: unquote(val)
end)
end
end
defmodule Digits do
import MapToFunction