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.

How do I import torch without receiving erors?

31 May 2026 @ 11:30 pm

I receive the error below when importing torch. I'm not sure how to install torch. Do I install it into my command prompt or how can I install it directly in jupyter notebook? I am not sure how to use pip, but everytime I try to install torch using pip I receive the same error below. Please explain how I can install torch in a very specific and simple way since I am not an extremely experiences programmer. Thanks import torch import torch.nn as nn import torch.nn.functional as F import math text = "hello world! transformers are fun." # Training text chars = sorted(list(set(text))) vocab_size = len(chars) char_to_idx = {ch: i for i, ch in enumerate(chars)} idx_to_char = {i: ch for i, ch in enumerate(chars)} data = [char_to_idx[ch] for ch in text] X = torch.tensor(data[:-1]) Y = torch.tensor(data[1:]) class PositionalEncoding(nn.Module): def __init__(self, d_model, max_len=100): super().__init__() pe = torch.zeros(max_len, d_model)

Consistent gets during pipelined function

31 May 2026 @ 10:47 pm

I have a very simple split function in Oracle 26 (os: oel9). My test case is: -- test, run that 2-3 time to avoid h-parsing exec dbms_monitor.session_trace_enable(); select split_to_array('Hello, Wor ld!!! sdfgsdsd sdfsd sdf sdfsdfdsfsd sdfsdfsdf', ' ') from dual; exec dbms_monitor.session_trace_disable(); Everything works fine, but I see this in the trace file: select split_to_array('Hellow, Wor ld!!! sdfgsdsd sdfsd sdf sdfsdfdsfsd sdfsdfsdf', ' ') from dual call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 2 0.00 0.00 0 6 0 1 ------- ------ -------- ---------- ---------- -----

Unexpected behavior in protocol inheritance

31 May 2026 @ 10:40 pm

I use main actor by default in project settings, and use Swift 6 mode. Here's the code: public protocol Main {} nonisolated public protocol NonIso {} // Foo is on main // As proven by the compilation failure in `testNonIso()` public protocol Foo: NonIso, Main { func foo() } nonisolated func testNonIso() { let f: Foo! = nil // Call to main actor-isolated instance method 'foo()' in a synchronous nonisolated context f.foo() } As verified by my testNonIso() function, the Foo protocol is isolated to main. Then I mark Foo as nonisolated, and the error is gone: public protocol Main {} nonisolated public protocol NonIso {} // Foo is on nonisolated // As proven by no compilation error in `testNonIso()` nonisolated public protocol Foo: NonIso, Main { func foo() } nonisolated func testNonIso() { let f: Foo! = nil // this compiles fine, since Foo is non-isolated f.foo() }

struggling to get libcurl to return only a specific amout of html from a site

31 May 2026 @ 9:20 pm

I don't want all the html from a specific site so i tried to alter CURL_MAX_WRITE_SIZE (not sure if I did this right, I'm new to C). Unfortunately it still returns way more than 650,000 characters and gives me the entire site. #include <stdio.h> #include <curl/curl.h> #ifdef CURL_MAX_WRITE_SIZE #undef CURL_MAX_WRITE_SIZE #define CURL_MAX_WRITE_SIZE 650000 #endif //for now this just prints the code for debugging purposes int processCode(char html[]){ printf("%s", html); return 0; } int main(){ CURL *curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, "https://amazon.com"); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 650000L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, processCode); curl_easy_perform(curl); curl_easy_cleanup(curl); return 0; }

How to mass edit XML?

31 May 2026 @ 7:11 pm

I have a bunch of xml files which needs some correction. <body> <text> <text> second level text before </text> main text <text> second level text after </text> </text> </body> I need to convert all text tags which are "second level" to comment. So that final xml would become <body> <text> <comment> second level text before </comment> main text <comment> second level text after </comment> </text> </body> Is there a tool which can help with this?

React native firebase notifications quick action

31 May 2026 @ 5:34 pm

We have a chat application built with React Native, and we are using React Native Firebase Cloud Messaging (FCM) for notifications. We have a requirement to support quick actions in notifications, similar to WhatsApp, where users can reply to a message directly from the notification bar without opening the app. Currently, messages are sent through a socket connection, although we can also use an API for sending messages if needed. My requirements are: 1. Always show notifications with a reply action/input field. 2. Ensure that messages sent from the notification reply action are delivered reliably and never lost. I looked into using silent notifications to trigger a local notification with a reply action. However, I'm concerned about reliability. If the user has force-quit the app, can a local notification still be shown reliably? I need a solution similar to WhatsApp's implementation. Could you advise on the recommended approach for

What is inappropriate about CultureInfo.CurrentUICulture?

31 May 2026 @ 1:27 pm

I just enabled Code Analysis rule CA1305 in my code base, and I get lots of the following warning: Warning CA1305: The behavior of 'string.Format(string, object)' could vary based on the current user's locale settings. Replace this call in 'some-function' with a call to 'string.Format(IFormatProvider, string, params object[])' This is fine, that's why I enabled CA1305 for. However, on one occasion where I have a construct like this: text.SomeParsingMethodWithFormatProvider(CultureInfo.CurrentUICulture) I get the following warning: Warning CA1305: 'some-function' passes 'CultureInfo.CurrentUICulture' as the 'IFormatProvider' parameter to 'SomeParsingMethodWithFormatProvider'. This property returns a culture that is inappropriate for formatting methods Huh? So in exactly what way is CultureInfo.CurrentUICulture inappropriate for formatting methods?

Grouping text rows in equal-sized groups

31 May 2026 @ 10:30 am

I have a table containing a lot of typed/named items and I want to create a (materialized?) view to group them together so that a UI can later make it easier for users to select. Description The goal is: If there are N elements of the same type, make sqrt(N) groups each of size sqrt(N). Instead of having e.g. 10k elements to scroll through, the UI would show 100 lines (the groups), each of which can be expanded into 100 lines (the items inside each group). 1 more click to make but a lot less scrolling. The UI will display group names as the range containing the named elements inside it. For instance, if a group contains all the items whose names start with A and B (but not C and beyond), then the group should be named A-B. If a group contains all the elements starting with C until e.g. EG, but elements starting with EH are the the next group, the group should be name C-EG. The idea is: Instead of c

Should I write long signed int or just long if I want a signed int of 32 bits?

31 May 2026 @ 10:26 am

So I just wondered if it would be better to be explicit with types e.g. using long signed int for a signed 32 bit int. Or if it would be better to just not waste your time and just write long from a best practice perspective in C. Can some compilers on some platforms misinterpret long as long float or long unsigned int?

Modulus of Very large Number

31 May 2026 @ 7:48 am

You are given a very large number N (which goes upto 1e10000) and a 64 bit integer P. How do i find N % P? for example: N= 8290826691135830692772803 , P = 95972011 modulus (N % P) = 60316167 obviously we cannot store N as a number and BigInteger does not exist in the C programming language (gmp is out of the question) How else can this be solved