Skip to content

Instantly share code, notes, and snippets.

View cmattoon's full-sized avatar

Curtis Mattoon cmattoon

View GitHub Profile
#!/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 / 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
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 / 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 | \
#!/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 / status
Created July 7, 2017 21:24
mock_status
The application is running
@cmattoon
cmattoon / Dockerfile
Created June 30, 2017 21:09
named-checkzone Docker image
FROM alpine:3.6
RUN apk update && apk add --no-cache bind
VOLUME ["/data"]
WORKDIR /data
ENTRYPOINT ["/usr/sbin/named-checkzone"]
@cmattoon
cmattoon / carrotland.py
Last active June 18, 2017 02:45
Google foo.bar - Carrotland
"""
* Carrotland
* ==========
*
* The rabbits are free at last, free from that horrible zombie science experiment. They need a happy, safe home, where they can recover.
*
* You have a dream, a dream of carrots, lots of carrots, planted in neat rows and columns! But first, you need some land. And the only person who's selling land is Farmer Frida. Unfortunately, not only does she have only one plot of land, she also doesn't know how big it is - only that it is a triangle. However, she can tell you the location of the three vertices, which lie on the 2-D plane and have integer coordinates.
*
* Of course, you want to plant as many carrots as you can. But you also want to follow these guidelines: The carrots may only be planted at points with integer coordinates on the 2-D plane. They must lie within the plot of land and not on the boundaries. For example, if the vertices were (-1,-1), (1,0) and (0,1), then you can plant only one carrot at (0,0).
*
#!/usr/bin/env python
"""
Creates a list of hosts from a CSV export of nodes
Usage: ./check_pe_csv path/to/csvfile
"""
import csv
import os
import sys
@cmattoon
cmattoon / init.sh
Last active June 12, 2017 12:03
Init.sh
#!/bin/bash
# wget <raw_url>
# chmod +x init.sh
# ./init.sh
if [ "${EUID}" != "0" ]; then
echo "You must be root"
exit 1;
fi