Skip to content

Instantly share code, notes, and snippets.

View schmohlio's full-sized avatar

Matthew Schmohl schmohlio

View GitHub Profile
@schmohlio
schmohlio / gist:4157d2fa82f3680fd08f1b111ed61515
Created April 10, 2017 03:16 — forked from mikepfeiffer/gist:4d9386afdcceaf29493a
EC2 UserData script to install CodeDeploy agent
#!/bin/bash
yum install -y aws-cli
cd /home/ec2-user/
aws s3 cp 's3://aws-codedeploy-us-east-1/latest/codedeploy-agent.noarch.rpm' . --region us-east-1
yum -y install codedeploy-agent.noarch.rpm
@schmohlio
schmohlio / BlockingQueue.java
Created February 16, 2017 05:04 — forked from dougnukem/BlockingQueue.java
Example Threadsafe BlockingQueue implementation in Java
public class BlockingQueue implements Queue {
private java.util.Queue queue = new java.util.LinkedList();
/**
* Make a blocking Dequeue call so that we'll only return when the queue has
* something on it, otherwise we'll wait until something is put on it.
*
* @returns This will return null if the thread wait() call is interrupted.
*/
@schmohlio
schmohlio / sse.go
Last active February 13, 2023 08:38 — forked from ismasan/sse.go
Example SSE server in Golang
// v2 of the great example of SSE in go by @ismasan.
// includes fixes:
// * infinite loop ending in panic
// * closing a client twice
// * potentially blocked listen() from closing a connection during multiplex step.
package main
import (
"fmt"
"log"
@schmohlio
schmohlio / EventMachines.md
Created January 8, 2016 16:19 — forked from eulerfx/EventMachines.md
The relationship between state machines and event sourcing

A state machine is defined as follows:

  • Input - a set of inputs
  • Output - a set of outputs
  • State - a set of states
  • S0 ∈ S - an initial state
  • T : Input * State -> Output * State - a transition function

If you model your services (aggregates, projections, process managers, sagas, whatever) as state machines, one issue to address is management of State. There must be a mechanism to provide State to the state machine, and to persist resulting State for subsequent retrieval. One way to address this is by storing State is a key-value store. Another way is to use a SQL database. Yet another way is event sourcing. The benefit of even sourcing is that you never need to store State itself. Instead, you rely on the Output of a service to reconstitute state. In order to do that, the state machine transition function needs to be factored into two functions as follows: