Posts tagged ‘erlang’

107 posts; newest first

Helpers for fold accumulators

erlang

On whether “fold accumulator helpers” are a good idea.

I’m currently writing some code that recursively folds over a multi-level data structure, and I found myself wondering whether introducing helper functions specifically to abstract over the accumulator are a good idea.

» read more

gen_server debug options

erlang

Erlang’s gen_server (and gen_statem, etc.) allow for you to pass {debug, DebugOptions} in gen_server:start_link/4 (et al.). The documentation for it is spread over several pages, making it hard to understand at first. How should we use it?

» read more

Erlang: via

erlang

Here’s how you can use via in a name specification when starting a gen_server (or gen_statem, etc.) to register your process with a process registry.

» read more

Simple log colouring in Erlang

erlang

By default, the improved logger originally introduced in Erlang/OTP-21 doesn’t support per-level colours. This is something that I miss from lager and from Elixir’s Logger. Here’s a simple way to implement something like lager.

» read more

Building Erlang/OTP

erlang

There’s more comprehensive information in various files in the HOWTO directory, but ain’t nobody got time for that. This works for me.

» read more

Forking Erlang/OTP

erlang

Some notes about hacking on and contributing to Erlang, because I don’t do it frequently enough to have all of this in muscle memory.

» read more

Erlang application versioning

erlang rebar3

When you’re investigating a problem with a deployed application, it’s useful to know precisely which version you’re looking at. Here’s how to automatically set the version number in an Erlang project.

» read more

Rebar3 Umbrella Projects

erlang rebar3

Some notes about using rebar3 with an umbrella project.

rebar3 new umbrella name=foo      # umbrella and release are aliases
cd umbrella/
cd apps/
rebar3 new app name=bar
rebar3 new lib name=baz

It doesn’t set up the application dependencies (because it can’t know what you mean to do), so you’ll need to do that yourself. Edit apps/foo/src/foo.app.src:

» read more

Erlang clustering recap

erlang

I want to write a post about using mutual TLS to secure Erlang distribution (clustering), with auto-provisioning of certificates when running in Kubernetes. This is not that post. This is a recap of basic Erlang clustering, to refresh my memory and lay some groundwork.

» read more

ALPN in Erlang

erlang

Per Wikipedia:

Application-Layer Protocol Negotiation (ALPN) is a Transport Layer Security (TLS) extension that allows the application layer to negotiate which protocol should be performed over a secure connection in a manner that avoids additional round trips and which is independent of the application-layer protocols.

» read more

Getting Erlang version

Use this helper function:

erlang_version() {
    erl -eval '
        {ok, Version} = file:read_file(
                            filename:join(
                                [code:root_dir(),
                                 "releases",
                                 erlang:system_info(otp_release),
                                 "OTP_VERSION"])),
        io:format("Erlang/OTP ~s", [Version]),
        halt().' -noshell
}
Note that this only works when you run erl; it doesn’t work in a released application.
» read more

Rebuilding kerl Installations

kerl erlang

If kerl list installations is displaying Erlang installations that you deleted ages ago, and you’ve got all of your installations in ~/.kerl/erlangs/, you can rebuild the list by running the following command:

» read more

Using kerl with direnv

kerl direnv erlang

kerl allows you to easily build and install multiple Erlang/OTP releases. It’s kinda like nvm or rvm, but for Erlang. It doesn’t do everything, and that’s what direnv is for. direnv allows you to run commands upon entering or leaving a particular directory.

» read more

gen_fsm learnings, part 3

erlang gen_fsm

Some odds and ends.

handle_info information

The last of the “I don’t know what this is for” functions is handle_info. This is documented as being called for messages that aren’t events or system messages.

» read more