Skip to content

Instantly share code, notes, and snippets.

@eiri
eiri / README.md
Created March 16, 2016 13:42
Does erlang's timers survive a death of their hatcher process?
Erlang/OTP 17 [erts-6.4.1.2] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V6.4.1.2  (abort with ^G)
1> c(zombie_timer).
{ok,zombie_timer}
2> zombie_timer:main().
-. start timer {1458135323982793,#Ref<0.0.0.79>} from <0.40.0>
-. loop is <0.40.0>
1. &lt;0.40.0&gt;
[core]
editor = vim
pager = less
whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eolpager
[color]
status = auto
branch = auto
diff = auto
interactive = auto
pager = true
@eiri
eiri / Makefile
Created February 24, 2016 13:28
Build a tiny (~3Mb) erlang distribution for embedded
# Build and slim Erlang
# Author: Matthias Lang <[email protected]>
# Reference: http://erlang.org/pipermail/erlang-questions/2016-February/087935.html
# Change the line below if you want to use a different version of Erlang
# (Keep in mind that patches may not apply cleanly)
erlang_version=otp_src_R14B03
erlang_source_file:=$(PACKAGE_SOURCES)/$(erlang_version)/$(erlang_version).tar.gz
erlang_root=$(GTH_ERLANG_ROOT)/$(erlang_version)
@eiri
eiri / pretty_config.erl
Created February 18, 2016 21:23 — forked from lefant/pretty_config.erl
a little escript snippet to pretty print erlang config, using the erl_syntax module
#!/usr/bin/env escript
%% -*- erlang -*-
%% * slurp in terms using inlined version of kernels file:consult/1
%% * convert to abstract syntax tree
%% * annotate all tuples
%% * pretty print using a hook to prefix the annotated nodes with newline
main([]) ->
io:format("%% -*-erlang-*-~n"),
@eiri
eiri / make_random_keys.erl
Last active February 17, 2016 14:51
Generate random unique keys with erlang's reference
make_random_ref_key() ->
<<X:264/big-unsigned-integer>> = term_to_binary(make_ref()),
[Key] = io_lib:format("~66.16.0b", [X]),
{ok, Key}.
make_random_md5_key() ->
<<X:128/big-unsigned-integer>> = crypto:hash(md5, term_to_binary(make_ref())),
[Key] = io_lib:format("~32.16.0b", [X]),
{ok, Key}.
@eiri
eiri / decompiler.erl
Created February 11, 2016 16:33
Decompile .beam files
#!/usr/bin/env escript
% -*- mode: erlang -*-
main([BeamFile]) ->
{ok,{_,[{abstract_code,{_,AC}}]}} = beam_lib:chunks(BeamFile,[abstract_code]),
io:fwrite("~s~n", [erl_prettypr:format(erl_syntax:form_list(AC))]).
@eiri
eiri / README.md
Created August 27, 2015 12:35
Demonstrate Erlang's 'busy wait' effect on CPU utilization

Demonstrate Erlang's 'busy wait' effect on CPU utilization

How?

Just make Erlang to do some light-load task in a bunch of relatively short leaving processes. Calculating PI to 80th digit in batches per 10 procs with short, 8 ms, sleep in-between, to give schedulers a breath space, will do.

Running

Run erl with 8 schedulers and no busy waiting on schedulers at all.

@eiri
eiri / README.md
Last active November 25, 2019 12:55
Quick demo of usage the linked documents in CouchDB (https://wiki.apache.org/couchdb/Introduction_to_CouchDB_views#Linked_documents)

Test CouchDB docs 'links'

Pre-req

Python with virtualenv, curl and jq in $PATH, running CouchDB available on http://localhost:5984

Prepare

git clone https://gist.github.com/f05328e7e24a1064c3ce.git test-linked
@eiri
eiri / gist.erl
Last active August 29, 2015 14:27
Extract rebared escript into zip file
{ok, F} = escript:extract("cfcheck", []).
file:write_file("c.zip", proplists:get_value(archive, F)).
@eiri
eiri / lists.js
Created August 19, 2015 02:09
Cycle a list, emit two elements per one item.
var items = _.chain(this.state.docs)
.slice(0, 10)
.map(function(doc, idx) {
return [
React.createElement(ListDivider, {
key: 'div' + idx,
inset: false
}),
React.createElement(ListItem, {
key: 'item' + idx,