Skip to content

Instantly share code, notes, and snippets.

View garazdawi's full-sized avatar

Lukas Larsson garazdawi

  • Erlang Solutions
  • Stockholm
View GitHub Profile
@garazdawi
garazdawi / bit_vector.erl
Last active June 9, 2023 17:42
A shared mutable bit-vector in Erlang
-module(bit_vector).
-export([new/1, get/2, set/2, clear/2, flip/2, print/1]).
new(Size) ->
Words = (Size + 63) div 64,
{?MODULE, Size, atomics:new(Words, [{signed, false}])}.
get({?MODULE, _Size, Aref}, Bix) ->
@garazdawi
garazdawi / gcount.erl
Created September 6, 2019 14:20
Global Counters in Erlang
-module(gcount).
-export([bench/0,bench/1]).
-export([ets_init/0,ets_new/1,ets_incr/1,ets_read/1]).
-export([cnt_init/0,cnt_new/1,cnt_incr/1,cnt_read/1]).
-export([cnt_pt_init/0,cnt_pt_new/1,cnt_pt_incr/1,cnt_pt_read/1]).
ets_init() ->
ets:new(?MODULE, [{write_concurrency,true},named_table,public]).
ets_new(Counter) ->
@garazdawi
garazdawi / rewrite-seealso.escript
Last active March 12, 2020 15:28
rewrite-seealso
#!/usr/bin/env escript
%% -*- erlang -*-
%%! +A 1 +SDio 1 +S 1 -mode minimal
%% This script can be used to convert <seealso> to <see*>
%% Invoked like this:
%% find lib/*/doc/src system/doc/*/ erts/doc/src/ '(' -name *.xml -o -name *.xmlsrc ')' -exec ./rewrite-seealso.escript {} \;
%% You need a OTP with built documentation for this to work
main([File]) ->
io:format("Parse: ~s~n",[File]),