Single File Elixir Scripts
fly.io
fly.io
But now, I love it! Mix.install([:req]) at the top and you've got an easy to use, great basis for scripts.
Toss in Livebook and you're well on your way to a wonderful exploratory environment. I've moved off having an open iex window to having a scratch Livebook open, and it's great for little explorations. I've been using it whenever I need to work with my company's API, and over time the little helper modules and functions have been evolving. I almost feel like pretty soon it might as well package it up and release them as a full-fledged Elixir library for use with the API.
Interactive Elixir (1.12.2) - press Ctrl+C to exit (type h() ENTER for help)
Mix.install([:req]) gives could not compile dependency :mint, "mix compile" failed.
[0] https://github.com/chrismccord/single_file_phx_bumblebee_ml
aka Baader-Meinhof phenomenon
(since I learned about it, it keeps popping up everywhere)
Embedded with Nerves, the various AI/ML libraries and tooling, LiveBook getting better every day, LiveView innovating and improving DevEx, etc..
Then there's fly.io pushing out content given their target market is developers and they have a big focus on deploying Elixir applications.
Single-file scripts that download their dependencies - https://news.ycombinator.com/item?id=34388826
Disclosure: the story is a link to my site.
I have plenty of single-file Elixir examples, many with tests included, in this elixir-snippets repo:
https://github.com/pmarreck/elixir-snippets/blob/master/prin...
Mix.install([ {:req, "~> 0.3"} ])
could not compile dependency :mint, "mix compile" failed. Also mix deps.get say that all dependencies are to date but then mix run gives again that could not compile dependency :mint, "mix compile" failed.
So no good way to learn elixir.
https://github.com/wojtekmach/mix_install_examples/blob/main...
it's like using Maven or npm all over again. but even worse because it generates a lot of code.
it creates disposable projects by design. No way to keep track of what to change when mix create outputs something different next year.
and now things like https://github.com/wojtekmach/mix_install_examples/blob/main... where is ecto even installed? download from where? so annoying this trend.
For Mix.install you can optionally specify the cache directory. For regular projects they are in the deps folder.
> The location of the cache directory can be controlled using the MIX_INSTALL_DIR environment variable.
https://hexdocs.pm/mix/1.14/Mix.html#install/2
> download from where?
Or you can specify a git commit, or a path if you want to alter it locally.
> No way to keep track of what to change when mix create outputs something different next year.
`mix.lock` keeps track of your resolved dependencies and should be checked in along with your code. Mix/Hex can also be provided the exact `==` versions rather than the `~>` or other Version specifiers
will you have one dep dir on each place you run the script at?
If anything I sometimes find myself annoyed that Ecto is not there by default, because it's part of almost all my projects, and often even a one-file script might benefit from bits of it.
That's how any modern package manager works (I'm thinking cargo as well). I'm not sure why not doing that would be preferable.
most languages dont havea built in package manager.
I've run into this with the Phoenix generators a bit because you need to make changes to your project if you want to update to newer versions of the Phoenix libraries, but they produce documentation about what you need to change.