Skip to content

Instantly share code, notes, and snippets.

@adamgavlak
Last active March 27, 2017 14:24
Show Gist options
  • Select an option

  • Save adamgavlak/9c6a3aaf9872676ee30affdb1f600ea0 to your computer and use it in GitHub Desktop.

Select an option

Save adamgavlak/9c6a3aaf9872676ee30affdb1f600ea0 to your computer and use it in GitHub Desktop.
defmodule Wework.Helper do
def parameterize(string) do
string
|> String.downcase
|> String.replace(~r/[^\w-]+/, "-")
|> String.replace(~r/-{2,}/, "-")
|> String.trim("-")
end
@default_length 4
def random_base32(length \\ @default_length) do
random_bytes(length)
|> Base.encode32(case: :lower)
|> String.slice(0..length - 1)
end
defp random_bytes(n \\ @default_length) do
:crypto.strong_rand_bytes(n)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment