Skip to content

Instantly share code, notes, and snippets.

View gmr's full-sized avatar
:octocat:
🐘 🐇 🐍

Gavin M. Roy gmr

:octocat:
🐘 🐇 🐍
View GitHub Profile
@gmr
gmr / 1-example.py
Last active June 4, 2019 22:25
Example usage of pgdumplib to read data from a pg_dump file
import pgdumplib
dump = pgdumplib.load('build/data/dump.compressed')
print('# Header: {}'.format(dump.toc.header))
print('# Database: {}'.format(dump.toc.dbname))
print('# Archive Timestamp: {}'.format(dump.toc.timestamp))
print('# Server Version: {}'.format(dump.toc.server_version))
print('# Dump Version: {}'.format(dump.toc.dump_version))
import gzip
import requests
r = requests.get('http://data.dot.state.mn.us/iris_xml/incident.xml.gz')
with open('incident.xml', 'w') as handle:
handle.write(gzip.decompress(r.content).decode('utf-8'))
@gmr
gmr / s3-strip-object-tags.py
Created August 29, 2018 17:33
Small Python CLI application for removing any object tags from all objects in a bucket
#!/usr/bin/env python3
import argparse
import logging
import sys
import boto3
LOGGER = logging.getLogger(__name__)
@gmr
gmr / 0-auto-manged-chef-repo.md
Last active February 8, 2018 22:45
This gist has files that are used to automate chef repository submodules used for roles, data bags, cookbooks and environments, ultimately uploading the maintained chef repository to chef via knife using Jenkins and Github.

The files in this gist are for having Jenkins automatically manage a chef repository using git submodules. This allows for clean, clutter free management of individual cookbooks, and individual respositories for roles, environments and data bags in our chef-repo.

The process relies on using Github (we use Github Enterprise) and Jenkins in combination with the Jenkins Github plugin to notify Jenkins when a repository has changed.

Our chef-repo directory looks something like:

chef-repo
    - cookbooks
          - Each cookbook is a git submodule managed by Jenkins
    - data_bags (git submodule managed by Jenkins)
@gmr
gmr / table_sizes.sql
Last active February 6, 2018 00:46
A PostgreSQL view that combines the relation size, the size of its indexes, the size of its toast table, and the size of the toast table indexes, combines them to give you a total table size.
CREATE OR REPLACE VIEW public.table_sizes AS
WITH tables AS (
SELECT a.oid, b.nspname, a.relname, a.reltoastrelid, pg_relation_size(a.oid) AS size
FROM pg_class AS a
JOIN pg_namespace AS b ON b.oid = a.relnamespace
WHERE a.relkind = 'r'
AND b.nspname NOT IN ('pg_catalog', 'information_schema')),
indexes AS (
SELECT i.oid, n.nspname, i.relname AS idxname, c.oid AS reloid, c.relname AS relname,
pg_relation_size(i.oid) AS size
@gmr
gmr / gist:3c28c9e3a71f5ef9fd83f1867fa6f11f
Created January 23, 2018 19:11
execute time per 10k chunk
Time: 3198.725 ms (00:03.199)
Time: 6887.960 ms (00:06.888)
Time: 10622.234 ms (00:10.622)
Time: 13110.130 ms (00:13.110)
Time: 21388.449 ms (00:21.388)
Time: 24127.707 ms (00:24.128)
Time: 28515.858 ms (00:28.516)
Time: 32666.766 ms (00:32.667)
2017/11/29 14:20:09.628249 [INFO] envconsul v0.7.2 (a508c43)
2017/11/29 14:20:09.629523 [INFO] (runner) creating new runner (once: false)
2017/11/29 14:20:09.630590 [DEBUG] (runner) final config: {"Consul":{"Address":"127.0.0.1:8500","Auth":{"Enabled":false,"Username":"","Password":""},"Retry":{"Attempts":12,"Backoff":1000000000,"MaxBackoff":120000000000,"Enabled":true},"SSL":{"CaCert":"","CaPath":"","Cert":"","Enabled":false,"Key":"","ServerName":"","Verify":true},"Token":"","Transport":{"DialKeepAlive":30000000000,"DialTimeout":30000000000,"DisableKeepAlives":false,"IdleConnTimeout":90000000000,"MaxIdleConns":100,"MaxIdleConnsPerHost":2,"TLSHandshakeTimeout":10000000000}},"Exec":{"Command":"/usr/local/bin/test-script.sh","Enabled":true,"Env":{"Blacklist":[],"Custom":["CUSTOM_ENV_VAR=FOUND","PATH=$PATH:/etc/myapp/bin"],"Pristine":false,"Whitelist":[]},"KillSignal":15,"KillTimeout":5000000000,"ReloadSignal":null,"Splay":5000000000,"Timeout":0},"KillSignal":2,"LogLevel":"debug","MaxStale":60000000000,"PidFile"
@gmr
gmr / example.vcl
Last active September 21, 2017 18:39
director autodirector_ random {
{
.backend = F_us_east_1_assets_aweberstage_com;
.weight = 100;
}{
.backend = F_us_west_1_assets_aweberstage_com;
.weight = 100;
}
}
@gmr
gmr / rmq-sorted-definitions.py
Created March 24, 2017 19:14
Script for dumping RabbitMQ definitions with deterministic sorting
#!/usr/bin/env python3
import argparse
import json
import requests
import sys
def dict_list_key(item):
if 'vhost' in item and 'name' in item:
return item['vhost'], item['name']
@gmr
gmr / whisper-sync.py
Last active January 12, 2017 13:14
Load missing datapoints on a remote graphite instance from the WHISPER_DIR on a graphite instance. Use threads to allow for multiple files to be processed at the same time to improve throughput.
#!/usr/bin/env python
import logging
import os
import random
import requests
import socket
import sys
import threading
import time
import whisper