I need to compare a title for 3 strings
here what I'm doing
var textMessage = ""
props.screen == 'dd' ? textMessage = "Next, select the dd " : null
props.screen == 'ff' ? textMessage = "Next, select the ff " : null
props.screen == 'ss' ? textMessage = "Next, select the ss " : null
It was not obvious how to get a random member of a container. So I wrote a function to retrive it given a generator.
namesapce ThorsAnvil
{
namespace Util
{
using Distribution = std::uniform_int_distribution<int>;
/* Get a distribution from [0, max) */
/* None ...
I wrote a class that opens a shared memory communication to use in my project, and would like a review.
mylib_com.hpp
#ifndef __MYLIB_COM_HPP
#define __MYLIB_COM_HPP
#include <sys/mman.h> /* For mmap */
#include <fcntl.h> /* For O_* in shm_open */
#include <unistd.h> /* For ftruncat...
I am an experienced self-taught professional Python programmer working my way through the book Classic Computer Science Problems in Python to try to catch myself up on some of the things I missed by not going to school for this. I am also currently trying to learn Clojure, and I thought why not k...
Recently I started to learn Python and PyQT5.
So here is my code for a calculator. Personally I don't like how doMath() function is looking but I don't now how to make it more readable and pythonic. Please review, any corrections and suggestions are welcomed.
import operator
import sys
from func...
Many a times, I've had the need to use a permutations with replacement function.
So, I've written a function to do just that:
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)
def permutations_with_replacement(n: int, m: int, cur=None):
if cur is None:
cur = []
if n...
I have an html table with multiple rows and columns.
<table>
<tr>
<td id="td1" class="my_tooltip"></td>
<td id="td2" class="my_tooltip"></td>
<td id="td3" class="my_tooltip"></td>
</tr>
</table>
Using Jquery UI - Tooltip, each td element should load different tooltip data with ...
This code takes an array of 3d images and applies the convolution function through multi-threaded image processing with padding, stride, pad values ... as parameters. I need suggestions on how to improve performance and maybe get rid of the for loops used(if that is possible).
Use this photo tig...
I have given the Mars Rover challenge a go in Python as DSA practice.
Here is the challenge:
A rover’s position and location is represented by a combination of x and y co-ordinates and a letter representing one of the four cardinal compass points. The plateau is divided up into a grid to sim...
@Heslacher @Vogel612 Do either of you happen to know the answer to this question on German.SE perhaps? About preferred word usage in industrial context.
@Vogel612 That's possible. Considering the only function of the emergency stop is to start the emergency stop procedure though, the English equivalent doesn't imply that either.
An emergency stop can be either a category 0 or 1 stop. A 0 immediately cuts power. A 1 cuts power eventually, but not immediately. A user probably won't notice the difference, but I imagine we can't put NOT-AUS on a cat 1 emergency stop.
While NOT-HALT is basically true enough either way.
A category 2 stop would allow power to remain, but those are not permitted for emergency stops. So with an emergency stop, the power will be cut eventually, one way or another.
@Osialek generally when talking about code, "optimize" means efforts to reduce the runtime, memory usage, or stability of a program. If you mean just improving the code in general, that can mean a whole spectrum of different things, and different people will have different priorities, opinions and tastes that will take different or even contrary directions. As mentioned here already, it is more appropriate to take these types of questions to codereview — Hymns For Disco7 secs ago
I want to simplify dict usage. Sometimes, when dictionary structure is quite well known, let's say:
d = {
'a': 1,
'b': 2,
'c': [ 1,2,3]
}
it would be nice to access this using d.a, d.b, d.c[0]..., not d['a'], d['b'], d['c'][0].
For this purpose I used this and wrote a function:
f...
I am working on a project that has to load a lot of data from JSON files. For this I have written the following struct.
struct JsonHelper {
static func parseJsonFile(file: String) -> Any? {
if let filepath = Bundle.main.path(forResource: file, ofType: "json") {
if let con...
I've been wondering for some time what the best way to pass a 2d array to functions is. I know that arrays, passed to functions, decay into pointers, so int arr[25] would become int *arr inside a function. The problem is with 2d arrays, int arr[5][5] would not become int **arr. Instead I've been ...
Anyone please review and share your feedback for the following code.
Multiple consumers generate random integer numbers and a single consumer receives it to display only odd numbers out of it.
package main
import (
"fmt"
"time"
"math/rand"
"sync"
)
var msgs = make(chan int)
var dummy = make(c...
I am trying to check that a list of files are all images using functional programming.
Some actions I go through are asynchronous, so I have to wait for them to completely finish before passing to a new one.
const filteredFiles = ['favicon.ico', 'site.webmanifest', 'browserconfig.xml'];
const f...
I want understand how to correctly structure a functional asyncio-based program.
The code below wraps two external APIs to provide the client a simple send_weather() function. Its structure reflects my current understanding of ansynchronous programming and the very little I've grasped of functio...
Given a positive integer n, find the smallest number of perfect squares (for example, 1, 4, 9, 16, ...) that sum to n.
sums = {0:0, 1:1}
def numSquares(n: int) -> int:
if n in sums:
return sums[n]
else:
s = 2**31
squares = [i**2 for i in range(1, int(n**(1/2)) + 1...
TLDR: Does the javascript community regard it as poor syntax to include a terminating semi-colon inside an anonymous function inside an Event Listener / Event Assignment statement, when the terminating semi-colon of the statement itself will be following not long after?
I'm currently writing a...
@Nexevis OP asked for a codereview, that's the place to get one working code or not. Over here I'd only suggest to burn the book he's using because it promotes the use of static methods. — Nicktar41 secs ago
@Nicktar The rules of the codereview stackechange specifically require the code to be working as intended. See here. "Code Review aims to help improve working code. " This question would be closed quickly and downvoted on that exchange in the current state. — Nexevis56 secs ago
I want to store a value in a dict (to behave like a cache) but I care about performances. I wonder if it is better to create a second variable in order to store the result of the sum compared to retrieving the value from the dict where the result is already stored.
Real code:
@property
def tota...
I can't believe DataTable/SqlDataAdapter massively beat out System.Data.Linq.DataContext.ExecuteCommand and ExecuteNonQuery (tried with both Stored Procedures and command text) and just straight SqlConnection/SqlCommand ExecuteCommand and ExecuteNonQuery called during looping. I was going to fin...
Stack overflow is not a code-writing or tutorial service, and we ask that you provide a minimal reproducible example including code for what you've already tried. If you have fully working code that you want to improve in efficiency, then Code Review might be a better fit — G. Anderson25 secs ago
I have written a Matrix library that contains all the main properties of matrices.
It's a relatively long project, I am hoping it is ok to post here since I really want to have it reviewed.
The project is compiled in GCC 9.2.0 and Boost 1.71.0, from https://nuwen.net/mingw.html, environment cod...
No, you just mix up too many topics, Joins, and Groups and Sums and List-flatening. If you do have a solution that works, it would be easier to understand. You said, you have one with foreach- but you don't want to use foreach. So present your bad but working solution, then we can improve it. (Might be better on CodeReview, cause this is not of common interest). — Holger49 secs ago
This code structure allows me to quickly create and manage behaviours on p5.js sketches. I'm planning to move to Java but wanted feedback beforehand.
The behaviour interface:
interface Behaviour<Element> {
apply(...elements: Element[]): void;
}
interface LinearBehaviour<Element> extends Be...
I have a Repl.it account that I use for my projects, and I don't really want to make a new api for storage every time, I've seen some like EasyDB and Jsonstore (I use Jsonstore in the background as storage here) but it doesn't have some of the features i want. It isn't done, but its working. I ju...
On February 12, 2020, we will be ending our support for the legacy 1.0 and 1.1 versions of TLS, which are no longer used except by some very old client software. For more details, see our announcement on Meta.
https://www.codewars.com/kata/best-travel
From what I understand of the problem, one must basically enumerate and the compare all the possible combinations of k elements from the vector. My solution works, but times out, so it isn't accepted. I've basically tried to create a sliding window that ...
Coming back to C++ after a hiatus in Java. Attempting to create an immutable object. Defined A in header as
public:
const int A;
Want to defensive check that A is positive in the constructor. Is this sane?
MyObj::MyObj(int a) : A(a) {
if (b < 0)
throw invalid_ar...
I need some help creating an program which selects 6 numbers from 49 and picks the winning and the losing numbers. How do you create that?
All I have found is a video from youtube but that program selects 6 numbers continously and you don't use the break command to stop the selection.
This is the...
So I wanted to write a script that would essentially print out the longest repeated string within the entire list. Here is what I got so far:
import re
import collections
#-----------------
def Rep_String(inp):
words = re.findall(r'\w+', open(inp).read().upper())
commons = collections....
If it's a per user auth then there's an increased cost to caching, but concurrency and duplicate reviews I don't think would matter as you make the function idempotent per user. As once you have one code back you ignore all others
Thanks in advance if you are reading this code.
I recently submitted this code as part of an interview (took about 4-5 hours). Unfortunately, they did not like the code and I received a form rejection email without any sort of feedback. However, I am committed to improving my code and I would li...
For Each MyIndex In Worksheets
If MyIndex.Name = "Inv_IB" Or MyIndex.Name = "Inv_MP"
With Sheets(MyIndex.Name)
nFilasActual = .Cells(Rows.Count, 4).End(xlUp).Row
Set dataRng = .Range("A2", .Range("N" & nFilasActual))
...
Suppose I have two classes Person and Address
public class Person {
private String fullName;
private Address address;
//getters and setters
}
public class Address {
private String street;
private int pinCode;
private Person person;
//getters and setters
}
Is it o...
As a Rust beginner, I would like to know how I could improve the following points considering the function below:
Handling Path and PathBuf types correctly;
Performance;
Rust writing style in general.
Here is the function, decorated with a full working example:
use std::env;
use std::path::{...
@C-Love511 if you're interested, do a search for a custom class based approach. That's my favorite solution. Create a custom class that automatically restores events, screen updates, calculation mode, etc. in it's Class_Terminasearch: event. Then create a new instance of the class in a sub and when that sub ends, the class instance scopes out and settings are restored. Check out this CodeReview post: codereview.stackexchange.com/q/182278/115996 — ChrisB35 secs ago
Generally speaking, if your code works and you're looking for someone to review it, you would want to ask on codereview.stackexchange.com. Please read their On Topic before posting, if you choose to do so. — Tieson T.52 secs ago