Skip to content

Instantly share code, notes, and snippets.

View stolen's full-sized avatar

Danil Zagoskin stolen

  • Erlyvideo
  • Moscow, Russia
View GitHub Profile
-module(cue_parse).
-export([parse_md/1]).
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}.
#!/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"
@stolen
stolen / deser_gs.erl
Created July 5, 2016 09:35
Deserialized gen_server pattern
-module(deser_gs).
-export([start_link/0]).
-export([init/1, handle_call/3, terminate/2]).
-export([hello/2, handle_hello/3]).
-export([world/1, handle_world/3]).
@stolen
stolen / timetop.erl
Created January 18, 2018 16:08
top processes by scheduled time
-module(timetop).
-export([top/2]).
top(Duration, Count) ->
OldPrio = erlang:process_flag(priority, high),
Result = scheduled_time_top(Duration),
erlang:process_flag(priority, OldPrio),
lists:sublist(Result, Count).
-module(udptest).
-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
stolen / otp_compat_transform.erl
Created June 5, 2018 11:34
build code both in OTP20 and OTP21 without deprecation warnings
-module(otp_compat_transform).
-export([parse_transform/2]).
-export([add_otp21_nowarn/1]). % Export to avoid unused function warning on OTP20
%% OTP_RELEASE is defined in OTP21, not before
-ifdef(OTP_RELEASE).
parse_transform(AST, _) ->
add_otp21_nowarn(AST).
-else.
parse_transform(AST, _) ->
@stolen
stolen / sendsock.escript
Last active September 25, 2019 09:53
demo: sending open TCP socket to another BEAM over UNIX socket
#!/usr/bin/env escript
%%% You need an OTP with fixes for sendmsg types
%%% see https://github.com/erlang/otp/pull/2400
-module(sendsock).
-mode(compile).
-export([main/1]).
@stolen
stolen / 00-hls-opus
Last active January 26, 2022 13:03
HLS with CODECS="opus"
Demo playlist + segments