Skip to content

Instantly share code, notes, and snippets.

Working from home

Orion Engleton rsgrafx

Working from home
Block or report user

Report or block rsgrafx

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Flatter.ex
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 / Atom.snippets.cson
Created May 29, 2018
Elixir Atom Snippets
View Atom.snippets.cson
'Iex Pry':
'body': """
require IEx
'New GenServer':
'body': """
rsgrafx / queen_attack.exs
Created May 7, 2018
Queen Attack Exercism solution
View queen_attack.exs
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 / using-with.exs
Created Apr 30, 2016
Best use cases for 'with' in elixir
View using-with.exs
defmodule Bicycle do
defstruct [wheels: 2, pedals: nil, seat: nil, pass: nil]
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 / citrusbyte.exs
Last active Dec 18, 2016
Citrusbyte. list reduce in Elixir
View citrusbyte.exs
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]
Citrusbyte.example [[1,2,[3]],4] #=> [1,2,3,4]
rsgrafx / paperclip.ex
Last active Sep 18, 2017
Setting up Arc in a phoenix app that was ported from a rails app using paperclip.
View paperclip.ex
# 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 / rewrite.exs
Last active Jan 29, 2016
elixir rewrite folder structure from filenames.
View rewrite.exs
# Specifically written for - this problem with folders unzipped from this 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 / Deploying NON Phoenix apps
Last active Aug 29, 2015
Deploying Simple NON Phoenix apps on VPS ( linode / Digital ocean) with Git
View Deploying NON Phoenix apps
#-- Follow this great writeup for prerequisites- having erlang/elixir/gitinstalled.
#-- Setting up repos on the vps etc.
# In my case - I'M NOT USING PHOENIX I had to modified the post-receive hook in the repo
#-------- post-receive hook
git --work-tree=/<your>/<path>/<> --git-dir=/<your>/<path>/<toyour.REPO> checkout -f;
cd /<your>/<path>/<>
View server_process.ex
# 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)
rsgrafx / gist:9862471
Created Mar 29, 2014
I started using Enumerable#detect. Decided to have a little fun with procs.
View gist:9862471
log = [
{time: 201201, x: 2},{time: 201201, y: 7},{time: 201201, z: 2},
{time: 201202, a: 3},{time: 201202, b: 4},{time: 201202, c: 0}
# Required - Results.
required_result = [{:time=>201201, :x=>2, :y=>7, :z=>2}, {:time=>201202, :a=>3, :b=>4, :c=>0}]
# Using global variables * and #Procs
You can’t perform that action at this time.