Random snippets of all sorts of code, mixed with a selection of help and advice.
Solving a multiple-choice multi-dimensional knapsack problem with OR-Tools
8 April 2026 @ 9:18 pm
I'm trying to solve a multiple-choice multi-dimensional knapsack problem with OR-Tools. Examples of solving multi-dimensional KPs can be found on the repository, but not the multiple-choice KP in any dimension. I assume the best solver for MMKP would be the Knapsack Solver or CP-SAT. I would appreciate it if anyone could provide example code that, ideally, does not require classes be of equal size.
LLM-based approach to fix incorrect PDF field coordinates for form rendering — is this reliable?
8 April 2026 @ 9:03 pm
I am working on a system that renders input fields on top of PDF forms using coordinates extracted from a document analysis tool.
Current Setup
For each form, we receive coordinates (X, Y, width, height) for fields from a document extraction system.
These coordinates are used directly to render fields on the PDF.
Rendering logic is consistent across all forms.
Problem
Some fields render correctly using the provided coordinates.
However, others are visibly misaligned when compared to the actual PDF layout.
-- Can anyone suggest how should we fix this issue using AI? Manually doing this would take a lot of time as there are 70k forms
Can not log-in to my Azure portal admin account after changed MFA setting
8 April 2026 @ 8:53 pm
I need urgently support from Azure team to get access to our Azure portal. My admin login got error message "can not go from here to there..."
Any help will be highly appreciated. thx.
Guenter
Replicating a particular plot
8 April 2026 @ 8:47 pm
I have this code that produces a nice plot
library(forecast)
fit <- auto.arima(WWWusage)
fc <- forecast(fit, h=20, level=95)
qf <- matrix(0, nrow=99, ncol=20)
m <- fc$mean
s <- (fc$upper-fc$lower)/1.96/2
for(h in 1:20)
qf[,h] <- qnorm((1:99)/100, m[h], s[h])
plot(fc)
matlines(101:120, t(qf), col=rainbow(120), lty=1)
Now, I want to create this graph using the following code that calculates the quantiles for another data set but I am not sure how to produce the above graph
library(fpp3)
library(distributional)
fc <- aus_production |>
model(ARIMA(Beer)) |>
forecast(h = 20)
pc <- seq(99)
fc |>
as_tibble() |>
group_by(Quarter) |>
reframe(percentile = quantile(Beer, pc / 100)) |>
unnest(percentile) |>
mutate(pc = rep(pc, 20))
XmlSerializer - Different Order of Namespaces in .NET Framework and in .NET 10.0
8 April 2026 @ 8:16 pm
Here is a serialize implementation using XmlSerializer:
public static string Serialize(object obj) {
var xmlSerializer = new XmlSerializer(obj.GetType());
using var stringWriter = new StringWriter();
using var xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings {
OmitXmlDeclaration = true
});
xmlSerializer.Serialize(xmlWriter, obj);
return stringWriter.ToString();
}
Using the same serializer produces different strings in .NET Framework and in .NET 10.
In .NET Framework, I get:
<item xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="7"><name>hello</name></item>
But in .NET 10, the result is:
<item xmlns:xsi="http://ww
Expected biome behavior when setting it as the default in settings.json?
8 April 2026 @ 7:59 pm
I'm experimenting with biome and I have the following in .vscode/settings.json :
{
"editor.defaultFormatter": "biomejs.biome",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.biome": "explicit",
"source.organizeImports": "explicit"
}
}
And I'm expecting the biomejs.biome vscode extension to be the extension that VSCode will now use ensure that running:
npx @biomejs/biome check --write
Will produce results consistent with whatever biomeproduces when files are saved. And so for the current sample project I created when I run
npx @biomejs/biome check --write
It changes 3 files. And if I go to save any of these files in vscode, it changes the files again to something that is different than what running
npx @biomejs/
How do i make this if statement?
8 April 2026 @ 4:42 pm
I'm trying to learn python in khan academy & I'm stuck on this challenge. the goal is to create an error message when the user inputs the day 31 for April, June, September, and November because they only go up to 30 days. Here's my code:
day = int(input("Enter a day (1-31): "))
if day < 1 or day > 31:
print("Error. Day must be between 1 and 31.")
month = int(input("Enter a month (1-12): "))
if month < 1 or month > 12:
print("Error. Month must be between 1 and 12.")
not_31_days = 4, 6, 9, 11,
if day == 31 and month == not_31_days:
print("Error. Day must be within the month.")
The error message says "April only has 30 days! If the month is 4 and the day is 31, it should print: Error. Day must be within the month."
Large heat map with multiple legends in ggplot
8 April 2026 @ 3:14 pm
I need to make a large heat map (>10-15 columns) with many different legends (different units, data types, etc). I've used the palmer penguin dataset below to show an example of how I am currently doing it. Essentially making individual heat map strips using geom_tile and then using patchwork to link them together. It always requires a lot of .svg editing in inkscape or affinity, so I'm looking for ways to streamline it and get it as close to the final desired product (copied at end).
# set up
library(tidyverse)
library(patchwork)
library(palmerpenguins)
# Format
penguins_formatted <- penguins %>%
group_by(species, sex) %>%
summarise(MEAN_BILL_LENGTH = mean(bill_length_mm),
MEAN_BILL_DEPTH = mean(bill_depth_mm),
MEAN_FLIPPER_LENGTH = mean(flipper_length_mm),
MEAN_MASS = mean(body_mass_g)) %>%
drop_na() %>%
rownames_to_column(var = "uniqueID")
#
Incompatibility in RRDs::graph regarding TICK boxes overlapping label
8 April 2026 @ 9:34 am
Many years ago I wrote some monitoring tool that collects data using RRD (actually using perl module RRDs. The OS at that time was SLES 10 (rrdtool 1.2012 and rrdtool 1.3007).
Since upgrading to SLES 15 SP6 (perl-rrdtool-1.8.0-150600.1.4.x86_64) I see that my TICK boxes overlap its label.
The bottom of the graphs look like this:
Screenshot showing bottom of incorrect RRD graph
The purpose of the TICKs is just a kind of "color legend" for a bar graph (green/yellow/orange/red) classifying a status not shown.
The part responsible to draw that bottom part looks like this (the @graph_args array from RRDs::graph($fname, @settings, @graph_args);):
...
51 'COMMENT: Last\\t Minimum\\t Average\\t Maximum\\t Sample\\n'
52 'GPRINT:S_A:LAST: %6.2lf\\t\\g'
53 'GPRIN
Curl C/C++ library based application produces erroneous response for HTTP POST request
7 April 2026 @ 10:31 pm
I use the following block of code to download some data from a server:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#include "../persistent/settings.h"
#include "network-helper.h"
#define HTTP_REQUEST_MAX_LENGTH 2048
struct MemoryStruct {
char *memory;
size_t size;
};
static size_t writeCb(void *contents, size_t size, size_t nmemb, void *userp)
{
size_t realsize = size * nmemb;
struct MemoryStruct *mem = (struct MemoryStruct *)userp;
char *ptr = (char *)realloc(mem->memory, mem->size + realsize + 1);
if(!ptr)
{
/* out of memory! */
printf("not enough memory (realloc returned NULL)\n");
return 0;
}
mem->memory = ptr;
memcpy(&(mem->memory[mem->size]), contents, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;
printf("Curl callback:\r\n")
for (