Skip to content

Instantly share code, notes, and snippets.

View systra's full-sized avatar

Andrzej Trawiński systra

  • jTendo
  • Warsaw, Poland
View GitHub Profile
@systra
systra / measure_processes.erl
Created December 10, 2016 21:41
Measure erlang processes spawn time
-module(measure_processes).
-export([limit/1]).
limit(N) ->
Limit = erlang:system_info(process_limit),
io:format("Limit allowed processes:~p~n", [Limit]),
statistics(runtime),
statistics(wall_clock),
L = for(1, N, fun() -> spawn(fun() -> wait() end) end),
{_, Time1} = statistics(runtime),
@systra
systra / imei.erl
Last active August 29, 2015 14:19
The calculation of the checksum digit of the IMEI number according to Luhn formula.
-module(imei).
-export([crc/1]).
crc(IMEI) when is_list(IMEI), length(IMEI) =:= 14 ->
calc(IMEI, 0).
calc([], Acc) ->
(10 - (Acc rem 10)) rem 10;
calc(L = [X|Rest], Acc) when length(L) rem 2 =:= 0 ->
find_free_port() ->
{ok, X} = gen_tcp:listen(0, [{active, false}]),
{ok, P} = inet:port(X),
gen_tcp:close(X),
{ok, P}
end.
@systra
systra / gist:0a39c709fc506bcaec1e
Created March 23, 2015 11:09
Reversing binary
reverse_bin(Bin) ->
S = size(Bin)*8,
<<X:S/integer-little>> = Bin,
<<X:S/integer-big>>.
@systra
systra / gist:56efef27ef3c579353f0
Created February 18, 2015 09:42
erl_call example
EI_TRACELEVEL=6 /opt/erlang/17.4/lib/erl_interface-3.7.20/bin/erl_call -v -d -n [email protected] -c cookie -a 'erlang length [[a,b,c]]'
erl_call: node = [email protected]
Cookie = cookie
flags = verbosep debugp
module: name = , size = 0
apply = erlang length [[a,b,c]]
ei_xconnect: Wed Feb 18 10:42:38 2015: -> CONNECT attempt to connect to node
ei_epmd_r4_port: Wed Feb 18 10:42:38 2015: -> PORT2_REQ alive=node ip=127.0.0.1
ei_epmd_r4_port: Wed Feb 18 10:42:38 2015: <- PORT2_RESP result=0 (ok)
ei_epmd_r4_port: Wed Feb 18 10:42:38 2015: port=62153 ntype=77 proto=0 dist-high=5 dist-low=5
@systra
systra / ttb_test
Created February 5, 2015 10:07
Test Erlang tracing
Spec = dbg:fun2ms(fun(_) -> message(caller()),return_trace() end).
AllModulesPattern = [{{M, '_', '_'},Spec}
|| {M, _} <- code:all_loaded()].
ttb:start_trace([node()],AllModulesPattern,
{all, [all]},
{handler, ttb:get_et_handler()}).
ttb:stop(format).
@systra
systra / udp_test.erl
Created January 2, 2015 10:43
Shared UDP socket gen_server
-module(udp_test).
-behaviour(gen_server).
-define(SERVER, ?MODULE).
-define(PORT, 9876).
-define(TIMEOUT, 10).
%% ------------------------------------------------------------------
%% API Function Exports
%% ------------------------------------------------------------------
@systra
systra / gist:c4d7aad06da310a39cd4
Last active August 29, 2015 14:07
freeswitch compilation errors - solutions (OS X Mavericks 10.9)
$ ./configure --enable-shared --enable-static --with-erlang --prefix=/opt/freeswitch --exec_prefix=/opt/freeswitch
...
setting PLATFORM_CORE_LDFLAGS to "--framework CoreFoundation"
setting PLATFORM_CORE_LIBS to "-ldl"
checking for inflateReset in -lz... no
configure: error: no usable zlib; please install zlib devel package or equivalent
FIX:
@systra
systra / gist:ee8b65a91cf51693ffad
Created June 24, 2014 06:34
beam permissions
sudo setcap cap_net_bind_service+ep ./erts-5.9.2/bin/beam
sudo setcap cap_net_bind_service+ep ./erts-5.9.2/bin/beam.smp
@systra
systra / gist:a8b954732f6c80edfd8f
Created June 18, 2014 14:25
record to proplist
R = #record{}.
lists:zip(record_info(fields, record), tl(tuple_to_list(R))).