Skip to content

Instantly share code, notes, and snippets.


Paul Schoenfelder bitwalker

View GitHub Profile
bitwalker / Option.cs
Created Jul 11, 2014
Implementation of Option<T> in C#
View Option.cs
using System;
namespace Types
public static class Option
public static Option<T> ToOption<T>(this T @this)
if (@this == null)
return Option<T>.None;
bitwalker / convert.sql
Created Apr 16, 2014
Convert a hex-encoded string to varbinary - MSSQL
View convert.sql
declare @hexstring varchar(max)
declare @bin varbinary(max)
set @hexstring = '0x10.....'
set @bin = (
select cast('' as xml).value('xs:hexBinary(substring(sql:variable("@hexstring"), sql:column("t.pos")))', 'varbinary(max)')
from (select case substring(@hexstring, 1, 2) when '0x' then 3 else 0 end) as t(pos)
select @bin
bitwalker / config.ex
Created Jul 19, 2016
Useful config wrapper for Elixir
View config.ex
defmodule Config do
@moduledoc """
This module handles fetching values from the config with some additional niceties
@doc """
Fetches a value from the config, or from the environment if {:system, "VAR"}
is provided.
An optional default value can be provided if desired.
bitwalker /
Created Mar 17, 2016 — forked from pnc/
Using Erlang observer/appmon remotely

Using OTP's observer (appmon replacement) remotely

$ ssh remote-host "epmd -names"
epmd: up and running on port 4369 with data:
name some_node at port 58769

Note the running on port for epmd itself and the port of the node you're interested in debugging. Reconnect to the remote host with these ports forwarded:

$ ssh -L 4369:localhost:4369 -L 58769:localhost:58769 remote-host
bitwalker / len.ex
Created Mar 29, 2016
How a body recursive function expands in Elixir
View len.ex
# This is our function definition,
# It is body (not tail) recursive, as it must wait for
# len(tail) to return before the addition can be performed
# on each iteration
def len([]), do: 0
def len([head | tail]), do: 1 + len(tail)
# If we call len([1, 2, 3]), this is what happens
len([1, 2, 3]) == 1 + len([2, 3])
len([2, 3]) == 1 + len([3])
View pattern.ex
defmodule Features do
use GenServer
@features [chat: true]
def enable(feature), do:, {:toggle, feature, true})
def disable(feature), do:, {:toggle, feature, false})
def enabled?(feature) do
case :ets.lookup(__MODULE__, feature) do
bitwalker / howto.txt
Created Oct 14, 2016
Deploying releases within containers
View howto.txt
This is not meant to be comprehensive, a guide, or anything quite that sophisticated, just a couple
notes on what I do at work, in production, and how my environment is set up.
- Infrastructure runs on AWS
- We run an internal PaaS based on OpenShift Origin/Kubernetes
- We push code to GitHub, which triggers a webhook, which in turn
triggers OpenShift to start a build, which fetches the source
code, and runs the build using the Dockerfile contained in the
bitwalker / Dockerfile
Last active Mar 12, 2017
Example Dockerfile for a release
View Dockerfile
FROM bitwalker/alpine-erlang:latest
MAINTAINER Paul Schoenfelder <>
ENV REFRESHED_AT=2016-06-21 \
HOME=/opt/app/ \
MIX_ENV=prod \
TERM=xterm \
bitwalker / Dockerfile
Created Sep 2, 2016
Release container image
View Dockerfile
FROM bitwalker/alpine-erlang:latest
MAINTAINER Paul Schoenfelder <>
ENV REFRESHED_AT=2016-06-21 \
HOME=/opt/app/ \
MIX_ENV=prod \
TERM=xterm \
APP=myapp \
bitwalker /
Created Jun 15, 2016 — forked from djo/
Handling of UNIX-signals in Erlang/Elixir is not supported, this script provides start-stop management with handling TERM signal for Docker installation.
#!/usr/bin/env bash
set -x
term_handler() {
echo "Stopping the server process with PID $PID"
erl -noshell -name "term@" -eval "rpc:call('app@', init, stop, [])" -s init stop
echo "Stopped"
trap 'term_handler' TERM INT