Skip to content

Instantly share code, notes, and snippets.

View satom99's full-sized avatar

Santiago Tortosa satom99

View GitHub Profile
@satom99
satom99 / variables.exs
Created November 13, 2023 18:27
Elixir variables that share a same name but are different
ast =
{:fn, [],
[
{:->, [],
[
[
{:a, [counter: 1], nil},
{:a, [counter: 2], nil}
],
{{:a, [counter: 1], nil}, {:a, [counter: 2], nil}}
@satom99
satom99 / currying.ex
Last active November 14, 2023 15:06
Elixir currying
defmodule Currying do
def function ~> argument when is_function(function) do
curry(function, argument)
end
def curry(function, arguments) when is_function(function) and is_list(arguments) do
{:arity, arity} = Function.info(function, :arity)
arguments = Enum.reverse(arguments)
defmodule Testing do
@behaviour :gen_statem
def test() do
{:ok, pid} = start_link()
:gen_statem.call(pid, :get_state) |> IO.inspect()
to_party(pid)
@satom99
satom99 / concept.ex
Created April 10, 2018 16:31
Command handler
defmodule Consumer do
use Coxir
use Coxir.Commands
@prefix "~"
@space :none
@channel :any
@permit :none
command ping do
@satom99
satom99 / http.ex
Last active December 30, 2017 17:23
Joseph#8035's curiosity
defmodule Socket do
use GenServer
alias Socket.Worker
def start_link do
GenServer.start_link __MODULE__, []
end
def init(_state) do
defmodule Test.ErrorView do
use Phoenix.View, root: ""
def render(path, _) do
[code, format] = path |> String.split(".")
IO.puts "Rendering #{format}"
format
end