Skip to content

Instantly share code, notes, and snippets.

View adamchainz's full-sized avatar
🍐
I like pears.

Adam Johnson adamchainz

🍐
I like pears.
View GitHub Profile
@adamchainz
adamchainz / logentries-messages-userscript.js
Created December 15, 2014 14:23
Highlight 'messages' text on logentries
// ==UserScript==
// @name Highlight 'messages' text on logentries
// @namespace http://adamj.eu/
// @version 0.1
// @author me@adamj.eu
// @match https://logentries.com/app/*
// @grant none
// ==/UserScript==
var highlightMessageKey = function () {
@adamchainz
adamchainz / patchy.patch
Created February 24, 2015 18:57
Django support update limit
From 8be1f398dfca15c45d34967edfc72fc951ec0cb1 Mon Sep 17 00:00:00 2001
From: Adam Chainz <adam@adamj.eu>
Date: Tue, 24 Feb 2015 18:56:47 +0000
Subject: [PATCH] Support delete limit
---
django/db/models/query.py | 4 ++--
django/db/models/sql/compiler.py | 2 ++
tests/update/tests.py | 13 +++++++++++--
3 files changed, 15 insertions(+), 4 deletions(-)
@adamchainz
adamchainz / hybrid.py
Created March 2, 2015 16:03
Context Manager/function/unittest class decorator hybrid
import functools
import types
class fixit(object):
"""
Context manager that can also be used as a function decorator or class decorator for unittest classes.
"""
def __init__(self, **kwargs):
self.kwargs = kwargs
@adamchainz
adamchainz / my_filters.py
Created March 25, 2015 23:10
Ansible Jinja2 filters for deleting anonymous ec2 instances
import datetime as dt
import time
import unittest
def aws_age_seconds(ec2_launch_time):
"""
Parse the ec2 launch time string and return how old it is in seconds.
"""
# Strip trailing subsecond part
@adamchainz
adamchainz / iam.py
Created May 14, 2015 14:43
Ansible IAM modules
#!/usr/bin/python
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@adamchainz
adamchainz / test.yml
Created May 23, 2015 16:45
Ansible template a variable
- hosts: 127.0.0.1
connection: local
gather_facts: no
tasks:
- set_fact:
my_templated_var: |
{
{% for key in ["foo", "bar"] %}
"{{ key }}": 1,
{% endfor %}

Keybase proof

I hereby claim:

  • I am adamchainz on github.
  • I am adamchainz (https://keybase.io/adamchainz) on keybase.
  • I have a public key whose fingerprint is 9131 6924 A46C 570B 077D 8CD1 EC71 25C9 3488 3BE5

To claim this, I am signing this object:

import subprocess
import requests
def print_all_non_wheels():
output = subprocess.check_output(['pip', 'freeze']).decode()
lines = [l.strip() for l in output.split('\n') if l.strip()]
for line in lines:
@adamchainz
adamchainz / ses_hash.py
Created November 23, 2016 16:46
SES credentials hash
"""
Implements the algorithm at https://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html
"""
import hmac
import hashlib
import base64
def ses_hash(secret_access_key):
message = "SendRawEmail"
@adamchainz
adamchainz / user.js
Last active June 1, 2017 13:26
GitHub Squash and Merge PR fixer
// ==UserScript==
// @name GitHub Squash and Merge PR fixer
// @namespace https://github.com/
// @version 1.0
// @description try to take over the world!
// @author Adam Johnson
// @match https://github.com/*
// @grant all
// ==/UserScript==