Skip to content

Instantly share code, notes, and snippets.

@thinktainer
thinktainer / azurekeys.sh
Created March 4, 2014 19:37
generate azure keys
# You may want to use another dir than /tmp
cd /tmp
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout azure-private.key -out azure-certificate.pem
chmod 600 azure-private.key azure-certificate.pem
openssl x509 -outform der -in azure-certificate.pem -out azure-certificate.cer
# Generate a keystore (azurekeystore.pkcs12)
# Transform private key to PEM format
openssl pkcs8 -topk8 -nocrypt -in azure-private.key -inform PEM -out azure-pk.pem -outform PEM
# Transform certificate to PEM format
module Seq =
let private spill (n:int) (s:seq<'a>) =
let en = s.GetEnumerator()
let pos = ref 0
let lst = [ while !pos < n && en.MoveNext() do
pos := !pos+1
yield en.Current]
if lst |> List.isEmpty then None else
Some((lst, seq { while en.MoveNext() do yield en.Current}))
@thinktainer
thinktainer / recursive-rename.ps1
Last active August 29, 2015 13:59
Recursive Rename Powershell
foreach($i in dir -Recurse -Include *.xml) {$parent = $i | Split-Path -Parent | Split-Path -leaf; $i | rename-item -newname {$parent + '.xml'}}
@thinktainer
thinktainer / install-plugin.sh
Created May 13, 2014 18:26
Install vagrant-fusion-plugin osx mavericks
export ARCHFLAGS="-arch x86_64"
NOKOGIRI_USE_SYSTEM_LIBRARIES=1 vagrant plugin install vagrant-vmware-fusion --verbose
@thinktainer
thinktainer / loadkeys.sh
Created May 14, 2014 09:34
load keymap centos
loadkeys dvorak

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:

@thinktainer
thinktainer / apiary.fsx
Created June 19, 2014 14:53
f# second session
open ApiaryProvider
let mdb = new ApiaryProvider<"themoviedb">("http://api.themoviedb.org")
mdb.AddQueryParam("api_key", ApiKey)
let query = "query", "craig"
let res = mdb.Search.Person(query=[query])
let totalPages = res.TotalPages
@thinktainer
thinktainer / odbc_config
Created September 19, 2014 20:46
missing odbc_config on ubuntu 14.04
#! /bin/sh
# This shell script saves various pieces of information about the
# installed version of unixODBC. Packages that interface to
# unixODBC can use it to configure their build.
# This file replaces the standard odbc_config, which is not
# relocatable
#
# Author: Alberto Di Meglio <alberto.di.meglio@cern.ch>
# Public domain
@thinktainer
thinktainer / dyingagent.fs
Last active August 29, 2015 14:06
an agent that dies
type EventPublisher (eventBus, logger) =
let agent eventBus (logger : ILoggingService) =
new Agent<EventAggregateMessage>(
fun inbox ->
let rec loop () = async {
let! message = inbox.Receive()
match message with
| EventAggregate aggregate ->
try
let playerId = aggregate.PlayerScope.PlayerId.ToString()