Skip to content

Instantly share code, notes, and snippets.

@myobie
Created April 27, 2020 16:13
Show Gist options
  • Save myobie/4ecb033102c2d522b2ca1df1688d90ab to your computer and use it in GitHub Desktop.
Save myobie/4ecb033102c2d522b2ca1df1688d90ab to your computer and use it in GitHub Desktop.
Save 14 characters for UUIDs
def generate_id do
result =
Ecto.UUID.generate()
|> String.replace(~r/-+/, "")
|> Base.decode16(case: :lower)
case result do
:error ->
throw("Something went wrong generating a uuid")
{:ok, value} ->
Base.encode64(value)
|> String.replace(~r/=+$/, "")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment