New post on Curiosum blog - Introduction to Elixir Genservers
I wrote a post about how to run Go code from Elixir via WebAssembly.
Hi everyone. Iâve tried once more to create a nice development setup using docker, or by now rather podman, on my local Mac. The goal was to be able to mount the sources of my projects using a shared folder, so that I can edit them using the tools installed on my Mac, but still use containers for managing Elixir versions and being a bit closer to the production environment.
Since setting this up was a bit more complicated then expected (see also this Thread on this forum), Iâve decided to write a blog post about it as documentation for myself and anyone who might be interested:
https://nobilisdata.com/blog/podman_using_parallels_and_shared_folders_for_elixir_development/
In the second post in my series on Elixir macros, I introduce the concept of a âquoted expressionâ, and show how to create them using quote
and unquote
.
I wrote up an experiment I did using metaprogramming to add guard clauses to the match operator.
Match Operator Guards
New post on the Dashbit blog:
Req API Client Testing â A guide through different testing approaches with Req-based API clients.
Hi,
I bumped on this article LiveView is best with Svelte
It has an interesting story on problems with Live View, and what they came up with: They use Svelte components to wrap live view hook objects for easier JS interop.
I thought maybe youâll find it interesting.
In the article they mention a specific scenario and admit that theyâre unsure if they just donât have the mental model right to solve it the âLiveViewâ way and thatâs why it was felt difficult to do. It involved the consecutive selects. Does anyone have thoughts on what the LiveView way would look like?
on the linked HN, from the creator of LiveSvelte:
"Thatâs true. And another downside is that once youâre in the Svelte environment you canât use your Phoenix components inside those Svelte components.
Iâve thought about adding a library of default Svelte components which mirror the core components you get from Phoenix out of the box. But then again you lose forms and changesets etc, itâs just annoying.
Where I see LiveSvelte fit is where you really need a lot of complex client side state. Sprinkle it in, but keep using phoenix components as your default, even with hooks."
I would try rendering all the second selects individually and controlling the visibility of them with the first, or setting the options of the second with a hook, using "phx-update=ignore"
. Havenât tried it though.
I thought their point that rewriting liveviews as live components is a lot of work was a bit odd. How often is one doing that that itâs an issue?
Elixir + Phoenix: How to Raise Custom HTTP Error Responses in Your REST API
This blog post shows how, by adding a few lines of code, you can return a custom HTTP error response (with status code and custom message/payload) in your Elixir + Phoenix REST API, at any time in the request-response lifecycle.
Explore how Elixirâs Commanded library revolutionizes application development through CQRS and Event Sourcing
My favorite GenServer pattern
What if another client calls before the previous data is returned? You donât want to clobber the from
field blindly.
Good question. I have used this in two scenarios. The first is a gen_server (B) that backed a port which a single process (A) pulled data from. A would call B which would then buffer an unknown amount of data from the port then rely back to A. So only one process knew that process B existed.
The second was a single process that would pull data from a network source. It had a queue of gen_servers which had callâd it for data, which it would reply to once it received a full chunk of data from the network. Once a waiter was finished with processing the data it would add itsself back to the queue by issuing a call and block for a reply. In this case the waiters didnât step on each otherâs toes.
A small tip on how to silence the noisy Phoenix.NotAcceptableError and Phoenix.CSRFProtection.InvalidCSRFTokenError exceptions in your Phoenix application by implementing the Plug.Exception protocol for them.
The focus of this article is to demonstrate various ways of registering a GenServer in Elixir so that the server can be discovered and communicated with by sending messages. Elixir runs on Erlang BEAM virtual machine and BEAM nodes can run on a single machine as well as in distributed mode as a cluster. In this article, we will explore various ways to register a GenServer both locally and globally using working code examples.
Iâm announcing a new library, HighlanderPG. It is a sequel to the Highlander library I released 4 years ago, but improves on the original in a few ways. In short, HighlanderPG is based on Postgres advisory locks and the original Highlander used :global
. HighlanderPG also introduces better supervisor semantics.
Iâm trying something new with this library. HighlanderPG is available for a yearly subscription of $100. Highlander is open source and will stay that way.
Read more about it here:
How can you generate PDFs of pages that are behind auth?
This little guide should get you going - and itâs only ~10 lines of code! Examples included for ChromicPDF and WeasyPrint and the strategy can be applied to any HTML â PDF renderer
Learn how to create URLs that users can change without breaking previous links: