Sunday, March 20, 2022

Yet Another Grab Bag

Hmm.

The past week was something of a different nature. It wasn't a hard week, but it was definitely a trying one at some level. For some unknown reason, I ended up sleeping no more than five hours a week day for the whole week---I think the sleep debt accumulated was starting to drive me a little nuts in the head. It was bad enough that I could feel that weird existential dread since Thursday/Friday.

It was rough. Intrusive thoughts were coming in here and there, and it was through active mental effort that I managed to counteract them. This was, of course, not counting the additional irritation from other inconsiderate actions by other people.

It was bad enough that I spent much of Saturday in a brain fog, just mechanically dragging myself to the Saturday service, and then continuing on to rehearsal. It was still bad enough that I slept in late on Sunday, and ended spending much of the afternoon just napping away.

I'm not dreading heading back to the office tomorroww though---there're things that need to be done, and I know how to do them, and have most of what needs to be done in control.

Situations like that are fine for me---it's when I have no control of things under my domain (like when someone decides to eschew planning make it my emergency) that I get irritated enough to lash back, hard.

But you, the reader, didn't just come here to listen to me talk about vague discomforts in my life, right?

------

I've been working on the Great Aquarium in Minecraft. The glass walls have been put up, and I have been mining me some ice from the frozen river, and have laid out half of the top surface of the aquarium with the ice. The second half had been filled in since the last time I wrote, and I have started putting in the kelp needed to convert the downward flowing water from the top-level source blocks into water source blocks.

Kelp takes time to grow, and even then, they have a maximal height that is randomly pre-determined and cannot be known without some kind of mod. Here is where I decided that I would just use the fact that I'm playing on a semi-survival single player server and just upped the random ticks game rule to allow the kelp to grow much faster after having plopped the kelp down.

The end result surprised me greatly. The idea I had was to slowly clear the kelp row by row, after having stacked on more kelp on whatever was already fully grown to fill up the entire water column with it to ensure that all of it was source blocks. I had done this for five rows when I suddenly realised that throughout the entire 3D space of the Great Aquarium, all the water blocks were source blocks, even when they were above the fully grown (but stunted height) of some of the kelp plants.

That... was way better than I had expected. It meant that I didn't have to go through the painful process I had in mind---I could basically harvest all the kelp and have the filling of the Great Aquarium declared done. The only problem that I had was how to dispose of all the kelp.

Minecraft kelp is a very versatile entity---it can be used as a food source (after smelting in a furnace), and as a fuel source (after combining into a dried kelp block made up of nine smelted kelp). It does require smelting though, and I had a spare semi-automatic smelter available. I had originally used that smelter to create deepslate from cobbled deepslate, but already I had way more than I had ever used, and thus it had been lying defunct. I quickly rejigged it to smelt kelp instead, and adjusted the input to it to allow direct loading from a shulker box. The idea there was to use shulker boxes to assist in moving a larger amount of kelp at once as I move through the Great Aquarium---it saves the amount of round trips with the [much farther] smelting set up from where I was getting the ``raw'' resources.

And with that, I now have yet another bit of industry set up.

I'll probably spend the next few days/weeks clearing out the kelp. Considering that I have only set up a single furnace to handle smelting, it will indeed take a while (unless I use my ``ad hoc smelting'' auto-feeder to increase the smelting rate by 100%). But that just gives me a good reason to have Minecraft running in the background while I am doing something else that isn't related to actively playing any game, a propensity that I am currently in.

------

In other news, I just want to point out that the PDF file format is... quite something. Despite having PyPDF2, there are still some manipulations that I wanted to do on PDF files that made me scratch my head still.

Context: I have a certain large PDF file that, when the ``zoom to content'' option is activated, does almost nothing, despite there being a nice thick border of nothingness separating from the text viewable text and the edge of the page. Almost all other PDF files that I have do not possess this singular problem.

At first blush, it seems minor, but considering single screen left/right split set up, having a working ``zoom to content'' means making much better use of the 960×1080 pixel real estate---it's the difference between readable text and ``oh no I can't see anything properly''.

I've managed to narrow the issue down to a much larger sized /CropBox compared to the /TrimBox. So fixing the PDF to do what I wanted was easy, at least on this front.

But doing that alone with pyPDF2 missed the important step of copying the bookmarks over to the new PDF file. That was where it started to get very hairy in a jiffy.

The long story short was that it was important to make use of the source PDF's ``outline'' object to learn of the bookmark's mapping to the system-level definition of the page (considered as an offset from the first page's binary segment), and translate it to work well in the new [adjusted] PDF.

Doing that alone was enough to copy the bookmarks, but they would still be unusuable since it means all nested bookmarks are fully expanded. For the large piece of work with sections and sub-sections, that was a no-go. The fix for that was arcane---the /Count key had to be set to the value of 0 to not expand that bookmark's child links.

After fixing those two, I realised that I was still missing one thing: the correct copying off the ``logical'' page numbers to the physical ones [as represented in the binary]. The technical term was /PageLabels, and to know it was to have to dig through the PDF specifications.

It was as arcane as it got... for now.

pyPDF2 made accessing all these weird objects very easy to do, and was definitely a massive time-saver. Of course, it not having a properly working copy data structure of the source PDF into the data struacture of the destination PDF was a great hindrance in the ease of programming---it was, however not likely that the original author might updateee things and do a new release. After writing up all the other customised code to do what I wanted while using pyPDF2 as the data access framework, I finally got the results I wanted.

Anyway, that's all I want to yammer about. The upcoming week is a little more controlled (hopefully), and there are some errands that I need to run.

Here's to hoping that the brain fog I had would be dispelled. Till the next update then.

No comments: