This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Pentabonacci do | |
import Integer, only: [is_odd: 1] | |
defp calc(0, _), do: 0 | |
defp calc(1, _), do: 1 | |
defp calc(2, _), do: 1 | |
defp calc(3, _), do: 2 | |
defp calc(4, _), do: 4 | |
defp calc(n, ets) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fibo O(n^2) | |
def fib(n) | |
raise ArgumentError if n < 0 | |
if n == 0 || n == 1 | |
1 | |
else | |
fib(n-1) + fib(n -2) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fibo O(n) | |
CACHE = {} | |
def fib(n) | |
raise ArgumentError if n < 0 | |
if CACHE[n] | |
CACHE[n] | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALGARISMOS = {"I" => 1, "V" => 5, "X" => 10, "L" => 50, "C" => 100, "D" => 500, "M" => 1000} | |
def to_arabico(romano) | |
total = 0 | |
romano = romano.chars | |
while romano != [] | |
ultimo = romano[-1] | |
penultimo = romano[-2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Protocolz do | |
defmacro defimplz(protocolo, [for: modulo_do_struct], [do: block]) do | |
quote do | |
defmodule (Module.concat([unquote(protocolo), unquote(modulo_do_struct)])) do | |
unquote(block) | |
end | |
end | |
end | |
defmacro defprotocolz(protocolo, [do: block]) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule SimpleBus do | |
def init do | |
{:ok, _} = Registry.start_link(:duplicate, __MODULE__) | |
end | |
def register_handler(module) do | |
Registry.register(__MODULE__, :event, module) | |
end | |
def emit(event_name, args) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule EventBus do | |
def init do | |
{:ok, _} = Registry.start_link(:duplicate, __MODULE__) | |
end | |
def register_handler(event_name, {m, f}, name \\ nil) do | |
name = name || "#{m}##{f}" | |
Registry.register(__MODULE__, event_name, {m, f, name}) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12:38:38.964 [info] Running LuklaWeb.Endpoint with Cowboy using http on port 4000 | |
Interactive Elixir (1.2.1) - press Ctrl+C to exit (type h() ENTER for help) | |
iex(1)> 12:38:42.771 [error] Disconnected from Redis (localhost:6379): :tcp_closed | |
12:38:42.776 [error] Error connecting to Redis (localhost:6379): connection refused | |
12:38:42.780 [error] Error connecting to Redis (localhost:6379): connection refused | |
12:38:42.792 [error] Error connecting to Redis (localhost:6379): connection refused | |
12:38:42.803 [error] Error connecting to Redis (localhost:6379): connection refused | |
12:38:42.813 [error] Error connecting to Redis (localhost:6379): connection refused | |
12:38:42.818 [error] Error connecting to Redis (localhost:6379): connection refused | |
12:38:42.824 [error] Error connecting to Redis (localhost:6379): connection refused |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule LuklaWeb.AsyncQueue do | |
use GenServer | |
alias LuklaWeb.Repo | |
alias LuklaWeb.AsyncQueue.Job | |
@reconnect_interval_millis 5000 | |
def start_link() do | |
GenServer.start_link(__MODULE__, [], name: AsyncQueue) |