Random snippets of all sorts of code, mixed with a selection of help and advice.
Setting up Claude API for Smart CodeInsight in RAD Studio 12.3
5 June 2026 @ 9:10 am
I am setting up Claude API in Embarcadero 12.3, but every time I send a command, it just prompts Not Found.
Settings are as follows:
Array index out of bounds error using Java 17 with valid array index
5 June 2026 @ 9:05 am
I am using Java language version 17 and encounter an error:
Code:
public class ArrayTest {
public static void main(String[] args) {
int arr_int[] = new int[5];
arr_int [0] = 1;
arr_int [1] = 2;
arr_int [2] = 3;
arr_int [3] = 4;
arr_int [4] = 5;
for (int i: arr_int)
{
System.out.println(arr_int[i]);
}
}
Error message:
2
3
4
5
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5
at org.example.ArrayTest.main(ArrayTest.java:15)
Process finished with exit code 1
Docker healthcheck failing
5 June 2026 @ 9:03 am
I have a Docker image for a website I am attempting to set up a healthcheck on. As per various answers on Stack Overflow and elsewhere, I've updated the healthcheck to use wget instead of curl, as it is an Alpine image, but it is still failing.
The error message is:
Connecting to localhost:3000 ([::1]:3000) wget: can't connect to remote host: Connection refused
website:
image: --IMAGE--
restart: always
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/"]
interval: 30s # Check every 30 seconds
timeout: 10s # Fail if check takes longer than 10 seconds
retries: 3 # Mark unhealthy after 3 consecutive failures
start_period: 40s # Grace period for application startup
How to properly use metaclasses in Python?
5 June 2026 @ 9:01 am
The first thing I thought of when I discovered metaclasses was making singletons. Is this code acceptable? The same thing can be achieved using decorators, so what are the advantages/disadvantages? What are the other cases when metaclasses can be useful?
from typing import Any
class Singleton(type):
def __call__[T](cls: type[T], *args: Any, **kwargs: Any) -> T:
if "_instance" not in cls.__dict__:
instance = super().__call__(*args, **kwargs)
setattr(cls, "_instance", instance)
return getattr(cls, "_instance")
class X(metaclass=Singleton):
@staticmethod
def x() -> str:
return 'abc'
class Y(metaclass=Singleton):
@staticmethod
def y() -> str:
return 'def'
x = X()
y = Y()
z = Y()
print(x.x(), y.y(), z is y)
Why is this while loop giving me an index error?
5 June 2026 @ 8:57 am
I'm making a block breaker game and this is a loop that decides which powerup to grant to the player. It is supposed to give a random powerup between the powerups that are not active (0).
So I made this while loop that starts at a random index between 0 and 3 (powerup list length - 1) and goes down until the negative length of the powerup list, and if it does reach it (which is supposed to mean that every powerup is active) it just assigns a random powerup.
I can't understand why it's giving me an index error.
This is the code:
t = 0
i = r.randint(0,len(LOGIC.powerup)-1) #(0 - 3)
while(1):
if LOGIC.powerup[i] == 0: #this is the line where i get the error
t = i
exit
i-=1
if i < -len(LOGIC.powerup): # -4
t = r.randint(0,len(LOGIC.powerup)-1)
exit
LOGIC.powerup[t] += 1200
CompressPictures doesn't appear on my XML ribbon in PowerPoint anymore
5 June 2026 @ 8:49 am
Years ago I created my own PowerPoint addin. It's still used a lot. Parts of it are my own VBA macros, others are just MSO functions. One of the latter is Compress Pictures. I recently noticed that the button has disappeared. (Win11, Microsoft365)
The XML code which worked for many years was:
<button idMso="PicturesCompress" enabled="true" showLabel="false"/>
Does anyone know if MS changed the idMso? (And if yes, what is the new one?)
Also I already tried
<control idMso="PicturesCompress" enabled="true" showLabel="false"/>
but that didn't change anything, that's why I assume they may have changed the idMso.
I would like to avoid any VBA workarounds here. There should be an XML solution to display it again. Thank you in advance!
Configuring Serilog and ApplicationInsights in AspNetCore application
5 June 2026 @ 8:48 am
I'm using Serilog to write ConsoleLogs and I was using the Serilog.Sink.ApplicationInsights package to write log messages to ApplicationInsights.
Unfortunately I now have to upgrade ApplicationInsights 3.x which is not supported by the Serilog Sink.
After reading the documentation I thought I could use Serilog to write only to the console sink and set "writeToProviders" to true so the logEvents can be written to ApplicationInsights by someone else.
BUT! As soon as I add services.AddApplicationInsightsTelemetry to my setup, I end up with every LogProvider douplicated inside the ILoggerFactory implementation from Serilog.
Minimal setup to reproduce:
using System.Globalization;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Serilog;
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.FromLogContext()
.WriteTo.Console(formatProvider: CultureInfo.InvariantCulture)
.CreateBootstrapLogg
Order of loading classes in PHP
5 June 2026 @ 8:47 am
Please explain the mechanism of loading classes in PHP, and why the first example does not cause an error, but the second does?
From documentation:
Classes should be defined before instantiation (and in some cases this is a requirement).
Under what conditions is this requirement mandatory?
Example 1:
namespace {
echo (new \Foo\Bar)->someattr;
echo (new Egg)->someattr;
exit(0);
class Egg
{
public $someattr = 2;
}
}
namespace Foo {
class Bar
{
public $someattr = 1;
}
}
/*
1
2
*/
Example 2:
namespace {
echo (new \Foo\Bar)->someattr . PHP_EOL;
echo (new Egg)->someattr . PHP_EOL;
exit(0);
class Egg extends \Foo\Bar
{
public $someattr = 2;
}
}
namespace Foo {
class Bar
{
public $someattr = 1;
}
}
/
CoPilot doesn't execute actions in Agentic mode with local LLM
5 June 2026 @ 8:43 am
I'm playing with local ollama model (qwen2.5-coder:7b) trying to connect it to CoPilot.
The local model is detected without issues.
Then, in Agent mode I give it a simple task like "Add a string field named XXX to this class" (C# project).
Model runs, provides some answer which look sensible, but CoPilot doesn't execute the action, instead it prints json output into its chat, something like:
{"name": "get_file", "arguments": {"filename": "...\\MyClass.cs"}}
My impression is that CoPilot doesn't understand what model tells it. Obviously, it needs to provide file contents, but it doesn't do it.
I did it in both Visual Studio 2026 and Visual Studio Code with the same result.
Any advice what can be wrong?
Best approach for Docker health checks in .NET containers without curl/wget?
5 June 2026 @ 8:21 am
have a .NET application running in Docker and need to configure container health checks.
Currently I see a few options:
Option 1
Install curl in the runtime image.
Use Docker HEALTHCHECK with a command such as:
HEALTHCHECK CMD curl -f http://localhost:8080/health/ready || exit 1
Option 2
Use an image such as aspnet:10.0-alpine that already contains wget.
Use wget for the health check.
Option 3
Create a custom executable or .NET program that calls the application's health endpoint and returns an appropriate exit code.
Use that executable in the Docker HEALTHCHECK.
My concern is that installing additional tools such as curl or wget increases