Skip to content

Instantly share code, notes, and snippets.

View elbrujohalcon's full-sized avatar
🇪🇸
Working from Catalunya

Brujo Benavides elbrujohalcon

🇪🇸
Working from Catalunya
View GitHub Profile
@elbrujohalcon
elbrujohalcon / el.erl
Created October 26, 2021 17:10
Shadowing clauses detection
-module(el).
-export([warn/2, warn_case/1]).
-export([clean/2, clean_case/1]).
warn(X, Y) ->
{just, X and Y};
warn(6, 6) ->
{six, 6}.
@elbrujohalcon
elbrujohalcon / pi.erl
Created June 22, 2021 08:57
Process Info Checker - v3
-module(pi).
-format #{paper => 80}.
-export([check/0]).
check() ->
Pid = spawn(fun wait/0),
erlang:yield(),
@elbrujohalcon
elbrujohalcon / pi.erl
Created June 22, 2021 08:31
Process Info Checker - v1
-module(pi).
-export([check/0]).
check() ->
Pid = spawn(fun wait/0),
erlang:yield(),
PI1 = erlang:process_info(Pid),
PI2 = erlang:process_info(Pid),
Pid ! stop,
@elbrujohalcon
elbrujohalcon / list_exceptions.md
Last active June 6, 2021 09:58
Exceptions from the lists module
Function No Fun Bad Fun
all/2 badfun badarity
any/2 badfun badarity
dropwhile/2 badfun badarity
filter/2 function_clause function_clause
filtermap/2 badfun badarity
flatmap/2 badfun badarity
foreach/2 badfun badarity
map/2 badfun badarity
@elbrujohalcon
elbrujohalcon / frequency.erl
Created July 7, 2020 14:58
Frequency with Errors
%% @doc Frequency server that "transmits" errors from server to client
-module frequency.
-export [test/0].
-export [start/0, allocate/0, deallocate/1].
-export [init/0].
test() ->
%% Ensure the server is killed... This is ugly
catch exit(whereis(frequency), kill),
@elbrujohalcon
elbrujohalcon / busy.erl
Created July 7, 2020 09:22
A very busy server that blocks its clients
-module busy.
-export [loop/0].
-export [test/0].
test() ->
start_server(),
{error, server_down} = call(server, die), % Your code will catch this
start_server(),
pong = call(server, ping_and_sleep),
@elbrujohalcon
elbrujohalcon / test.erl
Created July 1, 2020 10:19
OTP22 vs OTP21 Benchmarking
%% @doc Benchmark functions over lists.
%% Use it like: c(test), test:bench({test, rec}, 250, 5000, 2000).
-module test.
-export [
bench/4,
bench_tc/2,
rec/1,
lrec/1
].
-module(palin).
-export([test/0]).
-export([server/0]).
-export([start/0, check/2, stop/1]).
test() ->
Checks = [{"Abba", true},
{"baba", false},
{"Yo hago yoga hoy", true},
get_status_map(StormidMap) ->
get_status_map(?SEVERITY, StormidMap, #{}).
get_status_map([], _, Acc) -> Acc;
get_status_map([Status|Statuses], StormidMap, Acc) ->
NewAcc = Acc#{Status => get_storms(Status, maps:values(StormidMap))},
get_status_map(Statuses, StormidMap, NewAcc).
get_storms(Status, Storms) ->
-module joe.
-export [test/0, perms/1].
test() ->
[[]] = joe:perms(""),
["a"] = joe:perms("a"),
["ab", "ba"] = joe:perms("ab"),
["ba", "ab"] = joe:perms("ba"),
["123","132","213","231","312","321"] = joe:perms("123"),