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.

How should i reduce the memory usage on the web page while redering streaming data through websockets

6 April 2026 @ 5:43 am

i am using fastapi as backend and react for frontend currently , i'm renderind data which is a stream coming from websockets . and then i'm using visualization in frontend to render certain no.of records to display that data in a table format. if i sroll down or up, the data will be renderd in viewport height in the table. But the problem is , after some point of time(rendering 1GB of data) , i am getting high memory usage in the webpage.But i have render 8GB of data. so can you please help me ,how should i achieve less memory usage, while maintaing my above functionality !? except indexed db and gzip methods! are there any other recomended ways !?

Best practice for validating form error messages across different browsers and environments in automation tests

6 April 2026 @ 5:42 am

I’m working on automating UI tests for form validations, and I’ve noticed that validation messages can differ across browsers (Chrome, Firefox, Safari), as well as between headed and headless modes, and even across environments. For example, native browser validation messages (like required field errors) are not always consistent in wording or format depending on the browser or execution mode. This raises a question about the best approach for automation: Should we strictly verify the exact validation message text? Or is it better to validate the behaviour (e.g., field is marked invalid, submission is blocked, error state is shown)? How do teams usually handle cross-browser inconsistencies in such cases? Is it recommended to avoid native browser validation altogether and rely on custom validation messages? Context: UI automation using tools like Pl

OpenHTMLToPDF custom TTF fonts not applied (NotoSansArabic). It falls back to default font

6 April 2026 @ 5:26 am

I'm generating a PDF using OpenHTMLToPDF (PdfRendererBuilder) in a Spring Boot app, and my custom fonts (ttf) are not being applied. What am I missing for OpenHTMLToPDF to properly apply custom TTF fonts registered via useFont()? I've been struggling a few days on this I'm trying to use NotoSansArabic (Regular + Bold), but the PDF still renders with a fallback font Font files (in resources): assets/fonts/NotoSansArabic-Regular.ttf assets/fonts/NotoSansArabic-Bold.ttf // From the builder class (rest was omitted) val builder = PdfRendererBuilder() .useFastMode() .withHtmlContent(html, null) .toStream(outputStream) builder.useFont( { ClassPathResource("assets/fonts/NotoSansArabic-Regular.ttf").inputStream }, "Noto Sans Arabic", 400, com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.FontStyle.NORMAL, true ) builder.useFont( { ClassPathResource("assets/fonts/NotoSansArabi

How to safely remap (resize) mmap in Python while other threads are reading?

6 April 2026 @ 5:25 am

I am building segment-based log storage system in python using mmap module in python. I want to prioritize: Zero copy as much as possible Concurrent readers dynamic growth of underlying file Current Approach: class Entry: """ Owned by SegmentMemory class, provides read and write guarantees. """ def __init__(self, meta:SegmentMeta, init_segment_size, segment_size_inc) -> None: self.__mmap: mmap.mmap | None = None self.__file_obj: _io.BufferedRandom | None = None self.__capacity: int|None = None self.__filepath = meta.get_filepath() self.__mutable:bool = meta.is_mutable() self._refcount:AtomicInt = AtomicInt(0) self._lock: threading.Lock = threading.Lock() self.init_segment_size = init_segment_size self.segment_size_inc = segment_size_inc def load(self)

Ai-Assisted automation anomaly detection

6 April 2026 @ 5:22 am

I'm building an ML-based anomaly detection system that compares failed test execution logs against passed test execution logs to automatically find where and why a test failed. The goal is to reduce a 20K+ token log down to a few key anomalies, then pass those to an LLM for root-cause explanation. The problem: model doesn’t understand order and context, so it gets confused and flags normal data as abnormal Data Structure:- STEP START Set device config STEP START Load the configuration file STEP END Load the configuration file STEP START Set the device configuration (API call) ----------- API Request ----------- URL : https://example.com/createopaquedata Method : POST Body : rotuuid=000a...&value=%7B%22info%22%3A+%7B%22version%22... (2000+ chars) ----------------------------------- ----------- API Response ---------- Status : 200 Body : {"result":"OK","uui

Failing to check

6 April 2026 @ 5:13 am

