Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import os
import sys
from itertools import product
from random import sample
def load(filename):
with open(filename) as fd:
return filter(lambda x:x, map(lambda x:x.strip(), fd.readlines()))
@cmattoon
cmattoon / git_move.sh
Created September 28, 2017 03:34
git-prev-next
#!/bin/bash
# Provides 'git-prev' and 'git-next' commands for git
# to facilitate browsing step-by-step
# Run "source git_move.sh" to activate commands
_git_next() {
git log --reverse --pretty=%H master | \
#!/bin/bash
if [ $EUID != 0 ]; then
echo "You must be root"
exit 1;
fi
# Installs Docker on Ubuntu 14.04
apt-get update && apt-get -y install \
apt-transport-https \
ca-certificates \
@cmattoon
cmattoon / PrettyPrintTable.py
Created December 10, 2017 20:26
Python - Pretty-Print Tabular Data
#!/usr/bin/env python3
from typing import List
def ptable(data : List[List], sep : str = "\t", sort_by : int = None):
"""
Pretty-prints a table
Args:
data (list): A list of lists where data[0] = the first row
sep (str): Default "\t" - the separator to use
sort_by (int): Default None - the column index to sort by
#!/bin/bash
# 0 * * * * /usr/local/bin/docker-cleanup.cron.sh > /var/log/docker-cleanup.log 2> /var/log/docker-cleanup.err.log
cleanup_images() {
echo "Cleaning up images"
docker rmi -f $(docker images -af dangling=true -q)
}
cleanup_containers() {
echo "Cleaning up containers"
@cmattoon
cmattoon / k8s-svc-annotations.md
Created January 23, 2018 22:04 — forked from mgoodness/k8s-svc-annotations.md
AWS ELB-related annotations for Kubernetes Services (v1.5)
  • service.beta.kubernetes.io/aws-load-balancer-access-log-emit-interval (in minutes)
  • service.beta.kubernetes.io/aws-load-balancer-access-log-enabled (true|false)
  • service.beta.kubernetes.io/aws-load-balancer-access-log-s3-bucket-name
  • service.beta.kubernetes.io/aws-load-balancer-access-log-s3-bucket-prefix
  • service.beta.kubernetes.io/aws-load-balancer-backend-protocol (http|https|ssl|tcp)
  • service.beta.kubernetes.io/aws-load-balancer-connection-draining-enabled (true|false)
  • service.beta.kubernetes.io/aws-load-balancer-connection-draining-timeout (in seconds)
@cmattoon
cmattoon / fission_router_config.sh
Created February 21, 2018 15:42
Configure Fission Router
#!/bin/bash
# fission.io router config for CoreOS
# v0.1.0
#
# Usage:
# source fission_router_config.sh
# Or:
# eval $(./fission_router_config.sh)
ports=$(kubectl -n fission get svc | grep -e 'controller\|router' | cut -d: -f 2 | cut -d/ -f 1 | xargs echo)
"""
Allows one to handle *args and **kwargs together in an intuitive way:
api.create_thing('my-thing', 'property-1', 'property-2')
or
api.create_thing('my-thing', prop2='property-2')
or
api.create_thing(**config)
@cmattoon
cmattoon / conf--app.conf
Created July 11, 2018 23:53
dir2cm example
[app]
config_value = true
[db]
host = localhost
port = 1234
user = root
pass = toor
@cmattoon
cmattoon / route_tables.py
Created September 7, 2018 21:34
Graph AWS Route Tables
#!/usr/bin/env python
"""
./route_tables.py | dot -Tpng > routes.png
"""
import boto3
def get_tag(obj, key, default=''):
for tag in obj['Tags']:
if tag['Key'] == key:
return tag['Value']