Skip to content

Instantly share code, notes, and snippets.

View bench.exs
n = 1_000_000
bmap = FooBench.start(FooMap, n)
btup = FooBench.start(FooTuple, n){
"" => fn -> FooBench.readall(bmap) end,
"" => fn -> FooBench.readall(btup) end
}, memory_time: 5){
View my_cache.ex
defmodule MyCache do
@behaviour :gen_statem
@table :my_cache
@expire_after :timer.seconds(45)
@vacuum_idle_timeout :timer.minutes(5)
@vacuum_dead_timeout :timer.seconds(60)
# Public API functions

Build or install nghttp2 (optionally with support for the --interval DURATION flag).


brew install nghttp2


View lamport_clock.ex
defmodule :lamport_clock do
@moduledoc ~S"""
# Example
iex> lc0 =
%:lamport_clock{value: 1}
iex> # Node: A
iex> lc1a = :lamport_clock.increment(lc0)
%:lamport_clock{value: 2}
View quickbench.erl
%% -*- mode: erlang; tab-width: 4; indent-tabs-mode: 1; st-rulers: [70] -*-
%% vim: ts=4 sw=4 ft=erlang noet
%% API
%% Records
potatosalad /
Last active Aug 25, 2018
Possible race condition in Concuerror with ETS

Concuerror (version 0.20.0+build.2149.refc040b0d):

./concuerror --pa "$(exenv prefix)/lib/elixir/ebin" -m registry_example -t test --treat_as_normal=killed --treat_as_normal=shutdown --show_races=true

Example failure:

* Stop testing on first error. (Check '-h keep_going').
potatosalad /
Last active Aug 25, 2018
Possible race condition in ETS

The registry_example.ex test spawns two child processes who both attempt to register themselves against a unique Registry.

Only one should succeed. However, there seem to be cases when :ets.insert_new/2 returns true for two independent processes.

Example reproduction of the bug:

# This is on Erlang/OTP 21.0 and Elixir 1.7.2
# However, I was able to confirm the same behavior on master for both.
elixirc registry_example.ex
View erlang_logger.ex
defmodule ErlangLogger do
@moduledoc """
Designed to mirror [`kernel/include/logger.hrl`](
*WARNING:* Currently blows up if `__CALLER__` does not have a valid `mfa`
defmacro log_emergency(a) do
do_log(:emergency, [a], __CALLER__)
View example_encryptor.ex
defmodule ExampleEncryptor do
def encrypt(plain_text, password) do
salt = :crypto.strong_rand_bytes(32)
iterations = 4096
kek = derive_key_encryption_key(password, salt, iterations, 32, :sha512)
kiv = :crypto.strong_rand_bytes(12)
cek = :crypto.strong_rand_bytes(32)
civ = :crypto.strong_rand_bytes(12)
{cek_cipher_text, cek_cipher_tag} = :crypto.block_encrypt(:aes_gcm, kek, kiv, {<<>>, cek})

The following module can be placed in the root level of elixir-lang/elixir and executed using the following:

bin/elixirc keyword_delete_bench.ex && erl -noshell -pa . -pa lib/elixir/ebin -s 'keyword_delete_bench'

Example (minimized output):

## count=100000, size=10
You can’t perform that action at this time.