Elixir is (Still) Safe
A recently published paper makes some misleading claims about Elixir security. How do they hold up?
Elixir for Ruby developers: the three most important differences
Many developers who learn Elixir come from a background in Ruby. This is hardly surprising: Elixir’s creator, José Valim, was formerly a prominent Ruby developer, and Elixir has been attracting Rubyists since the very beginning!
But while Elixir’s syntax looks like Ruby at a glance, you’ll quickly realise that these similarities are skin-deep. The two languages are very different in their underlying designs, and Elixir often requires you to structure your code in a way that looks nothing like the equivalent Ruby. Certain aspects of Elixir will feel very unfamiliar to a Rubyist, and will take some getting used to.
This series will give a brief introduction to Elixir for developers who already know Ruby. But before we get into the details of Elixir’s syntax, it’s worth reviewing some of the higher-level differences between the two languages. In particular, here are the three most important differences between Elixir and Ruby:
https://phoenixonrails.com/blog/elixir-for-ruby-developers-the-three-most-important-differences
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