Revisiting Selective Code Generation from OpenAPI Specifications

I have now moved fully to using the openapi-generator for generating code from OpenAPI specifications, instead of the “official” swagger-codegen. This fork, by some of the original maintainers, has a much more active community & development pace over the original project. My PR to improve tag support in swagger-codegen is still sitting with no activity more than 6 months on.

Using tags as part of generation has been supported for all JAX-RS based generators as of version 5 of openapi-generator. I am using this through through the maven plugin, which correctly integrates with maven to add generated sources to the sources paths. We use this with the generate goal linked to the maven lifecycle so code generation is performed in every build of the project, so we can be sure that the code in the produced artefact reflects the specification in the repository.

The maven plugin has very detailed documentation with all the configuration options available for it, but going into this it is worth noting that some of the terminology is different between the two forks of the plugin. This is reflected in the documentation. Individual generators are documented here.

» Continue reading



How I Configure Pi-hole Without the UI

I run two Pi-hole instances for redundancy and needed an approach to keep some configuration consistent between the two instances.

There is a utility, gravity-sync, that can automate the sync between a primary instance and secondary instances, but I wanted to keep it simple as I don’t apply changes too often. I also wanted to still be able to set up a new instance with my existing configuration without needing to have one already working.

The two main things I need to keep in sync are:

  1. Custom DNS entries. I run Traefik as a load balancer in front of services running in Docker to provide HTTPS, and also so services have their own DNS names instead of needing to remember which port a specific service runs on
  2. Whitelist configuration, as there are some hosts on the default block lists that I need to be accessible

» Continue reading


Raspberry Pi USB Boot with JMS578 Based USB-to-SATA Enclosures

During the festive holiday period a part of one of the projects I have been working on involved moving my home automation setup from a Raspberry Pi 3B+ to a Raspberry Pi 4B 4GB. As part of this, I wanted to switch from using an SD card to booting from an SSD for improved performance.

I already had spare parts lying around which would be reused for this.

After using the Raspberry Pi Imager to provision the SSD with Raspberry Pi OS Lite, mounting the boot partition to add the ssh file, and connecting the enclosure to one of the USB 3 ports on the Pi it wouldn’t boot. After a bit of digging I found a workaround to get this working.

» Continue reading


Introducing toggl-summary-cli

toggl-summary-cli is a CLI utility, written in Typescript, for my own specific Toggl reporting requirements

I use Toggl Track for keeping track of what I am spending my time on while working. I’m not a contractor though, so I don’t have any hard requirement to ensure every minute of my day is accounted for. I do need to know though how many hours in a day or week that I have have been on the clock for reporting purposes.

This tool will, for a day or a week, report on:

  • booked time, the total for tasks
  • unbooked time, the total for unaccounted for time between tasks
  • total time, the sum of booked and unbooked time
  • break time, the sum of any times between a “marker” entry and the next task

In order to pick up on unbooked time and differentiate it from break time, I add entries with a tag of “marker”. This is used to indicate the start of a break. The break is determined to end when the next entry starts.

Configuration

This uses commander.js for supporting command line arguments. Running the program with a -h or --help flag will print out the usage instructions. Note if you have a .env file as below this will include the values from that file in the output.

$ npx @devwithimagination/toggl-summary-cli -h
npx: installed 52 in 12.172s
Usage: toggl-summary-cli [options]

Options:
  -D, --debug                    output extra debugging
  --api-key <api-key>            api token, found in Toggle profile settings
  --email <email>                your email address
  --workspace-id <workspace id>  id of the Toggle workspace
  -d, --day <date>               day to report on (in yyyy-MM-dd format). If a date is not supplied then this will default to today. (default: "2020-09-21")
  -w, --week                     If specified, interpret the day as the start of a week.
  -h, --help                     display help for command

This uses dotenv for supporting loading secrets from a .env file in directory the tool is ran from. This is used to provide default values for the required CLI options above. This file can contain:

API_TOKEN=<api token, found in Toggle profile settings>
EMAIL=<your email address>
WORKSPACE_ID=<id of the Toggle workspace>

Example Usage

An example of running this for a single day:

$ npx @devwithimagination/toggl-summary-cli -d 2020-09-18
Report page loaded 1 total booked time: 02:49:13
==== Totals for 2020-09-18 to 2020-09-18 ====
Counted booked time: 02:49:11
Counted unbooked time: 00:54:20
Counted break time: 00:00:00
Counted total time: 03:43:31

Running for a week:

$ npx @devwithimagination/toggl-summary-cli -d 2020-09-14 -w
Report page loaded 1 total booked time: 28:22:01
Report page loaded 2 total booked time: 28:22:01
==== Totals for 2020-09-14 to 2020-09-20 ====
Counted booked time: 28:21:26
Counted unbooked time: 07:20:12
Counted break time: 04:01:59
Counted total time: 35:41:38

This might be no use to anybody but me, but it helps with my time tracking and that is what matters. If you are interested in the implementation, it is available on GitHub here.