Skip to content

Instantly share code, notes, and snippets.

@cboddy
cboddy / deploy.py
Created October 17, 2015 14:10
A simple, generalised app deploymeent script over SSH with up-start runtime-management.
from subprocess import Popen
import argparse, os, os.path, shutil
upstart_template = """
description "$NAME service runtime"
author "chris@boddy.im"
# Start on startup
@cboddy
cboddy / pre-commit
Last active December 3, 2019 00:09
pre-commit git hook for python projects to run autopep8 linter
#!/bin/bash
# run autopep8 linter on any python files that are part of the commit
# and modify them in-place to conform to pep8
git diff --cached --name-only | egrep '\.py$' | xargs --no-run-if-empty autopep8 -ri
# re-index files staged for commit
git diff --cached --name-only | egrep '\.py$'| xargs -l git add
@cboddy
cboddy / service-checklist.md
Created September 28, 2016 12:14 — forked from acolyer/service-checklist.md
Internet Scale Services Checklist

Internet Scale Services Checklist

A checklist for designing and developing internet scale services, inspired by James Hamilton's 2007 paper "On Desgining and Deploying Internet-Scale Services."

Basic tenets

  • Does the design expect failures to happen regularly and handle them gracefully?
  • Have we kept things as simple as possible?
@cboddy
cboddy / thunderbird_to_mutt.py
Created October 8, 2016 15:29
A script to parse a csv address-book export from thunderbird and create mutt-aliases for each contact.
"""parse a csv address-book export from thunderbird and create mutt-aliases for each contact"""
import csv
import collections
import argparse
Contact = collections.namedtuple("Contact", ["first", "last", "email"])
def line_to_contact(line):
"""return: Contact based on csv line"""

Keybase proof

I hereby claim:

  • I am cboddy on github.
  • I am cboddy (https://keybase.io/cboddy) on keybase.
  • I have a public key whose fingerprint is 42EC 5971 1C62 640B 1739 7F3C FC8C 3F6C C16B BCCA

To claim this, I am signing this object:

@cboddy
cboddy / print_cbor.sh
Last active June 17, 2018 10:14
A bash function to pretty print a file or cbor-encoded data.
#!/bin/bash
#
# add to ~/.bashrc or similar
#
# usage:
#
# > cbor_print /path/to/my/file.cbor
function cbor_print() {
# pretty print the contents of a file of cbor-encoded data
@cboddy
cboddy / with_logger.sh
Created June 30, 2018 09:08
Update a java project that is using System.{out,err} for logging to use java.util.logger.
# usage:
# ./with_logger.sh path_to_project_src
#
for f in `find $1 -type f -name \*java |xargs grep -l System.out`;
do
echo $f
# add import statement after package declaration
sed -i '0,/package.*/s//&\nimport java.util.logging.*;/' $f
# add Logger instance after class declaration
sed -i '0,/.*class [a-zA-Z]\+.*/s//&\n\tprivate static final Logger LOG = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);/' $f
@cboddy
cboddy / jscript.sh
Last active July 4, 2018 17:15
A utility for compiling and running a single file Java program (for scripting)
#!/bin/bash
# compile a java source file and run it
#
# two options:
# 1. Add to interactive environment
#
# > source jscript.sh.
# (or do the above in ~/.bashrc)
# to make the function jscript available eg.
# > jscript HelloWorld.java
@cboddy
cboddy / WTF_JAVAC.java
Created August 15, 2019 18:09
Javac Snafu
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class WTF_JAVAC {
private static final Map<String, String> MAP = new HashMap<>();
private static final String HELP = "\n"+ MAP.entrySet().stream()
.sorted()
.map(e -> {
String s = e.getKey() + "\t:\t" + e.getValue();
@cboddy
cboddy / uk_covid_tracker.py
Last active July 28, 2020 10:57
Get the historical cases by day for a UK region as used in coronavirus.data.gov.uk (that only displays the latest value for a region)
#!/usr/bin/env python3
import urllib.request
import json
import sys
import argparse
# Used in https://coronavirus.data.gov.uk
URL='https://c19downloads.azureedge.net/downloads/data/ltlas_latest.json'