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.

Purpose of default template arguments on constructors [duplicate]

12 May 2026 @ 12:53 pm

std::optional<T> has a ctor. like this: template <class U = T> constexpr optional(U&& v); Source: C++23 latest draft, cppreference.com, see ctor. #8. What is the purpose of the default value for U? The template parameters of ctors. are always deduced, they cannot be provided explicitly at the call site.

Is putting new items in C++ `std::map` during a `std::for_each` that traverses that same map a potential segfault (if realocation happens)?

12 May 2026 @ 12:52 pm

So, in my AEC-to-WebAssembly compiler, written in C++11, I have this piece of code: if (!staticPropertiesInitialized) { // https://atheistforums.org/thread-63150-post-2055509.html#pid2055509 basicDataTypeSizes["Integer32"] = 4; basicDataTypeSizes["Character"] = 1; basicDataTypeSizes["Decimal32"] = 4; basicDataTypeSizes["Integer64"] = 8; basicDataTypeSizes["Decimal64"] = 8; basicDataTypeSizes["Integer16"] = 2; std::for_each(basicDataTypeSizes.begin(), basicDataTypeSizes.end(), [&](std::pair<std::string, int> type) { if (not(isPointerType(type.first))) basicDataTypeSizes[type.first + "Pointer&

Detect simulated location [Cordova]

12 May 2026 @ 12:40 pm

I want to detect simulated location, I’ve tried on iOS to use isSimulatedBySoftware flag from CLLocationSourceInformation, but It didn’t gave me a stable result while using apps like: PoKeep iMyFone AnyTo I’m really looking for a solution for this so any help will be appreciated, also to keep you know, “iMyFone AnyTo” require developer mode on iPhone to be on to be able to use it, so also if any one know how to detect and close developer mode [And it’s ok in App Store to release the app] please let me know

How to convert non-ascii hex to char in c

12 May 2026 @ 12:36 pm

I want to convert any given hex value to a char and then print the actual char string. The length of the given hex value "0xHHHHHHHH" may vary from 1 to 8. The following code uses two hex values for testing, "0x41" and "0x1EB": int main(int argc, char **argv) { long long_value = strtol("0x41", NULL, 16); int int_value = (int)long_value; char char_value = (char)int_value; printf("long_value: %ld, int_value: %d, char_value: '%c'\n", long_value, int_value, char_value); long long_value2 = strtol("0x1EB", NULL, 16); int int_value2 = (int)long_value2; char char_value2 = (char)int_value2; printf("long_value2: %ld, int_value2: %d, char_value2: '%c'\n", long_value2, int_value2, char_value2); printf("hex_41: '%c'\n", 0x41); printf("hex_1EB: '%c'\n", 0x1EB); re

Interleaved output of promise chained thenables, why?

12 May 2026 @ 12:27 pm

Using nodejs, I was expecting the chain to exhaust first and then follow. Is the following running while the resolve( chain ) is being unwrapped? I realize that the first follow then gets enqueued and then the first chain.then gets enqueued. Is the following execution order correct? I was under the impression that the resolve(chain) is getting unwrapped until it ends and then the follower chain runs. var chain = new Promise( function(resolve,reject){ resolve( '1' ); } ); var follow = new Promise( function(resolve,reject){ resolve( chain ); }); follow.then((a) => { console.log('follow 1', a); return 1; }).then((a) => { console.log('follow 2', a); return 2; }).then((a) => { console.log('follow 3', a); return 3; }); chain.then((a) => { console.log(' chain 1', a); return 2; }).then((a) => { console.log(' chain 2', a); retu

How do I export a file from a webpage that the user can Save rather than dropping straight into Downloads?

12 May 2026 @ 12:16 pm

Right now I'm using this code to allow the user to save an export of the data from my interactive webpage: const blob = new Blob([JSON.stringify(state, null, 2)], {type: 'application/json'}); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `filedump_${state.meta.name || 'export'}.json`; a.click(); This is 99% of what I want. But when I trigger this code (by clicking an Export button on the page), Firefox pops up a "File Downloaded" window, and the .json file sits in my Downloads directory. I would rather have it show up a "Save As" prompt, allowing me to save it to the local directory of my choosing. Is this possible? I am happy with making changes either server-side or client-side. I found an option in the Settings for Firefox which is a checkbox for "Always ask you where to save files", but this is overkill - I don't want this to change the behavior

How do I create a stacked bar chart with a complex dataset in R Studio with ggplot2?

12 May 2026 @ 12:08 pm

My dataset, very roughly, looks like this: Variable 1 Group 1a) Group 1b) Group 2a) ...(up to 9) yes 0 ... ... ... no 1 yes 1 no 0 ... ... I would like to create a stacked bar chart with the groups on the x-Axis, Variable one being stacked (yes/no) and the count on the y-Axis. It is to illustrate the relationship between working, being supported by ones parents and having time for leisure activities. Example Group 1a stands for "Yes, I have time for leisure and my parents support me financially" while Group 1b) stands for "Yes, I have time for leisure and my parents don't support me financially" and on it goes. There are 9 groups in total. Variable 1 are the answers to the question "Do you work?&qu

Could you guys kindly recommend powerful front end tools for a Laravel backend?

12 May 2026 @ 12:01 pm

I'm looking to build a website. I already know Laravel and ReactJS with Tailwind for CSS. I was wondering if ReactJS will be good enough for everything or if there will be a better option. I'm open to all suggestions. Thank you so much for your help. Cheer!

Using one Jenklinsfile accross multiple branch

12 May 2026 @ 11:49 am

**Is it a good practice to centralize Jenkinsfiles in a separate repository?** Hi everyone, I'm currently using a **Multibranch Pipeline** in Jenkins. My project repository contains a `Jenkinsfile` at its root, so every time I create a new branch, Jenkins automatically detects it and runs the pipeline which works fine. However, I'm questioning whether this is the right approach. Every branch ends up with its own copy of the `Jenkinsfile`, and keeping them all in sync can become painful as the project grows. I'm considering an alternative: having a **separate, dedicated repository** that contains only the `Jenkinsfile`, which would clone the project repository and checkout the target branch passed as a parameter. My questions are: - Is this a recognized good practice? - What are the trade-offs between both approaches (co-located vs. centralized Jenkinsfile)? - Are there Jenkins-native features (Shared Libraries, etc.) that addre

Trouble calculating HTML line wrapping positions

12 May 2026 @ 11:23 am

I’m trying to calculate where an HTML line breaks automatically. The result should be an array of character positions where the line breaks. I came up with the following formula, which works fine. I found one off-by-one issue in this minimal example, but that’s not the issue. The problem however, is that this breaks at specific zoom levels. This can be browser zoom or operating level zoom. At a browser zoom level of 175% for example, I see that the <span> element containing the word “need” is ~0.57px below the top level of the line element. In reality this is dynamic content. Font sizes may vary. This element is rendered invisibly and is only used to calculate line wrapping. Is there a way to get around this issue? Possible solutions I see are: Increasing the threshold, but having a threshold at all is not ideal. But then what would be an acceptable threshold? What if the font size becomes very small? This is user