Phoenix and beyond: Things we do with Elixir - Alexander Khokhlov

Elixir Club
Elixir ClubElixir Club
Александр Хохлов
@nots_io
Phoenix and beyond:
Things we do with Elixir
Founder at Nots.io
http://nots.io
Phoenix and beyond: Things we do with Elixir - Alexander Khokhlov
Phoenix and beyond: Things we do with Elixir - Alexander Khokhlov
Phoenix and beyond: Things we do with Elixir - Alexander Khokhlov
Why this talk?
In the beginning…
Phoenix:
Web Sockets, HAML, SASS
Guardian, Arc, ex_aws, Swoosh,
ueberauth/ueberauth_github
RethinkDB
rethinkdb_changefeed
postgrex
https://github.com/h4cc/
awesome-elixir
http://obolinx.com/resources/?p=1837
Erlang/Elixir port to Java process
with JInterface
https://www.safaribooksonline.com/library/view/erlang-programming/9780596803940/ch16s05.html
Phoenix and beyond: Things we do with Elixir - Alexander Khokhlov
def init(_params) do 

cd = “#{:code.priv_dir(:your_app)}" 

cmd = "java -jar package.jar" 

port = Port.open({:spawn,cmd}, [:binary, :use_stdio,
packet: 4, cd: cd]) 

true = Port.connect(port, self()) 

{:ok,port} 

end
Port.command(port, :erlang.term_to_binary(data))
def handle_info({port,{:data,b}}, port) do 

data = :erlang.binary_to_term(b) 

end
Postgrex.Notifications +
GenServer
Phoenix and beyond: Things we do with Elixir - Alexander Khokhlov
PLPGSQL:
PERFORM pg_notify(‘invitations_changes’, payload)
Elixir:
{:ok, pid} = Postgrex.Notifications.start_link(config)
Postgrex.Notifications.listen(pid, "invitations_changes") 



def handle_info({:notification, _pid, _ref,
"invitations_changes", payload}, state) do … end
Phoenix and beyond: Things we do with Elixir - Alexander Khokhlov
API:
HTTP API with
Poison & HTTPoison
HTTPoison.put(url, Poison.encode!(data)) 

HTTPoison.get(url) 

HTTPoison.post(url, Poison.encode!(data))) 

case resp do 

{:ok, %HTTPoison.Response{status_code: 200, body: body}}->
{:ok, body |> Poison.decode!} 

{:ok, %HTTPoison.Response{status_code: 404}} ->
{:error, :not_found} 

{:ok, %HTTPoison.Response{body: body}} ->
{:error, body |> Poison.decode!} 

{:error, %HTTPoison.Error{reason: reason}} ->
{:error, reason} 

end 

API:
Socket API with gen_tcp
Phoenix and beyond: Things we do with Elixir - Alexander Khokhlov
# receive tcp packet as message 

{:ok, socket} = :gen_tcp.connect('localhost', port,
[:binary, active: true]) 

def handle_info({:tcp, _socket, msg}, state) do ...
end 



# receive tcp packet with recv 

:inet.setopts(socket, active: false) 

:ok = :gen_tcp.send(socket, data) 

{:ok, <<_msg_len :: binary - size(16),
msg :: binary>>} = :gen_tcp.recv(socket, 0, 2000) 

Concurrent tasks
results = notes 

|> Task.async_stream(__MODULE__, :update,
[some, params], max_concurrency: 20) 

|> Enum.to_list 

|> Keyword.get(:ok) 



def update(note, some, params) do ... end 

Phoenix and beyond: Things we do with Elixir - Alexander Khokhlov
point@nots.io
http://nots.io
http://blog.nots.io
@nots_io
facebook.com/nots.io
1 of 29

More Related Content

What's hot(19)

Fun with exploits old and newFun with exploits old and new
Fun with exploits old and new
Larry Cashdollar432 views
Fake My PartyFake My Party
Fake My Party
Tanja Otto1.2K views
Ansible for beginners ...?Ansible for beginners ...?
Ansible for beginners ...?
shirou wakayama5.9K views
Node.jsNode.js
Node.js
Mat Schaffer823 views
Git::HooksGit::Hooks
Git::Hooks
Mikko Koivunalho875 views
Machine learning on source codeMachine learning on source code
Machine learning on source code
source{d}540 views
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricks
bcoca24.1K views
MeshU Thin & RackMeshU Thin & Rack
MeshU Thin & Rack
guestbac5dc1.5K views
Cooking with ChefCooking with Chef
Cooking with Chef
Orlando_Ruby_Users_Group743 views
New ES6 HotnessNew ES6 Hotness
New ES6 Hotness
Pawel Szymczykowski907 views
Effective ES6Effective ES6
Effective ES6
Teppei Sato52.2K views
Introduction to RetrofitIntroduction to Retrofit
Introduction to Retrofit
Kazuhiro Serizawa3.1K views

Similar to Phoenix and beyond: Things we do with Elixir - Alexander Khokhlov(20)

ElixirElixir
Elixir
Robert Brown3.6K views
Cosmos, Big Data GE implementation in FIWARECosmos, Big Data GE implementation in FIWARE
Cosmos, Big Data GE implementation in FIWARE
Fernando Lopez Aguilar3.5K views
Erlang sucks. EUC 2012Erlang sucks. EUC 2012
Erlang sucks. EUC 2012
Dmitrii Dimandt2.1K views
Transforming WebSocketsTransforming WebSockets
Transforming WebSockets
Arnout Kazemier5.4K views
Node introNode intro
Node intro
cloudhead919 views
Diseño y Desarrollo de APIsDiseño y Desarrollo de APIs
Diseño y Desarrollo de APIs
Raúl Neis153 views
Great Developers StealGreat Developers Steal
Great Developers Steal
Ben Scofield1.7K views
extending-phpextending-php
extending-php
tutorialsruby369 views
extending-phpextending-php
extending-php
tutorialsruby2K views

More from Elixir Club(20)

Phoenix and beyond: Things we do with Elixir - Alexander Khokhlov