Skip to content

Instantly share code, notes, and snippets.

View erikreedstrom's full-sized avatar

Erik Reedstrom erikreedstrom

View GitHub Profile
@erikreedstrom
erikreedstrom / bcp47.ex
Created February 13, 2016 16:25
Elixir module for parsing bcp 47 (https://tools.ietf.org/html/bcp47) spec'd language tags.
defmodule BCP47 do
@moduledoc ~S"""
Main BCP47 module.
The `BCP47` module provides a parser for
[bcp 47](https://tools.ietf.org/html/bcp47) spec'd language tags.
"""
@type tag :: String.t
@erikreedstrom
erikreedstrom / blank.ex
Created February 13, 2016 17:54
Blank protocol for Elixir
defmodule Blank do
@moduledoc """
Tools around checking and handling undefined or blank data.
"""
@doc """
Returns `true` if data is considered blank/empty.
"""
def blank?(data) do
Blank.Protocol.blank?(data)
@erikreedstrom
erikreedstrom / sequencer.ex
Created February 25, 2019 14:41
Hexadecimal midpoint spacer
defmodule Sequencer do
@base 256
def find_mid(a, b, n \\ 1) do
[a, b] = ensure_order([a, b])
ad = bin_to_list(a)
bd = bin_to_list(b)
intermediate_bytes = long_linspace(ad, bd, n)
@erikreedstrom
erikreedstrom / work_with_flags.ex
Created June 12, 2019 18:32
FunWithFlags toggle overlay for when having fun is not an option.
defmodule WorkWithFlags do
@moduledoc """
Feature Toggle overlay for when having fun is not an option.
The main difference from the main lib is the precedence of gates
and how they combine.
In this implementation, we define Boolean > Actor > (Group & Percent).
The Boolean gate works as a master switch; requiring the flag be expressly
@erikreedstrom
erikreedstrom / assersions_json.ex
Created September 4, 2019 13:41
Assertions for validating JSON responses in Elixir.
defmodule ExUnit.Assertions.JSON do
@moduledoc """
Assertions for validating JSON responses.
This code was cribbed from [Voorhees](https://github.com/danmcclain/voorhees)
and adapted to follow the modern ExUnit `lhs == rhs` assertion syntax,
as well as simplify matching logic.
"""
import ExUnit.Assertions