Skip to content

Instantly share code, notes, and snippets.

@teamon
teamon / exometer-elixir-alpine.md
Last active February 25, 2017 12:05
Installing elixometer and exometer on alpine inside docker with elixir 1.3.4 and erlang r18

versions

Alpine: 3.4 Elixir: 1.3.4 Erlang: R18

packages

linux-headers erlang-snmp
@teamon
teamon / avatar.ex
Created September 9, 2016 21:30
Quickly create avatar image from user name (initials)
# Much simplified version based on https://github.com/zhangsoledad/alchemic_avatar
# Avatar.generate/2 returns a Plug.Upload that can be passed directly
# into Ecto.Changeset (as for example fallback image)
defmodule Avatar do
@defaults [
size: 300,
font_path: Application.app_dir(:my_app, "priv/fonts/Roboto.ttf"),
font_size: 40,
font_weight: 500,
@doc """
Asserts based on pattern matching.
Example: check if collection contains element that matches the pattern
assert_match %{body: "lorem"} in messages
assert_match %{id: ^id} in response["users"]
"""
defmacro assert_match({:in, _, [left, right]} = assertion) do
code = Macro.escape(assertion)
@doc """
Validate each array element with validator
Examples
iex> changeset
...> |> validate_each(:emails, &validate_email)
...> |> validate_each(:phones, &validate_format(&1, &2, ~r/\d+/))
...> |> validate_each(:phones, &validate_length/3, is: 4)
"""
def validate_each(changeset, field, validator, opts) do
(0 to Int.MaxValue) == Range() // empty!
class X extends Actor {
def act {
val a = actor {
loop {
receive { // FAIL, must use 'self.receive'
case ...
}
}