Skip to content

Instantly share code, notes, and snippets.

View josevalim's full-sized avatar

José Valim josevalim

View GitHub Profile
defmodule FibAgent do
def start_link do
cache = Enum.into([{0, 0}, {1, 1}], HashDict.new)
Agent.start_link(fn -> cache end)
end
def fib(pid, n) when n >= 0 do
Agent.get_and_update(pid, &do_fib(&1, n))
end
defmodule Exq.RouterPlug do
import Plug.Conn
use Plug.Router
plug :match
plug :dispatch
get "/queues" do
IO.puts "YOLO"
conn |> halt()
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
@josevalim
josevalim / phoenix showdown rackspace onmetal io.md
Last active October 31, 2022 13:59 — forked from omnibs/phoenix showdown rackspace onmetal io.md
Phoenix Showdown Comparative Benchmarks @ Rackspace

Comparative Benchmark Numbers @ Rackspace

I've taken the benchmarks from Matthew Rothenberg's phoenix-showdown, updated Phoenix to 0.13.1 and ran the tests on the most powerful machines available at Rackspace.

Results

Framework Throughput (req/s) Latency (ms) Consistency (σ ms)
@josevalim
josevalim / authorize.ex
Last active April 29, 2018 09:16 — forked from jeremytregunna/authorize.ex
This looks horrible (formatter)
defmodule Api.Authorize do
alias Account.Models.User
def board?(board_id, %User{} = user, available_permissions, required_permissions) do
with(
{:ok, board} <- Tracker.Board.find(board_id),
true <- Tracker.OrganizationMembers.user_in_organization?(user.id, board.organization_id),
^required_permissions <-
Enum.to_list(
MapSet.intersection(