Skip to content

Instantly share code, notes, and snippets.

View amclain's full-sized avatar

Alex McLain amclain

View GitHub Profile
@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,
)
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)
# Binary search tree
defmodule Leaf do
@type t :: %__MODULE__{
value: integer,
left: t | nil,
right: t | nil
}
defstruct [:left, :right, :value]
@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
@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 / console_output.txt
Created February 17, 2015 23:22
REXML Line Feed Bug
Write Text: "bar"
Read Text: "\n bar\n "
XML String:
<root>
<foo>
bar
</foo>
</root>
(***********************************************************
Binary OR Bug
************************************************************)
PROGRAM_NAME = 'bor bug'
(***********************************************************)
(* System Type : NetLinx *)
(***********************************************************)
(* DEVICE NUMBER DEFINITIONS GO BELOW *)
(***********************************************************)
require 'ionian'
t1 = Time.now
puts t1
begin
s = Ionian::Socket.new host: '192.168.253.253:5000'
ensure
t2 = Time.now
puts t2
@amclain
amclain / dgx32 v1.2.312 firmware hotfix duet exceptions.txt
Created November 13, 2014 23:29
AMX DGX32 v1.2.312 firmware update fails to start AutoPatch Java servlet.
Line 1 (14:57:43):: Memory Available = 991723520 <204800>
Line 2 (14:57:43):: Memory Available = 991596544 <126976>
Line 3 (14:57:43):: Accepted connection:socket=120 addr=::ffff:10.30.50.62 port=33555
Line 4 (14:57:43):: Memory Available = 991567872 <28672>
Line 5 (14:57:43):: /opt/amx/javalib/jars/IntegratedApp/IntegratedApp.jar bundle matches flash file manifest
Line 6 (14:57:43):: starting /opt/amx/javalib/jars/IntegratedApp/IntegratedApp.jar bundle
Line 7 (14:57:43):: Service: Enova DGX iApp PHAL v1.2.1.15
Line 8 (14:57:43):: Memory Available = 991449088 <118784>
Line 9 (14:57:43):: TwinRivers:: Enova DGX Integrated Device Application v1.2.1.15
Line 10 (14:57:43):: Memory Available = 991342592 <106496>