useful
useful copied to clipboard
🇨🇭 A collection of useful functions for working in Elixir
I used this a few times: ```elixir def is_valid_url?(string) do [:scheme, :host, :port] |> Enum.map(&Map.get(URI.parse(string), &1)) |> Enum.all?() end ``` ```elixir test "is_valid_url?/1" do assert is_valid_url?("http://www.google.com") == true assert is_valid_url?("http//google.com")...
closes #64 This is a quick merge. Found this useful for small Elixir projects, thanks @ndrean 👌
I had this pretty (useful) complicated function: ```elixir def list_tuples_to_unique_keys(parts) do key = parts |> hd() |> elem(0) new_keys = Enum.map(1..length(parts), &(key "-#{&1}")) Enum.zip_reduce([parts, new_keys], [], fn [elt, new_key], acc...
If you find yourself trying to merge maps within a list that share a common key/value, this maybe for you. From: ```elixir [ %{ base: "dff3a13e58c2fcb2d1382f8f016e035405bad359", full_ref: "#Reference", full_name: "dff3a13e58c2fcb2d1382f8f016e035405bad359-m1440.webp"...
At present we have a `strip_struct_metadata/1` function is hidden in: https://github.com/dwyl/auth_plug/blob/da40aca75d5ecc0fc016023f4a61eb6f4b7cfb6f/lib/auth_plug_helpers.ex#L18C1-L33C6 ```elixir @doc """ `strip_struct_metadata/1` removes the Ecto Struct metadata from a struct. This is essential before attempting to create...
Suppose you have data in the form ` [{"M1", "C1"}, {"M1", "C2"}, {"M2", "C3"}]` and you want a map "grouped by": `[%{c: ["C2", "C1"], m: "M1"}, %{c: ["C3"], m: "M2"}]`...
# Context I just want a simple function that I can use to display the full human friendly date + time in my logs or UI. e.g: "2022-04-20 04:20" Why...
Given the following structure: ```elixir %{items: [%{id: 1}, %{id: 2}], another: %{key: :value}} ``` I would expect the following result: ```elixir %{another__key: :value, items__0__id: 1, items__1__id: 2} ``` But we...