Programming Update: October 2022


As October came around, it was time to get ready for Hacktoberfest. I’ve been participating for the past few years and I love the fact that DigitalOcean supports this project which gets more people to contribute to free and open source software. 

In the past, I’ve often contributed to my Extra Life Donation Tracker. Since the program is pretty mature at this point, most of the issues I have would have taken me too long, especially with how busy I’ve been with non-programming projects lately. So I dedicated my efforts to helping with some quality of life issues for the Prophecy Practicum (Django Version) that I’ve coded up for my friend. 

As a refresher, this is a project I made for a friend to automate a bunch of tasks for his spiritual practice. These folks seem to be doing the same thing, based on how he described it to me when we were figuring out how the Django project would work. Part of the way he runs it (and maybe this is key to the practice in general) is that each pair is randomized weekly. I created two random lists and used zip to create pairs, but unfortunately, in some cases (especially with an odd pair) the way I’d programmed it led to the person being paired with themselves. So that was my first important fix during this month.

Next was figuring out how to add in rich text support (bold, italics, underline, etc). I ended up using the ckeditor, as that seemed to require the least involved changes to the code. Then was a request to bring back the ability to save a draft to work on later.

Finally came something that I’d learned about while reading Flask Web Development – flash messages. Known in Django as the Message Framework, those are those messages that show up when you’ve succeeded at creating a post on a social media website, for example. It’s the web version of OS messages (OSX’s Growl, for example). Next up for that feature is figuring out how to make the “X” buttom make it disappear. 

I found time during an evening, while watching a comedy special with Danielle, to do the Advent of Code 2016 Day 14 in Python. I’ve gotten pretty good at hash-based problems and this one wasn’t too bad once I sorted out the regular expressions. It was fast enough in Python (even with a naive implementation for part 2. When I get back to this for the other languages I’m using for 2016 I’ll take another look and see if there’s anything I can optimize with the algorithm. However, overnight I began to wonder if it was more optimized in Python to use a regex or the built-in x in y syntax. So I used cProfile to check and found that it was seven times faster than the regex! For part 1 it was 7 seconds vs 1 second.

As often happens, this got the Advent of Code bug to bite me again and I did a few more days before the end of October. Day 15 had us simulating a carnival game – a kind of rotating pachinko. I spent at least an hour trying to figure out how to do it mathematically, but eventually gave up and just simulated the game. I tried putting a capsule in each second until I reached a time where the capsule went all the way through. 

Day 16 involved creating a checksum for data. I remembered having to figure out how to work with bits in a prior Advent of Code, but for this problem it was easier to just treat it as text and implement a text version of an XOR.

I skipped Day 17 as it was another puzzle where I had to move around the room and I am still not sure how to work on those. Day 18 was a very simple algorithm that kind of reminded me of a simplified Conway’s Game of Life where you’re only considering one row for your next evolution step.

Day 19 took me a few tries to get the setup and algorithm working for part 1. But part 2 introduces a circle that’s constantly changing shape and, while I got a hint on Reddit for how to think about the circle, I wanted to keep moving rather than getting stuck trying to figure out part 2.

Just a couple nights before the end of October I started on Day 20. However, I implemented an overly inefficient algorithm that crashes Python when I run it. I’ll need to revisit the code to figure out where I went wrong.

I also finished a few programming books this month. As I mentioned before, I finished Flask Web Development, 2nd Edition. I like reading various books about Python web technologies because each one seems to inform my knowledge of the other and strengthen my ability to code. I’ve blogged before about how there’s been a back-and-forth for me between Django, FastAPI, and Flask. That was one of the best well-written programming books I’ve ever read. It flowed very well and I intend to use it for a future flask project. I also finished Data Visualizaiton with Python and Javascript. I want to use what I learned there to create a dynamic website for viewing some of my end of year stats – such as with the music I listen to. We’ll see, but it might come some time in 2023. 

Finally, of all the programming articles I read in October, the one that stuck in my head was about the Rust developers updating the style guide. I am a frontline supervisor for programmers now, but I used to be a programmer before. Style guides never gelled with me until I really started to get into Python and trying to make sure my code was all PEP-8 compliant. Now that I see the value of a style guide (especially one that can be applied via a pre-commit hook, it was interesting to read about how the Rust developers were evolving their guide to go along with the evolution of their language.