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.

matching for null value causes mongodb query to require FETCH and filter, ie not covered by the index

17 April 2026 @ 12:37 am

https://mongoplayground.net/p/6EBVaNRelKr db.collection.aggregate([ { $match: { cheese: null } }, { $project: { _id: 0, cheese: 1 } } ]).explain("queryPlanner") Mongodb will return documents where the field, cheese, is either missing or has a value of null in the above query. Mongodb also stores null as the value in the index where the document's field is either missing or equal to null. Hence, since the query will return documents where the field is missing or null, why does it need to FETCH and then filter? There is ambiguity if the query is matching for "cheese: { $exists: false }". But there is no ambiguity for "cheese: null". "filter": { "cheese": { "$eq": null } }, Can som

How should one implement ternary (3 valued) logic in python?

17 April 2026 @ 12:25 am

See wiki article. I have a project that very naturally wants properties which are True, False, or ??. I would like to: use logical operators is, or, and, and not as usual stay relatively self-contained, ideally standard lib I expected to be able to use None, but unfortunately None or False and False or None evaluate to different things (only one of which is what I wanted). What can I do? I've considered creating a custom 'unknown' class, but I can't overwrite the logical operator behavior. I've found external libraries like trinary, but they use the |,^,& syntax instead. I note this is the logic of a NULL value in SQL, so presumably prac

How to stop Cairo/X11 from flickering when resizing?

17 April 2026 @ 12:25 am

I'm trying to make a GUI app with Cairo, but whenever I e.g. resize the main window, the background colour flickers in for a frame. There's a similar question about this, How to avoid cairo drawing xlib surface from flickering?, but the singular answer (just changing the background colour) doesn't actually solve anything. Here's a simple example to illustrate my point: #include <threads.h> #include <X11/Xlib.h> #include <cairo/cairo.h> #include <cairo/cairo-xlib.h> constexpr int start_width = 400; constexpr int start_height = 400; _Atomic bool have_been_killed = false; Display *_Atomic display; cairo_surface_t *_Atomic main_surface; int guiThread(void *const data); int main(int, char *[]) { display = XOpenDisplay(nullptr); if (!display) { return 1; } const Window root_window = XDefaultRootWindow(display);

Unable to repeat a structure with boofuzz

17 April 2026 @ 12:12 am

I'm trying to implement a boofuzz tree for the dns protocol. I'm currently stuck at the label and names definition, unable to make a repeat. Expected behaviour : the program should be able to produce a consecutives labels to make a name. a label is composed of a count byte and the specified number of bytes. a name is a set of labels, followed by a null-byte. I omit the null byte in this code. from boofuzz import * if __name__ == "__main__" : labelstr = FromFile("labelstr", filename="./wordlist", max_len = 63 ) labellen = Size("label_len", block_name="labelstr", length=1, endian=">") label = Block("label", children=(labellen, labelstr)) labelgrp = Repeat("label", block_name="label", min_reps=2, max_reps=10) req = Request("dns", children=(label)) #******************************************* # static spec

Is it a good or a bad idea to join two tables on several columns if joining on one column is enough?

16 April 2026 @ 11:54 pm

Let's assume that I have two tables with columns (product_id, user_id, event_id, event_payload) AS T1 and (product_id, user_id, event_id, event_metadata) AS T2. Then let's assume that T1 is ordered by product_id and event_id and T2 is ordered by user_id and event_id. I have two options to join these two tables: -- First option, join on one field because it's enough. ... from T1 join T2 on (T1.event_id = T2.event_id); -- Second option, join on more fields because it seems like such query is more -- optimized due to T1 and T2 being sorted (i.e. indexed) by some columns. ... from T1 join T2 on ( T1.product_id = T2.product_id and T1.user_id = T2.user_id and T1.event_id = T2.event_id ); What is the preferred way? Is the second option optimal or does ClickHouse only optimize filters such as ... on (T1.date = today()

Jackson 3 and final Map deserialization

16 April 2026 @ 11:43 pm

In a corporate project, I’m migrating from Spring 3.x to Spring 4.x, and also from Jackson 2.x to 3.x at the same time. I do have the following problem: with Jackson 2 this code works "as is", but I cannot find the way to make it work with Jackson 3, as the content field is not detected by Jackson. What am I missing to make it work? Sample code (can be run via an IDE JShell for convenience): import tools.jackson.databind.DeserializationFeature; import tools.jackson.databind.json.JsonMapper; import java.io.Serializable; import java.util.*; abstract class BaseMessage { protected UUID id; protected final Map<String, Serializable> content; // And other fields… protected BaseMessage() { id = UUID.randomUUID(); content = new HashMap<>(); } public <T extends Serializable> void addContent(final String key, final T value) { content.put(key, value

i want to create a game coin generator and link it with my game so I can generate the coins in the game to real money and link it to a trust wallet he

16 April 2026 @ 11:29 pm

I have already created a running game already buh I want Input or perhaps add a game in currency conversion in the game so I can link it to like trust wallet and withdraw the money, basically if I can't do I want to be able to do something like all this apps they say provides money while you play the games I want to create a game that looks like that buh has an actual game in currency conversion In it

Hosting PHP to the internet (xampp)

16 April 2026 @ 10:31 pm

So I have a problem with hosting my PHP files to the internet using xampp. I did port forwarding to my device with the same port that is on apache ( I tried 80 , 8080 ) but nothing worked. also changed required form local granted to all granted. and changed the servername. so i arrived to the conclusion that xampp do not support that. can you help me if there is a way as I only want to try and not interested in a paid hosting service. I just want to do it locally. also for you to understand this is just me trying things. So the only visitors are me on another device and my friends. I have no problem with the using public ip to log in . or something like duckdns.

UDP broadcast packet being received from one computer but not another [closed]

16 April 2026 @ 8:21 pm

I have a problem where an inbound UDP Broadcast packet is detected coming from one computer but it is not detected coming from another computer on the same network. Both packets are reaching the destination computer (verified via Wireshark). When examining these packets, the header information seems to be almost identical in anything that seems that it would matter. The code for the receiver is being run in VS2022 and is written in C++. I have tried disabling the firewall, etc. But for some reason, it does not trigger receiving data. I wrote some test software on another computer to transmit a UDP Broadcast packet and receive the data just as expected. The destination computer IP address is 164.217.14.114 with a subnet mask of 255.255.0.0. When sent from 164.217.14.121 (the test software), the packet according to WireShark is as follows:

Prevent cntlin to truncate variable values

16 April 2026 @ 6:20 pm

I 'm using the following code to set the format of my variable of interest: data thenameofmyvar; length label $200.; set mydb(keep= thenameofmyvar); retain fmtname '$myfmt' type '$'; start = put(_N_, 8.); label = thenameofmyvar; run; proc format cntlin=thenameofmyvar;run; data mydb;format thenameofmyvar $myfmt.;set mydb; run; The code does the job except that it truncates the variable ("thenameofmyvar") values although label was set to $200. The final length is 1. Can anyone help me please?