Skip to content

Instantly share code, notes, and snippets.

% Setup
tab = ets:new(tab, [set, named_table, public]),
true = ets:insert(tab, {foo, 0}).
% Slow: O(N) operation
Key = foo,
Threshold = 100,
NewVal = 101,
MatchSpec = ets:fun2ms(fun({K, V})
when K =:= Key
rebar3 proper --module=prop_find_broken_maps --numtests 10000 --max_shrinks 250 --constraint_tries 1000 --start_size 33
===> Verifying dependencies...
make: Nothing to be done for `all'.
===> Analyzing applications...
===> Compiling erldist_filter
=ERROR REPORT==== 14-Oct-2022::14:59:33.585605 ===
Module rebar3_proper_prv must be purged before deleting
===> Testing prop_find_broken_maps:prop_find_broken_maps()
.PHONY: all clean watch
CURDIR := $(shell pwd)
BASEDIR := $(abspath $(CURDIR))
SRCDIR := $(abspath $(BASEDIR)/src/)
core_find = $(if $(wildcard $1),$(shell find $(1:%/=%) -type f -name $(subst *,\*,$2)))
SOURCE_MMD := $(sort $(foreach pat,*.mmd,$(call core_find,$(SRCDIR)/,$(pat))))
OUTPUT_MMD_SVG = $(addsuffix .svg, $(basename $(SOURCE_MMD)))

Scripts for building Erlang/OTP

I have Erlang/OTP cloned into ~/local/otp and I have my PATH setup with ~/local/otp-install/bin at the front, so I can quickly test out full installs locally.

You can change the INTERESTING_TARGETS variable to point to whatever other flavors you're interested in building.

Usage

You may need to set ERL_TOP to pwd:

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int
main(void)
{
@potatosalad
potatosalad / dsu.erl
Last active March 4, 2022 21:19
Disjoint Set Union in Python3
-module(dsu).
-export([
new/0,
find/2,
insert/2,
union/3,
groups/1
]).
-module(ed25519ph).
-export([start/0]).
-export([
prehash/1,
prehash_init/0,
prehash_update/2,
prehash_final/1,
sign/3,
@potatosalad
potatosalad / trigger-otp-24-persistent-term-bug.erl
Created March 31, 2021 18:39
trigger-otp-24-persistent-term-bug.erl
N = 8000,
Terms = [{{a, list_to_atom(integer_to_list(I))}, I} || I <- lists:seq(1, N)],
Add = fun Add([]) -> ok; Add([{K, V} | T]) -> persistent_term:put(K, V), Add(T) end,
Len = fun() -> length(persistent_term:get()) end,
Random = fun() -> PTerms = [{X, Y} || {{a, X}, Y} <- persistent_term:get()], lists:nth(rand:uniform(length(PTerms)), PTerms) end,
DelRandom = fun() -> Key = element(1, Random()), persistent_term:erase({a, Key}), Key end,
EraserFun = fun() -> Eraser = fun Eraser() -> receive _ -> Eraser() after 1 -> DelRandom(), Eraser() end end, Eraser() end,
WriterFun = fun() -> Writer = fun Writer() -> receive _ -> Writer() after 1 -> Add(Terms), Writer() end end, Writer() end,
ReportFun = fun() -> Report = fun Report() -> io:format("there are ~w persistent terms~n", [Len()]), receive _ -> Report() after 1000 -> Report() end end, Report() end,
Add(Terms),
# Max Subset Sum No Adjacent
# https://www.algoexpert.io/questions/Max%20Subset%20Sum%20No%20Adjacent
#
# Write a function that takes in an array of positive integers
# and returns the maximum sum of non-adjacent elements in the array.
#
# If a sum can't be generated, the function should return `0`.
#
# Input:
# A = [75, 105, 120, 75, 90, 135]
# 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