StackOverflow.com

VN:F [1.9.22_1171]
Rating: 8.9/10 (12 votes cast)

Random snippets of all sorts of code, mixed with a selection of help and advice.

Highlighting the Data gride view rows

15 November 2025 @ 1:43 pm

I have a Data gride view in my WinForm app with .net8. I want to highlight some rows based on the current user role and the request nextlevel. I write this function and call it in form load. but at the end all rows are white. I'm sure about the user role value (1 , int32) and the nextlevel value. private void LoadPendingRequests() { DataTable dt = new DataTable(); using (SqlConnection con = new SqlConnection(connectionDB)) { con.Open(); // 1. Fetch requests with next pending level string query = @" SELECT r.RequestID, r.CreatedDate, u.FullName AS Requestor, r.Status, (SELECT MIN([Level]) FROM Approvals a WHERE a.RequestID = r.RequestID AND a.Status = 'Pending') AS NextLevel FROM Requests r JOIN Users u ON r.RequestorID = u.UserID WHERE r.Status = 'Pending'"; SqlDa

Why is `bson.objectid` missing even though `pymongo` is installed, and how can I fix this?

15 November 2025 @ 1:37 pm

I’m trying to import ObjectId from bson.objectid in a FastAPI project, but Python keeps throwing a ModuleNotFoundError even though pymongo is installed. Environment: Python: 3.13 pymongo: 4.15.3 My import: from bson.objectid import ObjectId Error: ModuleNotFoundError: No module named 'bson.objectid' But pip shows pymongo installed: (venv) pip show pymongo Name: pymongo Version: 4.15.3 Location: ./venv/lib/python3.13/site-packages Checking bson: (venv) pip show bson WARNING: Package(s) not found: bson So I am not using the wrong third-party bson package. But running this still fails: python -c "from bson.objectid import ObjectId; print(ObjectId)" ModuleNo

Complete the findStrings function in the editor below. It should return array of strings. follow w: an array of strings queries: an array of integers [closed]

15 November 2025 @ 1:24 pm

import math import os import random import re import sys # # Complete the 'findStrings' function below. # # The function is expected to return a STRING_ARRAY. # The function accepts following parameters: # 1. STRING_ARRAY w # 2. INTEGER_ARRAY queries # def findStrings(w, queries): # Write your code here if __name__ == '__main__': fptr = open(os.environ['OUTPUT_PATH'], 'w') w_count = int(input().strip()) w = [] for _ in range(w_count): w_item = input() w.append(w_item) queries_count = int(input().strip()) queries = [] for _ in range(queries_count): queries_item = int(input().strip()) queries.append(queries_item) result = findStrings(w, queries) fptr.write('\\n'.join(result)) fptr.write('\\n') fptr.close() in the following code edit it to get an array of stringsanf queries as an arra

My Flutter project runs fine in Android Studio, but VS Code and other platform shows configuration errors

15 November 2025 @ 1:19 pm

I started working on a flutter application which I built using Android Studio but when I tried running it on different platform like Vs Code it started giving configuration error assembleDebug. image link BUILD FAILED in 3m 40s Running Gradle task 'assembleDebug'... 222.6s Error: Gradle task assembleDebug failed with exit code 1

WebOTP API. Incorrect work after receiving an SMS

15 November 2025 @ 12:49 pm

I tried using the WebOTP API. I found a problem where a dialog box asking for permission to insert a code from an SMS appears even if there is no domain in the message. It is enough to send just a text with numbers. However, when I try to insert the code, nothing happens because the last line of the message is missing. Why does the dialog box appear if the SMS does not match the format (no domain in the message)? For example, I send a message to the device: "secret code 123456 to log in to the app." And a dialog box appears. I found formats for SMS here: https://developer.chrome.com/docs/identity/web-apis/web-otp Has anyone experienced something like this?

Free DNS service for subdomain

15 November 2025 @ 12:24 pm

Is there some free DNS domain service which I can use to resolve host name. I have a Database server which I want to access using domain name like db1.somedomain.com.

