Mocking External Dependencies in Elixir

A reader recently asked me about mocking external dependencies in Elixir. So, I wanted to discuss two popular mocking libraries and how to mock without a library (and which option I like best).

https://www.germanvelasco.com/blog/mocking-external-dependencies-in-elixir

Elixir’s best practices: Achieve secure authentication

In this article, we are going to go through the different vulnerabilities you may encounter with your authentication strategies and show you how to prevent them, and then we’ll look at how you can increase the security level in the context of Elixir applications.

https://medium.com/wttj-tech/elixirs-best-practices-achieve-secure-authentication-8961f60effc7

Devs For Ukraine: Free online remote conference featuring some notable elixir speakers (José Valim & more!)

We organized a small remote conference https://www.devsforukraine.io/ to raise funds for Ukraine. The lineup features notable elixir speakers and others. The goal is to raise money which will be distributed to several NGOs benefitting Ukraine.

Come join us!

Exploring Options for Storing Custom Data in Ecto

Ever wanted to store a blob of custom data on a database record? When the data is stored using Ecto there are several ways we can do it. This article explores two paths and discusses some of the pros and cons for each approach. It includes some extra tips like versioning the custom blob and creating a custom Ecto type for optionally storing it as binary. Which of the two choices is better? Well, it depends.

https://fly.io/phoenix-files/exploring-options-for-storing-custom-data-in-ecto/

How to paginate in Ecto.

https://cmdarek.com/pages/paginate-with-ecto.html

Finitomata :: a proper FSM library for Elixir

https://rocket-science.ru/hacking/2022/04/02/finitomata

The most important thing I wanted to automate would be the FSM pure description itself as well as OTP boilerplate. I wanted something, that is error-prone and easy to grasp.

EctoCellar v0.4.0 has been released🎉Store changes to your models, for auditing or versioning.

Store changes to your models, for auditing or versioning. Inspired by paper_trail.

Links

News

  • The number of stars has exceeded 50. This is a great honor 💚 💙 💜 💛 ❤️
  • Functions have been added that wrap Ecto.Repo.
insert_store/3 Ecto.Repo.insert + EctoCellar.store
update_store/3 Ecto.Repo.update + EctoCellar.store
upsert_store/3 Ecto.Repo.insert_or_update + EctoCellar.store
delete_store/3 Ecto.Repo.delete + EctoCellar.store
  • You can now get the primary key automatically.

See also CHANGELOG

Usage

1. Configuration.

Add ecto_cellar configure to your config.exs.

config :ecto_cellar, :default_repo, YourApp.Repo

2. Creates versions table.

You can generate migration file for EctoCeller. Let’s type mix ecto_cellar.gen. And migrate by mix ecto.migrate.

3. Stores changes to model.

Stores after a model is changed or created. These are stored as recoverable versions for the versions table.

By Repo.insert + EctoCellar.store/2.

iex> with {:ok, post} <- %Post{title: "title", views: 0} |> @repo.insert(),
...>      {:ok, _post} <- EctoCellar.store(post) do # or store!/2
...>   # do something
...> end

or

There is also a function that wraps EctoRepo.insert, update, insert_or_update and delete.

By EctoCellar.insert_store/3. (Uses EctoCellar.update_store/3 when updated.)

iex> case EctoCellar.insert_store(post) do # or update_store/3, upsert_store/3, delete_store/3
...>   {:ok, _post} -> # do_somesing
...>   error -> error
...> end

4. Gets versions and can restore it.

Uses EctoCellar.all/2 and EctoCellar.one/3, you can get past changes versions. And use it, you can restore.

iex> post = Post.find(id)
%Post{id: 1, body: "body3"...etc}

iex> post_versions = EctoCellar.all(post) # Can get all versions.
[%Post{id: 1, body: "body3"...etc}, %Post{id: 1, body: "body2"...etc}, %Post{id: 1, body: "body1"...etc}]

iex> version_1_inserted_at = ~N[2022-12-12 12:00:12]
iex> post_version1 = EctoCellar.one(post, version_1_inserted_at)
%Post{id: 1, body: "body1", inserted_at: ~N[2022-12-12 12:00:12]...etc}

iex> post_version1
iex> |> Post.changeset([])
iex> |> Repo.update() # Restored!!!

Options

The last argument of each function accepts the following options.

  • repo: You can select a repo other than the one specified in Config.

For contributers

You can test locally in these steps.

  1. make setup
  2. mix test

Bugs and Feature requests

Feel free to open an issues or a PR to contribute to the project.

Simple, Effective Elixir Test Setup in VSCode

A short blog post / note on how to setup elixir testing tasks and keybindings in VSCode. https://www.gatlin.io/notes/elixir-test-setup-in-vscode

[Announcement] Existence - asynchronous dependency health checks library

