Skip to content

Instantly share code, notes, and snippets.

# Store 3 hashes:
# When `row == 0`, we do not yet know the maximum length of `col`:
# 1. H[0] = 0 or previous H[1] (hash of all values excluding the final one for the column)
# 2. H[1] = hash((H[1], value)) (hash of all values including the final one for the column)
# 3. self.end = col
# When `row > 0` and `col < self.end`:
# 1. H[1] = hash((H[1], value)) (hash of left-hand values, excluding last)
# 2. H[2] = 0 or hash((H[2], value)) (hash of right-hand values, excluding first)
# When `col == self.end`:
# - Compare H[0] with H[2], if they don't match return False
export interface CancellablePromise<T> extends Promise<T> {
cancel(reason: any): void
}
export class Cancellable {
public promise: Promise<never>
private cancelled: boolean
private reason?: any
constructor() {
[package]
name = "nth-prime"
version = "0.1.0"
edition = "2018"
[dependencies]
futures-preview = "0.3.0-alpha.16"
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(%{
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).

Either:

brew install nghttp2

Or:

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}
%% -*- 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 August 25, 2018 19:07
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 --graph=registry_example.dot

Example failure:

* Stop testing on first error. (Check '-h keep_going').
@potatosalad
potatosalad / README.md
Last active August 25, 2018 15:31
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