Random snippets of all sorts of code, mixed with a selection of help and advice.
Error with XGBoost predicting on new data, when there is no target column in the new data (such as in data science competitions)
13 March 2026 @ 5:54 pm
In many data science competitions the user is asked to predict on new data when the target is not given in the new data set. The target is given in the training data set, but not the test set.
For example: https://www.kaggle.com/competitions/playground-series-s6e3/overview
I'm not able to do this using XGBoost on any data set.
Simple example:
# Set up train and test sets
train <- MASS::Pima.tr
train$type <- ifelse(train$type == "No", 0, 1)
test <- MASS::Pima.te
test$type <- ifelse(test$type == "No", 0, 1)
train_x = data.matrix(train[, 1 : ncol(train)])
train_y = train[,ncol(train) : ncol(train)]
#define predictor and response variables in test set
test_x = data.matrix(test[, 1 : ncol(test) -1])
xgb_train = xgb.DMatrix(data = train_x, label = as.matrix(train_y))
Do C standards allow nested member designators in offsetof()?
13 March 2026 @ 5:43 pm
I have the following struct:
struct case_a {
int a;
int b;
int c;
};
struct case_b {
int x;
int y;
int z;
};
struct foo {
int a;
union {
struct case_a a;
struct case_b b;
} u;
};
I also have a pointer to struct case_a and would like to convert it to pointer to foo:
#define CONTAINER_OF(ptr, type, member) \
((type*)(((char*)ptr) - offsetof(type, member)))
int main(int argc, char **argv)
{
struct foo foo;
struct case_a *aptr = &foo.u.a;
struct foo *fooptr = CONTAINER_OF(aptr, struct foo, u.a);
if (fooptr == &foo)
{
printf("OK\n");
}
return 0;
}
Note how I'm nesting members when using the CONTAINER_OF macro that calls offsetof.
Is this nesting of members permitted by the C standards? At least both clang and gcc with -pedantic, and even with a standard as old as C89, allow it.
Are there any major compiler
In React, s it really bad to call a potentially asynchronous function directly in render code?
13 March 2026 @ 5:40 pm
I have a question regarding best practices in React.js.
Recently, I came across a blogpost that claimed you shouldn't directly invoke a callback in React render code. And while intuitively I would agree to that statement (and I have never invoked a callback directly in render code before), I started questioning this statement and am wondering why (and if) that is really the case).
In other words, my question is: Why should I not do something like in the following? What would break if I did?
export const MyComponent = ({callback}) => {
callback(); // <-- Why not?
return <div>Irrelevant text here</div>;
}
Note that callback could be an asynchronous function returning a promise (or not).
Some further thoughts:
The react documentation itself
Phaser collision detection between a group and a tile layer
13 March 2026 @ 5:37 pm
How can you detect a collision between a group and a tilelayer in Phaser? A reason could be for example to delete bullets hitting a wall. In theory it is easy, just use a collider, but nothing works. I have tried overlap instead of collide, making the bullets a physics group, using world.addCollider, etc.
Some tiles have been set to collide with this following line:
this.groundLayer.setCollisionByProperty({ collides: true });
by getting the collide property from a JSON file produced by Tiled. So collision works fine between the player and the tiles.
The dysfunctional code is below:
this.physics.add.collider(
this.bullets,
this.groundLayer,
(bullet, tile) =>
{
console.log("hit");
bullet.setActive(false);
bullet.setVisible(false);
});
How to check a `struct gps_data_t*` for a NULL value the safe way?
13 March 2026 @ 5:28 pm
I'm using the gpsmm library and the gpsd service in a C++ program querying a GPS module. I get a struct gps_data_t* variable with all the data the GPS module spits out, but when it can't fix enough satellites or the gpsd isn't running, the content of the variable is a nullptr. Please don't ask me how someone can come with such an unsafe solution (well, C++ is not Rust).
Now I've got a branch in my program, which reads somehow like this:
gpsmm gps_handler;
struct gps_data_t *gps_data;
tmc::tmc ()
: gps_handler ("localhost", DEFAULT_GPSD_PORT),
{
}
tmc* tmc::Initialize ()
{
tmc* instance = new tmc ();
gps_data_t* response;
if (!(response = instance -> gps_handler.stream (WATCH_ENABLE | WATCH_JSON))) {
cout << "No GPSD running." << endl;
}
else {
// do somethin' with the GPS data
}
}
Passing texture between shaders
13 March 2026 @ 5:27 pm
I have created a first webgl2 program, which defines a FrameBuffer and writes 2 floats in a 1x2 texture:
gl.texImage2D(
gl.TEXTURE_2D,
0, // level,
gl.R32F, // internalFormat,
1, // targetTextureWidth,
2, // targetTextureHeight,
0, // border,
gl.RED, // format,
gl.FLOAT, // type,
null // data
)
This works fine, as I can readPixels() and get the expected result.
I would like this texture to be an input to a vertex shader of another program, but I am unsuccessful.
// in shader
uniform sampler2D u_texture;
...
void main() {
...
// this ymin always is equals 0 :(
float ymin = texelFetch(u_texture, ivec2(0, 0), 0).x;
...
}
My javascript:
// first compute the float values in first program
gl.useProgram(programCompute)
gl.bindFramebuf
End to End Automation of Kofax + FileNet Application
13 March 2026 @ 5:21 pm
I have to Automate the End to End flow of the Kofax + FileNet Application.
Kofax uploads documents which has some unique ID and some metadata of the document which is further stored in FileNet where it has to be validated by searching for the Document Title and the unique ID.
When the document is searched and is clicked in the FileNet, it shows the properties/metadata of the document from which it is verified that the document uploaded from Kofax has been stored in the FileNet.
Give me a guide how should I start with the End to End Automation of the two application. We are using WebDriverIO + Typescript + Cucumber BDD + SuperTest (for API).
How should I do the UI + API Automation Testing of this end to end flow?
AWS Cognito Custom Auth: How to differentiate authentication methods in first Lambda trigger (DefineAuthChallenge/CreateAuthChallenge)?
13 March 2026 @ 5:20 pm
I am implementing custom authentication in Amazon Cognito using the standard three triggers:
DefineAuthChallenge
CreateAuthChallenge
VerifyAuthChallengeResponse
My system supports multiple authentication methods for the same user:
Phone OTP login
Email OTP login
Google ID token verification
The flow starts with:
AdminInitiateAuth
AuthFlow = CUSTOM_AUTH
AuthParameters = {
USERNAME: <existing Cognito username>
}
The problem is that the first invocation of DefineAuthChallenge and CreateAuthChallenge does not contain ClientMetadata. From my testing, ClientMetadata only appears when the trigger is invoked from AdminRespondToAuthChallenge.
Because of this, in the first CreateAuthChallenge call I cannot determine which authentication method is being
need code for this: when a cell is selected, highlight that row and all rows with the same value in column B
13 March 2026 @ 4:26 pm
Need code for this: when a cell is selected, highlight that row and all rows with the same value in column B (table only, if possible).
I tried an even simpler code suggested by google, and it didn't work. if I could get that fixed, that would be an ok plan-B:
function onSelectionChange(e) {
const sheet = e.source.getActiveSheet();
const range = e.range;
const selectedValue = range.getValue();
// Clear previous highlights (optional, but recommended)
// Change 'Sheet1' to your actual sheet name if different
const fullRange = sheet.getRange('A:Z'); // Adjust this range as needed (e.g., 'A1:E100' or 'A:Z')
fullRange.setBackground(null);
if (selectedValue) {
// Apply new highlights using a conditional formatting rule
const rule = SpreadsheetApp.newConditionalFormatRule()
.withFormulaCode(`=$A1="${selectedValue}"`) // This formula compares each cell to the selected value
.setBackground("#ff0000") // Change to
Nextflow slurm jobName issues
13 March 2026 @ 3:39 pm
I am trying to customize the SLURM jobs submitted via Nextflow v.25.04.7 for tracking purposes. However, after multiple attempts and tests, I still cannot figure out the proper syntax. Here are a couple of tests I tried:
withLabel: large_res {
executor = "slurm"
executor.jobName = "${params.projectName}_${task.name}_${task.hash}"
cpus = 8
memory = 100.GB
time = 24.h
clusterOptions = "--account=myGroup --qos=myGroup-b"
}
This gives the following warnings and errors:
WARN: Cannot read project manifest -- Cause: No such property: jobName for class: java.lang.String
ERROR ~ No such variable: jobName
I also tried modifying the job name in the cluster options instead:
withLabel: large_res {
executor = "slurm"
// executor.jobName = "${params.projectName}_${task.name}_${task.hash}"
cpus = 8
memory = 100.GB