Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View anthonylebrun's full-sized avatar

Pierre Lebrun anthonylebrun

View GitHub Profile
@anthonylebrun
anthonylebrun / passingProps.js
Created February 7, 2016 20:16
Dynamically passing props in react from a component to it's yet unknown children.
var FooBar = React.createClass({
render() {
return <div className="foo-bar">
{React.Children.map(this.props.children, child => React.cloneElement(child, {passedProp: this.props.passedProp}))}
</div>
}
})
@anthonylebrun
anthonylebrun / gemlist.txt
Last active April 19, 2016 23:02
List of gems I use or interesting gem I might want to use in my next project
https://github.com/hashrocket/decent_exposure
https://github.com/dkubb/adamantium
https://github.com/tcrayford/Values
https://github.com/apotonick/reform
https://github.com/apotonick/cells
https://github.com/mikeyhogarth/duckpond
https://github.com/substantial/updeep
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"
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
# Really good explanation of FP vs OOP
http://scott.sauyet.com/Javascript/Talk/FunctionalProgramming
# 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

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.

defmodule PubSub do
@name __MODULE__
use GenServer
# API
def start_link(default \\ %{}) do
GenServer.start_link(__MODULE__, default, name: @name)
end
@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|