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.

c# await on object method call with nullable syntax throws exception [duplicate]

16 February 2026 @ 5:17 pm

I'm trying wrap my head around this issue, I've created a sample program. myClassObj is deliberately set to null to produce this scenario. Program fails at await myClassObj?.MethodAsync() Expectation was that it will handle null scenario as it does in case of action, myActionObj?.Invoke() does not fail. Curious to know why this is ? using System; using System.Threading.Tasks; public class MyClass { public async Task MethodAsync() { await Task.Delay(1000); } } public class Program { public async static Task Main() { Console.WriteLine("Start"); Action myActionObj = null; MyClass myClassObj = null; try { myActionObj?.Invoke(); // works await myClassObj?.MethodAsync(); // doesn't work } catch (Exception e) { Console.WriteLine($"{e}"); } C

Checking if a graph is connected with Z3

16 February 2026 @ 5:15 pm

I'm trying to code a solver for the chinese postman problem using z3. I have to check two things to see if there is already a solution available: if every node has even degree if the graph is connected The first is easy, but I don't know how to check the second. I feel like I should use the Transitive closure but I don't know how to implement the function in the code. I'm assuming that every edge is undirected. from z3 import * solver = Solver() nodes = ["A", "B", "C", "D", "E", "F", "G"] numnodes = 7 edges = [ ["A", "B", 5], ["B", "C", 1], ["C", "D", 7], ["D", "A", 9], ["E", "F", 3], ["F", "G", 2], ["G", "E", 3]] degree = [0] * numnodes for x, y, z in edges: degree[nodes.index(x)] +=1 degree[nodes

Login username sometimes not inserted into MySQL file

16 February 2026 @ 5:10 pm

I have a login page and ballot. To ensure no one is voting more than once, the checked names on the ballot are stored in the database along with their login username and corresponding ID number. For most ballots cast this work just fine. However, there have been ballots cast where the votes are stored but the username is blank and the ID number is 0. Zero is not an assigned value. Following is the code for process.php, where votes are submitted. My login page sets $_SESSION['username'] and $_SESSION['user_id'] after authenticating a user, and prevents users from logging in if they have already voted. <?php require_once('../Connections/pdo-connsunnygrove.php'); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); session_start(); $dbusername = $_SESSION["username"]; $userid = $_SESSION["user_id"]; $checkbox1 = $_POST['name']; $chk=""; for

How on Selenium to automate facebook/google registration

16 February 2026 @ 4:30 pm

I am developing a selenium test and I was able to create it for registration by email. However, writing a test for facebook and google login/registration is very tricky. One of the problem that they detect that it is a "bot" and show the captcha. The second problem is that their HTML structure (in the login popup) is so terrible (especialy in facebook) that it is very difficult using CSS selector to "hook" to some elements. Have anyone faced such a problem ? Maybe there is a better approach to test login/registation via google and facebook.

.NET clients cannot see Azure Service Bus messages created by node

16 February 2026 @ 3:58 pm

I have a node server that is posting messages to an Azure Service Bus topic using the rhea client. The system reading the messages is a .NET console app using the AMQP.NET Lite library. Both clients are AMQP 1.0 compliant. Here is the sample server code (node.js) sending data to the Azure Service Bus: import container from 'rhea'; const azureConfig = { address: 'my-service-bus.servicebus.windows.net', hostname: 'my-service-bus.servicebus.windows.net' user: 'RootManageSharedAccessKey', password: 'some-password', }; const connection = container.connect(azureConfig); connection.on('connection_open', () => { console.log(`Connection opened to ${azureConfig.address}`); const sender = connection.open_sender('my-topic'); sender.on('sendable', function(context) { context.sender.send(

I have error while executing npm run dev in VS Code

16 February 2026 @ 3:46 pm

I am trying to run next.js using npm run dev but I encounter following error: PS C:\Users\Shashwat\Desktop\Bookmark\smart-bookmark-app> npm run dev [email protected] dev next dev You are using Node.js 20.2.0. For Next.js, Node.js version ">=20.9.0" is required. When I check within terminal and command prompt this is my node version: PS C:\Users\Shashwat\Desktop\Bookmark\smart-bookmark-app> node -v v24.13.1 I don't know what is causing this error.

Customize kendo-editor in Angular

16 February 2026 @ 2:03 pm

I am using the Angular editor from Kendo UI in my application. When I select some text and choose an option from the Format dropdown (for example Heading or Paragraph), the style is applied to the entire line/block instead of only the highlighted text. Example If the editor contains: Revenue Growth 2024 and I highlight only Growth and choose Heading, the editor converts the whole line into a heading instead of formatting just the selected word. What I want I want the format option to behave like inline styling, meaning: only the selected text should change the rest of the line should remain unchanged What I tried Looked for a way to customize the formatting tool Tried adding custom formats Checked if the Angular edi

Memory leak happening with Python when creating numpy diagonal array and doing matrix math

15 February 2026 @ 9:45 pm

P = y.T @ (np.diag(Wc) @ y) This line is creating increased memory usage for me in the below code on my Windows 11 machine. As soon as I run the code, I see the RAM usage increasing and skyrocketing. But when I replace this line with P = y.T @ (y * Wc[:, None]) , the RAM usage is stable. However, I tested the same code on my Ubuntu 20.04 pc and it worked fine for both the alterations. I am not able to understand the strange behavior. Experts, please help. Ubuntu 20.04 no anaconda/ python venv; Python 3.10.12; Numy: 1.26.4 Windows 11 Business 10.0.26100 running anaconda environment: Python 3.13.9; Numpy: 2.4.0 import numpy as np, psutil, os, time, gc p = psutil.Process(os.getpid()) def rss_mb(): return p.memory_info().rss / 1024 / 1024 n = 3 kmax = 2*n + 1 Wc = np.random.randn(kmax) y = np.random.randn(kmax, n) print("start rss", rss_mb()) i = 0 while True: P = y.T @ (np.diag(W

How to create a member function for map?

14 February 2026 @ 10:57 pm

I have created a map like this: map<string, map<string, map<int, vector<int>>>> example; I can insert a value to this map like this: example["Stack"]["OverFlow"][3].push_back(2); Now I want to create an alias for push_back function. This code works well: #define SetValue push_back But the problem is when I put the dot operator, SetValue function is not shown in available functions list. For example, I define a vector such as vector<string> something Putting dot near to something word automatically shows push_back function. How can I achieve same effect for my own SetValue alias?

How to generate a matrix with every offset of vector without using a for loop

13 February 2026 @ 7:08 pm

For a given vector like v <- c(1,3,7,2,5), I want to create a matrix that repeats that vector with every possible offset, like this: NA NA NA NA 1 NA NA NA 1 3 NA NA 1 3 7 NA 1 3 7 2 1 3 7 2 5 3 7 2 5 NA 7 2 5 NA NA 2 5 NA NA NA 5 NA NA NA NA I could obviously do this with a for loop, but I am wondering if there’s a way to do this with a vectorized function or similar, because for loops are very slow. I was very impressed by the answers to this question, for example. As a specific example, the for-loop solution I wrote takes over 30 seconds to finish a 3000-long vector, while ideal solutions would return in a few seconds or less. For a 10,000-long vector, my for loop didn’t manage to finish after 15 minutes (at which point I gave up).