View erl_lint.erl
1 2 3 4 5 6 7 8 9 10
%% -*- 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
View rocket_date_time.ex
1 2 3 4 5 6 7 8 9 10
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
View split_stream.exs
1 2 3 4 5 6 7 8 9 10
"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)
View exq_web_router.ex
1 2 3 4 5 6 7 8 9 10
defmodule Exq.RouterPlug do
import Plug.Conn
use Plug.Router
 
plug :match
plug :dispatch
 
get "/queues" do
IO.puts "YOLO"
conn |> halt()
View epmd
1 2 3 4 5 6 7 8 9 10
+ 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
View parsec.exs
1 2 3 4 5 6 7 8 9 10
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)
View shutdown.exs
1 2 3 4 5 6 7 8 9 10
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)
View gist:3e1817e2e9b5b282fdbf
1 2 3 4 5 6 7 8 9 10
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
View exercise.exs
1 2 3 4 5 6 7 8 9 10
@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
View gist:f0d9025bb3f5a580aee6
1 2 3 4 5 6 7 8
=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}]}]}
Something went wrong with that request. Please try again.