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.

Laravel 11 add custom attribute of age in model

8 February 2026 @ 10:12 pm

In Laravel 11, I want to add a custom attribute named age in a Citizen model. It should calculate the age of a citizen from the birthdate. public function getAgeAttribute() { return $this->birthdate->diffInYears(\Carbon\Carbon::now()); } I have tried the code above but it does not work, Any ideas?

Plot objects it vispy on top of an image

8 February 2026 @ 10:09 pm

Afternoon, I'm trying to plot some objects on top of an image in Vispy, but somehow, they always get plotted behind it. For what i've read, the order in which everything is added in vispy should determine the layer position, but it seems my image always gets on top of everything. First i add the image to the canvas with: Image = scene.visuals.create_visual_node(visuals.ImageVisual) I = Image(parent=sc, interpolation="nearest",method='subdivide') I.set_data(img) Where img is the image path and sc is the canvas view, then, any object added, for ex, a line: Line = scene.visuals.create_visual_node(visuals.LineVisual) L = Line(parent=sc) L.set_data(line, color=color,width=width, connect=connect) And it gets plotted behind the image Is there anyway, any arg or similar, to set an object to be placed in front of the previous ones, or to keep the image always on "backgr

OpenCv's cv.VideoWriter output is BGR, even though I convert each frame to RGB before writing them

8 February 2026 @ 9:54 pm

My code records some video, but in the video blue and red seem to be switched. import cv2 as cv import numpy as np import asyncio #video assemble async def makeVideo(frames, w, h): output = 'output_video.mp4' fourcc = cv.VideoWriter_fourcc(*'mp4v') videowr = cv.VideoWriter(output, fourcc, 30, (w, h)) for frame in frames: videowr.write(cv.cvtColor(frame, cv.COLOR_BGR2RGB)) videowr.release() return output #video analysis async def analyse_vid(): #frames list frames = [] protection_mode_active = True cap = cv.VideoCapture(0) backSub = cv.createBackgroundSubtractorMOG2() if not cap.isOpened(): print("Cannot open camera") return width = int(cap.get(cv.CAP_PROP_FRAME_WIDTH)) height = int(cap.get(cv.CAP_PROP_FRAME_HEIGHT)) print(f'Width: {width} Height: {height}') last_warning_time = asyncio.get_event_loop().time() # Track th

Self hosted feed generator invalid feed generator service details

8 February 2026 @ 9:53 pm

