Skip to content

Instantly share code, notes, and snippets.

View josevalim's full-sized avatar

José Valim josevalim

View GitHub Profile
@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 / sample output
Created May 24, 2012 17:53 — forked from alco/sample output
Updated Elixir chat demo
defmodule Chat.Client do
# In all of the following functions 'server' stands for the server's pid
def join(server) do
send server, :join
end
def say(server, message) do
send server, { :say, message }
end
@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(
% from my unit tests
foo = 10
assert 10 == my_macro(:foo)
assert 10 == my_macro("foo")
% macro
defmacro my_macro(some_var) when is_atom(some_var) do
defmodule Dict.Behaviour do
# It is assumed that the client module implements following functions:
#
# size/1, fetch/2, put/3, reduce/3, update/4, delete/2
#
defmacro __using__(_) do
quote do
# Following are exact copies of HashDict:
def get(dict, key, default // nil) do
defmodule ExCoder do
vars = [ { "&Tab;", " " },
{ "&excl;", "!" },
{ "&quot; &QUOT;", "\"" },
{ "&num;", "#" },
{ "&dollar;", "$" },
{ "&percnt;", "%" },
{ "&amp; &AMP;", "&" },
{ "&apos;", "'" },
{ "&lpar;", "(" },
@josevalim
josevalim / def.exs
Last active December 20, 2015 08:19 — forked from avdi/def.exs
def next_state do
(board, x, y) ->
cell = cell_at(board, x, y)
live_count = live_neighbors(board, x, y)
next_state(cell, live_count)
(_, x, y) when (x < 0 or y < 0) ->
"."
end
def next_state do
def zip(a, b) do
list = to_list(a)
throw do
{ zipped, rest } = Reducers.reduce(b, { [], list }, fn
entry, { acc, [h|t] } -> { [{entry, h}|acc], t }
entry, { acc, [] } -> throw { :enum_zip, acc }
end)
:lists.foldl(fn(x, acc) ->
Expected:
[
[{"a","b"},{"c","d"}],
[{"a1","b1"},{"c1","d1"}],
[{"a2","b2"},{"c2","d2"}]
]
Actual:
@josevalim
josevalim / elixir.rb
Created March 3, 2012 20:25 — forked from huffman/elixir.rb
Elixir Homebrew recipe
# Install this recipe with:
# brew install https://raw.github.com/gist/1968046/0302279edc972e9d147110bd69284d0e2becda41/elixir.rb
require 'formula'
class ErlangInstalled < Requirement
def message; <<-EOS.undent
Erlang is required to install.
You can install this with: