All Questions

75,530 questions
Filter by
Sorted by
Tagged with
6 views

Improving unit tests and error handling with files in Rust (PNGme)

I want to become proficient in Rust and I've followed the PNGme exercise. I've completed it up until Chapter 4 included, where I've written a lot of tests myself for verifying that the command line ...
• 101
6 views

Async recursion that must ultimately return a promise

I have an asynchronous function that must ultimately return a Promise (the first function). This function has many tasks but I've stripped them all down to just one for clarity. One such task is a ...
• 113
1 vote
24 views

Minesweeper implementation in C++

I have implemented minesweeper in C++. You can get a box by entering the coordinates -row number, then column; starting from 0- of said box (eg: "0 0"); you can mark a box as a bomb by ...
12 views

Spawning a child process that is accessible in global scope through use of eval()

So basically my question is what would be a better way to achieve my goal? The code below works fine but looks like it is extremely inefficient and could be achieved in a better way. The code ...
• 101
18 views

Need to make my Tictactoe Game better (Java)

I need some help with a school-project that i have! My code is very unnecessarily long, and i know that there is better ways to write it. So i have this code (generated code is not included & some ...
9 views

A reduce method which shape incoming data to anew simplified form aggregated common data in single objects

I built a method using reduce of JS to aggregate together data from a DB in a better shape. What I'm wondering is, if that method can be simplified with a more ...
• 217
117 views

Implementation of the "tee" utility program

How can I optimize the program? To make it more optimal? The program should be more optimal in terms of source code, compiled executable size, memory usage, speed, bugs etc. Please criticize the ...
• 140
19 views

Game based loosely on cricket

Cricket is a PC game which is similar to real cricket but has little different rules There will be N number of players , Y number of overs, here one over means each player will hit one ball each, let'...
28 views

MVVM Architecture in WPF

I'm trying to use MVVM approach in .NET 6 WPF app. I've a simple project that has an object Entity and I have implemented ...
• 109
12 views

(Godot 4.0) I want my code to wait 1 second then add a value to my money and then wait again... but it won't work [closed]

if upg4Dis == 1: \$ScrollContainer/VBoxContainer/Upg4.disabled = true await get_tree().create_timer(1000).timeout money += 1 * multiplier so basically, ...
38 views

Basic Stack Operations using Linked List in C

I have made a few functions for some basic stack operations using linked lists. Please review my code and suggest some ways to increase its readability. I would also love to hear ideas on how to make ...
• 23
1 vote
24 views

Calculate average of each line of input

I made a program that will loop and calculate the average of the input given by the user. There are no problems here. I just want to know if there is a better way to do this, or a way to optimize this ...
• 11
255 views

std::array based push-only circular buffer

Minimal implementation of a circular buffer based on std::array, where elements can only be pushed and iterated. I'm interested on potential failures and very trivial optimizations, as I'd like to ...
• 161
15 views

Avoid a stream() inside a stream() [closed]

I have the following code. ...
• 101
21 views

Ballerina service resource methods

I'm playing around to find out idiomatic way to write service resource methods for HTTP API so that the actual program logic is separated from the resource methods. Currently the (simple) program ...
• 303
1 vote
54 views

Calculating square roots using binary search

I'm trying to find the square root of a number (num) using binary search in Rust. I'm new to Rust, but I've done quite a bit of programming in other languages, ...
• 111
1 vote
32 views

Binary Search Tree implementation in C++ with templates

Im implementing a BST using templates and dynamic memory, here is my attempt: This is the BSTNode.hh ...
• 269
39 views

Text-based game combat function in Python [closed]

I made a text-based game to learn python, since then I have tried to implement what I have found online to be "good practices". Does this follow good practices? Are inner functions good ...
17 views

Plot a 2D vector field with radial symmetry in Python

I computed a 2D vector field U = (u(x,y), v(x,y)) with radial symmetry, parametrized as (u,v) = a(r) (x,y) + b(r) (-y,x), where a(r), b(r) are given as solution of an IVP which I solved using ...
• 141
38 views

Generates all pairs (combinations of 2) up to a limit (exclusive)

Any improvements on this combination generator. Seen a lot of combination generators online, but none like this. Found pseudocode at: https://www.baeldung.com/cs/generate-k-combinations Fastest I ...
70 views

VBA functions to calculate sun and moon positions

I have the following VBA code (across three modules) to make UDFs to calculate sun & moon position data. The issue I'm facing is that they are very slow to run as I have over 6000 rows (over 10 ...
• 21
1 vote
25 views

Can someone point out what possible edge cases/leaks/inefficiencies my code has and how they could be avoided/fixed. Basically, I want to know what mistakes I make so I can avoid making them in the ...
• 13
8 views

Group list of objects into smallest possible number of sublists without exceeding maximum sum

I have converted my Java answer from this question into Rust. As I am new to Rust, I would like to know about what I could improve in my code. Mostly I would guess that I could improve on borrowing, ...
• 163
36 views

Is it possible to get the reference of the original variable in the frozenset according to the key?

There are frozenset in Python, but no frozendict or frozenmap. I tried to implement it (Don'...
• 121
1 vote
18 views

Creating a generic base class for singletons in Unity

Singletons can be very tricky to work with in Unity, especially when you dont want to give up on Monobehaviour features. Most examples I've seen make use of ...
• 183
499 views

Returning the other value of boolean enum

I have a class with a "mode" state. There are currently two modes and we are not likely to add more in the future. The class has a CurrentMode property, ...
• 183
84 views

Python function that shears image by n degrees while keeping the relationship between height and width

I am trying to find a method to shear/skew an image horizontally or vertically by n degrees (n ranges from -90 to 90 excluding the terminals) so that the result would meet the following conditions: ...
• 1,522
15 views

email HTML in Gmail app on iOS 15.4 is rendering wrong [closed]

I have a table in my email and on every device and email providers works well, but on newest iOS gmail app the table is transformed. What could I change to improve this table? My code: ...
25 views

I'm working on the following task from Codility: A prime is a positive integer X that has exactly two distinct divisors: 1 and X. The first few prime integers are 2, 3, 5, 7, 11 and 13. A prime D is ...
30 views

Algorithm for solving subsequence with highest win rate

Problem Inputs: 1. min length of subsequence 2. binary sequence outputs: 1. starting index of sequence 2. subsequence length The task is to find a subsequence ...
• 121
30 views

Calculate the number of burgers that can be made from the given ingredient inventory [closed]

Posted this on Stack Overflow and got recommended over here. I have, so far, found no errors in the code but it looks a bit complicated and I would like some feedback. This is my second project in my ...
1 vote
49 views

Implementation of Concurrent List in .NET

I would appreciate review of this implementation of the concurrent list that is, to my knowledge, currently missing in .NET Core. Requirements Thread safe Lock free Ordered Supports get and set by ...
• 111
19 views

Show/hide depending on ID and Class

I have written some code that shows a div class, based on what ID is clicked. I'm a beginner, so not sure how to make this code compact, it seems way too long at the moment. Can anyone suggest a ...
36 views

Simple non balancing indexed binary search tree

The following code represents a simple indexed binary search tree of integers. The insert method inserts an int. The indexed lookup looks up the ith smallest element (0 indexed). I'm trying to write C+...
• 21
8 views

Is it better to extend from EventTarget or implement EventTarget? [closed]

I guess this really just boils down to a question of inheritance vs composition. I've typically heard people advocate for composition more, but I am wondering if that holds true in an example like ...
• 345
1 vote
33 views

Adapter pattern in C++ via Inheritance and Composition

Any suggestions on how the implementation of the C++ Adapter pattern could be improved here? Implemented via: Composition Inheritance What needed to be adapted was the ...
44 views

Managing websocket subscriptions

The following code is pulling data off an exchange. It keeps the subscriptions to the channels because when the websocket client reconnects, all subscriptions are gone and we basically need to ...
• 423
11 views

Simple C11 mutex implementation using _Atomic

I'm trying to learn concurrency and synchronization using C programming (C11). As a learning exercise, I wanted to quickly implement a mutex I appreciate that this code is almost trivial, but I would ...
• 183
94 views

Implementing multidimensional integral for a custom function in C++

I am not an expert with C++, but I am trying to implement a 4-dimensional integral using GSL numerical integration approach. The code below shows the whole algorithm. Although it seems correct what I ...
• 219
23 views

Removing \n and \f from a string [closed]

I am trying to remove \n and \f (I'm not sure what they are called, I know \n is a new line) ...
68 views

Returning all divisors of a number as a matrix with N X 2 dimensions

I have developed a class structure with methods to return a matrix from a single input array. The objective is to insert the middle value of the array so 2n remains ...
• 21
1 vote
63 views

Printing the first n numbers of the Fibonacci sequence

I have written a code below for printing the first n fibonacci numbers, the code is as follows ...
25 views

How to random the questions for my quiz game in C# Console App [closed]

I create a quiz game app. The user will answer 3 subjects and it is a multiple choices. After the user answers 10 questions per subject, it will display the score per subject and also the overall ...
71 views

Python: Ensure an entry exists in only one document

I have written a server-side app in Python that manages email by comparing senders against different lists and then dispositioning the messages according to which list the sender is on. As a side ...
• 131
31 views

How to avoid DRY in function PHP? [closed]

I have some days in php practice. There is a following functon that groups data and returns: ...
89 views

Blackjack game in C++

I developed a blackjack game. I am relatively new to c++ and OOP, so I am asking for feedback on what could be improved. This game features betting, taking a card, standing, and splitting a hand. ...
75 views

another attempt to implement the tee command

I implemented the tee command from linux. The program implements the -a option Reads standard input until end-of-file, write a ...
• 140
1 vote
19 views

Sidenav menu that appears when click on button

I have a side menu that appears when click on button, which works fine. But now I want to clean up my code, shorten it if possible. I was wondering if there is an easier and cleaner way to achieve the ...
• 11
1 vote
14 views

Chemfig: isomeri equilibrium

I spent a lot of time looking for the right coefficients of the two arrows, in order to align the three xylenes. There is probably a more elegant method. Could you suggest it to me? ...