I am implementing a self hosted feed generator for bluesky. I ran the script to register it with no errors, but when I go it in bsky.com, I get the following: Hmm, the feed server appears to be misconfigured. Please let the feed owner know about this issue. Message from server: invalid feed generator service details in did document: did:web:usa-congress-wind-34f9235d0865.herokuapp.com My /xrpc/app.bsky.feed.describeFeedGenerator URI returns the following: { "did":"did:web:usa-congress-wind-34f9235d0865.herokuapp.com", "feeds":[ { "uri":"at://did:web:https:usa-congress-wind-34f9235d0865.herokuapp.com/xrpc/app.bsky.feed.getFeedSkeleton" }]} My /xrpc/app.bsky.feed.getFeedSkeleton URI does return data. { "cursor":"feed:535,t:2026-02-06T00:37:38.307000Z,post:25803105", "posts":[ "at

WebDAV server that respects user file permissions

8 February 2026 @ 9:47 pm

I am looking for a WebDAV server on Linux that takes user permissions into account, meaning that users should log in with their credentials (Linux username and password) and that they should only be able to read and write file they have access to (via Linux permissions or ACLs), like IIS does on Windows. From what I understand the only way to enforce filesystem permissions correctly (access, ownership, etc) is to have the web server process run as the logged in user. My best bet was to use Apache httpd, with WebDAV enabled, Basic Auth, with PAM for authentication, and the mod-ruid2 module that can dynamically switch the user of the httpd process to the user returned by PAM. But it turns out that mod-ruid2 is no longer maintained and that no replacement exists. What other options exist?

jOOQ: Is it ok to create DSLContext per HTTP request?

8 February 2026 @ 9:45 pm

From a performance perspective, does it make sense to create a new dslContext per HTTP/API request? I need to set some request specific session variables (like user_id), for dslContext but I'm worried doing this will put too much pressure on the DB or Connection pool.

Graph API 401 Unauthorized for Guest Users on Shared Files (Works in Lab, Fails in Prod)

8 February 2026 @ 9:43 pm

I have a web application (SPA) that accesses SharePoint Online files on behalf of a logged-in user (Delegated permissions). The application does not use a Service Principal for file access; it relies entirely on the user's context. The User: An external Guest user (B2B) invited to the tenant. The Action: The user logs in, and the app attempts to resolve a specific SharePoint sharing link (sent via "Specific People" sharing) using the Microsoft Graph API. The Issue: The API call returns 401 Unauthorized (Code: accessDenied) in the Production tenant. The Mystery: The exact same code, configuration, and user setup works perfectly in my Lab tenant. When opening the link directly - not through my web app, it works! I first have to confirm my email, click on 'Next', but then all is good,

How to use async function in the router?

8 February 2026 @ 9:37 pm

I have a simple code thet works fine: // app.js app.get("/welcome", userController.welcome); // controller.js exports.welcome = (req, res) => { res.json({ "users": 'users' }); } However i need to use DB-requests in the controller. So i rewrote my code like this: // app.js app.get("/welcome", userController.welcome); // controller.js exports.welcome = async (req, res) => { try { const users = await User.find({}); res.json({ "users": users }); } catch(error) { res.status(404).send(); } } After this my code stopped working. This is reflected in the fact that the browser always started showing an 404error. Please help my get users list in the browser instead of 404error.

Selecting particular elements from a list of lists [duplicate]

8 February 2026 @ 6:42 pm

I have this tibble head(dd,2) # A tibble: 10 × 4 .model yemo GPRT .mean <chr> <mth> <dist> <dbl> 1 ARIMA(GPRT) 2024 Dec N(136, 854) 136. 2 ARIMA(GPRT) 2025 Jan N(136, 1225) 136. str(dd) fbl_ts [10 × 4] (S3: fbl_ts/tbl_ts/tbl_df/tbl/data.frame) $ .model: chr [1:10] "ARIMA(GPRT)" "ARIMA(GPRT)" "ARIMA(GPRT)" "ARIMA(GPRT)" ... $ yemo : mth [1:10] 2024 Dec, 2025 Jan, 2025 Feb, 2025 Mar, 2025 Apr, 2025 May, 2025 Jun, 2025 Jul, 2025 Aug, 2025 Sep $ GPRT : dist [1:10] ..$ :List of 2 .. ..$ mu : num 136 .. ..$ sigma: num 29.2 .. ..- attr(*, "class")= chr [1:2] "dist_normal" "dist_default" ..$ :List of 2 .. ..$ mu : num 136 .. ..$ sigma: num 35 .. ..- attr(*, "class")= chr [1:2] "dist_normal" "dist_default" ..$ :List of 2 .. ..$ mu : num 136 .. ..$ s

Type erasure Problem with Java Method references

8 February 2026 @ 3:53 pm

I am using Flink with java where I am facing a type erasure problem. I have an interface called TransformationService, which has multiple implementations, only one of which is used by a single flink job. This is decided at runtime as shown in the code below. Following is the signature of my Transformation Service - public interface TransformationService<EVENT extends Event, KEY extends Key> { KEY keyBy(EVENT ev); } This is how it is being used in the calling code of the pipeline - TransformationService<Event, Key> service = getImplementation(pipelineType); DataStreamSource<Event> source = ...; source .uid("source") .rebalance() ... ... .keyBy(service::keyBy) ... ... env.execute(job); Each implementation of TransformationService uses concrete key and event types that extend Key and Event classes, respectively. An example implementation of Transf