Skip to content

Instantly share code, notes, and snippets.

@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"
},
@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 / 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 / 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 / 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 / HelloPhoenix.fsx
Created December 14, 2016 19:01
F# script that connects to Phoenix channels
// This sample shows connecting to a sample Phoenix chat application running locally.
// The sample Phoenix app was written by Chris McCord and can be found here:
// https://github.com/chrismccord/phoenix_chat_example)
// #r @".\packages\WebSocketSharp.1.0.3-rc11\lib\websocket-sharp.dll"
open WebSocketSharp
let ws = new WebSocket("ws://localhost:4000/socket/websocket")
ws.OnOpen.Add(fun args -> System.Console.WriteLine("Open"))
@bryanhunter
bryanhunter / bumper.exs
Created January 20, 2015 21:18
Example of Elixir and the bit-syntax to read a Bitmap image
defmodule Bumper do
@doc ~S"""
Reads a Bitmap (24-bit) and displays width, height, and the RGB of each pixel
"""
def show(filename) do
{:ok, bindata} = File.read(filename)
<< "BM",
_::size(64),
offset_to_pixels::size(32)-little,
@bryanhunter
bryanhunter / Handy.exs
Created January 11, 2015 15:29
Growing bag of handy short functions and one-liners in Elixir
# Show all Pids on local node with at least one message queued in its mailbox
Process.list |> Enum.filter(&(Process.info(&1)[:message_queue_len] >0))
## Functional Track talks from NDC London 2014
### Wednesday 2014-12-3
* [F-Words - Functional Programming Terms With More Than Four Letters - Calvin Bottoms](http://www.ndcvideos.com/#/app/video/2191)
* [Reactive Game Development For The Discerning Hipster - Bodil Stokke](http://www.ndcvideos.com/#/app/video/2221)
* [Erlang Patterns Matching Business Needs -- Torben Hoffman](http://www.ndcvideos.com/#/app/video/2211)
* [Equivalence Classes, xUnit.net, FsCheck, Property-Based Testing -- Mark Seemann](http://www.ndcvideos.com/#/app/video/2291)
* [Functional programming design patterns -- Scott Wlaschin](http://www.ndcvideos.com/#/app/video/2311)
* [Write Your Own Compiler in 24 Hours -- Phillip Trelford](http://www.ndcvideos.com/#/app/video/2281)
# Copyright 2012 Erlware, LLC. All Rights Reserved.
#
# This file is provided to you under the Apache License,
# Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,