Skip to content

Instantly share code, notes, and snippets.

@paul-butcher
paul-butcher / example
Last active November 29, 2018 12:03
mypy warnings plugin
myproj/performance_utils.py: note: In class "timeit":
myproj/performance_utils.py:18: error: Need type annotation for 'call_counts'
@paul-butcher
paul-butcher / gist:44c43431e3caa1b2a08c9d8f9b714eb8
Created August 15, 2018 13:46
Get the current time in ISO 8601 in painless
ZonedDateTime.ofInstant(Instant.ofEpochMilli(ctx._now), ZoneId.of("Z"))
@paul-butcher
paul-butcher / profileit.py
Created July 17, 2018 08:48
profiling decorator
import cProfile
import pstats
def profileit(limit=30):
def inner_profileit(func):
def wrapper(*args, **kwargs):
prof = cProfile.Profile()
retval = prof.runcall(func, *args, **kwargs)
@paul-butcher
paul-butcher / da.md
Created July 15, 2018 21:14
pandoc template for art gallery style walltext.

artist: gunderson author: paul medium: Acrylic on board date: July 2018 title: D.A. ...

In a sparse landscape, a single willow stands on the edge of a lake at sunset

@paul-butcher
paul-butcher / Makefile
Created June 7, 2018 09:29
Makefile for building plantuml diagrams
# This makefile is expected to run in a folder full of plantuml diagrams in
# files called *.uml.txt
# It will output those diagrams as png files into a subfolder called 'diagrams'
.PHONY: diagrams
DIAGRAM_SOURCES = $(wildcard *.uml.txt)
# plantuml based diagrams:
diagrams/%.uml.png: %.uml.txt
plantuml $< -o ./diagrams
@paul-butcher
paul-butcher / check_connection.groovy
Created January 23, 2018 12:20
Jenkins pipeline to check the ability to connect to a set of hosts.
def transformIntoStage(host_name, environment) {
return {
stage(environment + host_name.tokenize(".")[0]​) {
sshagent(credentials: ['my_key']) {
sh "ssh my_user@${host_name} 'whoami'"
}
}
}
}
@paul-butcher
paul-butcher / safe_tasks.py
Created August 29, 2017 13:26
Ensuring that an ansible task has no remote side-effects
from ansible.plugins.callback import CallbackBase
from ansible.errors import AnsibleParserError
def is_marked_safe(task):
return 'check_vars' in task.tags
def is_local(task):
"""
@paul-butcher
paul-butcher / pause.yml
Created August 29, 2017 09:18
An Ansible play that adds an extra hurdle before deploying to production.
### Request confirmation
# As a safeguard against accidentally running a playbook against production,
# This play pauses for confirmation if the play is being run without any tags.
# The three ways to bypass this pause are:
#
# * Run on a non-production environment
# * Supply a tag (e.g. --tag=check_vars (See https://t37.net/documenting-your-ansible-roles-interface-and-making-other-people-s-life-easier.html))
# * Supply an extra var jfdi: (-e jfdi=True)
#
@paul-butcher
paul-butcher / example
Last active November 26, 2018 14:45
Generating pyup safety reports in the Jenkins Warnings plugin https://pyup.io/safety/
╒══════════════════════════════════════════════════════════════════════════════╕
│ │
│ /$$$$$$ /$$ │
│ /$$__ $$ | $$ │
│ /$$$$$$$ /$$$$$$ | $$ \__//$$$$$$ /$$$$$$ /$$ /$$ │
│ /$$_____/ |____ $$| $$$$ /$$__ $$|_ $$_/ | $$ | $$ │
│ | $$$$$$ /$$$$$$$| $$_/ | $$$$$$$$ | $$ | $$ | $$ │
│ \____ $$ /$$__ $$| $$ | $$_____/ | $$ /$$| $$ | $$ │
│ /$$$$$$$/| $$$$$$$| $$ | $$$$$$$ | $$$$/| $$$$$$$ │
│ |_______/ \_______/|__/ \_______/ \___/ \____ $$ │
@paul-butcher
paul-butcher / example
Created March 1, 2017 11:17
Generating ansible-review reports in the Jenkins Warnings plugin
WARN: Best practice "YAML should be correctly indented" not met:
roles/mysql_server/tasks/main.yml:5: lines starting with '- ' should have same or less indentation than previous line
WARN: Best practice "Don't compare to "" - use `when: var` or `when: not var`" not met:
roles/mysql_server/tasks/main.yml:5: [EXTRA0015] Don't compare to empty string
WARN: Best practice "Python code should pass flake8" not met:
./templates/mytemplate.py:28: ./templates/mytemplate.py:28:11: E201 whitespace after '{'