Skip to content

Instantly share code, notes, and snippets.

@jmehnle
jmehnle / cmdline
Last active November 29, 2017 22:45
Ansible handler not role-scoped
$ ansible-playbook -i localhost, -v playbook.yml
No config file found; using defaults
PLAY [all] *********************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [a : set_fact] ************************************************************
ok: [localhost] => {"ansible_facts": {"x": "foo"}, "changed": false}
@jmehnle
jmehnle / aws-kms-crypt
Created December 5, 2018 15:05
AWS KMS string encryption/decryption convenience wrapper
#!/bin/bash
self="${0##*/}"
guid_re='[0-9a-z]{8}-([0-9a-z]{4}-){3}[0-9a-z]{12}'
usage () {
echo "Usage:"
echo " ${self} [--profile AWS_PROFILE] encrypt [--encryption-context KEY=VALUE] KEY_ID PLAINTEXT"
echo " ${self} [--profile AWS_PROFILE] decrypt [--encryption-context KEY=VALUE] CIPHERTEXT_BASE64"

Keybase proof

I hereby claim:

  • I am jmehnle on github.
  • I am jmehnle (https://keybase.io/jmehnle) on keybase.
  • I have a public key ASDGod8SxxGwWxPu851--Hu_pBwg1Rf7v7RygNtGUDJVdwo

To claim this, I am signing this object:

import gzip
import io
from typing import Iterator
class BytesReader:
def __init__(self, bytes_generator: Iterator) -> None:
self.bytes_generator = bytes_generator
self.buffer: bytes = b""
@jmehnle
jmehnle / README.md
Last active October 8, 2020 21:27
Python typing: mypy fails to match generic protocol class
(py3.7-typing-protocol) jbook:~/scratch> mypy --version
mypy 0.790+dev.7273e9ab1664b59a74d9bd1d2361bbeb9864b7ab
(py3.7-typing-protocol) jbook:~/scratch> mypy .
main.py:11: error: Type argument "pymysql.connections.Connection" of "DatabaseAdapter" must be a subtype of "pep249.Connection"
Found 1 error in 1 file (checked 2 source files)
(py3.7-typing-protocol) jbook:~/scratch> python
Python 3.7.9 (default, Sep  6 2020, 13:20:25)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
@jmehnle
jmehnle / pre_request.js
Last active December 1, 2021 01:11 — forked from dinvlad/pre_request.js
Auto-generate Google Access and ID tokens from a Service Account key and save it in Postman
/* This script auto-generates a Google OAuth token from a Service Account key,
* and stores that token in the "access_token" variable in Postman.
*
* Prior to invoking it, set the following variables in a Postman environment:
* - "service_account_key": the contents of your service account key.
* - "scope": a space-separated list of Google API scopes, e.g.:
* "https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.metadata"
*
* Then, paste this script into the "Pre-request Script" section
* of a Postman request or collection.