Skip to content

Instantly share code, notes, and snippets.

View polvalente's full-sized avatar

Paulo Valente polvalente

View GitHub Profile
defmodule Web.CardParams do
defstruct holder_name: "name",
last_digits: "1234",
address: %Web.AddressParams{street: "rua dos bobos", number: "zero"}
@enforce_keys [:holder_name, :last_digits, :address]
# esse cara aqui pra mim é problemático
# Ou você continua dependendo do Core.Address
# ou você tem que tirar o nome da struct e passar um map
@polvalente
polvalente / make_behaviour.ex
Created July 11, 2019 22:45
Create behaviour from a module
defmodule MakeBehaviour do
defmacro __using__(opts) do
module = opts[:module]
quote do
if not is_nil(unquote(module)) do
import unquote(module)
end
@on_definition {MakeBehaviour, :on_def}
end
end
@polvalente
polvalente / emoji_module.ex
Last active July 9, 2019 23:30
Emojis are happy
defmodule X do
@moduledoc """
iex> X.a
"happy_emoji"
"""
Enum.each(
[:"😀"],
fn (name) ->
def unquote(name)(), do: "happy_emoji"
@polvalente
polvalente / Makefile
Created September 21, 2018 04:47
Make test with retry
TEST_COUNT ?= 4
test:
ifeq ($(TEST_COUNT), 2)
exit 0;
else
exit 1;
endif
retry-test: