body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>This is a follow-up to my question over <a href="https://codereview.stackexchange.com/q/262772/242934">here</a>.</p>
<p>Having worked through most of the issues highlighted by @Reinderien in his detailed answer, I somehow got the code to work...</p>
<p>Some quick observations:</p>
<ol>
<li><code>elements.py</code> a... | [] | [
{
"body": "<p>Long story short, you've captured the wrong things in classes. You've put too much effort into centralizing your locators, which - first of all - shouldn't be centralized, and - second of all - are written in a fragile, over-expressed XPath style. You seem to be under the impression that every sin... | {
"AcceptedAnswerId": "262830",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T16:59:42.060",
"Id": "262810",
"Score": "1",
"Tags": [
"python",
"classes",
"selenium"
],
"Title": "How to make use of a class of descriptors to save code and other issues"
} | 262810 |
<p>Sorted List value using algorithm <strong>selection sort</strong>. Can you please review and let me know where I can improve.</p>
<pre><code>months = {"January": 1, "February": 2, "March": 3, "April": 4, "May": 5, "June": 6, "July": 7, "Augus... | [] | [
{
"body": "<p>Put your code in functions. Maybe this is pedantic, but it's not really an\n<em>algorithm</em> if you cannot reuse it. If the logic is floating around with\nvarious setup and printing code, it's not reusable in any convenient sense.</p>\n<p>Your demo code isn't doing what you think it's doing. Com... | {
"AcceptedAnswerId": "262815",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T17:32:28.540",
"Id": "262812",
"Score": "0",
"Tags": [
"python",
"reinventing-the-wheel"
],
"Title": "sorting list using selection sort algorithm"
} | 262812 |
<p>I have just written a hangman game in Python for a school project. It reads in a list of words from a text file, and graphics from another text file.</p>
<p>For each word, the program asks keeps asking for the user's guess, and prints out either the updated word or incorrect letters, until either the number of attem... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T22:53:18.703",
"Id": "518803",
"Score": "0",
"body": "Read [pep8](https://www.python.org/dev/peps/pep-0008/) for formatting conventions."
}
] | [
{
"body": "<p>By no means is this a complete list of suggestions for your code, but two that strike me are the following:</p>\n<h2>Validating input</h2>\n<pre><code>keepPlaying = input("Do you want to play the next word? (y/n): ")\n</code></pre>\n<p>This is a dangerous line because you do not validate... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T17:54:30.260",
"Id": "262813",
"Score": "2",
"Tags": [
"python",
"game",
"homework",
"hangman"
],
"Title": "Python Text-Based Hangman Game"
} | 262813 |
<p>So I've got a Discord bot that will load information about a user's personal charts and display it to them, and one of the commands is to get their leaderboard and show them the most successful songs on their charts. It does this by creating different pages in the embed, and the user can press the reactions to chang... | [] | [
{
"body": "<h1>Storing songs as objects</h1>\n<p>You are storing compound information in separate lists, which introduces a lot of bookkeeping and obfuscates the code.</p>\n<p>Objects are optimized and used for storing compound structured data like songs.</p>\n<pre class=\"lang-py prettyprint-override\"><code>c... | {
"AcceptedAnswerId": "262823",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T18:11:49.863",
"Id": "262814",
"Score": "1",
"Tags": [
"python",
"python-3.x",
"discord",
"discord.py"
],
"Title": "Discord.py pages for a leaderboard"
} | 262814 |
<p>Often end up using a <code>Scanner</code> to grab some simple input and often when dealing with <code>Number</code> input it can result in a lot of little bits just to check for valid input. In an effort to reduce this, I tried making it more generic with a <a href="https://docs.oracle.com/en/java/javase/11/docs/api... | [] | [
{
"body": "<p>While it can sometimes be useful to expose only static members and not allow instances of your class to be constructed, I don't see what you're gaining by doing that here. But by not allowing multiple different <code>ScannerInput</code>s, you <em>do</em> lose out on the ability to have them operat... | {
"AcceptedAnswerId": "262827",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T19:52:37.540",
"Id": "262817",
"Score": "3",
"Tags": [
"java",
"generics",
"exception"
],
"Title": "Generic Scanner(System.in) Parsing"
} | 262817 |
<p>I implemented the <a href="http://man.cat-v.org/plan_9/1/freq" rel="nofollow noreferrer">freq(1)</a> program from Plan 9 in go.</p>
<pre class="lang-golang prettyprint-override"><code>/* print histogram of character frequencies */
package main
import (
"bufio"
"flag"
"fmt"
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T22:07:26.733",
"Id": "518799",
"Score": "0",
"body": "I only have a small suggestion which doesn't need it's own answer.\n\nUse `:=` initialization shortcut instead of `var name typeName = value`, you can use `name := value` and go ... | [
{
"body": "<p>Overall looks fairly clean already.</p>\n<ul>\n<li>Like was already said in the comments, don't need <code>var</code> and the explicit function type, indeed just <code>freq := freqBytes</code> looks much cleaner.</li>\n<li>The parentheses around <code>!*dflag && ...</code> can be removed.<... | {
"AcceptedAnswerId": "262840",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T21:06:46.883",
"Id": "262819",
"Score": "4",
"Tags": [
"beginner",
"go"
],
"Title": "Plan 9 freq(1) in go"
} | 262819 |
<p>I have created an angular BaseService that aims to simplify calling API endpoints</p>
<p>I would like to know if you see any code smells, bad patterns or architecture issues.
What disadvantages could this have.</p>
<p>The idea is to decouple the api configuration from the implementation</p>
<p>The configuration is m... | [] | [
{
"body": "<p>It seems a bit odd to me that <code>ApiConfig</code> lives separately from the service. Isn't the set of available endpoints a property of the service? <code>some_service.call(endpoint_definitions[endpoint_name], some_parameters)</code> feels less natural to me than <code>some_service.endpoint_def... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-09T00:03:08.823",
"Id": "262826",
"Score": "4",
"Tags": [
"typescript",
"angular-2+"
],
"Title": "Are there technical issues/disavdantages on this BaseService that aims to simplify calli... | 262826 |
<p>I made a very simple user account registration program that works in the terminal using no external libraries other than <code>java.util.Scanner</code>. I want to know what improvements I can make to this code to make it more efficient and more readable:</p>
<pre class="lang-java prettyprint-override"><code>private ... | [] | [
{
"body": "<p>The logic to request the user data is fairly similar. It can be extracted to a method (in pseudocode):</p>\n<pre><code>inputInvalid = true\nwhile (inputInvalid) {\n print(inputToBeRequested)\n input = requestInput()\n if (!isValid(input))\n print(errorMessage)\n else\n inputInvalid = fal... | {
"AcceptedAnswerId": "262863",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-09T04:06:55.317",
"Id": "262833",
"Score": "2",
"Tags": [
"java"
],
"Title": "Java basic user account registration"
} | 262833 |
<p>For academic purposes I want to reinvent Blue Green Red to Grayscale function in Python. I am new to Python so I believe my code below can still be optimized.</p>
<pre><code>import cv2
import numpy as np
data = np.array([[[255, 0, 0], [0, 255, 0], [0, 0, 255]], [
[0, 0, 0], [128, 128, 128], [255, 255, 255], ]... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-09T10:39:58.230",
"Id": "518836",
"Score": "0",
"body": "How is `0.114 * blue + 0.587 * green + 0.299 * red` grey? I would expect grey to be `blue/3 + green/3 + red/3`"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate":... | [
{
"body": "<p>It appears that you are calculating linear combinations. If you are already using <code>numpy</code>, then the same can be achieved by broadcasting the dot product (with <code>@</code>):</p>\n<pre><code>import numpy as np\n\ndata = np.array([[[255, 0, 0], [0, 255, 0], [0, 0, 255]], \n ... | {
"AcceptedAnswerId": "262842",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-09T07:45:20.747",
"Id": "262835",
"Score": "3",
"Tags": [
"python",
"opencv"
],
"Title": "Reinventing BGR to Grayscale OpenCV convert function in Python"
} | 262835 |
<p>The function <code>processFus()</code> takes :</p>
<ul>
<li>Two lists of pulses (200 000 in each), as an input</li>
<li>Two lists of pulse, empty, pulseValid and invalid. The function must fill them at the end of the process.</li>
</ul>
<p>The function check for each pulse in listPulseA if it matches with one pulse ... | [] | [
{
"body": "<p>a few quick things that stick out...</p>\n<p><code>void Fus::processFus(std::list<Pulse> &listPulseA, std::list<Pulse> &listPulseB, ListPulse &pulseValid, ListPulse &pulseInvalid) {</code><br />\nI think a lot of those parameters ought to be <code>const</code>. Pass in... | {
"AcceptedAnswerId": "262850",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-09T07:50:10.437",
"Id": "262836",
"Score": "4",
"Tags": [
"c++",
"performance"
],
"Title": "Merge two pulses if they match"
} | 262836 |
<p>This is my first attempt at scripting with bash. I am running Ubuntu server, so I don't get to use all the gui back ups out there. Besides, tar works fine for personal use. Please let me know of any improvements and why.</p>
<pre><code>#!/bin/bash
# PURPOSE:
# TO BACK UP ALL FILES AND FOLDERS FROM A GIVEN DIRECTORY... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T00:01:01.310",
"Id": "518910",
"Score": "1",
"body": "Please do not update the code in your question to incorporate feedback from answers, doing so goes against the Question + Answer style of Code Review. This is not a forum where y... | [
{
"body": "<blockquote>\n<pre><code>NOW=$(date +%m-%d-%Y)\n</code></pre>\n</blockquote>\n<p>Prefer lower-case for variable names. This reduces the likelihood of conflict with environment variables used to change programs' behaviour (which are generally upper-case).</p>\n<p>That odd date format (with the day in... | {
"AcceptedAnswerId": "262859",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-09T08:44:06.003",
"Id": "262837",
"Score": "4",
"Tags": [
"array",
"bash",
"linux",
"logging",
"compression"
],
"Title": "Linux backup script written in bash for tar"
} | 262837 |
<p>I am an AP CS A teacher but as the syllabus does not include Graphics this is really my first time in using Java graphics. I am looking to produce a project not far above the realms of the AP CS A syllabus (classes, inheritance, interfaces, abstract) that will give students an insight into how to produce their own s... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-09T11:17:46.537",
"Id": "518838",
"Score": "2",
"body": "If you want to teach students game development, I can't recommend doing it using Swing and AWT. Today there are frameworks such as [LibGDX](https://libgdx.com/) to make games in ... | [
{
"body": "<p>If you attempt to lead by example, there are a few things that rub me the wrong way:</p>\n<ul>\n<li>Use an accepted code format. Spaces before opening braces, no new line at the start of a class or method, be <em>consistent</em>.</li>\n<li>Grab an installation of Sonar and ask its opinion. There w... | {
"AcceptedAnswerId": "262931",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-09T09:33:25.780",
"Id": "262839",
"Score": "3",
"Tags": [
"java"
],
"Title": "Sample Breakout Game to introduce students who have covered the AP CS A syllabus to Java Graphics:"
} | 262839 |
<p>I started writing a cyrptocoin from scratch, and then got sidetracked writing the database portion which I eventually turned it into its own project.</p>
<p>Data is written to the database and then retrieved through an index, similar to a memory-mapped vector.</p>
<p>The data are stored in "segments" that ... | [] | [
{
"body": "<p>Looks good! I see you are familiar with "modern" C++ techniques and habits. </p>\n<p>Hmm, the use of <code>const</code> data members means that the class cannot be <em>moved</em>, as well as not assigned to.</p>\n<p>Where's the destructor of <code>AshDB</code>? It contains file handle... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-09T13:18:14.150",
"Id": "262848",
"Score": "2",
"Tags": [
"c++",
"database",
"c++17"
],
"Title": "A simple write-once-read-many indexed based database"
} | 262848 |
<p>This is my first time using commit and rollback. I just need to know if this is a proper execution of the functions for this particular situation:</p>
<pre><code><?php
include("../include/sessions.php");
if(isset($_POST['addcriteria'])) {
$value = $_POST['addcriteria'];
$addname = isset($v... | [] | [
{
"body": "<blockquote>\n<h2>Does this appear as proper use of the commit and rollback functions?</h2>\n</blockquote>\n<p>I honestly haven't used PDO functions directly - typically used a framework like Laravel or similar.</p>\n<p>I do agree with the advice on <a href=\"https://phpdelusions.net\" rel=\"nofollow... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-09T15:03:23.590",
"Id": "262854",
"Score": "4",
"Tags": [
"php",
"sql",
"mysql",
"pdo",
"transactions"
],
"Title": "Using a transaction to create account records"
} | 262854 |
<p>I am working on a <code>CSV</code> data Sheet and want to parse and filter the data out it, While working on a code I found a similar code someone has asked on <a href="https://stackoverflow.com/questions/62533780/pandas-convert-the-unique-column-value-as-a-column-name-and-place-all-relating-s">SO POST</a> there and... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-09T16:56:42.267",
"Id": "518874",
"Score": "2",
"body": "I don't understand the downvote; this seems fine to me"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-09T17:10:51.247",
"Id": "518877",
"Sco... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-09T15:05:05.953",
"Id": "262855",
"Score": "1",
"Tags": [
"python",
"pandas"
],
"Title": "How to Better Parse CSV file with Pandas"
} | 262855 |
<p>I have created a simple Tic-Tac-Toe program. Can someone please review it and let me know where I can improve.</p>
<p>Here we can play against computer. Program start by putting 'X' at the center that is at the position 5. Then ask user to enter number from available position and then assign 'O' on selected position... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T02:08:08.777",
"Id": "518912",
"Score": "1",
"body": "I have just played a game where I won by getting 3 in a row across the top row. This did not register as a win, and the computer played 3 in a row across the bottom row, which st... | [
{
"body": "<h2>Print Statements</h2>\n<p>If you write <code>print(...)</code>, that includes a newline character. In your <code>draw_board</code> function, you have a couple lines where you specifically tell Python you <strong>don't</strong> want a newline, and then on the very next line you call print with no ... | {
"AcceptedAnswerId": "262870",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-09T20:05:32.080",
"Id": "262862",
"Score": "1",
"Tags": [
"python",
"python-3.x",
"tic-tac-toe"
],
"Title": "Tic Tac Toe program"
} | 262862 |
<p>I built a function that should greatly simplify working with long HTML forms, that save data to MySQL using PHP.</p>
<p>My forms usually have several hundred input elements that are added / altered / removed frequently from the form.</p>
<p>Goal of this function is to only write frontend HTML form markup, MySQL stru... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T06:49:14.447",
"Id": "519152",
"Score": "1",
"body": "Incorporating advice from an answer into the question violates the question-and-answer nature of this site. You could post improved code as a new question, as an answer, or as a... | [
{
"body": "<p>It looks like you are throwing caution to the wind here. I mean you are granting full control of your database structures to the end user and offering the raw mysqli errors when they arise. These are things that I would not entertain. I will hope that this is merely an academic exercise and tha... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-09T20:42:23.017",
"Id": "262864",
"Score": "1",
"Tags": [
"php",
"mysql",
"form"
],
"Title": "PHP function that clones HTML form structure to MySQL database structure"
} | 262864 |
<p>First of all, I am playing around with python for about a week tops. Absolute beginner here.</p>
<p>My story:
I work as an IT administrator so I am familiar with eg. PS on a very basic level. I actually got into python due to the fact that I am plotting/farming chia. Now a rather long holiday is coming up, so I thou... | [] | [
{
"body": "<p>It's generally a very bad idea to put credentials in a program. That's\na bigger topic, and the best approach will vary depending on your situation.\nBut you should address this problem.</p>\n<p>When naming things, let ordinary English usage guide you: plural for\ncollections (lists, tuples, dicts... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-09T22:57:08.747",
"Id": "262868",
"Score": "5",
"Tags": [
"python",
"beginner",
"python-3.x",
"file-system"
],
"Title": "Count *.plot files in certain directories on network file... | 262868 |
<p>This is my generalisation of <code>std::midpoint</code> incorporating advice received for <a href="/q/262762/75307">Find the mean of two values</a>. As well as supporting arithmetic types and pointers, as <code>std::midpoint</code> does, it also supports iterators, complex numbers and user-defined types such as big... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T11:25:39.753",
"Id": "518925",
"Score": "2",
"body": "I don’t have anything to add, but here’s a good video from CppCon on implementing [std::midpoint](https://m.youtube.com/watch?v=sBtAGxBh-XI)"
}
] | [
{
"body": "<ol>\n<li><p><code>std::transform</code> is defined in <code><algorithm></code>. You should include that.</p>\n</li>\n<li><p>Have it work for ranges with minimal work:</p>\n</li>\n</ol>\n<pre><code>template <std::ranges::range range>\nconstexpr auto midpoint(range &&r)\n{\n ret... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T06:36:37.250",
"Id": "262873",
"Score": "5",
"Tags": [
"c++"
],
"Title": "Find the mean of two values, take two"
} | 262873 |
<p>My ASP.NET application references a classlib that contains the business logic, where I need to have access to the <code>IIdentity</code> of the "current user".</p>
<p>In ASP.NET controller it is easy, outside it is not possible out of the box in a async model (I did not find any equivalent of <code>Thread.... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T13:46:24.317",
"Id": "518932",
"Score": "0",
"body": "Is this code already implemented and working? We only review working code on code review. If this code is currently in design you might want to ask this question on [Software Eng... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T10:18:18.540",
"Id": "262881",
"Score": "1",
"Tags": [
"security",
"asp.net"
],
"Title": "Access to IIdentity outside of aspnet application"
} | 262881 |
<p>This is a follow-up of my question over <a href="https://codereview.stackexchange.com/q/262810/242934">here</a>.</p>
<p>I adopted @Reinderien's suggested script to a second website below:</p>
<h1>fudan.py</h1>
<pre class="lang-py prettyprint-override"><code>from contextlib import contextmanager
from dataclasses impo... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-16T07:24:02.867",
"Id": "519373",
"Score": "0",
"body": "@Reinderien, I have removed the `wuhan.py` update to make the question more concise. You can ignore `add_to_bib` and `add_to_zotero` for now. The functions were inherited from my... | [
{
"body": "<p>I'm going to give a partial answer that ignores most of what you've done, because the approach is Selenium-based when that is really not needed here. Compared to some of your other questions, this website is very simple, DOM-wise - and follows a very simple and standard pagination strategy. The bi... | {
"AcceptedAnswerId": "263305",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T11:11:56.277",
"Id": "262883",
"Score": "3",
"Tags": [
"python",
"selenium"
],
"Title": "Looping through keywords and multiple pages in Selenium"
} | 262883 |
<p>So, I am interested, what is the proper way to submit a highsocre (such as of a Pacman game) in PHP? <a href="https://sourceforge.net/p/svg-pacman/code/ci/master/tree/setPacmanHighscore.php" rel="nofollow noreferrer">Here</a> is what I tried:</p>
<pre class="lang-php prettyprint-override"><code><?php
if (array_ke... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T20:36:10.337",
"Id": "518948",
"Score": "0",
"body": "The statement \"_Here is what I tried:_\" leads me to ask - does it work to the best of your knowledge? And what exactly do you mean by \"_proper_\"?"
},
{
"ContentLicens... | [
{
"body": "<p>The following example may help you with writing more readable code, add addresses vulnerability CWE-209 by returning HTTP status codes instead of detailed error messages. From a security perspective the browser/referrer checks, 'hash' and random numbers you have implemented would not be effective ... | {
"AcceptedAnswerId": "263551",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T11:20:48.823",
"Id": "262884",
"Score": "0",
"Tags": [
"php",
"game",
"session"
],
"Title": "Submitting highscore in PHP"
} | 262884 |
<p>I'm practicing <code>oop</code> concepts these days. To figure it out I tried the below problem.</p>
<p>There is a sensor monitoring system. It is a simple system that prints a value, whenever a sensor has picked a value.</p>
<p>I tried to solve this problem according to <code>oop</code> and <code>SOLID</code> princ... | [] | [
{
"body": "<p>Very good code, nicely done.</p>\n<p>As for your questions:</p>\n<blockquote>\n<p>For example as the SensorMonitor how can it know the details of currently operating sensors, and what sensors are in the monitoring process?</p>\n</blockquote>\n<p>It does not.</p>\n<p>You have modeled a clear associ... | {
"AcceptedAnswerId": "262924",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T13:58:34.260",
"Id": "262885",
"Score": "2",
"Tags": [
"java",
"object-oriented",
"interface"
],
"Title": "Registering listeners according to SOLID pricipals"
} | 262885 |
<p>Example</p>
<pre><code>String creditCardNumber1 = "4561261212345467";
int sum = IntStream.range(0, creditCardNumber1.length()).filter(i -> i % 2 != 0).map(i -> Character.getNumericValue(creditCardNumber1.charAt(i))).sum() + IntStream.range(0, creditCardNumber1.length()).filter(i -> i % 2 =... | [] | [
{
"body": "<p>To only have one stream, push down the decision of separating odd and even values:</p>\n<pre class=\"lang-java prettyprint-override\"><code>int sum = IntStream.range(0, creditCardNumber1.length())\n .map(i -> {\n int value = Character.getNumericValue(creditCardNumber1.charAt(i));\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T14:13:52.987",
"Id": "262886",
"Score": "0",
"Tags": [
"java",
"integer",
"stream"
],
"Title": "Luhn algorithm using Stream API"
} | 262886 |
<p>I have a JSON structure in the following example format:</p>
<pre><code>[
{date: '01-01-2021', name: 'House 1', value: '500'},
{date: '01-01-2021', name: 'House 2', value: '600'},
{date: '01-01-2021', name: 'House 3', value: '700'},
{date: '01-01-2021', name: 'House 4', value: '800'},
{date: '01-02-2021', ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-12T07:15:28.557",
"Id": "519071",
"Score": "5",
"body": "That isn't JSON. See [RFC 8259, Section 7](https://datatracker.ietf.org/doc/html/rfc8259#section-7): strings use double quotes. And the only unquoted symbols in JSON are `true`, ... | [
{
"body": "<h3>Scoping issues</h3>\n<p>You are using an "immediately invoked function expression" (IIFE) here to scope the <code>unique_dates</code>, but in the process you forgot to use the function argument you introduced to correctly scope the function you have there.</p>\n<p>Note how you have <cod... | {
"AcceptedAnswerId": "262891",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T16:39:13.660",
"Id": "262890",
"Score": "10",
"Tags": [
"javascript",
"array",
"functional-programming",
"ecmascript-6",
"iteration"
],
"Title": "Restructuring JSON to... | 262890 |
<p>This code can woocommerce order change status. But as you can see, this code is hard to read. How can I make it cleaner?</p>
<pre><code><?php
$tarih = explode('T', $order->get_date_completed());
$now = date("Y-m-d");
$origin = date_create($tarih[0]);
$target = date_create($now);
$interval = date_dif... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T20:28:41.810",
"Id": "518947",
"Score": "3",
"body": "Welcome to Code Review! The current question title, which states your concerns about the code, is too general to be useful here. Please [edit] to the site standard, which is for ... | [
{
"body": "<p>This is a partial review only, I may edit this post later as more details become available.</p>\n<p>I am not familiar with woocommerce at all. You may have design constraints but I would strongly recommend to use a templating engine like <a href=\"https://twig.symfony.com/\" rel=\"nofollow norefer... | {
"AcceptedAnswerId": "262915",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T19:20:48.297",
"Id": "262895",
"Score": "-1",
"Tags": [
"php",
"wordpress"
],
"Title": "Woocommerce order change status"
} | 262895 |
<p>This is a follow-up question for <a href="https://codereview.stackexchange.com/q/262690/231235">Image Processing Median Filter in C</a>. Under the same tiny bmp image read / write framework, a <a href="https://en.wikipedia.org/wiki/Sobel_operator" rel="nofollow noreferrer">sobel edge detection</a> function has been ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T20:01:04.697",
"Id": "518945",
"Score": "0",
"body": "Where do the directions go? You're computing them, but it seems like they're forgotten about"
}
] | [
{
"body": "<h1>Avoid code duplication</h1>\n<p>Whenever you repeat some pattern multiple times, try to find some way to remove the repetition. I see you are doing several 3x3 convolutions. Consider writing a function that does this:</p>\n<pre><code>static int convolve(const struct RGB *pixels, int w, int color,... | {
"AcceptedAnswerId": "262902",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T19:31:54.950",
"Id": "262896",
"Score": "3",
"Tags": [
"performance",
"c",
"reinventing-the-wheel",
"image",
"memory-management"
],
"Title": "Image Processing Sobel Ed... | 262896 |
<p>I developed a python Connect 4 game that only uses <code>sys & numpy</code> everything else is regular python! All I'm requesting is a stronger code. This is what I made:</p>
<pre class="lang-py prettyprint-override"><code>import sys
import numpy
BOARD_SIZE_X = 7
BOARD_SIZE_Y = 6
SEARCH_DEPTH = 4
COMPUTER_PLAY... | [] | [
{
"body": "<h1>PEP-8: the Style Guide for Python Code</h1>\n<p><a href=\"https://pep8.org/\" rel=\"nofollow noreferrer\">PEP-8</a> defines many conventions that will assist in making Python programs more readable and maintainable by a wider audience. Things like:</p>\n<ul>\n<li><code>snake_case</code> should b... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T20:14:02.643",
"Id": "262897",
"Score": "3",
"Tags": [
"python"
],
"Title": "python - Connect 4 Terminal Game"
} | 262897 |
<p>I have implemented suggestion and created new draft of the Tic Tac Toe program. Please review and let me know where I can improve.</p>
<pre><code>import random
def update_board():
"""Play game"""
board = [[3 * row + col for col in range(1, 4)] for row in range(3)]
total_co... | [] | [
{
"body": "<p>Follow <a href=\"https://www.python.org/dev/peps/pep-0008/#function-and-variable-names\" rel=\"nofollow noreferrer\">PEP8</a> naming conventions when naming variables and functions.</p>\n<hr />\n<p><code>user_turn == False</code> should be <code>user_turn is False</code>, or even better <code>not ... | {
"AcceptedAnswerId": "262927",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T20:47:37.940",
"Id": "262898",
"Score": "1",
"Tags": [
"python",
"python-3.x",
"tic-tac-toe"
],
"Title": "Tic Tac Toe (new draft)"
} | 262898 |
<p>This is a small script to update my project's README file. Notes on improvements from any aspect are welcome!</p>
<p>Here is the <a href="https://raw.githubusercontent.com/T145/the-blacklist/master/.github/README.md" rel="nofollow noreferrer">document it updates</a>.</p>
<p><strong>readme.sh</strong> <em>(Executed l... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T19:57:32.603",
"Id": "519039",
"Score": "1",
"body": "It is great to see what you ended up with. https://github.com/T145/the-blacklist/blob/master/scripts/update_readme.sh You've integrated our feedback excellently. Bravo."
}
] | [
{
"body": "<h1>Good</h1>\n<ul>\n<li>great variable names, but I quibble over a couple later on</li>\n<li>nice use of blank lines to organize code</li>\n<li>appropriate use of <code>sed</code>. (Regex search and replace is the only time to use it.) I wouldn't expect any XML tools to be an improvement. <code>:)... | {
"AcceptedAnswerId": "262907",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T21:42:31.053",
"Id": "262903",
"Score": "6",
"Tags": [
"bash",
"linux",
"posix",
"sh"
],
"Title": "Updating text in a HTML document with Bash"
} | 262903 |
<p>I'm not asking for help solving a problem but rather asking for help for possible ways to improve the speed of my program.</p>
<p><strong>Essentially what this does is:</strong>
Tracks market data by pulling the data from the public API provided by the devs.
Compares the data with a pre-determined price I input, if ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T15:30:03.310",
"Id": "519000",
"Score": "0",
"body": "Is the slowest part `resp = s.get(URL).json()`? If so, does `URL` have any options to perhaps reduce the response payload?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"Cr... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-10T22:30:37.680",
"Id": "262905",
"Score": "3",
"Tags": [
"python",
"performance",
"python-3.x",
"web-scraping",
"api"
],
"Title": "Speed Up API Requests & Overall Python Cod... | 262905 |
<p>I got tasked to develop an accordion-like function for a webpage.</p>
<ul>
<li>The header will always be visible, while the main content (and footer) be styled as <code>display: none;</code></li>
<li>At the end of the header, there's a button. Clicking on it will trigger my jQuery code.</li>
<li>The code should set ... | [] | [
{
"body": "<p>Your code looks fine. First, there isn't much going on so it would be a little too early to think about optimizations or all other sorts of things, unless you experience a real problem.</p>\n<p>But to make it more clear or simplify it, this is how I would recommend to do it:\nCache HTML elements (... | {
"AcceptedAnswerId": "262917",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T01:31:42.910",
"Id": "262910",
"Score": "2",
"Tags": [
"jquery"
],
"Title": "jQuery: Scrolling down into a content"
} | 262910 |
<p>I'm building a fuzzy search table widget in <a href="https://github.com/fltk-rs/fltk-rs" rel="nofollow noreferrer">FLTK-RS</a>. On my pretty decently spec'd machine I'm getting pretty laggy performance, does anyone have any thoughts on ways to improve this?</p>
<p>If you'd like to clone it from a repo, here's a link... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T01:35:00.080",
"Id": "262912",
"Score": "0",
"Tags": [
"rust"
],
"Title": "Fuzzy Search Table Widget in FLTK-Rs"
} | 262912 |
<pre><code> register(name, version, ip, port) {
this.cleanup();
const key = name + version + ip + port;
if (!this.services[key]) {
this.services[key] = {};
this.services[key].timestamp = Math.floor(new Date() / 1000);
this.services[key].ip = ip;
this.services[key].port = port;
... | [] | [
{
"body": "<p>The code is pretty clear, I wouldn't call amateurish. Some cleanup could be done, though.</p>\n<h1>Avoid duplication</h1>\n<p>The timestamp code is duplicated, you could create a function for it:</p>\n<pre><code>const getTimestamp = () => {\n return Math.floor(new Date() / 1000)\n}\n</code><... | {
"AcceptedAnswerId": "262975",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T01:54:48.027",
"Id": "262914",
"Score": "1",
"Tags": [
"node.js"
],
"Title": "Node.js Service Registry"
} | 262914 |
<p>I was working on the problem to check if the parenthesis are balanced using Scala.</p>
<p>Examples:</p>
<ul>
<li><code>balance("(Hello (my) name is (StackOverflow))")</code> -> <code>True</code></li>
<li><code>balance("(Hello (my) name is StackOverflow))(((((((")</code> -> <code>False</code... | [] | [
{
"body": "<p>First off, I'm not sure why <code>processChar</code> throws an <code>IllegalArgumentException</code> on non-paren characters - wouldn't it be fine to just ignore those characters instead and return the stack unchanged? Those characters don't affect whether a string is balanced or not, after all.</... | {
"AcceptedAnswerId": "263244",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T03:26:29.010",
"Id": "262918",
"Score": "2",
"Tags": [
"functional-programming",
"scala"
],
"Title": "Scala Parentheses Balancing in Functional Programming"
} | 262918 |
<h3>Setup</h3>
<p>I am writing a class based, object oriented algorithm in typescript. In many cases, a class will create another child class, passing itself as an argument to the child class. For example:</p>
<pre><code>interface RoomDetails {
name: string;
items: string[];
}
class House {
rooms: Room[];
c... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T05:22:35.493",
"Id": "518974",
"Score": "0",
"body": "\"every new Item has references to both the Room and House it belongs to\" Why sabotage yourself? Why do this when you can find the house from the room the item belongs to? Why w... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T04:37:30.760",
"Id": "262921",
"Score": "0",
"Tags": [
"object-oriented",
"typescript",
"classes"
],
"Title": "Best practice to denote circular references in typescript classes an... | 262921 |
<p>(See the previous version <a href="https://codereview.stackexchange.com/questions/262790/a-simple-clusterness-measure-of-data-in-one-dimension-using-java-follow-up">here</a>.)</p>
<p>This time, I have encorporated all the suggestions made by <a href="https://codereview.stackexchange.com/users/227157/marc">Marc</a>. ... | [] | [
{
"body": "<p>The only thing I would change in your code is about the <code>Comparator</code> you are using below:</p>\n<pre><code>processedPoints.sort(\n (a, b) -> Double.compare(\n a.doubleValue(), \n b.doubleValue()));\n</code></pre>\n<p>You could use the... | {
"AcceptedAnswerId": "262964",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T11:29:02.933",
"Id": "262932",
"Score": "2",
"Tags": [
"java",
"machine-learning",
"numerical-methods"
],
"Title": "A simple clusterness measure of data in one dimension using... | 262932 |
<p>I am dealing with a string <code>draw_result</code> that can be in one of the following formats:</p>
<pre><code>"03-23-27-34-37, Mega Ball: 13"
"01-12 + 08-20"
"04-15-17-25-41"
</code></pre>
<p>I always start with <code>draw_result</code> where the value is one from the above values. I ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T23:28:46.263",
"Id": "519055",
"Score": "2",
"body": "Just to understand the setup here: why is the `13` excluded in the first example?"
}
] | [
{
"body": "<p>Nice solution, a few suggestions:</p>\n<ul>\n<li>The function name <code>convert_to_int_array</code> seems too general. Consider a more specific name, for example, <code>extract_numbers</code>, or something similar.</li>\n<li>There is no need to initialize <code>results_as_array</code> to <code>No... | {
"AcceptedAnswerId": "262934",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T11:41:06.510",
"Id": "262933",
"Score": "3",
"Tags": [
"python"
],
"Title": "Converting a string to an array of integers"
} | 262933 |
<p>I have to deal with raw memory manipulation. For that I wrote a function which stores data one after another, and another function which reads this data and stores it into variables.</p>
<p>More precisely:</p>
<pre><code>/**
* - `void * pack( dest, src1, ..., srcn )`
* `void * pack( void * dest, src1, ..., srcn ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T14:47:00.547",
"Id": "518997",
"Score": "2",
"body": "I think it's reasonable to include your tests using Google Test, even if you also provide the `main()` for convenience. That allows us to review the tests properly, too (e.g. na... | [
{
"body": "<p>Auto-review by compiler:</p>\n<pre class=\"lang-none prettyprint-override\"><code>g++-10 -std=c++20 -fconcepts -fPIC -g -Wall -Wextra -Wwrite-strings -Wno-parentheses -Wpedantic -Warray-bounds -Weffc++ 262935.cpp -o 262935\n262935.cpp:41:105: warning: extra ‘;’ [-Wpedantic]\n 41 | temp... | {
"AcceptedAnswerId": "262983",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T13:32:23.657",
"Id": "262935",
"Score": "6",
"Tags": [
"c++",
"memory-management",
"c++14",
"serialization"
],
"Title": "Packing and unpacking values in a buffer"
} | 262935 |
<p>This script simply installs the chosen packages if they're not present on a Linux system using the <code>apt</code> package manager. Notes on improvements of any aspect are welcome!</p>
<p><strong>setup_env.sh</strong></p>
<pre class="lang-bsh prettyprint-override"><code>#!/usr/bin/env bash
set -euo pipefail
instal... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T16:07:25.693",
"Id": "519004",
"Score": "0",
"body": "I don't know bash, and this doesn't merit an answer, but would it be easier to make the list of packages to install an array that you can iterate over? You could then avoid typin... | [
{
"body": "<h1>Good</h1>\n<ul>\n<li>Yay for using a function to contain most of the functionality</li>\n<li>Good indentation</li>\n<li>It looks like you're following shellcheck</li>\n<li>Good names for the variable and function</li>\n</ul>\n<h1>Suggestions</h1>\n<ul>\n<li>Use double square brackets for conditio... | {
"AcceptedAnswerId": "262946",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T15:55:31.857",
"Id": "262937",
"Score": "1",
"Tags": [
"bash",
"linux",
"posix",
"installer"
],
"Title": "Installing packages if they don't exist in Bash"
} | 262937 |
<p>I am in need of a "debiased" clamp function, to generate a uniformly-distributed random number from a good PRNG.</p>
<p>Let's assume that <code>RNG</code> in the below code is a field containing an instance of a good (or good enough) PRNG such as PCG, Xoshiro, or MT, which produced a reasonably-uniform dis... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T17:21:14.173",
"Id": "519012",
"Score": "0",
"body": "Why not simply `return RNG.NextPositiveInt() % maxnum`?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T18:54:40.143",
"Id": "519023",
"Sc... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "10",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T16:10:43.243",
"Id": "262938",
"Score": "1",
"Tags": [
"c#",
"algorithm"
],
"Title": "C# Debiasing from Good PRNG"
} | 262938 |
<p>I am implementing a function that computes the angle between two vectors when given two n-dimensional arrays and an axis along which to operate. I want to do this with as few copies as possible, and as numerically stable as possible. (The latter gets problematic for small angles (<a href="https://scicomp.stackexchan... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T17:48:38.780",
"Id": "262945",
"Score": "1",
"Tags": [
"python",
"performance",
"numpy",
"vectorization"
],
"Title": "Computing the angle between two vectors (vectorized) for ... | 262945 |
<p>This method is supposed to make a custom requests and then get its response. Sometimes, the response is a string, and most the time the response is in JSON format. As far as I know I can't have a function which returns either a string or a json format. So because of that I have the same method twice but one returns ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T18:27:14.903",
"Id": "519019",
"Score": "1",
"body": "1) `Skip SSL` unacceptable as a huge security breach 2) `HttpWebRequest` is deprecated many years ago, use `HttpClient` instead 3) use [asynchronous programming](https://docs.mic... | [
{
"body": "<ul>\n<li>Don't bypass Certificate validation. You may install development certificates provided by Microsoft for debugging.</li>\n<li>Use suffix <code>Async</code> for Task-returning (awaitable) methods. It makes code more readable.</li>\n<li>As far as I can see, the solution is intended to simplify... | {
"AcceptedAnswerId": "262973",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T18:21:38.113",
"Id": "262949",
"Score": "2",
"Tags": [
"c#"
],
"Title": "C# A function to make custom requests"
} | 262949 |
<p>So I have been learning more about binary numbers lately, particularly
in related to describing a gamestate. While perhaps chess is the most natural candidate I wanted to start of with something simpler. So I choose tic tac toe. For reference I used the <a href="https://libfbp.blogspot.com/2017/05/tic-tac-toe-bitboa... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T23:51:45.887",
"Id": "519059",
"Score": "0",
"body": "This is certainly more interesting that the typical tic-tac-toe question – worth an upvote! It would be better still if you were to provide more details on your benchmarking: how... | [
{
"body": "<h1>Bugs</h1>\n<h2><code>COL1 == COL3</code></h2>\n<p>This will make it hard to win in one of those two columns!</p>\n<h2><code>if move</code></h2>\n<p>Your mainline will call <code>board.add_and_update_state(move)</code> with <code>move = 0</code>, which in turn calls various other methods with <cod... | {
"AcceptedAnswerId": "262969",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-11T22:45:15.593",
"Id": "262956",
"Score": "8",
"Tags": [
"python",
"python-3.x",
"tic-tac-toe",
"bitwise",
"bitset"
],
"Title": "Representing Tic-Tac-Toe using a binary ... | 262956 |
<p>I'm using this kind of data binding in PHP, is it safe?</p>
<pre><code>$sql = "CALL registerUsers(?, ?, ?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("sssssss", $_usr_code, $_usr_eml, $_usr_name, $_usr_pass, $_fileName, $_usr_type, $_usr_role);
$stmt->execute();
</cod... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-12T09:22:26.337",
"Id": "519074",
"Score": "2",
"body": "There is no context here. This very short script is asking about _general best practice_, no?"
}
] | [
{
"body": "<p>Yes, it is safe, as in <code>$_usr_name</code> cannot be used to inject SQL commands.</p>\n<p>This doesn't mean <code>$_usr_name</code> can no longer be a threat. It could, for instance, contain Javascript code and do <a href=\"https://owasp.org/www-community/attacks/xss/\" rel=\"nofollow noreferr... | {
"AcceptedAnswerId": "262962",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-12T02:03:43.877",
"Id": "262959",
"Score": "-2",
"Tags": [
"php",
"html"
],
"Title": "PHP binding data in stored procedure"
} | 262959 |
<p>I have written a small program that swallows windows. It works in X.org using the xcb library. This is my first rust program but I have lots of other programming experience.</p>
<p>Any general improvements are great, but a specific problem I've been having is that if the program exits too quickly (child process is s... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-13T16:25:57.190",
"Id": "519132",
"Score": "1",
"body": "Would `xcb::map_window_checked(&conn, win).request_check().unwrap()` help you?"
}
] | [
{
"body": "<p>Welcome to Rust, and welcome to Code Review!</p>\n<p>I do not have a Linux device at hand, so I will focus more on the code itself rather than the functionality.</p>\n<h1><code>extern crate</code></h1>\n<p>In general, <code>extern crate</code> is <a href=\"https://stackoverflow.com/a/64623808\">no... | {
"AcceptedAnswerId": "263047",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-12T02:22:06.393",
"Id": "262960",
"Score": "3",
"Tags": [
"beginner",
"rust",
"linux",
"x11"
],
"Title": "Possible improvements to window swallowing program?"
} | 262960 |
<p>I have tried to code a genetic algorithm to guess the coefficients of a degree 4 polynomial. The information initially provided is values of y = f(x) for different x using the original polynomial. I then generate 100 polynomials with randomly selected coefficients. These polynomials are then ranked based on the leas... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T00:46:49.443",
"Id": "531687",
"Score": "0",
"body": "I have a question for you, did you get any coefficent value? thank you"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-11-09T04:54:43.547",
"Id": "5... | [
{
"body": "<h1>This is not the best algorithm</h1>\n<p>If the goal is to get the best coefficients for a polynomial so it fits the given points, then a <a href=\"https://en.wikipedia.org/wiki/Polynomial_regression\" rel=\"noreferrer\">polynomial regression</a> algorithm such as <a href=\"https://numpy.org/doc/s... | {
"AcceptedAnswerId": "262965",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-12T06:52:16.283",
"Id": "262963",
"Score": "7",
"Tags": [
"python",
"python-3.x",
"numpy",
"numerical-methods",
"genetic-algorithm"
],
"Title": "Genetic algorithm to gues... | 262963 |
<p>I got this two subjects that both have a delay and I need the second one to be subscribed when the first one is completed, asynchronously. Both subjects only emit once (http requests) and I'm trying to <strong>avoid nested subscriptions</strong> but I can't figure out an optimal solution.</p>
<p>What I've got so far... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-12T20:04:30.087",
"Id": "519105",
"Score": "0",
"body": "This question does not seem to match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or chan... | [
{
"body": "<p>I think what you want to do is to have 2 subscriptions to your first http request, to achieve that just use a subject and subscribe to it. that way you can handle your second request with operators like <code>switchMap</code> <code>ConcatMap</code> etc, based on your needs. here is the sample base... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-12T09:36:18.110",
"Id": "262966",
"Score": "1",
"Tags": [
"rxjs"
],
"Title": "how to avoid nested asynchronous subscriptions in RxJS?"
} | 262966 |
<p>I'm wrote Asynchronous Lock provider for reducing lock that breaks <code>async</code> keyword.</p>
<p>All tasks with <code>async</code> and <code>await</code> keywords are chained by <code>GetAwaiter().OnCompleted(Callback)</code> on I know. But some cases are not, for example: <code>lock</code> keyword, <code>Event... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-17T20:53:09.420",
"Id": "519536",
"Score": "1",
"body": "Did I answer your question?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-19T10:17:28.367",
"Id": "519668",
"Score": "1",
"body": "@aep... | [
{
"body": "<p><code>SemaphoreSlim</code> provides async locking out-of-the-box.</p>\n<pre><code>using var semaphore = new SemaphoreSlim(1);\n\n// ...\n\nawait semaphore.WaitAsync();\ntry\n{\n // critical section code\n}\nfinally\n{\n semaphore.Release();\n}\n</code></pre>\n<blockquote>\n<p>Is this really ... | {
"AcceptedAnswerId": "262970",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-12T10:19:26.987",
"Id": "262967",
"Score": "0",
"Tags": [
"c#",
"async-await"
],
"Title": "C# Asynchronous Lock class"
} | 262967 |
<p>I have a controller whose role is to persist some data into an external resource (could be a file, database, or anything else). This class takes generic objects, which may implement <code>INotifyPropertyChanged</code>, or <code>INotifyStateChanged</code>, or none of them. Note the later is a simplified version of <c... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-12T12:43:51.240",
"Id": "262971",
"Score": "0",
"Tags": [
".net",
"vb.net"
],
"Title": "Data optionally observable"
} | 262971 |
<p>I have a C# program to check if a hard coded host is available and if not, waits then checks again (this is a loop in form of recursion). How can it be enhanced?</p>
<pre><code>using System;
using System.Net.NetworkInformation;
using System.Windows.Forms;
namespace trial17
{
public partial class Form5 : Form
... | [] | [
{
"body": "<p>You probably want to avoid using recursion on <code>conn</code>. Say you did not have internet connection for a long time. Then, for every failed connection you will add a new entry to the call stack. Which could eventually lead to a stack overflow.</p>\n<p>It's probably a better idea to have two ... | {
"AcceptedAnswerId": "262977",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-12T15:37:58.197",
"Id": "262974",
"Score": "1",
"Tags": [
"c#",
"networking",
"status-monitoring"
],
"Title": "Program to continuously check availability of internet connection c... | 262974 |
<p>I'm new to coding in general and I am working in flutter right now. I've successfully been able to add single string objects into a list but I'm having issues adding an object with multiple strings into a list. I'd love some guidance if anyone's able to help!</p>
<p>This is my model</p>
<pre><code>import 'dart:conve... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-12T16:18:30.597",
"Id": "262976",
"Score": "2",
"Tags": [
"dart",
"flutter"
],
"Title": "Adding multiple items to a list in flutter"
} | 262976 |
<p>I have a simple chat system. I have built this to scale so I would appreciate optimisation tips or alternative table structures too. This does not include the pub/ sub queue system.</p>
<p>Users</p>
<pre><code>| id | name | createdAt
</code></pre>
<p>Conversations - 1 Conversation has many messages & many partic... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-12T17:45:12.743",
"Id": "262978",
"Score": "1",
"Tags": [
"database",
"postgresql"
],
"Title": "Scalable and Optimised group chat system"
} | 262978 |
<p>I am trying to create a function which can visualize(compare) two items of 'Platform', 'Genre' and 'Publisher' according to the 'Global_Sales' in different 'Year'.</p>
<p>The DataFarame looks like:
<a href="https://i.stack.imgur.com/lymlx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lymlx.png" ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-12T21:35:36.513",
"Id": "519107",
"Score": "1",
"body": "Can you please include a minimal dataset, so we can run your code? =)"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-13T01:38:49.613",
"Id": "51... | [
{
"body": "<ul>\n<li>Don't need to sort at all, much less doing it twice over with the same criteria</li>\n<li>Why only accept two by-values, when you could accept an arbitrary number in a set?</li>\n<li>Your group-by criteria should be over both the year and your by-column</li>\n<li>No need to concat, reset an... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-12T18:51:15.783",
"Id": "262979",
"Score": "0",
"Tags": [
"python",
"data-visualization"
],
"Title": "Comparing global sales of video game publishers"
} | 262979 |
<p>I wrote a simple multitthreading program which does particle swarm optimization. Optimization itself and some corresponding functions were taken from <a href="https://nathanrooy.github.io/posts/2016-08-17/simple-particle-swarm-optimization-with-python/" rel="nofollow noreferrer">https://nathanrooy.github.io/posts/20... | [] | [
{
"body": "<p>Some suggestions:</p>\n<ol>\n<li>Run the code through <code>black</code> and <code>isort --profile=black</code> to format it more idiomatically without any manual work.</li>\n<li>Run the code through <code>flake8</code> or <code>pylint</code> to check for other maintainability issues.</li>\n<li>Ru... | {
"AcceptedAnswerId": "262995",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-12T19:43:05.110",
"Id": "262980",
"Score": "3",
"Tags": [
"python",
"python-3.x",
"multithreading"
],
"Title": "Particle swarm algorithm with multiple threads"
} | 262980 |
<p>I'm pulling data in from an API and putting it in the top two rows of a sheet. This script is to copy the data from the "pull" sheet into a daily sheet. The rub is that the data may change and I want to dynamically copy the data over; i.e. if the column header exists, put the new data in the bottom row. ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-12T20:23:44.553",
"Id": "262981",
"Score": "0",
"Tags": [
"javascript",
"google-apps-script"
],
"Title": "Is there a better way to copy dynamic data from one sheet to another in google s... | 262981 |
<p>I am attempting to learn the Nim language by making a small and simplistic <a href="https://en.wikipedia.org/wiki/Register_machine" rel="nofollow noreferrer">register machine</a>.
It is intended to interpret some basic instructions.</p>
<p>The entire parsing lexing process consists of splitting the inputted code by ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-13T17:30:25.970",
"Id": "519136",
"Score": "0",
"body": "I rolled back your last edit. In this exchange, editing the question after it's been answered, invalidates the answer."
},
{
"ContentLicense": "CC BY-SA 4.0",
"Creati... | [
{
"body": "<blockquote>\n<p>The entire parsing lexing process consists of splitting the inputted code by spaces (not whitespace in general), which newlines are counted as. Is this reasonable code style in Nim?</p>\n</blockquote>\n<p>Those are completely different things: you're writing an interpreter for some o... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-13T05:04:31.803",
"Id": "262989",
"Score": "2",
"Tags": [
"performance",
"beginner",
"interpreter",
"virtual-machine",
"nim"
],
"Title": "Tiny attempt at a register machine i... | 262989 |
<p>I started learning OOP programming style in PHP. After end of the course, I wrote a simple calculator in OOP style. Can some one check my code and give me feedback?</p>
<pre><code>//Calculator Class
<?php
use lib\calculator\classes as classes;
spl_autoload_register(function ($className) {
require_once $clas... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-13T07:17:10.387",
"Id": "519119",
"Score": "2",
"body": "Welcome to Code Review! I changed the title so that it describes what the code does per [site goals](/questions/how-to-ask): \"*State what your code does in your title, not your ... | [
{
"body": "<p>A very short answer with a few things I noticed.</p>\n<ul>\n<li>The <code>__destruct()</code> function in class <code>calculator</code> doesn't do anything useful.</li>\n<li>The methods <code>__construct()</code>, <code>getNumOne()</code>, <code>setNumOne()</code>, <code>getNumTwo()</code> and <co... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-13T06:38:37.973",
"Id": "262991",
"Score": "4",
"Tags": [
"php",
"object-oriented",
"calculator"
],
"Title": "Object-oriented calculator class"
} | 262991 |
<p>I want to create a hierarchy of Typescript interfaces because I think classes would be an overkill in my case. The main obstacle is checking if an object has a specific type. I solved it this way:</p>
<pre class="lang-js prettyprint-override"><code>enum AnimalId {
Mammal = 1,
Fish = 3,
}
interface BaseAnimal {
... | [] | [
{
"body": "<p>Your questions:</p>\n<ol>\n<li>You could use BaseAnimal, but that would only give you the base properties. There's no way I know of to make this work other than casting, but that would make it unsafe. The discriminated union is quite nice imo, it's very easy to understand.</li>\n<li>Since typescri... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-13T07:01:56.163",
"Id": "262992",
"Score": "2",
"Tags": [
"javascript",
"typescript",
"type-safety"
],
"Title": "Typescript type checking of hierarchical types"
} | 262992 |
<p>Im making this project from few days , and now i need little help because i am struggling.
The task says</p>
<p>II. Define a student booklet class CStudBook that inherits CStudent with a member data container of the student's grades. To implement a constructor with a filename parameter from which to initialize conta... | [] | [
{
"body": "<ol>\n<li>The task is flawed. Inheritance should be "is a" relation, but "Student booklet is a student" is false. <a href=\"https://en.wikipedia.org/wiki/Liskov_substitution_principle\" rel=\"nofollow noreferrer\">LSP</a> will not work here. Of course, it's up to your tutor to tea... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-13T11:58:06.577",
"Id": "262996",
"Score": "-1",
"Tags": [
"c++",
"object-oriented",
"classes"
],
"Title": "c++ program with 2 classes"
} | 262996 |
<p>from kotlin <a href="https://kotlinlang.org/docs/coding-conventions.html#class-layout" rel="nofollow noreferrer">page</a> we can read:</p>
<blockquote>
<p>In particular, when defining extension functions for a class which are
relevant for all clients of this class, put them in the same file with
the class itself. Wh... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-13T13:22:05.430",
"Id": "519128",
"Score": "1",
"body": "Welcome to the Code Review Community, please post your real working code, not `simplified` code."
}
] | [
{
"body": "<p>I have very little information about your code overall, but I have this feeling, that you have all your 'code' code in one huge module.</p>\n<p>DTO is used to represent your models outside your app and to communicate with another layer and are not part of your domain.\nFollowing that, I expect tho... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-13T12:25:20.903",
"Id": "262997",
"Score": "0",
"Tags": [
"kotlin",
"extension-methods",
"dto"
],
"Title": "Kotlin extension function in dto vs pojo dto in hexagonal architecture"
} | 262997 |
<p>Is there a better way to loop item of an array using <code>forEach</code> and make repeat it using <code>setTimout</code>/<code>Interval</code> or something else?</p>
<p>I need that each item of the array was repeated each value of delay for some time (duration):</p>
<pre><code>const arr = [
{ delay: 1_000, durati... | [] | [
{
"body": "<h2>Source code is too complex</h2>\n<p>The code is way too complex for what you are doing\nMainly due to all of the superfluous code.</p>\n<h3>Not needed</h3>\n<ul>\n<li>all the <code>return null</code>,</li>\n<li>all of the class code for object <code>loopElm</code></li>\n<li><code>that = this</cod... | {
"AcceptedAnswerId": "263014",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-13T14:33:04.267",
"Id": "263000",
"Score": "1",
"Tags": [
"javascript",
"array",
"closure"
],
"Title": "Each item of the array must loop and show message for some time (duration)... | 263000 |
<p>I tried to make a simple recursive web scraper using Python. My idea was to grab all the links, titles and tag names.</p>
<p>Website: <a href="https://lifebridgecapital.com/podcast/" rel="nofollow noreferrer">https://lifebridgecapital.com/podcast/</a></p>
<p>Course of Action:</p>
<p>Grab all the tags links from the ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T19:11:28.653",
"Id": "519209",
"Score": "1",
"body": "Can you include the code for HTMLSession ? I suspect this is a part that can potentially be improved."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06... | [
{
"body": "<p>First: if you only cared about the episode links, there's no reason to scrape. They have an <a href=\"https://feeds.buzzsprout.com/489505.rss\" rel=\"nofollow noreferrer\">RSS feed</a> that is not only machine-readable and structured (unlike the HTML), it's structured better than the resulting CSV... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-13T15:03:27.473",
"Id": "263002",
"Score": "3",
"Tags": [
"python",
"python-3.x",
"recursion",
"web-scraping"
],
"Title": "Simple Python Recursive Web Scraper"
} | 263002 |
<p>I've written a simple LRU cache class and I am trying to make it thread-safe. My thoughts are that I just need to wrap the code that updates the ordered dict in a lock so that if any thread is writing to the ordered dict, all other writes/reads need to wait. Is that correct?</p>
<p>Also, what is the best way to test... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-13T19:57:37.833",
"Id": "519138",
"Score": "1",
"body": "Welcome to Code Review! I changed the title so that it describes what the code does per [site goals](/questions/how-to-ask): \"*State what your code does in your title, not your ... | [
{
"body": "<p>The use of <code>self._store</code> isn't thread-safe, because we are only locking its writers. We need to ensure that readers don't see it in an inconsistent state, too.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-13T20:14:23.903",... | {
"AcceptedAnswerId": "263009",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-13T19:26:35.383",
"Id": "263008",
"Score": "-1",
"Tags": [
"python",
"multithreading",
"cache"
],
"Title": "Thread-safe LRU cache in Python"
} | 263008 |
<p>A while ago I decided to start working on a project that will keep me busy for a while and will help me sharpen my programming skills.
I do not underestimate the work behind apps like adobe xd, sketch.app, or figma but I just want to understand how those apps work and if I can do something similar.</p>
<p>The featur... | [] | [
{
"body": "<p>This is perfect example for inheritance. You should separate code into multiple files and get rid of</p>\n<pre><code>if(type === '...') {\n // ...\n}\n</code></pre>\n<p>conditions. Shape class should contain only common functions like</p>\n<pre><code>public get isSelected(): boolean {}\npublic se... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-13T21:55:43.787",
"Id": "263011",
"Score": "0",
"Tags": [
"javascript",
"canvas",
"vue.js"
],
"Title": "Draw shapes using the Html5 Canvas api"
} | 263011 |
<p>I'm using MemorySharp to calculate the memory address from a pointer address and then inject values in memory.</p>
<p>The code works perfectly, but I was wondering if this would be the right way. I found a little dirty the way I'm calculating the memory address. Maybe there's a easier way that I'm not able to see.</... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T09:58:16.877",
"Id": "519156",
"Score": "2",
"body": "In 64 bit app the address is `long` not `int`, check `IntPtr.Size`."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T16:42:30.380",
"Id": "5191... | [
{
"body": "<p>Clean code advice.\nYou need to calculate Base in a loop with two expressions:</p>\n<pre><code>Base += ptr;\nBase = mSharp.Read<IntPtr>(Base, false);\n</code></pre>\n<p>The second should not be calculated for the last iteration, but before the loop you have</p>\n<pre><code>IntPtr Base = mSha... | {
"AcceptedAnswerId": "263016",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T04:36:52.457",
"Id": "263015",
"Score": "0",
"Tags": [
"c#",
"memory-management"
],
"Title": "Getting address with MemorySharp"
} | 263015 |
<p>Print all combinations from dictionary which will result in the number N</p>
<pre><code> Input:
Dictionary { “flag”:4.5, “temp”:2 ,”foo”:9} and N = 11
Output:
temp*1+flag*2
flag*2+temp*1
foo*1+temp*1
temp*1+foo*1
</code></pr... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T14:11:24.053",
"Id": "519181",
"Score": "2",
"body": "Orderings are not considered in combinations. `temp*1 + flag*2` and `flag*2 + temp*1` would be considered the same combination. Permutations are ordering dependent. Perhaps yo... | [
{
"body": "<p>I'm picking up your point: <em>The code looks nasty but I am not sure how to make it look good.</em></p>\n<p>if you are using java it's recommended to write code in object-orientated manner. Doing so will clean up (and bloat) the code, hopefully it finally leads to an SOLID code ;-)</p>\n<h2>one S... | {
"AcceptedAnswerId": "263311",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T08:09:32.417",
"Id": "263018",
"Score": "2",
"Tags": [
"java",
"algorithm",
"programming-challenge"
],
"Title": "Print all combinations from dictionary which will result in nu... | 263018 |
<p>I made very simple scripting language (interpreter) in C and now, I want to make my code better.</p>
<p>Here is my code:</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TRUE (1 == 1)
#define FALSE (1 == 0)
#define FUNCTION_COUNT 2
#define MAX_FUNCTION_NAME_LENGTH... | [] | [
{
"body": "<p>Careful with choice of identifiers - names beginning with <code>str</code> are reserved for future library extension. The identifiers beginning with <code>is_</code> are okay, because <code>_</code> isn't a lowercase letter.</p>\n<p>This is needlessly verbose:</p>\n<blockquote>\n<pre><code>if (st... | {
"AcceptedAnswerId": "263020",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T08:31:08.040",
"Id": "263019",
"Score": "3",
"Tags": [
"c",
"interpreter"
],
"Title": "Very simple scripting language (interpreter) in C"
} | 263019 |
<p>A new version of this code based on the provided advice can be found <a href="https://codereview.stackexchange.com/questions/263059/c-threadgroup-implementation">here</a>.
Latest improvement is found <a href="https://codereview.stackexchange.com/questions/263098/c-improved-threadgroup-implementation">here</a>.</p>
<... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T11:57:28.320",
"Id": "519163",
"Score": "0",
"body": "I wouldn't call this a thread _pool_ - that would imply that calling code could come along and find a running thread to do its work. Here, we just have a gang of threads that st... | [
{
"body": "<p><code>start_and_block()</code> is mis-named - call it <code>start_and_busy_wait()</code>. Busy-waiting is inefficient. Instead of avoiding <code>std::condition_variable</code>, embrace it; use it in the slow path instead of <code>while(threads.size() > threads_ready.load());</code> and <code>... | {
"AcceptedAnswerId": "263023",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T11:11:12.503",
"Id": "263022",
"Score": "3",
"Tags": [
"c++",
"c++11",
"multithreading"
],
"Title": "C++11 ThreadPool implementation"
} | 263022 |
<p>This is a follow-up question for <a href="https://codereview.stackexchange.com/q/262690/231235">Image Processing Median Filter in C</a>. I am attempting to create a <a href="https://en.wikipedia.org/wiki/Gaussian_function" rel="nofollow noreferrer">two dimensional gaussian</a> image like below in C.</p>
<p><a href="... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T13:23:20.417",
"Id": "519175",
"Score": "0",
"body": "It seems like you implemented your own BMP-format routines? Why?"
}
] | [
{
"body": "<h1>Don't use <code>long double</code></h1>\n<p>Almost no code needs <code>long double</code>; it has much more precision than you need, and it is much less efficient than a <code>float</code>. Really, stop using it.</p>\n<h1>Use <code>size_t</code> for sizes, counts and indices</h1>\n<p>This is some... | {
"AcceptedAnswerId": "263046",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T13:07:53.653",
"Id": "263024",
"Score": "4",
"Tags": [
"algorithm",
"c",
"file",
"image",
"memory-management"
],
"Title": "Two dimensional gaussian image generator in ... | 263024 |
<p>I wrote a file sytem watcher class that is used to monitor file modification and then execute user-defined handler. Other file system events like moving or deleting don't need to be monitored. The usage is pretty straightforward:</p>
<pre><code>const auto watcher = fswatcher.on_modify("file.txt", [] () {
... | [] | [
{
"body": "<blockquote>\n<p>So what do you think about this commenting style?</p>\n</blockquote>\n<p>It encourages <em>meandering</em> functions, and does not help make sure each "clump" is cohesive. You lose the exit pathway, where you can <code>return</code> when you have the answer as the function... | {
"AcceptedAnswerId": "263042",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T13:34:46.353",
"Id": "263025",
"Score": "2",
"Tags": [
"c++",
"multithreading",
"file-system",
"linux",
"c++20"
],
"Title": "A file system watcher class for on-fly fil... | 263025 |
<p>I want to show the battery icon given the <code>status</code> provided in props. I am trying to keep it simple but without writing too much code, i.e.: . <code>if ... else</code>, <code>switch</code>s statements...</p>
<p>Below code snippet works but it kinda looks forced, not sure.</p>
<pre><code>import {
TiBat... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T15:01:40.533",
"Id": "519186",
"Score": "0",
"body": "little code. It is nice. All by Fowler ))"
}
] | [
{
"body": "<h2>Prefer <code>const</code> over <code>let</code></h2>\n<p>The variable <code>Balance</code> is declared with <code>let</code>.</p>\n<blockquote>\n<pre><code>let Balance = battery[status].icon;\n</code></pre>\n</blockquote>\n<p>It can be declared with <code>const</code> instead, since it is only as... | {
"AcceptedAnswerId": "263033",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T14:36:37.130",
"Id": "263026",
"Score": "2",
"Tags": [
"react.js",
"jsx"
],
"Title": "Show react component given a condition"
} | 263026 |
<p>First of all, I chose the nearest data points/training examples</p>
<pre><code>import numpy as np
import copy
nearest_setosa = np.array([[1.9, 0.4],[1.7, 0.5]])
nearest_versicolour = np.array([[3. , 1.1]])
</code></pre>
<p>and then I labeled negative examples as -1, and kept the label for the positive example.</p>
... | [] | [
{
"body": "<h2>There are certainly things you could improve</h2>\n<p>This use of global is quite confusing: you are using eta, model_w and model_b as a local variables to the <code>for eta in np.arange(.1, 2.0, .1)</code>, not as a global state. A cleaner way to do that would be to pass them as parameters to up... | {
"AcceptedAnswerId": "263151",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T14:46:47.610",
"Id": "263027",
"Score": "2",
"Tags": [
"python",
"algorithm",
"machine-learning"
],
"Title": "a prototype of finding the (almost) best learning rate and initia... | 263027 |
<p>I'm trying to learn how to use logistic regression with Sklearn. After learning the theory, I tried implementing it using the <a href="https://www.kaggle.com/rashikrahmanpritom/heart-attack-analysis-prediction-dataset" rel="nofollow noreferrer">Heart Attack Analysis</a> datasheet from Kaggle.</p>
<p>Here's a snippet... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-24T15:59:59.660",
"Id": "520040",
"Score": "0",
"body": "What is your expected score for using logistic regression?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-24T16:01:23.240",
"Id": "520041",
... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T15:29:43.090",
"Id": "263028",
"Score": "0",
"Tags": [
"python-3.x",
"machine-learning",
"classification"
],
"Title": "Logistic regression using Sklearn in Python"
} | 263028 |
<h2>What it does</h2>
<ul>
<li>Converts melting point and boiling point from degrees celsius to kelvin</li>
<li>These are in a dict which is in a tuple as no changes should be made to it</li>
<li>No user input</li>
</ul>
<h2>Purpose</h2>
<p>Learning exercise to understand classes and OOP</p>
<h2>What I need help with</... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T17:08:38.013",
"Id": "519193",
"Score": "0",
"body": "`to_kelvin(self, celsius: int)` seems more like a general utility function rather than a method related to or acting on `ConvertToKelvin`. If this was more integrated, I might e... | [
{
"body": "<p>Very nice question and great use of types! Let us step through your questions one at a time</p>\n<hr />\n<p><strong><code>Is this how you do classes</code></strong></p>\n<p>I would argue <em>no</em>, but let us take a step back and look at how brilliant classifies as a <code>class:</code></p>\n<bl... | {
"AcceptedAnswerId": "263035",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T15:38:22.077",
"Id": "263030",
"Score": "3",
"Tags": [
"python-3.x",
"object-oriented",
"classes"
],
"Title": "Temperature Converter: °C to K"
} | 263030 |
<p>I seek critique on a sorting implementation for a dynamic array data-structure.</p>
<h2>Design decisions</h2>
<ul>
<li>Uses the quicksort algorithm.</li>
<li>Uses an optimized XOR swap for swapping the elements. XOR swap doesn't need
extra memory and is optimized to do the swapping in up to 512 bit chunks.</li>
<li>... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T18:26:09.607",
"Id": "519204",
"Score": "0",
"body": "Unable to compile and test without 3rd party sites."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T19:17:13.690",
"Id": "519211",
"Score"... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T16:30:13.033",
"Id": "263032",
"Score": "2",
"Tags": [
"c",
"sorting"
],
"Title": "In place dynamic array sorting without using extra memory"
} | 263032 |
<p>This is a project to pull domain & IP blacklists from various sources and compile them into one list. There are some whitelists included that are applied when a blacklist is built.</p>
<p>It draws blacklist and whitelist source entries from <a href="https://raw.githubusercontent.com/T145/the-blacklist/master/sou... | [] | [
{
"body": "<h2>Minor nitpicks</h2>\n<p>While assigning variables from unquoted command substitutions apparently <em>is</em> safe, I personally prefer double quoting my command substitutions regardless of context - I find rules easier to remember if I follow them consistently. So I would have double quoted the <... | {
"AcceptedAnswerId": "263130",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T17:51:42.873",
"Id": "263036",
"Score": "4",
"Tags": [
"bash",
"linux",
"shell",
"sh"
],
"Title": "Generating a domain and IP blacklist with Bash"
} | 263036 |
<p>What can I improve in this script? Do I read user's yes/no answers by right way? Should I write bash scripts so that to be compatible with POSIX?</p>
<pre><code>#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o nounset
# set -o xtrace
if ! command -v zpool &> /dev/null || ! command -v zfs &> ... | [] | [
{
"body": "<p>I'm just reviewing the code, not the meaning behind it.</p>\n<hr />\n<p>Get out of the habit of using ALLCAPS variable names, leave those as\nreserved by the shell. One day you'll write <code>PATH=something</code> and then\n<a href=\"https://stackoverflow.com/q/27555060/7552\">wonder why</a>\nyour... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T18:12:23.107",
"Id": "263037",
"Score": "5",
"Tags": [
"bash",
"linux"
],
"Title": "Bash partitioning script"
} | 263037 |
<h1>Situation</h1>
<p>I'm scraping data from a paginated list on a website to be sent out as notifications.
For the most part we'll only need to scape the first page and handle additions, deletions and duplicates.</p>
<p>When adding a page with items we've never seen before, we just store the page in memory.</p>
<pre c... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T13:27:58.220",
"Id": "519279",
"Score": "0",
"body": "If a duplicate only gets into the log if the log has a duplicate, how did that duplicate get into the log in the first place? Also in your first example you state \"Notice how A ... | [
{
"body": "<p><code>_read_last_line</code> is clever but is going to be slow. You're better off reading in buffer chunks of say 1k and doing string operations like <code>.rindex</code>. This will almost certainly contain a newline on the first try for most kinds of log files. Once you have found the newline, yo... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T18:18:53.787",
"Id": "263038",
"Score": "3",
"Tags": [
"python",
"python-3.x",
"queue"
],
"Title": "Merging pages together into an append log"
} | 263038 |
<p><strong>Motivation:</strong> I was solving an array based i/o problem and encountered Time Limit Errors, it was later found that the code for java ran roughly <code>10x</code> slower than the python implementation.</p>
<p><strong>Question</strong>: I would like to know which part of my code failed in the latter impl... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T21:32:35.677",
"Id": "519224",
"Score": "0",
"body": "The standard comment/answer for performance questions: get yourself a decent profiler to find out what method call consumes the majority of time. I wouldn't be surprised to see s... | [
{
"body": "<h1>Python Code</h1>\n<ul>\n<li><a href=\"https://pep8.org/\" rel=\"nofollow noreferrer\">PEP-8</a> recommends\n<ul>\n<li>a space around binary operators like <code>=</code>.</li>\n<li>a space after commas (<code>n, k = …</code>)</li>\n<li>using the throw away variable (<code>_</code>) for loops whic... | {
"AcceptedAnswerId": "263053",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T20:49:05.717",
"Id": "263043",
"Score": "3",
"Tags": [
"python",
"java",
"performance",
"array",
"time-limit-exceeded"
],
"Title": "Java i/o speed less than python i/o... | 263043 |
<p>I've been trying to solidify my understanding of the binary number system by writing code. So, I tried to write a function with what I currently understand about the binary system that returns a string representation of the binary number representing the input.</p>
<p>Any feedback regarding how I may optimize the pr... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T23:36:10.253",
"Id": "519233",
"Score": "5",
"body": "*solidify my understanding of the binary number system*: I pedagogically suggest attempting a general algorithm to convert any given (input) number with its base, to any given (... | [
{
"body": "<p>Your code has a possible bug, depending on your CPU/compiler.</p>\n<p>You are treating <code>UINT32_MAX</code> (<code>0xFFFFFFFF</code>) as a special case, however, you could run into problems with any value greater that <code>0x80000000</code>.</p>\n<p>For example, if we let <code>n</code> be <co... | {
"AcceptedAnswerId": null,
"CommentCount": "13",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-14T21:18:21.323",
"Id": "263045",
"Score": "11",
"Tags": [
"c"
],
"Title": "Unsigned 32-bit integer to binary string function"
} | 263045 |
<p>I've decided it would be best to break this project down into several parts. Consider this Part 1(GUI Design).</p>
<p>I'm looking for help making 2 main improvements:</p>
<ol>
<li>Whenever I make a GUI, its always very repetitive to add JLabels, panels, buttons, adding panels to cards, etc. Is there a way to simplif... | [] | [
{
"body": "<p>Not sure where to start here:</p>\n<ol>\n<li>You are using Java</li>\n<li>The UX is bad</li>\n<li>It looks ugly</li>\n<li>The code isn't formtted</li>\n<li>It's just bad you know</li>\n</ol>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T00:12:19.413",
"Id": "263049",
"Score": "1",
"Tags": [
"java",
"swing",
"gui",
"awt"
],
"Title": "Bank Account GUI"
} | 263049 |
<p>I got this exercise on a job interview and i'd like to know how can i improve my code.</p>
<p>Exercise:</p>
<p>Create a function that returns a reduced version of a fraction.</p>
<p>Examples</p>
<ul>
<li>Reduce("4/6") = "2/3"</li>
<li>Reduce("10/11) = "10/11"</li>
<li>Reduce("... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T22:54:51.463",
"Id": "519341",
"Score": "0",
"body": "What does your code output for `Reduce(\"4/2\")`, `Reduce(\"4/-6\")`, `Reduce(\"-6/-2\")`, or any ill formated fractions involving 0 or infinity?"
}
] | [
{
"body": "<p>Not bad.</p>\n<ol>\n<li><p>Add tests and move examples there.</p>\n</li>\n<li><p>Split long lines:</p>\n<pre><code>if( members.Length != 2\n || !int.TryParse(members[0], out int numerator) \n || !int.TryParse(members[1], out int denominator) \n || denominator == 0\n)\n</code></pre>\n</li>\n</ol>\n... | {
"AcceptedAnswerId": "263066",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T01:32:45.220",
"Id": "263050",
"Score": "3",
"Tags": [
"c#",
"interview-questions"
],
"Title": "Function that receives a string fraction and has to return said fraction reduced"
} | 263050 |
<p>As stated, I know this works but I want to improve this code! I don't expect anyone to re-write this but if you have some "try this instead" then great!</p>
<pre class="lang-java prettyprint-override"><code>import java.util.*;
public class Polynomial implements Iterable<Object>, Comparable<Polyno... | [] | [
{
"body": "<p>I'm only looking at Polynomial and your Exception class.</p>\n<h2>General</h2>\nClasses not carefully and intentionally designed to be extended should be marked as final.\n<p>All of your classes are missing meaningful javadoc.</p>\n<p>Comments that explain what code is doing generally indicates th... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T03:42:35.530",
"Id": "263052",
"Score": "4",
"Tags": [
"java",
"algorithm"
],
"Title": "Java Polynomial, while I know this works, help me make it better"
} | 263052 |
<p>Edit: An improved code based on feedback is available <a href="https://codereview.stackexchange.com/questions/263098/c-improved-threadgroup-implementation">here</a>.</p>
<hr />
<p>As a kind of sequel to the previous <a href="https://codereview.stackexchange.com/questions/263022/c11-threadpool-implementation">questio... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T08:36:52.007",
"Id": "519253",
"Score": "0",
"body": "not really, I just prefer to keep it lowest as possible, because of portability reasons. I have been using C++14, and I found no features in c++17 that would make me switch. But ... | [
{
"body": "<h1>Fix compiler warnings</h1>\n<p>Enable compiler warnings and try to fix all of them. There are several unused parameters. You can avoid the warnings by not giving the parameters a name. For example, you can omit the name <code>start</code> from the lambda in <code>main()</code>:</p>\n<pre><code>[&... | {
"AcceptedAnswerId": "263087",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T06:55:01.087",
"Id": "263059",
"Score": "3",
"Tags": [
"c++",
"multithreading"
],
"Title": "C++ ThreadGroup Implementation"
} | 263059 |
<p>I want to see if there's a better way to write this code, solely in Javascript.</p>
<p>There are two kinds of sets, the first set (C7, T7, C11, T11) have four options in the first select, and then up to two options in the second set.</p>
<p>The second set (14X, 17X) have eight options in the first select, and then u... | [] | [
{
"body": "<p>As you likely observed in your code, it is very repetitive. Many programmers believe in the <strong><a href=\"https://en.wikipedia.org/wiki/Don%27t_repeat_yourself\" rel=\"nofollow noreferrer\"><em>Don't Repeat Yourself</em></a></strong>\n(i.e. D.R.Y.) principle. One way to do that is to abstract ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T07:40:05.713",
"Id": "263060",
"Score": "3",
"Tags": [
"javascript",
"beginner",
"ecmascript-6",
"event-handling"
],
"Title": "Limit second <select> options based on the first... | 263060 |
<p>I am writing API code using SpringBoot, Spring JDBC Template etc. In one scenario, I am fetching list of Object from DB and storing it like this:</p>
<pre><code>List<StudentDataVO> studentData = jdbcTemplate.query(sql, new ResultSetExtractor<StudentDataVO>(StudentDataVO.class), params);
</code></pre>
<p>... | [] | [
{
"body": "<ol>\n<li>Personally, I will not prefer mentioning List in the variable names if its already a list,\n<br>Example: <code>studentIDList</code></li>\n<li><code>populateStudentDescList</code>: Good use of the <code>stream</code>, but we can also filter the non null objects earlier,<br></li>\n</ol>\n<pre... | {
"AcceptedAnswerId": "263076",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T08:09:19.517",
"Id": "263061",
"Score": "2",
"Tags": [
"java"
],
"Title": "Improvement in code written using Java8 streams - traditional for loop"
} | 263061 |
<p>I'm trying to learn digital design this summer and currently going through this excercise of creating a 32-bit ALU based on this schematic:</p>
<p><a href="https://i.stack.imgur.com/DvomM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DvomM.png" alt="enter image description here" /></a></p>
<p>Im... | [] | [
{
"body": "<p>The layout of your code is good, and you chose meaningful names for your signals. There are some improvements you can make, however.</p>\n<p>The following signals are essentially unused:</p>\n<pre><code> wire logic negative, zero, carry, overflow;\n</code></pre>\n<p>You do make assignments ... | {
"AcceptedAnswerId": "263079",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T08:19:29.523",
"Id": "263063",
"Score": "3",
"Tags": [
"verilog"
],
"Title": "Finding the carry out of the \"+\" operator in SystemVerilog"
} | 263063 |
<p>I am attempting to implement two dimensional <a href="https://en.wikipedia.org/wiki/Bicubic_interpolation" rel="nofollow noreferrer">bicubic interpolation</a> algorithm in Matlab. The input is a two dimensional array and the output is the interpolated result.</p>
<p>The test input matrix:</p>
<pre><code>input = [1 1... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T11:42:16.703",
"Id": "263071",
"Score": "2",
"Tags": [
"algorithm",
"reinventing-the-wheel",
"image",
"numerical-methods",
"matlab"
],
"Title": "Two dimensional bicubic in... | 263071 |
<p>I have created a product configurator in VueJS and the whole functionality of it runs on one single function. I've put the word algoritm in the title in quotes because I don't really know if it is allowed that title. Anyhow, I have a feeling that the code I wrote is way to complicated and repeat a-lot of the same st... | [] | [
{
"body": "<h2>The original</h2>\n<p>Some comments on the code:</p>\n<pre><code>function addToChosenOptions(step, option) {\n -- if statement around the whole block. use the guard clause to return early\n // Option is in stock\n if(option.stock === 1) {\n -- too low level - extract it in... | {
"AcceptedAnswerId": "263296",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T12:22:44.840",
"Id": "263072",
"Score": "6",
"Tags": [
"javascript",
"beginner",
"algorithm",
"vue.js"
],
"Title": "Improving product configurator \"algoritm\""
} | 263072 |
<p>I'm programming a tool in Excel which reads two exported .csv files, performs some calculations based on <code>Dates</code> and <code>Strings</code> and populates a dashboard to be copied into a Google Sheet daily report.</p>
<p>Although the exported data would be no more than 150 rows (across two worksheets), I wro... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T13:44:29.407",
"Id": "519282",
"Score": "3",
"body": "Sees `'@Folder()`. Smiles at another RubberDuck user!"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T16:03:21.720",
"Id": "519305",
"Scor... | [
{
"body": "<h3>About "Fast" Code</h3>\n<p>I take [mild] issue with "fast mode" and similar "optimize speed" wordings, because code that needs these switches toggled is very often code that is simply inefficient, and turning off calculations and screen repaints makes the macro compl... | {
"AcceptedAnswerId": "263290",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T13:16:20.250",
"Id": "263074",
"Score": "4",
"Tags": [
"object-oriented",
"vba",
"classes"
],
"Title": "Using OOP/Class Module called \"FastMode\" to toggle Application object... | 263074 |
<p>I just wrote my first standard neural network with SGD gradient descent in c++, I am really interested if I have done anything wrong or inefficient, suggestions would help me a ton
(There is lots of CSV reading/writing code, because I like to plug CSV's to a website which converts CSV to Line graph to see how is my ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T14:03:28.733",
"Id": "519286",
"Score": "0",
"body": "I could have made actuvation function stuff bit cleaner with virtual classes, but that has a performance impact (I am pretty sure)."
},
{
"ContentLicense": "CC BY-SA 4.0... | [
{
"body": "<p><code>#define WEIGHT_RANDOM_RANGE .1</code><br />\nDon't use <code>#define</code> to make your constants. Use <code>constexpr</code>.</p>\n<p>In your CSV parser:</p>\n<pre><code> scalar value = scalar(std::stof(line.substr(0, found)));\n line = line.substr(found + 1, line.size());\n</code></pre>\... | {
"AcceptedAnswerId": "263080",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T14:02:18.503",
"Id": "263077",
"Score": "8",
"Tags": [
"c++",
"machine-learning",
"neural-network"
],
"Title": "My first functional naive neural network in C++"
} | 263077 |
<p>I'm trying to perform a decryption operation using RSA. I'm using the PolarSSl library. I have a char array <code>key[]</code> that contains RSA private key like the following,</p>
<pre><code>N = D0C2ACDCF780B1E4846054BDA700F18D567247FE8BC5BA4FBCAB814E619DA63A20F65A58EE89FC0824DC9367C5725BDDC596065F1C8868E99C896F3A0... | [] | [
{
"body": "<p>I don't know how this lib works but in general terms, replacing the <code>switch</code> with a look-up table should help with readability/maintenance and performance both. Since there's just 15 items, we don't need to use much memory for such a table and can afford to leave empty items in it.</p>\... | {
"AcceptedAnswerId": "263100",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T20:00:22.180",
"Id": "263085",
"Score": "1",
"Tags": [
"performance",
"c",
"strings",
"encryption"
],
"Title": "tokenize char array with PolarSSL library"
} | 263085 |
<p>I'm writing a simple function to transform functions by logging the result before returning it.</p>
<p>The function as written by me:</p>
<pre><code>function loggerise(f) {
return function() {
const r = f(...arguments)
console.log(r)
return r
}
}
</code></pre>
<p>(fiddle: <a href="https://jsf... | [] | [
{
"body": "<p>I don't know if you thought about this, but you can do it also like this:</p>\n<pre><code>function logI(f) {\n return function(...arguments) {\n const res = f(...arguments)\n console.log(res)\n return res\n }\n}\n\nfunction func(a1, a2) {\n return a1 + a2\n}\n\nlogI(func)(12,2)... | {
"AcceptedAnswerId": "263233",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T22:19:06.013",
"Id": "263088",
"Score": "4",
"Tags": [
"javascript",
"functional-programming"
],
"Title": "Add result-logging to any function"
} | 263088 |
<p>I am trying to find a way to pass a partial application as an argument of an other application with no overhead. I think I have find a way to do it (which might be dirty). The templated structure "partial_add" is kind of a partial version of add2. I am passing the type "partial_add" as template a... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-16T00:24:07.283",
"Id": "519346",
"Score": "1",
"body": "You might be looking for something called \"expression templates\". Boost has a fairly old library for that, but the technique in general is explained in many books and is a tec... | [
{
"body": "<p>If I understand your code, this example is simply:</p>\n<pre><code>int b[100];\n// ... the values for b are filled in with interesting things\nusing std::begin; using std::end;\n\nint a = std::accumulate (begin(b), end(b), 0);\n</code></pre>\n<p>as the default operation to <code>accumulate</code> ... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-15T22:53:01.927",
"Id": "263089",
"Score": "-1",
"Tags": [
"c++",
"performance",
"template"
],
"Title": "Passing a partial application as an argument of an other function with no ove... | 263089 |
<p>I am looking for best performance regarding this code point is I don't have a clear idea weather a map integrated in a for loop is a good idea, the problem is the array is a nested object coming from Db that I don't have any control of, could there be a better version ?
the code does the following
the for loop popul... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-16T06:42:26.630",
"Id": "519372",
"Score": "0",
"body": "The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to **simply sta... | [
{
"body": "<p><code>array.map()</code> is meant to convey that you're transforming the values of one array into another in a different array. If you're intending to do a side-effect (like printing to the console, or manipulating the DOM) iteratively and not return a result, <code>array.forEach()</code> conveys ... | {
"AcceptedAnswerId": "263093",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-16T03:09:45.793",
"Id": "263092",
"Score": "1",
"Tags": [
"javascript"
],
"Title": "Can this code be improved regarding map with in a For loop"
} | 263092 |
<p>I have the following code for the n queens problem described here: <a href="https://leetcode.com/problems/n-queens/" rel="nofollow noreferrer">https://leetcode.com/problems/n-queens/</a></p>
<pre><code>;; depth first permutations + early pruning
(define (left-diagonal-attack pos perm index n)
(if (empty? perm) #f... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-18T18:43:55.673",
"Id": "519636",
"Score": "0",
"body": "memory-wise seems hard to improve, most of the memory is being used to store the actual solutions right?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021... | [
{
"body": "<p>Probably not. C++ is known for its raw performance. It can work with data that is close to the machine's underlying representation, and easily compiles down fairly directly to machine code. Not only that, but the code you copied could probably optimize even better (run faster) if it used <code>... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-16T06:53:07.980",
"Id": "263097",
"Score": "0",
"Tags": [
"c++",
"racket"
],
"Title": "Why is this racket n queens code so inefficient?"
} | 263097 |
<p>After the amazing feedback from <a href="https://codereview.stackexchange.com/questions/263022/c11-threadpool-implementation/263078?noredirect=1#comment519332_263078">these</a> <a href="https://codereview.stackexchange.com/questions/263059/c-threadgroup-implementation/263087?noredirect=1#comment519369_263087">questi... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-16T15:15:31.067",
"Id": "519409",
"Score": "0",
"body": "I don't see why the `function` needs all those parameters. It should only take the thread ID, and anything else it needs would be lambda captures when making that specific funct... | [
{
"body": "<p><strong>Lambdas are not inefficient.</strong> You need to pack up those values <em>somehow</em>, and the way lambda captures work are just constructor arguments. That is, it copies the desired values into storage locations, which is exactly the work needed when passing a parameter (storing it in... | {
"AcceptedAnswerId": "263378",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-16T08:17:33.423",
"Id": "263098",
"Score": "1",
"Tags": [
"c++",
"multithreading"
],
"Title": "C++ Improved ThreadGroup Implementation"
} | 263098 |
<p>I have a macro written in word for transferring captions written in excel to a corresponding photograph in a word document. At the moment it runs however I am finding that it slows down over time the more captions it has to process. As such it is useful for up to approximately 200 photographs however I need it to pr... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-16T08:46:15.423",
"Id": "519380",
"Score": "0",
"body": "Please delete your current question and post it on StackOverflo website instead. The purpose of this website is to improve code which fully works."
},
{
"ContentLicense":... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-16T08:27:38.373",
"Id": "263099",
"Score": "1",
"Tags": [
"performance",
"excel",
"memory-management",
"ms-word"
],
"Title": "Inserting captions under photographs in word based o... | 263099 |
<p>I tried making a music player with tkinter in python but there's an error about module not callable but I'm not able to fix it. Can someone help?</p>
<pre><code>import tkinter as Tk
import pygame
import os
def __init__(self,root):
self.root = root
# title of the window
self.root.title("MusicPlaye... | [] | [
{
"body": "<blockquote>\n<p><code>imported tkinter as Tk</code></p>\n</blockquote>\n<blockquote>\n<p><code>root = Tk() # In order to create an empty window</code></p>\n</blockquote>\n<p>You imported tkinter under the name Tk, which coincidentally matches with the <code>Tk()</code> class of the tkinter module. B... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-16T10:41:00.843",
"Id": "263101",
"Score": "0",
"Tags": [
"python",
"tkinter"
],
"Title": "Tkinter music player"
} | 263101 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.