Use router `on_mount` hooks instead of duplicating LiveView mount logic

Copy-pasting the same assigns across every LiveView mount/3 function creates maintenance nightmares. Router-level on_mount hooks run automatically bef...
almirsarajcic

almirsarajcic

6 days ago

Stop mixing LiveView handlers with JavaScript hooks

Handling the same event in both Phoenix and JavaScript creates race conditions and unpredictable behavior. Keep server logic in LiveView handlers and ...
almirsarajcic

almirsarajcic

13 days ago

The amazing v/1 helper function

I may be late on this one but today I learned about the v/1, a helper function that retrieves the value from a previous expression by its line number ...
jrowah

jrowah

19 days ago

Phoenix contexts should return tuples, not raise

Phoenix context functions that raise exceptions break LiveView error handling and force try/catch everywhere. Tagged tuples enable composable error ha...
almirsarajcic

almirsarajcic

20 days ago

Prevent duplicate Oban jobs with `unique` worker options

Multiple button clicks or retries can enqueue the same background job multiple times, causing duplicate charges, emails, or API calls. Oban's built-in...
almirsarajcic

almirsarajcic

27 days ago

Stop rewriting Ecto queries from scratch - use `Ecto.Query.exclude/2` instead

Building complex queries often means starting with a base query, then customizing it for different use cases. Most developers duplicate the entire que...
almirsarajcic

almirsarajcic

1 month ago

Fixing `Ecto.StaleEntryError` with optimistic locking patterns

Race conditions in concurrent updates cause cryptic Ecto.StaleEntryError crashes in production. The error happens when multiple processes try to updat...
almirsarajcic

almirsarajcic

1 month ago

Phoenix application configuration

The config folder plays a pivotal role in any phoenix application. Its constituents are normally config.exs, dev.exs, prod.exs, runtime.exs and test.e...
Deankinyua

Deankinyua

1 month ago

Hunting down flaky tests with `--repeat-until-failure`

Nothing destroys developer confidence like tests that randomly fail in CI. One day your build is green, the next it's red with the exact same code. Th...
almirsarajcic

almirsarajcic

1 month ago

Impelementing Infinite Scroll in Phoenix

Infinite scroll is a listing-page design approach seen a lot on widely used apps such as TikTok and Instagram to keep the user engaged, loading additi...
Deankinyua

Deankinyua

1 month ago

Preventing atom exhaustion attacks with `String.to_existing_atom`

Using String.to_atom/1 on user input is a critical security vulnerability that can crash your entire BEAM VM through atom exhaustion. Here are two app...
almirsarajcic

almirsarajcic

1 month ago

Executing OS processes using Elixir Ports

Ports in Elixir provide us an interface for communicating with external processes by sending and receiving messages. They make it easy to start and ma...
Deankinyua

Deankinyua

2 months ago

Speed up Phoenix with ETS content caching and TTL expiration

Database queries for content-heavy pages become performance bottlenecks fast. Redis adds infrastructure complexity. ETS gives you microsecond lookups ...
almirsarajcic

almirsarajcic

2 months ago

Fine tuning routing for a better UX

Phoenix gives you a very cool and easier way to fine tune your routing and be able to effectively handle cases where, say a user has a typo in the url...
jrowah

jrowah

2 months ago

Verifying Replicate Signatures

Replicate is a platform for running AI models without having to worry about setting up infrastructure. A more simple definition would be "The Cloud bu...
Deankinyua

Deankinyua

2 months ago