Skip to content

Instantly share code, notes, and snippets.

@hiway
Last active April 15, 2024 11:33
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 hiway/d3981fd49175e50ef3d67c2d995684cc to your computer and use it in GitHub Desktop.
Save hiway/d3981fd49175e50ef3d67c2d995684cc to your computer and use it in GitHub Desktop.
Elixir snippets for writing libraries
defmodule ConfigValidate do
def ensure_value_is_not_nil(key, value, suggestion) do
if value == nil do
raise """
Please set #{key} under mix.exs project configuration.
def project do
[
...
#{suggestion}
...
]
end
"""
end
end
end
defmodule GitInfo do
@spec author_email() :: binary()
def author_email() do
case System.cmd("git", ["config", "--get", "user.email"]) do
{email, 0} -> email |> String.trim()
_ -> "author@example.com"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment