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.

Spring-Boot Reactor WebClient - Difference between Direct and Proxified connection

19 December 2025 @ 1:20 pm

Context: I have a back-end Spring-Boot micro-service (SB v3.5.6) which connect to several external resources. My micro-service is deployed in a k8s cluster and uses Istio as internal k8s proxy. For Internet access we have to use a specific proxy: let's name it "proxy.us.aws.comp.net:3128" Some of these resource are in our VPC and can be accessed directy and others are in public Internet (SAAS services). The domain used for all internal resources in the same VPC is: <subdomains>.comp.net Exemple of configuration: # internal servers ## internal API internal.api.base.url: https://specific-internal.api.comp.net:8709/internal-api/v2/ ## External Service external.api.base.url: https://an-external-rest.api.domain.com/the-api/v1/ To connect to these API's, I am creating a WebClient using spring-boot-starter-webflux with the default c

Spring-Boot Kafka Property-File Configuration

19 December 2025 @ 1:15 pm

We use Kafka in Spring-Boot 3.4 and we want to upgrade to 4.0 We have some consumers with a Kafka-Listerner annotation. The whole config is in the application yaml-file. We just have the annotation like so: @Transactional @KafkaListener( topics = "${spring.kafka.consumer.topics.prozess-status}", groupId = "${spring.kafka.consumer.groups.prozess-status}", clientIdPrefix = "${spring.kafka.consumer.clients.prozess-status}", containerFactory = "kafkaListenerContainerFactory" ) void verifyProzessstatus(@Header(KafkaHeaders.RECEIVED_KEY) Long key) { businessLogRepository.verify(key); } We didn't define any kafkaListenerContainerFactory. This was done be Spring in the background. Now with the upgrad, Spring doesn't auto provide the kafkaListenerContainerFactory anymore. I found some code example how to co

Go code using WMI returns inconsistent USB port count; how to reliably get fixed physical USB ports?

19 December 2025 @ 1:14 pm

I'm trying to get the number of physical USB ports on a Windows machine using Go and WMI. I wrote the following code using ole and oleutil: func GetUSBCount() (int, error) { runtime.LockOSThread() defer runtime.UnlockOSThread() if err := ole.CoInitialize(0); err != nil { return 0, fmt.Errorf("CoInitialize failed: %v", err) } defer ole.CoUninitialize() unknown, err := oleutil.CreateObject("WbemScripting.SWbemLocator") if err != nil { return 0, fmt.Errorf("CreateObject failed: %v", err) } defer unknown.Release() ws, err := unknown.QueryInterface(ole.IID_IDispatch) if err != nil { return 0, fmt.Errorf("QueryInterface failed: %v", err) } defer ws.Release() serviceRaw, err := oleutil.CallMethod(ws, "ConnectServer") if err != nil { return 0, fmt.Errorf("ConnectServer failed: %v", err) } service := serviceRaw.ToIDispatch() defer service.Release() resultRaw, err := oleutil.CallMethod(service, &quo

What is the best practice to write a Spring Boot class which deals with a REST API?

19 December 2025 @ 1:11 pm

I have a Spring Boot application which has integration with two different REST services. One of those integrations is implemented as a @Component and uses RestTemplate. Also it uses only a static key and a static secret that never changes. The other integration REST API uses @Service and HttpClient. Also it generates a token which is reused for an hour until it expires, and so on. I am not sure what is the best practice for the last integration, to keep it that way or to use it in a @Service with RestTemplate or convert it to @Component? Or something else? What is the best practice for Spring Boot to implement an integration with a REST API which uses time limited tokens?

State transition not responding to condition change in AnyLogic

19 December 2025 @ 1:02 pm

I have created an agent with a Boolean attribute. When this attribute is true, the agent will transit from state A to state B. I am trying to set this attribute to true for each agent that exits a delay block on the main agent. The code is under the On at Exit section of the delay block and looks something like this. agent.Attribute = true. The problem is the agent is not changing state. What am I doing wrong ?

Blazor binding problem : Upgraded .NET 9 to 10

19 December 2025 @ 1:01 pm

We upgraded our ASP.NET Core Blazor application from .NET 9 to .NET 10 and we are experiencing a wierd problem and cant find a solution for it. The setup is InteractiveServer and is follows : A web page has a button (Component we made). When this button is clicked, a confirmation pop up comes (written in the Button component). When the button is pressed again, the confirmation message is lost for some reason and this is only happening after upgrade to .NET 10. Form uses the following to display button <Button Id="CreateAndSendButton" OnClick="ShowCreateDialog" Enabled="CanCreate" Style="ButtonStyle.Secondary">Create and Send</Button> Scripts below for button.razor <button type="@Type.ToString()" id="@Id" class="@($"text-nowrap {@_cssClass}")" @onclick="

App write database not reflecting stuff i am adding

19 December 2025 @ 1:00 pm

I made a db and made a collection for my project but now the new updates cals it a table. but after writing all my code for some reason the database table has not updated the records i added.

How to make it so that once the song is finished playing no more turtles move on the screen? [closed]

19 December 2025 @ 12:28 pm

To start this code is a part of a huge file that I don't fully think is necessary to paste onto here as the area that has the problem can work on its own. Also, the code is already not working as intended and I have no idea how to fix it. I want it so that while the song is playing each turtle moves (bonus credit if you have them move to the beat of the song) and if the key is hit when it is near the bottom turtles then they get 1 point but if they miss, they get - 1. Here is a visual representation of it working earlier after the song is finished playing it should print the score in the terminal (For now). Currently when I start the program it plays the music, opens the turtle window and makes the title, but it does not make the background or any of the turtles. It freezes and when I click on anything on the screen it crashes. I have tried for loops, while loops and now ontimer which I still don't fully understand. Here is the grand reveal of the said code: de

How to define an interface equivalent in Typed Racket?

19 December 2025 @ 11:41 am

For Java's classes and interfaces usage, what is the equivalent in Racket? #lang racket (define fish-interface (interface () get-size grow eat)) (define fish% (class* object% (fish-interface) (super-new) (define size 1) (define/public (get-size) size) (define/public (grow) (set! size (+ size 1))) (define/public (eat) (set! size (+ size 2))))) (define my-fish (new fish%)) (send my-fish grow) (send my-fish eat) (send my-fish get-size) ; should return 4 However, I cannot find the equivalent of interface in typed/racket. How should I write an interface in typed/racket?

How To Handle Generic Type Changing As You Move Up The Call Stack When Using The Result Pattern

19 December 2025 @ 11:12 am

I am learning about different ways to handle errors in .NET REST APIs. I saw the Result Pattern come up and I'm now trying to implement it in a personal project. However, I can't help but feel I am missing something as it feels very awkward to use. I will try and explain through example: Here in my repository, I am using a simple in-memory list which stores my Users: public Result<Guid>Add(User user) { var userExists = CheckIfUserNameExists(user.GetUserName()); if (userExists) { var error = UserErrors.UserAlreadyExistsError(user.GetUserName()); return Result<Guid>.Failure(error); } _users.Add(user); return Result<Guid>.Success(user.GetId()); } If the username exists then I return a failure Result and return an Error. If a User is successfully added to the list then I want to return the user id to the ca