Basically, im trying to make a whitelist where only certain roles can use this command, and it logs a role as being "theirs", I have tried debugging by printing roles and stuff and now It is not even going through the check, like it will print the admin table, but then dosent move onto the check where it adds to the db/sends a message, it does nothing. cogs/roles.py import discord from discord.ext import commands from utils.databases import roles_db from utils.variables import admin class Roles(commands.Cog): def __init__(self, bot): self.bot = bot @commands.hybrid_group() async def custom(self, ctx: commands.Context): return @custom.command(name="register", description="Registers a custom role to a user") async def register(self, ctx: commands.Context, role: discord.Role, member: discord.Member): print(admin) if any(r.id in admin for r in c

I made a kernel module that hooks systemcall but it can't be compiled

6 April 2026 @ 5:03 am

What's the problem? It's not compiling. The content of the code is to replace the function in the systemcall array with the function I created, print out "Hooked! Opening file" in the kernel, and return the original real_open function. *cpu is arm (using raspberry pie). #include <linux/module.h> #include <linux/kernel.h> #include <linux/syscalls.h> #include <linux/kallsyms.h> #include <linux/kprobes.h> asmlinkage long (*real_open)(const char __user *, int, umode_t); asmlinkage long my_open(const char __user *filename, int flags, umode_t mode){ char buf[256]; copy_from_user(buf, filename, 255); printk(KERN_INFO "Hooked! Opening file:%s\n", buf); return real_open(filename, flags, mode); } typedef int (*set_memory_func)(unsigned long addr, int numpages); int enable_write(unsigned long addr, int numpages){ set_memory_func set_rw; struct kprobe kp = {

Key counter in C, how to pause and resume for key logging

6 April 2026 @ 5:03 am

Hi I have written a code for key counting but I don't know how to pause it and resume it, can someone help to modify my code? example like I press F1 then to pause the key counting, then if I press again F1 to resume to key counting how to do it? please help if anyone good in c programming #include <stdio.h> #include <windows.h> #include <winuser.h> HHOOK hook; LPMSG msg; int counter = 0; void Stealth() { HWND Stealth; AllocConsole(); Stealth = FindWindowA("ConsoleWindowClass", NULL); ShowWindow(Stealth,SW_SHOWNORMAL); } LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam){ if (wParam == WM_KEYDOWN) { counter++; printf("Current count: %d\n", counter); } return 0; } int main() { Stealth(); hook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, NULL, 0); if (hook != NULL) puts("All is good") ;

Recommended architecture for ASP.NET backend with JWT auth and Next.js SSR frontend (future mobile/desktop clients)?

6 April 2026 @ 4:36 am

I’m building a system with an ASP.NET backend that uses JWT-based authentication and a Next.js frontend with server-side rendering (SSR). Currently: Backend: ASP.NET (JWT auth) Frontend: Next.js (SSR) In the future, I plan to add: Mobile clients (e.g., React Native or native apps) Desktop clients I’m trying to choose a scalable and maintainable architecture that works well across all these clients. Some specific questions: Is using a Backend-for-Frontend (BFF) pattern recommended in this scenario? How should authentication be handled across SSR (Next.js) and other clients (mobile/desktop)? Should the Next.js app communicate directly with the ASP.NET API, or go through an intermediate layer (BFF)? What are the trade-offs between a single API vs. multiple BFFs for different clients?

Samsung Gallery edit/save leaves video in MediaStore.IS_PENDING=1 state

6 April 2026 @ 3:35 am

I’m encountering an issue where videos edited in Samsung Gallery become permanently inaccessible to third-party apps. Problem After editing a video in Samsung Gallery and tapping “Save” (overwrite): • The video does not appear in the “Videos” tab of any media picker • The video appears in Gallery under “Collections > Camera” • External apps cannot open the file • MediaStore shows IS_PENDING=1 and it never resets Reproduction steps 1. Open Samsung Gallery 2. Select a video from camera roll 3. Edit the video 4. Tap “Save” (overwrite) 5. Open a third-party app and try to access the video Result: • Video missing from “Videos” tab • Visible in Gallery, but cannot be opened externally val projection = arrayOf(MediaStore.Video.Media.IS_PENDING) val cursor = contentResolver.query( MediaStore.Video.Media.EXTERNAL_CONTENT_URI, pr