Skip to content

Instantly share code, notes, and snippets.

View zhongwencool's full-sized avatar
🌊

zhongwencool zhongwencool

🌊
  • China Guǎng Zhōu
View GitHub Profile
-module(rec_test).
-compile(export_all).
-include_lib("kernel/src/inet_dns.hrl").
%% Requires R12B5 +
-include_lib("eunit/include/eunit.hrl").
%% Retrieves the value stored in the record Rec in field Field.
info(Field, Rec) ->
Fields = fields(Rec),
info(Field, Fields, tl(tuple_to_list(Rec))).
@kuenishi
kuenishi / beam.rst
Created July 26, 2012 16:22
Erlang BEAM memo

BEAM

assemble

$ erlc -S test.erl
-module(benchmark).
-author('cooldaemon@gmail.com').
-export([run/1]).
run(Count) ->
Keys = lists:seq(1, Count),
lists:foreach(
fun ({F, TargetName}) ->
{[SetRunTime, SetWallClock], [GetRunTime, GetWallClock]} = F(Keys),
@hamidreza-s
hamidreza-s / Erlang - ClearConsole.erl
Created April 12, 2014 05:25
How to clear the Erlang shell.
%% move cursor to beginning of the line
io:format("\e[H").
%% clear the console
io:format("\e[J").
%% both
io:format("\e[H\e[J").
@rubencaro
rubencaro / install_elixir.md
Last active September 30, 2023 03:58
Elixir installation guide

Elixir installation guide

Version numbers should be the ones you want. Here I do it with the last ones available at the moment of writing.

The simplest way to install elixir is using your package manager. Sadly, at the time of writing only Fedora shows the intention to keep its packages up to date. There you can simply sudo dnf install erlang elixir and you are good to go.

Anyway, if you intend to work with several versions of erlang or elixir at the same time, or you are tied to a specific version, you will need to compile it yourself. Then asdf is your best friend.

@pnc
pnc / observer.md
Last active July 6, 2024 19:06
Using Erlang observer/appmon remotely

Using OTP's observer (appmon replacement) remotely

$ ssh remote-host "epmd -names"
epmd: up and running on port 4369 with data:
name some_node at port 58769

Note the running on port for epmd itself and the port of the node you're interested in debugging. Reconnect to the remote host with these ports forwarded:

$ ssh -L 4369:localhost:4369 -L 58769:localhost:58769 remote-host
@jadeallenx
jadeallenx / discussion.md
Last active April 21, 2023 17:13
When does terminate/2 get called in a gen_server?

When does terminate/2 get called in a gen_server?

This is what the [official documentation][1] says about the terminate/2 callback for a gen_server:

This function is called by a gen_server when it is about to terminate. It should be the opposite of Module:init/1 and do any necessary cleaning up. When it returns, the gen_server terminates with Reason. The return value is ignored.

Reason is a term denoting the stop reason and State is the internal state of the gen_server.

Reason depends on why the gen_server is terminating. If it is because another callback function has returned a stop tuple {stop,..}, Reason will have the value specified in that tuple. If it is due to a failure, Reason is the error reason.