body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p><strong>Prototype:</strong></p>
<pre><code>char *fgetline_alloc( FILE *fp, bool flush, int *nchars, bool eolend );
</code></pre>
<p>I realize this C99 function may be a bit more involved than expected, hence asking for reviews before using it for real (it's tested, but not extensively). I'll post the source code fir... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-19T18:48:28.810",
"Id": "514955",
"Score": "0",
"body": "Welcome to Code Review! 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. Thi... | [
{
"body": "<p>The macro is a little over-complex. If we're happy to always provide a string literal as format specifier (and we should be, for debugging), then just concatenate the prefix:</p>\n<pre><code>#define DBGMSG(format, ... )\\\n fprintf(stderr, "*** %s(): " format, __func__, __VA_ARGS__ )... | {
"AcceptedAnswerId": "260940",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-19T14:48:04.260",
"Id": "260939",
"Score": "4",
"Tags": [
"c"
],
"Title": "fgetline_alloc An involved C function for reading lines of arbitrary length"
} | 260939 |
<p>I am using this merge sort function to sort table rows by Date, Letter, and Number. It works, but it is super messy and hard for others to read.</p>
<p>The dates are being sorted in two formats YYYY-MM-DD and MM/DD/YYYY which is why there are if statements regulating each format.</p>
<p>And the reason I am different... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-19T18:55:12.210",
"Id": "514957",
"Score": "1",
"body": "Separate the date compairison from the merge sort logic. Merge() should accept a compare function as a parameter."
}
] | [
{
"body": "<h2>Code Style</h2>\n<ul>\n<li>You seem to use var, let, and const randomly. Pick a style and stick with it.</li>\n<li>The Javascript community generally uses camelCase for both variable names and function names. While it's not extremely important, I would recommend following suit.</li>\n<li>Always u... | {
"AcceptedAnswerId": "260960",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-19T17:04:54.000",
"Id": "260946",
"Score": "5",
"Tags": [
"javascript",
"mergesort"
],
"Title": "Merge Sort implementation is messy"
} | 260946 |
<p><strong>Hello everyone!</strong></p>
<p>In today's assignment I had to complete a rather unusual translator, take a look at my solution, tell me what I can do to make it better and show off yours!</p>
<p>Write a function that translates some text into New Polish and vice versa. Polish is translated into New Polish b... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-19T23:11:48.703",
"Id": "514968",
"Score": "1",
"body": "Not super important, but I'll just note that this is basically just a variation of \"Pig Latin\"."
}
] | [
{
"body": "<p>Your code is reasonable, but it does get tripped up if the text (<code>input</code>)\ncontains multiple adjacent spaces or the cleaned text (<code>content</code>) ends up\ncontaining multiple adjacent spaces. It also could be simplified here and\nthere. Some suggestions to consider: (1) parameteri... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-19T19:07:24.253",
"Id": "260949",
"Score": "3",
"Tags": [
"python",
"algorithm"
],
"Title": "NewPolish - unconventional translator in Python"
} | 260949 |
<p>As the title indicates this is one of the last most problems of Project Euler. The problem is straightforward. However, similar to the rest of the Euler Project problems either <code>Memory Error</code> or long execution times are problems. An explanation of the problem is:</p>
<blockquote>
<p>Consider the Fibonacci... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T04:43:44.873",
"Id": "514977",
"Score": "0",
"body": "The answer may lie here https://en.wikipedia.org/wiki/Fibonacci_number#/media/File:Thirteen_ways_of_arranging_long_and_short_syllables_in_a_cadence_of_length_six.svg . I 'm not s... | [
{
"body": "<p>A low hanging fruit first. You don't need to work through the entire powerset. Given that <span class=\"math-container\">\\$i_0 < i_1 < ... < i_k\\$</span>, and <span class=\"math-container\">\\$N = F_{i_0} + F_{i_1} + ... + F_{i_k}\\$</span>, how small <span class=\"math-container\">\\$F... | {
"AcceptedAnswerId": "260963",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-19T20:29:37.713",
"Id": "260951",
"Score": "2",
"Tags": [
"python",
"performance",
"programming-challenge",
"fibonacci-sequence"
],
"Title": "Project Euler Problem #755"
} | 260951 |
<p>I'm trying to implement a graph structure in python, making use of the classes Vertex, Edge and Graph. The goal is to read a csv file that contains users names and a number (weight), like such <strong>Lynch,Arnold,23</strong></p>
<p>The entire structure of the code that I have at the moment is the following:</p>
<pr... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-19T20:54:01.850",
"Id": "260952",
"Score": "0",
"Tags": [
"python",
"graph"
],
"Title": "Graph Implementation for Social Network"
} | 260952 |
<p>I wrote a simple Zoopla real estate scraper for just practicing what I learned so far in Python, Requests, BeautifulSoup and overall web scraping fundamentals. By looking at my code I feel like there would be a better and more elegant way to write it but unfortunately as a beginner I don't know yet. So, I believe I ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T15:32:13.040",
"Id": "515038",
"Score": "1",
"body": "Your code is incorrectly indented, particularly the class methods."
}
] | [
{
"body": "<ul>\n<li>Make a Session instead of issuing individual Requests <code>get</code>; this promotes explicit connection pooling, cookie sharing etc.</li>\n<li>There's no need for your current <code>print</code>s. If you find them to be of very high value, convert them into real logging calls</li>\n<li>Pr... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-19T20:55:55.703",
"Id": "260953",
"Score": "3",
"Tags": [
"python-3.x",
"json",
"web-scraping",
"beautifulsoup"
],
"Title": "Refactor Web Scraper"
} | 260953 |
<p>I have wrote following solution for one answer but I want to refactor to make it more simple and readable.</p>
<p>I am receiving params</p>
<pre><code>sample_params = [{ user_id: 1, email: 'example1@example.com' },
{ user_id: 5, email: 'example5@example.com' },
{ user_id: 13, email: 'example13@example.com'}]
</cod... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T08:41:25.153",
"Id": "514994",
"Score": "0",
"body": "I changed title but I want to refactor code so it was part of title but now removed it."
}
] | [
{
"body": "<p>Not sure if it's what you're looking for, in terms of readability:</p>\n<pre><code>data = User.where(id: sample_params.pluck(:user_id))\n .pluck(:department_id, :id).group_by {|u| u.shift }\n\nresults = data.map do |department_id, user_ids|\n users = user_ids.flatten.map do |id| \n e... | {
"AcceptedAnswerId": "261123",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T03:23:58.157",
"Id": "260961",
"Score": "1",
"Tags": [
"ruby",
"ruby-on-rails",
"hash"
],
"Title": "How to reduce code in hash created using Database and Params in rails"
} | 260961 |
<p>I thought this community is better place to ask my question so I ask here rather than at StackOverflow.
Recently, I learned that <code>Numba</code> can make Python function which uses <code>numpy</code> modules and <code>for</code> loops super faster so I was trying to implement it to my code in order to optimize ex... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T06:40:51.063",
"Id": "514986",
"Score": "1",
"body": "We require that the poster know why the code is written the way it is. Please [**follow the tour**](https://CodeReview.StackExchange.com/tour), and read [**\"What topics can I as... | [
{
"body": "<p>Actually, it is embarrassing to answer my question, but I think the problem was about the initial compilation time using <code>numba</code>. After I executed function <code>Grid_Search</code> once and executed it again, it outperforms original code in terms of execution time.</p>\n<p><a href=\"htt... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T06:20:28.810",
"Id": "260964",
"Score": "3",
"Tags": [
"performance",
"python-3.x",
"comparative-review",
"numpy",
"numba"
],
"Title": "Using Numba works slower than not u... | 260964 |
<p>My code for a LocalBinaryPatern in python is running very slow. I tried optimizing it with tips from online. I'am still getting used to python, and programming in General so any tips are very welcome! Here is the code:</p>
<pre><code>def localbinarypattern(image, radius=2):
h, w = image.shape
if radius == 1:... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T08:00:41.870",
"Id": "514990",
"Score": "0",
"body": "small tip: `feat = [0 for _ in range(255)]` => `feat = [0]*255`"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T08:01:44.443",
"Id": "514991",... | [
{
"body": "<h1>No <code>else</code> after <code>return</code></h1>\n<p>You have code like</p>\n<pre><code>if x:\n return 0\nelse:\n ...\n</code></pre>\n<p>Just drop the <code>else</code>, because you previously already returned. Use else branches only if the code converges again after the two branches, no... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T07:58:50.777",
"Id": "260967",
"Score": "0",
"Tags": [
"python",
"performance"
],
"Title": "My code for a LocalBinaryPatern in python is running very slow. Any tips?"
} | 260967 |
<p>I need some help to evaluate whether I am doing it right. The scenario is, a 3rd party application is sending a webhook request after a successful payment but the problem is that sometimes this application may send the same notification more than once. So it is recommended to ensure that implementation of the webhoo... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T15:07:49.583",
"Id": "515034",
"Score": "2",
"body": "Based on your wording, _sometimes this application may send the same notification more than once_ is a little ambigious. Is this an issue you need help fixing (in which case this... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T08:07:10.010",
"Id": "260968",
"Score": "1",
"Tags": [
"python",
"database",
"django",
"web-services",
"django-template-language"
],
"Title": "processing webhook request c... | 260968 |
<p>Solved task is pretty straightforward: mounting partition if not mounted already, to start executable.</p>
<p>There is a couple of checks and notifications because it is supposed to be launched from X and there are no way to see <code>stdout</code>/<code>stderr</code> stream. I have started with much larger version ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T09:52:19.450",
"Id": "514997",
"Score": "1",
"body": "Terminology: a _partition_ is a part of a disk (such as `/dev/sda5`). The filesystem directory to which we attach its filesystem (`/mnt/Games`) is called a __mount point__."
}... | [
{
"body": "<h2>Shell Errorhandling</h2>\n<p>There's one thing I would have done differently (though it's not relevant to the small piece of code here) and that is the error handling inside the function.</p>\n<ol>\n<li>You can use <code>set -e</code> to automatically exit the function, you could eliminate the <c... | {
"AcceptedAnswerId": "260979",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T08:45:21.647",
"Id": "260970",
"Score": "3",
"Tags": [
"bash"
],
"Title": "Wrapper to mount partition before launching executable"
} | 260970 |
<p>I have been playing around with numpy and matplotlib.</p>
<p>My little project was to create a scatter plot ranging from -1 to 1 on both X and Y, but where the shading is done with the XOR scheme.</p>
<p>The following is the code that I have implemented (it is in a cell of a jupyter notebook, hence the trailing <cod... | [] | [
{
"body": "<p>Since <code>(a < 0 and b > 0) or (a > 0 and b < 0)</code> can be summarized as <code>a*b < 0</code>, moreover <code>*</code> and <code><</code> work on vectors, we get the one-liner:</p>\n<pre><code>plt.scatter(X[0], X[1], c=X[0]*X[1] < 0)\n</code></pre>\n",
"comments": []... | {
"AcceptedAnswerId": "260972",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T08:55:35.157",
"Id": "260971",
"Score": "1",
"Tags": [
"python",
"performance",
"numpy",
"matplotlib"
],
"Title": "Removing Loop from Numpy XOR"
} | 260971 |
<p>I am writing a Python code for KMeans clustering.</p>
<p>The aim of this post is to find out <strong>how I can make my below mentioned code optimal when the number of clusters is very large.</strong> I am dealing with <strong>data with tens of millions of samples and scores of features</strong>. The n<strong>umber o... | [] | [
{
"body": "<p>First, some Python improvements. You do repeated lookups of the kind <code>cluster_dict[cluster]</code>. If you were to directly iterate over <code>cluster_dict.values()</code> these would all be not needed. Also, list comprehensions are usually faster than building a simple list with a <code>for<... | {
"AcceptedAnswerId": "260980",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T10:28:13.673",
"Id": "260973",
"Score": "7",
"Tags": [
"python",
"performance",
"algorithm",
"machine-learning"
],
"Title": "Optimize K-Mean for large number of clusters"
... | 260973 |
<p>I have a simple class that listens click and draws two points on the page.</p>
<p>If first point is not exist it is drawn. When second point is present it should be changed after each click.</p>
<p>I dislike this part of code:</p>
<pre><code>this.point2.element.style.left = `${e.x}px`;
this.point2.element.style.top ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T13:21:40.160",
"Id": "515015",
"Score": "2",
"body": "Welcome to the Code Review Community. Unlike Stack Overflow we do not answer `How to` questions. because they indicate the code is not working as expected. On Code Review the cod... | [
{
"body": "<p>There are some repetitions in the current implementation, which can be refactored and the code will become clearer. For example:</p>\n<ul>\n<li>Use a custom <code>type</code> or <code>interface</code> for the private members.</li>\n</ul>\n<pre class=\"lang-js prettyprint-override\"><code>interface... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T10:49:18.627",
"Id": "260975",
"Score": "1",
"Tags": [
"javascript",
"typescript",
"dom"
],
"Title": "How to keep current HtmlElement active and change its properties?"
} | 260975 |
<p>I have the following working code to get IPv4/v6 addresses from host names:</p>
<pre class="lang-cpp prettyprint-override"><code>#include <array>
using std::array;
#include <iostream>
using std::cout;
#include <netdb.h>
#include <stdexcept>
using std::domain_error;
#include <sys/socket... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T11:29:52.510",
"Id": "515006",
"Score": "1",
"body": "You object to a for loop, would you object to `std::copy` or something similar?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T11:31:36.027",
... | [
{
"body": "<p>I agree with you that the copying of data from <code>s6_addr</code> seems cumbersome. I would instead just cast without copying:</p>\n<pre><code>auto& bytearray = reinterpret_cast<std::array<unsigned char,16>&>(ipv6socket->sin6_addr.s6_addr);\n</code></pre>\n<p>(If we had n... | {
"AcceptedAnswerId": "260981",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T11:05:08.607",
"Id": "260976",
"Score": "1",
"Tags": [
"c++",
"array",
"c++17",
"networking"
],
"Title": "Gather all IP addresses of a host as a vector"
} | 260976 |
<p>I've made a program which reads from the console and writes it in a <code>.txt</code> file. This programm should write in a file with <code>\n</code>.</p>
<pre class="lang-cpp prettyprint-override"><code>#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T06:37:46.367",
"Id": "515089",
"Score": "0",
"body": "I guess `main2()` is a typo that should be `main()`, right?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-26T22:40:35.957",
"Id": "515566",
... | [
{
"body": "<h1>Error Handling</h1>\n<p>You check whether the output file was opened correctly, but all you do is output a message (you don't even say what's wrong!) and then you keep on ignoring it. What if <code>file.txt</code> is a directory or read-only? I guess you haven't tested these cases. By default, th... | {
"AcceptedAnswerId": "261019",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T14:19:30.367",
"Id": "260983",
"Score": "4",
"Tags": [
"c++",
"file-system"
],
"Title": "Efficiently write in a file in C++"
} | 260983 |
<p>I have an inner class for filtering:</p>
<pre><code>private class RegSpecification implements Specification<Reg> {
private final transient RegFilterDTO filter;
private transient Predicate predicate;
private transient CriteriaBuilder cb;
public RegSpecification(RegFilterDTO filter) {
t... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-31T18:48:30.120",
"Id": "515993",
"Score": "2",
"body": "Hi sophie. 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. As such we have ... | [
{
"body": "<p>I would suggest that the <code>PredicateBuilder</code> actually follows a builder like pattern, where methods are cascaded to create the object. Currently the <code>predicate</code> object is updated with seaparate calls to the static method in the <code>PredicateBuilder</code>. Rather than that y... | {
"AcceptedAnswerId": "260990",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T15:47:10.063",
"Id": "260984",
"Score": "2",
"Tags": [
"java"
],
"Title": "Writing a clean Predicate Builder"
} | 260984 |
<p><strong>Problem:</strong></p>
<p>Given a string <code>aaabbcccaad</code> print the no. of occurrence of the character in the same order in which the character occurred.</p>
<p>Expected output:
<code>(a, 3), (b, 2), (c, 3), (a, 2), (d, 1)</code></p>
<p><strong>The approach:</strong></p>
<ol>
<li>Loop through each cha... | [] | [
{
"body": "<p>Problems like this tend to be annoying: so close to a simple solution, except for the need to be adjusting state during the loop. In this case, <code>itertools.groupby()</code> offers a shortcut, because its grouping function defaults to an identity, which is exactly what you need.</p>\n<pre><code... | {
"AcceptedAnswerId": "260991",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T16:04:50.980",
"Id": "260986",
"Score": "2",
"Tags": [
"python"
],
"Title": "Return character frequency in the order of occurrence"
} | 260986 |
<p>I have been trying to write a number guessing game and I am trying to condense the second while loop when guess =! random_number. <br>I can't figure out if there is any better way to shorten the code but to still achieve the same result. I wonder if someone is able to help me out. <br> If there's anything else which... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T18:39:54.960",
"Id": "515053",
"Score": "2",
"body": "Welcome to Code Review! Please [edit] your question so that the title describes the *purpose* of the code, rather than its *mechanism*. We really need to understand the motivati... | [
{
"body": "<p>Miscellaneous notes:</p>\n<ul>\n<li>you don't need a <code>break</code> after a <code>return</code></li>\n<li>you could (attempt to) return directly from the input; "except" will still catch and cycle errors</li>\n<li><code>inputNumber()</code> explicitly returns an integer; no need to c... | {
"AcceptedAnswerId": "260993",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T16:35:47.243",
"Id": "260988",
"Score": "0",
"Tags": [
"python"
],
"Title": "Is there a better way to condense the while loop?"
} | 260988 |
<p>This is a follow-up question for <a href="https://codereview.stackexchange.com/q/260782/231235">Android app class serialization</a>. The implementation of <code>User</code> class has been updated and the functionality of null string checking, password strength checking and the correctness of date formatting are cons... | [] | [
{
"body": "<h2>Dates</h2>\n<pre><code>// Reference: https://stackoverflow.com/a/20231617/6667035\nprivate boolean IsDateValid(String dateStr) {\n if (dateStr.matches("([0-9]{2})/([0-9]{2})/([0-9]{4})"))\n return true;\n else\n return false;\n}\n</code></pre>\n<p>Did you read the c... | {
"AcceptedAnswerId": "261000",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T16:52:24.840",
"Id": "260989",
"Score": "0",
"Tags": [
"java",
"object-oriented",
"android",
"classes",
"null"
],
"Title": "Android APP User class implementation"
} | 260989 |
<p>I made this c# hangman game...</p>
<p>I would like to know what you all think about it.</p>
<p>This is a pretty basic but still gets the job done let me know what you think.</p>
<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace idontknow
{
class thehanged... | [] | [
{
"body": "<p>The common C# naming conventions are to have class/struct fields, method parameters and local variable in camelCase and namespaces, type names, property, and method names in PascalCase. Additionally, field names are often introduced with an underscore.</p>\n<p>Example:</p>\n<pre class=\"lang-cs pr... | {
"AcceptedAnswerId": "260998",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T17:24:05.370",
"Id": "260992",
"Score": "0",
"Tags": [
"c#",
"object-oriented",
"game",
"hangman"
],
"Title": "A C# hangman game"
} | 260992 |
<p>C++ has the function <a href="https://en.cppreference.com/w/cpp/algorithm/sample" rel="noreferrer">std::sample</a> which randomly samples from a range and places the results via an output iterator. My goal is to create a utility that directly returns a single value in the event that we only want to sample a single r... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T19:54:28.543",
"Id": "515063",
"Score": "0",
"body": "My goal was to, as much as possible, delegate implementation details to `std::sample`. The theory is that `std::sample` already works, but in the specific case that we only want ... | [
{
"body": "<p><strong>Interface</strong></p>\n<p>First of all, I would consider usage cases. If there is significant need for sampling from one-pass-only sequences (streaming from a file or network), then I would keep current interface of returning selected value. This might open a can of worms though.</p>\n<p>... | {
"AcceptedAnswerId": "261005",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T18:07:53.757",
"Id": "260995",
"Score": "7",
"Tags": [
"c++",
"random"
],
"Title": "Convenience function wrapping C++17's std::sample for distance=1 case"
} | 260995 |
<p>I'm new to C as in I've only studied it for a year and it's my first language. I still don't know how to handle real world code and so would like to see how a real world programmer would write up a program that can find and replace text in a text file.</p>
<p>It took me 3 days to figure this out and I've tried my be... | [] | [
{
"body": "<p>I would not go into whether your program is working or not but I would like to give my views after seeing your code.</p>\n<p>Pointer copy can be cleaned up:</p>\n<pre><code>void strcpy_0n(char *dest, const char *source, size_t num)\n{\n ...\n *dest = *source;\n dest++;\n so... | {
"AcceptedAnswerId": "261082",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T18:46:02.367",
"Id": "261001",
"Score": "4",
"Tags": [
"beginner",
"c",
"text-editor"
],
"Title": "C: Find and Replace in a text file (by a new programmer)"
} | 261001 |
<p>I have made this small checkout stepper with Vue (v 2.x.x):</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"><code>var app = new Vue({
el: "#cart",
data: {
stepCounter: 1... | [] | [
{
"body": "<blockquote>\n<h3>Is there any room for "shortening" the code?</h3>\n</blockquote>\n<h3>Shorthands</h3>\n<p><a href=\"https://vuejs.org/v2/guide/syntax.html#Shorthands\" rel=\"nofollow noreferrer\">Shorthands</a> can simplify the markup. The click handlers already use the shorthand <code>@c... | {
"AcceptedAnswerId": "261008",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T20:08:27.987",
"Id": "261004",
"Score": "4",
"Tags": [
"javascript",
"css",
"ecmascript-6",
"event-handling",
"vue.js"
],
"Title": "Vue.js checkout stepper"
} | 261004 |
<p>I'm looking for any sort of optimization and/or conventional practice tips, such as using the appropriate data types and naming my variables appropriately.</p>
<pre><code>#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
constexpr short MIN_ELEMS = 3;
constexpr short ... | [] | [
{
"body": "<ol>\n<li><p>Sort your includes. That way, you can keep track even if there are more of them.</p>\n</li>\n<li><p>Writing a test-program is a good idea. Though print the seed-value, and allow overriding from the command-line for reproducibility.</p>\n<p>In line with that, add a method to test whether ... | {
"AcceptedAnswerId": "261012",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T20:58:58.323",
"Id": "261007",
"Score": "2",
"Tags": [
"c++",
"sorting",
"heap"
],
"Title": "Trying for an efficient and readable heap-sort implementation"
} | 261007 |
<p>I created a system that allows individuals to ask questions about code, and chat. I wanted to make this system smaller and better because this is easy to bypass for some reason.</p>
<p>The modules/packages I used for this chatroom project</p>
<pre class="lang-py prettyprint-override"><code>import os
import time
</co... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-01T00:49:33.297",
"Id": "516034",
"Score": "0",
"body": "How is this a chat room? Is the file mapped to an NFS mount or something?"
}
] | [
{
"body": "<p>I have carefully read all of your code and I would like to propose some changes, in line with the PEP8 good practice convention:</p>\n<ul>\n<li>ideally, the indentation is a multiple of 4;</li>\n<li>it is not necessary to use multiple '#' to comment a line;</li>\n<li>boolean expressions like <code... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T21:49:52.670",
"Id": "261009",
"Score": "3",
"Tags": [
"python"
],
"Title": "python Chatroom/Codehelp through the terminal"
} | 261009 |
<p>Recently wrote a brainfuck interpreter in Go.</p>
<p>Here's the Github Repo <a href="https://github.com/anthonygedeon/brainfuck" rel="nofollow noreferrer">Brainfuck</a></p>
<h3>Areas that need work</h3>
<p>The parsing for brackets <code>[]</code> is still buggy and is known to fail when dealing with nested loops i.e... | [] | [
{
"body": "<h1>Structure</h1>\n<p>I would expect to find something that just runs Brainfuck code, like a method or a function, not have this embedded into the main function. Similarly, retrieving the code from stdin or from a file could be moved to a separate function. It would make these things easier to under... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-20T23:48:16.313",
"Id": "261011",
"Score": "1",
"Tags": [
"go",
"interpreter",
"brainfuck"
],
"Title": "Go Brainf*ck Interpreter"
} | 261011 |
<p>I have a fundamental but interesting question.</p>
<p>I have written this python code which checks the payload sent from a specific IoT topic.</p>
<p>First, I would love to get honest feedback and learn how to improve my code to be most efficient, readable, and straightforward.</p>
<p>Second I would like to know whe... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T03:51:53.633",
"Id": "515076",
"Score": "4",
"body": "_Copyright Amazon.com, Inc._ - uh, what? Did you write this code?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T06:02:33.543",
"Id": "515085... | [
{
"body": "<blockquote>\n<pre><code>THINGS_URL_TEST = 'https://some_production_url'\n</code></pre>\n</blockquote>\n<p>The testing URL should not be same as production URL</p>\n<hr />\n<blockquote>\n<pre><code>NO_OF_SECONDS_TO_TEST_SUB_ON_TOPIC = 3\n</code></pre>\n</blockquote>\n<p>Prefer using prefix <code>NUM<... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T00:38:45.127",
"Id": "261013",
"Score": "4",
"Tags": [
"python"
],
"Title": "What's the best practices I ain't using in this code?"
} | 261013 |
<p>I have made a simple contact management in C++.</p>
<p>It's my second project; I'm pretty sure it can be done more better and I could decrease its runtime, but I just joined the C++ community this year. So can you review my code?</p>
<p>It's a CUI-based contact management system through which you can add, delete, ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T06:02:18.527",
"Id": "515084",
"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>Your C++ code is very C-like. This is one of the cases where a class would be an obvious choice to structure your code. However, before that, I would like to point out a few things in your current code.</p>\n<hr />\n<ol>\n<li>The <code>const std::string&& Main</code> should be <code>const ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T03:54:39.917",
"Id": "261015",
"Score": "2",
"Tags": [
"c++",
"beginner"
],
"Title": "Contact management program"
} | 261015 |
<p>As far as I test, there is no any bug point tested. However, I wonder that if there is a problem with the usage of <code>arr.Length</code> or <code>arr.Length - 1</code>.
Further, as to the boundaries like begin <= end with end = mid - 1 or begin < end with end = mid as in the codes.</p>
<p>// size is array le... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T09:04:12.053",
"Id": "515103",
"Score": "0",
"body": "@BCdotWEB is it matter? It is just an algorithm."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T09:31:21.760",
"Id": "515104",
"Score": "... | [
{
"body": "<blockquote>\n<p>As far as I test, there is no any bug point tested.</p>\n</blockquote>\n<p>Well, then you didn't test all of the edge cases, did you?</p>\n<p>Given the array <code>int[] arr = new[] { 1, 2, 3, 4, 5 };</code> I would at least test for the following edge-cases:</p>\n<ul>\n<li>first ite... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T08:29:18.860",
"Id": "261024",
"Score": "-2",
"Tags": [
"c#",
"algorithm",
"binary-search"
],
"Title": "Binary Search Algorithm Difference"
} | 261024 |
<p>I'm programming Tic-Tac-Toe using minimax algorithm with alpha-beta pruning after taking Harvard's CS-50. My logic is working perfectly, except for the return time of minimax (especially on the first call, when only one player played). I was thinking of replacing the extra recursive call of minimax to max/min value.... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T10:01:10.670",
"Id": "261029",
"Score": "4",
"Tags": [
"python",
"tic-tac-toe"
],
"Title": "Minimax algorithm efficiency"
} | 261029 |
<p>I have an endpoint in my RestAPI which can receive 3 optional parameters and then find information in the database with these parameters, also it is possible to combine the parameters. So, in my controller I take a Map<String, Object> which contains these parameters and then pass it to the service level, where... | [] | [
{
"body": "<p>Although it works, the major issue with this approach is its extreme complexity and concreteness. If a new parameter <code>d</code> enters the game, it will became hellish to maintain!</p>\n<p><em>What can be done to improve the current implementation, without changing the approach?</em></p>\n<ul>... | {
"AcceptedAnswerId": "261090",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T10:36:35.897",
"Id": "261031",
"Score": "1",
"Tags": [
"java",
"performance",
"rest",
"spring",
"hibernate"
],
"Title": "Handling multiple optional parameters in Sprin... | 261031 |
<p>this is a kata from codewars, here is the description of the kata:</p>
<p>think of a Quadribonacci starting with a signature of 4 elements and each following element is the sum of the 4 previous, a Pentabonacci (well Cinquebonacci would probably sound a bit more Italian, but it would also sound really awful) with a ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T22:10:51.737",
"Id": "515139",
"Score": "0",
"body": "As a side note - don't use .map() to perform side-effects, use a for loop instead (or .forEach()). You know you're using .map() wrong if you don't use the newly constructed array... | [
{
"body": "<blockquote>\n<p>I think the problem is the slice method but I don't what to use it instead.</p>\n</blockquote>\n<p>It is, but it's not as simple as taking out the <code>slice</code> and using something else in its place, the problem is more fundamental than that.</p>\n<p>This algorithm scales poorly... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T10:59:09.400",
"Id": "261032",
"Score": "1",
"Tags": [
"javascript",
"performance"
],
"Title": "build a Xbonacci function that takes a signature of X elements ,each next element is th... | 261032 |
<p>I am trying to plot heatmap with three variables x, y and z, each with vector length of 932826. The time taken with the function below is 28 seconds, with a bin size of 10 on each x and y. I have been using another program where the same plot happens in 6 - 7 seconds. Also, I know that the plot function of that prog... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T13:33:47.970",
"Id": "515120",
"Score": "0",
"body": "Do you have access to a GPU or to multiples cores to accelerate the execution?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T15:45:20.100",
... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T13:16:10.393",
"Id": "261037",
"Score": "3",
"Tags": [
"python",
"scipy",
"interpolation"
],
"Title": "Speed up interpolation in Python"
} | 261037 |
<p><strong>Write an improved code to identify a valid straight of eight cards</strong>, e.g. <code>4H,5S,AC,7C,8H,AH,0S,JC</code>. Note that the card combination may include Wilds (as we see in our example, with the Ace of Clubs standing in for a Six and the Ace of Hearts standing in for a Nine), but must include at le... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T16:07:22.723",
"Id": "515130",
"Score": "1",
"body": "Could you please clarify what you are looking? Please read [ask]."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-22T15:40:14.023",
"Id": "515166... | [
{
"body": "<p>Good news! There's lots of room for improvement in your code! (How's that for a positive spin?)</p>\n<h1>Counting Aces</h1>\n<pre class=\"lang-py prettyprint-override\"><code> ace = [0 for card in group if card[0] == 'A']\n</code></pre>\n<p>This code creates a list (<code>ace</code>), which o... | {
"AcceptedAnswerId": "261046",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T15:47:16.377",
"Id": "261044",
"Score": "6",
"Tags": [
"python",
"python-3.x"
],
"Title": "Identify valid 8 card poker straight"
} | 261044 |
<p>I'm developing a RPG game and being blocked by the settings of HP(hit points/health points/health power), attack and defense for the characters - Assassin, Tank and Warrior</p>
<p>I'd like to figure out the values so that the Assassin is guaranteed to defeat the Warrior, meanwhile, the Warrior is guaranteed to defea... | [] | [
{
"body": "<p>I would like to mention that this (<code>T > A > W > T</code>) is a very interesting problem to figure out.</p>\n<p>That being said, let me provide my inputs.</p>\n<ol>\n<li><p>Actually <code>super</code> call is necessary when your class <code>extends</code> another class. Why so? Becaus... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T22:21:02.550",
"Id": "261047",
"Score": "3",
"Tags": [
"java",
"algorithm"
],
"Title": "calculations for values that match specified criteria in a limit search space"
} | 261047 |
<p>The Locker Problem is as followed:</p>
<blockquote>
<p>Twenty bored students take turns walking down a hall that contains
a row of closed lockers, numbered 1 to 20. The first student opens all the
lockers; the second student closes all the lockers numbered 2, 4, 6, 8, 10, 12, 14,
16, 18, 20; the third student operat... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-22T18:50:32.547",
"Id": "515193",
"Score": "0",
"body": "Since you've mentioned _Number Theory_, I hope you know that the answer is readily available without `for i in 1..(lockers.len()+1)` loop."
}
] | [
{
"body": "<p>Your code seems fine. However, there is one part I'd definitely change: the scope of variables. For example, <code>lockercount</code> isn't necessary for more than the initial <code>lc</code>. We can keep its scope down:</p>\n<pre><code> println!("How many students?");\n let lc = {... | {
"AcceptedAnswerId": "261077",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-21T23:37:46.447",
"Id": "261050",
"Score": "3",
"Tags": [
"rust"
],
"Title": "Rust Locker Problem Number Theory"
} | 261050 |
<p>The live version is at my <a href="https://github.com/tlatimer/lingoCheater" rel="nofollow noreferrer">github</a></p>
<p>Lingo is a game where the host secretly picks a 5 letter word, then provides the first letter to the player. The player then guesses a word, and the host gives feedback on what letters are right, ... | [] | [
{
"body": "<p>The quality of your code is good.\nYou have a clear consistent style, which looks quite PEP 8 compatible.\nThe one glaring change I'd make is your variables at the top of the file are actually constants.\nAs such the names would be <code>UPPER_SNAKE_CASE</code> if you decide to follow PEP 8 here.<... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-22T01:46:13.493",
"Id": "261053",
"Score": "6",
"Tags": [
"python",
"python-3.x",
"game"
],
"Title": "python wordgame solver in 270 lines"
} | 261053 |
<p>I recently completed the following exercise, but wanted some feedback on how idiomatic etc. my haskell program is. This is from a course which introduces us to file IO before we cover the theory of monads, so my monad-knowledge is still in its infancy. Any feedback much appreciated.</p>
<p>Here's the task:</p>
<bloc... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-22T09:17:58.780",
"Id": "515152",
"Score": "1",
"body": "You can use great http://hackage.haskell.org/package/optparse-applicative library for option parsing."
}
] | [
{
"body": "<p>First things first: great work on adding a type signature on every function. Now, let's see how we can improve the code.</p>\n<p></p>\n<h2>Use interesting case first, others later</h2>\n<p>When we pattern match in a binding or in a <code>case</code> expression, it's often easier to start with the ... | {
"AcceptedAnswerId": "261076",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-22T08:33:02.043",
"Id": "261055",
"Score": "1",
"Tags": [
"haskell"
],
"Title": "Haskell program with basic CLI parsing, file reading, and decoding file contents into specified types"
} | 261055 |
<p>I am writing a credit card generator. I have method <code>GenerateVisa()</code> who will return either a 13 or 16 numbers string.
This is the default value but GenerateVisa can also take a parameter. THis parameter will allow us to force the output to either 13 or 16.
What is this parameter? I could use a int like <... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-22T09:58:41.117",
"Id": "515155",
"Score": "0",
"body": "Hi Aloisdg - the others aren't \"VISA\" - perhaps the generate visa method shouldn't be creating them??"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-... | [
{
"body": "<p>You may need to have a class for each card type, and an abstract class that would be shared between them.</p>\n<p>from the Wikipedia page, I can see each card can have <code>Name</code>, <code>IIN Range</code> , <code>Active</code>, <code>Length</code> and <code>Validation</code>. Now, from there ... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-22T08:39:31.047",
"Id": "261056",
"Score": "-1",
"Tags": [
"c#",
"f#"
],
"Title": "What would be this best way to show that my function can accept some specific numbers as input?"
} | 261056 |
<p>I have been working on porting my PowerShell 7 scripts to Python 3.9.5 lately, re-implementing the same logic in a different programming language, keeping what makes it work and removing unnecessary parts, improving the code, and this is one of the scripts that has been re-implemented.</p>
<p>The code is simple, an... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T05:03:54.303",
"Id": "518742",
"Score": "0",
"body": "Have you seen https://stackoverflow.com/questions/6841333/why-is-subtracting-these-two-times-in-1927-giving-a-strange-result or https://youtu.be/-5wpm-gesOY? While useful for lea... | [
{
"body": "<p>This is a good approach you have done if you have to skip <code>datetime</code> module.</p>\n<p>There are many more cultures that you have not added but that's different topic.</p>\n<p>First, I will answer your question related to command line argument. NO there is <a href=\"https://stackoverflow.... | {
"AcceptedAnswerId": "261080",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-22T09:41:33.833",
"Id": "261059",
"Score": "1",
"Tags": [
"python",
"beginner",
"python-3.x",
"datetime"
],
"Title": "Python code to find difference between two dates"
} | 261059 |
<p>I have a list of path I want to filter out. I want to keep only paths matching a specific pattern and remove all paths matching another specific pattern.</p>
<p>To achieve this I pattern matched on each pattern. Here is the code:</p>
<pre><code>let stringToSpan (s: string) =
System.ReadOnlySpan<char>(s.ToC... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-22T13:46:42.173",
"Id": "515161",
"Score": "0",
"body": "Please follow the guidelines: https://codereview.stackexchange.com/help/how-to-ask"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-01T22:37:33.683",
... | [
{
"body": "<p>Lets focus on <code>filterByPattern</code>.</p>\n<p>A Predicate is a function returning a boolean (<code>'T -> bool</code>). Since the predicate host most of the logic, lets start by spliting the Predicate from the filter to work on it.</p>\n<pre><code>let patternPredicate (includePattern: stri... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-22T10:04:01.167",
"Id": "261060",
"Score": "2",
"Tags": [
"f#",
"pattern-matching"
],
"Title": "How to refactor the boolean logic of this F# function?"
} | 261060 |
<p>If we apply outward curving, inward curving, and no curving at all, <strong>individually</strong> to each of the 4 corners of the rectangle, we get next 81 variations:</p>
<p><a href="https://i.stack.imgur.com/62Clz.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/62Clz.gif" alt="Rounded rectangles... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-22T14:20:09.167",
"Id": "261067",
"Score": "1",
"Tags": [
"performance",
"algorithm",
"assembly",
"graphics",
"x86"
],
"Title": "81 variations of the rounded rectangle"
} | 261067 |
<p>I have recently come across a use case where I need to lump many maps into a single container. These maps can have different combinations of key/value types, but they all differ from one another.</p>
<p>For a certain set of key types <code>Key1, Key2, ...</code> and value types <code>Val1, Val2,...</code> the obviou... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-22T16:14:24.643",
"Id": "515172",
"Score": "0",
"body": "Can you add some test code that gives examples of how this is used? And include some details on why you're using (shared) pointers to maps internally, rather than just storing th... | [
{
"body": "<p>This looks quite good already, and it's an interesting problem to solve. However, I'll first try to give some arguments why you perhaps shouldn't, and then mention some things that could be improved.</p>\n<h1>Encapsulation</h1>\n<blockquote>\n<p>but this doesn't scale well for many maps, as if we ... | {
"AcceptedAnswerId": "261098",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-22T15:19:31.093",
"Id": "261069",
"Score": "1",
"Tags": [
"c++",
"c++17",
"collections",
"template-meta-programming"
],
"Title": "A multi key/value type \"folded\" map class ... | 261069 |
<p>I have written a function that takes as input a list of 5 numbers, then the program's goal is to return the largest drop in the list. It is important to understand that [5, 3, ...] is a decrease of 2 and that [5, 20, .....] is a decrease of 0. In short, a decrease can only be from left to right and the largest decre... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-22T16:40:17.500",
"Id": "515174",
"Score": "2",
"body": "Welcome to Code Review! – The site standard is for the title to simply state the task accomplished by the code, not your concerns about it. Please see [How do I ask a good questi... | [
{
"body": "<p>This can be solved in a single pass, e.g., O(n).</p>\n<p>For each temperature, subtract it from the highest temperature seen so far to get the drop. Keep track of the largest drop. Also update the highest temperature.</p>\n<pre><code>def biggest_drop(temperatures):\n highest = temperatures[0]... | {
"AcceptedAnswerId": "261085",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-22T15:31:21.323",
"Id": "261070",
"Score": "3",
"Tags": [
"python",
"algorithm",
"comparative-review",
"complexity"
],
"Title": "Find the largest decrease in a sequence of nu... | 261070 |
<p>I work with a charity that does a number of jobs, more than 100, less than 1000 a year. Jobs are identified with a year, and an up to 3 digit serial number, so <code>2021#123</code> for instance.</p>
<p>I'm writing a Python report program to pull jobs out of our database, and I'd like be be able to specify ranges of... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-27T09:51:43.213",
"Id": "515589",
"Score": "0",
"body": "I changed the title so that it's a bit more specific. Please check that I haven't misrepresented your code, and correct it if I have."
},
{
"ContentLicense": "CC BY-SA 4... | [
{
"body": "<p>This isn't so much a Python question as it is a RegEx question. The Python tag is almost irrelevant.</p>\n<h1>'+' -vs- '*'</h1>\n<p>You regex includes two alternates:</p>\n<ul>\n<li><code>(?:20\\d\\d#\\d{1,3}(?:,\\d{1,3})+)</code></li>\n<li><code>(?:20\\d\\d#\\d{1,3})</code></li>\n</ul>\n<p>The d... | {
"AcceptedAnswerId": "261073",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-22T16:01:42.407",
"Id": "261072",
"Score": "4",
"Tags": [
"python-3.x",
"regex"
],
"Title": "Regex to match several slightly different strings"
} | 261072 |
<p>I've been creating a math engine in C++. I have decided now is a good time to ask for feedback from the community. Right now the main "good" things it has is complex numbers, calculus and a fraction class. I am planning to add set theory sometime in the future, although I don't know how useful it would be ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-23T12:27:12.650",
"Id": "515232",
"Score": "1",
"body": "A comment, because it is really out of scope here. But you might want to look into things like [cln](https://www.ginac.de/CLN/), [ginac](https://www.ginac.de/), [singular](https:... | [
{
"body": "<h1><code>using namespace std</code></h1>\n<p>Given that you're using <code>template</code> and declare your <code>class</code>, you're working in a header-only library. However, you should <em><strong>never</strong></em> use <code>using namespace</code> in header. Not only <a href=\"https://stackove... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-22T19:45:02.007",
"Id": "261078",
"Score": "8",
"Tags": [
"c++",
"mathematics"
],
"Title": "A math engine with support for complex numbers, calculus, and fractions"
} | 261078 |
<p>I have a bash script that fixes or creates, and syncs the asciidoc attributes and yaml header for blog posts. It does what it is supposed to. But notice I have put <code>sleep</code> commands in between the <code>sed -i</code> insert commands. This is because I was getting unusual error messages such as:</p>
<pr... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T07:13:00.880",
"Id": "515281",
"Score": "1",
"body": "This question could be improved by showing a simple set of inputs and outputs, so we can replicate your results. It looks like your code has been mis-copied somehow - a lot of l... | [
{
"body": "<blockquote>\n<pre><code>export sectnumlevels=2 \nexport toc="true" \nexport includedir="include"\n</code></pre>\n</blockquote>\n<p>It's not clear why any of these need to be exported</p>\n<blockquote>\n<pre><code>[[ -z "$1" ]] && { echo "need a file&q... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-22T20:46:22.037",
"Id": "261083",
"Score": "1",
"Tags": [
"bash",
"sed"
],
"Title": "Bash script syncronizing yaml and asciidoc headers using sed"
} | 261083 |
<p>This Program is a simple phonebook, user is given 3 choice, add a number to the phone book, dial a number or exit the program. Are there Any Improvements that i can make, either efficient or cleaning the code or something useful i can add?</p>
<pre><code>import java.util.ArrayList;
import java.util.Scanner;
public ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T21:33:15.423",
"Id": "515454",
"Score": "1",
"body": "I have rolled back Rev 2 → 1. Please see [_What to do when someone answers_](https://codereview.stackexchange.com/help/someone-answers)."
}
] | [
{
"body": "<p>These are my suggestions:</p>\n<ol>\n<li>No need to invoke <code>print</code> before <code>task</code> in main. At that point, the numbers would be empty anyway.</li>\n<li>Better to declare numbers as : <code>List<String> numbers = new ArrayList<>();</code> (interface name on the left ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-23T05:18:01.423",
"Id": "261089",
"Score": "2",
"Tags": [
"java",
"array"
],
"Title": "Java Simple Phonebook"
} | 261089 |
<p>There is a personal program of mine which logs in, scrape links and then download them. The downloader part is based on <code>Youtube-dl</code> and I think it's a smell code. Is there any way to improve this code?</p>
<pre><code>import requests
import subprocess
import getpass
import time
from bs4 import BeautifulSo... | [] | [
{
"body": "<h1>Issues</h1>\n<p>The first one is the use of the <code>or</code> operator. If you wish to compare a variable with two values, you will have to write the comparison operator twice.\nFor instance,</p>\n<pre class=\"lang-py prettyprint-override\"><code>if Login_ == 'y' or 'Y':\n ...\n</code></pre>\n... | {
"AcceptedAnswerId": "261114",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-23T09:49:26.080",
"Id": "261096",
"Score": "1",
"Tags": [
"python",
"python-3.x",
"web-scraping"
],
"Title": "Simple download manager based on Youtube-dl"
} | 261096 |
<p>I have a contact model, on change I set the state of the <code>contact</code> object, how can I make the below function more readable?</p>
<p>The <code>address</code> field is different because it's an object: <code>['address', 'city', 'state', 'zip']</code></p>
<pre><code> const onFieldChange = (
key,
inde... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-23T16:49:33.003",
"Id": "515250",
"Score": "2",
"body": "I don't see anything that can be improved in your code. In particular I don't see any repetition or any other boring code. Splitting the code into several smaller functions would... | [
{
"body": "<p>You can do :</p>\n<pre><code> const onFieldChange = (\n key,\n index = 0,\n isMulti = false,\n isAddress = false\n ) => event => {\n const value = event.target.value\n const updatedContact = {...contact}\n if (!isMulti) {\n updatedContact[key] = value\n }\n ... | {
"AcceptedAnswerId": "261113",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-23T09:56:56.253",
"Id": "261097",
"Score": "0",
"Tags": [
"javascript",
"react.js"
],
"Title": "Set state on field change"
} | 261097 |
<p>I'm very new to programming and I decided to start my journey with Python. It's my fifth day of learning and decided to try myself out and make a very simple slot machine. I was stuck for hours because I had issues with the balance counter but finally managed to make it work.</p>
<p>Would you please rate it or give ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T06:56:53.930",
"Id": "515278",
"Score": "0",
"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>All your <code>win1</code>, <code>win2</code> and <code>win3</code> functions are essentially the same. When you have multiple functions/pieces of code that are nearly identical, look at what parts of them are the same, and what parts are different. Make the identical parts the body of a function,... | {
"AcceptedAnswerId": "261103",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-23T13:37:04.433",
"Id": "261101",
"Score": "3",
"Tags": [
"python",
"beginner"
],
"Title": "Slot-machine balance counter"
} | 261101 |
<p>This is my attempt at simulating an eco system.
Basically this thing is suppost to simulate how an eco system works.
Its not the most accurate thing but it's something.
Let me know what you think about it.</p>
<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
namespace Ecosystemsimulatio... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-23T18:52:45.223",
"Id": "515258",
"Score": "2",
"body": "One quick tip: be consistent with your casing. Should have \"HasEaten\", \"GenerateRandomBool\", \"hasAlreadyEaten\" and there are others that seem a bit haphazard. Read https://... | [
{
"body": "<p>The biggest code smell I see is repeated enumeration of the same collection multiple times in a row, except you are actually creating copies for no good reason (more on this later).</p>\n<p>Try to find a way to change your design to require enumerating a collection the least amount of times possib... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-23T17:06:38.520",
"Id": "261107",
"Score": "-1",
"Tags": [
"c#",
"object-oriented"
],
"Title": "C# oop eco system simulation"
} | 261107 |
<p>I made a 52 standard deck generator for practicing my C#. Just to let you know I am using the unity editor.</p>
<p>I would your feedback as to whether my code is good/bad or whatever you may desire.</p>
<pre><code>using System;
using System.Collections.Generic;
using UnityEngine;
public class Standard52Deck {
L... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-26T18:29:17.413",
"Id": "515555",
"Score": "0",
"body": "Comments are not for extended discussion; the conversation has been [moved to chat](https://chat.stackexchange.com/rooms/124723/discussion-on-question-by-mr-banks-c-standard-52-c... | [
{
"body": "<p>You have nicely read the rank count into the variable <code>rankCount</code>, but later, you are writing <code>index % 13</code>. It is not immediately clear where this number comes from. Use the variable there too.</p>\n<p>Since these numbers never change and are well known for a 52-card deck, yo... | {
"AcceptedAnswerId": "261110",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-23T17:10:09.387",
"Id": "261108",
"Score": "11",
"Tags": [
"c#",
"unity3d"
],
"Title": "C# - Standard 52 card deck"
} | 261108 |
<p>This is a follow-up question for <a href="https://codereview.stackexchange.com/q/260576/231235">Android APP connect to FTP server in Java</a>. I am attempting to create a tiny FTP host manager with <code>FTPHostProfile</code> class and <code>FTPHostProfiles</code> class.</p>
<p><strong>The experimental implementatio... | [] | [
{
"body": "<p>Important caveat: I know nothing about the Special Android coding conventions that are different from vanilla java.</p>\n<h2>General</h2>\nIt's preferable to use lowercase letters for acronyms in class names. `FtpHostProfile` is easier to read than `FTPHostProfile`.\n<p>Classes which have not been... | {
"AcceptedAnswerId": "261120",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-23T17:21:02.090",
"Id": "261109",
"Score": "1",
"Tags": [
"java",
"multithreading",
"android",
"networking",
"ftp"
],
"Title": "Android APP FTP host profile class impleme... | 261109 |
<p>I'm constructing a homework from my Spring Boot Course and so far I did the JPA layer and want to have some feedback, before start the business rules, about if the I could improve something or change a type of relationship in my app. Any suggestions will be welcome.</p>
<p>Here is the exercise:</p>
<p>"Assume w... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T11:46:24.103",
"Id": "515300",
"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": "<p>Welcome to code review! I have some comments about the data structure from banking point of view.</p>\n<ul>\n<li>Users usually have more than one account.</li>\n<li>E-mail is not a unique identifier.</li>\n<li>The assumption that <a href=\"https://www.kalzumeus.com/2010/06/17/falsehoods-programmer... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-23T19:43:15.347",
"Id": "261115",
"Score": "2",
"Tags": [
"java",
"spring",
"jpa"
],
"Title": "Bank exercise with Java Spring Boot and JPA"
} | 261115 |
<p>I'm making a snake game for practicing the MVC pattern and also going out of my comfort zone (I'm in data processing / data science, mostly procedural coding)</p>
<p>The game is available in <a href="https://nabla-f.github.io/" rel="nofollow noreferrer">https://nabla-f.github.io/</a></p>
<p>This is a classical snake... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T11:02:01.547",
"Id": "515293",
"Score": "1",
"body": "The code provided in question does nothing. Please provide a working copy of the code you wish reviewed in the question. (linking a repo does not count as reviewable code as it i... | [
{
"body": "<p>I do not pretend to be true like uncle Bob :)</p>\n<p>However, I think your case you have to separate your controllers on main and another different.</p>\n<p><strong>preparation</strong></p>\n<p>app.js</p>\n<pre><code>const boardDrawerController = BoardDrawer(new BoardModel(), new BoardDrawerView(... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T01:05:13.810",
"Id": "261121",
"Score": "1",
"Tags": [
"javascript",
"object-oriented",
"mvc",
"snake-game"
],
"Title": "Snake game MVC (Vanilla JS) - Help separating concerns... | 261121 |
<p><strong>Question:</strong>
Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string "".</p>
<p>Example :</p>
<pre><code>Input: strs = ["flower","flow","flight"]
Output: "fl"
</c... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T23:32:55.433",
"Id": "515360",
"Score": "0",
"body": "You should look into the Trie data structure and fine tune it to your needs. The Trie data structure is used in applications such as spell check and your cell phone’s text word s... | [
{
"body": "<h3>1. Don't think too much about performance.</h3>\n<p>Worst performance problems arise because the coder <em>thought</em> something could be faster but she didn't consider that the JVM does runtime optimizations for her code.</p>\n<p>So always prefer writing <strong>readable code that works</strong... | {
"AcceptedAnswerId": "261130",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T07:03:51.490",
"Id": "261125",
"Score": "3",
"Tags": [
"java",
"strings"
],
"Title": "Longest common prefix for set of strings"
} | 261125 |
<h2>Description</h2>
<p>This is my attempt at writing a wrapper around Microsoft's research API (<em>evaluate</em> endoint).</p>
<p>My goals were:</p>
<ol>
<li>learn how to write classes</li>
</ol>
<ul>
<li>does it look ok overall?</li>
<li>should all methods except for <code>download_publications</code> and <code>save... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T07:49:44.813",
"Id": "261127",
"Score": "0",
"Tags": [
"python",
"object-oriented",
"api"
],
"Title": "Microsoft Academic API wrapper"
} | 261127 |
<p>I understand there is <a href="https://codereview.stackexchange.com/questions/222292/character-picture-grid-exercise-automatetheboringstuff">another question</a> on this already, however this is what I coded and wanted to know if this would raise any red flags?</p>
<p>Regarding the Character picture exercise located... | [] | [
{
"body": "<p>It's wasteful to use <code>range()</code> and then only use the result for indexing.</p>\n<p>Instead, just iterate directly over the values:</p>\n<pre><code>for col in range(len(grid[0])):\n for row in grid:\n print(row[col],end='')\n print()\n</code></pre>\n<p>We can simplify, though... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T08:22:45.130",
"Id": "261128",
"Score": "2",
"Tags": [
"python",
"beginner",
"python-3.x"
],
"Title": "Automate The Boring Stuff - Character Picture Grid"
} | 261128 |
<p>I and Abishek Joshi forked a repo, and improved a lot of code in it and published it, we did that because that original repo was last commited on 2020 december.
For more info on history you can visit the <a href="https://github.com/Readme-Workflows/recent-activity#history" rel="nofollow noreferrer">repo readme's his... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T11:28:40.193",
"Id": "261131",
"Score": "0",
"Tags": [
"node.js"
],
"Title": "A recent activity github action written in node.js"
} | 261131 |
<p>I'm testing here ways to find prime number. But it looks weird because of repeating parts. Are there any options to make it prettier. Probably I should use cycle or wrap it in an interface.</p>
<pre><code> start = System.nanoTime();
res = PoKrestyanski.letsUseit(numbers);
duration = (System.na... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-26T18:48:11.327",
"Id": "515556",
"Score": "0",
"body": "You're not measuring execution time. You're measuring setup time and JVM warmup time. Take a look at this [Stack Overflow question and answers](https://stackoverflow.com/questi... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T11:52:56.067",
"Id": "261132",
"Score": "1",
"Tags": [
"java"
],
"Title": "I'm testing here ways to find prime number. But it looks weird because of repeating parts"
} | 261132 |
<p>I am trying to implement a cache which can be persisted. Also, some of the functions that I am trying to cache takes arguments that are not python objects (external library objects). But they seem to have a <code>hash</code> value. My first try was to use <code>lru_cache</code> but it didn't have an option to persis... | [] | [
{
"body": "<p>It seems rather inefficient to reload the cache file on every cache miss. The last part of <code>wrapper()</code> saves the file whenever the cache is updated, so the cache and file should always be in synch. Loading the file could be moved into <code>outer()</code>.</p>\n",
"comments": [],
... | {
"AcceptedAnswerId": "261158",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T12:04:39.460",
"Id": "261133",
"Score": "4",
"Tags": [
"python",
"python-3.x",
"cache"
],
"Title": "Python persistant cache for non-pythonic objects"
} | 261133 |
<p>I am attaching the code here. I am very new to VBA and trying to do a complex calculation using Macro. Please help me improve the speed of the attached code. The code works fine and produces the end output. The program is intended to do the following. I am calling the below two subs after data is filled in the sheet... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T13:24:55.407",
"Id": "515305",
"Score": "0",
"body": "Did you post the whole code, or did you post too much ? I don't see where CF_RH_NG is actually used in this code."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDat... | [
{
"body": "<p>As best I can tell, <code>Sub CF_Amb_Pr_NG()</code> sets cells <code>C2</code> and <code>C3</code> to formulas that changes with each iteration through the loop, then ends with them set to <code>"=R1539C2"</code>.</p>\n<p>You then copy cell <code>E2</code> to each row in column <code>D</... | {
"AcceptedAnswerId": "261141",
"CommentCount": "10",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T12:35:26.487",
"Id": "261135",
"Score": "0",
"Tags": [
"performance",
"beginner",
"vba",
"excel",
"macros"
],
"Title": "Improving Speed of VBA Code - Copy/paste two s... | 261135 |
<p>Time ago I had a header implemented with a Bootstrap carousel: You know, something like this:</p>
<pre><code><div class="carousel">
<div class="item"><img src="pic1.jpg"></div>
<div class="item"><a href="example.com"><im... | [] | [
{
"body": "<h2>Yes hacky!</h2>\n<p>This is very hacky as you are doing a media query the long way. Interpreting the resulting media aware DOM for a URL that you then manually parse.</p>\n<h3>Learn and use the API</h3>\n<p>There are many API's available to a modern browser environment. The general rule is if it ... | {
"AcceptedAnswerId": "261149",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T12:57:05.220",
"Id": "261137",
"Score": "3",
"Tags": [
"javascript",
"html"
],
"Title": "How to have <picture> elements with different links on each image?"
} | 261137 |
<p>I am learning numpy, pandas, and sklearn for machine learning now. My teacher gives me code like below, but I guess it is ugly. This code is for splitting the data into training set and testing set, and later we could manipulate the entire data or just training/testing set by the <code>[True, False, True, False ... ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T09:35:00.373",
"Id": "515392",
"Score": "0",
"body": "[Cross-posted at Stack Overflow](https://stackoverflow.com/q/67671132/1014587)"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T12:38:03.377",
... | [
{
"body": "<p><strong>Inspired by Gulzar at Stackoverflow.</strong></p>\n<p>I do not realize it works until after a night's sleep.</p>\n<p><strong>So, below is enough:</strong></p>\n<pre class=\"lang-python prettyprint-override\"><code>offset_orig = range(m)\noffset_train, offset_test = train_test_split(offset_... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T13:02:35.757",
"Id": "261139",
"Score": "0",
"Tags": [
"python",
"numpy",
"pandas"
],
"Title": "Get a \"train or test\" slicing elegantly after splitting"
} | 261139 |
<p>I want to calculate the intersection point, in time, of 2 or 3 moving averages.</p>
<p>To solve this problem I decided to transform the moving average(ma) data into geometrical lines and calculate the intersection point via the formula for lines in the slope/intercept form.</p>
<p>X coordinate is the unix timestamp ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T13:05:27.530",
"Id": "261140",
"Score": "0",
"Tags": [
"go"
],
"Title": "Calculate intersection point of 2 or 3 moving averages"
} | 261140 |
<p>Link to full problem description: <a href="https://www.codewars.com/kata/534e01fbbb17187c7e0000c6" rel="nofollow noreferrer">https://www.codewars.com/kata/534e01fbbb17187c7e0000c6</a></p>
<p>My code:</p>
<pre><code>def spiralize(size):
def get_change_values():
change_x = 0
change_y = 0
if... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T15:51:52.653",
"Id": "515334",
"Score": "6",
"body": "Please embed the problem description in the body of the question. Links can be broken."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-27T12:51:22.21... | [
{
"body": "<p>Without changing your algorithm we can make your code simpler in a few places. I'd say the algorithm is quite sensible, I would've chosen the same approach.</p>\n<hr />\n<p><strong>Comments and docstrings</strong></p>\n<p>Providing some comments here and there and explaining the general algorithmi... | {
"AcceptedAnswerId": "261148",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T15:01:18.277",
"Id": "261145",
"Score": "4",
"Tags": [
"python",
"algorithm"
],
"Title": "Codewars: Make a spiral"
} | 261145 |
<p>I have an enumerable source for which I do not know how big it is. I want to select a random element from it, without having to hold the whole collection in memory and with uniform distribution. I read about the reservoir sampling algorithm, and created a simple implementation for the very basic case where the reser... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T16:03:27.193",
"Id": "515336",
"Score": "2",
"body": "Welcome to the Code Review Community. Please include the code from entire class/program in the question since there is only one more function, this will help us understand what t... | [
{
"body": "<p>Let me try another answer.</p>\n<p>Background info: <a href=\"https://en.wikipedia.org/wiki/Reservoir_sampling\" rel=\"nofollow noreferrer\">Wikipedia Reservoir Sampling</a>.</p>\n<p>The intro header to the Wikipedia link states:</p>\n<blockquote>\n<p>The size of the population <em><strong>n</stro... | {
"AcceptedAnswerId": "261164",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T15:16:28.057",
"Id": "261146",
"Score": "3",
"Tags": [
"c#",
"random"
],
"Title": "Reservoir Sampling of an enumerable collection of unknown size"
} | 261146 |
<p>How can this code be improved by "closuring" of functions here?</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="true">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>// Your code here.
let countBs = countChar();
fun... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T17:35:50.827",
"Id": "515343",
"Score": "0",
"body": "Welcome to Code Review! Did you take this code from [the book](https://eloquentjavascript.net/2nd_edition/03_functions.html#h_3rsiDgC2do) or is this code that you wrote? If you w... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T17:15:06.290",
"Id": "261151",
"Score": "2",
"Tags": [
"closure"
],
"Title": "Make better solution for Bean counting example from \"Eloquent JavaScript\" book"
} | 261151 |
<p>I have method that fetches all orders from Database and filtering, sorting that data(I know better to do It by specific query to Database but I dont know how).
I have Order entity that has following</p>
<pre><code>public class Order {
private int orderId;
private int userId;
private int carId;
privat... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T17:56:10.423",
"Id": "515347",
"Score": "1",
"body": "Maybe you want to have a look at Javas [Streams-API](https://docs.oracle.com/javase/tutorial/collections/streams/). Also you might want to distinguish between foreward and revers... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T17:39:06.900",
"Id": "261152",
"Score": "3",
"Tags": [
"java",
"linked-list",
"database",
"stream"
],
"Title": "How can I filter and sort LinkedList faster and more effective?... | 261152 |
<p>Here is the code for the game :</p>
<pre><code>#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
using std::vector;
using std::cout;
using std::cin;
using std::endl;
using std::time;
using std... | [] | [
{
"body": "<p>I think there's quite a lot to improve, especially the first point I mention below. Consider updating your code according to the suggestions and then creating a new review question on Code Review.</p>\n<h1>Use proper names and spelling</h1>\n<blockquote>\n<p>I know some functions have childish nam... | {
"AcceptedAnswerId": "261161",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T18:27:44.587",
"Id": "261155",
"Score": "6",
"Tags": [
"c++",
"algorithm",
"game",
"vectors",
"connect-four"
],
"Title": "Improving C++ Connect-four game with little A... | 261155 |
<p>My .bash_aliases file contains several aliases.
In the beginning, when I wanted to see the aliases, I print the .bash_aliases file,</p>
<p>The output wasn't readable at all, so I created a python script to make it better.
To call my python script, I use the alias <code>print_aliases_manual</code></p>
<p>What is the ... | [] | [
{
"body": "<p><strong><code>print</code></strong></p>\n<p>f-Strings are a great and convenient tool for including variables and calculations in strings. I'd say they're generally not needed when printing only variables. For example</p>\n<pre><code>print(f'{bcolors.WARNING}{line}{bcolors.ENDC}')\n</code></pre>\n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T22:28:45.050",
"Id": "261163",
"Score": "7",
"Tags": [
"python",
"python-3.x"
],
"Title": "Python script that make my .bash_aliases file MUCH more readable and clear"
} | 261163 |
<p>I've made this script to automate blocking some deviant hosts on my router, and was curious if there's anything much else that can be done to make it quicker and more efficient.</p>
<p>Presently I'm restricted to using packages available on the <a href="https://bin.entware.net/armv7sf-k3.2/Packages.html" rel="nofoll... | [] | [
{
"body": "<p>We're missing a shebang line. The question is tagged <a href=\"/questions/tagged/bash\" class=\"post-tag\" title=\"show questions tagged 'bash'\" rel=\"tag\">bash</a>, but that seems overkill, since there's nothing here that's not standard POSIX shell.</p>\n<pre><code>#!/bin/sh\n</code></... | {
"AcceptedAnswerId": "261180",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T22:53:21.837",
"Id": "261165",
"Score": "3",
"Tags": [
"bash",
"linux",
"shell",
"sh"
],
"Title": "The Blacklist: Blocking Malicious domains using Bash"
} | 261165 |
<p>I am here to ask for some more experienced programmers to critique my first project. I wanted to see where I lack and what I can improve on. Thank you for taking time out of your day to help me better my skills as a programmer! I hope I did a good job for being a beginner but I know there is much more to learn!</p>
... | [] | [
{
"body": "<p>You need to add exception handling in player_choice. Currently, if I type in 'Y', the game crashes with error code:</p>\n<pre><code>Traceback (most recent call last):\n File "/Users/jake/Documents/TTRreview.py", line 299, in <module>\n place_marker(game_board, player2, player_c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T01:01:02.697",
"Id": "261169",
"Score": "9",
"Tags": [
"python",
"tic-tac-toe"
],
"Title": "Python: Tic Tac Toe Game"
} | 261169 |
<p>Is there any room for improvement, in terms of simplicity and efficiency?</p>
<pre><code>from random import randint
class Dice():
def __init__(self):
"""Making a dice instance with 6 sides."""
self.sides = 6
class Roller(Dice):
def __init__(self,name,age):
... | [] | [
{
"body": "<ol>\n<li><code>Roller</code> should not inherit from <code>Dice</code>, as <code>Roller</code> represents a human. Humans being a sub-class of <code>Dice</code> is pretty unintuitive. Rather, <code>Roller</code> should have an attribute: <code>self.dice = Dice()</code></li>\n<li>There's no particula... | {
"AcceptedAnswerId": "261201",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T07:53:57.657",
"Id": "261177",
"Score": "3",
"Tags": [
"python",
"performance",
"python-3.x"
],
"Title": "Dice rolling program which also counts and stores the result"
} | 261177 |
<p>Hmm, I know this has been implemented countless times, and Python 3.9.5 <code>math</code> standard library has a built-in <code>gcd()</code> method that does exactly this, but this is how I do this, I think completing simple programming challenges using new ways will let gain experience that will help me find ingeni... | [] | [
{
"body": "<p>It's more common to use <a href=\"https://en.wikipedia.org/wiki/Euler_method\" rel=\"nofollow noreferrer\">Euler's method</a> to find GCD, rather than factorising both numbers. However, I'll continue reviewing with the existing algorithm, as there's useful insights to be found.</p>\n<hr />\n<p>Fi... | {
"AcceptedAnswerId": "261182",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T08:24:37.533",
"Id": "261179",
"Score": "3",
"Tags": [
"python",
"beginner",
"python-3.x",
"programming-challenge",
"mathematics"
],
"Title": "Python code to find grea... | 261179 |
<p>Hi I was just asked by stackoverflow to move this question into this forum (<a href="https://stackoverflow.com/questions/67685433/how-to-design-the-react-component-properly">https://stackoverflow.com/questions/67685433/how-to-design-the-react-component-properly</a>).</p>
<p>Hi I am pretty new to react and I want to ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T10:17:25.183",
"Id": "515394",
"Score": "1",
"body": "Please follow the guidelines: https://codereview.stackexchange.com/help/how-to-ask"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T13:55:01.443",
... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T10:00:10.090",
"Id": "261181",
"Score": "1",
"Tags": [
"react.js"
],
"Title": "What is the best way to pass an argument from one subcomponent to other subcomponent?"
} | 261181 |
<p>I wrote a Pi Calculator using the BBP Algorithm in Cython. My specific goals are make the code more legible and more performant. This is a purely academic script in order to teach me how to implement complex algorithms with arbitrary precision (so no monetary gain, it's not homework, but is a personal goal). I have ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-26T12:59:26.747",
"Id": "515515",
"Score": "0",
"body": "I fixed my breaking gmpy2 by compiling gmp, mpfr, mpc, and gmpy2 from source. I should note that I had to ensure I used python3 and not python when performing the gmpy2 install. ... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T10:24:46.297",
"Id": "261183",
"Score": "5",
"Tags": [
"python",
"performance",
"beginner",
"reinventing-the-wheel",
"cython"
],
"Title": "Pi Calculator Using BBP (Bailey–... | 261183 |
<h2>Please review this code</h2>
<p>I have written a function to find the successor of BST in c. It takes three arguments, i.e root pointer to the binary search tree, node value of which we have to find a successor and parent pointer (for first call it is also root pointer. It will return an integer that is the success... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T11:54:20.563",
"Id": "515398",
"Score": "4",
"body": "Do you have a test program that drives this? It is easier to review if we can compile and run for ourselves, and for that we need a definition of `BSTNode`."
},
{
"Conte... | [
{
"body": "<p><strong>Missing return</strong></p>\n<p>Code may even fail the last <code>rt == INT_MAX</code> and then no return is specified.</p>\n<pre><code> if (rt == INT_MAX)\n return parent_node -> data;\n\n // Missing return.\n }\n</code></pre>\n<p><strong>Use <code>const</code></strong></p>\n<p>U... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T11:16:12.543",
"Id": "261185",
"Score": "0",
"Tags": [
"algorithm",
"c",
"binary-search",
"binary-search-tree"
],
"Title": "Finding inorder successor of a BST in C"
} | 261185 |
<p>I have recently started to work with C++ and I do consider myself quite basic in C++ coding.</p>
<p>I have made the following two functions and I was wondering whether someone could give me some hints on how to improve and speed up this code.</p>
<p>Please, note that the second function is then used in <code>R</code... | [] | [
{
"body": "<p>Don't write <code>using namespace std;</code>.</p>\n<p>The constants including <code>pi</code> are provided in a standard header already. If you did need to define a constant, use <code>constexpr</code>.</p>\n<pre><code>double deltaa;\nif (k == 0) {\n deltaa = 1;\n } else {\n ... | {
"AcceptedAnswerId": "261207",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T13:39:17.420",
"Id": "261186",
"Score": "1",
"Tags": [
"c++",
"performance",
"rcpp"
],
"Title": "The average amount of time required to travel between two points in a torus-li... | 261186 |
<p>I am implementing a fixed point type, which mostly is used to be able store numbers as multiples of some base (power of 2). Apart from that, the type should be able to replace double/float values without the need of modifying some code. In its current implementation only basic arithmetic operations are possible but ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T14:22:25.107",
"Id": "515413",
"Score": "0",
"body": "Do you know about the \"spaceship\" operator? Which C++ dialect is this targeting?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T14:31:51.963",... | [
{
"body": "<blockquote>\n<p>I want most binary functions (operator+, etc...) to be compatible with two fixed objects, as well with one fixed object and one built-in arithmetic type - e.g. fixed + fixed, fixed + int, int + fixed. This currently leads to a lot of code duplication which I would like to get rid of.... | {
"AcceptedAnswerId": "261189",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T14:09:32.577",
"Id": "261187",
"Score": "3",
"Tags": [
"c++",
"c++14",
"fixed-point"
],
"Title": "Fixed Point Type"
} | 261187 |
<p>I am new to python, and developing a moderate application for which I need to setup a logging mechanism.</p>
<p>The below program sets up log handling, which gives the user an option to specify whether log rotation is required or not.</p>
<p>The rest is my application. The code is mostly written in terms of function... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T15:12:56.227",
"Id": "515417",
"Score": "2",
"body": "Welcome to Code Review! When you state \"_Rest all is my application_\" does that mean it is all a [R.E.S.T.](https://en.wikipedia.org/wiki/Representational_state_transfer) appli... | [
{
"body": "<p><strong><code>is_file_exist</code></strong></p>\n<p>This function basically follows the pattern</p>\n<pre><code>if condition:\n return True\nelse:\n return False\n</code></pre>\n<p>If <code>type(condition) == bool</code>, this pattern can always be simplified to</p>\n<pre><code>return condit... | {
"AcceptedAnswerId": "261208",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T14:25:36.083",
"Id": "261188",
"Score": "8",
"Tags": [
"python",
"beginner",
"python-2.x"
],
"Title": "log setup using RotatingFileHandler and basicConfig"
} | 261188 |
<p>This is a follow-up question for <a href="https://codereview.stackexchange.com/q/260989/231235">Android APP User class implementation</a>. I am attempting to create a password strength assessment class which is named <code>PasswordStrengthAssessment</code> in Java. Instead of adding "111111", "123123&... | [] | [
{
"body": "<h2>Test Harness</h2>\n<p>Your question presents a main activity that seems to act as a test harness for a particular case 'dogggg'. If the common password list has been downloaded then 'dogggg' is weak, if it hasn't then it's not. This is OK if you are just trialling something, however it makes re... | {
"AcceptedAnswerId": "261215",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T16:02:53.553",
"Id": "261195",
"Score": "1",
"Tags": [
"java",
"object-oriented",
"android",
"error-handling",
"classes"
],
"Title": "Android APP Password Strength Ass... | 261195 |
<p>I wanted to implement a short and functional brainfuck interpreter with minimal code repetition. It uses a little bit of macro magic, and does nested loops iteratively rather than using a cache, but it seems to do fine for most tasks I've given it.</p>
<p>One of my goals was to use the absolute minimum in external l... | [] | [
{
"body": "<blockquote>\n<p>One of my goals was to use the absolute minimum in external libraries</p>\n</blockquote>\n<p>Why? It's going to make your code slower in all likelihood, it's not helping you learn the standard libraries, and it's making your code longer, more complex and less legible. There is no win... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T17:17:36.350",
"Id": "261197",
"Score": "3",
"Tags": [
"c",
"brainfuck"
],
"Title": "Simple Brainfuck Interpreter Implementation in C"
} | 261197 |
<p>I am new to python and I am trying to write a function with various actions based on the parameters sent. I am checking if the data has valid format then it publishes to /accepted otherwise to /rejected. If the data is fine then it does the function and then publishes to /success otherwise to /failure</p>
<p>Here is... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T17:27:40.010",
"Id": "515430",
"Score": "1",
"body": "It would be nice to see this used in a `__main__` context where example input is given. There are a lot of questions around this, like \"What is `client`?\" If your entire progra... | [
{
"body": "<p>Given that there isn't much here to analyse purely based on performance since we don't know what those other function calls do, here are some minor changes:</p>\n<pre class=\"lang-py prettyprint-override\"><code>def data_handler(message, topic):\n try:\n logging.debug(f'Invoked on topic ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T17:18:51.110",
"Id": "261198",
"Score": "2",
"Tags": [
"python",
"performance"
],
"Title": "Better way to structure and optimise try except statements"
} | 261198 |
<blockquote>
<p>Follow-up from <a href="https://codereview.stackexchange.com/questions/261165/the-blacklist-blocking-malicious-domains-using-bash">this question</a> using @Toby Speight's answer:</p>
</blockquote>
<p>The primary concern is <code>jq</code> improvement/optimization, but please detail any others.</p>
<pre ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-26T15:44:16.213",
"Id": "515537",
"Score": "0",
"body": "Please refrain from modifying the code. After getting an answer you are not allowed to change your code anymore. This is to ensure that answers do not get invalidated and have to... | [
{
"body": "<p>Don't use a <code>for</code> loop to iterate over program output. See <a href=\"http://mywiki.wooledge.org/BashFAQ/001\" rel=\"nofollow noreferrer\">http://mywiki.wooledge.org/BashFAQ/001</a></p>\n<p>Try this -- extract the keys, urls, rules all at once:</p>\n<pre class=\"lang-sh prettyprint-overr... | {
"AcceptedAnswerId": "261206",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T17:19:25.877",
"Id": "261199",
"Score": "0",
"Tags": [
"linux",
"shell",
"sh"
],
"Title": "The Blacklist - follow-up"
} | 261199 |
<p>I'm brushing up on Python, working my way through <a href="https://www.manning.com/books/python-workout" rel="noreferrer">Python Workout</a>. One of the exercises is to emulate the Python zip() function, assuming each iterable passed to the function is of the same length. Here's what I've come up with:</p>
<pre><cod... | [] | [
{
"body": "<p>You should not apply <code>len</code>, because that requires that the first argument be at least as strong as a <code>Collection</code>, when <code>zip</code> should not need that guarantee and should only need <code>Iterable</code> which is a weaker type.</p>\n<p>Gathering results in memory can b... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T17:56:32.013",
"Id": "261202",
"Score": "6",
"Tags": [
"python",
"reinventing-the-wheel"
],
"Title": "Emulating Python zip() Function"
} | 261202 |
<p>I am trying to implement a basic hash table using a list of tuples. The code produce the desired output. Please help me improve my code as I feel there are a lot of while loops.</p>
<pre><code>#global variables to keep track of the hash table
count = 0
size = 1000
def hash_table(size):
return [None] * size
... | [] | [
{
"body": "<p>Despite the code produce the desired output in your simple test case, your implementation is quite flawed.</p>\n<pre class=\"lang-py prettyprint-override\"><code>a = hash_table(size)\n\ninsert_hash(a, 1, 'john')\ninsert_hash(a, 2, 'edward')\ndelete_hash(a, 1)\nprint_hash(a, 2)\n</code></pre>\n<p>O... | {
"AcceptedAnswerId": "261213",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T17:59:28.057",
"Id": "261204",
"Score": "2",
"Tags": [
"python",
"reinventing-the-wheel",
"hash-map"
],
"Title": "Implementing hash table in Python using Tuples"
} | 261204 |
<blockquote>
<p>This is a follow-up to <a href="https://codereview.stackexchange.com/q/261089/120114">this phonebook code</a>.</p>
</blockquote>
<p>This Phone Book allows the user to Enter a value between 1-3.</p>
<p>Entering 1 lets the user Add a number to the phone book, when the process is finished, the user is aske... | [] | [
{
"body": "<h2>Conventions</h2>\n<p>Following language conventions can make your code more approachable to other people. Java methods follow <code>camelCase</code>, so <code>CallNumber</code> should be <code>callNumber</code> etc. More naming conventions <a href=\"https://www.oracle.com/java/technologies/java... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T21:44:34.047",
"Id": "261211",
"Score": "2",
"Tags": [
"java",
"object-oriented",
"static"
],
"Title": "PhoneBook in Java - follow-up"
} | 261211 |
<p>I am really new to React and I worked on some challenges. I need to mention I did most of the stuff on my own without much dependence on the internet beside what functions do. I'd like to know if I did something wrong in regard to code structure and if there are better ways to achieve what I did.</p>
<p>The purpose ... | [] | [
{
"body": "<p>you can make this part of code a little bit shorter, before:</p>\n<pre><code>const [firstName, setFirstName] = useState("");\nconst [lastName, setLastName] = useState("");\nconst [email, setEmail] = useState("");\n\nconst onFirstNameChange = (event) => {\n setFi... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T21:58:23.657",
"Id": "261212",
"Score": "3",
"Tags": [
"beginner",
"react.js",
"jsx"
],
"Title": "Simple registration form with validation"
} | 261212 |
<p>This program will get data from a folder called Data which has txt files and will return the filename with a score but I don't think it's really good.</p>
<p>Can I get any kind of feedback on this program. Is there anyway this can be written in a better way or something that should be added to?</p>
<pre><code>import... | [] | [
{
"body": "<p>For <code>nltk</code>, <code>default_download_dir</code> is <code>PYTHONHOME\\lib\\nltk</code> on Windows or <a href=\"https://www.nltk.org/api/nltk.html#nltk.downloader.Downloader.default_download_dir\" rel=\"nofollow noreferrer\">one of various</a> <code>/usr</code> directories, falling back to ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-25T23:20:08.663",
"Id": "261216",
"Score": "3",
"Tags": [
"python",
"python-3.x"
],
"Title": "Simple Search Engine Program in Python"
} | 261216 |
<p>I was doing the following exercise:</p>
<blockquote>
<p>Create an algorithm which asks the user a number from 1 to 7, and each number represents a day on the week. For example, 1 represents Sunday, 2 represents Monday and so on. The user will type this number and the program will show them the name of the day on the... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-26T15:29:58.447",
"Id": "515536",
"Score": "1",
"body": "@gnasher729 You're welcome to add an answer saying so."
}
] | [
{
"body": "<p>It's great that you're thinking about classes, but you've misapplied them. This is a very simple problem that does not call for object-oriented code. The <code>calendar</code> module already has the name sequence, so you really only need a validation loop and a small output routine:</p>\n<pre><cod... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-26T00:57:30.057",
"Id": "261219",
"Score": "9",
"Tags": [
"python",
"beginner",
"datetime"
],
"Title": "Simple day-of-week program"
} | 261219 |
<p>need some help or advice, HackerRank's <a href="https://www.hackerrank.com/challenges/frequency-queries" rel="nofollow noreferrer">frequency-queries</a> challenge,
the challenge of this Hackerrank problem is to check if the frequencies of number in your data structure matches the queries.</p>
<p>small integer values... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-26T04:07:18.457",
"Id": "515473",
"Score": "5",
"body": "[Edit] the question to include a brief summary of the problem that the code solves."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-26T14:36:04.793",... | [
{
"body": "<h1>Performance of <code>std::map</code></h1>\n<p>Well, looking up in a map is a slow operation.</p>\n<pre><code>if(map[value] > 1){\n map[value]--;\n</code></pre>\n<p>is looking up the same thing twice. Don't do that with maps!</p>\n<p>You could write:</p>\n<pre><code>auto& v= map... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-26T02:34:24.120",
"Id": "261223",
"Score": "-2",
"Tags": [
"c++",
"performance",
"programming-challenge",
"time-limit-exceeded"
],
"Title": "HackerRank frequency queries"
} | 261223 |
<p>I am a newbie to JS and I am working on a FizzBuzz challenge. Below is what I have tried. Essentially when the function takes a value then it would iterate from 1 up to the value and an array would result.</p>
<p>I am seeking advice on adding conditional checking such as:</p>
<ol>
<li>If the value of <code>n</code> ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-26T11:34:21.503",
"Id": "515506",
"Score": "1",
"body": "Welcome to CodeReview. I voted to close because this code does not work at all, `fizzBuzz(20)` returns `undefined`. Also Fizz is every 3, not every 4."
},
{
"ContentLicen... | [
{
"body": "<blockquote>\n<p>I am hoping to seek advice on adding conditional checking such as: 1) if the value n is less than 4, it will return the string: "Please insert a value greater than or equal to 4" and 2) if the function is passed no value, it should return an empty array. I am not sure where... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-26T03:50:21.347",
"Id": "261224",
"Score": "0",
"Tags": [
"javascript",
"beginner",
"fizzbuzz"
],
"Title": "Fizz Buzz function that returns an array"
} | 261224 |
<p>I'm learning the file system library and thought nothing could be better than a project, so I thought of recreating the basic Linux commands such as <code>ls</code>, <code>cd</code> etc using C++ and <code><filesystem></code>.</p>
<p>As I said, I'm learning C++ and exploring libraries, so there could be weird ... | [] | [
{
"body": "<blockquote>\n<pre><code> std::cout << "\\033[32m" << path << "\\033[0m";\n</code></pre>\n</blockquote>\n<p>Please don't do that - not all the world is an ANSI terminal.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 4.0",
"Creat... | {
"AcceptedAnswerId": "261243",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-26T04:35:59.947",
"Id": "261228",
"Score": "1",
"Tags": [
"c++",
"beginner",
"file-system"
],
"Title": "Basic Linux filesystem commands"
} | 261228 |
<p>I have a data frame that has several columns, one of which contains html objects (containing tables). I want a column of table arrays.</p>
<p>My problem is that this piece of code takes a long time to run. Is there any way I can optimize this? I tried list comprehension, which doesn't significantly improve run time.... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-26T06:34:21.183",
"Id": "515478",
"Score": "4",
"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... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-26T06:00:06.063",
"Id": "261230",
"Score": "0",
"Tags": [
"python",
"performance",
"html",
"pandas",
"iteration"
],
"Title": "How do I make my html object-to-table array scri... | 261230 |
<p>Looking a way to reduce the below code to get comma separated values from the list of arrays
By using ECMA or plain old vanilla JS. How should we achieve this?</p>
<p><strong>Actual Array Data:</strong></p>
<pre><code>[{
ansBook: "046H",
ansPersonId: "2044000102",
bookNbr: "046H&... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-31T06:45:37.323",
"Id": "515931",
"Score": "0",
"body": "Consider one single `reduce` instead of the 5 `map` calls."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-31T13:56:51.353",
"Id": "515970",
... | [
{
"body": "<p>Honestly, structure-wise, your code seems pretty good. I've just got a handful of minor code-cleanup suggestions:</p>\n<ul>\n<li>Use <code>===</code> instead of <code>==</code>, <code>==</code> does some magical type coercion, and can create unexpected results.</li>\n<li>You've got some unenesary ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-26T07:16:43.427",
"Id": "261231",
"Score": "0",
"Tags": [
"javascript",
"array",
"typescript",
"join"
],
"Title": "Simplifying the array of objects with comma separated values"
} | 261231 |
<p>Here is a code I experimented with recently:</p>
<pre class="lang-hs prettyprint-override"><code>let br = [0]:[n:(concat $ take n br) | n <- [1..]] in concat br
</code></pre>
<p>This code produces the <a href="https://oeis.org/A007814" rel="nofollow noreferrer">binary rule</a> <code>0 1 0 2 0 1 0 3 ...</code></p>... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-27T16:24:20.213",
"Id": "515624",
"Score": "0",
"body": "Re Edit 2: The python version should be `yield 0 \\n for b...: yield b+1 \\n yield 0`"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-27T16:42:38.520... | [
{
"body": "<p>I would use an <code>interleave</code> helper:</p>\n<pre class=\"lang-hs prettyprint-override\"><code>interleave :: [a] -> [a] -> [a]\ninterleave (x:xs) ys = x : interleave ys xs\n\nbinaryRule :: [Integer]\nbinaryRule = interleave [0,0..] (map (+ 1) binaryRule)\n</code></pre>\n<p>Or golfed: ... | {
"AcceptedAnswerId": "261248",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-26T08:01:35.480",
"Id": "261233",
"Score": "2",
"Tags": [
"haskell",
"lazy"
],
"Title": "How can I make a shorter binary rule in haskell?"
} | 261233 |
<p>I would like to transform my <code>dataframe</code> into an array of fixed-sized chunks from each unique segment. Specifically, I would like to transform the <code>df</code> to a list of <code>m</code> arrays each sized <code>(1,100,4)</code>. So at last, I would have an <code>(m,1,100,4)</code> array.</p>
<p>Since ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-26T13:04:01.710",
"Id": "515516",
"Score": "2",
"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... | [
{
"body": "<p>Your code appears to be quadratic in the number of groups. Each call to <code>np.concatenate()</code> allocates enough memory to hold the new array and then copies the data. The first group is copied the first time through the loop. Then the first and second groups on the second time. Then the fi... | {
"AcceptedAnswerId": "261294",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-26T12:46:29.807",
"Id": "261239",
"Score": "4",
"Tags": [
"python",
"performance",
"python-3.x",
"array",
"numpy"
],
"Title": "Dataframe transformation to numpy ndarray t... | 261239 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.