Hello! I write a lot of utility scripts. Little helpers to automate repetetive work. Like going through all those YAML files and updating that one config item, or reading through all those database entries and finding the two that are messed up because of that weird bug I just found. These scripts are usually small. … Continue reading PowerShell Scripts with Arguments
Category: Pure Programming
A Checklist for Submitting Pull Requests
Hello! Reviewing code is hard, especially because reviewers tend to inherit some responsibility for problems the code causes later. That can lead to churn while they try to develop confidence that new submissions are ready to merge. I submit a lot of code for review, so I've been through a lot of that churn. Over … Continue reading A Checklist for Submitting Pull Requests
PowerShell: Sort Hash Table Into Ordered Dictionary
Hello! PowerShell's Hash Tables are unordered. The keys don't always come back in the same order you entered them: I created the hash in the order a, b, c, d but I got back c, b, d, a. That's normal. PowerShell also has Ordered Dictionaries that work like Hash Tables but preserve order: Today I … Continue reading PowerShell: Sort Hash Table Into Ordered Dictionary
Don’t Import requests From botocore.vendored
Hello! I've seen this anti-pattern scattered around plenty DevOps code, especially in AWS lambda functions: Vendoring libraries like requests into other libraries like botocore is arguably an anti-pattern in general, but reaching in to botocore and importing it in your own code is definitely one. Here are some of the reasons: The maintainers may un-vendor … Continue reading Don’t Import requests From botocore.vendored
PowerShell: Getting Properties From Objects In Arrays
In PowerShell, I often run commands that return arrays I need to filter. Once I've filtered out object I'm looking for, I need to read a property off that object. There are a few ways to do this. Here are three. These are also good examples if you're new to PowerShell and trying to switch … Continue reading PowerShell: Getting Properties From Objects In Arrays
How to Use Out-String in PowerShell: Don’t
In my PowerShell Help Commands For Linux Users post, I showed you this pattern for searching for command aliases: A beginner mistake! Here's the problem: I'm used to the Unix shells, like bash, where everything is a string. When you run alias in bash, you get this: A multiline string with one alias per line. You search … Continue reading How to Use Out-String in PowerShell: Don’t
Python: JSON Structured Logging
Hello! If you're setting up JSON logging in AWS lambda, check out this instead. You need some extra code to prevent duplicate log messages. Recently, I've been switching to logs structured as JSON. Using the sample command in my pattern for production-ready Python scripts, that means we replace delimited-strings like these: With JSON objects like … Continue reading Python: JSON Structured Logging
Simplifying Messy Conditions: Adaptive Models
Hello! Years ago I found Martin Fowler's article on Adaptive Models. Adaptive models let you replace nests of conditions with a declaration of actions. That pattern has helped clean up my DevOps code a ton of times. Fowler is a better programmer than me. His article is The Source of Truth for this pattern. However, … Continue reading Simplifying Messy Conditions: Adaptive Models
How to Upgrade DevOps Code to Python 3
Python 2 is going away! It's time to upgrade. You shouldn't run anything in prod that's not actively supported. If there are security flaws you won't have a sure path to remediation. Start the upgrade now so you have time to finish before support ends. In DevOps you’re not usually writing much raw Python. A … Continue reading How to Upgrade DevOps Code to Python 3
Python DevOps Code Error Checking: Lint with Pyflakes
Hello! For those unfamiliar with linting (static analysis), read Dan Bader's introduction. There are several linters for Python, but when I'm doing DevOps I use Pyflakes. I love the opening sentence of its design principals: Pyflakes makes a simple promise: it will never complain about style, and it will try very, very hard to never … Continue reading Python DevOps Code Error Checking: Lint with Pyflakes