Skip to content

Instantly share code, notes, and snippets.

View colin-nolan's full-sized avatar

Colin Nolan colin-nolan

View GitHub Profile
@colin-nolan
colin-nolan / pip-install-ansible.sh
Last active March 21, 2017 10:30
Install/Update Ansible from PyPi
# Install pip
apt-get install -y python-pip
# Install dependencies for cryptography (dependency of ansible)
apt-get install -y build-essential libssl-dev libffi-dev python-dev
# Install/Update Ansible
pip install -U ansible
# In Debian-world, cron.daily runs at a random time. This is an ansible task to
# change it to run at an hour specified by `cron_daily_time`.
- name: Change cron.daily to run at a specified time
become: yes
replace:
path: /etc/crontab
regexp: '(\S*[ \t])(\S*)([ \t].*cron\.daily)'
replace: '\g<1>{{ cron_daily_time }}\g<3>'
@colin-nolan
colin-nolan / kill-docker-machines.sh
Last active July 21, 2017 14:56
Force kills all Docker machines
docker-machine ls -q | while read machineName; do
docker-machine rm -f "$machineName"
done
@colin-nolan
colin-nolan / speed-checker.sh
Created September 16, 2017 16:23
Periodically logs the Internet speed (requires `speedcheck` CLI)
#!/bin/bash
set -euf -o pipefail
# Note: jitter is not removed
PERIOD_IN_SECONDS=3600
while true
do
# To install `speedtest`: `pip install speedtest-cli`
@colin-nolan
colin-nolan / install-git-subrepo.sh
Last active February 13, 2018 04:04
Install Git Subrepo
apt-get update \
&& apt-get install -y --no-install-recommends \
less \
git
git clone --depth=1 --branch=0.3.1 https://github.com/ingydotnet/git-subrepo.git /tmp/git-subrepo \
&& cd /tmp/git-subrepo \
&& make install \
&& cd - \
&& rm -rf /tmp/git-subrepo
@colin-nolan
colin-nolan / bottle_wrapper.py
Last active March 7, 2018 09:57
Wrapper for creating Python Bottle server applications
# Copyright (c) 2018 Genome Research Limited
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
@colin-nolan
colin-nolan / wsgi_server.py
Last active March 7, 2018 10:43
Controller for Python WSGI server
# Copyright (c) 2018 Genome Research Limited
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
@colin-nolan
colin-nolan / verify-blocks.sh
Created June 13, 2018 10:11
Verifies content addressed blocks in S3
s3Location="$1"
function verifyMd5 {
objectLocation="$1"
objectName="$(basename ${objectLocation})"
mc cat "${objectLocation}" \
| md5sum -c <(echo "${objectName} -") --status \
&& echo "${objectLocation} = OK" \
|| echo "${objectLocation} = BAD"
exit 0
@colin-nolan
colin-nolan / passenger-memory-over-time.py
Created June 18, 2018 11:11
Very quick plot of passenger instance memory usage over time
# Requires install of packages:
# - delta
# - leather
#
# Working with data written periodically to a file:
# `passenger-status --show=xml | python <(echo -e "import xmltodict\nimport json\nimport sys\nprint(json.dumps(xmltodict.parse(sys.stdin.read())))")`
import json
from collections import defaultdict
import leather
@colin-nolan
colin-nolan / get-contributed-github-repos.sh
Created June 25, 2018 11:37
Gets a list of GitHub repositories that a user has contributed to within the last 90 days
#!/usr/bin/env bash
#
# Note: there is a 300 event/90 day limit (https://developer.github.com/v3/activity/events/).
#
# Requires: jq curl sed grep
#
set -euf -o pipefail
GIT_USER=$1