Skip to content

Instantly share code, notes, and snippets.

View jlouis's full-sized avatar

Jesper Louis Andersen jlouis

View GitHub Profile
-module(trecord_test).
-compile({parse_transform, trecord}).
-export([x/0]).
-record(bar,
{baz = 3, quux}
).
@jlouis
jlouis / z.erl
Created February 25, 2014 14:26
-module(z).
-export([t0/0, t1/0]).
t0() ->
A = [{"name1", 1}, {"name2", 77}, {"name3", 33}, {"name4", 234}],
t(A).
t1() ->
A = [{"name1", 1}, {"name2", 77}, {"name3", 33}, {"name4", 234}],
% uname -a
FreeBSD raspberry-pi 10.0-RELEASE FreeBSD 10.0-RELEASE #0: Sat Mar 8 00:52:09 CET 2014 root@dragon.lan:/usr/home/jlouis/P/crochet-freebsd/work/obj/arm.armv6/usr/src/sys/RPI-B arm
% erl
Erlang R16B03-1 (erts-5.10.4) [source] [async-threads:10] [kernel-poll:false]
Eshell V5.10.4 (abort with ^G)
1>
@jlouis
jlouis / ex.erl
Created May 12, 2014 23:03
Erlang processes are trivially linearizible
-module(ex).
-compile(export_all).
-include_lib("eqc/include/eqc.hrl").
-include_lib("eqc/include/eqc_statem.hrl").
%% reg_ is a register process maintaining a single register
reg_proc() ->
case whereis(reg) of
-module(agner).
-export([ec/2]).
fac(N) ->
lists:foldl(fun erlang:'*'/2, 1, lists:seq(1, N)).
ec(M, U) ->
X = math:pow(U, M) / fac(M),
Rho = U / M,
-module(integer_coding).
-compile(export_all).
-include_lib("eqc/include/eqc.hrl").
power(_N, 0) -> 1;
power(N, P) -> N * power(N, P-1).
perturb() ->
@jlouis
jlouis / test_tcp.erl
Created September 8, 2014 15:17
Improved version of test_tcp
-module(test_tcp).
-export([run_tcp/3, recv_tcp/3, send_tcp/4]).
-define(SOCKET_OPTS, [{active, false}, binary, {delay_send, true}, {packet, 4}]).
run_tcp(Port, P, N) ->
spawn_link(fun() ->
recv_tcp(Port, P, N)
end),
@jlouis
jlouis / shell
Created September 8, 2014 17:22
jlouis@eldar:~$ cabal install idris
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: idris-0.9.14.3
trying: network-2.4.1.2/installed-040...
trying: parsec-3.1.3/installed-6c6...
trying: parsers-0.12.1
rejecting: attoparsec-0.10.4.0/installed-d9f... (conflict: parsers =>
attoparsec>=0.12.1 && <0.13)
rejecting: attoparsec-0.12.1.2, 0.12.1.1, 0.12.1.0 (conflict: parsec =>
— [2014-09-22] [GH/jlouis/dht_bt] Thoughts on QuickChecking a DHT
I am currently trying to get the BitTorrent DHT, which is Kademlia based into shape. I have code for all of it, but it is tied
deeply into the way we did stuff in BitTorrent and I want a way to do this outside of eTorrent, because a world-global DHT
for Erlang nodes are generally applicable and useful. So this is where we stand. The BitTorrent DHT has two important properties
* Very high resilience against node failure
* Slow query rates
For a global DHT, these are exactly the properties you are after. We don't care that queries will take a bit of time, as long as they
@jlouis
jlouis / fail_routing_table.txt
Created September 27, 2014 17:17
Failed Routing table test
47> eqc:module({testing_time, 60}, dht_routing_table_eqc).
prop_seq: ....................................................................................................(x10)......................................................................................(x1)...Failed! After 964 tests.
[{set,{var,1},{call,dht_routing_table_eqc,ranges,[]}},
{set,{var,2},
{call,dht_routing_table_eqc,has_bucket,
[{660458869799682934959721832362753874361116000256,
660815681722859424929986403855116248145211686912}]}},
{set,{var,3},
{call,dht_routing_table_eqc,range,
[1103605397128662530547004573024933458597958554231,