Skip to content

Instantly share code, notes, and snippets.

Andrew Bennett potatosalad

Block or report user

Report or block potatosalad

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Cargo.toml
[package]
name = "nth-prime"
version = "0.1.0"
edition = "2018"
[dependencies]
futures-preview = "0.3.0-alpha.16"
View bench.exs
n = 1_000_000
bmap = FooBench.start(FooMap, n)
btup = FooBench.start(FooTuple, n)
Benchee.run(%{
"bmap.read" => fn -> FooBench.readall(bmap) end,
"btup.read" => fn -> FooBench.readall(btup) end
}, memory_time: 5)
Benchee.run(%{
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
View README.md

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

Either:

brew install nghttp2

Or:

View lamport_clock.ex
defmodule :lamport_clock do
@moduledoc ~S"""
# Example
iex> lc0 = :lamport_clock.new()
%: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
-module(quickbench).
%% API
-export([bench/2]).
-export([bench/3]).
-export([compare/3]).
%% Records
@potatosalad
potatosalad / README.md
Last active Aug 25, 2018
Possible race condition in Concuerror with ETS
View README.md

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 --graph=registry_example.dot

Example failure:

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

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`](https://github.com/erlang/otp/blob/da166b76de977171243dd2ea7f86b98f451fabc5/lib/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__)
end
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})
You can’t perform that action at this time.