Skip to content

Instantly share code, notes, and snippets.

View emerleite's full-sized avatar

Emerson Macedo emerleite

View GitHub Profile
@emerleite
emerleite / decode.txt
Created November 12, 2018 17:53 — forked from michalmuskala/decode.txt
Jason benches
Operating System: macOS"
CPU Information: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Number of Available Cores: 8
Available memory: 16 GB
Elixir 1.7.0-dev
Erlang 21.0
Benchmark suite executing with the following configuration:
warmup: 5 s
time: 30 s
@emerleite
emerleite / 1-README.md
Created October 9, 2018 22:14 — forked from tonytonyjan/1-README.md
Remote React Components Loading
defmodule Upa.VideoWatchProgress do
def save(attrs) do
struct(Upa.VideoWatchProgress, attrs)
|> changeset
|> Upa.Repo.insert(on_conflict: insert_conflict_strategy(attrs))
|> case do
{:error, _} = error -> raise Upa.DatabaseCommandError
{:ok, changeset} -> :ok
end
end
defmodule UpaEventSourcing.VideoWatchProgress.EventAggregator do
def start_link(event) do
Task.start_link(fn ->
Upa.VideoWatchProgress.save(event) #Saves to the database
end)
end
end
defmodule UpaEventSourcing.VideoWatchProgress.EventConsumer do
use ConsumerSupervisor
children = [
worker(UpaEventSourcing.VideoWatchProgress.EventStore, []),
worker(UpaEventSourcing.VideoWatchProgress.EventConsumer, [
%{producer: UpaEventSourcing.VideoWatchProgress.EventStore,
processor: UpaEventSourcing.VideoWatchProgress.EventAggregator}
])
]
config :upa, video_watch_progress_min_demand: 1
config :upa, video_watch_progress_max_demand: 192
config :upa, Upa.Repo,
adapter: Ecto.Adapters.MySQL,
hostname: "host.example.com",
database: "our_database",
username: "${MYSQL_USR}",
password: "${MYSQL_PWD}",
pool_size: 48
defmodule UpaEventSourcing.VideoWatchProgress.EventStore do
use GenStage
@event_processing_timeout 11 #Max seconds to process a track video watch progress event
def start_link() do
@emerleite
emerleite / video_watch_progress_controller.ex
Last active February 2, 2018 01:34
VideoWatchProgressController
#Phoenix Action
def track_time(conn, params) do
RequestParamsHandler.prepare(conn, params)
|> EventStore.enqueue #Send to GenStage pipeline
send_resp(conn, 201, "")
end
@emerleite
emerleite / upa_event_sourcing_application.ex
Last active November 23, 2017 20:16
User Profile API Event Sourcing
#Supervision Tree definition for Events
children = [
worker(UpaEventSourcing.VideoWatchProgress.EventStore, []),
worker(UpaEventSourcing.VideoWatchProgress.EventConsumer, [
%{producer: UpaEventSourcing.VideoWatchProgress.EventStore,
processor: UpaEventSourcing.VideoWatchProgress.EventAggregator}
])
]
@emerleite
emerleite / elixirconf-2017-recap.md
Created September 29, 2017 17:45 — forked from KronicDeth/elixirconf-2017-recap.md
Recap of all talks at ElixirConf 2017

Elixir Native UI - Boyd Multerer https://www.youtube.com/watch?v=77FW-jrCyCs

Thinking In Ecto - Darin Wilson https://www.youtube.com/watch?v=YQxopjai0CU

  1. Repository pattern https://youtu.be/YQxopjai0CU?t=2m12s
  2. Explicitness https://youtu.be/YQxopjai0CU?t=5m29s