Welcome to ElixirDrops!

Hello there and welcome to the ultimate hub for the Elixir community! Whether you're a seasoned developer or just starting your journey, ElixirDrops is the perfect place to discover, share, and discuss the best tips and tricks for mastering Elixir. Sign in to explore, learn and become a contributor on this platform.

Keeping stale gzip assets out of Phoenix tests

I spent too long debugging a LiveView hook in ElixirDrops because the browser kept running old JavaScript. The source and freshly built app.js were co...
almirsarajcic

almirsarajcic

10 hours ago

0

Let ExUnit shut down your test processes

Start test-owned processes with start_supervised!/1 so ExUnit waits for them to shut down before running your cleanup callbacks....
almirsarajcic

almirsarajcic

yesterday

0

Put `phx-change` inputs inside a form

Put every input with its own phx-change binding inside a form. Outside one, the markup looks wired, but LiveView will not send the event....
almirsarajcic

almirsarajcic

2 days ago

0

Check the exit status from `System.cmd/3`

Check the exit status when wrapping an external command. A nonzero exit from the program does not make System.cmd/3 raise....
almirsarajcic

almirsarajcic

3 days ago

0

Make `capture_log` assertions test-specific

Do not assert on generic text in logs captured by async tests....
almirsarajcic

almirsarajcic

4 days ago

0

Avoid `File.cd!/2` in async tests

Do not use File.cd!/2 to isolate filesystem work in concurrent tests. Its callback looks scoped, but the current working directory belongs to the enti...
almirsarajcic

almirsarajcic

5 days ago

0

Build sequence diffs with List.myers_difference/2

Use List.myers_difference/2 to turn two sequences into an edit script without adding a diff dependency....
almirsarajcic

almirsarajcic

6 days ago

0

Capture warnings with Code.with_diagnostics/2

Use Code.with_diagnostics/2 when warnings and errors need to become structured data instead of terminal text....
almirsarajcic

almirsarajcic

8 days ago

0

Update matching list items with Access.filter/1

Use Access.filter/1 to update only the list elements that match a predicate, without mapping and rebuilding the surrounding structure yourself....
almirsarajcic

almirsarajcic

9 days ago

0

Discard late replies with process aliases

Send hand-rolled request replies to a process alias, then deactivate the alias when the caller stops waiting....
almirsarajcic

almirsarajcic

10 days ago

0

Reject unknown struct keys with struct!/2

Use struct!/2 when runtime attributes must contain only fields that belong to the struct....
almirsarajcic

almirsarajcic

11 days ago

0

The Module Behind the Curtain

Use defdelegate when a function should simply forward its arguments to another module....
spapiernik

spapiernik

12 days ago

1

Build strings with iodata, not concatenation

Building a string by repeatedly <>-ing onto an accumulator can be quadratic — but not for the reason most people think. The BEAM has a runtime optimiz...
almirsarajcic

almirsarajcic

12 days ago

2

Ecto's :utc_datetime silently drops microseconds

:utc_datetime stores second precision. Hand it a DateTime.utc_now/0 value — which carries microseconds — and Ecto.Type.cast/2 truncates it with no war...
almirsarajcic

almirsarajcic

13 days ago

0

get_in/2 needs Access.key!/1 for structs

get_in/2, put_in/3, and update_in/3 walk a path of atom keys through maps and keyword lists just fine — but the same atom path raises on a struct. ``...
almirsarajcic

almirsarajcic

14 days ago

2