Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Elixir Atom Snippets
'.source.elixir':
'Iex Pry':
'prefix':'pry'
'body': """
require IEx
IEx.pry()
"""
'New GenServer':
'prefix':'genmod'
'body': """
defmodule $1 do
use GenServer
def start_link(_) do
GenServer.start_link(__MODULE__, %{})
end
def init(opts) do
{:ok, opts}
end
end
"""
'New Struct Module':
'prefix':'defms'
'body':"""
defmodule $1 do
defstruct []
end
"""
'Enum.map':
'prefix':'map'
'body':"""
Enum.map($1, fn($2) -> end)
"""
'GenServer handle call':
'prefix':'hcall'
'body': """
def handle_call($1, from, state) do
{:reply, state, state}
end
"""
'GenServer Handle Call':
'prefix':'defcall'
'body': """
def handle_call($1, from, state) do
{:reply, state, state}
end
"""
'GenServer handle Cast':
'prefix':'hcast'
'body': """
def handle_cast($1, state) do
{:noreply, state}
end
"""
'GenServer Handle Cast':
'prefix':'defcast'
'body': """
def handle_cast($1, state) do
{:noreply, state}
end
"""
'GenServer Handle Info':
'prefix':'definfo'
'body': """
def handle_info($1, state) do
{:noreply, state}
end
"""
'Supervisor':
'prefix':'ovisor'
'body':"""
defmodule $1 do
use Supervisor
def start_link(arg) do
Supervisor.start_link(__MODULE__, arg)
end
def init(arg) do
children = [
worker(${1:.Worker}, [$3], restart: :temporary)
]
supervise(children, strategy: :simple_one_for_one)
end
end
"""
'IO Inspect':
'prefix':'io'
'body':"""
IO.inspect($1, label: "VALUE: \#{$1\} ->")
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment