What is the benefit of Keyword Lists?

Keyword List Map/Struct HashDict (deprecated) Duplicate keys yes no no Ordered yes no no Pattern matching yes  yes no Performance¹ (Insert) very fast² fast³ fast⁴ Performance¹ (Access) slow⁵ fast³ fast⁴ Keyword lists are lightweight and have a simple structure underneath them, which makes them very flexible. You can think of them as syntax sugar on … Read more

Where does Elixir/erlang fit into the microservices approach? [closed]

This is a very open question but I will try to illustrate why Elixir/Erlang may be the best platform out there for developing distributed systems (regardless if you are working with microservices). First, let’s start with some background. The Erlang VM and its standard library were designed upfront for building distributed systems and this really … Read more

Elixir: use vs import

import Module brings all the Functions and Macros of Module un-namespaced into your module. require Module allows you to use macros of Module but does not import them. (Functions of Module are always available namespaced.) use Module first requires module and then calls the __using__ macro on Module. Consider the following: defmodule ModA do defmacro … Read more

How to join strings in Elixir?

If you just want to join some arbitrary list: “StringA” <> ” ” <> “StringB” or just use string interpolation: “#{a} #{b}” If your list size is arbitrary: Enum.join([“StringA”, “StringB”], ” “) … all of the solutions above will return “StringA StringB”

How can I schedule code to run every few hours in Elixir or Phoenix framework?

There is a simple alternative that does not require any external dependencies: defmodule MyApp.Periodically do use GenServer def start_link(_opts) do GenServer.start_link(__MODULE__, %{}) end def init(state) do schedule_work() # Schedule work to be performed at some point {:ok, state} end def handle_info(:work, state) do # Do the work you desire here schedule_work() # Reschedule once more … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)