Skip to content

Instantly share code, notes, and snippets.

View bryanhunter's full-sized avatar

Bryan Hunter bryanhunter

View GitHub Profile
@bryanhunter
bryanhunter / bangpipe.exs
Last active November 12, 2017 00:57
BangPipe - a really silly Elixir macro
Interactive Elixir (1.5.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> defmodule Bangpipe do
...(1)> defmacro left <|> right do
...(1)> quote do
...(1)> unquote(left)
...(1)> |> case do
...(1)> {:ok, val} -> val
...(1)> val -> val
...(1)> end
...(1)> |> unquote(right)
@bryanhunter
bryanhunter / UnionTypes.fs
Created November 12, 2017 00:54
Shape union in F#
module UnionTypes
// Learn more about F# at http://fsharp.org
type Shape =
| Circle of float
| Square of float
| Triangle of float * float
| Rectangle of float * float
@bryanhunter
bryanhunter / UnitsOfMeasure.fs
Created November 12, 2017 00:55
Union type with units of measure
module UnitsOfMeasure
[<Measure>] type cm
[<Measure>] type inch
type Shape<[<Measure>]'u> =
| Circle of float<'u>
| Square of float<'u>
| Triangle of float<'u> * float<'u>
| Rectangle of float<'u> * float<'u>
@bryanhunter
bryanhunter / ColorNameTest.exs
Last active March 31, 2018 18:41
An example of property-based testing in Elixir 1.6
# Until StreamData ships in Elixir it needs to be added as a dependency.
# https://hexdocs.pm/stream_data/StreamData.html#content
# https://hex.pm/packages/stream_data
# Add this to your mix.exs deps...
# {:stream_data, "~> 0.4.2"}
defmodule ColorNameTest do
use ExUnit.Case, async: true
use ExUnitProperties
@bryanhunter
bryanhunter / keybindings.json
Created April 20, 2018 20:43
VS Code User Settings
// Mac ~/Library/Application Support/Code/User/keybindings.json
[
{
"key": "alt+enter",
"command": "workbench.action.terminal.runSelectedText"
},
{
"key": "cmd+h",
"command": "editor.action.startFindReplaceAction"
},