Library features:

  • User defined dependencies checks with flexible settings.
  • Dependencies checks functions are executed asynchronously.
  • Built-in Plug module providing customizable response for a http health-check endpoint.
  • Support for multiple independent Existence instances and associated health-checks endpoints (example use case: separate Kubernetes readiness and liveness http probes).
  • Checks states are stored and accessed using a dedicated ETS tables per Existence instance, which means practically unlimited requests per second processing capacity.

https://github.com/Recruitee/existence

Doctest functions with side effects

How to write doctests for public functions that have side effects in elixir on the example from Mox’s documentation. https://manusachi.com/blog/doctests-with-side-effects

Finitomata — a proper FSM library for Elixir

Finitomata provides a boilerplate for FSM implementation, allowing to concentrate on the business logic rather than on the process management and transitions/events consistency tweaking.

It reads a description of the FSM from a string in PlantUML format.

https://github.com/am-kantox/finitomata

Diving into the macros that make Phoenix controllers work

You’ve made a Phoenix controller before, but do you know how it actually works? Let’s explore some code together. https://www.brewinstallbuzzwords.com/posts/phoenix-controller-macros/

ThinkingElixir 092: Temple with Mitchell Hanberg

In episode 92 of Thinking Elixir, we talk with Mitchell Hanberg and learn about why he created the alternate Phoenix templating language called “Temple”. He explains how Temple works, some of its unique benefits and where he’s going with it in the future. Mitchell also took over maintenance of the testing project Wallaby from Chris Keathley. We revisit what Wallaby is and the special place it can have when building automated full system tests for our projects.

https://podcast.thinkingelixir.com/92

Phoenix LiveView Under The Hood: The Form Function Component

Let’s demystify LiveView’s form function component by taking a look under the hood.

https://blog.appsignal.com/2022/03/29/phoenix-liveview-under-the-hood-the-form-function-component.html

🎉 SmartLogic is Hiring!

ISO a Staff Engineer and a Mid Level Ruby on Rails or Elixir Developer. Both roles are full time and fully remote (within the US). SmartLogic is a great place to work - come join our team! https://smartlogic.io/about/jobs

livebook-connect script, new in Legendary 6.6.0

I just added script/livebook-connect to Legendary. It lets you connect Livebook to your running server with a single command! https://gitlab.com/mythic-insight/legendary

EctoCellar has been released🎉Store changes to your models, for auditing or versioning.

Store changes to your models, for auditing or versioning. Inspired by paper_trail.

Links

Add ecto_cellar congigure to your config.exs.

config :ecto_cellar, :repo, YourApp.Repo

2. Creates versions table.

You can generate migration file for EctoCeller. Let’s type mix ecto_cellar.gen. And migrate by mix ecto.migrate.

3. Stores changes to model.

Stores after a model is changed or created. These are stored as recoverable versions for the versions table

iex> with {:ok, post} <- %Post{title: "title", views: 0} |> @repo.insert(),
iex>      {:ok, _post} <- EctoCellar.store(post) do # or store!/2
iex>   # do something
iex> end

4. Gets versions and can restore it.

Uses EctoCellar.all/2 and EctoCellar.one/3, you can get past changes versions. And use it, you can restore.

iex> post = Post.find(id)
%Post{id: 1, body: "body3"...etc}

iex> post_versions = EctoCellar.all(post) # Can get all versions.
[%Post{id: 1, body: "body3"...etc}, %Post{id: 1, body: "body2"...etc}, %Post{id: 1, body: "body1"...etc}]

iex> version_1_inserted_at = ~N[2022/12/12 12:00:12]
iex> post_version1 = EctoCellar.one(post, version_1_inserted_at)
%Post{id: 1, body: "body1", inserted_at: ~N[2022/12/12 12:00:12]...etc}

iex> post_version1
iex> |> Post.changeset([])
iex> |> Repo.update() # Restored!!!

Bugs and Feature requests

Feel free to open an issues or a PR to contribute to the project.

Can we send Message to Non-Existing Process ?| Elixir Expert

Sending Message Never Fail

Speed up your daily work with Elixir console tricks

I would like to present some useful tricks to speed up your work.

Elixir’s interactive shell is a great tool to make your work comfortable. You don’t need to use a browser to check function errors. You have everything available in the console!

More on: https://bartoszgorka.com/speed-up-your-daily-work-with-elixir-console-tricks

ThinkingElixir 091: Reviewing Elixir with José Valim - Part 3

In episode 91 of Thinking Elixir, José Valim returns to continue with part 3 of our 5 part series as we count down to the 10 year anniversary of the Elixir project we know and love. In Part 3, we talk through the Elixir releases of 1.7, 1.8, and 1.9. We talk about the unification efforts between Elixir and Erlang. These came through changes to error stacktraces, how documentation is stored, a unified logger, and more. We learn how features like Mix.target made a big difference for the Nerves project. We also hear the call for contributors to help bring a few remaining date/time features to Elixir. The big feature in Elixir 1.9 was the addition of deployment releases and the early efforts at managing config for releases. We thought this would be a short episode but found there was a lot to talk about and learn!

https://podcast.thinkingelixir.com/91

Previous page Next page