Code Examples
Much of what I’ve worked on I cannot show but here are some highlights of me messing around with various different things.
HTML & CSS
Lately I’ve been focused on learning HTML5, CSS, and Java/TypeScript after many years away. I’m having a lot of fun with it. I’ll be adding a portfolio soon. Here’s some code though:
- requirements diagram in css
- this website
- I also explain stuff in my blog as I learn it in the “learning xxx” articles.
C++
C++ reflection
C++26 recently came out and I have not been playing with it yet. So I’m learning it anew and there are quite a few very significant changes to how metaprogramming is done now. It’s not as simple as just applying concepts I already knew. So I’ve recently built a GCC 16.1 docker image (there wasn’t one officially) and have been messing about with it. I’m putting some of that in snippets on gitlab:
- iterate members in which I learn how to iterate members in a class and print their names.
Metaprogramming fizzbuzz in all the versions
I created a blog entry a bit back that I later deleted. The code still exists and is kinda commented but not very well (my hobby code suffers this quite a bit). The project is to implement fizzbuzz in code per the old interview question but with C++ metaprogramming. It goes from C++03 through C++20.
Modern Arduino
Long while back I started a project to make an Arduino library that used modern C++ coding standards. It was going pretty well and I was getting pretty good results but I got distracted. One of those distractions was to see just how far I could push a really absurd idea. I ended up making this a compilable piece of C++ that actually produces something:
constexpr auto atmega328p_28p3 =*
(PC[6_c])--[ 1_p - U - 28_p]--(PC[5_c])
(PD[0_c])--[ 2_p , 27_p]--(PC[4_c])
(PD[1_c])--[ 3_p , 26_p]--(PC[3_c])
(PD[2_c])--[ 4_p , 25_p]--(PC[2_c])
(PD[3_c])--[ 5_p , 24_p]--(PC[1_c])
(PD[4_c])--[ 6_p , 23_p]--(PC[0_c])
(VCC)--[ 7_p , 22_p]--(GND)
(GND)--[ 8_p , 21_p]--(AREF)
(PB[6_c])--[ 9_p , 20_p]--(AVCC)
(PB[7_c])--[10_p , 19_p]--(PB[5_c])
(PD[5_c])--[11_p , 18_p]--(PB[4_c])
(PD[6_c])--[12_p , 17_p]--(PB[3_c])
(PD[7_c])--[13_p , 16_p]--(PB[2_c])
(PB[0_c])--[14_p - _ - 15_p]--(PB[1_c]);
The idea being that now you could use things like 1_p as an index to operations to toggle pins on/off
and other things. Happens at compile time and if you grouped them (I don’t believe I ever got to this part)
you’d get merged operations where any pins existing on the same register would be updated with the same
operation. It also compiled down super small because it is mostly metaprogramming (of a rather old
variety–it needs updating).
PineTime watch face
At one point I owned a PineTime watch that I was messing around with. I had a Raspberry PI 3 that I used for programming it through the SWD pins and was replacing the bootloader (next subsection). I decided to use RIOT for the embedded OS just because it’s a “microkernel”, which is a subject I wrote about in college so I thought it would be fun. There was no driver for the display so I made one.
RIOT MCUBoot
I can be a bit of a purist when left to my own devices and no deadlines. I wanted my bootloader to use RIOT also and nobody had done that. So I made MCUBoot for RIOT. A limited form, mind you, that does none of the stuff you really use mcuboot for. It juts gets it up and uses it. Makes the driver for the space on the NRF52 in the pinetime and a few other things specific for that device.
Nix
The idea of a “declarative” package manager and then an OS built on top of it is really intreguing to me. I have been using Nix as my Linux version of choice for going on a year now. It’s a long learning curve and I’ve not gotten very far because I’m also learning other things at the same time. It’s also pretty difficult and frustrating and some of the packages can be unstable. Still, it’s a promising system and I really enjoy frustrating myself with it. I think it shows a lot of promise if you are interested in a really secure build system with a well defined supply chain that is in reviewable code–important stuff if you are working on regulated systems.
I have a couple basic examples:
- About the simplest flake you can get
- some configuration.nix for a macvlan container
- some configuration.nix for librewolf with some plugins
Guix
Guix is similar to Nix and started out using the nix daemon. I believe it’s changed since. It uses scheme instead of a homebrew language. This doesn’t mean it’s simpler because the nix language is about as simple as you can get. Guix is different in a lot of ways I won’t get into here. I think it might be a better choice for someone who needs a really tight supply chain and repeatable builds, but it’s also considerably slower to update stuff and doesn’t include a lot. Sometimes it seems to work better for stuff like Python integration, but other times maybe not.
I did get far enough to create a channel that adds tofu for install:
