Advent of Code: Historian Hysteria

Day 1 assignment

2024-12-01-generated.png

The Chief Historian is always present for the big Christmas sleigh launch, but nobody has seen him in months! Last anyone heard, he was visiting locations that are historically significant to the North Pole; a group of Senior Historians has asked you to accompany them as they check the places they think he was most likely to visit….

-- Day 1 - Advent of Code 2024

[Read More]

Building a compile time annotation processing in Java

In Java we have the option to add or change the code we are compiling during compilation. It allows us to add new code based upon annotations in the code. This could for example be used to generate some proxy classes, or setting up some service loader files.

In this post we will be looking at annotation processing to create a light-weight and very simplistic bean context.

Note: if you are looking for a CDI framework please don’t use the example in this post but look at Guice or Spring instead.

[Read More]

Advent of Code - Day 6: Wait For It

2023-12-06-generated.png

As you try to figure out what to do next, you notice a poster on a wall near the ferry dock. “Boat races! Open to the public! Grand prize is an all-expenses-paid trip to Desert Island!” That must be where the sand comes from! Best of all, the boat races are starting in just a few minutes.

-- Day 6 - Advent of Code 2023

Solution in Java

Full source can be found: in GitHub

[Read More]

Advent of Code - Day 5: If You Give A Seed A Fertilizer

2023-12-05.png

“Oh, we had to stop the water because we ran out of sand to filter it with! Can’t make snow with dirty water. Don’t worry, I’m sure we’ll get more sand soon; we only turned off the water a few days… weeks… oh no.” His face sinks into a look of horrified realization.

-- Day 5 - Advent of Code 2023

Solution in Java

Full source can be found: in GitHub

[Read More]

Advent of Code - Day 4: Scratchcards

2023-12-04-generated.png

Tell you what: if you can help me with something quick, I’ll let you borrow my boat and you can go visit the gardener. I got all these scratchcards as a gift, but I can’t figure out what I’ve won."

-- Day 4 - Advent of Code 2023

Solution in Java

Full source can be found: in GitHub

Part 1

I created a class Card to represent the scratch cards from the assignment. Each card has a score() representing the amount of points of the card.

[Read More]

Advent of Code - Day 3: Gear Ratios

2023-12-03-generated.png

You and the Elf eventually reach a gondola lift station; he says the gondola lift will take you up to the water source, but this is as far as he can bring you. You go inside.

It doesn’t take long to find the gondolas, but there seems to be a problem: they’re not moving.

-- Day 3 - Advent of Code 2023

Solution in Java

Full source can be found: in GitHub

[Read More]

Advent of Code - Day 2: Cube Conundrum

2023-12-02-generated.png

You’re launched high into the atmosphere! The apex of your trajectory just barely reaches the surface of a large island floating in the sky. You gently land in a fluffy pile of leaves. It’s quite cold, but you don’t see much snow. An Elf runs over to greet you.

-- Day 2 - Advent of Code 2023

Solution in Java

Full source can be found: in GitHub

Part 1

The first step for today is the parsing of the input string into Game instances. To do this I created a record representing a single game and a parsing method createGame that processes a single line of the input.

[Read More]

Advent of Code - Day 1: Trebuchet?!

2023-12-01-generated.png

Something is wrong with global snow production, and you’ve been selected to take a look. The Elves have even given you a map; on it, they’ve used stars to mark the top fifty locations that are likely to be having problems.

-- Day 1 - Advent of Code 2023

Solution in Java

Full source can be found: in GitHub

Part 1

In the first part of this years Advent of Code we are requested to find the first and last digit in a string. The input will consists out of multiple of these strings.

[Read More]

Catching most PHP errors

When developing in PHP you may have encountered the following problem:

During an upgrade of the code, or just a minor bug fix, you have introduced new (non critical-error) code. This is causing PHP to crash and report ugly warnings to the user.

Well I think most developers of PHP have found this problem. One option, which is always done on live servers, is setting the logging level very low. Only critical errors are displayed. Though effective it’s far from perfect. I know I want to know when a page is creating problems, even if it is just a minor bug.

[Read More]
website  PHP 

MySQL and Random Row Selection

I’ve been working on a quiz section for one of my websites lately, well tried to anyway. One of the dumbest things happened. In a quiz you want to randomly pick questions and serve them to the visitor. That way they can answer them and shout WAHOO once they have one right.

Problem I had was that I couldn’t figure out how to sort all the questions in a completely random order, well semi random any way (since a computer does not know random as we do). I tried to do this by first counting the number of rows in the table and then creating a random array with 0..x (x being the number of rows). But this is very inefficient.

[Read More]