Skip to content

Instantly share code, notes, and snippets.

@bryanhunter
bryanhunter / keybindings.json
Created Apr 20, 2018
VS Code User Settings
View keybindings.json
// 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 Mar 31, 2018
An example of property-based testing in Elixir 1.6
View ColorNameTest.exs
# 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 Nov 12, 2017
Union type with units of measure
View UnitsOfMeasure.fs
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>
View UnionTypes.fs
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 Nov 12, 2017
BangPipe - a really silly Elixir macro
View bangpipe.exs
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 Dec 14, 2016
F# script that connects to Phoenix channels
View HelloPhoenix.fsx
// 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 Jan 20, 2015
Example of Elixir and the bit-syntax to read a Bitmap image
View bumper.exs
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 Jan 11, 2015
Growing bag of handy short functions and one-liners in Elixir
View Handy.exs
# 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))
View ndclondon2014_fp_track
## 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)
View Makefile
# 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,