4 ms·
I haven't used Elixir for scripting yet, but I really like the idea of including deps at the top of the file. It's always been a pain to manage this in other sc
by sb8244 3y ago
I haven't used Elixir for scripting yet, but I really like the idea of including deps at the top of the file. It's always been a pain to manage this in other scripting environments. I did scripts with Ruby in past and it didn't end up being easy to use because of external deps.
- tomjakubowski 3y agogood ol' nasty jupyter notebooks support this: %pip install foo~=1.5 %pip install bar~=1.7 import foo import bar
- radiospiel 3y agoTBF ruby lets you use inline bundler. See https://bundler.io/guides/bundler_in_a_single_file_ruby_script.html https://bundler.io/guides/bundler_in_a_single_file_ruby_scri...
- sb8244 3y agoOh that's awesome. I didn't know about this (or not sure when it was released.) edit: it's been out since 2015 it looks like. Not sure why but I didn't know about this before. It would have been useful.
- deleted 3y ago[deleted]
- thibaut_barrere 3y agoIt's not that well known, and it's awesome too. I used that last week on "fire rescue production" scripts, and it was quite useful. I'm glad that my 2 favorite languages have that feature.
- networked 3y agoYou can declare dependencies at the top of a script file in a few languages, though usually through a third-party tool. I have a page on my site with a list of such languages and tools: https://dbohdan.com/scripts-with-dependencies https://dbohdan.com/scripts-with-dependencies. For example, for Crystal there is https://github.com/Val/crun https://github.com/Val/crun. I wish more developers knew about single-file scripts with dependencies. People seem to only discover them accidentally through a language or runtime that has the support built in. It means Elixir will contribute to the awareness, but Elixir itself is niche. Maybe Deno and Bun, as JavaScript runtimes, will popularize them. Having a common term not specific to any language may help, as there doesn't seem to be one. It hinders search. "(Single-file) scripts with dependencies" is what I have settled on. Edit: Added the Crystal example and the second paragraph.
- josevalim 3y agoThis is a very nice resource, thanks for sharing!
- crymer11 3y agoI'll second @josevalim's comment, but I also wanted to mention how delighted I am to find out today that a joke[1] I probably spent way too much time 7 years ago has actually served a useful purpose! 1 - https://hex.pm/packages/leftpad https://hex.pm/packages/leftpad
- sodapopcan 3y agoHa! I just found this the other day and thought it was for real, lol. I wasn't actually looking for leftpad, of course, but, well done!
- networked 3y agoHaha. Thanks for writing it. I appreciate your and every leftpad porter's effort. :-) It makes for a perfect little dependency test with a standardized name. (Standardized up to /left[_-]?pad/i.) When a language doesn't have a leftpad package, I go looking for a concise way to make terminal text bold, which takes more time. Plus, seeing code like https://github.com/colinrymer/leftpad.ex/blob/8d2230bf094eed83c89e42352a81de184cf154c2/lib/leftpad.ex https://github.com/colinrymer/leftpad.ex/blob/8d2230bf094eed... is just fun: defmodule Leftpad do @moduledoc """ Remembering `String.rjust/3` can be difficult, so Leftpad provides you another way to easily left pad/right justify your UTF-8 encoded binaries. """ @doc ~S""" Provides basically the same functionality as [`String.rjust/3`](http://elixir-lang.org/docs/stable/elixir/String.html#rjust/3) ## Examples iex> Leftpad.pad("foo", 5) " foo" iex> Leftpad.pad("foobar", 6) "foobar" iex> Leftpad.pad("1", 2, ?0) "01" """ @spec pad(string :: String.t, count :: non_neg_integer, char :: char) :: String.t def pad(string, count, char \\ 32), do: String.rjust(string, count, char) end Look at that one line doing all the work, and even it delegates it to another function.