Random snippets of all sorts of code, mixed with a selection of help and advice.
Does the NPU on the Snapdragon 8 Gen 3 support frequency adjustment?
26 November 2025 @ 10:07 am
I have a rooted Android phone equipped with the Snapdragon 8 Gen 3 chip. I want to adjust the NPU frequency in a similar way to how I adjust CPU or GPU frequencies via sysfs, but I can't find any relevant tutorials. Can the frequency of the Qualcomm NPU be adjusted? If yes, what methods can be used to adjust it?
React Router v7 SPA mode: How to use strict CSP without unsafe-inline when <Scripts /> injects inline module scripts?
26 November 2025 @ 10:05 am
I'm migrating an app from React Router v6 + Webpack to React Router v7 (SPA mode) + Vite and I'm having issues with setting a strict Content Security Policy.
In RR6 I had a normal index.html and loaded my bundle externally:
<script src="/js/admin-panel-bundle.js"></script>
This allowed me to use the following CSP without problems:
<meta http-equiv="Content-Security-Policy"
content="default-src 'self'; style-src 'self' 'unsafe-inline';">
Problem in React Router v7
In RR7 SPA mode, the app must use a root Layout component that generates the entire HTML document.
React Router injects its client entry through an inline <script type="module">, via:
export const Layout = ({ children }: { children: React.React
Error undefined variable when defining in included files
26 November 2025 @ 10:04 am
The following is my directory tree:
├── ansible.cfg
├── censored_inventory.ini
├── group_vars
│ ├── censored-dir
│ │ └── secret_info.yml
│ └── tmp_var.yml
├── host_vars
│ └── tmp_var.yml
├── main.yml
├── tmp_var.yml
├── vars
│ └── tmp_var.yml
└── vault_pass
At first I tried to put sensitive variables in secret_info.yml and encrypt with ansible-vault, then use it in playbook (main.yml) by setting vars_files path in ansible.cfg. However I kept getting error messages with command ansible-playbook main.yml -vvvv:
fatal: [localhost]: FAILED! => {
"msg": "The task includes an option with an undefined variable. The error was: 'try_var' is undefined. 'try_va
Is it possible to set stdin of a process to a pipe and the rest to a TTY device?
26 November 2025 @ 10:03 am
I am trying to spawn a process such that I'll be able to do the following:
Send text to its standard input and specify EOF (by closing the stdin pipe)
Connect the process' stdout and stderr to a TTY device such that its behavior is identical when its run inside a TTY
Initially, I'd launched the process in a pty using creack/pty (Go), but soon after I realized that there's no way to 'send' EOF. I know that EOF is neither a signal nor a character so it can't be sent.
Previously I was able to launch the process with all 3 standard pathaways (stdin, stdout, and stderr) connected to pipes. This worked, but I couldn't get the program to behave as if it had been run inside a TTY.
Take for example, the highlighting behavior of grep.
SAML 2.0 exegesis: Does the spec regulate the handling of IdP sessions?
26 November 2025 @ 9:54 am
The SAML Profiles specification for the Web Browser SSO Profile, line 477ff. says:
The ForceAuthn<AuthnRequest> attribute, if present with a value of true, obligates the identity provider to freshly establish this identity, rather than relying on an existing session it may have with the principal.
But how the identity provider handles "existing sessions" (when it starts or ends one) is not said. More generally, line 391f. says:
It is assumed that the user is using a standard commercial browser and can authenticate to the identity provider by some means outside the scope of SAML.
An indication that such a session might end at all is given by the SessionNotOnOrAfter<AuthnStatement> attribute in the
Why argparse treats unknown arg as a known arg in case unknown arg name is part of a known arg name? [duplicate]
26 November 2025 @ 9:53 am
I have a Python project that uses argparse. I noticed an unwanted behavior of argparse when parsing some unknown arguments.
I use both known and unknown arguments. I have a parameter --list-installed. Now, if I pass the --list parameter, it is treated as known, while it should be unknown.
See this code:
import argparse
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("--list-installed", action="store_true")
def parse_options(options: list[str]) -> None:
args, unknown_args = parser.parse_known_args(options)
print("input options:", options)
print(" args:", args)
print(" unknown_args:", unknown_args)
print()
parse_options(["kcalc"])
"""
input options: ['kcalc']
args: Namespace(list_installed=False)
unknown_args: ['kcalc']
"""
parse_options(["kcalc&q
Is it possible that the assertion can fail with memory_order::relaxed to transfer pointers?
26 November 2025 @ 9:51 am
Consider this example:
#include <iostream>
#include <atomic>
#include <thread>
#include <cassert>
int main(){
std::atomic<int> val = 1;
std::atomic<std::atomic<int>*> ptr;
auto t1 = std::thread([&](){
auto v = val.load(std::memory_order::relaxed);
while(true){
if(v==-1){
v = val.load(std::memory_order::relaxed);
continue;
}
if(val.compare_exchange_strong(v,v+1,std::memory_order::acquire,std::memory_order::relaxed)==true){
break;
}
}
ptr.store(&val,std::memory_order::relaxed); // #1
});
auto t2 = std::thread([&ptr](){
std::atomic<int>* val_ptr = ptr.load(std::memory_order::relaxed); // #2
while(val_ptr==nullptr){
val_ptr = ptr.load(std::memory_order::relaxed); // #3
}
Handling YYYY-MM-DD as UTC
26 November 2025 @ 9:39 am
I use this package and my function is this:
const formatDate = (
date: string | Date,
dateFormat: string = 'PP p',
timezone?: string,
) => {
const zoneDate = toZonedTime(date, timezone ?? 'UTC')
console.log(zoneDate)
return format(zoneDate, dateFormat, { locale: getDateLocale() })
date is coming from the database and in the database we store everything in UTC. However, for a birthday, we just store: 2025-11-21.
Now, when the timezone in toZonedTime is UTC, this happens:
Thu Nov 20 2025 23:00:00 GMT+0100 (CET)
The AI said that, without the time/zimezone information on '2025-11-21', toZonedTime treats the 2025-11-21 as being local timezone and then shifts the timezone to UTC, re
How do I make a matplotlib bar graph scale with the amount of items?
26 November 2025 @ 9:17 am
I am working on a small project and it is my first time using matplotlib, and I am struggling with how to make my bar graph look better with more inputs. The whole idea of the program is to read text documents and show the characters from most used to least used. It's a tool I decided to make for myself to help me with designing my split keyboard layout.
The problem is the bigger the text document, the worse the bar graph looks. It always seems to be created at the exact same size so everything gets smushed. I have some screenshots of a few of my tests.
best case scenario
bad case
worst case
and this is the code that actually makes the graph
names = list(sorted_count.keys())
values = list(sorted_count.values())
How to skip debounce on the first keystroke only?
26 November 2025 @ 9:14 am
I have a simple debounce implementation using `useEffect` and `setTimeout` that delays updating a `value` state by 1 seconds after the user stops typing in an input:
import { useEffect, useState } from "react";
const useDebounceInput = (input: string): string => {
const [value, setvalue] = useState<string>(input);
useEffect(() => {
const timer = setTimeout(() => {
setvalue(input);
}, 1000);
return () => {
clearTimeout(timer);
};
}, [input]);
return value;
};
export default useDebounceInput;
This works fine for debouncing, but I want to change the behavior so that:
On the very first keystroke (when the input goes from empty → non-empty), setValue(input) should happen immediately (no 1000 ms delay).
All subsequent changes should still be debounced by 1 seconds as before.