Casting functions with pointer arguments to function pointers with void* argument

15 November 2025 @ 11:16 am

The following code is accepted by GCC and the resulting binary prints the expected results. But is it standard conform and would always work on different systems using different compilers? Minimal example #include <print> using func_t = void(*)(void* data); void int_func(int* data) { std::println("{}", *data); } void const_int_func(const int* data) { std::println("{}", *data); } void int_arry_func(int(&data)[2]) { for (int elem : data) std::println("{}", elem); } void const_int_arry_func(const int(&data)[2]) { for (int elem : data) std::println("{}", elem); } int main() { func_t func_1 = reinterpret_cast<func_t>(int_func); func_t func_2 = reinterpret_cast<func_t>(const_int_func); func_t func_3 = reinterpret_cast<func_t>(int_arry_func); func_t func_4 = reinterpret_cast<func_t>(const_int_arry_func); int val = 5; int vals[2]

Escape characters issue when defining a regex in a JSON string

15 November 2025 @ 10:01 am

I am trying to extract values for colorName from the following strings located in <script> of an HTML page. \\"colorName\\":\\"GLOSS REDSKY SHDWSIL WHT IMPASTO\\" \\"colorName\\":\\"GLOSS PREMIUM FJORD METALLIC / WHITE METALLIC SILVER\\" The HTML is returned in response.text using Python Scrapy. I want to extract GLOSS REDSKY SHDWSIL WHT IMPASTO and GLOSS PREMIUM FJORD METALLIC / WHITE METALLIC SILVER from the code snippet using regex. re.findall('\\\\"colorName\\\\":\\\\"(.*?)\\\\"', response.text) This line of code works fine, but when I tried to put the regex in a JSON string

PSTH with numpy.histogram shows periodic “gaps” at bin boundaries even after integer time conversion—how to bin robustly?

15 November 2025 @ 3:31 am

I’m computing peristimulus time histograms (PSTHs) in Python. Each trial aligns spikes to a reach-start timestamp and bins them into fixed-width bins. I see vertical “gaps” (low counts) at exact bin boundaries (e.g., every 20 ms). I thought it was floating-point, so I converted everything to integers and even tried microseconds + half-open bins, but the stripes persist. Minimal example (synthetic data that reproduces the effect on my machine): import numpy as np # ---- synthetic spikes: uniform + weak locking every 20 ms ---- rng = np.random.default_rng(0) n_trials = 200 pre_s, post_s, bw_s = 1.0, 4.0, 0.02 # 20 ms TICK = 1_000_000 # microseconds pre, post, bw = int(pre_s*TICK), int(post_s*TICK), int(bw_s*TICK) edges_rel = np.arange(-pre, post+1, bw, dtype=np.int64) # trial starts (ms), here zeros for simplicity reach_ticks = np.zeros(n_trials, dtype=np.int64) # build spikes per trial with slight bin-boundary bias spike_ticks = [] fo

How to make it so a parent NEEDS its children to exist in MySQL?

14 November 2025 @ 11:42 pm

I am designing a DB where basically parent can't exist without two children. E.g: Entity set Marriage, CAN'T exist without entity set Man and entity set Woman, but neither Man or Woman need Marriage Entity set to exist. (Lets imagine only Man and Woman marriages so its less complex). Also, lets imagine Marriage can have many men or many women, but men and women can only have ONE marriage. I need help on the query, how do I enforce this? CREATE TABLE Marriage( marriageId INT ) CREATE TABLE Man( manId INT, marriageId INT, FOREIGN KEY (marriageId) REFERENCES Marriage(marriageId) ON DELETE SET NULL ) CREATE TABLE Woman( womanId INT, marriageId INT, FOREIGN KEY (marriageId) REFERENCES Marriage(marriageId) ON DELETE SET NULL ) This is basically what I have now. (other attributes don't matter right now). In summary my question is, how can I enforce the TOTAL participation in both ends from marriage?