My First Post

After many, many years I’ve switched from a Blogger site to a static Hugo site. Why? Well, it seemed like I’d given Blogger a plenty long run and it was time to try something else. And here it is!

September 28, 2025

Python, pre-commit, and black

If you’ve had trouble configuring a python project with local repo copies of black and get errors you can’t explain, this may help. Maybe. I ran into some config issues somewhere between my pre-commit config and my black config. In case someone else runs into this I wanted to leave some bread crumbs. The issue. Black keeps exiting with “exit code: 123” after it tries formatting non-python files. It then told me it couldn’t format files that weren’t python files: yaml, md, and toml. I’d thought I’d excluded everything I needed to, but something was still tripping me up. ...

November 28, 2024 · Andrew Diederich

CUPS and POP!_OS

Ok, sometimes I use this blog so I can find stuff later. So, Andrew, if you find you can’t add a printer in System76’s Pop!_OS because your login and password don’t let you log into CUPS, try: sudo usermod -aG lpadmin $USER Courtesy of https://github.com/pop-os/pop/issues/1262.

September 6, 2021

Dual Booting with EFI, The Joy of

For several years I’ve purchased my laptops from System 76. They’re good, and I’m on my third laptop. Many moons ago I needed a hardware swap-out while I was on a 2-week R&R from an Iraq deployment, and they hooked me right up. (I also live 30 minutes from where their HQ was at the time.) I learned the hard way that I needed Windows to control the booting of Windows and Linux (usually SUSE), or Windows patches would never work quite right. ...

May 31, 2020

Lethality: The Podcast

I recorded two podcasts while at the U.S. Army War College. The second was on Lethality. In DoD terms, lethality means “good.” It’s the new hotness–all the rage. As an artilleryman, I approve. But there’s another side to these things. I’ve also studied a lot of economics, and it may just be easier to lose the peace as to lose the war. In that vein, I offer There’s More to Life than Lethality. (Though the Space Force #pewpew article was more fun.)

May 31, 2020 · Andrew Diederich

Podcasting at the U.S. Army War College

I was able to be on two podcasts while a student at the U.S. Army War College (USAWC) over the last year. The first was aimed at a civilian academic audience. Basically, “What in the world is it like to be a military grad student at a ‘War College’?” Yes, there are such things, and the things are a bit different in a professional military education (PME) setting than at a regular university. For example, the military is a direct consumer of its own product, so there is a very tight feedback loop, analyzing the output. ...

August 3, 2019 · Andrew Diederich

Python argparse with defaults -- in-script and importable

I’ve tried using argparse (and optparse before that) and have had trouble finding a workflow that made me happy. This one is pretty close. It allows you to make defaults for when you call a script on the command line and makes those same defaults available if you import the module. It works like this: Make a dictionary with the defaults you want. In the function you write that parses the arguments, use the dictionary values as the defaults. Merge the defaults dictionary and the arguments dictionary together. Return the merged dictionary. The Gist version is available here, or you can see it below, too. ...

June 27, 2017 · Andrew Diederich

Cat facts & python

I’d not actually used anything with json before, but (unsurprisingly) the requests library came through. >>> import requests >>> url = 'http://catfacts-api.appspot.com/api/facts?number=1' >>> print(requests.get(url).json()['facts'][0]) Cat families usually play best in even numbers. Cats and kittens should be acquired in pairs whenever possible. While that gets you the answer, when did you ever really just want the answer? That’s pretty uninteresting. Let’s get there in stages. This is straightforward (yes, I’m assuming you have requests installed already): ...

June 10, 2017

Free laws!

This is something I’ve been looking for for a long time. Colorado is now letting you have a complete copy of the law for free! http://coloradofoic.org/colorado-statutes-database-should-be-free-lawmakers-decide/ has more information about it. Years ago I’d made a fancy pdf of the Colorado Constitution with LaTeX, but this has the amazing benefit that I don’t have to do it. You can download your very own Colorado Constitution from http://tornado.state.co.us/gov_dir/leg_dir/olls/2015titles.htm. Slightly strange: the constitution download is under the Colorado Revised Statutes. The link for the constitution is a web only copy. ...

March 4, 2016 · Andrew Diederich

CSV reader examples for python 3

Among other things, I like python. I quite like the Talk Python to Me podcast, done by Michael Kennedy. He is, among other things, a python trainer. Among his online python training videos is one on parsing csv (comma separated value) files. His example didn’t actually use the python csv module, so I whipped up a couple of examples that used csv.reader and csv.DictReader. These use python 3.4. csv.reader example: #!c:\anaconda3\python.exe '''taken from https://www.youtube.com/watch?v=qajONCIvhEc https://support.spatialkey.com/spatialkey-sample-csv-data/ http://samplecsvs.s3.amazonaws.com/Sacramentorealestatetransactions.csv ''' import csv import os def main(): print("Hello File I/O minicast using csv.reader") filename = os.path.abspath(os.path.join("data", "Sacramentorealestatetransactions.csv")) print(filename) with open(filename, 'r') as csvfile: fin = csv.reader(csvfile, delimiter=',') header = next(fin) print(header) # ['street', 'city', 'zip', 'state', 'beds', 'baths', 'sq\_\_ft', 'type', 'sale_date', 'price', 'latitude', 'longitude'] entries = [] for line in fin: # lines look like # \['3526 HIGH ST', 'SACRAMENTO', '95838', 'CA', '2', '1', '836', 'Residential', 'Wed May 21 [00:00:00](http://www.youtube.com/watch?v=qajONCIvhEc&t=00h00m00s) EDT 2008', '59222', '38.631913', '-121.434879'\] row = dict() for i, h in enumerate(header): row[h] = line[i] entries.append(row) entries.sort(key= lambda r: -1\*int(r['price'])) # Entries are a list of dicts. Each line looks like: # {'street': '9401 BARREL RACER CT', 'state': 'CA', 'sq\_\_ft': '4400', 'city': 'WILTON', 'beds': '4', 'baths': '3', 'sale_date': 'Fri May 16 [00:00:00](http://www.youtube.com/watch?v=qajONCIvhEc&t=00h00m00s) EDT 2008', 'price': '884790', 'longitude': '-121.194858', 'latitude': '38.415298', 'zip': '95693', 'type': 'Residential'} for e in entries\[:5\]: print("{0} beds, {1} baths sold for ${2:,}".format( e['beds'], e['baths'], int(e['price']) )) if *_name_* == '__main__': main() csv.DictReader example: ...

September 3, 2015