Electricmonk

Ferry Boender

Programmer, DevOpper, Open Source enthusiast.

Blog

Category: python

An Ansible safeguard

At my work, we use ansible to provision all kinds of things, from servers to monitoring. Ansible is very powerful, but with great power comes great responsibility. One downside of automating many things with ansible is that you could also accidentally destroy a lot of things with a single wrong command. In a perfect world […]

SSL/TLS client certificate verification with Python v3.4+ SSLContext

Normally, an SSL/TLS client verifies the server’s certificate. It’s also possible for the server to require a signed certificate from the client. These are called Client Certificates. This ensures that not only can the client trust the server, but the server can also trusts the client. Traditionally in Python, you’d pass the ca_certs parameter to the […]

Lurch: a unixy launcher and auto-typer

I cobbled together a unixy command / application launcher and auto-typer. I’ve dubbed it Lurch. Features: Fuzzy filtering as-you-type. Execute commands. Open new browser tabs. Auto-type into currently focussed window Auto-type TOTP / rfc6238 / two-factor / Google Authenticator codes. Unixy and composable. Reads entries from stdin. You can use and combine these features to […]

Understanding Python’s logging module

I’m slightly embarrassed to say that after almost two decades of programming Python, I still didn’t understand its logging module. Sure, I could get it to work, and reasonably well, but I’d often end up with unexplained situations such as double log lines or logging that I didn’t want. >>> requests.get(‘https://www.electricmonk.nl’) DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection […]

Merging two Python dictionaries by deep-updating

Say we have two Python dictionaries: { ‘name’: ‘Ferry’, ‘hobbies’: [‘programming’, ‘sci-fi’] } and { ‘hobbies’: [‘gaming’] } What if we want to merge these two dictionaries such that “gaming” is added to the “hobbies” key of the first dictionary? I couldn’t find anything online that did this already, so I wrote the following function […]

Reliable message delivery with Mosquitto (MQTT)

I was looking for a message queue that could reliably handle messages in such a way that I was guaranteed never to miss one, even if the consumer is offline or crashes. Mosquitto (MQTT) comes very close to that goal. However, it wasn’t directly obvious how to configure it to be as reliable as possible So this […]

Exploring UPnP with Python

UPnP stands for Universal Plug and Play. It’s a standard for discovering and interacting with services offered by various devices on a network. Common examples include: Discovering, listing and streaming media from media servers Controlling home network routers: e.g. automatic configuration of port forwarding to an internal device such as your Playstation or XBox. In this […]

Ansible-cmdb v1.14: Generate a host overview of Ansible facts.

I’ve just released ansible-cmdb v1.14. Ansible-cmdb takes the output of Ansible’s fact gathering and converts it into a static HTML overview page containing system configuration information. It supports multiple templates and extending information gathered by Ansible with custom data. This release includes the following bugfixes and feature improvements: Look for ansible.cfg and use hostfile setting. html_fancy: […]

mdpreview, a Markdown previewer to be used with an external editor

There are many Markdown previewers out there, from the simplest commandline tool + webbrowser to full-fledged Markdown IDE’s. I’ve tried quite a few, and I like none of them. I write my Markdown in an external editor (Vim), something very few Markdown previewers take in account. The ones that do are buggy. So I wrote mdpreview, […]

Manually scrolling a Python GTK Webview

I was trying to manually scroll a (Python) GTK embedded Webview in order to position the webview back to where it was after setting new contents with webview.load_html_string(html, ‘file:///’). I couldn’t get it to work, and Google wasn’t of much help either. I could scroll the Webview just fine from a key-press-event handler on the main window […]

The text of all posts on this blog, unless specificly mentioned otherwise, are licensed under this license.