Autocontext: Lets DRY your Ecto contexts.
Yeah, for some, this could be an Ecto’s heresy, but I’ve built a lib that provides ActiveRecord-like callbacks, simplifying database operations management. This includes [before | after]_save
, [before | after]_create
, [before | after]_update
, and [before | after]_delete
functions.
Also, thanks to the Elixir community I have also added some configurability that is (yet) inaudit on ActiveRecord land. This is:
- Support for optional transactions on the operation. Behind the scenes the operation is wrapped in a Ecto.Multi
-
Support for multiple configurations that may involve different Changesets over a Single Schema or even different Changesets over different Schemas.
Example:
This is Just a way to abstract the functions you would write anyway on your contexts, Behind the scenes it uses the typical Ecto calls, it just saves writing and repeating the same code every time. Imo having to write the same every time does not make sense. Of course for the 1% of the times when it does you can overwrite the functions at your will.
Make your Ecto contexts fun! https://github.com/michelson/autocontext
Creating infinite sequences with Stream.unfold/2
Want to learn how to create infinite sequences in Elixir?
We can do it with Stream.unfold/2
🤯
Check out how we use it to generate a finite sequence, an infinite sequence, and the Fibonacci sequence. 😊
🎥 https://elixirstreams.com/tips/creating-infinite-sequences-with-unfold
Library authors hate this one weird trick!
I think my head hit the keyboard when I learned how much time I had wasted when debugging Elixir dependencies.
No more mucking with path deps or its ilk. mix deps.compile is your friend! See more at:
SQL Injections vs Elixir
Let’s keep building safe, robust applications with Elixir. Happy coding! 🚀🔒 Take a moment to read it here: https://curiosum.com/blog/sql-injections-vs-elixir
#Elixir #WebSecurity #SQLInjection
Turn maps (and keyword lists) into structs
One nice way of turning a map or keyword list into an existing struct is to use struct/2
or struct!/2
.
What about attributes that aren’t defined in the struct?
-
struct/2
will drop them 👋 -
struct!/2
will raise an error 💥
Check it out! 👀
👉 https://www.elixirstreams.com/tips/turn-maps-into-structs-with-struct
Thinking Elixir 160: LiveView Async Pattern and Admin Tools
Episode 160 of Thinking Elixir. After experience with a LiveView “anti-pattern”, Andy Glassman developed an “Async Pattern” for loading data into a LiveView. Andy shares the problem this helps solve and we discuss when it’s a good fit. We also talk with Andy about the current state of “admin tools” in Elixir and he shares his feelings on the importance of building admin tools from the start in our projects.
Observe Your Phoenix App with Structured Logging
Let’s configure a Phoenix LiveView application to use a structured logger and monitor the app with AppSignal: https://blog.appsignal.com/2023/07/18/observe-your-phoenix-app-with-structured-logging.html
Instilling a passion for functional programming in developers - Elixir Meetup #19
It’s for those who are interested in becoming a better programmer, who has a better and more clear understanding of not only functional programming but programming in general.
Check the Mikołaj Kubera presentation: https://www.youtube.com/watch?v=ZL4gH2WwcBw
Testing Timer-based Logic in Elixir with Klotho Library
We introduce an approach to testing time- and timer- based logic in Elixir with an unburdensome variant of dependency injection https://dev.to/savonarola/testing-timer-based-logic-in-elixir-with-klotho-library-2c90
Implementing an NTP server in Elixir
In this post we go thru a simple Network Time Protocol server implementation in Elixir. While the end product is not production ready we learn a lot about UDP, sniffing traffic, GenServers, bitstrings, sigils, and other cool tricks.
What's new in Livebook 0.10 - Introducing Multi-Session Livebook Apps
Livebook 0.10 was released! 🎉
The main new feature is Multi-Session Livebook Apps. You can think of them as something similar to scripts, but instead of running in a terminal, they are interactive web applications accessed through the browser.
The other new features are:
- Presentation View
- Initial Erlang Support
- Live Doctests
- Dataframe File Export
Announcement blog post: https://news.livebook.dev/whats-new-in-livebook-0.10—introducing-multi-session-livebook-apps-3Dbpss
Full changelog: https://github.com/livebook-dev/livebook/blob/v0.10/CHANGELOG.md
Adjustments of Phoenix application configuration
Rearrange Phoenixʼ config files to improve their developer experience!
https://bitcrowd.dev/two-small-adjustments-of-phoenix-application-configuration
Elixir Fortaleza Conf 2023
An event organized by the Elixir community. Dates: September 21st and 22st, 2023 Location: Fortaleza, Ceará, Brazil. Stay tuned for more information at https://elixiremfoco.com/elixirfortalezaen
How to run a function N times
Ever want to do something N times?
If you come from the Ruby on Rails world (like I did), you might be looking for something like 5.times { do_something }
.
This is one way I like to do this:
-
Create a stream with the function you want to run repeatedly with
Stream.repeatedly/1
. -
Then, when you want to run that
N
times, youEnum.take(N)
!
Check it out! 👇
https://www.elixirstreams.com/tips/run-elixir-function-n-times
A small language (Ovo2) in Elixir : a graphical stateful environment
My experiment of a small language hosted in elixir finds closure with humor, after becoming an interactive stateful system with weird features and a graphical liveview interface. The post features a recreation of “99 bottles of beer” in an ovo-idiomatic way.
Introducing typeid_elixir
An Elixir implementation of TypeIDs: type-safe, K-sortable, and globally unique identifiers inspired by Stripe IDs
typeid_elixir | hex.pm sloanelybutsurely/typeid-elixir hexdocs
Thinking Elixir 159: Langchain with Elixir and Safe Ecto Migrations
Episode 159 of Thinking Elixir. Mark and David share what’s caught their interests and focus. Langchain is a popular framework in JS and Python communities for building services that knit together different services enabling people to quickly build impressive demos. Mark talks about the parts of Langchain that interest him and how he’s been building ways for Elixir apps to play in that space too. We also catch up with David’s job change, moving, and talk about his ideas around using Oban for managing data migrations in a new way.
Comparing Datetimes and Dates in Elixir
Elixir 1.15 introduced new DateTime
and Date
functions to compare dates.
Let’s cover the new functions, what already exists, and what to avoid at all costs!
-
New ✨:
DateTime.before?/2
,DateTime.after?/2
(and theirDate
counterparts) are new (since Elixir 1.15) and allow for strict comparison of datetimes (and dates), -
We’ve had
DateTime.compare/2
for a while, and it returns:gt
,:lt
, or:eq
. The nice thing aboutcompare/2
is that it has equality. -
Never use
<
,>
,==
to compare dates or datetimes! They perform structural comparisons. They don’t understand semantics.
Check out a short video of me walking through those! 👇 https://www.elixirstreams.com/tips/comparing-elixir-datetimes-and-dates
IntelliJ Elixir v15.1.0
Changelog
v15.1.0
Enhancements
- Add “Homebrew on Linux” SDK locations.
Bug Fixes
-
Replace uses of
Cell.horizontalAlign(HorizontalAlign)
The API is scheduled for removal and is replaced byCall.align(AlignX.FILL)
. -
Ignore
group:
for docs. - Don’t resolve built-in types against the index if index is updating.
-
findModuleForPsiElement
inmostSpecificSdk
in read action. -
Skip finding
mix.exs
for OTP apps if it can’t be read. -
Include
mix new
stderr inIOException
for better triage. - Highlight binary numbers and module attributes as usual in types.
-
Use
org.apache.commons.lang.SystemUtils
instead oforg.codehaus.plexus.interpolation.os.Os
to detect if on Windows for Test marker file URL. -
Call
FileIndex.getContentRootForFile
inReadAction
when getting working directory formix format
. -
Don’t include
null
target usage types when finding usage type across all targets. - Skip bare Aliases when resolving Types.
-
Exclude
.elixir_ls
directory when configuring newProject
s. If the.elixir_ls
directory is included the.beam
it produces can interfere with normalStubIndex
. - Check if Internal Erlang SDK home path exists for SDK for New Project.
-
Stop
prependingQualifiers
at EEx tags.
How To Add Magic Link Login to phx.gen.auth
How to safely, simply, and securely add magic link login to your Phoenix app! phx.gen.auth provides the tools to make it quick and easy