StackOverflow.com

VN:F [1.9.22_1171]
Rating: 8.5/10 (13 votes cast)

Random snippets of all sorts of code, mixed with a selection of help and advice.

rust: How to propagate errors across task boundaries in an ergonomic way?

15 March 2026 @ 10:17 pm

I am writing a small cli application to learn rust and did start my error propagation with a lot of Result<_, Box<dyn std::error::Error>>. This is quite flexible and works nicely. Now I tried to introduce async/await code into my program. The first thing to learn was that std::error::Error does not imply Send. But my program needs to do some error propagation across task boundaries, for example when I do tokio::spawn(foo()). So the naive solution is to just constraint my return types to Result<_, Box<dyn std::error::Error + Send>> where ever necessary. But now I am hitting some types that can not be automatically coerced to dyn std::error::Error + Send. Specifically I have these cases which work without Send but not with Send: Err("something".into()) std::io::Error

Possible determine avifRGBFormat when decoding with libavif?

15 March 2026 @ 10:00 pm

When encoding an image using libavif, you can set the format, with something like avifRGBImage rgb; avifRGBImageSetDefaults(&rgb, image); rgb.format = AVIF_RGB_FORMAT_GRAY; avifImageRGBToYUV(image, &rgb); avifEncoder *encoder = avifEncoderCreate(); avifEncoderAddImage(encoder, image, 0, AVIF_ADD_IMAGE_FLAG_NONE); However, I can't figure out how to determine the format when decoding. You might expect the corresponding call to avifImageYUVToRGB(image, &rgb) to set format on rgb, but it doesn't seem to. I'm starting to wonder if avifRGBFormat is just used to encode the data, and not actually a property that is included in the final data. I know there is alphaPresent on avifDecoder, but that's not a completely distinguishing. Is it poss

Correct way to track pressed keystates on focusing a window

15 March 2026 @ 9:52 pm

What is the correct way to track the keys that are currently pressed, at the time that a window is being focused? More specifically, a way that guarantees that those keys that are reported as "pressed" will properly receive a WM_KEYUP message when released? Context I have an application that processes WM_KEYDOWN and WM_KEYUP (and the SYSKEY-equivalents) to pipe keys into a custom input-handling system. When the window loses focus, all keys should release, so I can just use WM_KILLFOCUS to clear out all keys in my input handler. The problem arises with trying to re-track keys, that are held at the time that the window gains focus. I can intercept WM_SETFOCUS, and I tried different ways of checking for checking pressed keys (GetAsyncKeyState/GetKeyState/GetKeyboardState). Those do the right thing most of the time, however there is situations where keys will get stuck - that is, a key will be set to "pressed" inside WM_SETFOCUS,

ValueError: shapes mismatch when combining Re-ID Cosine distance and IoU matrices for custom MOT tracking

15 March 2026 @ 9:39 pm

I am building a custom Multi-Object Tracking (MOT) system using Python, OpenCV, and TensorFlow. My goal is to track people and perform real-time clothing recognition. To prevent ID switches when a person turns around (which drastically changes their clothing features), I am implementing a custom matching cascade similar to DeepSORT. I want to associate existing tracks with new detections using a weighted cost matrix that combines the Re-ID feature cosine distance and the bounding box IoU: enter image description here However, I am encountering a ValueError related to shape broadcasting when calculating the final cost matrix. The Code: Here is the minimal reproducible example of my matching logic. track_features is a history bank of features, and det_features are extracted from my TensorFlow model. import numpy as np from sci

NextAuth v5 (Auth.js) + Authentik: signOut doesn't fully log out the user

15 March 2026 @ 9:31 pm

I'm using NextAuth v5 with Authentik as an OIDC provider in a Next.js App Router app. When a user clicks "Sign out", I call `signOut({ redirect: false })` and redirect to `/login`. The NextAuth session cookie is cleared, but the Authentik browser session persists — if someone enters the same email on the login page, Authentik auto-authenticates them without sending a new magic link. I've tried the OIDC end-session redirect approach: await signOut({ redirect: false }); const logoutUrl = new URL("https://auth.example.com/application/o/my-app/end-session/"); logoutUrl.searchParams.set("id_token_hint", idToken); logoutUrl.searchParams.set("post_logout_redirect_uri", "https://myapp.example.com/login"); redirect(logoutUrl.toString()); But Authentik shows its "Default Invalidation Flow" UI instead of redirecting to `post_logout_redirect_uri`. How do I fully log a user out of both NextAuth a

How should toString methods be formatted

15 March 2026 @ 9:30 pm

I lately learned about the toString method and its uses. From what I've been taught, the toString method is used as a concise representation of an object as a string of characters, usually used as a debugging tool. My question is how should I format my toString methods so they would provide a concise reflection of the object's values at the moment? Let's e.g. say that I have the next classes: abstract public class Vehicle { public FuelTank fuelTank; public String model; @Override public String toString() { return ??? } } public class Truck extends Vehicle { public Cargo cargo; public Truck() { fuelTank.addFuel(5); model = "Strong Truck"; cargo.maxWeightInKG(5); } @Override public String toString() { return super.toString() + ??? } } public class Garage() { Truck truck; @Override public String t

Zig Zag horizontal lines

15 March 2026 @ 9:28 pm

How to write, horizontal lines from bottoms ( LL LH ), tops (HH HL) ? It gives information when it crosses (down and next up) bar. It draws horizontal line from bottoms to crossing bar and gives me information. The x,y coordinate of start line is stored, that I may use it. Below is similar code, with functionality which I would like to have in code below. https://pl.tradingview.com/v/iD9mSVdF/ https://pl.tradingview.com/v/Cb5QhBAl/ // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © tgh //@version=5 indicator('funkcja', 'funk', overlay=true, precision=2, max_bars_back = 1000) showHHLL = input(defval=true, title="showHHLL?") showHHw = input(defval=true, title="showHHw?") // ukrywa i pokazuj

Visual Studio 2026

15 March 2026 @ 9:27 pm

I just downloaded the software, and I want to start learning to code in C++. Problem I cannot figure out how to pull up the console/terminal. The longer it takes, the more stupid I feel. Any thoughts. This is how my screen currently stands.

ModuleNotFoundError: No module named 'pkg_resources' With Django Project

15 March 2026 @ 9:26 pm

ModuleNotFoundError: No module named 'pkg_resources' when trying to run Django Application. This error simply indicates a version mismatch. Django support may not work with the latest Python versions because support still remains in earlier versions of python. So all you can do is create a virtual environment that is tied to a previous version of Python such as 3.11.

Why does initializing std::atomic_flag with false work on GCC and Clang but not Visual Studio?

15 March 2026 @ 8:45 pm

Here is the code: #include <atomic> std::atomic_flag bShouldStop = false; int main() { } Compiles on GCC and Clang but not on Visual Studio, gives errors: <source>(6): error C2440: 'initializing': cannot convert from 'bool' to 'std::atomic_flag' <source>(6): note: 'std::atomic_flag::atomic_flag': no overloaded function could convert all the argument types Link to Godbolt.