StackOverflow.com

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

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

Apply custom function to each row of a data.table and add result to the data.table

13 July 2025 @ 4:40 am

I have below code library(data.table) mm = matrix(1:4, ncol=2, dimnames=list(c("r1", "r2"), c("c1", "c2"))) as.data.table(mm) A_Custom_Function = function(x) c('Calc1' = mean(x) * 2 + var(x), 'Calc2' = min(x), 'Calc3' = max(x)) My goal is to apply A_Custom_Function function to each row and add the resulting vector as new columns to mm itself. Could you please help with some efficient procedure to achieve this. I have really big data, table with more that 10,000,000 rows. I am looking for some generic procedure to work with any custom function.

Explain mcp resource end to end workflow

13 July 2025 @ 4:40 am

I feel like I understand MCP tool. that is - when the user gives the prompt, using the available tools, mcp-client talks to LLM and gets the task executed along with parameters LLM provides using tool/call. Here LLM is responsible for providing which tool to call along with parameters. When mcp-server exposes resources, how does this work? lets say we have this resource "file://t-shirt/description" which has the product description. When the prompt is "can you summarize the t-shirt product features", should the LLM instruct the mcp-client to read the file? (It does not seem to work like this). It would be nice if you could explain the end to end workflow how mcp resource works.

React Native Expo dev-client on Android emulator only shows the large arrow splash screen and never loads my app UI

13 July 2025 @ 4:07 am

enter image description here I’m working on a bare React Native app with Expo’s custom dev client workflow, but when I launch it on the Android emulator I never get past the arrow splash screen. It seems to be the Expo Dev Launcher logo, and I can’t swipe or tap it to load my actual app. What I’ve tried Start the Expo Dev Server for dev-client npx expo start --dev-client In a separate terminal, build & install on Android npx expo run:android Build and install both succeed, but the emulator shows only this screen: I’ve tried: Clicking the arrow icon Swiping up with mouse drag and with adb shell input swipe Fetching dev servers from the Dev Launcher menu Nothing ever loads my JS bundle or displays my MainActivity/React Navigation screens. What I want Bypass or disable thi

Rails server crashes on Mac M2 with Bus Error

13 July 2025 @ 3:58 am

I have been struggling to set up a Rails 5.1.7 application on my MacBook M2 for months. I installed Rosetta, x86_64 brew, and my terminal app is set to run with Rosetta. ~ ❯ arch i386 ~ ❯ which brew /usr/local/bin/brew ~ ❯ brew list ==> Formulae abseil coreutils icu4c@77 lz4 pkgconf xz autoconf gdbm krb5 m4 postgresql@14 yarn automake gettext libffi mysql protobuf@29 zlib bison gh libnghttp2 node readline zstd brotli git libtool node-build redis c-ares glib libunistring nodenv ruby-install ca-certificates gmp libuv openssl@3 shared-mime-info chruby heroku libyaml pcre2 terminal-notifier ==> Casks ~ ❯

How to get peaks consistent with KDE in one-dimensional data using python?

13 July 2025 @ 3:24 am

Example data: a = [68, 63, 20, 55, 1, 21, 55, 58, 14, 4, 40, 54, 33, 71, 36, 38, 9, 51, 89, 40, 13, 98, 46, 12, 21, 26, 40, 59, 17, 0, 5, 25, 19, 49, 91, 55, 39, 82, 57, 28, 54, 58, 65, 2, 39, 42, 65, 1, 93, 8, 26, 69, 88, 32, 15, 10, 95, 11, 2, 44, 66, 98, 18, 21, 25, 17, 41, 74, 12, 4, 33, 93, 65, 33, 25, 76, 84, 1, 63, 74, 3, 39, 9, 40, 7, 81, 55, 78, 7, 5, 99, 37, 7, 82, 54, 16, 22, 24, 23, 3] Its KDE looks like this: enter image description here to produce this kdeplot: import matplotlib.pyplot as plt import seaborn as sns fig = plt.figure(figsize=(12, 6)) ax = sns.kdeplot(a, bw_adjust=0.5, fill=True, cut=0) ax.set_xticks(np.arange(0, 100, 5)) I want to get the highest 2 peaks in the KDE plot. The 1st one i

How do I use the jQuery each function?

13 July 2025 @ 2:01 am

This jQuery should loop through and grab the href attribute from each href link and display the different href in each of the #link divs. But the problem is that I get all three URLs printed in the first #link div, like this: enter image description here jQuery(document).ready(function() { $("h3.post-title a").each(function(){ var thelink = this.href; jQuery("#thelink").append(thelink); }); }); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min

Using std::move with Constructor(Type t) or Constructor(Type&& t). What's the difference?

12 July 2025 @ 11:21 pm

I'm studying std::move semantics and I would like this to be clarified to me: Say I have: // Message.h class Message { private: std::array<uint8_t, BUFFER_SIZE> buffer; std::queue<Packet> packets; public: Message(Packet p) { packets.push(std::move(p)); } } Now I have: Packet p; p << data; // put data into the packet Message m(p) // wrap the packet in a message. So this code generates unnecessary copies for my use case, because I will never use p ever again. So I'd like to use the std::move semantics to avoid every copy possible. What I don't understand is the following: If I do: Packet p; Message m(std::move(p)); While the constructor of Message is still

Flutter: in app web view causes app to be killed in windows

12 July 2025 @ 10:30 pm

I'm building a flutter app on windows, i have tried different packages for in app web view like flutter_inappwebview and webview_cef. The problem is when the application goes to the webview screen , the application get killed on the tester machine (the app closes unexpectedly). i don't know why or what i have missed, it's working on my machine but closes on tester machine. Although the recommended way to initialize the web view is applied within the initiate method of the webview screen : void initState(){ super.initState(); initiate(); } void initiate()async{ if (!kIsWeb && defaultTargetPlatform == TargetPlatform.windows) { final availableVersion = await WebViewEnvironment.getAvailableVersion(); assert(availableVersion != null,

How to inject images from native app to webview and opload to server

12 July 2025 @ 9:21 pm

I have the following code. I want upload images to server in webview in my application but doesn't work. How to inject images from native app to webview and upload to server? My Screenshot @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(requestCode==123 && resultCode==RESULT_OK) { // Checking whether data is null or not if (data != null) { // Checking for selection multiple files or single. if (data.getClipData() != null) { // Getting the length of data and logging up the logs using index for (int index = 0; index < data.getClipData().getItemCount(); index++) { // Getting the URIs of the selected files and logging them into logcat at debug level Uri uri = d

File is not showing the the slack channel

12 July 2025 @ 8:37 pm

Using Node.js, how can I send a file to a Slack app using the Slack API? I tried the method using Slack docs, but the message I tried to send using postMessage is working. However, for sending files, we should use a different approach as per the Slack docs. That same approach I have followed, but on Slack, I didn't see any file that I tried to upload, but the code is successfully running. Please help if I should add any params or should I call any other methods. https://api.slack.com/methods/files.upload const messageRes = await web.chat.postMessage({ channel: "#jr-developers", text: "🚨 Incident detected! Please check the attached report below.", }); console.log("Message sent:", messageRes.ts); // console.log(messageRes); // Step 3: Upload file content to the URL using axios const fileName = "continent.