Last active
March 27, 2017 14:24
-
-
Save adamgavlak/9c6a3aaf9872676ee30affdb1f600ea0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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