Random snippets of all sorts of code, mixed with a selection of help and advice.
A way for a function to accept multiple types of 2d-collections (rectangular matrix) as parameter like 2d-array or array of vectors. 2d-span? mdspan?
21 May 2026 @ 10:42 pm
AFAIK, the next collections are memory contiguous:
C-style array T[N]
Array <std::array<T, N>
Vector std::vector<T>
And the next 2-dimensional collections would also be memory contiguous:
C-style array of arrays (2d array) T[M][N]
Array of arrays (2d array) std::array< std::array<T, N>, M>
i.e. that a vector of vectors (2d vector) std::vector< std::vector<T> > would not be memory contiguous (because each inner vector, rows/sub-vectors, can have different size?).
But what about the next 2-dimensional collections?
std::array< std::vector<T>, N >
std::vector< <std::array<T, N> >
An example of work case would be about a function with a parameter that could receive mu
Is it bad practice to programmatically add submodules to sys?
21 May 2026 @ 10:26 pm
I made a small Python module that has a custom _all_ and want to group certain objects into submodules. More specifically, I want the primary functionality of my code accessible through * imports and also want the types I use internally to be accessible in bulk but not necessarily with the rest of the module. So something like this :
from mymodule import * # Primary
from mymodule.types import * # Extra
The first thing that came to mind was grouping with different files, but since it's such a small module that feels excessive. When researching it, I learned it was possible to do it all in one file by instantiating a module object using types.ModuleType and forcing that directly into sys.modules. But to me this seems quite messy and I'm honestly surprised it's even possible. Is this always bad practice, or are there situations where it's acceptable?
VSCode Flutter - over 750 problems reported in build/.../SourcePackages files after flutter 3.44 upgrade
21 May 2026 @ 10:17 pm
I've just upgraded flutter to the latest 3.44 version and my Problems tab is reporting a huge number of issues in files in build/macOS/SourcePackages and build/iOS/SourcePackages; e.g.
build/macos/SourcePackages/firebase_auth-6.5.1/example/lib/auth.dart
These are obscuring the problems I want to see in my code.
Does anyone have any idea why I'm suddenly seeing all these now and what I can do about it?
I can't see an option to just report problems in my code.
Delete line if substitution would leave it empty
21 May 2026 @ 10:00 pm
Just as a very small example, lets say I have the following:
s/foo//g
and I run with it perl -p and the following input:
foo foo foo
foo bar
bar bar
foo bar bar
foo
This would output:
bar
bar bar
bar bar
The lines that only consisted of foo are now blank (aside from the spaces that were between them, if any). For these lines, I would like to eliminate them, but leave any originally blank lines alone.
One way I thought to do this would be to replace foo with some specially recognized string instead, say X, and then any line only consisting of Xs gets deleted, but choosing the right string (instead of X) would be a challenge for general input. Also, then it goes in two passes, which is less fun.
Use Unordered_Map or Vector with conversion to Unordered_Map to fill a File->FileInfo structure for file manager
21 May 2026 @ 8:56 pm
I'm writing a file manager which needs to find and show files in the current path based on the filename-based Hash Map structure
file1.txt --> FileInfo
file2.txt --> FileInfo
file3.txt --> FileInfo
The reason it can't be just an std::vector (e.g. a list of FileInfos) is because quick lookups are required on selecting file(s). For example upon selecting items, I need to compute the total selection size and show it in the status bar, which requires quick access to the individual FileInfo by filename. Not all columns may be visible in the UI and I can't grab those values from anywhere other than the linked FileInfo.
The simple approach is
std::unordered_map<std::wstring, FileInfo> contents;
and on exploring the path, after populating each FileInfo, I do:
contents.emp
Cannot generate dependency in my Spring project
21 May 2026 @ 7:57 pm
I am using IDEA Ultima.I cannot find dependency in my POM when i hit "generate" and type "spring-boot-devtools". How to fix it?
I tried to ask Chat-GPT and followed it recommendations - renewed JDK up to latest version, but nothing changed.
OpenGL batch renderer shows blank window with clear color and no OpenGL errors
21 May 2026 @ 6:37 pm
I'm working on a project that I'd like to implement a batch renderer for.
I've tried enabling debug mode and have not been receiving any OpenGL messages let alone errors. I've tried using RenderDoc to inspect the program while it is running with no luck as I'm somewhat unfamiliar with what the program should look like in RenderDoc. As far as I can tell looking at the visual studio debugger my vertices are being correctly packed and I'm not getting any OpenGL errors from any of the functions I'm calling.
Here is my codebase; it runs and displays a blue colored window. It should display that along with a red rectangle in the center of the screen, but I see no such rectangle.
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <spdlog/spdlog.h&g
How do I direct data from an array to alsa pcm in C?
21 May 2026 @ 4:53 pm
I want to play a mono wav file from memory rather than from the original file to reduce latency. I have found various C code examples that parse wav file data so I now have all the header information and an array containing the signed 16bit samples for the file I want to use. I have found this C code to playback wave files from the command line.
* Simple sound playback using ALSA API and libasound.
*
* Compile:
* $ cc -o play sound_playback.c -lasound
*
* Usage:
* $ ./play <sample_rate> <channels> <seconds> < <file>
*
* Examples:
* $ ./play 44100 2 5 < /dev/urandom
* $ ./play 22050 1 8 < /path/to/file.wav
*
* Copyright (C) 2009 Alessandro Ghedini <[email protected]>
* --------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* Alessandro Ghedini wrote this file. As long as you retain this
* notice you can do whatever you want with this stuff. If we
* meet
How to add chars to a malloc buffer?
21 May 2026 @ 3:25 pm
I am trying to read the contents of a file and store it into string.
if ((f = fdopen(fd, "r")) != NULL) {
// Go to end of file
fseek(f,0,SEEK_END);
// Get size
sz = ftell(f);
// Go back to start
rewind(f);
char *string = (char *) malloc(sz*sizeof(char));
while ((ch = fgetc(f)) != EOF) {
//putchar(ch);
}
}
Glassfish 5.1 EE 8 (not Jakarta) problem with waffle library to perform HTTP Basic Authentication [closed]
21 May 2026 @ 5:01 am
When I typed username and password in Google Chrome pop-up I got an exception:enter image description here
java.lang.AbstractMethodError: com.sun.jna.Structure.getFieldOrder()Ljava/util/List;
at com.sun.jna.Structure.fieldOrder(Structure.java:952)
at com.sun.jna.Structure.getFields(Structure.java:1006)
at com.sun.jna.Structure.deriveLayout(Structure.java:1172)
at com.sun.jna.Structure.calculateSize(Structure.java:1097)
at com.sun.jna.Structure.calculateSize(Structure.java:1049)
at com.sun.jna.Structure.allocateMemory(Structure.java:403)
at com.sun.jna.Structure.<init>(Structure.java:194)
at com.sun.jna.Structure.<init>(Structure.java:182)
at com.sun.jna.Structure.<init>(Structure.java:169)
at com.sun.jna.Structure.<init>(Structure.java:161)
at com.sun.jna.platform.win32.Sspi$SecHandle.<init>(Sspi.java:496)
at com.sun.