Elixir Blog Posts

blog-posts
wiki
stickies

#304

Brahaha, that’s awesome! ^.^


#305

Code.Formatter

artilce Image


#306

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


#307

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


#308

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


#309

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:

^.^


#310

@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?


#311

Enable tracing using the debug option.

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


#312

Running distributed Erlang & Elixir applications on Docker


#314

The practical guide on how to get back the GenServer previous state.

Article Image

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


#315

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


#316

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.


#317

Well, Thanks for the information. :bouquet:


#318

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.


#319

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…


#320

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


#321

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.


#322

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.


#323

Gotcha… :smile:


#324

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