Skip to content

Instantly share code, notes, and snippets.

Avatar

Pierre Lebrun anthonylebrun

View GitHub Profile
View keybase.md

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:

View Trails TODO
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
View gist:cd14a7ecc41fd18c5f4a3871186b6e18
- Caramel Pork and eggs
- Fish tomato pineapple soup
- Amok
- Nom Banh Chok
- Prahok
- Khmer BBQ
@anthonylebrun
anthonylebrun / spycraft.rb
Created May 21, 2017
A function that allows spying on ruby objects
View spycraft.rb
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|
View pub_sub.ex
defmodule PubSub do
@name __MODULE__
use GenServer
# API
def start_link(default \\ %{}) do
GenServer.start_link(__MODULE__, default, name: @name)
end
View pop.ex
# 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
View Functional Programming Resources
# Really good explanation of FP vs OOP
http://scott.sauyet.com/Javascript/Talk/FunctionalProgramming
View metaprogramming.ex
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
View fizzbuzz.ex
defmodule Fizzbuzz do
def parse(range \\ 1..100) do
range |> Enum.map(&parse_num/1) |> Enum.join
end
defp parse_num(n) do
fizzbuzzer(n, rem(n, 3), rem(n, 5))
end
defp fizzbuzzer(_, 0, 0), do: "FizzBuzz"