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

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:

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),
@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': """
@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 / 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 / citrusbyte.exs
Last active December 18, 2016 04:41
Citrusbyte. list reduce in Elixir
defmodule Citrusbyte do
@moduledoc """
This module - demonstrates use of pattern matching in Elixir to modify a list.
[[1,2,[3]],4] -> [1,2,3,4]
Usage:
Citrusbyte.example [[1,2,[3]],4] #=> [1,2,3,4]
"""
@rsgrafx
rsgrafx / paperclip.ex
Last active September 18, 2017 15:28
Setting up Arc in a phoenix app that was ported from a rails app using paperclip.
# Ecto - Model
defmodule YourPhoenixApp.PaperclipAvatar do
use YourPhoenixApp.Web, :model
alias YourPhoenixApp.{Repo, PaperclipAvatar}
#
# There are places in my existing app where only the avatar image is required.
# So I created a module that sole purpose was to read that data.
#
schema "users" do
field :avatar_file_name, :string
@rsgrafx
rsgrafx / rewrite.exs
Last active January 29, 2016 07:55
elixir rewrite folder structure from filenames.
#
# Specifically written for - this problem with folders unzipped from this https://www.prepbootstrap.com website.
# may be able to help someone solve similar issue.
#
# Problem: Folder contains no folder structure - but hints at them in the file names:
# /
# Theme-LightWayAdmin\blog.html
# Theme-LightWayAdmin\font-awesome\less\list.less
# Theme-LightWayAdmin\bootstrap-elements.html
# Theme-LightWayAdmin\font-awesome\less\mixins.less
@rsgrafx
rsgrafx / Deploying NON Phoenix apps
Last active August 29, 2015 14:27
Deploying Simple NON Phoenix apps on VPS ( linode / Digital ocean) with Git
#-- Follow this great writeup for prerequisites- having erlang/elixir/gitinstalled.
#-- Setting up repos on the vps etc.
#-- http://gabrieljaldon.com/articles/deploying-phoenix-with-git.html
# In my case - I'M NOT USING PHOENIX I had to modified the post-receive hook in the repo
#-------- post-receive hook
#!/bin/bash
git --work-tree=/<your>/<path>/<toyour.app> --git-dir=/<your>/<path>/<toyour.REPO> checkout -f;
cd /<your>/<path>/<toyour.app>
# Eratta Elixir In Action Chpt. 6 Listing 6.x pg. 170
defmodule ServerProcess do
def start(callback_mod) do
spawn(fn ->
initial_state = callback_mod.init
loop(callback_mod, initial_state)
end)
end