Random snippets of all sorts of code, mixed with a selection of help and advice.
Logic introductory exercise
15 June 2026 @ 4:37 am
The problem and the explanation:
The problem is: "N numbers are entered one by one. Display: A. Quantity of numbers between 100 and 500. B. Percentage of numbers equal to zero. C. Average of negative numbers. D. Sum of the entered numbers that belong to the first half. E. Average of the entered numbers."
We cannot use arrays, and the critical point to solve is point D, as it's ambiguous what strictly constitutes the "first half." This is an introductory logic exercise where we can only work with the tools we've been taught, such as variables and loops. We cannot use functions, arrays, or For loops.
"How to handle class imbalance in PyTorch when using ImageFolder for medical image classification?"
15 June 2026 @ 3:25 am
Problem Description: I am building a pneumonia detection model using the chest-xray-pneumonia dataset. My dataset is imbalanced: the 'PNEUMONIA' class has significantly more samples than the 'NORMAL' class. I am using torchvision.datasets.ImageFolder and DataLoader for training.
What I have tried: I have implemented a standard training loop with CrossEntropyLoss. The model achieves high accuracy but seems biased towards the majority class. I am looking for the best practice to handle this in PyTorch.
Specific Question:
Should I use WeightedRandomSampler or pos_weight in the loss function?
Which approach is more recommended for a binary classification task in a medical context where false negatives are critical?
Best practice for organizing Claim Types and Values as constants in ASP.NET
15 June 2026 @ 3:24 am
I'm trying to refactor the authorization layer in my ASP.NET Core Web API project to remove any hard coded strings in policies.
For roles, I used an enum, and for policies I used a flat static class, and it works fine. However, I am struggling to find the cleanest way to represent (Claim type, Claim value) pairs without hardcoding. Here's what I had done previously:
.AddPolicy(PolicyName.SampleAccess, policyConfig =>
policyConfig.RequireClaim("sampleClaim", "sampleValue"));
Now I wanted to avoid hardcoding the claim type (sampleClaim) and the allowed values (sampleValue). One approach was to create separate classes, but I'm confused if that's the proper industry standard. Please help.
TIA
Parsing Wind financial data's HHMMSSmmm integer time
15 June 2026 @ 3:04 am
Wind financial data exports use an integer time format — 92501020 means 09:25:01.020. The date is another integer, e.g. 20251222.
I need to combine them into a DolphinDB TIMESTAMP for sorting and filtering.
Date is straightforward:
temporalParse(string(20251222), "yyyyMMdd")
// → 2025.12.22
But I couldn't find a format string that works for 92501020. Tried variations like temporalParse(string(92501020), "HHmmSSS") — no luck.
I ended up writing a manual arithmetic parser:
def parseWindTime(t) {
ms = t % 1000
sec = (t / 1000) % 100
mnt = (t / 100000) % 100
hr = t / 10000000
return hr * 3600000l + mnt * 60000l + sec * 1000l + ms
}
Then combine:
ts = timestamp(temporalParse(string(date), "yyyyMMdd")) + parseWindTime(time)
It produces correct results, but feels lik
Backend request crashing [closed]
14 June 2026 @ 11:57 pm
What could be the issue if you are receiving an error 500 or simply your backend is crashing due to missing supabase_service_role_key, yet you have configured your var correctly in cloudfare pages?
Is fixing child.prototype.constructor necessary in ES5 if we solely rely on [[Prototype]] check methods like Object.getPrototypeOf()?
14 June 2026 @ 10:38 pm
When implementing the parasitic combination inheritance pattern in ES5, almost every resource (including Nicholas Zakas' book) insists on fixing the constructor property like this:
function inheritPrototype(childSide, parentSide) {
childSide.prototype = Object.create(parentSide.prototype);
// Is this line below actually necessary in ES5?
childSide.prototype.constructor = childSide;
}
However, from an OLOO (Objects Linking to Other Objects) perspective, the .constructor property seems to be just a fragile, misleading illusion left over from trying to make JavaScript look like a class-based language.
If my architecture explicitly bans the usage of instance.constructor for type checking, and we strictly use modern ES5/ES6 diagnostic tools like:
Object.getPrototypeOf(instance)
Parent.prototype.isPrototypeOf(inst
Health Connect rate-limit RemoteException on API 33 and below, even on the first call
14 June 2026 @ 9:01 pm
I use Health Connect inside a DataSapien SDK. On API 34 our read flow works fine. On API 33 and below, we get this immediately
android.os.RemoteException: Request rejected. Rate limited request quota has been exceeded. Please wait until quota has replenished before making further requests.
Setup: androidx.health.connect:connect-client:1.1.0, compileSdk 36, minSdk 26, Kotlin 2.1.0 / 2.2.21.
My Implementation:
Client creation:
fun getHealthConnectClient(): HealthConnectClient? {
val ctx = context ?: return null
when (HealthConnectClient.getSdkStatus(ctx)) {
HealthConnectClient.SDK_UNAVAILABLE -> return null
HealthConnectClient.SDK_UNAVAILABLE_PROVIDER_UPDATE_REQUIRED -> return null // opens Play Store
}
return HealthConnectClient.getOrCreate(ctx)
}
Before reads we check/request permissions:
Eager loading nested collections via multi-level Include statements causes synchronization delays in desktop data contexts
14 June 2026 @ 8:26 pm
I am working on an optimized logistics application using a desktop client interface with an isolated SQLite data source managed by Entity Framework Core.
When attempting to invoke multiple level eager loading using nested .Include().ThenInclude() statements, the data context changes do not seem to immediately update the presentation layer elements despite implementing the standard change notification interfaces. The model schema is mapped down below.
Why does the underlying collection binding experience this synchronization delay?
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
namespace WpfAppLogistics.Models
{
public class StorageZone
{
private int id;
private string name;
public StorageZone()
{
ProductItems = new ObservableCollection<ProductItem>();
}
public int Id { get => id; set => id = value; }
Chronic AI Code Mutation & Context Drift in Autonomous Agent Workflows despite Git/CI Controls — Looking for Permanent Architectural Solutions
14 June 2026 @ 6:35 pm
For the past several months, I have been using state-of-the-art AI developer models (such as Google Codex and Anthropic Claude workflows) to manage, modify, and deploy our multi-brand codebase.
While the speed of generation is incredible, we are facing a chronic, critical problem that is causing severe operational fatigue and delaying our product launches.
The Core Problem:
Even though we strictly follow standard industry guardrails, configure explicit context files, use rigorous version control (Git), and maintain distinct deployment branches, the AI sub-agents repeatedly suffer from what looks like "memory drift" or "regression anomalies."
The Zombie Comeback: The AI continuously attempts to rewrite, bypass, or over-write pre-existing core logic (like fixed business pricing parameters or carrier routing rules) that was explicitly locked in past sessions.
Context Ov
Cannot change orientation of triangle in ThreeJS
14 June 2026 @ 6:20 pm
I have an octahedron whose vertices coordinates came from a computation. I build the object using a BufferGeometry and a MeshStandardMaterial (see the code below).
The resulting object has 4 facets with, apparently, the normals pointing to the inside of the object. I identified these triangles by computing the dot product between the vector from the center of the object to the center of the triangle and the normal vector of the triangle.
I tried three strategies to change the orientation of these triangles, but they change nothing: always three darker triangles in the bottom half and one in the top half. Where is my fault?
const material = new MeshStandardMaterial({
side: DoubleSide,
roughness: 0.5,
metalness: 0.6,
color: "#00FF00"
});
const geometry = new BufferGeometry();
geometry.setAttribute("position", new Float32BufferAttribute(vertices, 3));
// First strategy: compute the v