Skip to content

Instantly share code, notes, and snippets.

View seriyps's full-sized avatar

Sergey Prokhorov seriyps

View GitHub Profile
@seriyps
seriyps / log_format.erl
Last active March 2, 2021 18:44
Small helpers to format common erlang structures (records and stacktraces)
%% @doc Hepers to format common erlang constructs (records, stacktraces) in a more human-readable way
%% Inspired heavily by https://github.com/erlang-lager/lager
-module(log_format).
-export([record/2, f_record/2]).
-export([records/2, f_records/2]).
-export([stack/1, f_stack/1]).
%% @doc Converts record to a string using `#record{}', not `{tuple}' syntax
%%
%% `record(#my_record{a = 1, b = qwerty}, record_info(fields, my_record))'
@seriyps
seriyps / epgsql_cmd_prepared_query_oom_protection.erl
Created April 18, 2023 09:04
`epgsql` command with OOM protection. It discards the incoming results if the number of bytes received exceeds the threshold
-module(epgsql_cmd_prepared_query_oom_protection).
-behaviour(epgsql_command).
-export([init/1, execute/2, handle_message/4]).
-export_type([response/0]).
-type response() :: {ok, Count :: non_neg_integer(), Cols :: [epgsql:column()], Rows :: [tuple()]}
| {ok, Count :: non_neg_integer()}
| {ok, Cols :: [epgsql:column()], Rows :: [tuple()]}