Mix.env() doesn't work in releases

Mix.env() doesn't exist in production releases. Your conditional routes will silently fail, and you won't know until deployment. Use Application.compi...
almirsarajcic

almirsarajcic

19 days ago

0

Add query params to Phoenix verified routes with `~p`

Phoenix verified routes handle query parameters with the same ~p sigil you use for paths. Pass a map or keyword list after ?#{} and get compile-time v...
almirsarajcic

almirsarajcic

27 days ago

0

`defguard` creates reusable guard expressions

Repeating the same guard logic across multiple functions? Define it once with defguard and use it everywhere - in function heads, case, cond, and with...
almirsarajcic

almirsarajcic

1 month ago

0

`tap/2` runs side effects in pipelines

Need to log, send a message, or cache a value mid-pipeline without breaking the flow? tap/2 executes a function for its side effect, ignores the retur...
almirsarajcic

almirsarajcic

1 month ago

0

Use `Ecto.Multi` for complex transactions in Phoenix contexts

Manual transaction management with nested operations becomes unreadable and error-prone. Ecto.Multi provides named operations, automatic rollback, and...
almirsarajcic

almirsarajcic

1 month ago

0

Live Sessions in Phoenix LiveView: Reducing navigation time between LiveViews

The main idea behind live sessions is to reduce navigation time when navigating a group of routes. Normally what happens when navigating between LiveV...
Deankinyua

Deankinyua

1 month ago

0

`File.stream!/1` processes large files with constant memory

File.read!/1 loads the entire file into memory. A 2GB log file? That's 2GB of RAM. Use File.stream!/1 to process files line-by-line with constant memo...
almirsarajcic

almirsarajcic

1 month ago

2

Stop using `Repo.preload` in loops - use `preload` in queries

Calling Repo.preload/2 inside Enum.map or comprehensions creates N+1 queries - one query to fetch the parent records, then one additional query for ea...
almirsarajcic

almirsarajcic

2 months ago

0

Use `Task.Supervisor` instead of bare `Task.async`

Bare Task.async creates linked tasks that can crash your process or leave zombie tasks running. Task.Supervisor provides supervised tasks with automat...
almirsarajcic

almirsarajcic

2 months ago

0

Prevent race conditions with `Ecto.Query.lock/2`

Two users buying the last item simultaneously can cause overselling. Use PostgreSQL row locks with lock: "FOR UPDATE" to prevent concurrent updates fr...
almirsarajcic

almirsarajcic

2 months ago

0

Use `temporary_assigns` for large lists in LiveView

Sending entire lists over the socket on every LiveView update kills performance. Mark list assigns as temporary to send them once and drop them from s...
almirsarajcic

almirsarajcic

2 months ago

0

Use `send_update_after/4` for delayed LiveComponent updates

Manual timer management with Process.send_after/3 in LiveComponents creates cleanup complexity. LiveView's send_update_after/4 handles delayed updates...
almirsarajcic

almirsarajcic

2 months ago

0

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

3 months ago

0

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

3 months ago

0

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

3 months ago

0