Random snippets of all sorts of code, mixed with a selection of help and advice.
Getting Input without Blocking Mode in C
7 December 2025 @ 6:34 pm
I was assigned a homework 3 weeks ago, and I presented it two weeks ago.The homeworks was that making an embedded project working linux environment by abstracting some functions, like:
int uartRead(void *char, int len) {
int result = write(1, data, size);
return result;
}
int uartRead(void *data, ssize_t size) {
int result = read(0, data, size);
return result;
}
The project gets some prompts from user, and making operations according to the input, like configuring sensor, turning-on/off sensors, etc.
In my project, since I am using read function like below:
while (1)
{
// something
uartRead(prompt, 15);
// something
}
my project is working in blocking mode. I was asked, however, how to do that even print out sensor measurements periodically even if user doesnt prompt any input.
I proposed thread-way, one thread expecting input while the other handles outputting. I am however wond
How to make a video post with Facebook Graph API
7 December 2025 @ 6:32 pm
I am finding the documentations super confusing and all the paths lead to various errors.
What I've tried,
Path 1:
Upload video using the ${page_id}/videos edge and pass the received Id to POST:${page_id}/feed
This results in an auth error. And after some research I came to understand that /feed dosen't accept video files
Path 2:
Resumable API:
Upload using https://developers.facebook.com/docs/video-api/guides/publishing#resumable-upload. This ends with an error in video_status. But this same file can be posted to FB directly, and to IG as reels (file has mimetype video/mp4)
{
"status": {
"video_status": "error",
"uploading_phase": {
"status": "complete",
"bytes
set PUPPETEER_SKIP_DOWNLOAD env variable but still
7 December 2025 @ 6:31 pm
try to install a node project in a mac, but keep getting a puppteer installation error. I don't know why the installation fails, simply I just want to skip the installation
node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/puppeteer: Running postinstall script, failed in 1.1s
.../node_modules/puppeteer postinstall$ node install.mjs
│ Error: ERROR: Failed to set up chrome-headless-shell v127.0.6533.88! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.
│ at file:///Users/cc/Downloads/cua/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/puppeteer/lib/esm/puppeteer/node/install.js:84:27
│ at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
│ at async Promise.all (index 1)
│ at async downloadBrowser (file:///Users/cc/Downloads/cua/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/puppeteer/lib/esm/p
Troubleshooting: A single regular expression matching nested braces usable for java and perl
7 December 2025 @ 6:24 pm
I have a regular expression in an extension of java by florian ingerl
to parse a latex command,
\\\\DocumentMetadata(?<docMetadata>\\{(?:[^{}]|(?'docMetadata'))*\\})
but the important thing is that it allows nested braces.
The concrete string to be matched is
\DocumentMetadata{pdfversion=1,7,pdfstandard={a-3b,UA-1}}
but earlier or later time comes where deeper nesting is required.
To that end, I use the extension com.florianingerl.util.regex.MatchResult of the builtin java regular expressions.
Now I want to use latexmk for latex which is in Perl and need to adapt .latemkrc which is just Perl code.
So i need the same regular expression or at least something similar i can automatically transform.
Up to now each expression worked in both worlds. But this one does not match in Perl.
Maybe there is some extension whi
Why am I seeing a performance hit in a kind k8s cluster with port forwarding to a simple web worker?
7 December 2025 @ 6:22 pm
I'm trying to determine why there is a performance difference between an application serving requests from within a kind k8s cluster versus the application just running on the local host. When I run a load test of the application on the local host, I see exactly the type of result I expect. But when I run the same application in the cluster I consistently see dropped requests. Why am I seeing a performance hit in a kind k8s cluster with port forwarding to a simple web worker? And as a bonus, what could I do to improve the situation?
Setup
Commands I use to provision the kind cluster and deployment:
$ kind create cluster --config kind-multi-node.yaml
$ kind load docker-image myapp:v0.0.1
$ kubectl create deployment myapp --image=myapp:v0.0.1
$ kubectl expose deployment myapp --type=LoadBalancer --port=8000
$ cat kind-multi-node.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
How to play a pitched sound n times?
7 December 2025 @ 6:10 pm
I'm making a game and am using WebAudio API for audio.
I want to play a given sound exactly n times, with a different pitch than normal.
As long as I don't change the pitch, i.e. keep playbackRate = 1.0, everything is working fine.
However, with a different pitch, be it lower/slower (<1) or higher/faster (>1), I'm facing a different behavior between browser, Firefox against all others.
With Firefox, it works like I want. Regardless of the pitch, the sound is always played exactly as many times as wanted.
With other browsers (Chrome/Safari/Edge), the sound is cut in the middle, and isn't played the wanted number of times. If the pitch is higher, it is played more times than desired, and with lower pitch, it's played less times.
The problem is the interpretation of the third parameter of AudioBufferSource.start(), the duration the source has to be played.
Firefox takes the playbackRate into account and adjust the real duration according
How to answer to an SMB DeviceIOControl request?
7 December 2025 @ 6:09 pm
I am implementing an SMB server in c# using https://github.com/TalAloni/SMBLibrary
Now when I try to open the share using Samba client, it tries to negotiate the protocol details. Problem is, the DeviceIOControl function is extremely generic and it's hard to find the specific data format for your actual problem.
Samba client sends:
DeviceIOControl(handle=(null),
ctlCode=0x140204(devicetype=14, accessmode=0,
function=81),inputLength=28, maxOutputLength=24)
StructSize=0, DialectCount=0, ClientSecMode=0xBE4D,
ClientCaps=0x48F4C728, ClientGuid=..., Dialects=[]
this ctlCode is probably called FSCTL_VALIDATE_NEGOTIATE_INFO
What does this data actually mean and how do I answer to it?
The AI gave me this structure for output, but it's bigger than what samba client provided for return, so it breaks.
0 2 StructureSize
2
nswag generates 200 instead of 201
7 December 2025 @ 6:04 pm
I have a .NET 10 API, part of this API looks like this:
"/api/Users": {
"post": {
"tags": [
"Users"
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CreateUserDto"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/CreateUserDto"
}
},
"application/*+json": {
"schema": {
"$ref": "#/components/schemas/CreateUserDto"
}
}
},
"required": true
},
"responses": {
"201": {
Web form repeatedly resubmits itself after submission by Apple users
7 December 2025 @ 5:41 pm
I have a .php file on the web which contains an html form. That form (in case it's relevant) calls the original .php file when a user presses "Submit". That is, the file is called newform.php and the form within that file looks like this:
<form method=POST action="newform.php" id="trythis">
...
<input type="submit" value="Submit"></p>
</form>
Mostly, this works fine. Occasionally, though, a user will leave the browser window open after submitting the form, which then re-submits itself anywhere from a few times a day to a few times a week until that window gets closed (so I get several duplicate submissions from the same user).
I have enough data to be sure of these things:
This is not caused by users repeatedly hitting the submit button. It is also not caused by users refreshing the page. In many cases, the users are not
Understanding error handling with Promise and async functions
7 December 2025 @ 5:38 pm
The code below has a bug I can't understand.
I have 2 implementations of consumer. The first one (consumer) works fine when the callback Promise is rejected, and the error is caught by the outer main catch.
On the other hand consumer2 throw an unhandled exception UNLESS the following catch is added in the for each loop
p.catch(err=>'this catch is needed with consumer2 to avoid unhandled error propagating to main thread')
What's the difference between consumer and consumer2 here? I thought I could remove the Promise wrapper because async automatically returns a Promise and rejects it when an error is thrown. Plus I thought that the promise in the promises array fetched by consumer gets handled in try catch statement.
async function mapAsync(iterable, concurrency, cb) {
let promisees = []
let consumers = []
let results = Array(iterable.length)
if (concurrency > iterable.length)
concurrency = iterable.length
asy