Elixir Blog Posts

https://medium.com/@blackode/elixir-1-6-3-supports-comments-in-the-middle-of-pipelines-when-and-expressions-b7ccace2176a

Code.Formatter

artilce Image

5 Likes

https://medium.com/@jackmarchant/composing-elixir-plugs-in-a-phoenix-application-a199d4c771cf

5 Likes

I wrote another blog post: CSRF Protection in Plug and Phoenix!

5 Likes

Have you ever needed to search through HTML nodes text but didn’t know how?

Here is my tip on how to find HTML nodes by text using Floki and a regex

2 Likes

There’s also Meeseeks, it has a large variety of searching options.

And yes I know that this is not strictly related, but anytime I see the words ‘HTML’ and ‘Regex’ in the same paragraph I immediately think of:

^.^

2 Likes

@OvermindDL1 yeah I posted the same SO link on reddit few minutes ago :smiley:

I know Meeseekes and it’s my HTML parser of choice right now mainly for the XPath support

I was working on a project that used Floki heavily and this was just a quick trick to make it work without rewriting a lot of code.

Lucky me the author of the fl-contains pseudo class used =~ and not String.contains?

1 Like

Enable tracing using the debug option.

This explains how to debug the messages and log to the console with a simple option.

2 Likes

Running distributed Erlang & Elixir applications on Docker

3 Likes

The practical guide on how to get back the GenServer previous state.
https://medium.com/blackode/how-to-retrieve-genserver-state-after-termination-the-practical-guide-1bafcff780bb

Article Image

Deep understanding of the usage of Supervisors and GenServer together to achieve the fault tolerance.

2 Likes

Careful with that though, the terminate/2 callback is not always called…

4 Likes

I save to stash on each call instead of terminate.

  def handle_call(..., state) do
    ...
    reply_success(state, :ok)
  end

  defp reply_success(state, reply) do
    name = state.uuid
    persist_state(name, state)
    {:reply, reply, state, @timeout}
  end

As mentionned, terminate is not always executed. It allows me to configure call replies on one spot.

4 Likes

Well, Thanks for the information. :bouquet:

1 Like

That is a great approach :clap: .

I appreciate that. However, I have a doubt on this. Will that be a duplication of state? As we are saving state for every request? What makes difference with GenServer state ?

Thank you.

1 Like

The stash used is a public ets table… There is one state in the server, and one copy in an ets table, under a given key (Here I use the worker uuid). The solution does not survive a reboot, but the read/write are fast enough.

I start worker from a master GenServer, linked to each worker and trapping exit.

So when a worker dies with :normal reason, I delete stash entry from the exit call_back of the master GenServer. This is how I clean up old state…

2 Likes

11 posts were split to a new topic: Opinionated vs modular web frameworks

Be careful with saving the entire state to a stash: the point of restarting the process, rather than just doing a try/catch, is to start from a clean slate so the system can recover from a bad state. When possible it’s better to recompute things or refetch them from database during the process startup.

See for instance The Onion Layer Theory and On Erlang, State and Crashes.

6 Likes

The workers I have in this example are db-less… they hold dynamic state for a game of go.

For something related to retrieve state from db, there is this excellent talk.

2 Likes

Gotcha… :smile:

1 Like

Hi there, I am new to Elixir and like to share a post about my first impressions of getting started and a basic example application that might be interesting for others just starting with Elixir. All feedback is welcome!

Cheers
Jorin

4 Likes

A post was split to a new topic: Choosing Elixir’s Phoenix to power a real-time Web UI