body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I have a web server that can send websites, images, mp3 and other things and I was wondering how I could improve the code and make the server more efficient.</p> <pre><code>//this is where you enter the default file directories char *defaultDir1 = &quot;/Users/rowan/Desktop/webServer(Mac)/website/displaySite/&quot;;...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-28T20:34:05.850", "Id": "534180", "Score": "1", "body": "[Related SO question](https://stackoverflow.com/q/70118629/1014587)." } ]
[ { "body": "<h1>Calling <code>strcat</code> in a loop is inefficient</h1>\n<p>The function <code>strcat</code> works the following way:</p>\n<p>It must first search the entire the destination string until it finds the terminating null character at the end. It then appends the source string.</p>\n<p>Therefore, ca...
{ "AcceptedAnswerId": "270469", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-28T02:39:26.540", "Id": "270459", "Score": "11", "Tags": [ "performance", "c", "multithreading", "http" ], "Title": "Multi-threaded web server serving HTML, images, etc" }
270459
<p>This query is a part of Conway’s game of life. Currently, this program takes about 70 lines of code in Python to return the functionality of the game, which can be simplified to fewer lines of code and it ends when a keyboard interrupt occurs. I eventually want to eliminate the keyboard interrupt and improve this co...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-28T15:39:55.953", "Id": "534146", "Score": "1", "body": "'Eliminate the keyboard interrupt' and replace it with what?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-28T16:38:50.050", "Id": "534154", ...
[ { "body": "<p><strong>Indentation</strong></p>\n<p>Please fix your code indentation, as it is now it's painful to figure out what's supposed to be happening. The comments provide the corect suggestions to make it easy for you as well.</p>\n<hr />\n<p><strong>CONSTANTS</strong></p>\n<p>The characters for living ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-28T03:59:06.753", "Id": "270461", "Score": "2", "Tags": [ "python", "functional-programming", "game-of-life" ], "Title": "Improving the Conway's Game of Life Code With Functions in P...
270461
<p>I am very much new to AWS Services and NodeJS. I would like to query a DynamoDB with username and if it exists return a boolean (true/false). I do not want to hard code the username anywhere in my Lambda code. Below is my code which currently returns all the contents of DDB:</p> <pre><code>var AWS = require('aws-sdk...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-28T10:35:13.960", "Id": "534136", "Score": "0", "body": "Does the current code produce the required output?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-28T16:37:03.893", "Id": "534151", "Score":...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-28T09:56:19.933", "Id": "270464", "Score": "0", "Tags": [ "node.js", "lambda" ], "Title": "Query DynamoDB and get a response" }
270464
<p>I was writing a social media sample application for Android in Kotlin. One of the requirements in the project is a screen which show the profile of his friend to a user. This profile screen should also update itself dynamically if that friend updates his profile when the user is viewing his profile. I can achieve th...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-28T18:40:29.930", "Id": "270470", "Score": "0", "Tags": [ "android", "kotlin", "firebase" ], "Title": "Implementing a persistent Firestore event listener with Kotlin flows" }
270470
<p>The program is designed to take data from a MySQL database, using mysql-connector-python, and print it as a table in Python using the texttable module. The program also plots charts based on the data from MySQL database using the matplotlib library.</p> <p>For those who don’t have any data in MySQL, the program will...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-28T19:34:10.947", "Id": "534176", "Score": "0", "body": "Why not use object-relational mapping (ORM) ?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T14:34:38.807", "Id": "534216", "Score": "1",...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-28T19:10:11.517", "Id": "270471", "Score": "2", "Tags": [ "python", "python-3.x", "sql", "mysql", "matplotlib" ], "Title": "Student report card management Python program" }
270471
<p>So I built a method containing three for loops which essentially tried to match items in list a) with items in list b). It worked fine, but to try and improve it for reasons which are not (I think) germane here, I tried to incorporate an array list () into the comparison so as to remove the entries on the b) list th...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-28T23:50:28.860", "Id": "534194", "Score": "1", "body": "Code Review is applicable only to working as intended code. Thus the question is off-topic here. Try asking on StackOverflow instead." }, { "ContentLicense": "CC BY-SA 4....
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-28T20:43:31.863", "Id": "270472", "Score": "-2", "Tags": [ "c#" ], "Title": "Mysterious ArgumentOutOfRangeException between array and List implementation" }
270472
<p>I am having trouble with applying to 3 steps needed to proof correctness, most likely because I did not formally study CS or Mathematics and am still learning about loop and class invariants. The three steps:</p> <ol> <li>Initialization</li> <li>Maintenance</li> <li>Termination</li> </ol> <p>My understanding of the ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-28T20:46:41.080", "Id": "270473", "Score": "0", "Tags": [ "java", "beginner", "sorting", "quick-sort" ], "Title": "Quicksort Invariant and steps to determine correcteness" }
270473
<p>I have data in JSON format.</p> <pre><code>{&quot;ts&quot;:1393631983,&quot;visitor_uuid&quot;:&quot;ade7e1f63bc83c66&quot;,&quot;visitor_source&quot;:&quot;external&quot;,&quot;visitor_device&quot;:&quot;browser&quot;,&quot;visitor_useragent&quot;:&quot;Opera/9.80 (Windows NT 6.1) Presto/2.12.388 Version/12.16&quot...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-28T22:51:04.060", "Id": "534188", "Score": "0", "body": "Can you show us what you've tried? If you're not sure how to get started, check out the tag wiki for [tag:json] for some helpful links." }, { "ContentLicense": "CC BY-SA ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-28T21:11:51.050", "Id": "270474", "Score": "-3", "Tags": [ "python", "json" ], "Title": "Create a histogram using JSON data in Python" }
270474
<p>I have completed my project which simulates the path of a particle trapped in a device known as a <a href="https://en.wikipedia.org/wiki/Magnetic_mirror" rel="nofollow noreferrer">magnetic mirror.</a> I would like your thoughts and improvements on my implementation.</p> <p>Here is the code:</p> <pre><code>from numba...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-28T23:25:08.553", "Id": "534193", "Score": "0", "body": "Related: [Phase diagrams of particles in a mirror](https://codereview.stackexchange.com/questions/269666/phase-diagrams-of-particles-in-a-mirror/269706#269706)" } ]
[ { "body": "<ul>\n<li>Rather than <code>4.0 * pow(10, -7)</code>, prefer scientific notation literals, i.e. <code>4e-7</code></li>\n<li>In nearly all cases there's no need for a <code>.0</code> suffix. Float promotion will do the right thing with an integer value.</li>\n<li>Prefer using inner tuples rather than ...
{ "AcceptedAnswerId": "270479", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-28T22:44:21.470", "Id": "270477", "Score": "3", "Tags": [ "python", "numpy", "simulation", "matplotlib", "physics" ], "Title": "Path of a particle in a non-uniform B fiel...
270477
<p><strong>Rules:</strong> You should create a function that receives a string with brackets, parentheses, or curly brackets, an example:</p> <pre><code>test('{A}') </code></pre> <p>The function must check that the opening and closing of the brackets are correct. If they are correct it should return <code>true</code>, ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T16:00:08.220", "Id": "534223", "Score": "1", "body": "This is too simple to be an answer: you can replace `getReverseBracket` with a plain object that holds the opening bracket as the key, and the closing as the value, like this: `c...
[ { "body": "<h1>Correctness</h1>\n<p>Your code falsely identifies <code>(hi)there</code> as having unbalanced brackets.</p>\n<h1>Formatting</h1>\n<p>The <code>else return false</code> clauses can be replaced with a single <code>return false</code> at the end of the function. There is no need to treat the 0 as a ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T00:08:38.860", "Id": "270478", "Score": "8", "Tags": [ "javascript", "balanced-delimiters" ], "Title": "Check for balanced brackets in JavaScript" }
270478
<p>My implementation of the lowest common ancestor (<a href="https://en.wikipedia.org/wiki/Lowest_common_ancestor" rel="nofollow noreferrer">LCA</a>) algorithm for my tree data structure. I selected the non-preprocessed (naïve) implementation for this first implementation. Support for any number of input positions (1+)...
[]
[ { "body": "<h1>Answers to your questions</h1>\n<blockquote>\n<ul>\n<li>Is my understanding of the complexity <span class=\"math-container\">\\$O(Ih)\\$</span> correct? Where <span class=\"math-container\">\\$I\\$</span> is the number of input node and <span class=\"math-container\">\\$h\\$</span> the tree heigh...
{ "AcceptedAnswerId": "270489", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T03:55:13.937", "Id": "270482", "Score": "2", "Tags": [ "c++", "algorithm", "tree", "c++20" ], "Title": "A Lowest Common Ancestor (LCA) Tree Algorithm" }
270482
<h3>Predeclared class instance tracks the number of regular instances</h3> <p>In VBA, predeclared class instances can act as <a href="https://rubberduckvba.wordpress.com/2018/04/24/factories-parameterized-object-initialization/" rel="nofollow noreferrer">object factories</a>, and in general, it makes sense to keep this...
[]
[ { "body": "<p>I'm guessing this is a highly redacted version of the <code>DbManager</code> class as it seems to have no 'Db' behavior and no external dependencies. As a consequence, setting the PredeclaredId = True, on the surface, seems unnecessary as there are no parameters in the <code>Create</code> functio...
{ "AcceptedAnswerId": "270539", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T06:36:03.450", "Id": "270483", "Score": "1", "Tags": [ "object-oriented", "vba" ], "Title": "Predeclared class instance tracks the number of regular instances" }
270483
<p>When you run a jar file by double-clicking on it, you don't get console so all your input/output have to be on GUI. This program solves this problem and gives users/programmers a console which can be used for input/output as done on console by command line programs. So, in effect this program gives a console for JAR...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T22:52:26.507", "Id": "534354", "Score": "0", "body": "Are your sure it compiles? In method `keyPressed(KeyEvent ke)` you have some illegal syntax `Id_keyPressed = Thread.currentThread().getId();`. Please read [ask]." }, { "C...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T08:49:23.027", "Id": "270487", "Score": "-1", "Tags": [ "java", "swing", "gui" ], "Title": "Console for Java JAR programs" }
270487
<p>The code below will generate an HTML select tag and options using a text file having list of countries. If the file doesn't exist or contains only empty / white space lines then generate an input box instead of select tag.</p> <hr /> <h2>generate_select_tag_and option_from_list_of_countries.php</h2> <pre><code>&lt;?...
[]
[ { "body": "<p>Consider using concatenation:</p>\n<ul>\n<li>rather than <code>$label_input_html = $label_input_html . ...</code></li>\n<li>use <code>$label_input_html .= ...</code></li>\n</ul>\n<p>You're outputting HTML, so end $label_input_html with <code>&lt;br&gt;</code>, not <code>\\n</code>.</p>\n<p>Also se...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T12:59:28.527", "Id": "270491", "Score": "3", "Tags": [ "php", "html", "io" ], "Title": "Generate HTML select tag and options using a text file having list of countries" }
270491
<p>I am working on a Python package for converting baking recipes. Ideally, the recipe is simply stored as a CSV file read in by the package. Given the recipe can be imperial or metric units of measurement, I am trying to internally convert any set of measurement units to metric for simplicity.</p> <p>The main question...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T14:49:05.613", "Id": "534217", "Score": "2", "body": "Welcome to Code Review. Please post the full code if possible to give more context to reviewers." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T1...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T13:57:53.877", "Id": "270493", "Score": "-1", "Tags": [ "python" ], "Title": "What would be a recommended data structure for a set of baking conversions?" }
270493
<p>Please, tell me, why this code doesn't work without &quot;-'0'&quot; in this string:&quot;result = 10* result + (str[i++] - '0');&quot;? Объясните, пожалуйста, люди добрые, почему код не работает без &quot;-'0'&quot; в этой строке кода: &quot;result = 10* result + (str[i++] - '0');&quot;?</p> <pre><code> ``` ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T16:22:34.740", "Id": "534225", "Score": "1", "body": "You may want to post this question on [so] or [ru.so]. It is off-topic on Code Review. If you decide to post it on Stack Overflow, then \"doesn't work\" is not a sufficient probl...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T14:22:13.383", "Id": "270494", "Score": "-2", "Tags": [ "c", "helper" ], "Title": "C, atoi. Своя функция atoi на C" }
270494
<p>This program takes x numbers and displays the mean, median and mode.</p> <p>My goal here was to use classes and class properties the best i could to make the code shorter (honestly i may have just made it longer), so i would like to get some feedback on that.</p> <pre><code>import tkinter as tk from typing import Ca...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T16:17:18.913", "Id": "270497", "Score": "1", "Tags": [ "python", "calculator", "statistics", "tkinter" ], "Title": "Mean, median and mode GUI" }
270497
<p><em>Terminology usage</em>: I will use chunk, page, partition, or subrange interchangeably.</p> <p>I frequently use and promote using the <code>System.Collections.Concurrent.Partitioner</code> class (<a href="https://docs.microsoft.com/en-us/dotnet/api/system.collections.concurrent.partitioner.create?view=net-6.0#Sy...
[]
[ { "body": "<p>I think your approach is simple and straight forward. The overall naming convention is good. Many parts of the class have descriptive naming, and that makes things much easier to understand the class.</p>\n<p>The validations methods such as <code>CheckCannotBeNegative</code>, <code>CheckMustBePosi...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T18:04:29.190", "Id": "270502", "Score": "2", "Tags": [ "c#" ], "Title": "A Custom Range Partitioner" }
270502
<p>I've built this complex form or at least what I would consider a complex form and it feels really dirty. It felt dirty while I was programming it but I wanted to get it working and then go back and refactor it. The form consists of the days of the week and for each day there are three options (breakfast, lunch, dinn...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T18:44:35.887", "Id": "270503", "Score": "0", "Tags": [ "php", "laravel" ], "Title": "Choose meals for a week" }
270503
<p>The method is given NxN matrix always powers of 2 and a number,it will return true if the num is found example for 4x4 size: <a href="https://i.stack.imgur.com/HBw2L.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HBw2L.png" alt="example" /></a></p> <pre><code> public class Search{ public static ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T08:09:05.247", "Id": "534267", "Score": "0", "body": "This looks unfinished. Have you actually tested it?" } ]
[ { "body": "<p>No, the code doesn't do what it should.</p>\n<ul>\n<li>The method should be recursive (calling itself) or looping, currently it only executes once.</li>\n<li>The complexity is constant O(1) because you dont use recursion or loops.</li>\n</ul>\n<p>Binary-Search Implementation in O(2n):</p>\n<pre><c...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T18:54:48.433", "Id": "270505", "Score": "-1", "Tags": [ "java", "performance" ], "Title": "Search in circular sorted martix" }
270505
<p>I'm currently learning python with an udemy course. I wrote this code, which is meant to be a higher lower game, where the second answer always stays. As far as i tested it my code is working fine, but i feel like many solutions are bad. Its just felt weird coding some of the solutions, but i cant come up with bette...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T20:43:14.657", "Id": "534237", "Score": "1", "body": "Welcome to Code Review! Could you tell us about the imports, or better yet, show us that code too?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29...
[ { "body": "<p>I'm not going to go too heavily into refactoring the whole thing.</p>\n<p>Some basic readability things:</p>\n<pre><code>return_values = compare(options[0], options[1], score)\nscore = return_values[1]\nlost = return_values[0]\n</code></pre>\n<p>It would be much clearer if you did:</p>\n<pre><code...
{ "AcceptedAnswerId": "270549", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T20:35:38.467", "Id": "270508", "Score": "4", "Tags": [ "python", "beginner", "number-guessing-game" ], "Title": "Higher lower game" }
270508
<p>I want to use shell scripts to consume kafka messages and return to status. I found that my script wasn't efficient enough.</p> <p>Can I write this script better?</p> <p>I want to output kafka-console-consumer.sh execution time, how do I write it?</p> <p>The input result can be kafka_Check|consumer:0|consumer_time:0...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T08:18:44.047", "Id": "534269", "Score": "2", "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>I'm not good enough with shell programming to really dig into your code, but I have some suggestions nonetheless!</p>\n<ul>\n<li>Make sure you know <em>where</em> the inefficiency is.<br />\nThere's no bennefit from optimizing stuff that isn't the bottleneck. For example, if most of the time that ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T22:10:12.483", "Id": "270513", "Score": "0", "Tags": [ "bash", "shell" ], "Title": "Bash script to process Kafka messages" }
270513
<p>I have the following piece of code.</p> <pre><code>someFunction = async () =&gt; { let boolean = await this.someFetchFunction(); if (!boolean) boolean = this.someOtherFunction(); return boolean; } </code></pre> <p>I was wondering what would be a cleaner/better solution to this code. Was thinking in a more ES...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T22:31:57.347", "Id": "534246", "Score": "1", "body": "You could do this: `return await this.someFetchFunction() || await this.someOtherFunction();`." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T22:...
[]
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T22:26:59.567", "Id": "270514", "Score": "1", "Tags": [ "javascript", "ecmascript-6" ], "Title": "avoid reassigning variables in javascript" }
270514
<pre><code>public class Diff { public static int findMinDiff1 (int[] a, int x, int y) { // runtime efficenecy: linear o(n),depends on a.length // memory efficenecy: 1+1+1.. n int temp_x = -1; int temp_y = -1; int min = Integer.MAX_VALUE; for(int i = 0 ; i &lt; a.length ; i++) { ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T03:13:38.270", "Id": "534261", "Score": "0", "body": "What tests have you run?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T03:19:14.303", "Id": "534262", "Score": "0", "body": "I just ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T00:01:25.347", "Id": "270517", "Score": "0", "Tags": [ "java", "performance", "array" ], "Title": "Given Array and 2 ints return the smallest distance between based on index" }
270517
<p>I'm trying to take a raw byte array of audio and trim it.</p> <p>The user selects a start and end value using a range slider.</p> <pre><code>// args are doubles from 0.0 - 1.0 // audio is uncompressed, 16-bit, 44,100hz, MONO public static byte[] trimBytes(byte[] fullLength, double from, double to) { int startin...
[]
[ { "body": "<blockquote>\n<p>0.0 - 1.0, Is this going to crash for any reason?</p>\n</blockquote>\n<p>As you don't check, there's an <code>ArrayIndexOutOfBoundsException</code> that could be turned into an <code>IllegalArgumentException</code>.</p>\n<blockquote>\n<p>is there a better way to do this?</p>\n</block...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T01:24:03.277", "Id": "270518", "Score": "0", "Tags": [ "java", "algorithm", "android", "audio", "byte" ], "Title": "Safely and Quickly Trim a Byte Array of Audio in Java" ...
270518
<p>I just had a realization about Mergesort possibly being unstable depending on how it is implemented while reading <a href="https://www.quora.com/Is-merge-sort-a-stable-sorting-algorithm" rel="nofollow noreferrer">this post</a>.</p> <p>Would the merge method below lead to an unstable algorithm?</p> <pre class="lang-j...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T04:50:49.133", "Id": "534264", "Score": "2", "body": "Depends on how `isLessThan` is implemented. If it returns `false` on equal elements, then yes, it is unstable. That said, there is not enough to review, VTC." }, { "Conte...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T03:59:20.507", "Id": "270521", "Score": "-1", "Tags": [ "java", "mergesort" ], "Title": "Mergesort unstable as Implemented?" }
270521
<p>I'm trying to write a Java function that will take a byte array (of PCM audio recorded on Android) and return an array of data of floats that is intended to be used to create a visual representation of the audio wave -- a standard (quick and dirty) volume over time wave similar to the appearance of what Soundcloud u...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T05:44:54.183", "Id": "534266", "Score": "2", "body": "`array of [values] intended to be used to create a visual representation` of what? Volume over time? Over frequency? Note that several hundred samples of *samples* will most like...
[]
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T05:18:15.577", "Id": "270522", "Score": "0", "Tags": [ "java", "algorithm", "android", "audio", "byte" ], "Title": "Converting Audio Bytes to Array of Floats for Visual Re...
270522
<p><code>strcat_new()</code> function, not present in standard C library.</p> <p>Syntax: <code>char *strcat_new(char *delim, long num_args, ...);</code></p> <p>The code is below. Can someone please do the code review?</p> <hr /> <h2>strcat_new.c</h2> <pre><code> #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #inclu...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T13:26:31.797", "Id": "534305", "Score": "0", "body": "Please do not edit the question, especially the code, after an answer has been posted. Changing the question may cause answer invalidation. Everyone needs to be able to see what ...
[ { "body": "<p><strong>Neat and well formatted</strong></p>\n<p><strong>Design</strong></p>\n<p>Rather than &quot;then after every string, the 'delim' string is concatenated.&quot; (that sounds like <code>n</code> delimiters), I would expect <em>between</em> every string. <em>between</em>, or the like, matches c...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T07:03:13.710", "Id": "270524", "Score": "9", "Tags": [ "c", "library" ], "Title": "strcat_new() function, not present in standard C library" }
270524
<p>I know this question could be the new variant of other 1million questions but before you say that, let me explain what I'm trying to achieve.</p> <p>I have a lot of APIs and want to create an SDK. There is an API for each function (Statistics, ApplicationLogs, Transactions and so on). To use those services, the API ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T09:29:45.713", "Id": "534288", "Score": "0", "body": "`Gets` isn't a good name. Should be GetList or GetAll or something like that. And `public string _baseUrl = \"\";` is really bad: it's `public` yet it has the naming of a `privat...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T08:32:06.780", "Id": "270525", "Score": "0", "Tags": [ "c#", "dependency-injection" ], "Title": "ASP.NET Core dependency injection in class library with params" }
270525
<p>Write a function: <strong>class Solution { public int solution(int N); }</strong> that, given an integer N, returns the smallest integer greater than N, the sum of whose digits is twice as big as the sum of digits of N. Examples: 1. Given N = 14, the function should return 19. The sum of digits of 19 (1 +9 = 10) is ...
[]
[ { "body": "<p>Here is what i can recommend on what you've written:</p>\n<ul>\n<li>You should name your variables properly: names such as <code>i</code> should be only used as indexes.</li>\n<li>Why do you stop at <code>k</code> = 100000? Why not go further? What if <code>N</code> is bigger than that?</li>\n<li...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T09:16:22.527", "Id": "270527", "Score": "1", "Tags": [ "java", "algorithm" ], "Title": "Given an integer N, returns the smallest integer greater than N, the sum of whose digits is twi...
270527
<p>I have written a Python3 program that looks for matching strings and removes them from files.</p> <pre><code>import os path = os.getcwd() ignore_files = [&quot;remove-lines.py&quot;, &quot;to-remove&quot;] with open(&quot;to-remove&quot;, &quot;r&quot;, newline=&quot;&quot;) as pattern_file: remove_patterns ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T16:03:39.843", "Id": "534319", "Score": "0", "body": "Is there any reason why you opted not to go for a regex based solution? Can you give some example files?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021...
[ { "body": "<h2>Picking the right tools</h2>\n<p>Your entire script can be written as the following one-liner</p>\n<pre><code>grep -RiIl 'search' | xargs sed -i's/.*\\(here\\|there\\|why\\).*//g'\n</code></pre>\n<p>Whenever your entire script can be expressed as a oneliner, it is a good indication that something...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T09:54:06.610", "Id": "270530", "Score": "4", "Tags": [ "python", "performance", "python-3.x" ], "Title": "Remove matching lines from all files" }
270530
<p><a href="https://i.stack.imgur.com/n2SGk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n2SGk.png" alt="enter image description here" /></a></p> <p>I have 2 datafarme And need result, date of datefarme 2 between date of dataframe 1 result = A of datefarme 2 add in datafarme 1</p> <pre><code>impo...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T13:02:25.827", "Id": "534302", "Score": "1", "body": "Please include **your** code to achieve the result needed in the question: See [How do I ask a Good Question?](https://codereview.stackexchange.com/help/how-to-ask)" }, { ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T10:00:59.297", "Id": "270532", "Score": "-1", "Tags": [ "python", "pandas" ], "Title": "Merge two Dataframe with condition" }
270532
<h3>Resolving circular references in VBA via ObjectStore class and CleanUp cascade</h3> <p>I have been working on a VBA database library and realized I had a few circular reference loops in my class hierarchy, as illustrated in the figure (left panel). I recalled reading an RDVBA blog <a href="https://rubberduckvba.wor...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T10:47:01.063", "Id": "270533", "Score": "1", "Tags": [ "object-oriented", "vba" ], "Title": "Resolving circular references in VBA via ObjectStore class and CleanUp cascade" }
270533
<p>Checking return flags is generally very important. But, when you don't need to based on meeting pre-conditions, the syntax gets unnecessarily ugly.</p> <p>This class allows returning a value with flags that the caller can ignore.</p> <pre class="lang-cpp prettyprint-override"><code>#include &lt;tuple&gt; template &...
[]
[ { "body": "<h2>Naming:</h2>\n<p><code>retval</code> would be better named something like <code>[specific_function]_result</code> where the <code>[specific_function]</code> is the name of the function whose return value it is (e.g. <code>std::from_chars</code> and <code>std::from_chars_result</code>).</p>\n<hr /...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T17:07:08.020", "Id": "270543", "Score": "0", "Tags": [ "c++", "c++20" ], "Title": "Allow caller optional flags for returns" }
270543
<p>I have a vector of values <code>vals</code>, a same-dimension vector of frequencies <code>freqs</code>, and a set of frequency values <code>pins</code>.</p> <p>I need to find the max values of <code>vals</code> within the corresponding interval around each pin (from pin-1 to pin+1). However, the intervals merge if t...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T19:20:05.873", "Id": "270546", "Score": "1", "Tags": [ "python", "numpy" ], "Title": "find max value in islands defined by other vector" }
270546
<p>I'm interested in how I can improve my HTML and CSS? I didn't yet learn JS, even though I used it for onclick function, so I'm not currently interested in how to improve the JS in this code. I was wondering:</p> <p>Is it alright to use spans inside button for accessibility? First I had all divs, than made the parent...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T07:23:18.660", "Id": "534375", "Score": "0", "body": "We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review. Please [**follow the tour**](https://CodeReview.StackExchan...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T19:44:04.730", "Id": "270548", "Score": "0", "Tags": [ "javascript", "html", "css", "html5" ], "Title": "Suggestions on how to upgrade HTML and CSS making a hamburger icon tha...
270548
<p>I am using a <code>KeyNotFoundException</code> to check if an item exists in a <code>Dictionary</code>, creating it when the exception is thrown:</p> <pre><code>public Section GetSection(int plankNo, int sectionNo) { if (plankNo &lt; 1 || plankNo &gt; NumberOfPlanks || sectionNo &lt; 1 || sectionNo &gt; Sections...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T20:43:05.657", "Id": "534348", "Score": "3", "body": "Using an exception will cause the stack to unwind every time you find a missing key, which will be very expensive. Just use the `ContainsKey` method on Dictionary, or `TryGetValu...
[ { "body": "\n<p><a href=\"https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.trygetvalue?view=net-6.0\" rel=\"nofollow noreferrer\"><code>TryGetValue</code></a> would be the way to go without using <code>KeyNotFoundException</code>.<br />\nIt would look like the below:</p>\n<pre...
{ "AcceptedAnswerId": "270564", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T19:55:01.370", "Id": "270550", "Score": "0", "Tags": [ "c#", "hash-map", "error-handling" ], "Title": "Use an exception to check if item in dictionary" }
270550
<p>Given the current table:</p> <pre><code>+------------+-------+ | date | value | +------------+-------+ | 01/01/2000 | 1 | | 03/04/2000 | 3 | | 05/08/2000 | 4 | | 07/11/2000 | 2 | +------------+-------+ </code></pre> <p>For each <code>date</code> I'm looking to get an average of the values for t...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T20:18:55.463", "Id": "270551", "Score": "0", "Tags": [ "python", "mysql", "numpy" ], "Title": "Calculate of the average of time discounted values" }
270551
<p>I was looking for C++ versions of the machine learning metrics implemented in Python's sklearn, but they were surprisingly hard to find. I came across <a href="https://cppsecrets.com/user/index.php?id=articles&amp;uid=5758" rel="nofollow noreferrer">a website that had most of the loss functions implemented in Python...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T22:25:02.787", "Id": "534353", "Score": "0", "body": "The biggest reason why you don't get good speed is because you're not exactly using the right tools. You should look into CUDA programming or at least use a library like Eigen to...
[ { "body": "<h1>Design review</h1>\n<p>There are two very common mistakes people make when trying to translate code from other languages to C++ looking for a performance boost.</p>\n<p>The first is trying a direct translation: that is, literally rewriting the exact same code logic from the other language to C++....
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T21:19:05.770", "Id": "270553", "Score": "3", "Tags": [ "c++", "performance", "machine-learning" ], "Title": "Machine Learning Loss Functions In C++" }
270553
<p>I have a function <code>general_statistics</code> that takes a dict as input and get the wanted information. the function is working without any problem, but I want to know if I can do it with a pythonic way because I'm trying to improve my skills.</p> <pre><code>def general_statistics(input_data: dict): res...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T07:23:47.240", "Id": "534376", "Score": "1", "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>Your</p>\n<pre><code>if 'general' in input_data.keys():\n if bool(input_data['general']):\n</code></pre>\n<p>could be</p>\n<pre><code>if 'general' in input_data:\n if input_data['general']:\n</code></pre>\n<p>or even</p>\n<pre><code>if general := input_data.get('general'):\n</code></pre>\n<p...
{ "AcceptedAnswerId": "270559", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T00:24:40.727", "Id": "270556", "Score": "1", "Tags": [ "python" ], "Title": "best way to get data from dict" }
270556
<p>I have two large arrays of objects, which look something like:</p> <pre class="lang-js prettyprint-override"><code>[ { key: &quot;prop&quot;, Email: &quot;someEmail@email.com&quot; }, //... ] </code></pre> <p>and</p> <pre class="lang-js prettyprint-override"><code>[ { key: &quot;prop&quot;, &quot;AN EMAIL&quot...
[]
[ { "body": "<p>I also prefer the second example, due to the functional programming style. I believe it's easier to read because you've decoupled the getter from the transformation.</p>\n<p>The only change I'm tempted with is to pull out and share the getter logic with some currying. Something like this:</p>\n<pr...
{ "AcceptedAnswerId": "270579", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T00:27:36.643", "Id": "270557", "Score": "0", "Tags": [ "javascript", "array" ], "Title": "Map chaining vs execute on first map" }
270557
<p>I have some code that needs to return a <code>datetime</code> of the next 9am or 9pm, UTC. I've figured out some code to do this, but it feels unnecessarily complex to me. Is there a way to simplify this?</p> <pre class="lang-py prettyprint-override"><code>from datetime import datetime, timezone, timedelta class Ni...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T05:27:41.037", "Id": "534370", "Score": "0", "body": "what if the given `current_time` was 9:49 AM in UTC+1 timezone? (8:49 AM UTC)" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T07:54:12.150", "...
[ { "body": "<p>There is a much simpler approach using <code>timedelta</code> to do this.</p>\n<p>You start by getting the current hour from <code>now</code> (<code>now.hour</code>). If you subtract this from <code>now</code> it will take you to midnight. Then we add/remove an appropriate number of extra hours to...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T00:40:14.073", "Id": "270558", "Score": "3", "Tags": [ "python", "python-3.x", "datetime" ], "Title": "Finding the next 9am/pm from now" }
270558
<p><a href="https://www.hackerrank.com/challenges/absolute-permutation/problem" rel="nofollow noreferrer">https://www.hackerrank.com/challenges/absolute-permutation/problem</a></p> <p>I know that if you work out the math and logic first, the algorithm can be simplified greatly (shifting indices), but is that the only w...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T05:11:46.277", "Id": "534369", "Score": "0", "body": "_Does_ it pass all the test cases?" } ]
[ { "body": "<p>Yeah, you are recreating <code>tmp</code> every iteration of your loop. This makes your solution O(n^2). You could easily make your solution O(n) by setting <code>tmp</code> before your loop and then updating it along with <code>newlist</code>. The reason your current solution is O(n^2) is that bu...
{ "AcceptedAnswerId": "270562", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T01:44:59.950", "Id": "270560", "Score": "0", "Tags": [ "python", "performance", "combinatorics" ], "Title": "Absolute Permutation | Hacker Rank: Any way to make this python co...
270560
<p>Consider the following two classes:</p> <pre><code>public class Person&lt;P extends Comparable&lt;P&gt;&gt; { private List&lt;Person&lt;P&gt;&gt; following = new ArrayList&lt;Person&lt;P&gt;&gt;(); private List&lt;Person&lt;P&gt;&gt; friends = new ArrayList&lt;Person&lt;P&gt;&gt;(); private P id; ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T05:43:32.490", "Id": "534371", "Score": "0", "body": "Welcome to Code Review. Did you test any of this? It seems like a couple of library functions without implementation." }, { "ContentLicense": "CC BY-SA 4.0", "Creatio...
[ { "body": "<p>Surely, as you are aware of the term <em>code smell</em>, you have reads this? <a href=\"https://blog.codinghorror.com/code-smells/\" rel=\"nofollow noreferrer\">https://blog.codinghorror.com/code-smells/</a></p>\n<p>The first stench I sense is that you <em>indecently expose</em> the internal data...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T05:17:59.113", "Id": "270561", "Score": "0", "Tags": [ "java" ], "Title": "Objects for a face book" }
270561
<p>I have invented the fastest string search algorithm. It is called &quot;&quot;Choudhary String Search Algorithm (choudharyStringSearchAlgorithm)&quot;&quot;. I have compared my algorithm with Brute Force Algorithm, Boyer Moore Algorithm, Rabin Karp Algorithm, and Knuth Morris Pratt Algorithm and my algorithm is the ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T11:41:43.787", "Id": "534393", "Score": "5", "body": "*\"I have invented the fastest string search algorithm\"* - My gut feeling: If that were true, I wouldn't hear about it on codereview :-P. Some explanation in addition to the cod...
[ { "body": "<p>Maybe your algorithm is really fast, but this site isn't about algorithm review, it's about code review.</p>\n<p>And a &quot;fastest string search algorithm&quot; should come in a software package of an equally high quality, which it doesn't. The current code quality is far below acceptability for...
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T07:32:13.293", "Id": "270565", "Score": "-2", "Tags": [ "java", "strings", "search" ], "Title": "Fastest string search algorithm invented by me. It is called \"\"Choudhary String ...
270565
<p>I was doing the Magic Ball 8 project (its task is to read a user's question and output a prediction) on Python and wrote the following code:</p> <pre><code>from random import choice from time import sleep list_of_predictions = [ &quot;Undoubtedly&quot;, &quot;It seems to me - yes&quot;, &quot;It is not cle...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T07:57:38.307", "Id": "534378", "Score": "0", "body": "You probably want to reject \"Why?\" and \"Who?\" questions as well..." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T07:58:55.127", "Id": "5...
[ { "body": "<p>What I see bad in your code is <strong>readability</strong>. It is good if you keep the proper spacing between each component.</p>\n<p>If you have a long list, dict or tuple break it into lines.</p>\n<pre><code>list_of_predictions = [\n &quot;Undoubtedly&quot;,\n &quot;It seems to me - yes&q...
{ "AcceptedAnswerId": "270573", "CommentCount": "8", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T07:40:35.363", "Id": "270566", "Score": "3", "Tags": [ "python", "python-3.x" ], "Title": "Magic ball 8 program" }
270566
<p>I am learning Python and for practice I have written this function which sorts a list.</p> <p>Can you please provide feedback on how I have structured it and what better ways could be there to write it for optimization/structuring?</p> <pre><code>originallist=[5, 4, 0, 3, 2,1] lowervalue=int() duplicatelist=origina...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T19:22:15.813", "Id": "534443", "Score": "0", "body": "You've implemented an insertion sort (I think), which is inherently not really an optimal way to sort things. Do you want answers within the context of implementing insertion so...
[ { "body": "<p>There's some odd features to this code, even for a coding practice exercise. Python of course has <a href=\"https://docs.python.org/3.7/library/functions.html#sorted\" rel=\"nofollow noreferrer\">a couple</a> of <a href=\"https://docs.python.org/3.7/library/stdtypes.html#list.sort\" rel=\"nofollow...
{ "AcceptedAnswerId": "270602", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T07:47:50.107", "Id": "270567", "Score": "0", "Tags": [ "python", "beginner", "python-3.x", "sorting", "reinventing-the-wheel" ], "Title": "Simple sort function" }
270567
<p>I have a methods like.</p> <pre><code> public function getReceiptGames(Request $request):JsonResponse{ $result = []; $page = $request-&gt;get('page') ? (int)$request-&gt;get('page') : null; if ($page) { $pagination = $this-&gt;receiptGameRepository-&gt;paginateAll($page); $games = $pagination-&gt;items(); ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T13:05:30.490", "Id": "534398", "Score": "2", "body": "Sorry, but with only one method, we can't help you. If all the methods are just like this, letter by letter, you can remove all the methods and keep this one; but probably they h...
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T08:12:13.987", "Id": "270568", "Score": "-2", "Tags": [ "repository", "pagination", "doctrine" ], "Title": "How to remove boilderplate code from the methods" }
270568
<p>I believe that using <code>TryParse</code> is not a great idea here. How to improve this part?</p> <pre><code>using (CustomerDataReader reader = customCommand.ExecuteReader()) { while (reader.Read()) { var person = new Organization { Name = re...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T11:24:52.860", "Id": "534390", "Score": "1", "body": "`So I believe that using TryParse is not a great idea here` believing and reasoning are two different things. Tell us why you don't need the `TryParse` ?" }, { "ContentLi...
[]
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T08:41:24.953", "Id": "270570", "Score": "-2", "Tags": [ "c#" ], "Title": "How to get rid of TryParse in this code?" }
270570
<p>Contextually, I'm evaluating if a member exists with the supplied information. This, ostensibly, is intended to prevent the addition of new members with the same details.</p> <p>The user will be provided with a list of members having the same details as the new member they're trying to add.</p> <p>I set this up so t...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T13:17:04.927", "Id": "534401", "Score": "2", "body": "Generic best practices are outside the scope of this site. Please [**follow the tour**](https://CodeReview.StackExchange.com/tour), and read [**\"What topics can I ask about here...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T09:24:11.820", "Id": "270571", "Score": "-2", "Tags": [ "c#", "error-handling", "asp.net-core" ], "Title": "Is relying on exception handling a good way to ensure that the app's wo...
270571
<p>I have the following vue component which all works fine</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;template&gt; &lt;div class="sales-agreements"&gt; &lt...
[]
[ { "body": "<p>Computed properties can return objects, which seems useful for you.</p>\n<pre><code>computed: {\n filteredItems() {\n switch (this.$route.query.salesType) {\n case 'bricks':\n return {\n filteredSalesAgreementItems: this.salesAgreementItems.filter(obj =&gt; obj.departmen...
{ "AcceptedAnswerId": "270582", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T11:46:03.007", "Id": "270575", "Score": "2", "Tags": [ "javascript", "ecmascript-6", "vue.js" ], "Title": "group computed properties in vue component" }
270575
<p>I have a long switch statement and it would be great if someone know how to make it cleaner.</p> <p>Code is available on Github: <a href="https://github.com/Rabbit-Company/Passky-Server/blob/main/php/index.php" rel="nofollow noreferrer">https://github.com/Rabbit-Company/Passky-Server/blob/main/php/index.php</a></p> ...
[]
[ { "body": "<p>I'm quite surprised that you placed the <code>userSentToManyRequests()</code> function in every case. If you do that then you can just start with it before the <code>switch ()</code>.</p>\n<p>To get rid of the <code>switch</code> you can use an array containing the names of the arguments for each ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T12:47:52.687", "Id": "270578", "Score": "4", "Tags": [ "php" ], "Title": "Passky Password Manager router with authentication and validation guards" }
270578
<p>This is a command line application which displays the text of an EPUB one sentence at a time.</p> <p>I am going to make it more robust, including:</p> <ul> <li>make the segmentation more accurate, because it currently groups together unrelated text sometimes</li> <li>make it faster, so that the segmentation occurs a...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T14:52:40.337", "Id": "270580", "Score": "0", "Tags": [ "python", "curses" ], "Title": "Command-line sentence-by-sentence EPUB reader in Python" }
270580
<p>I'm learning Java in a MOOC right now and this is my solution for exercise grade statistics.</p> <p>This is the exercise:</p> <blockquote> <p>In this exercise we create a program for printing statistics for points in course. The program receives points (integers from zero to one hundred) as input, based on which it ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T17:15:45.977", "Id": "534432", "Score": "2", "body": "I've edited the title of your post. The *Code Review* site requires the title of the post describe _what the code does_. Titles reading like \"What do you think about ...\" or ...
[ { "body": "<h2>Package Name</h2>\n<p>Java code should be placed into a package with a name that avoids collisions with other developers. The best practice is to use the reverse-reading of some domain/account/email that you own, e.g.</p>\n<pre><code>package com.stackexchange.codereview.srxxx.grading;\n</code></p...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T16:52:14.407", "Id": "270585", "Score": "1", "Tags": [ "java" ], "Title": "Grade Statistics" }
270585
<p>I want to find if all of a list of substrings exist in a string, in the correct order (with or without spaces between them), it seems to be a good use for regex.</p> <p>I think I need to build a regex filter of <code>&quot;a.*b.*c&quot;</code> and use search to find that anywhere in my string.</p> <p>Are there any ...
[]
[ { "body": "<p>The problem with your current approach is that it can give incorrect results\nor raise an exception if any of the substrings contain characters that\nhave special meaning in Python regular expressions.</p>\n<pre><code>are_substrings_in_text(['a', '.', 's'], 'abacus')) # Returns True\nare_substri...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T18:51:19.507", "Id": "270589", "Score": "0", "Tags": [ "python", "regex" ], "Title": "Python function for finding if all substrings exist in a string in sequence" }
270589
<p>This is the code I came up with for the Rust pig latin exercise.</p> <p>I am looking for suggestions on how to make it more idiomatic.</p> <p>I think working with iterators instead of chars and Strings would be a step in the right direction?</p> <p>I was unable to figure out how to use <code>.map</code> to reach the...
[]
[ { "body": "<p>I can't see how you got stuck. You just do like you said: use <code>map</code> instead of Strings, then collect into a Vec, and finally join into one String.</p>\n<p>Here is the code.</p>\n<pre class=\"lang-rust prettyprint-override\"><code>fn main() {\n let phrase = &quot;Test sentence for pig...
{ "AcceptedAnswerId": "270606", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T18:53:51.200", "Id": "270590", "Score": "1", "Tags": [ "beginner", "rust", "pig-latin" ], "Title": "Rust Pig Latin Translator - Idiomatic suggestions" }
270590
<p>I recently faced this following question in a Java coding round, needless to say I did not get a callback. So I want to know where I am going wrong in my solution and also what can be done to improve it.</p> <p><strong>The Problem statement was as follows:</strong></p> <blockquote> <p>Create a java program, with two...
[]
[ { "body": "<p>As you requested I am going to ignore B-Tree and display stuff.</p>\n<p>First off after reading problem description it is not obvious for me how exactly should the solution look like:</p>\n<ul>\n<li><code>random integer values</code> - does plural form of <code>values</code> suggests that producer...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T19:47:38.097", "Id": "270595", "Score": "1", "Tags": [ "java", "multithreading", "producer-consumer" ], "Title": "Producer/Consumer Multi-Thread implementation - Is the solution c...
270595
<p>I know this is probably more complicated than it needs to be, however, I would really appreciate some help. I'm trying to create a trigger in MySQL that will update the value in the Costs table when a value is inserted into the Assignments table. HOWEVER, it can't just be that value, it has to be the product of the ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T20:18:16.037", "Id": "270597", "Score": "0", "Tags": [ "sql", "mysql", "error-handling", "database" ], "Title": "Create trigger that updates Table3 from an insert into Table1 ...
270597
<p>Just solved <a href="https://projecteuler.net/problem=2" rel="nofollow noreferrer">Euler Project Problem 2</a> using JavaScript and I would like to know how I could improve my code. I do think it looks good, but you never know.</p> <h3>Problem Statement</h3> <blockquote> <p>Each new term in the Fibonacci sequence is...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T23:03:30.930", "Id": "534473", "Score": "0", "body": "Are you sure you're getting the correct result? You start with different numbers and your ending isn't spot on, although the latter doesn't seem to influence the outcome." } ]
[ { "body": "<p>With a bit of fiddling I come to this code:</p>\n<pre><code>function fibonacci() {\n let s = t = 0, a = 1, b = 2;\n do {\n s = a + b;\n a = b;\n b = s;\n t += s &amp; 1 ? 0 : s;\n } while (s &lt;= 4000000);\n return t;\n}\n\nconsole.log(fibonacci());\n</code...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T22:04:09.940", "Id": "270598", "Score": "1", "Tags": [ "javascript", "programming-challenge" ], "Title": "Euler Project Problem 2 JavaScript" }
270598
<p>I'm trying to improve the following <a href="https://github.com/Marfusios/binance-client-websocket" rel="nofollow noreferrer">Binance Web Socket API wrapper</a>. I like it because it uses <code>System.Reactive</code> and it takes advantage of the <a href="https://github.com/binance/binance-spot-api-docs/blob/master/...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-01T22:29:44.533", "Id": "270599", "Score": "1", "Tags": [ "c#", "json", ".net-core" ], "Title": "Achieving same abstraction by replacing JObject's implementation with System.Text.Jso...
270599
<p>I am trying to solve a <a href="https://leetcode.com/problems/implement-strstr/" rel="nofollow noreferrer">needle in haystack</a> using <a href="https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm" rel="nofollow noreferrer">Rabin-Karp algorithm</a>, but for large inputs my code takes way too long time. Here i...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T03:16:29.337", "Id": "534488", "Score": "2", "body": "How large does `n` get? Thinking about the implications of this: `10**(n-i-1)`." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T03:17:26.433", ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T02:47:06.980", "Id": "270604", "Score": "0", "Tags": [ "python", "performance", "programming-challenge" ], "Title": "String search using Rabin-Karp algorithm" }
270604
<p>On web pages, obviously we cannot serve 4000x4000px photos and just let CSS do the resizing: it would be <strong>too slow for end users and too bandwidth-consuming for the server</strong>.</p> <p>So it's important to rescale photos to the desired size that will be <em>actually used</em> on the website. For this reas...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T19:25:27.513", "Id": "534591", "Score": "0", "body": "I added the `.htaccess` tag, because without understanding what that does you cannot understand the PHP code." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T09:58:11.343", "Id": "270607", "Score": "1", "Tags": [ "php", "image", ".htaccess" ], "Title": "Serve rescaled jpg images on demand with myphoto!500.jpg syntax (here 500px-width r...
270607
<p>I wrote a method that lets me retry RestSharp requests when a specific exception is thrown.<br /> Here's the code for that method:</p> <pre><code>private async Task&lt;T_Out&gt; RunRequestWithRetry&lt;T_In, T_Out&gt;(Func&lt;SignatureAccount, T_In, T_Out&gt; request, SignatureAccount signatureAccount, T_In requestBo...
[]
[ { "body": "<p>Here are few suggestions :</p>\n<p>First, make a loop</p>\n<ul>\n<li>the readability is improved as you will see only <code>request.Invoke(signatureAccount, requestBody)</code> call in one place.</li>\n<li>you will get rid of the nested Task</li>\n<li>it will be more simple if your customer decide...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T10:43:06.447", "Id": "270608", "Score": "0", "Tags": [ "c#", "generics", "async-await" ], "Title": "Retrying a RestRequest" }
270608
<p>This is a popular <a href="https://leetcode.com/problems/minimum-window-substring/" rel="nofollow noreferrer">question on LeetCode</a>:</p> <blockquote> <h3>76. Minimum Window Substring</h3> <p>Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every charac...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T11:41:24.950", "Id": "534526", "Score": "0", "body": "Seems like the paste is not yet approved, I have updated with a sample using another tool .. hope this works at your end." } ]
[ { "body": "<p>The main bottleneck is how characters of a string are accessed. A Swift <code>String</code> is a collection of <code>Character</code>s, and a <code>Character</code> represents a single extended grapheme cluster, which can be one or more Unicode scalars. That makes counting and index operations lik...
{ "AcceptedAnswerId": "270611", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T10:58:24.130", "Id": "270609", "Score": "1", "Tags": [ "programming-challenge", "time-limit-exceeded", "swift" ], "Title": "Minimum Window Substring in Swift exceeds LeetCode ...
270609
<p>I am doing the Advent of Code challenge to learn Rust (obviously there may be spoilers if you still want to do the challenge).</p> <p>The instructions are too long to include verbatim so I will <a href="https://adventofcode.com/2021/day/1" rel="nofollow noreferrer">link them</a> and give a summary for the two parts....
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T12:58:57.363", "Id": "534537", "Score": "0", "body": "Please summarise the _objective_ in the question title and description, so that the question has value even when the linked resource is not accessible. Thanks!" } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T11:04:31.637", "Id": "270610", "Score": "2", "Tags": [ "programming-challenge", "rust" ], "Title": "Advent of Code 2021: day 1" }
270610
<p>I have the following code, like a git command line system with various supported parameters and commands. But as can be seen, it involves a lot of if-else conditions which<br> It doesn't seem that clean and is error-prone. Could there be a way to restructure it using some design pattern<br><br></p> <pre><code>public...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T12:57:29.400", "Id": "534535", "Score": "4", "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>I was half inclined not to answer. As others said this question could be improved to better fit the forum.</p>\n<p>However there's enough here IMHO to warrant an answer.</p>\n<p>Firstly, don't worry about patterns at this point. There's more fundamental issues to look at.</p>\n<p>Names like <code>...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T11:19:26.803", "Id": "270612", "Score": "-2", "Tags": [ "java", "design-patterns" ], "Title": "Refactoring existing code with some design pattern" }
270612
<p>I'm trying to write idiomatic and fast Rust code by solving AoC challenges this year! :-)</p> <p><a href="https://adventofcode.com/2021/day/2" rel="nofollow noreferrer">Link to AoC Day 2 problem</a></p> <p>The input format in this problem is a list of lines each containing one string token (one of <code>forward/down...
[]
[ { "body": "<ol>\n<li>Let's address this</li>\n<li>Let's address this too</li>\n<li>I looked up the definition of <code>io::Lines</code>, its overhead is one heap allocation per line, so the cost is small but real. <code>buf.read_line</code> with a reused <code>String</code> would be slightly faster.</li>\n</ol>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T11:46:57.423", "Id": "270613", "Score": "2", "Tags": [ "programming-challenge", "rust" ], "Title": "Reading input in idiomatic Rust for Advent of Code Day 2" }
270613
<p>This is a follow-up question for <a href="https://codereview.stackexchange.com/q/251823/231235">A recursive_transform Template Function with Execution Policy</a>, <a href="https://codereview.stackexchange.com/a/253853/231235">A recursive_transform Template Function Implementation with std::invocable Concept and Exec...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T12:09:06.043", "Id": "270615", "Score": "3", "Tags": [ "c++", "recursion", "template", "concurrency", "c++20" ], "Title": "Order guaranteed recursive_transform template fu...
270615
<p>I need help refactoring the following code using something simpler: <br></p> <pre><code> HashMap&lt;String, Blob&gt; blobmap = new HashMap&lt;&gt;(); blobmap.putAll(brLast.getParentTracked()); for (Blob blob : blobmap.values()) { Blob t; try { t = brCommit.getB...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T15:04:24.530", "Id": "270619", "Score": "0", "Tags": [ "java" ], "Title": "converting iteration of maps to streams" }
270619
<p>When fridays_135 is called, a list of dates between the start date and end date is produces by date_range. That list is then narrowed down to just the Friday dates and then grouped by month by fridays_by_month. Finally, fridays_135 loops through those groups of months, extracts the 0th, 2nd, and 4th element in that ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T09:21:49.910", "Id": "534619", "Score": "0", "body": "You shouldn't use comments to describe your function, but [docstrings](https://www.python.org/dev/peps/pep-0257/)." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDa...
[ { "body": "<p>Here are a few pointers on how your code can be improved:</p>\n<h1>Style</h1>\n<p><a href=\"https://www.python.org/dev/peps/pep-0008/\" rel=\"noreferrer\">PEP8</a> recommends surrounding top-level functions by two blank lines. This improves readability somewhat.</p>\n<p>Also, docstrings are suppos...
{ "AcceptedAnswerId": "270628", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T16:01:04.153", "Id": "270620", "Score": "3", "Tags": [ "python", "python-3.x", "datetime" ], "Title": "Produce a list of every 1st, 3rd, and 5th Friday of each month in a date...
270620
<p>I had to write a custom function to load a yaml file from the current working directory. The function itself works and my intention was to write it in a pure fashion but my senior colleague told me that the way I wrote this function is utterly bad and I have to rewrite it.</p> <p>Which commandment in Python did I vi...
[]
[ { "body": "<p>Which commandment did you violate? Using <code>os.path</code> and <code>pathlib</code> in the same breath! <code>pathlib</code> is an object-oriented replacement to <code>os.path</code>.</p>\n<pre><code> path = os.path.join(Path.cwd().resolve(), file)\n if os.path.isfile(path):\n wi...
{ "AcceptedAnswerId": "270626", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T18:13:04.213", "Id": "270625", "Score": "2", "Tags": [ "python", "python-3.x", "file-system" ], "Title": "Read file from current path in Python" }
270625
<p>I've tried optimising my program by removing invalid values for possible spaces instead of searching from 1-9, and by choosing values with the lowest number of empty spaces in its row and column, but these are marginal improvements and sometimes slow it down.</p> <p>I've heard of constraint satisfaction being used t...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T02:50:53.370", "Id": "534607", "Score": "0", "body": "Haven't looked at your code at all, but Peter Norvig's is often worth [studying](https://norvig.com/sudoku.html)." } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T19:48:14.067", "Id": "270627", "Score": "1", "Tags": [ "python", "recursion", "sudoku", "backtracking" ], "Title": "How can I optimise my recursive backtracking sudoku algorit...
270627
<p>I am trying to write a simple rock paper scissors game in pycharm using classes and pygame. So far, I have not incorporated pygame yet. My idea is to import images that change in regards to the user's choice and the computer's random choice.</p> <p>This is what I have so far:</p> <pre><code>import random class Roc...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T21:18:07.060", "Id": "534594", "Score": "0", "body": "Could you double check your indentation? If you highlight everything and click `{}`, that should get you started. Otherwise, your last few lines aren't rendering correctly." ...
[ { "body": "<h1>Good things</h1>\n<p>You mostly follow PEP8 styling conventions, making your code quite readable. The only exception I see is an extra blank line at the beginning of the <code>score</code> and <code>play</code> methods.</p>\n<p>Also, it is good thinking to wrap your game state into a class for fu...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T20:52:34.433", "Id": "270630", "Score": "1", "Tags": [ "python", "beginner", "rock-paper-scissors" ], "Title": "Simple Rock Paper Scissors game in Python" }
270630
<p>This Bash program parses day, month, year and month and year from arguments:</p> <pre><code>#!/usr/bin/env bash for arg do day= month= year= case $arg in */*/*|*-*-*) read -r year month day &lt;&lt;&lt; &quot;$(date '+%Y %m %d' -d &quot;$arg&quot;)&quot; ;; ????/??|????/?) ...
[]
[ { "body": "<p>How about</p>\n<pre class=\"lang-bsh prettyprint-override\"><code>for arg do\n day= month= year=\n\n case $arg in\n */*/* | *-*-*)\n read -r year month day &lt; &lt;(date '+%Y %m %d' -d &quot;$arg&quot;)\n ;;\n ????[-/]?? | ????[-/]?)\n IFS='-/' read -r y...
{ "AcceptedAnswerId": "270632", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T21:39:23.610", "Id": "270631", "Score": "1", "Tags": [ "parsing", "datetime", "bash" ], "Title": "Parse a selection of date formats" }
270631
<p>I'm fairly new to Python and am exploring how to fix functions and make code 'more effective and readable'. As a first step, I would want to try to make shorter snippets of code here - for example by dividing it into more functions.</p> <p>I would also appreciate further improvements regarding possible errors I migh...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T02:34:54.767", "Id": "534606", "Score": "2", "body": "Some clarification of the input file format would be good; I can derive it from the code, but it's not at all obvious." } ]
[ { "body": "<h2>Some good stuff:</h2>\n<ul>\n<li>You're using error-specific <code>except</code> clauses.</li>\n<li>You're using <code>where</code> blocks.</li>\n</ul>\n<h2>Items you can improve:</h2>\n<ul>\n<li><p>Use a <code>main</code> method. See <a href=\"https://www.guru99.com/learn-python-main-function-wi...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T22:06:49.527", "Id": "270633", "Score": "4", "Tags": [ "python", "performance", "error-handling", "mathematics" ], "Title": "Find the mean magnitude of values inside unit circ...
270633
<p>To start I'd like say that I'm a beginner writing my first Next.js app though I feel this question is more React related. I'm building an app where an user can add/edit stored food, recipes etc. which means I use a lot of submit form handlers. In every handler I:</p> <ol> <li><p>Check if inputs are correct (I also d...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T08:24:52.827", "Id": "534617", "Score": "2", "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 ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-02T22:28:08.737", "Id": "270634", "Score": "0", "Tags": [ "javascript", "beginner", "algorithm", "react.js", "redux" ], "Title": "Cookbook app in next.js" }
270634
<p>I'm trying to create multiple rows in my db with an array. This array has multiple objects of products chosen by the client.</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><cod...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T03:11:59.833", "Id": "534608", "Score": "2", "body": "Please pick a title that describes the function of the program." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T07:29:39.743", "Id": "534616",...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T00:10:30.080", "Id": "270635", "Score": "0", "Tags": [ "javascript", "performance", "node.js" ], "Title": "Improving multiple row creation query in JavaScript" }
270635
<p>Well I was solving Problem 3 from Project Euler, but I just found out that my code is really bad, it would take so much time to finish processing the code and I honestly do not know how to optimize it.</p> <h1>Problem Statement</h1> <blockquote> <p>The prime factors of 13195 are 5, 7, 13 and 29. <br /> What is the l...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T01:16:56.127", "Id": "534603", "Score": "0", "body": "You don't need to test for primality. If you start with 2 and proceed in sequence 2, 3,4,5, ... then when you find a factor it is *guaranteed* to be prime. Another optimization i...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T00:40:17.863", "Id": "270636", "Score": "0", "Tags": [ "javascript", "programming-challenge" ], "Title": "Euler Project Problem #3 Optimization Needed" }
270636
<p>I want to print the below pattern</p> <pre><code>* * * * * * * * * * * * * * * </code></pre> <p><strong>My logic written</strong></p> <pre><code>for row in range(1,6): for col in range(1,6): if row is col: print(row * '* ') </code></pre> <p>Can someone review the code and suggest any improvements needed...
[]
[ { "body": "<p>Welcome to Code Review.</p>\n<p>Your code is literally 4 lines. So there isn't much to review.</p>\n<ul>\n<li><p>Do not use the <code>is</code> operator to compare the integers. See <a href=\"https://stackoverflow.com/questions/132988/is-there-a-difference-between-and-is\">difference between <code...
{ "AcceptedAnswerId": "270640", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T04:21:23.580", "Id": "270639", "Score": "3", "Tags": [ "python", "design-patterns" ], "Title": "Design a pattern using python" }
270639
<p>I have different format of address in an array, those format looks like this</p> <p><code>lastname/firstname/_/country/postalCode/_/regionId/city/addressFirst/addressSecond/_/phone</code></p> <p><code>lastname</code> =&gt; a part of the address (noted <code>AddressPart</code>) <code>/</code> =&gt; a separation <code...
[]
[ { "body": "<blockquote>\n<p>What I don't like in what I did is :</p>\n<ol>\n<li><p>I replace items, so I need to filter from the list of parts the one I want, to keep the one I want to remove</p>\n</li>\n<li><p>it is 4 replaces operations, and I was wondering if it was improvable.</p>\n</li>\n</ol>\n</blockquot...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T08:38:45.840", "Id": "270644", "Score": "1", "Tags": [ "javascript", "strings", "typescript" ], "Title": "get address parts based on requested parts" }
270644
<p>Heart rate or blink generator. Clocked from the system frequency, but calculated from a constant of 120MHz. Has a prescaler with values 2, 3, 5, 6, for even heart beat / blinking. The IS_DEBUG parameter is required for debugging for easy control over the rhythm, this parameter reduces 120MHz to 120Hz. IS_BLINK selec...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T14:18:04.590", "Id": "270647", "Score": "1", "Tags": [ "verilog", "fpga", "systemverilog", "rtl" ], "Title": "Heart beat RTL module" }
270647
<p>Develop a program to maintain a list of homework assignments. When an assignment is assigned, add it to the list, and when it is completed, remove it. You should keep track of the due date. Your program should provide the following services:</p> <ol> <li>Add a new assignment.</li> <li>Remove an assignment.</li> <li>...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T23:20:17.500", "Id": "534637", "Score": "0", "body": "Hey, can you please provide the actual text of the assignment?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T23:32:47.210", "Id": "534639", ...
[ { "body": "<ul>\n<li><p>Right names.</p>\n<p>The class should be called <code>Assignment</code> singular, and instead of <code>assignmentName</code> one can drop <code>assignment</code>, maybe call it <code>topic</code> as <code>name</code> is too generic, misleading.</p>\n</li>\n<li><p>Your question: where wha...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T20:08:12.490", "Id": "270650", "Score": "4", "Tags": [ "java" ], "Title": "Create a list of assignments" }
270650
<p>Everything currently works exactly as requested by the instructor, I've included as much possible commented documentation as I can think of to make it easier for people to see what the required criteria is for the project! Let me know what you guys think, I would really appreciated it!</p> <p>The program is disjoint...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T21:15:37.733", "Id": "534631", "Score": "3", "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 state...
[]
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T20:53:15.957", "Id": "270651", "Score": "1", "Tags": [ "python", "beginner", "homework" ], "Title": "Generate and display usernames" }
270651
<p>This is a working solution to <a href="https://adventofcode.com/2021/day/3" rel="nofollow noreferrer">today's Advent of Code puzzle</a>, written in Haskell. However, I feel like this solution is not optimal.</p> <pre class="lang-hs prettyprint-override"><code>module BinaryDiagnostic (parseInput, part1, part2) where ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T22:11:09.387", "Id": "270654", "Score": "2", "Tags": [ "performance", "programming-challenge", "haskell", "functional-programming" ], "Title": "Advent of Code 2021, Day 3 in H...
270654
<p><a href="https://i.stack.imgur.com/YfzVp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YfzVp.png" alt="screenshhot" /></a></p> <pre><code>def shuffle(): global deck positions = [i for i in range(52)] deck = [i for i in range(52)] cards = [A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K] ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T23:27:27.743", "Id": "534638", "Score": "1", "body": "Welcome to Code Review! Please confirm: is the code working as expected?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T00:09:06.347", "Id": ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-03T23:15:48.783", "Id": "270655", "Score": "-4", "Tags": [ "beginner", "python-3.x" ], "Title": "tried to make blackjack in python, deck that should only contain standard cards somehow h...
270655
<p><a href="https://i.stack.imgur.com/Adpkq.jpg" rel="nofollow noreferrer">Here is what it should look like</a> I am having trouble aligning the first day of the month with the right weekday. The calendar is going to be for this year so January first will be on Friday but I cant seem to get any of firsts of each month ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T06:42:10.617", "Id": "534649", "Score": "0", "body": "Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing *what* your code does. Once the code does what you want, ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T03:54:30.490", "Id": "270657", "Score": "-1", "Tags": [ "c++" ], "Title": "C++ Calendar Alignment" }
270657
<p>I created a BaseRoute class route handling.</p> <p>The BaseRoute class takes the following parameters:</p> <pre><code> 1. prefix - the name of the endpoint such as posts 2. service - the service it has to call such as post_service 3. response_model:Pydantic Model - the response it will return ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T07:59:04.873", "Id": "270659", "Score": "0", "Tags": [ "python", "object-oriented", "design-patterns" ], "Title": "Object Oriented Routing using Python's FastAPI" }
270659
<p>Given a list of integers a 2D graph has to be plotted taking 1st, 3rd, 5th, ... numbers as upward slope and 2nd, 4th, ... numbers as downward slope.</p> <p>I have used a Python list to do it. Is there any further optimization possible with Python?</p> <h2>Sample input:</h2> <blockquote> <p>3, 1, 2, 3, 6, 2, 3, 6, 2,...
[]
[ { "body": "<p><strong>Some simple things:</strong></p>\n<p>check out</p>\n<p><code>top</code> and <code>length</code> could probably have better names (Top of what? Length of what?), maybe <code>max_x</code>, <code>max_y</code>? And <code>print_list</code> could be better as e.g. <code>graph</code> and <code>p...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T08:26:01.810", "Id": "270660", "Score": "7", "Tags": [ "python", "graph", "data-visualization", "ascii-art" ], "Title": "Draw a 2d graph using slashes" }
270660
<p>My favourite 3rd party library isn't getting maintained so now I need to make my own library for interfacing with Riot Games' API. Epic.</p> <p>Problem is that there are <em>rules</em>, such as:</p> <ul> <li>100 requests in 2 minutes</li> <li>20 requests in 1 second</li> </ul> <p>So I made an API request scheduler.<...
[]
[ { "body": "<p>Don't use <code>time.time</code>; use <code>time.monotonic</code> - otherwise, certain OS time changes are going to deliver a nasty surprise.</p>\n<p>Make a constant for your 120 seconds.</p>\n<p>You ask:</p>\n<blockquote>\n<p>Is <code>-&gt; dict</code> OK?</p>\n</blockquote>\n<p>Not really. This:...
{ "AcceptedAnswerId": "270689", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T10:05:02.937", "Id": "270661", "Score": "3", "Tags": [ "python", "python-3.x" ], "Title": "API call scheduler for Python" }
270661
<p>I'm learning regex for c++, and tried to make a simple function. It is very small but I'm satisfied, because this is the first time I managed to pass function as argument. This is a replace function. Please give me tips on how to improve:</p> <pre><code>std::string Replace(std::string text, std::regex reg, std::func...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T10:29:11.783", "Id": "270662", "Score": "1", "Tags": [ "c++", "regex" ], "Title": "Replace function for C++" }
270662
<p>I am trying to solve the following exercise:</p> <p>&quot;Consider a function ​ removePrimes() be a C function that takes as input an array of integers, removes all numbers that are prime, and returns the compacted version of the array. Create an array of 200 integers, with random values between 7 and 13, and call ​...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T18:36:03.980", "Id": "534671", "Score": "0", "body": "user252524: `if (n==1){ return 1; }` --> Usually 1 is not considered a _prime_." } ]
[ { "body": "<p>Given that all the values are between 7 and 13, we can implement <code>is_prime()</code> much more efficiently:</p>\n<pre><code>bool is_prime(int n)\n{\n switch(n) {\n case 7: case 11: case 13: return true;\n default: return false;\n }\n}\n</code></pre>\n<hr />\n<p>In <code>rem...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T10:54:19.323", "Id": "270663", "Score": "1", "Tags": [ "c", "array" ], "Title": "Given an array of integers randomly selected from 7 to 13 (included), build a function that remove the...
270663
<p>I am trying to find all the &quot;missing&quot; devices in our database. Therefore I filter for the existing device ids and then prepare the data to be presentable and usable. The question I have is if there is any way to speed this up. Especially in the beginning <code>existing_device_ids</code> can even be empty a...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T12:07:53.903", "Id": "270665", "Score": "0", "Tags": [ "mongodb", "pymongo" ], "Title": "Is there a way to speed up the group stage of the MongoDB aggregation pipeline?" }
270665
<p>I have two rest application say a1 and a2 which is running on different containers. From a1 application i am calling the service exposed by a2 application for some processing. I am using okhttp to call the rest end point exposed by a2 and i am providing a callback url in request body. Once the request is received on...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T15:41:19.760", "Id": "270668", "Score": "0", "Tags": [ "java", "rest", "callback" ], "Title": "Callback Url example with Okhtp" }
270668
<p>I implemented this carousel component in react:</p> <pre><code>import React from &quot;react&quot;; import { AiOutlineArrowLeft, AiOutlineArrowRight } from &quot;react-icons/ai&quot;; import { useResizeDetector } from &quot;react-resize-detector&quot;; let arrowStyle = { background: &quot;white&quot;, border: &...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T16:10:14.610", "Id": "270670", "Score": "2", "Tags": [ "css", "image", "react.js", "jsx" ], "Title": "Carousel in react" }
270670
<p>I think I programmed a bottom-up merge sort, but I'm a little sceptical that it will work under any data set. By now, I've tested it with many random arrays of massive lengths, and it seems to work; the only thing making me doubt my function is that whenever I look online for a non-recursive one, all of the algorith...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T16:29:14.657", "Id": "270671", "Score": "1", "Tags": [ "javascript", "algorithm", "array", "mergesort" ], "Title": "Bottom-up merge sort" }
270671
<p>I have just started learning Java last month and started the java snake game program. I need to write a java snake game where the snake grows when it eats an apple, and dies when it touches itself. The goal of Snake is to create a snake as long as possible. When the snake reaches the end of the screen, it will re-em...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T17:24:25.793", "Id": "534663", "Score": "0", "body": "You also took out some code. In SnakeBody there's a bodyLength that's used but not defined. And in Snake, there's a foodPosition method that was removed.\nYou would need to pos...
[]
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T16:55:25.367", "Id": "270672", "Score": "-2", "Tags": [ "java", "eclipse" ], "Title": "Snake doesn't move in Java snake game" }
270672
<p>I have implemented the bulls and cows game in C++. The code:</p> <pre><code>#include &lt;cstdio&gt; #include &lt;cstdlib&gt; #include &lt;ctime&gt; struct DigitMatches { int matches_in_right_positions; int matches_in_wrong_positions; }; void CountNumberDigits(int (&amp;counts)[10], int n) { while (n &...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T18:40:14.560", "Id": "534674", "Score": "0", "body": "Can you provide a bit more introduction for those of us who have never heard of \"the bulls and cows game\"?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "...
[ { "body": "<p>Thoughts:</p>\n<ol>\n<li>The names are descriptive.</li>\n<li>This is supposed to be C++ but all of the libraries are from C -- my compiler complains about scanf (changed to scanf_s) as unsafe.</li>\n<li>Ask yourself &quot;Why did I make a class?&quot; A class is a container for data and code - it...
{ "AcceptedAnswerId": "270690", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T18:02:45.850", "Id": "270673", "Score": "0", "Tags": [ "c++", "object-oriented" ], "Title": "The bulls and cows game" }
270673
<p>I'm learning rust and doing an exercise where to parse a particular SGML document. Each line in a document can be either an opening tag &quot;&quot; , a closing tag &quot;&quot; or a scalar: &quot; Val&quot;. I'm using a regex with named capture groups to detect and extract, and would like to return an enum afterwar...
[]
[ { "body": "<p>Hello and welcome to the Rust community.</p>\n<h2>Correctness</h2>\n<p>Are you sure the code is correct? The regex looks odd, but ok. It seems that <code>Tag::Close</code> does not carry any meaningful info, even though it contains a String.</p>\n<h2>Manual</h2>\n<p>Be sure to read up on <code>if ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T18:46:58.743", "Id": "270675", "Score": "2", "Tags": [ "beginner", "rust" ], "Title": "Idiomatic way to extract matches from rust Regex?" }
270675
<p>In one of my homework projects, I have to parse a matrix definition into a matrix data structure in C. The elements of the matrix will be given in a list of double. I need a simple tokenizer and parser for the task naturally, but I have not much experience in parsing. I implemented the tokenizer and parser. The toke...
[]
[ { "body": "<p>Code looks pretty good. I prefer some other <a href=\"https://www.doc.ic.ac.uk/lab/cplus/cstyle.html\" rel=\"nofollow noreferrer\">style guide</a>, but this looks consistent, and consistency is important too.</p>\n<h3>Indentation</h3>\n<p>Arbitrarily, you can spell the string constant like this:</...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T19:09:56.540", "Id": "270677", "Score": "1", "Tags": [ "c", "parsing" ], "Title": "Parsing A Simple Matrix Definition In C" }
270677
<p>My code is working but it is extremely long. So, I guess there is a way to make it shorter/more efficient.</p> <p>The problem solved here is from Advent of Code 2021, Day 3, Part 1: <a href="https://adventofcode.com/2021/day/3" rel="nofollow noreferrer">https://adventofcode.com/2021/day/3</a></p> <pre><code>binary_l...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T21:47:55.830", "Id": "534692", "Score": "0", "body": "This seems like a very hardcoded way to go about things. For starters, I see a lot of `if` that should've been `elif`. What version of Python did you write this for?" }, { ...
[ { "body": "<p>I'm just going to make one suggestion, which you should be able to apply across a lot of your code.</p>\n<ol>\n<li>Use <a href=\"https://docs.python.org/3/tutorial/datastructures.html?highlight=list\" rel=\"nofollow noreferrer\"><code>list</code></a> structures, which are analogous to <em>arrays</...
{ "AcceptedAnswerId": "270688", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-12-04T20:36:38.737", "Id": "270682", "Score": "3", "Tags": [ "python" ], "Title": "Inefficient Solution - Advent of Code 2021, Day 3, Part 1" }
270682