Skip to content

Instantly share code, notes, and snippets.

View bitwalker's full-sized avatar

Paul Schoenfelder bitwalker

View GitHub Profile
@bitwalker
bitwalker / Option.cs
Created July 11, 2014 20:32
Implementation of Option<T> in C#
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
bitwalker / convert.sql
Created April 16, 2014 20:43
Convert a hex-encoded string to varbinary - MSSQL
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
bitwalker / run.sh
Created June 15, 2016 20:57 — 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.
#!/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
[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 / config.ex
Created July 19, 2016 23:00
Useful config wrapper for Elixir
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 / observer.md
Created March 17, 2016 16:09 — forked from pnc/observer.md
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
bitwalker / len.ex
Created March 29, 2016 17:34
How a body recursive function expands in Elixir
# 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])
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 October 14, 2016 02:35
Deploying releases within containers
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
Last active March 12, 2017 03:25
Example Dockerfile for a release
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