Working through “Property Based Testing in PropEr with Erlang and Elixir” in Elixir – Part 2

I have returned to this book now that the book is out of beta.

I also started using a different repo:

The only difference between my code and the samples is that I am using the pipe syntax where possible. My Execism.IO background in Elixir is also forcing me to make style changes to keep the code in Elixir format.

Part 1 chapter 4 does use the erlang queue library. It would be good to be able to get Elixir documentation on erlang packages.

The part 2 sample code is broken but I am working on fixing in my repo.

It turned out to be easier to download the code from the pragprog site.

Designing Elixir Systems With OTP – Part Two

I have continued working through this beta book and have updated the github repo: with the samples.

So far this book is easier to follow than say Programming Phoenix since it does not keep changing the code that you are working on. The testing code is normally close to where you have typed it, so finding mistakes does not require too much effort. I would recommend using mix test after each code sample has been typed in as fixing errors can be tricky.

Note the only difference between my code and the supplied sample is the use of the british name Maths rather than Math for the sample code. My degree is in Mathematics so I can’t let a typo like that stand!

The main points from the second half of the book are the very clean validation techniques used. I like that they called the process returned by start_link a session.

The book currently stops at the end of chapter 6, so I will have to resume work on this series once it has been updated.

Designing Elixir Systems With OTP – Part One

These are my notes as I am working my way through this book from PragProg. I am reading a beta version of the book so things may change. I’ll be posting this to my github repo: (

The introduction starts by building a simple counter application as the domain and wraps it in a send/receive process with an API.

The code samples here are clean and clearly ordered. The only note that I have found so far is that I needed to delete the autogenerated Count.ex file to avoid a warning.

Takeaway from the intro: Supervisors are about lifecycles.

Takeaway from type introductions: Send the functions to the data!

Chapter 3 typo: response.ex is misspelt (reported).

excoveralls looks to be a better code coverage tool.

Essential Docker and Docker-Compose Commands

I spent some of today trying to work out why a Docker image that I was using did not work correctly.

This is the most useful command for debugging a docker image:

docker run -it ubuntu /bin/bash

This is based upon the ubuntu image but feel free to replace it with whatever you are trying to debug.

You can do the same with a docker-compose

docker-compose run --entrypoint /bin/bash

I am now looking at how to run a gradle build inside a docker container and then extract the log files. It will be especially useful to be able to view the log files. It may be possible to add a web server to view them.

It’s now also possible to stand up a Jenkins server on your dev machine to test Jenkinsfiles before deploying them to the build server.

docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts

Designing for Scalability with Erlang/OTP using Elixir – Part 2

Chapter 4

I am still working my way through this book.

The main difficulty that I am finding with chapter 4 is the scattered nature of the example code. It’s all small snippets, some of which references code in the previous chapter.

This is in addition to the Erlang => Elixir translations:

  • atom => :atom
  • VariableName => variable_name
  • moduleName => ModuleName

Some of the Elixir functions are reordered for consistency.

1> gen_server:start_link({local, timeout}, timeout, [], []).

1> c "Timeout.ex"
2> GenServer.start_link(Timeout, [], name: :timeout)
3>, {:sleep, 100})
4>, {:sleep, 5001})

The GenServer will by default timeout if a message takes more than 5 seconds to respond.

Samples for Chapter 4 have been pushed to with hash: cc8dd44

Chapter 5

The Erlang sys module can be reference from iex using :sys

The the log commands require atoms.

:sys.log(Frequency, :print)

:sys.log(Frequency, :get)

Now at hash: 830c1ea

Chapter 6

This is an odd chapter for Elixir as the Finite State Machine was considered defective and was not adapted as a wrapper. I am going to skip this chapter

Chapter 7

GenEvent has also been Deprecated

Designing for Scalability with Erlang/OTP using Elixir – Part 1

This is another of my book walk through series. This time I am working on Designing for Scalability with Erlang/OTP.

This is the book that goes into detail about OTP in general.

Chapter 2 : Introducing Erlang (edc0862)

The above is a repo with commit hash of where I have currently got to.

So far we have some basic recursion and some manual send/receive logic.

We have now seen the first use of ets – Erlang Term Storage a simple persistence layer.

Notes from Twitter

You build it you support it (even if not first line). It’s the other side of continuous delivery. You also need the right to fix anything that could wake you up. It focuses the developers minds to proper testing, logging, auditing and error handling. There is no wall.

Management frequently believes that the value of the advice is proportional to the cost. Also, knowledge gained outside an organisation is more valuable than that gained within.

Automate Your Life: Banking

I have been encouraging my team to automate everything.

To live by this principle I have started to automate my bank spreadsheet. I keep a spreadsheet with all of my banking transactions. This comes in handy should I need to investigate an old transaction. My current sheet covers the last 9 years. I had been manually copying the details over.

My bank allows statements to be exported as CSV files.

Here is a simple bash script that allows the data to be put into the format that I want:

cat filename.csv | awk -F, ‘{print $1 “,” $5 “,” $7 “,” $6 }’ | sed ‘1d’ | tail -r

I like the newest transactions at the bottom and credits before debits.

This becomes much easier to import into a google sheet rather than fighting with open office.

I have multiple current accounts and rebalance the main current account to a fixed amount at the end of each month. The remainder is moved into an offset mortgage. Credit card bills get paid (when due) from the mortgage account. This maximised the offset benefit.

How to Document Microservices

Here is a great article on using dot to document microservices:

I have forked and extended the gist to:

This is all you need to generate the below image from the above text:

dot -Tpng > architecture.png

You can even add annotations to the lines by adding [label=”My Link”] to the connection before.

These are ideal to add to the of github projects.

I especially like the idea of having a diagram with the source to create it under source control.

This requires you to install graphviz which can be done:

# Mac
brew install graphviz

# Windows
choco install graphviz

# Linux
sudo apt-get install graphviz

For the purists who want to keep their machines clean:

# Docker
cat | docker container run --rm -i vladgolubev/dot2png > file.png

How Jenkinsfiles Really Work

I only recently encountered the Jenkinsfile format. Previously I had used the clunky Jenkins UI or the cleaner Circle CI options.

Some of my colleagues had described it as using a special Groovy declarative syntax. It is in fact simply Groovy code using some neat tricks.

Groovy allows a closure (what other languages may call a lambda) to be used as a function parameter:

def block(Closure closure) {


This can then be used as follows:

block( { print (‘hello’) } )

Groovy allows the closure to be moved outside the brackets as a code block:

block() {

print ‘hello’


Here I have started to use the groovy trick of dropping brackets. In fact you can also drop the leading brackets:

block {

print ‘hello’


This is beginning to look like the pipeline or stage steps from a Jenkinsfile.

You can even add parameters:

def wrap(marker, Closure closure{

println marker

println marker


// Which can be used as:

wrap (‘name’) {

// something …


Jenkinsfiles are code pretending to be config, with the added benefit of being able to become code again when needed.