Skip to content

Instantly share code, notes, and snippets.

@ijunaid8989
Created June 30, 2016 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ijunaid8989/c59e4ae43bbc4166ec0db55a12a84bba to your computer and use it in GitHub Desktop.
Save ijunaid8989/c59e4ae43bbc4166ec0db55a12a84bba to your computer and use it in GitHub Desktop.
defp generate_exid(title) do
clip_exid =
title
|> String.replace_trailing(" ", "")
|> String.downcase
|> String.slice(0..5)
chars = (?a..?z |> Enum.into([]) |> Enum.map(&to_string([&1]))) ++ (1..9 |> Enum.to_list)
random_string = Enum.map(0..3, fn(_) -> Enum.random(chars) end) |> Enum.join("")
"#{clip_exid}-#{random_string}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment