Skip to content

Instantly share code, notes, and snippets.

View amclain's full-sized avatar

Alex McLain amclain

View GitHub Profile
@amclain
amclain / keybase.md
Last active November 19, 2017 23:48

Keybase proof

I hereby claim:

  • I am amclain on github.
  • I am amclain (https://keybase.io/amclain) on keybase.
  • I have a public key whose fingerprint is 7F55 1929 3940 7EEE F65F F628 7C6A BF67 0F73 7AD9

To claim this, I am signing this object:

@amclain
amclain / gen_statem_turnstyle.ex
Last active July 1, 2020 22:29
A simple Elixir experiment with the OTP state machine gen_statem
defmodule Turnstyle do
@moduledoc """
This state machine emulates a turnstyle gate that has a rotating bar
and a coin slot. If the gate is locked a coin must be inserted to unlock
it, and then the bar will rotate to let you through when it is pushed.
The bar will then lock back in position.
"""
@behaviour :gen_statem
# Binary search tree
defmodule Leaf do
@type t :: %__MODULE__{
value: integer,
left: t | nil,
right: t | nil
}
defstruct [:left, :right, :value]
defmodule MergeSort do
@spec sort([number]) :: [number]
def sort(list) do
case Enum.count(list) do
0 -> list
1 -> list
_ ->
midpoint = Enum.count(list) / 2 |> ceil()
{head_list, tail_list} = Enum.split(list, midpoint)
@amclain
amclain / emqtt.ex
Last active December 19, 2023 16:35
# Connect and subscribe
def init(_args) do
Logger.info "Starting emqtt..."
{:ok, pid} = :emqtt.start_link(
clientid: "emqtt",
host: 'localhost',
# clean_start: false,
)