Skip to content

Instantly share code, notes, and snippets.


Danil Zagoskin stolen

  • Erlyvideo
  • Moscow, Russia
View GitHub Profile
stolen / sendsock.escript
Last active Sep 25, 2019
demo: sending open TCP socket to another BEAM over UNIX socket
View sendsock.escript
#!/usr/bin/env escript
%%% You need an OTP with fixes for sendmsg types
%%% see
stolen / otp_compat_transform.erl
Created Jun 5, 2018
build code both in OTP20 and OTP21 without deprecation warnings
View otp_compat_transform.erl
-export([add_otp21_nowarn/1]). % Export to avoid unused function warning on OTP20
%% OTP_RELEASE is defined in OTP21, not before
parse_transform(AST, _) ->
parse_transform(AST, _) ->
View udptest.erl
-export([start_sender/2, start_reader/2]).
start_sender(Addr, Port) ->
Options0 = [{broadcast, true}, {reuseaddr, true}, {active, once}, {multicast_loop, true},
{multicast_ttl, 4}, {high_msgq_watermark, 262144}, {low_msgq_watermark, 65536}, {sndbuf, 262144}],
% {multicast_if, {127,0,0,1}}],
Options = Options0,
stolen / timetop.erl
Created Jan 18, 2018
top processes by scheduled time
View timetop.erl
top(Duration, Count) ->
OldPrio = erlang:process_flag(priority, high),
Result = scheduled_time_top(Duration),
erlang:process_flag(priority, OldPrio),
lists:sublist(Result, Count).
stolen / deser_gs.erl
Created Jul 5, 2016
Deserialized gen_server pattern
View deser_gs.erl
-export([init/1, handle_call/3, terminate/2]).
-export([hello/2, handle_hello/3]).
-export([world/1, handle_world/3]).
View ranch_race.escript
#!/usr/bin/env escript
%% -*- mode: erlang -*-
%%! -pa ranch/ebin -sname ranch_race +P 1000000 +A 200 +K true -env ERL_MAX_PORTS 1000000
%% This script is tested only in Linux environment.
%% I could not make it work with Mac OS (it limits connection rate).
%% Warning: you are likely going to hit max open files limit.
%% Before running this script you should raise max fds by executing:
%% sudo -E -- bash -c "ulimit -n 1000000; sudo -E -u $USER bash --login"
View cue_parse.erl
parse_md(<<CatNumber:128/binary, LeadInNum:64/integer, IsCD:1, 0:2071, TrackNum:8, Rest/binary>>) ->
Metadate = #{cat_number => CatNumber, lead_in => LeadInNum, is_cd => (IsCD == 1), tracks => TrackNum},
{ok, Metadate, Rest};
parse_md(<<_/binary>>) ->
{error, not_enough_data}.
View bininspector.erl
% For inspecting binary usage by all accessible ETS tables, run
% [{T, (catch ets:foldl(fun bininspector:collect/2, {0, 0}, T))} || T <- ets:all()].
collect(B, {S, R}) when is_bitstring(B) ->
{S + byte_size(B), R + binary:referenced_byte_size(B)};
collect(T, Acc) when is_tuple(T) ->
View tlsv12_no_hs.escript
#!/usr/bin/env escript
%% -*- mode: erlang -*-
%% vim: sw=2 ts=2
% This escript sends valid TLSv1.2 client_hello to specified server
% crashing the OTP 17.0 acceptor due to bad hashsign default value
% Usage example: ./tlsv12_no_hs.escript localhost 9998
View badhandshake.escript
#!/usr/bin/env escript
%% -*- mode: erlang -*-
%% vim: sw=2 ts=2
% This escript sends garbage SSLv3 record between client_hello and any other record
% to specified server causing acceptor to crash with function_clause
% Usage example: ./badhandshake.escript localhost 9998