Skip to content
Henry m edited this page Oct 4, 2023 · 5 revisions

Getting started with Elixir

Introduction

Purpose

References

Vocabulary

Overview

Installation

Installing Elixir from OS repo

  1. sudo apt install elixir

Installing ASDF

This tool Allows you to keep up to date with tools like Elixir and to swap between versions

  • Getting started with ASDF

  • sudo apt install curl git dirmngr gpg gawk automake autoconf gcc libssl-dev libncurses5-dev libwxgtk3.0-gtk3-dev

    • This includes the packages for compiling erlang.
  • wx-config --version

  • git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.8.1

  • vi ~/.bashrc

    • . $HOME/.asdf/asdf.sh
    • . $HOME/.asdf/completions/asdf.bash
  • bash

  • asdf --version

    • v0.8.1-a1ef92a
  • asdf plugin-add erlang https://github.com/asdf-vm/asdf-erlang.git

  • asdf plugin-add elixir https://github.com/asdf-vm/asdf-elixir.git

Installing Elixir and erlang using ASDF

  • Erlang: 24.0.2

  • Elixir: 1.12

  • asdf update

  • asdf plugin-update --all

  • asdf list-all erlang

  • asdf list-all elixir

  • asdf install erlang 24.0.2

    • This takes about 6min
  • asdf global erlang 24.0.2

  • erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' -noshell

  • asdf install elixir 1.12.0-otp-24

  • asdf global elixir 1.12.0-otp-24

  • elixir -v

    • Make sure that the erlang and elixir fits together
      • Erlang/OTP 24 [erts-12.0.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
      • Elixir 1.12.0 (compiled with Erlang/OTP 24)

First project

  1. mix new sip_server --sup
  2. cd sip_server
  3. mix deps

Syntax

data storage

Array

[] - array

  • add element to the end: [1,2,3] ++ [4]
  • add element to at the beginning: [0 | 1,2,3]
  • cut first element [ head | rest ]
  • length: Kernel.length(array)

String

Modules

WebSocket Server

WebSocket Client

Messaging

Message operations

Show all messages in inbox

messages = :erlang.process_info(self(), :messages)
IO.inspect(messages, label: "messages")

Rabbit messaging

Tools

crash dump invesigation

See:

  1. cd TO_CRASH_DUMP_DIR
  2. iex
  3. :crashdump_viewer.start

Debugging

Debugging messaging

show all messages in the inbox

messages = :erlang.process_info(self(), :messages)
IO.inspect(messages, label: "messages")

RegEx

Regex groups

  • [] - matches a single character with the bracket

    • work as an 'or'
    • e.g. 'gr[ae]y' will match
      • 'gray' and 'grey'
  • [^] - will negate what is in the brackets

  • () - matches whole pattern or multiple patters if separated with '|' And captures it

    • captures text that can be referenced by $n, where n is the capture group
    • e.g. 'gr(a|e)y'
    • can be used to match whole strings within the parentheses.
    • you can embed capture groups in capture groups. ((\d+) \w)
  • Matching a range of characters using square brackets [] defines a character class. You can also specify a range of characters like a-z, as long as the start and end represent a contiguous range of code points

Quantifiers

  • '+' - One or more.
  • '*' - zero or more.
  • '?' - none or one. (0 or 1 time)
  • {n,m} - between n and m times.
    • {1,5} - between 1 and 5, both included.
    • {2,} - at least two times, but no upper limit.
    • {8} - exactly 8 times.

Anchors

  • '^' - pattern appears at the beginning of the string
  • '$' - pattern appears at the ed of the string

Generate call graphs

See: mix xref

  • mix xref callers MyMod
  • mix xref graph --label runtime --only-direct

Troubleshooting

Troubleshooting telemetry

Metric type summary is unsupported. Dropping measure

16:32:29.343 [warn]  Metric type summary is unsupported. Dropping measure. metric_name:=[:handling, :time]

16:32:29.343 [warn]  Metric type summary is unsupported. Dropping measure. metric_name:=[:event, :reception, :deltatime]

Troubleshooting compilation errors

The function call will not succeed

See:

The function call will not succeed
...
breaks the contract
Clone this wiki locally