Skip to content
View example.ex
defmodule SomeModule do
def start(host, options) do
# We are assuming SomeSup has been already started somewhere
# (ideally in a supervision tree).
{:ok, child_pid} = SomeSup.attach_to(SomeSup, host, options)
end
end
defmodule SomeSup do
use Supervisor
View foo.erl
%% When compiled with: erlc +bin_opt_info foo.erl
%%
%% It prints:
%%
%% foo.erl:13: Warning: NOT OPTIMIZED: compiler limitation: instruction {get_map_elements,
%% {f,3},
%% {x,1},
%% {list,[{atom,state},{x,6}]}} prevents delayed sub binary optimization
-module(foo).
View elixir_parser.yrl
Nonterminals
grammar expr_list
expr container_expr block_expr access_expr
no_parens_expr no_parens_one_expr no_parens_one_ambig_expr
bracket_expr bracket_at_expr bracket_arg matched_expr unmatched_expr max_expr
op_expr matched_op_expr no_parens_op_expr no_parens_many_expr
comp_op_eol at_op_eol unary_op_eol and_op_eol or_op_eol capture_op_eol
add_op_eol mult_op_eol hat_op_eol two_op_eol pipe_op_eol stab_op_eol
arrow_op_eol match_op_eol when_op_eol in_op_eol in_match_op_eol
type_op_eol rel_op_eol
View erl_lint.erl
%% -*- 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
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
"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
defmodule Exq.RouterPlug do
import Plug.Conn
use Plug.Router
plug :match
plug :dispatch
get "/queues" do
IO.puts "YOLO"
conn |> halt()
View epmd
+ 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
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
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)
Something went wrong with that request. Please try again.