Random snippets of all sorts of code, mixed with a selection of help and advice.
Form page reloads on submit despite calling event.preventDefault() in JavaScript
8 January 2026 @ 12:49 pm
I am trying to prevent a form from reloading the page when it is submitted. I am calling event.preventDefault(), but the page still reloads every time I click the submit button.
Here is my HTML:
<form id="loginForm">
<input type="text" id="username" />
<button type="submit" id="submitBtn">Submit</button>
</form>
And my JavaScript:
const btn = document.getElementById("submitBtn");
btn.addEventListener("click", function (event) {
event.preventDefault();
console.log("Button clicked");
});
I expected the form submission to be stopped and only the console message to be printed. However, the page still reloads after clicking the submit button.
I tried using preventDefault() and confirmed that the event handler is running, but the reload still happens.
What is the correct way to prevent th
How to end NodeJS(TS) operation gracefully on manual SIGINT?
8 January 2026 @ 12:43 pm
I know that this question has many answers, but neither works cleanly as I intend.
Goal:
I have a Typescript script that is triggered via Commander command, and then I process data.
I want to finish database update, calculation for current data cycle, then break and exit.
I listen to signint, and gracefully handling works great.
My only issue is with logs output that I see a new terminal prompt on Mac some time after SIGINT request and then the rest of the logs.
Example Code
main.ts
import { program } from 'commander';
import { logger } from '@src/logger';
async function cleanup(): Promise<void> {
await db.destroy();
redis.disconnect();
await pubsub.close();
}
program
.name('process-data')
.version('0.0.0')
.option('--config <string>', 'path to a config file')
.actio
Homebrew: formula fails to run with error ZIP does not support timestamps before 1980
8 January 2026 @ 12:41 pm
I maintain a Homebrew formula on my own tap, and I'm having issues to update it. I'm not sure if this is Python- or Homebrew-related. Here is my formula:
class Kosmorro < Formula
include Language::Python::Virtualenv
desc "Ephemerides calculation program"
homepage "https://kosmorro.space"
url "https://files.pythonhosted.org/packages/8e/62/9c1f4377a50615be7046e3c6112ea7238bc5296d622946a3b360b6807765/kosmorro-1.0.1.tar.gz"
sha256 "7eabe34410ace99d850786665276bf417ed33df998376adbc0af2d1c4431b873"
revision 1
depends_on "[email protected]"
depends_on "certifi"
depends_on "numpy"
depends_on "python-argcomplete"
resource "babel" do
url "https://files.pythonhosted.org/packages/7d/6b/d52e42361e1aa00709585ecc30b3f9684b3ab62530771402248b1b1d6240/babel-2.17.0.tar.gz"
sha256 "0c54cffb19f690cdcc52a3b50bcbf71e07a808d1c80d549f2459b9d2cf0afb9d"
e
How to compute expected payoff of a game with stopping conditions (Markov / DP approach?)
8 January 2026 @ 12:38 pm
A game pays +4 with probability 0.6 and −3 with probability 0.4 each round.
The game stops the first time either two losses occur consecutively or the cumulative payoff reaches +10, whichever happens first.
What is the expected total payoff?
I have a game defined as follows:
Each round:
+4 with probability 0.6
−3 with probability 0.4
The game stops the first time either:
the cumulative payoff reaches +10 or more, or
two losses occur consecutively
I want to compute the expected total payoff at the stopping time, starting from a payoff of 0.
I believe this can be modeled as a finite-state process (e.g., a small Markov chain or dynamic programming setup), where the state needs to track both the current cumulative payoff and whether the previous round was a loss, but I am unsure how to:
define the minimal state space cleanly,
write the recurrence equations for the expected payoff,
and handle the stop
How do I search a number of archived tar files for a specfic file
8 January 2026 @ 12:34 pm
I have a number of dated archives and I want to be able to search each one, but I don't want to have to search each one individually.
The command I started using using is
tar tvfz 20260107.tgz | grep <filename>
I am using the grep because I don't necessarily know the exact path or the whole file name.
I have used tried to use xargs to iterate through the file list but I need a way to report back which filename was successful.
ls *.tgz | xargs -I{} tar tvfz {} | grep <filename>
How can I trigger software on a Windows PC from the internet while the PC is sleeping?
8 January 2026 @ 12:33 pm
I want to build a piece of software that can be invoked remotely from a server on the internet, even when the target linux/(proffered Windows) PC is in sleep mode.
The goal is roughly:
A Windows PC is sleeping (not hibernated or shut down)
A remote server sends some kind of request
The PC wakes up and runs my software (or a service that then runs the software)
I understand that a sleeping PC is not actively running applications, so I’m trying to figure out what mechanisms are realistically possible for this.
My first programming exercises in College
8 January 2026 @ 12:23 pm
this is my first posting questions here in stackoverflow
Machine Problem 1:
Create a program to print your name on the screen.
You may add some info. like Course etc.:
Name: Juan Dela Cruz
Course: BSIT
My code:
#include <stdio.h>
int main(){
printf("Name: scythress"):
printf("Course: BSIT");
return 0;
}
Is there any other approach to solve this problem (I guess this is not a problem) but a unique way of coding this like ascii numbers?
Python ValueError while training Logistic Regression model
8 January 2026 @ 11:48 am
I am trying to train a Logistic Regression model using scikit-learn in Python.
When I try to fit the model, I get the following error:
ValueError: could not convert string to float
Here is the code I am using:
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.fit(X_train, y_train)
I checked my dataset and noticed that some columns contain string values.
How can I preprocess the data to fix this error?
offsetWidth does not match visible element width
8 January 2026 @ 11:29 am
I am running into a very confusing issue when measuring the width of a button using offsetWidth.
I am using Vue 3 and Quasar. I have a q-btn inside the #append-slot of a q-field. I am trying to calculate the width of the button so I can move it to the right of the field.
I am aware that I could simply put the button in a different template, like #after instead of #append and I wouldn't have to worry about calculating the width and moving the button in an absolute position. Sadly in my very specific case that is simply not possible.
Visually, the button looks completely correct and the text I am trying to display on it is rendered on a single line. However, when I measure the width via offsetWidth, the value is incorrect for labels with spaces.
label on button
offsetWidth
hello
45px (correct)
hello world
45
How to configure email alerts for Service Control Policy (SCP) changes in AWS?
8 January 2026 @ 9:42 am
I want to configure alerts in AWS so that I receive an email notification whenever a Service Control Policy (SCP) is modified.
Specifically, I want to be notified when any of the following actions occur in AWS Organizations:
CreatePolicy
UpdatePolicy
DeletePolicy
AttachPolicy
DetachPolicy
These actions should apply only to Service Control Policies (SCPs).
I am looking for a step-by-step procedure to set this up, including which AWS services to use (for example, CloudTrail, EventBridge, SNS, etc.).
Can someone explain the recommended approach and how to configure it correctly?