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
%% -*- erlang-indent-level: 4 -*- | |
%% | |
%% %CopyrightBegin% | |
%% | |
%% Copyright Ericsson AB 1996-2014. All Rights Reserved. | |
%% | |
%% The contents of this file are subject to the Erlang Public License, | |
%% Version 1.1, (the "License"); you may not use this file except in | |
%% compliance with the License. You should have received a copy of the | |
%% Erlang Public License along with this software. If not, it can be |
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 Rocket.DateTime do | |
def type, do: :datetime | |
# Provide our own casting rules. | |
def cast(string) when is_binary(string) do | |
# Try to parse different formats here | |
end | |
# Datetime itself should also be valid | |
def cast(%Ecto.DateTime{} = datetime) 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
"foo bar baz" | |
|> Stream.unfold(fn | |
"" -> nil; | |
acc -> | |
case String.split(acc, " ", parts: 2) do | |
[left, right] -> {left, right} | |
[left] -> {left, ""} | |
end | |
end) | |
|> Enum.take(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 Exq.RouterPlug do | |
import Plug.Conn | |
use Plug.Router | |
plug :match | |
plug :dispatch | |
get "/queues" do | |
IO.puts "YOLO" | |
conn |> halt() |
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
+ EPMD | |
- Distributed systems are cool | |
- Distributed systems are also complex | |
- First step: How to find other machines (and nodes) in the same network | |
- Erlang Port Mapper Daemon | |
+ EPMD in C | |
- Ships with Erlang | |
- is a TCP server | |
- usually 4369 |
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 Parsec do | |
# Handles parsec for ..., do: ... | |
defmacro parsec({:for, _, args}) do | |
{exprs, [[do: return]]} = Enum.split(args, -1) | |
do_parsec(exprs, return) | |
end | |
# Handles parsec for ... do ... end | |
defmacro parsec({:for, _, args}, do: return) do | |
do_parsec(args, return) |
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
iex(2)> import Supervisor.Spec | |
nil | |
iex(3)> Supervisor.start_link([worker(Task, [fn -> Process.register(self, :hello); :timer.sleep(:infinity) end])], strategy: :one_for_one) | |
{:ok, #PID<0.61.0>} | |
iex(4)> Process.whereis(:hello) | |
#PID<0.62.0> | |
iex(5)> Process.exit(self(), :shutdown) | |
** (EXIT from #PID<0.57.0>) shutdown | |
Interactive Elixir (0.15.2-dev) - press Ctrl+C to exit (type h() ENTER for help) |
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
iex(1)> defmodule Foo do | |
...(1)> use GenEvent | |
...(1)> end | |
{:module, Foo, | |
<<70, 79, 82, 49, 0, 0, 8, 144, 66, 69, 65, 77, 69, 120, 68, 99, 0, 0, 2, 7, 131, 104, 2, 100, 0, 14, 101, 108, 105, 120, 105, 114, 95, 100, 111, 99, 115, 95, 118, 49, 108, 0, 0, 0, 2, 104, 2, 100, 0, 4, ...>>, | |
[true, true, true, true, true, true]} | |
iex(2)> {:ok, pid} = GenEvent.start_link | |
{:ok, #PID<0.50.0>} | |
iex(3)> GenEvent.add_handler(pid, Foo, []) | |
:ok |
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
@proto_version "1.0" | |
def process_options(opts) do | |
ret = [] | |
if opts[:in], do: ret = ["-in"|ret] | |
case opts[:err] do | |
:out -> ret = ["-err", "out"|ret] | |
:err -> ret = ["-err", "err"|ret] | |
_ -> nil |
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
=ERROR REPORT==== 12-Jun-2014::15:23:03 === | |
** Task <0.38.0> terminating | |
** Reason for termination == | |
** {badarg,[{erlang,hd,[[]],[]}, | |
{'Elixir.Agent.Server',handle_call,3, | |
[{file,"lib/agent/server.ex"},{line,11}]}, | |
{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,580}]}, | |
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]} |