Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / r15b03-on-raspbian1212.sh
Last active May 20, 2017 11:29
Builds Erlang R15B03 from source on the Raspberry Pi. Tested on the 2012-12-16 build of Raspbian (Wheezy)
#!/bin/bash
# Pull this file dowm, make it executable and run it with sudo
# wget https://gist.github.com/raw/4361444/r15b03-on-raspbian1212.sh
# chmod u+x r15b03-on-raspbian1212.sh
# sudo ./r15b03-on-raspbian1212.sh
if [ $(id -u) != "0" ]; then
echo "You must be the superuser to run this script" >&2
exit 1
fi
@bryanhunter
bryanhunter / .emacs
Created June 7, 2014 18:50
Emacs setup for Erlang developement
;; Where is Erlang on this machine?
(if (not (boundp 'erlang-root-dir))
(cond
((or (eq system-type 'windows-nt)(eq system-type 'ms-dos))
(setq erlang-root-dir "C:/bin/erlang/erl5.9")) ;; Windows
((eq system-type 'darwin)
(setq erlang-root-dir "/usr/local/lib/erlang")) ;; Mac
((eq system-type 'gnu/linux)
(setq erlang-root-dir "/usr/local/lib/erlang")) ;; Linux
)
@bryanhunter
bryanhunter / CaliburnMicroConventionsForActipro.cs
Created March 12, 2012 16:40
Caliburn.Micro conventions for Actipro controls
using ActiproSoftware.Windows.Controls.Ribbon.Controls;
using ActiproSoftware.Windows.Controls.Ribbon.Controls.Primitives;
using Caliburn.Micro;
namespace SampleApp
{
public static class CaliburnMicroConventionsForActipro
{
public static void AddConventions()
{
@bryanhunter
bryanhunter / install-r14b03.sh
Created May 25, 2011 19:28
Script to install Erlang 14B03 (tested on a fresh Ubuntu 11.04 install)
# You will need to make this file executable (chmod u+x) and run it with sudo
apt-get -y install build-essential m4 libncurses5-dev libssh-dev unixodbc-dev libgmp3-dev libwxgtk2.8-dev libglu1-mesa-dev fop xsltproc default-jdk
mkdir -p /src/erlang
cd /src/erlang
wget http://www.erlang.org/download/otp_src_R14B03.tar.gz
tar -xvzf otp_src_R14B03.tar.gz
chmod -R 777 otp_src_R14B03
cd otp_src_R14B03
./configure
make
@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 / CastleBootstrapper.cs
Created August 5, 2011 16:29
Castle bootstrapper for Caliburn.Micro
// Hooks up Castle Windsor as the container for your Caliburn.Micro application.
// Turns on support for delegate factory methods (e.g. passing the factory "Func<XyzEditViewModel>" as a constructor arg)
// Dependencies: In addition to Caliburn.Micro you will need to reference Castle.Core and Castle.Windsor
public class CastleBootstrapper<TRootViewModel> : Bootstrapper<TRootViewModel>
{
private ApplicationContainer _container;
protected override void Configure()
{
@bryanhunter
bryanhunter / ndc-oslo-2014.md
Last active April 10, 2016 11:40
NDC Oslo 2014 - FP Cheat Sheet

#The Functional Programmers Cheat Sheet for NDC Oslo 2014

This year NDC Oslo has a full three-day functional programming track with an amazing lineup. If you agree that the future of programming is FP, use this as your "auto pilot" guide on what sessions to attend.

Cheer for sessions on Twitter using the #ndcoslo and #fptrack hashtags.

[The full agenda (including non-fp sessions) is here].