SlideShare uma empresa Scribd logo
1 de 57
Baixar para ler offline
ELIXIRTolerância a Falhas para Adultos
Fabio Akita
@akitaonrails@akitaonrails
Rubyconf Brasil 2016 – 23 e 24 de SetembroRubyconf Brasil 2016 – 23 e 24 de Setembro
Rubyconf Brasil 2016 – 23 e 24 de SetembroRubyconf Brasil 2016 – 23 e 24 de Setembro
Rubyconf Brasil 2016 – 23 e 24 de SetembroRubyconf Brasil 2016 – 23 e 24 de Setembro
Chris McCordChris McCord José ValimJosé Valim
Joe Armstrong - EricssonJoe Armstrong - Ericsson
defmodule Teste do
def say(name) do
IO.puts("Hello #{name}")
end
end
Teste.say("Fabio")
defmodule Teste do
@spec say(String.t)
def say(name) when is_string(name) do
IO.puts "Hello " <> name
end
end
Teste.say "Fabio"
OPTIONAL PARENTHESIS
-module(teste).
-export([qsort/1]).
qsort([]) -> [];
qsort([Pivot|T]) ->
qsort([X||X<-T,X =< Pivot]) ++
[Pivot] ++
qsort([X||X<-T,X > Pivot]).
defmodule Teste do
def qsort([]), do: []
def qsort([pivot|t]) do
qsort(for x <- t, x < pivot, do: x) ++
[pivot] ++
qsort(for x <- t, x >= pivot, do: x)
end
end
defmodule Teste do
def factorial(n) do
if n == 0 do
1
else
n * factorial(n - 1)
end
end
end
Teste.factorial(10)
# => 3628800
defmodule Teste do
def factorial(0), do: 1
def factorial(n) do
n * factorial(n - 1)
end
end
Teste.factorial(10)
# => 3628800
CALL BY PATTERN
{:ok, result} = Enum.fetch([1, 2, 3, 4], 3)
IO.puts result
# => 4
registro = {:ok, %{name: "Fabio", last_name: "Akita"}}
{:ok, %{name: name}} = registro
IO.puts name
# => Fabio
registro = %{name: "Fabio", year: 2016, foo: {:ok, [1, 2, 3]}}
%{name: name, foo: {:ok, result}} = registro
IO.puts Enum.join([name|result], ", ")
# => Fabio, 1, 2, 3
%{last_name: name} = registro
# => ** (MatchError) no match of right hand side value: ...
PATTERN MATCHING
(“Regex for non-String”)
a = 1
a = 2
IO.puts a
# => 2
^a = 3
# => ** (MatchError) no match of right hand side value: 3
message = "Hello"
IO.puts message <> " World!"
# => "Hello World!
IO.puts "#{message} World!"
# => "Hello World!
{:a, "b", 67, true}
[:a, "b", 67, true]
%{a: 1, b: 2, c: 3}
[a: 1, b: 2, c: 3]
# => [{:a, 1}, {:b, 2}, {:c, 3}]
range = (1..100)
interval = Enum.slice(range, 30, 10)
evens = Enum.filter(interval, fn(n) -> rem(n, 2) == 0 end)
multiplied = Enum.map(evens, fn(n) -> n * 10 end)
Enum.take(multiplied, 2)
range = (1..100)
# => [1, 2, 3, 4 ... 98, 99, 100]
interval = Enum.slice(range, 30, 10)
# => [31, 32, 33, 34, 35, 36, 37, 38, 39, 40]
evens = Enum.filter(interval, fn(n) -> rem(n, 2) == 0 end)
# => [32, 34, 36, 38, 40]
multiplied = Enum.map(evens, fn(n) -> n * 10 end)
# => [320, 340, 360, 380, 400]
Enum.take(multiplied, 2)
# => [320, 340]
range = (1..100)
interval = Enum.slice(range, 30, 10)
evens = Enum.filter(interval, fn(n) -> rem(n, 2) == 0 end)
multiplied = Enum.map(evens, fn(n) -> n * 10 end)
Enum.take(multiplied, 2)
Enum.take(
Enum.map(
Enum.filter(
Enum.slice((1..100), 30, 10),
fn(n) -> rem(n, 2) == 0 end
),
fn(n) -> n * 10 end
), 2
)
range = (1..100)
interval = Enum.slice(range, 30, 10)
evens = Enum.filter(interval, fn(n) -> rem(n, 2) == 0 end)
multiplied = Enum.map(evens, fn(n) -> n * 10 end)
Enum.take(multiplied, 2)
(1..100)
|> Enum.slice(30, 10)
|> Enum.filter(fn(n) -> rem(n, 2) end)
|> Enum.map(fn(n) -> n * 10 end)
|> Enum.take(2)
(1..100)
|> Enum.slice(30, 10)
|> Enum.filter(&(rem(&1, 2)))
|> Enum.map(&(&1 * 10))
|> Enum.take(2)
(1..100)
|> Enum.slice(30, 10)
|> Enum.filter(fn(n) -> rem(n, 2) end)
|> Enum.map(fn(n) -> n * 10 end)
|> Enum.take(2)
PIPE OPERATOR
|>
function = fn -> IO.puts("Hello from function") end
function.()
# => Hello from function
pid = spawn(function)
# => Hello from function
Process.alive?(pid)
# => false
Process.alive?(self)
# => true
pid = spawn(fn ->
receive do
{:say, from} ->
send(from, "say what?")
_ ->
Process.exit(self, :normal)
end
end)
Process.alive?(pid)
# => true
send(pid, {:say, self})
receive do
message ->
IO.puts("Recebido: " <> message)
end
# => Recebido: say what?
send(pid, "blabla")
Process.alive?(pid)
# => false
“PROCESSES”
Lightweight
Isolated
Message passing
Mailbox
Garbage Collected
pid = spawn(fn -> ... end)
Process.exit(pid, :kill)
pid = spawn_link(fn ->
receive do
{:say, from} ->
send(from, "say what?")
_ ->
Process.exit(self, :normal)
end
end)
send(pid, "blabla")
** (EXIT from #PID<0.47.0>) killed
pid = spawn_link(fn -> ... end)
Process.exit(pid, :kill)
pid = spawn_link(fn ->
receive do
{:say, from} ->
send(from, "say what?")
_ ->
Process.exit(self, :normal)
end
end)
Process.flag(:trap_exit, true)
send(pid, "blabla")
receive do
{:EXIT, _pid, reason} ->
IO.puts("Motivo do crash: #{reason}")
end
# => Motivo do crash: normal
ASYNCHRONOUS
EXCEPTIONS
(spawn_link, flag, exit)
“GLOBALS”
Javascript
Scala
Go
Clojure
...
defmodule Stack do
def start_link do
Agent.start_link(fn -> [] end,
name: __MODULE__)
end
def pop do
Agent.get_and_update(__MODULE__,
fn(state) ->
[head|tail] = state
{head, tail}
end)
end
def push(new_value) do
Agent.update(__MODULE__,
fn(state) ->
[new_value|state]
end)
end
end
Stack.start_link
Stack.push "hello"
Stack.push "world"
Stack.pop
# => world
Stack.pop
# => hello
Process.list |> Enum.reverse |> Enum.at(0) |> Process.exit(:kill)
Stack.push "foo"
# => ** (exit) exited in: GenServer.call(Stack, {:update, ...,
5000)
# ** (EXIT) no process
# (elixir) lib/gen_server.ex:564: GenServer.call/3
defmodule Stack.Supervisor do
use Supervisor
def start_link do
Supervisor.start_link(__MODULE__, :ok)
end
def init(:ok) do
children = [
worker(Stack, [])
]
supervise(children, strategy: :one_for_one)
end
end
Stack.Supervisor.start_link
Stack.push "hello"
Stack.push "world"
Stack.pop
# => world
Stack.pop
# => hello
Process.list |> Enum.reverse |> Enum.at(0) |> Process.exit(:kill)
Stack.push "foo"
Stack.push "bla"
Stack.pop
# => bla
Stack.pop
# => foo
Stack.Supervisor.start_link
Process.list |> Enum.reverse |> Enum.at(0) |> Process.exit(:kill)
“YOCTO” SERVICES
(micro > nano > pico > femto > atto > zepto > yocto>
APRENDENDO
OBRIGADO!
Perguntas?
@akitaonrails

Mais conteúdo relacionado

Mais procurados

ECMAScript 6 new features
ECMAScript 6 new featuresECMAScript 6 new features
ECMAScript 6 new featuresGephenSG
 
Build a compiler in 2hrs - NCrafts Paris 2015
Build a compiler in 2hrs -  NCrafts Paris 2015Build a compiler in 2hrs -  NCrafts Paris 2015
Build a compiler in 2hrs - NCrafts Paris 2015Phillip Trelford
 
Part2 from math import * from simpson import * k=1 def f(x): return (exp(-(x...
Part2 from math import * from simpson import *  k=1 def f(x): return (exp(-(x...Part2 from math import * from simpson import *  k=1 def f(x): return (exp(-(x...
Part2 from math import * from simpson import * k=1 def f(x): return (exp(-(x...hwbloom25
 
Javascript - The basics
Javascript - The basicsJavascript - The basics
Javascript - The basicsBruno Paulino
 
[EN] Ada Lovelace Day 2014 - Tampon run
[EN] Ada Lovelace Day 2014  - Tampon run[EN] Ada Lovelace Day 2014  - Tampon run
[EN] Ada Lovelace Day 2014 - Tampon runMaja Kraljič
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my dayTor Ivry
 
Introduction to jRuby
Introduction to jRubyIntroduction to jRuby
Introduction to jRubyAdam Kalsey
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?Adam Dudczak
 
The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6Bryan Hughes
 
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...akaptur
 
Perl 5.10 on OSDC.tw 2009
Perl 5.10 on OSDC.tw 2009Perl 5.10 on OSDC.tw 2009
Perl 5.10 on OSDC.tw 2009scweng
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonakaptur
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)hasan0812
 
大量地区化解决方案V5
大量地区化解决方案V5大量地区化解决方案V5
大量地区化解决方案V5bqconf
 
The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)GroovyPuzzlers
 

Mais procurados (20)

Let's golang
Let's golangLet's golang
Let's golang
 
PubNative Tracker
PubNative TrackerPubNative Tracker
PubNative Tracker
 
FPBrno 2018-05-22: Benchmarking in elixir
FPBrno 2018-05-22: Benchmarking in elixirFPBrno 2018-05-22: Benchmarking in elixir
FPBrno 2018-05-22: Benchmarking in elixir
 
Python Tidbits
Python TidbitsPython Tidbits
Python Tidbits
 
ECMAScript 6 new features
ECMAScript 6 new featuresECMAScript 6 new features
ECMAScript 6 new features
 
Build a compiler in 2hrs - NCrafts Paris 2015
Build a compiler in 2hrs -  NCrafts Paris 2015Build a compiler in 2hrs -  NCrafts Paris 2015
Build a compiler in 2hrs - NCrafts Paris 2015
 
Part2 from math import * from simpson import * k=1 def f(x): return (exp(-(x...
Part2 from math import * from simpson import *  k=1 def f(x): return (exp(-(x...Part2 from math import * from simpson import *  k=1 def f(x): return (exp(-(x...
Part2 from math import * from simpson import * k=1 def f(x): return (exp(-(x...
 
Javascript - The basics
Javascript - The basicsJavascript - The basics
Javascript - The basics
 
[EN] Ada Lovelace Day 2014 - Tampon run
[EN] Ada Lovelace Day 2014  - Tampon run[EN] Ada Lovelace Day 2014  - Tampon run
[EN] Ada Lovelace Day 2014 - Tampon run
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
 
Introduction to jRuby
Introduction to jRubyIntroduction to jRuby
Introduction to jRuby
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6
 
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
 
Perl 5.10 on OSDC.tw 2009
Perl 5.10 on OSDC.tw 2009Perl 5.10 on OSDC.tw 2009
Perl 5.10 on OSDC.tw 2009
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)
 
大量地区化解决方案V5
大量地区化解决方案V5大量地区化解决方案V5
大量地区化解决方案V5
 
Go a crash course
Go   a crash courseGo   a crash course
Go a crash course
 
The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)
 

Semelhante a Elixir Tolerância a Falhas para Adultos - Fabio Akita

Elixir -Tolerância a Falhas para Adultos - GDG Campinas
Elixir  -Tolerância a Falhas para Adultos - GDG CampinasElixir  -Tolerância a Falhas para Adultos - GDG Campinas
Elixir -Tolerância a Falhas para Adultos - GDG CampinasFabio Akita
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingMuthu Vinayagam
 
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoThe Software House
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a ElixirSvet Ivantchev
 
Erlang bootstrap course
Erlang bootstrap courseErlang bootstrap course
Erlang bootstrap courseMartin Logan
 
Ruby - Uma Introdução
Ruby - Uma IntroduçãoRuby - Uma Introdução
Ruby - Uma IntroduçãoÍgor Bonadio
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with PythonHan Lee
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyArturo Herrero
 
FS2 for Fun and Profit
FS2 for Fun and ProfitFS2 for Fun and Profit
FS2 for Fun and ProfitAdil Akhter
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1Ke Wei Louis
 

Semelhante a Elixir Tolerância a Falhas para Adultos - Fabio Akita (20)

Elixir -Tolerância a Falhas para Adultos - GDG Campinas
Elixir  -Tolerância a Falhas para Adultos - GDG CampinasElixir  -Tolerância a Falhas para Adultos - GDG Campinas
Elixir -Tolerância a Falhas para Adultos - GDG Campinas
 
Lập trình Python cơ bản
Lập trình Python cơ bảnLập trình Python cơ bản
Lập trình Python cơ bản
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
PythonOOP
PythonOOPPythonOOP
PythonOOP
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python Programming
 
Java VS Python
Java VS PythonJava VS Python
Java VS Python
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Basics
BasicsBasics
Basics
 
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duo
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
 
Erlang bootstrap course
Erlang bootstrap courseErlang bootstrap course
Erlang bootstrap course
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Elixir cheatsheet
Elixir cheatsheetElixir cheatsheet
Elixir cheatsheet
 
Ruby - Uma Introdução
Ruby - Uma IntroduçãoRuby - Uma Introdução
Ruby - Uma Introdução
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Python From Scratch (1).pdf
Python From Scratch  (1).pdfPython From Scratch  (1).pdf
Python From Scratch (1).pdf
 
FS2 for Fun and Profit
FS2 for Fun and ProfitFS2 for Fun and Profit
FS2 for Fun and Profit
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 

Mais de Fabio Akita

Devconf 2019 - São Carlos
Devconf 2019 - São CarlosDevconf 2019 - São Carlos
Devconf 2019 - São CarlosFabio Akita
 
Meetup Nerdzão - English Talk about Languages
Meetup Nerdzão  - English Talk about LanguagesMeetup Nerdzão  - English Talk about Languages
Meetup Nerdzão - English Talk about LanguagesFabio Akita
 
Desmistificando Blockchains p/ Developers - Criciuma Dev Conf 2018
Desmistificando Blockchains p/ Developers - Criciuma Dev Conf 2018Desmistificando Blockchains p/ Developers - Criciuma Dev Conf 2018
Desmistificando Blockchains p/ Developers - Criciuma Dev Conf 2018Fabio Akita
 
Desmistificando Blockchains - 20o Encontro Locaweb SP
Desmistificando Blockchains - 20o Encontro Locaweb SPDesmistificando Blockchains - 20o Encontro Locaweb SP
Desmistificando Blockchains - 20o Encontro Locaweb SPFabio Akita
 
Desmistificando Blockchains - Insiter Goiania
Desmistificando Blockchains - Insiter GoianiaDesmistificando Blockchains - Insiter Goiania
Desmistificando Blockchains - Insiter GoianiaFabio Akita
 
Blockchain em 7 minutos - 7Masters
Blockchain em 7 minutos - 7MastersBlockchain em 7 minutos - 7Masters
Blockchain em 7 minutos - 7MastersFabio Akita
 
Desmistificando Mitos de Tech Startups - Intercon 2017
Desmistificando Mitos de Tech Startups - Intercon 2017Desmistificando Mitos de Tech Startups - Intercon 2017
Desmistificando Mitos de Tech Startups - Intercon 2017Fabio Akita
 
30 Days to Elixir and Crystal and Back to Ruby
30 Days to Elixir and Crystal and Back to Ruby30 Days to Elixir and Crystal and Back to Ruby
30 Days to Elixir and Crystal and Back to RubyFabio Akita
 
Uma Discussão sobre a Carreira de TI
Uma Discussão sobre a Carreira de TIUma Discussão sobre a Carreira de TI
Uma Discussão sobre a Carreira de TIFabio Akita
 
THE CONF - Opening Keynote
THE CONF - Opening KeynoteTHE CONF - Opening Keynote
THE CONF - Opening KeynoteFabio Akita
 
A Journey through New Languages - Rancho Dev 2017
A Journey through New Languages - Rancho Dev 2017A Journey through New Languages - Rancho Dev 2017
A Journey through New Languages - Rancho Dev 2017Fabio Akita
 
Desmistificando Mitos de Startups - Sebrae - AP
Desmistificando Mitos de Startups - Sebrae - APDesmistificando Mitos de Startups - Sebrae - AP
Desmistificando Mitos de Startups - Sebrae - APFabio Akita
 
A Journey through New Languages - Guru Sorocaba 2017
A Journey through New Languages - Guru Sorocaba 2017A Journey through New Languages - Guru Sorocaba 2017
A Journey through New Languages - Guru Sorocaba 2017Fabio Akita
 
A Journey through New Languages - Insiter 2017
A Journey through New Languages - Insiter 2017A Journey through New Languages - Insiter 2017
A Journey through New Languages - Insiter 2017Fabio Akita
 
A Journey through New Languages - Locaweb Tech Day
A Journey through New Languages - Locaweb Tech DayA Journey through New Languages - Locaweb Tech Day
A Journey through New Languages - Locaweb Tech DayFabio Akita
 
A Journey through new Languages - Intercon 2016
A Journey through new Languages - Intercon 2016A Journey through new Languages - Intercon 2016
A Journey through new Languages - Intercon 2016Fabio Akita
 
Premature Optimization 2.0 - Intercon 2016
Premature Optimization 2.0 - Intercon 2016Premature Optimization 2.0 - Intercon 2016
Premature Optimization 2.0 - Intercon 2016Fabio Akita
 
Conexão Kinghost - Otimização Prematura
Conexão Kinghost - Otimização PrematuraConexão Kinghost - Otimização Prematura
Conexão Kinghost - Otimização PrematuraFabio Akita
 
The Open Commerce Conference - Premature Optimisation: The Root of All Evil
The Open Commerce Conference - Premature Optimisation: The Root of All EvilThe Open Commerce Conference - Premature Optimisation: The Root of All Evil
The Open Commerce Conference - Premature Optimisation: The Root of All EvilFabio Akita
 
Premature optimisation: The Root of All Evil
Premature optimisation: The Root of All EvilPremature optimisation: The Root of All Evil
Premature optimisation: The Root of All EvilFabio Akita
 

Mais de Fabio Akita (20)

Devconf 2019 - São Carlos
Devconf 2019 - São CarlosDevconf 2019 - São Carlos
Devconf 2019 - São Carlos
 
Meetup Nerdzão - English Talk about Languages
Meetup Nerdzão  - English Talk about LanguagesMeetup Nerdzão  - English Talk about Languages
Meetup Nerdzão - English Talk about Languages
 
Desmistificando Blockchains p/ Developers - Criciuma Dev Conf 2018
Desmistificando Blockchains p/ Developers - Criciuma Dev Conf 2018Desmistificando Blockchains p/ Developers - Criciuma Dev Conf 2018
Desmistificando Blockchains p/ Developers - Criciuma Dev Conf 2018
 
Desmistificando Blockchains - 20o Encontro Locaweb SP
Desmistificando Blockchains - 20o Encontro Locaweb SPDesmistificando Blockchains - 20o Encontro Locaweb SP
Desmistificando Blockchains - 20o Encontro Locaweb SP
 
Desmistificando Blockchains - Insiter Goiania
Desmistificando Blockchains - Insiter GoianiaDesmistificando Blockchains - Insiter Goiania
Desmistificando Blockchains - Insiter Goiania
 
Blockchain em 7 minutos - 7Masters
Blockchain em 7 minutos - 7MastersBlockchain em 7 minutos - 7Masters
Blockchain em 7 minutos - 7Masters
 
Desmistificando Mitos de Tech Startups - Intercon 2017
Desmistificando Mitos de Tech Startups - Intercon 2017Desmistificando Mitos de Tech Startups - Intercon 2017
Desmistificando Mitos de Tech Startups - Intercon 2017
 
30 Days to Elixir and Crystal and Back to Ruby
30 Days to Elixir and Crystal and Back to Ruby30 Days to Elixir and Crystal and Back to Ruby
30 Days to Elixir and Crystal and Back to Ruby
 
Uma Discussão sobre a Carreira de TI
Uma Discussão sobre a Carreira de TIUma Discussão sobre a Carreira de TI
Uma Discussão sobre a Carreira de TI
 
THE CONF - Opening Keynote
THE CONF - Opening KeynoteTHE CONF - Opening Keynote
THE CONF - Opening Keynote
 
A Journey through New Languages - Rancho Dev 2017
A Journey through New Languages - Rancho Dev 2017A Journey through New Languages - Rancho Dev 2017
A Journey through New Languages - Rancho Dev 2017
 
Desmistificando Mitos de Startups - Sebrae - AP
Desmistificando Mitos de Startups - Sebrae - APDesmistificando Mitos de Startups - Sebrae - AP
Desmistificando Mitos de Startups - Sebrae - AP
 
A Journey through New Languages - Guru Sorocaba 2017
A Journey through New Languages - Guru Sorocaba 2017A Journey through New Languages - Guru Sorocaba 2017
A Journey through New Languages - Guru Sorocaba 2017
 
A Journey through New Languages - Insiter 2017
A Journey through New Languages - Insiter 2017A Journey through New Languages - Insiter 2017
A Journey through New Languages - Insiter 2017
 
A Journey through New Languages - Locaweb Tech Day
A Journey through New Languages - Locaweb Tech DayA Journey through New Languages - Locaweb Tech Day
A Journey through New Languages - Locaweb Tech Day
 
A Journey through new Languages - Intercon 2016
A Journey through new Languages - Intercon 2016A Journey through new Languages - Intercon 2016
A Journey through new Languages - Intercon 2016
 
Premature Optimization 2.0 - Intercon 2016
Premature Optimization 2.0 - Intercon 2016Premature Optimization 2.0 - Intercon 2016
Premature Optimization 2.0 - Intercon 2016
 
Conexão Kinghost - Otimização Prematura
Conexão Kinghost - Otimização PrematuraConexão Kinghost - Otimização Prematura
Conexão Kinghost - Otimização Prematura
 
The Open Commerce Conference - Premature Optimisation: The Root of All Evil
The Open Commerce Conference - Premature Optimisation: The Root of All EvilThe Open Commerce Conference - Premature Optimisation: The Root of All Evil
The Open Commerce Conference - Premature Optimisation: The Root of All Evil
 
Premature optimisation: The Root of All Evil
Premature optimisation: The Root of All EvilPremature optimisation: The Root of All Evil
Premature optimisation: The Root of All Evil
 

Último

Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 

Último (20)

Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 

Elixir Tolerância a Falhas para Adultos - Fabio Akita

  • 1. ELIXIRTolerância a Falhas para Adultos Fabio Akita
  • 3. Rubyconf Brasil 2016 – 23 e 24 de SetembroRubyconf Brasil 2016 – 23 e 24 de Setembro
  • 4. Rubyconf Brasil 2016 – 23 e 24 de SetembroRubyconf Brasil 2016 – 23 e 24 de Setembro
  • 5. Rubyconf Brasil 2016 – 23 e 24 de SetembroRubyconf Brasil 2016 – 23 e 24 de Setembro
  • 6.
  • 7. Chris McCordChris McCord José ValimJosé Valim
  • 8. Joe Armstrong - EricssonJoe Armstrong - Ericsson
  • 9.
  • 10.
  • 11. defmodule Teste do def say(name) do IO.puts("Hello #{name}") end end Teste.say("Fabio") defmodule Teste do @spec say(String.t) def say(name) when is_string(name) do IO.puts "Hello " <> name end end Teste.say "Fabio"
  • 13. -module(teste). -export([qsort/1]). qsort([]) -> []; qsort([Pivot|T]) -> qsort([X||X<-T,X =< Pivot]) ++ [Pivot] ++ qsort([X||X<-T,X > Pivot]). defmodule Teste do def qsort([]), do: [] def qsort([pivot|t]) do qsort(for x <- t, x < pivot, do: x) ++ [pivot] ++ qsort(for x <- t, x >= pivot, do: x) end end
  • 14. defmodule Teste do def factorial(n) do if n == 0 do 1 else n * factorial(n - 1) end end end Teste.factorial(10) # => 3628800 defmodule Teste do def factorial(0), do: 1 def factorial(n) do n * factorial(n - 1) end end Teste.factorial(10) # => 3628800
  • 16. {:ok, result} = Enum.fetch([1, 2, 3, 4], 3) IO.puts result # => 4 registro = {:ok, %{name: "Fabio", last_name: "Akita"}} {:ok, %{name: name}} = registro IO.puts name # => Fabio registro = %{name: "Fabio", year: 2016, foo: {:ok, [1, 2, 3]}} %{name: name, foo: {:ok, result}} = registro IO.puts Enum.join([name|result], ", ") # => Fabio, 1, 2, 3 %{last_name: name} = registro # => ** (MatchError) no match of right hand side value: ...
  • 18. a = 1 a = 2 IO.puts a # => 2 ^a = 3 # => ** (MatchError) no match of right hand side value: 3 message = "Hello" IO.puts message <> " World!" # => "Hello World! IO.puts "#{message} World!" # => "Hello World! {:a, "b", 67, true} [:a, "b", 67, true] %{a: 1, b: 2, c: 3} [a: 1, b: 2, c: 3] # => [{:a, 1}, {:b, 2}, {:c, 3}]
  • 19. range = (1..100) interval = Enum.slice(range, 30, 10) evens = Enum.filter(interval, fn(n) -> rem(n, 2) == 0 end) multiplied = Enum.map(evens, fn(n) -> n * 10 end) Enum.take(multiplied, 2) range = (1..100) # => [1, 2, 3, 4 ... 98, 99, 100] interval = Enum.slice(range, 30, 10) # => [31, 32, 33, 34, 35, 36, 37, 38, 39, 40] evens = Enum.filter(interval, fn(n) -> rem(n, 2) == 0 end) # => [32, 34, 36, 38, 40] multiplied = Enum.map(evens, fn(n) -> n * 10 end) # => [320, 340, 360, 380, 400] Enum.take(multiplied, 2) # => [320, 340]
  • 20. range = (1..100) interval = Enum.slice(range, 30, 10) evens = Enum.filter(interval, fn(n) -> rem(n, 2) == 0 end) multiplied = Enum.map(evens, fn(n) -> n * 10 end) Enum.take(multiplied, 2) Enum.take( Enum.map( Enum.filter( Enum.slice((1..100), 30, 10), fn(n) -> rem(n, 2) == 0 end ), fn(n) -> n * 10 end ), 2 )
  • 21. range = (1..100) interval = Enum.slice(range, 30, 10) evens = Enum.filter(interval, fn(n) -> rem(n, 2) == 0 end) multiplied = Enum.map(evens, fn(n) -> n * 10 end) Enum.take(multiplied, 2) (1..100) |> Enum.slice(30, 10) |> Enum.filter(fn(n) -> rem(n, 2) end) |> Enum.map(fn(n) -> n * 10 end) |> Enum.take(2)
  • 22. (1..100) |> Enum.slice(30, 10) |> Enum.filter(&(rem(&1, 2))) |> Enum.map(&(&1 * 10)) |> Enum.take(2) (1..100) |> Enum.slice(30, 10) |> Enum.filter(fn(n) -> rem(n, 2) end) |> Enum.map(fn(n) -> n * 10 end) |> Enum.take(2)
  • 24. function = fn -> IO.puts("Hello from function") end function.() # => Hello from function pid = spawn(function) # => Hello from function Process.alive?(pid) # => false Process.alive?(self) # => true
  • 25. pid = spawn(fn -> receive do {:say, from} -> send(from, "say what?") _ -> Process.exit(self, :normal) end end) Process.alive?(pid) # => true send(pid, {:say, self}) receive do message -> IO.puts("Recebido: " <> message) end # => Recebido: say what? send(pid, "blabla") Process.alive?(pid) # => false
  • 27. pid = spawn(fn -> ... end) Process.exit(pid, :kill)
  • 28. pid = spawn_link(fn -> receive do {:say, from} -> send(from, "say what?") _ -> Process.exit(self, :normal) end end) send(pid, "blabla") ** (EXIT from #PID<0.47.0>) killed
  • 29. pid = spawn_link(fn -> ... end) Process.exit(pid, :kill)
  • 30. pid = spawn_link(fn -> receive do {:say, from} -> send(from, "say what?") _ -> Process.exit(self, :normal) end end) Process.flag(:trap_exit, true) send(pid, "blabla") receive do {:EXIT, _pid, reason} -> IO.puts("Motivo do crash: #{reason}") end # => Motivo do crash: normal
  • 33. defmodule Stack do def start_link do Agent.start_link(fn -> [] end, name: __MODULE__) end def pop do Agent.get_and_update(__MODULE__, fn(state) -> [head|tail] = state {head, tail} end) end def push(new_value) do Agent.update(__MODULE__, fn(state) -> [new_value|state] end) end end
  • 34. Stack.start_link Stack.push "hello" Stack.push "world" Stack.pop # => world Stack.pop # => hello Process.list |> Enum.reverse |> Enum.at(0) |> Process.exit(:kill) Stack.push "foo" # => ** (exit) exited in: GenServer.call(Stack, {:update, ..., 5000) # ** (EXIT) no process # (elixir) lib/gen_server.ex:564: GenServer.call/3
  • 35. defmodule Stack.Supervisor do use Supervisor def start_link do Supervisor.start_link(__MODULE__, :ok) end def init(:ok) do children = [ worker(Stack, []) ] supervise(children, strategy: :one_for_one) end end
  • 36. Stack.Supervisor.start_link Stack.push "hello" Stack.push "world" Stack.pop # => world Stack.pop # => hello Process.list |> Enum.reverse |> Enum.at(0) |> Process.exit(:kill) Stack.push "foo" Stack.push "bla" Stack.pop # => bla Stack.pop # => foo
  • 37. Stack.Supervisor.start_link Process.list |> Enum.reverse |> Enum.at(0) |> Process.exit(:kill)
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46. “YOCTO” SERVICES (micro > nano > pico > femto > atto > zepto > yocto>
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 53.
  • 54.
  • 55.
  • 56.