Skip to content

Instantly share code, notes, and snippets.

Paul Schoenfelder bitwalker

Block or report user

Report or block bitwalker

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View pattern.ex
defmodule Features do
use GenServer
@features [chat: true]
def enable(feature), do: GenServer.call(__MODULE__, {:toggle, feature, true})
def disable(feature), do: GenServer.call(__MODULE__, {:toggle, feature, false})
def enabled?(feature) do
case :ets.lookup(__MODULE__, feature) do
@bitwalker
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.
Overview:
- 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
bitwalker / Dockerfile
Created Sep 2, 2016
Release container image
View Dockerfile
FROM bitwalker/alpine-erlang:latest
MAINTAINER Paul Schoenfelder <paulschoenfelder@gmail.com>
ENV REFRESHED_AT=2016-06-21 \
HOME=/opt/app/ \
MIX_ENV=prod \
TERM=xterm \
APP=myapp \
APPVER=0.1.0
@bitwalker
bitwalker / Dockerfile
Last active Mar 12, 2017
Example Dockerfile for a release
View Dockerfile
FROM bitwalker/alpine-erlang:latest
MAINTAINER Paul Schoenfelder <paulschoenfelder@gmail.com>
ENV REFRESHED_AT=2016-06-21 \
HOME=/opt/app/ \
MIX_ENV=prod \
TERM=xterm \
REPLACE_OS_VARS=true
EXPOSE 5000
@bitwalker
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
bitwalker / run.sh
Created Jun 15, 2016 — forked from djo/run.sh
Handling of UNIX-signals in Erlang/Elixir is not supported, this script provides start-stop management with handling TERM signal for Docker installation.
View run.sh
#!/usr/bin/env bash
set -x
term_handler() {
echo "Stopping the server process with PID $PID"
erl -noshell -name "term@127.0.0.1" -eval "rpc:call('app@127.0.0.1', init, stop, [])" -s init stop
echo "Stopped"
}
trap 'term_handler' TERM INT
@bitwalker
bitwalker / config.ex
Created Jun 6, 2016
A nice config wrapper which allows using the {:system, "VAR"} convention comfortably
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.
View iptables.txt
[centos@ip-172-22-245-135 ~]$ sudo iptables -L -n -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
681K 129M ACCEPT all -- tun0 * 0.0.0.0/0 0.0.0.0/0 /* traffic from docker for internet */
743K 517M ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 multiport dports 4789 /* 001 vxlan incoming */
2825K 2958M ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
336 29457 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0
59589 3575K ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
1786 99404 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
6827 429K OS_FIREWALL_ALLOW all -- * * 0.0.0.0/0 0.0.0.0/0
@bitwalker
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])
@bitwalker
bitwalker / app.ex
Created Mar 23, 2016
A simple solution to executing code as part of a release
View app.ex
defmodule MyApp do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
:ok = handle_args!
children = []
Supervisor.start_link(children, strategy: :one_for_one, name: MyApp.Supervisor)
You can’t perform that action at this time.