Skip to content

Instantly share code, notes, and snippets.

View rsgrafx's full-sized avatar
🏠
Working from home

Orion Engleton rsgrafx

🏠
Working from home
View GitHub Profile
@rsgrafx
rsgrafx / using-with.exs
Created April 30, 2016 20:57
Best use cases for 'with' in elixir
defmodule Bicycle do
defstruct [wheels: 2, pedals: nil, seat: nil, pass: nil]
end
defmodule BikeTypeCheck do
def check(%Bicycle{wheels: count, pedals: val}=bike) do
return = with {:ok, 2} <- count_wheels(count),
{:ok, true} <- has_pedals(val),
do: pedal_away(bike)
@rsgrafx
rsgrafx / queen_attack.exs
Created May 7, 2018 01:36
Queen Attack Exercism solution
defmodule Queens do
@type t :: %Queens{black: {integer, integer}, white: {integer, integer}, grid: List.t()}
defstruct black: nil, white: nil, grid: nil
@doc """
Creates a new set of Queens
"""
@spec new({integer, integer}, {integer, integer}, integer) :: t()
def new(white \\ {0, 3}, black \\ {7, 3}, grid \\ 8)
@rsgrafx
rsgrafx / Atom.snippets.cson
Created May 29, 2018 23:13
Elixir Atom Snippets
'.source.elixir':
'Iex Pry':
'prefix':'pry'
'body': """
require IEx
IEx.pry()
"""
'New GenServer':
'prefix':'genmod'
'body': """
defmodule Flattery do
def run({a, b}, acc)
when is_map(b) == false,
do: Map.merge(acc, %{a => b})
def run({_a, b}, acc)
when is_map(b),
do: go(b, acc)
def run({a, b}, acc),

Keybase proof

I hereby claim:

  • I am rsgrafx on github.
  • I am tuplelife (https://keybase.io/tuplelife) on keybase.
  • I have a public key ASDF1I-_D-XnbfleX_TCVlZjgcwtlbG5udGTKxSPJIyWSAo

To claim this, I am signing this object: