body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>The query below already has indexes based its execution plan but it is still under performant with larger datasets. Are the additional null checks needed and why? Do you see anything that can be done to optimize the overall execution time? The execution plans shows clustered index seeks and no additional indexes are... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-02T02:32:55.210",
"Id": "529716",
"Score": "0",
"body": "Does your indentation actually look like that? That's rather odd."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-02T02:37:24.760",
"Id": "529717... | [
{
"body": "<p>"Are the additional null checks needed and why?" Nobody knows, only you know about the data. We don't know if these checks are needed or not. They may be useless and slowing you down.</p>\n<p>It's hard to advise without knowing the data, and the table structure and what indexes are alrea... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-02T00:21:20.210",
"Id": "268583",
"Score": "-2",
"Tags": [
"sql",
"sql-server",
"t-sql"
],
"Title": "T-SQL Query Performance"
} | 268583 |
<p>Features:</p>
<ul>
<li>messages formatted with clear borders</li>
<li>errors sent to stderr</li>
<li>colour handling</li>
<li>colours can be included in other strings <code>echo</code>ed to the screen without having to use the <code>-e</code> option</li>
<li>the desired colour can be either a string or a function</l... | [] | [
{
"body": "<p>Make a string <code>str</code> full of spaces with the length of variable <code>a</code>:</p>\n<pre><code>printf -v str "%*s" ${#a} " "\n# or\nstr="${a//[^ ]/ }*"\n</code></pre>\n<p>I don't like the feature that you can have 2 different kind of parameters (string or f... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-02T01:53:55.610",
"Id": "268587",
"Score": "1",
"Tags": [
"bash",
"console",
"formatting",
"ascii-art"
],
"Title": "Colour message prettifier in Bash"
} | 268587 |
<h4>Overview</h4>
<p>I've created an asynchronous and recursive method of generating word squares, of any size (known as the order of the square), from a known word list. If you're unfamiliar with <a href="https://en.wikipedia.org/wiki/Word_square" rel="nofollow noreferrer">word squares</a>:</p>
<blockquote>
<p>A word ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T07:25:59.113",
"Id": "529816",
"Score": "0",
"body": "Does your implementation work as expected? (except from performance perspective)"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T20:41:11.943",
... | [
{
"body": "<h4>Algorithm</h4>\nIt is always better to start out with a <s>good</s> decent algorithm before we try to optimize by vectorizing etc. Let’s look at what we need to do.<br><br>\n<ol>\n<li><p>Iterate through all the words (List<string>)<br>\nFor every word in the dictionary we can start with a ... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-02T13:38:08.060",
"Id": "268593",
"Score": "3",
"Tags": [
"c#",
"performance",
"recursion",
"async-await"
],
"Title": "Asynchronous and recursive word square generator in C#"
} | 268593 |
<p>I have written a function that gives the number of hashes present in a Merkle Mountain Range proof. Using Solidity, this function can be written as:</p>
<pre class="lang-solidity prettyprint-override"><code>function getMmrProofSize(uint32 index, uint32 n) private pure returns (uint8) {
// if n is a power of 2
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-03T07:29:04.590",
"Id": "529773",
"Score": "1",
"body": "Please find where questions about mechanisms are [on-topic](https://stackoverflow.com/help/on-topic): [Which computer science / programming Stack Exchange sites do I post on?](ht... | [
{
"body": "<p>The function returns a <code>ceiledLog2</code> of an eventual <code>n</code>, <em>plus</em> the number of times it has been called until it reaches that eventual <code>n</code>. This observation leads to a simple iterative rewrite (please pardon my <a href=\"/questions/tagged/c\" class=\"post-tag\... | {
"AcceptedAnswerId": "268602",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-02T14:06:55.640",
"Id": "268594",
"Score": "0",
"Tags": [
"performance",
"recursion",
"bitwise",
"solidity"
],
"Title": "Recursive function that gives the number of hashes pr... | 268594 |
<p>I’m new to coding, and for my first project I’m working on a calculator that takes coordinate labels and metric components as input and outputs non-zero components of a number of other tensors (technically Christoffel symbols aren’t components of a tensor, they’re just elements of an array disguised as a tensor).</p... | [] | [
{
"body": "<p>I've <a href=\"https://codereview.stackexchange.com/a/267744/25834\">said it before</a> and I'll say it again: you need to stop asking your user for markup that's non-standard and goes through an undocumented blender. Ask for Sympy-format expressions, period. I suspect that one of the reasons you ... | {
"AcceptedAnswerId": "268662",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-02T14:28:55.157",
"Id": "268595",
"Score": "2",
"Tags": [
"python",
"sympy",
"latex"
],
"Title": "Calculate general relativity-related tensors/arrays using metric tensor as input... | 268595 |
<p>I created a computer program which takes a list of names and dishes chosen. The program then counts how many dishes and which dish are ordered. The result is then returned from a function. The algorithm is currently a brute force O(N*M) where N is the number of dishes and M is the number of people. Below is the code... | [] | [
{
"body": "<ul>\n<li>Add PEP484 typehints</li>\n<li>Don't count things yourself when <code>Counter</code> exists and is more suitable for the task</li>\n<li><code>rows</code> is ignored, so drop it from your arguments list</li>\n<li>Your assertions, main guard and function structure are pretty good; keep it up!... | {
"AcceptedAnswerId": "268600",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-02T14:57:33.393",
"Id": "268596",
"Score": "2",
"Tags": [
"python-3.x"
],
"Title": "Counting Restaurant Orders"
} | 268596 |
<pre><code>function postFetch(data) {
let element = document.getElementById('placetoputlist');
element.innerHTML = "";
for (let priority of data.priority_list) {
element.innerHTML += "<h1>" + priority + "</h1>";
element.innerHTML += "<ul>";
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-03T01:46:48.767",
"Id": "529771",
"Score": "0",
"body": "I would rename the variables to what they are doing for the business logic, instead of `placetoputlist` i would rename it as `listForTasks` or whatever makes most sense for the t... | [
{
"body": "<p>A couple of good points to start out:</p>\n<ul>\n<li>You use <code>for..of</code> loops... great!</li>\n<li>You use <code>fetch</code>... great!</li>\n</ul>\n<p>Suggestions for improvement:</p>\n<h3>Naming</h3>\n<p>JS uses <code>snakeCase</code>, not <code>snake_case</code>. It's OK to use <code>s... | {
"AcceptedAnswerId": "268607",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-02T21:10:11.120",
"Id": "268605",
"Score": "2",
"Tags": [
"javascript",
"html"
],
"Title": "A javascript script to load a list into a HTML page"
} | 268605 |
<p>I have a bunch of code that adds the string representation of members in a class to a List.</p>
<pre><code>using System.Collections.Generic;
using System.Linq.Expressions;
...
//Note: AuthModel is a custom class containing Id, Name, UserName, email, etc...
var someProperties = new List<string>();
somePropertie... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-03T05:50:24.927",
"Id": "529772",
"Score": "1",
"body": "[nameof expression](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/nameof)"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-... | [
{
"body": "<p>one way is you can use anonymous type like this :</p>\n<pre><code>public static string[] GetMemberName<T>(Expression<Func<T, object>> memberAccess)\n{\n var body = (NewExpression) memberAccess.Body;\n return body.Members.Select(x=> x.Name)?.ToArray();\n}\n</code></pre>\n... | {
"AcceptedAnswerId": "268609",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-03T04:56:10.520",
"Id": "268608",
"Score": "0",
"Tags": [
"c#",
"lambda"
],
"Title": "Simplify this code that adds string representation of class members to a List"
} | 268608 |
<p>Classic <a href="https://en.wikipedia.org/wiki/Pointer_jumping" rel="nofollow noreferrer">pointer jumping</a> algorithm summarizing values from an array adapted to run on a GPU instead of a PRAM.</p>
<p>Read about <a href="https://www.khronos.org/api/opencl" rel="nofollow noreferrer">openCL</a> and <a href="https://... | [] | [
{
"body": "<p>While pointer-jumping may be applied to arrays, it is rather intended for linked-lists. For arrays <a href=\"http://www.mathcs.citadel.edu/rudolphg/csci495/f15/Ike-GPU-Lesson.pdf\" rel=\"nofollow noreferrer\">parallel reduction algorithm</a> is better suited as it takes advantage of constant acces... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-03T11:48:43.193",
"Id": "268612",
"Score": "1",
"Tags": [
"java",
"multithreading",
"concurrency",
"opencl"
],
"Title": "pointer jumping on a GPU using Aparapi"
} | 268612 |
<p>I'm new to using JS for anything other than DOM manipulation, so I'm not sure if the following code is taking full advantage of the Async concept in JS.</p>
<p>This is an example of a function I'm writing in my Discord.js bot project. The function checks for new RSS feed items from a given URL and then calls another... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-03T12:35:09.540",
"Id": "529783",
"Score": "0",
"body": "Welcome to Code Review. Does the code produce the correct output?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-03T12:41:00.737",
"Id": "529784... | [
{
"body": "<p>The way you wrote your call to <code>DataService.UpdateLastChackDate()</code> makes it appear like there was some coding error that happened. Arrow functions take an expression-only body as its return value. Writing it this way makes it seem like we're awaiting for <code>DataService.UpdateLastChac... | {
"AcceptedAnswerId": "268652",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-03T11:58:51.317",
"Id": "268613",
"Score": "2",
"Tags": [
"javascript",
"promise",
"discord"
],
"Title": "Check RSS feed and post to Discord"
} | 268613 |
<p>I have the following problem. I want to write a class that handles events and passes it through but reduce its number if there recently was an event. Basically it is debounce. However there is a slight change that if we don't receive events for a while and the latest event was skipped we want to emit this event.</p>... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T07:30:06.883",
"Id": "529817",
"Score": "1",
"body": "Have you done some kind of profiling, for example via [CodeTrack](https://www.getcodetrack.com/)?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T... | [
{
"body": "<p>Using the following function to test, 62% of your CPU usage is used by <code>DateTime.Now</code> and 15% by <code>Timer.Change</code></p>\n\n<pre class=\"lang-cs prettyprint-override\"><code>static void Main()\n{\n var throttle = new Throttle();\n for (int index=0; index < int.MaxValue; i... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-03T12:11:49.060",
"Id": "268614",
"Score": "3",
"Tags": [
"c#",
"timer"
],
"Title": "Timer for event throttling"
} | 268614 |
<p>My application is an insight/statistic application that contains a lot of data. I don't need to do any <code>joins</code> as everything is in one table, and still, when the results are even about 100k-300k, it takes a lot of time to load.</p>
<p>The server side is fine as it has 4CPUs and 8 memory and they are intel... | [] | [
{
"body": "<p>This is difficult to answer without knowing more information (e.g. your schema).</p>\n<ul>\n<li>Have you tried an <a href=\"https://guides.rubyonrails.org/active_record_querying.html#running-explain\" rel=\"nofollow noreferrer\">SQL EXPLAIN</a> to understand where the bottleneck is?</li>\n<li>Do y... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-03T12:25:15.173",
"Id": "268615",
"Score": "0",
"Tags": [
"ruby-on-rails",
"database",
"active-record"
],
"Title": "Ruby on Rails - Optimizing a query for a huge database"
} | 268615 |
<p>I'm creating a schema design for a user profile and transactions.</p>
<p>I am very new in data modeling and currently this is my design. The schema has multiple <code>deposit</code> table because the application I'm working on will use different <code>payment gateways</code> for money transfer and their transaction ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-03T13:44:28.543",
"Id": "529789",
"Score": "0",
"body": "In addition to your diagram, can you show the full SQL defining your tables?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-03T13:56:15.393",
"I... | [
{
"body": "<p>The correct data model often depends on the use-cases that you want to support. Looking at your model there are several questions that spring to mind, which you might want to consider.</p>\n<ul>\n<li>There's a 1:1 mapping between <code>user</code> and <code>profile</code>, what are you trying to a... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-03T12:46:14.297",
"Id": "268617",
"Score": "7",
"Tags": [
"sql",
"mysql"
],
"Title": "Schema design for user profile and transaction"
} | 268617 |
<pre class="lang-py prettyprint-override"><code>import math
num_rows = int(input())
if num_rows % 2 != 0:
upper_mid = math.ceil(num_rows/2)
lower_mid = num_rows//2
#prints upper normal triangle
for row in range(0, upper_mid):
for col in range(upper_mid-1, row, -1):
... | [] | [
{
"body": "<p>Calling <code>print</code> is very slow, you should focus on building strings then have one print. Fortunately Python has some really nice string manipulation options.</p>\n<blockquote>\n<pre class=\"lang-py prettyprint-override\"><code>for col in range(upper_mid-1, row, -1):\n print(end="... | {
"AcceptedAnswerId": "268627",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-03T18:10:12.393",
"Id": "268625",
"Score": "10",
"Tags": [
"python",
"python-3.x",
"ascii-art"
],
"Title": "Printing a diamond shape in ASCII"
} | 268625 |
<p>I wrote a program that takes a string as standard input and checks if the words in the string are in the scrabble dictionary, then checks each letter of the words and gives back the the score of the words based off of what they would be worth in scrabble. The program is supposed to be written using various STL conta... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-03T20:42:44.920",
"Id": "529807",
"Score": "0",
"body": "Is the word list sorted? Your `std::find` is doing a linear search thru your vector. One alternative is a Trie."
}
] | [
{
"body": "<h1>Use the right STL containers</h1>\n<p>Searching for an entry in a <code>std::vector</code> of words with <code>std::find()</code> is going to be very slow, as it just checks against each item in the list. A much better option is to use a <a href=\"https://en.cppreference.com/w/cpp/container/unord... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-03T19:52:44.910",
"Id": "268628",
"Score": "4",
"Tags": [
"c++"
],
"Title": "program that takes string and outputs number of scrabble words and the score for each scrabble word"
} | 268628 |
<p>I am playing with a <a href="https://pchemguy.github.io/SQLite-ICU-MinGW/stdcall" rel="nofollow noreferrer">custom-built</a> SQLite library intending to access it from VBA via the C-language API. I keep the library within the project folder, so I load it via the LoadLibrary API. To make the load/unload process more ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T10:16:06.870",
"Id": "529822",
"Score": "2",
"body": "In your examples could you please include when and how you call the free methods, and how you might be using this class in conjunction with the code to actually call into the loa... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-03T22:15:37.093",
"Id": "268630",
"Score": "3",
"Tags": [
"object-oriented",
"vba"
],
"Title": "VBA class managing loading DLL libraries"
} | 268630 |
<p>This is LeetCode question 118 Pascal's triangle.</p>
<blockquote>
<p>Given an integer numRows, return the first numRows of Pascal's triangle.</p>
</blockquote>
<p>There is an example.</p>
<blockquote>
<p>Input: numRows = 5</p>
<p>Output: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]</p>
</blockquote>
<p>I am interested ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T08:42:59.660",
"Id": "530555",
"Score": "0",
"body": "To mark the most useful answer accepted, click the green mark to the left of the answer's post."
}
] | [
{
"body": "<p>as far as I know, there is no solution so far on generating <code>Pascal's Triangle</code> in a single loop or doing it without a loop. (unless of course if the results are hard coded, which is impossible).</p>\n<p>For the <code>Pascal's Triangle</code> there are two basic rules :</p>\n<ul>\n<li>E... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T02:27:57.687",
"Id": "268635",
"Score": "0",
"Tags": [
"c#",
"array"
],
"Title": "Time complexity of generating Pascal's triangle"
} | 268635 |
<p>I have made a tiny Android-project to familiarize myself with user input validation.</p>
<p>The app just has an EditText-control for user input, a button "Compute Result" and a TextView, which shows the result. As input is an integer expected.</p>
<p>The essential part of the code:</p>
<pre><code>buttonCo... | [] | [
{
"body": "<p>There's already a <code>CharSequence.isNotEmpty()</code> function in the Kotlin standard library, so you could have used that instead of <code>!TextUtils.isEmpty(strInput)</code>. But you don't even need to check if it's empty when you're using <code>toIntOrNull()</code>. It will return null if th... | {
"AcceptedAnswerId": "268647",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T05:01:36.683",
"Id": "268637",
"Score": "0",
"Tags": [
"android",
"kotlin"
],
"Title": "Android user input validation"
} | 268637 |
<p>I wired up a Gear Shift Indicator for my dad's car to display what gear it is currently in, and showing changes with animations (sliding up and down as appropriate, with a few bonus ones for fun at car shows).</p>
<p>Security is not really a concern due to its localised nature, but I'd like to release the code for o... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T16:11:53.350",
"Id": "529846",
"Score": "0",
"body": "Does the compiler support `constexpr`? Generally, I would suggest changing the global `const` values to `constexpr`."
},
{
"ContentLicense": "CC BY-SA 4.0",
"Creatio... | [
{
"body": "<h1>About your concerns</h1>\n<blockquote>\n<p>The application is not critical to the vehicle's function</p>\n</blockquote>\n<p>Indeed, the vehicle will function fine without it, but consider that a person is driving in the vehicle, and making decisions based on what your gear shift indicator shows. ... | {
"AcceptedAnswerId": "268724",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T06:43:02.813",
"Id": "268638",
"Score": "4",
"Tags": [
"c++",
"performance",
"error-handling",
"formatting",
"arduino"
],
"Title": "Gear Shift Indicator using Hall Eff... | 268638 |
<p>I am trying to create a code for the Basic evapotranspiration equation by Hargreaves. I have attached a screenshot of the equation to be replicated.
<a href="https://i.stack.imgur.com/ScK16.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ScK16.png" alt="Hargreaves equation" /></a></p>
<p>I want to create a... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T03:55:00.457",
"Id": "529908",
"Score": "3",
"body": "I have concerns about the accuracy of that math (fixed year durations?), but that's a separable issue and I'll have to assume that you need an implementation faithful to this ref... | [
{
"body": "<p>I wonder if there is a need for a class here? It seems <code>class Hargreaves</code> has no responsibilities and is solely used to compute the evapotranspiration value based on the inputs provided in the constructor. Should a function be used instead?</p>\n<pre class=\"lang-py prettyprint-override... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T07:24:02.597",
"Id": "268639",
"Score": "8",
"Tags": [
"python",
"python-3.x",
"object-oriented",
"python-2.x",
"classes"
],
"Title": "Calculate evapotranspiration"
} | 268639 |
<p>I want to check with Javascript if a week number (with year) is within two other week numbers.</p>
<p>Example data: <code>Year-Week</code> <code>startDate: 2020-32</code> <code>endDate: 2021-52</code> <code>checkDate: 2021-30</code>.
In this case checkDate is within the two years.</p>
<p>How do I make Javascript kno... | [] | [
{
"body": "<p><strong>Logic</strong></p>\n<p>Your logic is not entirely correct, consider the following arguments:</p>\n<pre><code>startYear: 2001\nstartWeek: 10\nendYear: 2002\nendWeek: 5\ncheckYear: 2001\ncheckWeek: 15\n</code></pre>\n<p><code>checkYear === startYear</code> is true, but <code>checkWeek <= ... | {
"AcceptedAnswerId": "268642",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T08:26:05.857",
"Id": "268641",
"Score": "8",
"Tags": [
"javascript"
],
"Title": "Check if calendar week number falls within two other week numbers"
} | 268641 |
<p>I am writing a function that will retrieve the name of a certain record defined as a <code>u32</code>, I wanted to make the function filter the record code first in macro classes and descending to the string value I am looking for.<br />
I wrote the code as below and it works, but I would like to know if there was a... | [] | [
{
"body": "<p>(Not acquainted to Rust.) You have a class range code and an individual event code.</p>\n<ul>\n<li><p>One could give both a string name, and concatenate them with "_" between.\nThis would remove some redundancy. It could be done in the event code "get my class name."</p>\n</li>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T09:53:18.487",
"Id": "268643",
"Score": "1",
"Tags": [
"rust"
],
"Title": "Find record name from an hexadecimal record code value using bitwise \"and\""
} | 268643 |
<p>I made a generic decorator in C++20 with concept for specialization. The idea is to be able to define only one function in the decorator to decorate all functions in a class.</p>
<p>You may <a href="https://godbolt.org/z/96ss7beGa" rel="nofollow noreferrer">try it</a> (it's a bit long to insert here and it's better ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T14:19:50.343",
"Id": "529840",
"Score": "1",
"body": "@G.Sliepen I just insert the code in the question. Source code of godbolt link are immutable but I understand the need to insert the code in the question."
}
] | [
{
"body": "<h1>Answers to your questions</h1>\n<blockquote>\n<ul>\n<li>How can I get rid of the huge <code>enum</code> that has all possible names of functions?</li>\n</ul>\n</blockquote>\n<p>Instead of putting everything in one <code>enum</code>, you can just have an arbitrary number of types. Instead of check... | {
"AcceptedAnswerId": "268661",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T12:47:27.967",
"Id": "268645",
"Score": "1",
"Tags": [
"c++",
"design-patterns",
"c++20"
],
"Title": "Generic decorator inspired by functional programming"
} | 268645 |
<p>The main objective of this bot to make fast and reliable automatic subscriptions to email newsletter for people, who filled the website form(submissions go to google sheet)</p>
<p>I had too many requests to google docs.(rate limit error) -> so i added sleep 5 after every subscription. Also added break into email-... | [] | [
{
"body": "<h2>Exceptions</h2>\n<p>Using <code>except Exception</code> to ignore exceptions without knowing the exact causes is often not a great idea. It makes it hard for someone unfamiliar with the code to tell what kinds of exceptions are expected, and also means that when things go wrong in unexpected ways... | {
"AcceptedAnswerId": "268702",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T14:42:07.500",
"Id": "268650",
"Score": "1",
"Tags": [
"python",
"api",
"google-sheets"
],
"Title": "Check Google Sheet for emails, verify delivery by api and Subscribe via ap... | 268650 |
<p>I have put together this small application that uses the <strong><a href="https://jsonplaceholder.typicode.com/" rel="nofollow noreferrer">JSONPlaceholder</a> API</strong> and Vue.js.</p>
<p>The application crosses users and posts and displays the <em>posts by user</em> (author):</p>
<p><div class="snippet" data-lan... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T17:26:17.413",
"Id": "268657",
"Score": "0",
"Tags": [
"javascript",
"vue.js"
],
"Title": "Vue and JSONPlaceholder application"
} | 268657 |
<h1>Problem Description</h1>
<p>I am building a library that helps me building TUI Apps more faster, for example printing TUI Menus and other components. I would like to get feedback on my design decisions to see if I'm properly following SOLID principles.</p>
<p>To solve this scenario while trying to follow the princi... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T18:51:00.507",
"Id": "529874",
"Score": "1",
"body": "Can `UIMenuPrinter` be a static class? Then: `MenuPrinter.Print( thisMenu );`. Keeping a reference to the menu is not necessary."
},
{
"ContentLicense": "CC BY-SA 4.... | [
{
"body": "<p>Here are my observations:</p>\n<h3><code>UIMenu</code></h3>\n<ul>\n<li>Try to use consistent naming\n<ul>\n<li>Your current naming: <code>Title</code>, <code>MenuRows</code>, <code>AppendLine</code></li>\n<li>Suggested naming #1: <code>Title</code>, <code>Items</code>, <code>AddItem</code></li>\n<... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T17:51:33.503",
"Id": "268659",
"Score": "3",
"Tags": [
"c#",
"object-oriented",
"console"
],
"Title": "Print a Menu in the Command Line following SOLID"
} | 268659 |
<p>I have been working on a series of posts about a library to connect to databases but most of the scenarios I have to resort to some "JOIN" the problem arose when two or more tables had some columns with the same name causing the last one to prevail.</p>
<p>I understand that the problem may lie in a bad dat... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T20:14:29.363",
"Id": "529880",
"Score": "0",
"body": "Could you please expand on how `$outPut` is used? perhaps [edit] and show how that variable is used, as well as describe where `$dbUsing` and `$dbquery` come from/are defined"
... | [
{
"body": "<h1>Readability - style guide</h1>\n<p>It is recommended that a style guide be followed for the sake of anyone reading and maintaining the code - including your future self. For PHP the PHP Framework Interop Group maintains style guides - including <a href=\"https://www.php-fig.org/psr/psr-1/\" rel=\... | {
"AcceptedAnswerId": "268838",
"CommentCount": "10",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T19:58:02.017",
"Id": "268663",
"Score": "1",
"Tags": [
"performance",
"php",
"object-oriented",
"sql",
"security"
],
"Title": "Prevent Column Name Collision"
} | 268663 |
<p><a href="https://cses.fi/problemset/task/1636/" rel="nofollow noreferrer">Question Link</a></p>
<blockquote>
<p>Consider a money system consisting of n coins. Each coin has a positive integer value. Your task is to calculate the number of distinct ordered ways you can produce a money sum x using the available coins.... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T14:25:37.197",
"Id": "529942",
"Score": "0",
"body": "You know that you don't have to do the modulo (a slow operation) three times. (a+b)%M is the same as (a%M + b%M)%M."
},
{
"ContentLicense": "CC BY-SA 4.0",
"Creation... | [
{
"body": "<p>Normally I do a design review first, then review the code itself. This time I’m going to switch it around.</p>\n<h1>Code review</h1>\n<p>Before I get into review <em>this</em> code, I just have to say that <a href=\"https://usaco.guide/problems/cses-1636-coin-combinations-ii-ordered/solution\" rel... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T20:05:01.607",
"Id": "268664",
"Score": "3",
"Tags": [
"c++",
"algorithm",
"programming-challenge",
"time-limit-exceeded",
"dynamic-programming"
],
"Title": "Recursive sol... | 268664 |
<p>I've just created a small script to clone all projects within a Gitlab Group and all Subgroups inside it.</p>
<p>As I am trying to level up my Go skills, I would welcome any reviews and enhancement on my code.</p>
<p><code>clone.go</code></p>
<pre class="lang-golang prettyprint-override"><code>package gl
import (
... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-04T23:18:35.570",
"Id": "268670",
"Score": "1",
"Tags": [
"recursion",
"go"
],
"Title": "Small recursive script in go to clone all projects in a Group"
} | 268670 |
<p>I'm quite new to C++, so as a beginner's project I decided to create a program that can solve second degree polynomials and (some) cubics using this lengthy formula I had found online.</p>
<p>I would love to receive some advice in regards to the code as I am eager to improve my code in any way possible and take away... | [] | [
{
"body": "<p>My feedback, note I did a code review that means I did not check the correctness of your calculations. You would need to place your calculation methods in a separate library (and then link to executable) and write unit tests for that.</p>\n<p>Here are my comments.</p>\n<pre><code>#include <cmat... | {
"AcceptedAnswerId": "268696",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T00:31:25.483",
"Id": "268671",
"Score": "3",
"Tags": [
"c++",
"beginner",
"mathematics"
],
"Title": "Third and second degree polynomial equation solver in C++"
} | 268671 |
<p>I'm posting this here mostly as I posted it <a href="https://stackoverflow.com/questions/69169764/changing-game-mode-in-tic-tac-toe-the-odin-project">over at stack<strong>overflow</strong></a> because the user that answered me recommended it:</p>
<p>I'm learning to code with <strong>The Odin Project</strong>. So fa... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T08:34:39.423",
"Id": "529929",
"Score": "1",
"body": "I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or c... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T01:26:59.947",
"Id": "268673",
"Score": "1",
"Tags": [
"javascript",
"beginner",
"html",
"tic-tac-toe",
"dom"
],
"Title": "Changing game mode in Tic Tac Toe [The Odin Proj... | 268673 |
<p>I'm building a small Delphi application where a user can input a file or directory manually by typing it or by selecting it from a dialog . Since it can be input manually, I want to ensure that I save that path as it is on the file system. For example: the user input <code>c:\program files</code>, the path is update... | [] | [
{
"body": "<p>As many Windows API functions work since 90's - you can call a function with zero size buffer first - function will fail, but will return needed buffer size, then you create your buffer with required size and call the function again with real buffer. In your case - you can make <code>FilePath</cod... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T03:41:56.370",
"Id": "268676",
"Score": "3",
"Tags": [
"file-system",
"windows",
"delphi"
],
"Title": "Delphi function to canonicalize the capitalization in a file path"
} | 268676 |
<p>For generating a list of characters, I currently use a static list, 2 components and some unclear conditional renders.</p>
<pre><code>export const chars = [
'#',
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',... | [] | [
{
"body": "<p>First of all I would split the <code>chars</code> arrays into two: the one with alphabet and the other one with soecial chars.</p>\n<p>If you did not do it I assume you have a reason.\nBut we still can obtain all special chars from <code>chars</code> array in generic way:</p>\n<pre class=\"lang-js... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T07:23:14.643",
"Id": "268680",
"Score": "0",
"Tags": [
"react.js",
"typescript",
"jsx"
],
"Title": "Listing the range from A-Z with special characters in JSX"
} | 268680 |
<p>I am looking to get any type of improvement, I want to be able to hash a list of 'blocks' aka strings and check if hashes match per block, if you can help me with that, currently reading and writing is optimized as I am writing direct bytes, any type of improvement in performance is appreciated!
I am also looking to... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T10:03:46.400",
"Id": "529937",
"Score": "0",
"body": "What would `crypto()` actually do in the real world? Currently there's a trivial speedup by not computing the same block hash a very large number of times, but I'm presuming it ... | [
{
"body": "<h2>An alternative algorithm</h2>\n<p>I do not quite know what you want to do, and so this might miss. But I am presuming that you are not trying to stress-test <code>sha256</code> by hashing the same block a zillion times and checking it works, and thus your <code>h()</code>, which always returns t... | {
"AcceptedAnswerId": "268684",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T09:22:11.823",
"Id": "268683",
"Score": "1",
"Tags": [
"python",
"python-3.x",
"multithreading",
"file",
"hash"
],
"Title": "Hashing with python optimization, hashlib ... | 268683 |
<p>I am working on an e-commerce website.</p>
<p>The home page has 2 inputs: <strong>Looking for</strong> and <strong>Location</strong>. The user would enter their desired product and location and click on <strong>Search</strong> as shown below:</p>
<p><a href="https://i.stack.imgur.com/IQps1.png" rel="nofollow norefer... | [] | [
{
"body": "<h2>Using CSS instead of JavaScript to apply styles</h2>\n<p>If only there was <a href=\"https://stackoverflow.com/a/48360699\">browser support for <code>:has()</code> pseudo-selector</a> - then the JavaScript function <code>bringStickyInputToTopOfThePageOnMobile()</code> could be eliminated. Another... | {
"AcceptedAnswerId": "268743",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T12:34:21.527",
"Id": "268686",
"Score": "0",
"Tags": [
"javascript",
"jquery",
"css",
"user-interface",
"autocomplete"
],
"Title": "Building user friendly inputs on a ... | 268686 |
<p>I created a text-based RPG.</p>
<p><strong>game.py</strong></p>
<pre><code>import random
import os
import items
from maps import mappa
import pickle
class Player:
def __init__(self, name):
self.name = name
self.lvl = 1
self.points = 5
self.attributepoints = 2
self.str = ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T21:55:55.583",
"Id": "530452",
"Score": "0",
"body": "Thanks for posting everything, this looks like a great subject for review"
}
] | [
{
"body": "<p>I assume this your first project of such size, and if so, that's a great work. It's really cool you've done all this.</p>\n<h3>Bad Recursion</h3>\n<p>This is the worst problem in your code. You see, calling the function is not free, it uses space in a call stack. The space is released on function ... | {
"AcceptedAnswerId": "268692",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T12:40:46.033",
"Id": "268687",
"Score": "10",
"Tags": [
"python",
"beginner",
"game",
"role-playing-game"
],
"Title": "Text-based role-playing game"
} | 268687 |
<p>I am seeking a general code review.</p>
<blockquote>
<p>Task:<br />
Write a program that takes JSON-formatted opening hours of a restaurant as an input and outputs hours in more human readable format.</p>
<p>Input:<br />
Input JSON sconsist of keys indicating days of a week and corresponding opening hours as values.... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T15:43:26.877",
"Id": "529949",
"Score": "4",
"body": "We can provide a better code review when more of the code is included."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T16:08:30.323",
"Id": "5... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T15:02:55.513",
"Id": "268690",
"Score": "1",
"Tags": [
"python",
"json",
"api",
"pydantic"
],
"Title": "Restaurant Open Hours - Converting Json to human readable format"
} | 268690 |
<p>I have implemented the classical Hoare's algorithm, but I think that the implementation is not readable enough. I have tried to refactor it in the way that I used to use in C#. But now I have got compiler errors.</p>
<p>Let me show some details. This is the first implementation:</p>
<pre class="lang-rust prettyprint... | [] | [
{
"body": "<p>When you start using references and arrays in rust you tend to run into difficulties with the borrow checker. The borrow checker isn't smart enough to understand the invariants of the algorithm, and thus has to be overly cautious.</p>\n<p>There are three solutions:</p>\n<h2>Use Indexes</h2>\n<p>In... | {
"AcceptedAnswerId": "268761",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T15:35:11.890",
"Id": "268691",
"Score": "0",
"Tags": [
"rust"
],
"Title": "Rust way of the generic quicksort implementation"
} | 268691 |
<p>I am trying to create the algorithm described in the image from this link <a href="https://i.stack.imgur.com/golea.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/golea.png" alt="Graph coloring problem" /></a>
Simply put any two adjacent nodes must not share tuples and if they do they are colored ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T21:28:44.593",
"Id": "529978",
"Score": "0",
"body": "It looks like `Dataset`, `Row` and `SparkSession` are all from `org.apache.spark.sql`, while `Graph` and `Node` are unrelated to the Spark classes with those names - is that righ... | [
{
"body": "<h2><code>coloring</code></h2>\n<ul>\n<li>Without seeing the rest of the class, I have no idea why this needs to not be static - maybe one of the functions it calls interacts with some internal state, but it doesn't <em>look</em> like that's the case. If it doesn't need an instance of whatever class ... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T16:08:11.857",
"Id": "268693",
"Score": "-1",
"Tags": [
"java",
"algorithm",
"graph",
"apache-spark"
],
"Title": "Graph coloring problem with Spark (JAVA)?"
} | 268693 |
<p>I've written some code that is yielding the desired results but it seems verbose. The code gets the distinct objects from an array of objects when looking at only a subset of the keys. Is there a more concise way to write the code to get the same output?</p>
<p><div class="snippet" data-lang="js" data-hide="false"... | [] | [
{
"body": "<p>Here is what I came up with:</p>\n<p><div class=\"snippet\" data-lang=\"js\" data-hide=\"false\" data-console=\"true\" data-babel=\"false\">\r\n<div class=\"snippet-code\">\r\n<pre class=\"snippet-code-js lang-js prettyprint-override\"><code>const source = [\n {\"id\":\"1\",\"department\":\"gro... | {
"AcceptedAnswerId": "268697",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T16:52:34.830",
"Id": "268695",
"Score": "0",
"Tags": [
"javascript"
],
"Title": "get distinct objects from an array based on a subset of keys"
} | 268695 |
<p><a href="https://kdevcalculator.web.app/" rel="nofollow noreferrer">https://kdevcalculator.web.app/</a></p>
<p>Code: <a href="https://github.com/AmishBaztard/Calculator/blob/main/script.js" rel="nofollow noreferrer">https://github.com/AmishBaztard/Calculator/blob/main/script.js</a></p>
<p>Just looking for a code rev... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T19:06:51.930",
"Id": "268700",
"Score": "2",
"Tags": [
"javascript"
],
"Title": "Vanilla Javascript Calculator using ESLint Air BnB Style"
} | 268700 |
<p>Every data that is collected is published in the spreadsheet and I don't know how to work with sending in blocks so I don't publish one by one, I would like some help to professionalize the data extraction model.</p>
<p>To facilitate extraction, I use the Cheeriogs library:</p>
<p><a href="https://github.com/tani/ch... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T20:35:50.777",
"Id": "268704",
"Score": "0",
"Tags": [
"google-apps-script",
"google-sheets"
],
"Title": "Web scraping publishing data line by line causing slowness and many simultane... | 268704 |
<p><strong>The purpose</strong></p>
<p>This code is intended to achieve the following goals:-</p>
<ol>
<li>Create a hard coded list of lifts, this is pretty static and I add some extra info so I'm ok with this being in the code but I may move it to configuration or an external store eventually</li>
<li>Every minute (or... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-05T23:35:43.000",
"Id": "268708",
"Score": "2",
"Tags": [
"beginner",
"functional-programming",
"f#"
],
"Title": "Download and parse XML data from a URL every minute with F#"
} | 268708 |
<p>I'm creating a small app to get familiarize with React. I'm trying to follow the pattern introduced in this Kent C Dodds <a href="https://kentcdodds.com/blog/how-to-use-react-context-effectively" rel="nofollow noreferrer">article</a>. But I have more states than the article.</p>
<p>Here is my initial state</p>
<pre>... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-06T07:16:32.040",
"Id": "529998",
"Score": "4",
"body": "Please [edit] your question so that the title describes the *purpose* of the code, rather than its *mechanism*. We really need to understand the motivational context to give goo... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-06T03:34:24.490",
"Id": "268709",
"Score": "0",
"Tags": [
"javascript",
"react.js",
"redux",
"react-native"
],
"Title": "Crud operations for profiles with React hooks"
} | 268709 |
<p>I'm relatively new to C++, and have attempted a Rock Paper Scissors game, and it works. Here and there I added some countdowns so that the program doesn't run instantly. Any tips for improving the program even further, or maybe even something to add a further level of complexity to the game to make it better?</p>
<p... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-07T16:34:34.270",
"Id": "530117",
"Score": "0",
"body": "Since you are asking about ways to add further complexity to the game, you may want to try implementing [Rock Paper Scissors Lizard Spock](https://en.wikipedia.org/wiki/Rock_pape... | [
{
"body": "<p>Don't repeat yourself.<br />\nThe <code>instructions</code> function does the same thing 4 times, changing only one string. Make the thing you want to do <em>for each string</em> the code, just once. Then drive it in a loop with the data. E.g.</p>\n<pre><code>const char* lines[] = {\n "... | {
"AcceptedAnswerId": "268718",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-06T12:24:19.427",
"Id": "268716",
"Score": "6",
"Tags": [
"c++",
"beginner",
"game",
"rock-paper-scissors"
],
"Title": "Rock-paper-scissors in C++"
} | 268716 |
<p>I have written the following function to read multiple CSV files into pandas dataframes. Depending on the use case, the user can pass optional resampling (frequency and method) and/or a date range (start/end). For both options I'd like to check if both keywords were given and raise errors if not.</p>
<p>My issue is ... | [] | [
{
"body": "<p>It's normal to do the parameter checking first:</p>\n<pre><code>def file_loader(filep, freq: str = None, method: str = None,\n d_debut: str = None, d_fin: str = None):\n if d_debut is not None and d_fin is None:\n raise ValueError("Please provide an end timestamp!&quo... | {
"AcceptedAnswerId": "268719",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-06T13:19:44.563",
"Id": "268717",
"Score": "2",
"Tags": [
"python",
"pandas"
],
"Title": "Read CSV, with date filtering and resampling"
} | 268717 |
<p>I am writing a program that asks questions, takes the user's input, and responds according to whether the answer they gave is correct or not.</p>
<p>I am looking to improve my code with respect to cleanliness and readability.</p>
<pre><code>const readline = require('readline');
const rl = readline.createInterface({... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-06T14:52:52.757",
"Id": "530025",
"Score": "3",
"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>This code is <a href=\"https://en.wikipedia.org/wiki/Don%27t_repeat_yourself\" rel=\"nofollow noreferrer\">WET (<strong>w</strong>rote <strong>e</strong>verything <strong>t</strong>wice)</a> and hard to extend/reuse. What if you want to ask, say, 10 questions? How about 100? Following the original... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-06T14:38:16.507",
"Id": "268720",
"Score": "2",
"Tags": [
"javascript",
"node.js",
"console",
"quiz"
],
"Title": "Arithmetic quiz on the command line"
} | 268720 |
<p>I am currently finalising the class for a trading strategy and wanted to know if the below could be re-written in a shorter way that will let it run faster?</p>
<p>This is PCA1 df:</p>
<pre><code> USDJPY EURUSD GBPUSD AUDUSD GBPAUD
date pca_component
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-06T19:14:35.657",
"Id": "530034",
"Score": "1",
"body": "Please revisit your indentation - it's not going to work in its current state"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-06T21:44:05.510",
"... | [
{
"body": "<p>The structure of your code is weird; are you sure it's doing what you want? If it is, <em>strongly</em> consider adding comments or better variable names or something to make it clearer what it's supposed to be doing. Without such explanation, it looks like you have code inside your loop that ough... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-06T17:52:45.777",
"Id": "268726",
"Score": "-2",
"Tags": [
"python",
"performance"
],
"Title": "A custom trading strategy"
} | 268726 |
<p>So my friend told me he just did 1 while and a bunch of if-else with only using 3 arrays to get the same output as mine code does.</p>
<p>So I wonder if I just make this unnecessarily complicated. I have created 5 arrays here.</p>
<p>What's your opinion on this?</p>
<pre><code>#include <stdio.h>
#include <f... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-06T21:00:59.100",
"Id": "530038",
"Score": "1",
"body": "Why did you reimplement `strcmp`?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-06T21:03:50.633",
"Id": "530039",
"Score": "0",
"body":... | [
{
"body": "<p>Instead of using <code>open()</code> and <code>close()</code> directly, we could use <code><stdio.h></code> for a more portable program.</p>\n<p>Don't use reserved names for your own functions (here, a name beginning with <code>str</code>). I don't see why we have written this, though - jus... | {
"AcceptedAnswerId": "268758",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-06T20:47:32.597",
"Id": "268732",
"Score": "2",
"Tags": [
"c"
],
"Title": "use C to create uniq()"
} | 268732 |
<p>I am a self taught python developer and I trying to write clean code as mush as possible. Since I do not have any environment that can give me constructive criticism, I would like to hear your opinions, so, here it is a python password generator, I know that something like that can be made with single function, but ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-07T08:47:07.337",
"Id": "530072",
"Score": "2",
"body": "side note, it's weak, not week :)"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-07T09:08:11.227",
"Id": "530073",
"Score": "1",
"body":... | [
{
"body": "<p>Good use of type annotations!</p>\n<p>Variable and method naming is mostly concise and readable.</p>\n<hr />\n<p><code>password_level</code>: <code>week</code> should be <code>weak</code>.</p>\n<hr />\n<p>In its current implementation <code>GeneratePassword</code> does not need to be a class, func... | {
"AcceptedAnswerId": "268738",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-06T21:05:22.617",
"Id": "268734",
"Score": "9",
"Tags": [
"python",
"yaml"
],
"Title": "Python password generator class"
} | 268734 |
<p>I have done some validation in the following code and wanted to know if that's the correct way to go about it. The validation is related to <code>start year</code> and <code>end year</code> when user hits <code>Get rows</code> button. So I always want to make sure that <code>start year</code> is less than <code>end ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-06T23:16:35.810",
"Id": "268737",
"Score": "0",
"Tags": [
"javascript",
"html"
],
"Title": "validating start and end year with return statement"
} | 268737 |
<p>My program displays the price of a movie ticket. The price is based on the customer’s age. If the user enters a negative number, the program displays the “Invalid age” message.</p>
<pre><code>#include<iostream>
using namespace std;
int main(){
int age = 0;
int price = 0;
cout <&... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-07T07:16:43.877",
"Id": "530065",
"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>Your overall code works fine, but there are some improvements.</p>\n<h2>Using else if's</h2>\n<p>You are comparing age against <code>0, 4, 64, 65</code> pointlessly, it can only be one. In this case we can use <code>else if</code>.</p>\n<h2>Duplicate code</h2>\n<p>Once you have determined the pric... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-07T01:27:33.660",
"Id": "268742",
"Score": "3",
"Tags": [
"c++",
"beginner",
"programming-challenge"
],
"Title": "Calculate movie ticket price"
} | 268742 |
<p><a href="https://leetcode.com/problems/maximum-width-of-binary-tree/" rel="nofollow noreferrer">Problem Statement</a></p>
<pre><code>Given the root of a binary tree, return the maximum width of the given tree.
The maximum width of a tree is the maximum width among all levels.
The width of one level is defined as t... | [] | [
{
"body": "<h3>The bug</h3>\n<p>The code doesn't terminate, because the loop condition <code>frontierRef[0] !== undefined</code> will never be false. After the last level of the tree, <code>newElements</code> will have all <code>null</code> values, the <code>slice</code> will slice off all but the first element... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-07T04:46:29.143",
"Id": "268745",
"Score": "0",
"Tags": [
"javascript",
"programming-challenge",
"time-limit-exceeded",
"functional-programming",
"tree"
],
"Title": "Leetcode... | 268745 |
<h3>Problem</h3>
<p>I have <a href="https://nest.pijul.com/nicoty/sieve:code_review" rel="nofollow noreferrer">a project</a> in which I implemented variants of the Sieve of Eratosthenes as well as benchmarking and profiling harnesses for these (which can be ran with <code>./run.sh benchmark</code> and <code>./run.sh pr... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-08T07:49:16.640",
"Id": "530148",
"Score": "0",
"body": "Ok, I think one reason it (and the segmented variant) is slow is because if the overall list size is smaller than the \"cache size\", it does a check on whether it should use the... | [
{
"body": "<p>I think I've solved a part of the problem, which was that my previous implementations of the wheel factorised sieves didn't actually skip checking for multiples of the base primes used by their wheel. <a href=\"https://nest.pijul.com/nicoty/sieve:main\" rel=\"nofollow noreferrer\">After improving ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-07T08:42:06.597",
"Id": "268749",
"Score": "3",
"Tags": [
"performance",
"algorithm",
"rust",
"memory-optimization",
"sieve-of-eratosthenes"
],
"Title": "Segmented Sieve of E... | 268749 |
<p>I'm starting out on a project that will standardise some increasingly complex webcomponents. In a final version the goal is to support multiple different design systems (as the components might be used for different brands, which require different color schemes, border radiuses, margins, etc.). This is my attempt at... | [] | [
{
"body": "<p>Not really a full answer: I would rename <code>defineProperties</code> to <code>resolveProperties</code> which is a more commonly used name for this type of action.</p>\n<p>Maybe I'd move the props to the top of the class, as first line. My JS isn't what it used to be, but in most languages it's g... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-07T09:35:55.450",
"Id": "268752",
"Score": "3",
"Tags": [
"javascript",
"html",
"webcomponent"
],
"Title": "Simple button webcomponent"
} | 268752 |
<p>I am learning about hooks, so I try to write code that display current time.</p>
<p>I had comment in each line of code the reason I write it. So:</p>
<ol>
<li>Am I understand right?</li>
<li>Is there any bad practice?</li>
<li>What need to be improved?</li>
</ol>
<pre><code>import * as React from 'react'
function ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-07T13:24:37.793",
"Id": "530087",
"Score": "0",
"body": "You may find this interesting/useful: https://overreacted.io/a-complete-guide-to-useeffect/"
}
] | [
{
"body": "<p>By default, <code>useEffect</code> will run on every render. Because you're setting state in <code>useEffect</code>, state will render on every render, causing loops of unnecessary renders.</p>\n<p>To fix this, pass an empty dependency array to <code>useEffect</code>:</p>\n<pre><code>React.useEffe... | {
"AcceptedAnswerId": "268754",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-07T09:40:29.767",
"Id": "268753",
"Score": "0",
"Tags": [
"javascript",
"react.js",
"jsx"
],
"Title": "React - Display current time using useState, useEffect"
} | 268753 |
<p><sup>If I formatted my question wrong, feel free to notify me or update, this is my first question on <em>this</em> subforum</sup></p>
<p>This is literally my first ever Go project, decided to make a Tic Tac Toe (ironically I came up with that idea myself, turns out a lot of people use this as a beginner project heh... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T09:32:32.993",
"Id": "530557",
"Score": "0",
"body": "Huh, I had a good answer from another user, where did that go?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T13:10:18.683",
"Id": "531031",
... | [
{
"body": "<h3>Update one:</h3>\n<p>Had a brainfart, realized that I dont need to check everything if it matches X or O, just the last move. If the last move has been done by X, O will never win, so checking for that is a waste of compute as it reduces checks by 50%. The new version has functions like this, red... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-07T18:30:28.127",
"Id": "268762",
"Score": "4",
"Tags": [
"beginner",
"game",
"go",
"tic-tac-toe"
],
"Title": "first Go program: Tic Tac Toe"
} | 268762 |
<p>This would seem obvious, but there is a lot that can go wrong. What happens is the user enters alpha values etc.</p>
<p>I have come up with this function and would appreciate any suggestions or comments on how to handle this better:</p>
<pre class="lang-cpp prettyprint-override"><code>#include <iostream>
#inc... | [] | [
{
"body": "<h1>Consider all possible errors</h1>\n<p>You only considered the possibility of failing to parse the number and reaching the end of the input. However, there might also be a read error that causes <code>fail()</code> to return <code>true</code>, <code>eof()</code> to return <code>false</code>, but w... | {
"AcceptedAnswerId": "268768",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-07T19:22:39.963",
"Id": "268765",
"Score": "6",
"Tags": [
"c++"
],
"Title": "Reading a number from the standard input"
} | 268765 |
<p>I've just wrote my first real C program. It calculates the dimensions of a circle or a sphere based on the user input.</p>
<p>The program asks the user which dimension they are entering and then prints the values of the remaining dimensions.</p>
<pre><code>#include <stdio.h>
#define _USE_MATH_DEFINES
#include&... | [] | [
{
"body": "<ol>\n<li><p>Check your privilege.</p>\n<p>This is apparently Windows code. It won't compile on Linux. I added:</p>\n<pre><code> #ifdef unix\n #include <string.h>\n #define _stricmp strcasecmp\n #endif\n</code></pre>\n</li>\n<li><p>Limit the scope of your symbols</p>\n<p>You have global... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-07T19:50:45.387",
"Id": "268766",
"Score": "4",
"Tags": [
"beginner",
"c",
"calculator"
],
"Title": "Circle & Sphere Calculator"
} | 268766 |
<p>The code I have below is currently what I am wanting to see if I can shorten. The code works as-is right now but I don't like the face that each IF statement has its own <strong>$each loop</strong> in it. <strong><code>I was wanting to see if I can condensed this down</code></strong> to allow only one call to the <s... | [] | [
{
"body": "<p>You can use bracket notation to reference the correct item depending on the content of <code>input.TextField</code> eg <code>text: item[input.TextField.toLowerCase()]</code></p>\n<p>That way you only need test if input is a valid option. You can use an <a href=\"https://developer.mozilla.org/en-U... | {
"AcceptedAnswerId": "268822",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-07T20:38:08.090",
"Id": "268767",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "A more elegant way of adding option data to a dropdown box using jQuery"
} | 268767 |
<p>To get the Firefox default profile, I am using the following program.</p>
<pre><code>import glob
from pathlib import Path
import re
x = glob.glob(str(Path.home()) + '/.mozilla/firefox/*/')
r = re.compile(".*default-release.*")
firefox_default_profile = list(filter(r.match, x))[0]
print(firefox_default_pro... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-08T09:04:40.093",
"Id": "530150",
"Score": "1",
"body": "What do you mean by \"get the Firefox default profile\"? The full path to the folder it is in? Or something else? Can you [clarify](https://codereview.stackexchange.com/posts/268... | [
{
"body": "<ul>\n<li>You don't need to import <code>glob</code>; <code>pathlib.Path</code> has a <a href=\"https://docs.python.org/3/library/pathlib.html#pathlib.Path.glob\" rel=\"noreferrer\"><code>Path.glob</code></a> method.</li>\n<li>You don't need to import <code>re</code>; you can merge the regex into the... | {
"AcceptedAnswerId": "268771",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-07T21:32:24.963",
"Id": "268770",
"Score": "5",
"Tags": [
"python",
"python-3.x"
],
"Title": "Get the Firefox Default Profile"
} | 268770 |
<p>I'm new here. I recently found myself in charge of a large PHP-based system. The guy that wrote it produced some of the worst code I've ever seen. I've never been in charge and have had the luxury of working under some very good programmers who took the time to "groom" me - but with stricter languages like... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-08T07:09:54.553",
"Id": "530142",
"Score": "2",
"body": "Is this an example of the \"worst code\", or is this after you've made an effort to improve it to the best of your ability?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"C... | [
{
"body": "<p>I had a short look at your code. It is a pity you haven't included an example e-mail in your question. It makes reviewing your e-mail parsing code more difficult than it needs to be.</p>\n<h1>Object Oriented Programming</h1>\n<p>The very first thing I noticed is that you use a single <code>class</... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-08T01:29:58.133",
"Id": "268773",
"Score": "3",
"Tags": [
"php",
"parsing"
],
"Title": "PHP fetch an automated email, parse text for specific data, store, send summary"
} | 268773 |
<p>My program calculates the user's age in years and months. It takes the user's birth year and month and then the current year and month as input.</p>
<pre><code>#include <iostream>
using namespace std;
int main ()
{
int y1 , m1 , y2 , m2 ;
cout<<"Enter Your year of birth"<... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-08T14:00:30.910",
"Id": "530177",
"Score": "0",
"body": "Smart move to only consider year and month, that avoids [the problem with timezones](https://www.youtube.com/watch?v=-5wpm-gesOY)."
}
] | [
{
"body": "<p>Avoid <code>using namespace std</code> - that dumps the whole of the standard library into the global namespace, eliminating all the advantages of it having a namespace.</p>\n<p>When taking input, think about how it can fail. If something that's not a number is entered, then we'll be working with... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-08T02:22:19.627",
"Id": "268774",
"Score": "0",
"Tags": [
"c++",
"programming-challenge",
"datetime"
],
"Title": "Year/month difference calculator"
} | 268774 |
<p>I am looking for ways to improve this little utility function:</p>
<pre class="lang-lisp prettyprint-override"><code>(defun break-down (taste sequence)
"Break down a list SEQUENCE into consecutive lists of constant TASTE.
The TASTE argument is a function which is applied on sequence elements to
taste them. Ta... | [] | [
{
"body": "<ol>\n<li>I can't find a better alternative.</li>\n<li>I think “yes” in this case. I prefer to use <code>reduce</code> with functions that are binary operators on the sequence elements, but maybe this is a just a personal preference.</li>\n<li>I think you have done a good work on documentation and ch... | {
"AcceptedAnswerId": "268816",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-08T05:51:09.977",
"Id": "268775",
"Score": "1",
"Tags": [
"common-lisp"
],
"Title": "Break down a list SEQUENCE into consecutive lists of constant TASTE"
} | 268775 |
<p>Learning Bash using hunt and peck method. Following code was put together from results of many "How do I ..." searches. Thus styling may be inconsistent. See code for my motivation. Any advice gratefully accepted.</p>
<pre><code>#!/bin/bash
# Motivation:
# To ease the process of examining large quantiti... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T07:48:17.053",
"Id": "530278",
"Score": "0",
"body": "Welcome to Code Review! Incorporating advice from an answer into the question violates the question-and-answer nature of this site. You could post improved code as a new questio... | [
{
"body": "<blockquote>\n<pre><code>trap "exit" INT TERM ERR\n</code></pre>\n</blockquote>\n<p>The normal response to <code>INT</code> and <code>TERM</code> is to exit with a failure value, rather than a success value. I'd leave that alone, and additionally make <code>ERR</code> do the same with a si... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-08T16:50:22.960",
"Id": "268785",
"Score": "4",
"Tags": [
"bash"
],
"Title": "Ease process for gathering metadata from PDF, DJVU, EBOOK files"
} | 268785 |
<p>I'm only three days into React, so please forgive my ignorance.</p>
<p>I'm working on an application in which you can design something consisting of various parts. The interface has a list of items in one place (let's call it <code>PartsList</code>) and a visualization of these parts in another place (<code>Visualiz... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-08T18:48:59.647",
"Id": "530189",
"Score": "0",
"body": "Welcome to Code Review! The current question title, which states your concerns about the code, is too general to be useful here. Please [edit] to the site standard, which is for ... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-08T18:39:35.837",
"Id": "268787",
"Score": "0",
"Tags": [
"javascript",
"react.js",
"jsx"
],
"Title": "Passing global state and state-modifying functions to child elements in a React... | 268787 |
<p>This is my very basic Weather App. Would appreciate your opinion mainly about style, writing code etc. I know there is not much functionality to this app, but I have created it just to practice and to share with you guys so you could possibly point weak points I need to focus on as a programmer. As I am learning mai... | [] | [
{
"body": "<ul>\n<li><p>Destroying and re-creating the entire icon label feels like an awkward solution. Isn't it possible to keep the label as it is and only replace its image? I believe something like <code>self.image_lbl.configure(image=self.weather_image)</code> might do that</p>\n<ul>\n<li>I'm also wonderi... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-08T20:06:22.107",
"Id": "268790",
"Score": "7",
"Tags": [
"python",
"beginner",
"tkinter"
],
"Title": "Weather App- Python"
} | 268790 |
<p>For my first Rust exercise I decided to re-implement a project I wrote in C++ for my data structures class a few years ago, plus make it generic. I am looking for all suggestions, but I am primarily concerned about writing more idiomatic Rust.</p>
<pre><code>use bitvec::prelude::*;
use counter::Counter;
use std::cmp... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-08T21:31:17.247",
"Id": "268794",
"Score": "1",
"Tags": [
"beginner",
"rust",
"compression"
],
"Title": "Generic Huffman Encoding"
} | 268794 |
<p>I'm looking to highlight some words on a webpage, I've grouped them now, but changed the css and html slightly and this seems to have broken it.</p>
<p>For context, looking to add a list of words in JS which would then apply formatting to those words. I changed the p to a span because I wanted them to be an inline-b... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-09T00:01:36.530",
"Id": "530199",
"Score": "0",
"body": "You can try making a list of strings like `['dolor', 'ut']`, and run a loop through this list and process each element with your `hilliter` function"
},
{
"ContentLicense... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-08T23:49:39.537",
"Id": "268797",
"Score": "0",
"Tags": [
"javascript",
"formatting"
],
"Title": "Beginner Q: Is there a cleaner way to group a list in JS?"
} | 268797 |
<p>I wrote a program that uses stat() to find some details of all the files in a current directory. I then store all that information into a string using sprintf() and keep adding to the size to prevent my string from being overwritten and then I copy the string into a char**. This code seems to work but I was wonderin... | [] | [
{
"body": "<ul>\n<li><p>The function is doing too much. Stick to <a href=\"https://en.wikipedia.org/wiki/Single-responsibility_principle\" rel=\"nofollow noreferrer\">SRP</a>:</p>\n<ul>\n<li>One function to iterate the directory</li>\n<li>One function to collect the information about one file</li>\n<li>One func... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-09T02:12:31.173",
"Id": "268799",
"Score": "2",
"Tags": [
"c"
],
"Title": "Making a program that lists files in a directory and sorts the output using stat()"
} | 268799 |
<p>I have written a Python 3 program that can encrypt and decrypt <a href="https://en.wikipedia.org/wiki/Playfair_cipher" rel="nofollow noreferrer">Playfair cipher</a>, though I know it has been implemented countless times, none of the scripts I have seen so far(e.g. <a href="https://codegolf.stackexchange.com/a/23363"... | [] | [
{
"body": "<p>First of all</p>\n<ul>\n<li>This code looks like it does what you want</li>\n<li>You've separated methods well</li>\n<li>The code style looks reasonable (in terms of formatting, blank lines etc).</li>\n</ul>\n<p>Second, stop reading code golf, it's a poor standard even if you're trying to learn wh... | {
"AcceptedAnswerId": "268833",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-09T05:50:39.200",
"Id": "268801",
"Score": "2",
"Tags": [
"python",
"python-3.x",
"cryptography"
],
"Title": "Python 3 Playfair cipher encrypter and decrypter"
} | 268801 |
<p>Given the code:</p>
<pre class="lang-js prettyprint-override"><code>async getData() {
const response = await handleRequest(…);
return response;
}
</code></pre>
<p>Many of static code analyzers mark this code with an <a href="https://rules.sonarsource.com/javascript/RSPEC-1488" rel="nofollow noreferrer">is... | [] | [
{
"body": "<p>Mostly I see it same as you do. Not every optimization must be done only because it is possible. It might become interesting if you get any performance issues, because it is a heavily used function. But normally I also prefer more clear and readable code –</p>\n",
"comments": [
{
... | {
"AcceptedAnswerId": "268811",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-09T10:49:50.553",
"Id": "268807",
"Score": "1",
"Tags": [
"javascript",
"async-await"
],
"Title": "Regarding \"Local variables should not be declared and then immediately returned or... | 268807 |
<p>I have completed my hangman project in C++.</p>
<p>I would like your thoughts and improvements on my implementation.</p>
<p>Here is the code:</p>
<pre><code>#include <iostream>
#include <ctime>
#include <string>
#include <vector>
std::string get_random_word(std::vector<std::string>&... | [] | [
{
"body": "<p>Looks pretty good and kudos for not having <code>using namespace std;</code> <br></p>\n<p>Here is some nitpicking.<br></p>\n<p>Your indentation is all over the place, here you have an extra tab:<br></p>\n\n<pre class=\"lang-cpp prettyprint-override\"><code>if (secret_word.find(guess) != std::strin... | {
"AcceptedAnswerId": "268815",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-09T11:41:53.353",
"Id": "268810",
"Score": "5",
"Tags": [
"c++",
"game",
"console",
"hangman"
],
"Title": "Hangman game coded in C++"
} | 268810 |
<p>This function has 16 repeated calls to the same function, passing in the same handles to each:</p>
<pre><code>// Create all 16 colors
void fill_color_gcs(xcb_connection_t *c, xcb_window_t w, xcb_screen_t *s,
xcb_gcontext_t *col) {
col[0] = color_gc(c, w, s, 0, 0, 0);
col[1] = color_gc... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-09T13:01:17.287",
"Id": "530224",
"Score": "5",
"body": "For me it would make more sense to put your parameters in an array and use a loop"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T05:38:44.767",
... | [
{
"body": "<p>For me it looks like you create some kind of color table here.\nIn the first step I would make the function more flexible by giving the colors as parameter</p>\n<pre><code>void fill_color_gcs(xcb_connection_t *c, xcb_window_t w, xcb_screen_t *s,\n xcb_gcontext_t *col, float *colorTable)... | {
"AcceptedAnswerId": "268845",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-09T12:56:40.787",
"Id": "268812",
"Score": "-1",
"Tags": [
"c",
"comparative-review",
"macros",
"xcb"
],
"Title": "Populate a color table in XCB"
} | 268812 |
<p>My bot is fully functional and I would love some feedback. Thanks!</p>
<p>Main loop for keep it running (main.py)</p>
<pre><code>from functions import RunBot, InitPraw
reddit_handler = InitPraw()
doctor_who_subreddit_handler = reddit_handler.subreddit("doctorwho")
while(True):
RunBot(doctor_who_subredd... | [] | [
{
"body": "<p>Function and variable names in Python should follow <code>snake_case</code>.</p>\n<hr />\n<p><a href=\"https://www.python.org/dev/peps/pep-0008/#indentation\" rel=\"noreferrer\">PEP 8</a> recommends using 4 spaces per indentation level.</p>\n<hr />\n<p><strong><code>LoadQuotes</code></strong></p>\... | {
"AcceptedAnswerId": "268851",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-09T16:07:45.053",
"Id": "268820",
"Score": "6",
"Tags": [
"python",
"reddit"
],
"Title": "Reply bot for reddit. Simple bot that replies when \"doctor\" is mentioned"
} | 268820 |
<p>I am learning C and doing challenges like those found on exercism.io and the various data structure & algorithm sites.</p>
<p>I have a sense that while this works and it makes sense to me that it can be improved and probably isn't how a professional C programmer would have solved it.</p>
<p>Interested if this wo... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-09T18:04:33.980",
"Id": "530244",
"Score": "4",
"body": "Your code returns an unterminated string. You should add ‘\\0’ at then end of `acronym`. We usually only review working code. This is what I got for `United States of America` : ... | [
{
"body": "<p>I'll show you what I would write first:</p>\n<pre><code>char *abbreviate(const char *phrase) {\n assert(phrase);\n\n char *acronym = malloc(strlen(phrase) / 2 + 1);\n if (!acronym) {\n return NULL;\n }\n\n char previous = ' ';\n size_t len = 0;\n\n for (size_t i = 0; phrase[i]; i++) {\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-09T17:05:07.047",
"Id": "268821",
"Score": "2",
"Tags": [
"beginner",
"c",
"programming-challenge",
"strings"
],
"Title": "Phrase to acronym in C from exercism.io"
} | 268821 |
<p>Let's say I have a number set like below</p>
<pre><code>// 1,2,3,4,5,6,7,8
</code></pre>
<p>Now I want to go from <code>2</code> to <code>5</code>. To go from <code>2</code> to <code>5</code> there are two ways: one is forwards and another is backwards</p>
<pre><code>forwards: +3
backwards: -5
</code></pre>
<p>Backw... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T04:15:04.033",
"Id": "530271",
"Score": "0",
"body": "I have a question, the set you receive as parameter comes always sorted?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T04:16:26.457",
"Id": ... | [
{
"body": "<h2>Optimization / Simplification</h2>\n<p>Your code can be converted into the following</p>\n<p><div class=\"snippet\" data-lang=\"js\" data-hide=\"false\" data-console=\"true\" data-babel=\"false\">\r\n<div class=\"snippet-code\">\r\n<pre class=\"snippet-code-js lang-js prettyprint-override\"><code... | {
"AcceptedAnswerId": "268881",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-09T23:30:35.927",
"Id": "268828",
"Score": "4",
"Tags": [
"javascript",
"mathematics"
],
"Title": "find closest distance between two numbers (looking for improvement)"
} | 268828 |
<p>In question <a href="https://codereview.stackexchange.com/q/268454/231235">"Dictionary based non-local mean implementation in Matlab"</a>, the Manhattan distance between two three-dimensional structures can be calculated by <code>ManhattanDistance</code> function. In this post, besides Manhattan distance, ... | [] | [
{
"body": "<p>Your test cases don’t test the error condition handling:</p>\n<pre class=\"lang-matlab prettyprint-override\"><code>if size(X1)~=size(X2)\n fprintf("Sizes of inputs are not equal!\\n");\n return;\nend\n</code></pre>\n<p>In the case of two inputs with different dimensionality, you w... | {
"AcceptedAnswerId": "268857",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-09T23:53:35.017",
"Id": "268829",
"Score": "1",
"Tags": [
"array",
"error-handling",
"matrix",
"matlab"
],
"Title": "Calculate distances between two multi-dimensional arrays ... | 268829 |
<p>I have completed my Python project which calculates and outputs the number densities of dozens of different species (over 11 chemical elements total) in a model atmosphere of the Sun. The code reads in a file that contains mass and temperature for a given depth in the Sun.</p>
<p>I would like your thoughts and impro... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T03:46:19.520",
"Id": "530270",
"Score": "1",
"body": "Can you link some sample data?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T17:04:25.247",
"Id": "530303",
"Score": "0",
"body": "@... | [
{
"body": "<p>This is very interesting. I see that it's homework. I can't say whether the output of your code is correct (astrochemistry?), but in terms of Python + Pandas + Numpy development there's some room for improvement.</p>\n<p>Overall your code is very flat, has few functions, and operates almost entire... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T00:30:58.990",
"Id": "268831",
"Score": "7",
"Tags": [
"python",
"pandas",
"homework",
"jupyter"
],
"Title": "Output number densities in model atmosphere of the Sun"
} | 268831 |
<p>The code runs fine and was manageable without any error handling.</p>
<p>Once I started to handle errors and build out the code the if/elif/else branches quickly became too much. How can I route the view function conditionally based on the button that sent the request without all the conditionals? I tried refactorin... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T00:43:03.003",
"Id": "530266",
"Score": "1",
"body": "Hi, welcome to Code Review. Please, do not remove the imports from your code. They are needed to understand the code"
},
{
"ContentLicense": "CC BY-SA 4.0",
"Creation... | [
{
"body": "<p>Don't provide multiple methods -</p>\n<pre><code>methods=('GET', 'POST')\n</code></pre>\n<p>only to then check the method:</p>\n<pre><code>if request.method == 'POST':\n</code></pre>\n<p>Instead, separate this into two functions each accepting one method each and remove your <code>if</code>.</p>\n... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T00:34:00.410",
"Id": "268832",
"Score": "4",
"Tags": [
"python",
"flask",
"web-services"
],
"Title": "Flask static url view"
} | 268832 |
<p>I'm solving the <a href="https://leetcode.com/problems/longest-palindromic-substring" rel="nofollow noreferrer">Longest Palindromic Substring</a> problem on LeetCode.</p>
<p>And here's my final submission:</p>
<pre><code>public static String longestPalindrome(String s)
{
// to avoid TLE
char [] sChars = s.to... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T08:54:33.123",
"Id": "530279",
"Score": "0",
"body": "Take a look at this algorithm\nhttps://en.wikipedia.org/wiki/Longest_palindromic_substring\nI think its not so complicated to transfer it to Java"
},
{
"ContentLicense": ... | [
{
"body": "<h3>Avoid unnecessary operations</h3>\n<p>Thinking about unnecessary operations is important in general, especially in functions that are called very frequently. Let's take a look at <code>isPalindrome</code>.</p>\n<p>To check if a string is palindrome, you can compare characters pairwise from the en... | {
"AcceptedAnswerId": "269216",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T08:38:20.470",
"Id": "268841",
"Score": "1",
"Tags": [
"java",
"strings",
"time-limit-exceeded",
"palindrome"
],
"Title": "Finding longest palindromic substring in a strin... | 268841 |
<p>Here is my starting point for a laravel CRUD controller.</p>
<p>I would appreciate it if someone could do a review and show me how an experienced developer would approach this.</p>
<p>I do not want to progress with my app if I am not using the best practices.</p>
<p>I am using Laravel 8</p>
<pre><code><?php
name... | [] | [
{
"body": "<h2>Displaying all records?</h2>\n<p>The <code>index()</code> method returns all records:</p>\n<blockquote>\n<pre><code>$employees = Employee::all();\n</code></pre>\n</blockquote>\n<p>This could be disadvantageous for multiple reasons - especially when there are thousands or more records:</p>\n<ul>\n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T10:59:29.273",
"Id": "268843",
"Score": "1",
"Tags": [
"php",
"validation",
"laravel",
"eloquent"
],
"Title": "Laravel CRUD Controller - code request"
} | 268843 |
<p>Parallel reduction kernels using different synchronization approaches + <a href="http://www.jocl.org/" rel="nofollow noreferrer">JOCL</a> host level application that runs all 3 sync modes and CPU reduction on random data and outputs evaluation times:</p>
<ul>
<li><code>BARRIER</code>: Uses local barriers to sync bet... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T12:33:12.727",
"Id": "268846",
"Score": "0",
"Tags": [
"java",
"opencl"
],
"Title": "3 sync approaches for parallel reduction on GPU using openCL + jocl"
} | 268846 |
<p>It took me a while to compute this script, it works perfectly, but I think that it is very raw and long.</p>
<p>The goal of the script is to produce a graph of cumulated rainfall with 3 lines:</p>
<ul>
<li>Cumulated rainfall of the rainiest year</li>
<li>Cumulated rainfall in the current year (for example from 1st J... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T13:31:49.603",
"Id": "530296",
"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>Welcome to Code Review. Here are a few improvements to the code:</p>\n<ul>\n<li><p>Use <code>const</code> and arrow notation for your functions.</p>\n</li>\n<li><p>Stick to the DRY (Don't Repeat Yourself) principle: you are doing the same logic three times.</p>\n</li>\n<li><p><code>beginX</code> v... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T13:21:03.210",
"Id": "268848",
"Score": "3",
"Tags": [
"javascript",
"google-apps-script",
"google-app-engine"
],
"Title": "Calculate cumulative daily rainfall"
} | 268848 |
<p>XCB is a library for C programmers providing a low-level interface to X11 protocol.</p>
<p>It is typically used for small X client programs, and in the implementation of toolkit libraries such as Qt.</p>
<hr />
<ul>
<li><a href="http://xcb.freedesktop.org/" rel="nofollow noreferrer">Project wiki</a></li>
<li><a href... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T13:27:15.043",
"Id": "268849",
"Score": "0",
"Tags": null,
"Title": null
} | 268849 |
For code that uses functions in the X protocol C-language Binding library. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T13:27:15.043",
"Id": "268850",
"Score": "0",
"Tags": null,
"Title": null
} | 268850 |
<p>I am creating a simple Country class. This Country have list of know countries. we can get the list of known countries <code>Country.AllCountries</code>,</p>
<pre><code>public class Country
{
static Country()
{
AllCountries = GetAllCountries();
}
public string Name { get; set; }
public s... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T18:06:18.373",
"Id": "530305",
"Score": "1",
"body": "Go with the service so it wouldn't be treated as a child/parent reference, this would be more safer and appropriate. Using a service, would also keep the business logic intact. I... | [
{
"body": "<p>The term I would use is Provider as in ICountryProvider, and I would expect it to be provided to the classes that use it via dependency injection. Of course that doesn’t have to be the case, you could create the interface and apply it manually. But I would consider your first example a code smel... | {
"AcceptedAnswerId": "268873",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T14:42:03.500",
"Id": "268853",
"Score": "0",
"Tags": [
"c#",
"comparative-review"
],
"Title": "List of objects inside same model vs Factory vs Service"
} | 268853 |
<p>To learn C, I'm doing the traditional <a href="https://en.wikipedia.org/wiki/Fizz_buzz" rel="nofollow noreferrer">FizzBuzz</a> challenge with extra restrictions:</p>
<ul>
<li>The start and end of sequence is provided by the user</li>
<li>Instead of directly printing the results, the results must be stored in an arra... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T19:34:33.380",
"Id": "530310",
"Score": "1",
"body": "Do you want pretty or fast code? Most of the ways to optimize this goes against best coding practices like using built-in functions etc."
},
{
"ContentLicense": "CC BY-SA... | [
{
"body": "<p>I’ll start with the basics.</p>\n<p>Your code returns an array of strings when it could have simply returned a string. A C-style string is an array that is terminated with a zero character.</p>\n<p>You are coping data into <code>fizzBuzz</code> and then appending <code>fizzBuzz</code> into <code>f... | {
"AcceptedAnswerId": "268864",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T18:50:11.037",
"Id": "268859",
"Score": "5",
"Tags": [
"c",
"strings",
"array",
"pointers",
"fizzbuzz"
],
"Title": "FizzBuzz, but with provided start and end of sequen... | 268859 |
<p>This is a question about Java/JavaFX concurrency. Specifically, how can the UI request intermediate data from a thread running in an infinite loop.</p>
<p>I have a simulation program in Java and JavaFX. The simulation model executes its calculations in an infinite loop running in the background. The simulation upd... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-10T21:08:45.933",
"Id": "268865",
"Score": "2",
"Tags": [
"java",
"concurrency",
"javafx"
],
"Title": "Obtaining intermediate results from a continuously running background thread in... | 268865 |
<p>After many different approaches and attempts I arrived at this method to set application scope settings for my applications:</p>
<pre><code>public abstract class ConfigData : INotifyPropertyChanged
{
private System.Configuration.Configuration _cfg;
private ClientSettingsSection _section;
public event Pr... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-11T08:00:52.107",
"Id": "530320",
"Score": "0",
"body": "For me it's perfect because you are using same `INotifyPropertyChanged` and I don't see what can be improved"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-11T07:29:04.413",
"Id": "268869",
"Score": "0",
"Tags": [
"c#",
"configuration"
],
"Title": "Accessing and changing Application scope Settings from separate project"
} | 268869 |
<p>The following JSON</p>
<pre class="lang-json prettyprint-override"><code>{
"a": {
"b": {
"c":{
"d": [
{
"e": {
... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-11T07:37:21.960",
"Id": "268870",
"Score": "1",
"Tags": [
"ruby",
"json",
"hash"
],
"Title": "Unpack a flattened hash into Hash/JSON"
} | 268870 |
<p>Normally when a line ends with <code>-</code>, it means it should be joined differently.</p>
<p>For example, if we join lines of:</p>
<pre><code>The causal part of the competency definition is to distinguish between
those many characteristics that may be studied and measured about a per-
son and those aspects that a... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T04:42:58.103",
"Id": "530369",
"Score": "2",
"body": "I think a more precise definition of the problem statement would be helpful for readers and reviewers, so they know up-front what edge cases may or may not need to be handled. Fo... | [
{
"body": "<h3>Low hanging fruits</h3>\n<ul>\n<li><p>use a <a href=\"https://stackoverflow.com/questions/419163/what-does-if-name-main-do\">if_main guard</a> in your code. This means you can import it without the whole thing running each time you load it.</p>\n</li>\n<li><p>Adding functions is always a good thi... | {
"AcceptedAnswerId": "269076",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-11T13:13:26.550",
"Id": "268876",
"Score": "5",
"Tags": [
"python",
"python-3.x"
],
"Title": "Join Lines (considering `-` at the end of lines)"
} | 268876 |
<p>Since I met the <a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/out-parameter-modifier" rel="nofollow noreferrer"><code>out</code> keyword in C#</a>, I'm trying to find an equivalent in JS.</p>
<p>So, please take a look at the code and leave your opinions or suggestions about this... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-11T15:18:08.060",
"Id": "530337",
"Score": "0",
"body": "What do you mean by \"double checking\"? Why is #2 better than #1 - don't they both effectively have the same \"check that `number` contains a number, then do stuff with that num... | [
{
"body": "<p>None of these seem like a winner. I would do something like:</p>\n<pre class=\"lang-javascript prettyprint-override\"><code>function withParsed(string, success, error) {\n const number = parseInt(string, 10)\n if(!isNaN(number))\n return success(number)\n \n return error(string)\n... | {
"AcceptedAnswerId": null,
"CommentCount": "10",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-11T14:33:31.340",
"Id": "268878",
"Score": "0",
"Tags": [
"c#",
"javascript",
"comparative-review"
],
"Title": "C# 'out' keyword in JavaScript"
} | 268878 |
<p><strong>I am trying to determine the correctness of a helper method within my MaxHeap class.</strong></p>
<p>The goal of this helper method is, given the index of any node in the Max Heap, sink it to the correct level in the heap so that all of its children are greater than the node, and its parent is greater (essen... | [] | [
{
"body": "<h3>Verifying correctness</h3>\n<p>To verify the correctness of a program, you must verify all the paths of execution, <em>and</em> all the relevant variations of data. It's good to write unit tests for them. Consider these cases (from simpler to complex):</p>\n<ul>\n<li>the index is out of bounds</l... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-11T16:15:15.050",
"Id": "268880",
"Score": "1",
"Tags": [
"java",
"algorithm",
"heap",
"binary-tree"
],
"Title": "Sink algorithm in Max Heap Correctness"
} | 268880 |
<p>is there a more elegant way to do what the code below does without use "foreach"?
I am trying to load answers from questions but only the answers that contains a direct relation with an Appointment</p>
<pre class="lang-php prettyprint-override"><code>public function show(Request $request, Patient $patient)... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T15:30:14.693",
"Id": "530417",
"Score": "0",
"body": "Ahoy! Please [edit] to explain the relationships more thoroughly. Is there a one-to-many relationship between questions and answers? and also does an answer belong to an appointm... | [
{
"body": "<p>The solution below comes after rethinking the actual implementation of the business logic.</p>\n<p>Since one Appointment can have zero or many Answers, I do not need to relate Appointments with a Form.</p>\n<p>All I have to do is only save Answers with the reference of Question and Appointment.</p... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-11T18:01:59.903",
"Id": "268882",
"Score": "0",
"Tags": [
"php",
"laravel",
"eloquent"
],
"Title": "Eloquent eager loading deep nested relation with \"where\" condition"
} | 268882 |
<p>I found I need to loop through a list to create a brute force algorithm. Therefore, I decided to make a library, but to generalize the result by using a generator. There are three cases which is every single element, every pair of elements, and every triple of elements. The cases store a variable which contains the ... | [] | [
{
"body": "<p>What you are doing is basically equivalent to <a href=\"https://docs.python.org/3/library/itertools.html#itertools.product\" rel=\"nofollow noreferrer\">itertools.product</a>, you should check it out.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate... | {
"AcceptedAnswerId": "268918",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-11T18:50:06.573",
"Id": "268884",
"Score": "2",
"Tags": [
"python",
"python-3.x",
"generator"
],
"Title": "Library to Help Loop with Generators"
} | 268884 |
<p>I have changed the design of my library to help looping with generators. The new version uses iterables which allow a data structure or generator to be passed to the functions. The iterators are then yielded in a single element, a pair of values from the same iterator, or a triplet of values from the same iterator. ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-11T20:57:03.260",
"Id": "530350",
"Score": "0",
"body": "It is not duplicate since I did change the library so that a list can be used instead of only a generator."
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-11T20:19:49.633",
"Id": "268887",
"Score": "0",
"Tags": [
"python-3.x",
"algorithm",
"iterator"
],
"Title": "Library To Help Looping Redesign"
} | 268887 |
<p>I'm doing freeCodeCamp's Coding Interview Prep to improve my JavaScript skills. <a href="https://www.freecodecamp.org/learn/coding-interview-prep/rosetta-code/word-frequency" rel="nofollow noreferrer">This challenge</a> is called "Word Frequency", and is based on the <a href="https://rosettacode.org/wiki/W... | [] | [
{
"body": "<p>The code is easily readable and variables are well named. What you could do is have functions instead of lambdas, but that is just my personal preference. Also "wordSplit" is a function and would be a bit better named splitIntoWords(text) {...}</p>\n<p>From the reuse and maintenance pers... | {
"AcceptedAnswerId": "268904",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-11T21:32:28.590",
"Id": "268888",
"Score": "2",
"Tags": [
"javascript",
"algorithm",
"programming-challenge",
"strings",
"interview-questions"
],
"Title": "Find the 'n' m... | 268888 |
<p>So I came up with a "new" sorting algorithm:</p>
<pre class="lang-js prettyprint-override"><code>function indexSort(array, min, max) {
var newArray = Array.from({length:Math.abs(max-min)}, () => 0);
for (let i = 0; i < max; i++) {
if (array.includes(array[i])) {
newArray[a... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-11T22:37:07.350",
"Id": "530353",
"Score": "0",
"body": "Welcome to Code Review! I [changed the title](https://codereview.stackexchange.com/revisions/268889/2) so that it describes what the code does per [site goals](https://codereview... | [
{
"body": "<p>I'll try to summarize what's been said in the comments into an answer and add my two cents to it.</p>\n<p>First of all I suppose this was made because you had an idea on how to sort numbers and just tried implementing it to see how it'd work out. Nothing wrong with that, but as has been said said,... | {
"AcceptedAnswerId": "268898",
"CommentCount": "11",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-11T22:20:47.840",
"Id": "268889",
"Score": "0",
"Tags": [
"javascript",
"performance",
"sorting",
"ecmascript-6"
],
"Title": "custom array sorting algorithm"
} | 268889 |
<p>I'm a newbie. I'm at <a href="https://automatetheboringstuff.com/chapter4/" rel="noreferrer">Chapter 4 of Automate the Boring Stuff with Python</a>.</p>
<blockquote>
<p><strong>Comma Code</strong></p>
<p>Say you have a list value like this:</p>
<p><code>spam = ['apples', 'bananas', 'tofu', 'cats']</code></p>
<p>Writ... | [] | [
{
"body": "<h1>Return values</h1>\n<pre class=\"lang-py prettyprint-override\"><code>def list_to_string(some_list):\n new_string = ''\n if not some_list:\n return ''\n ...\n</code></pre>\n<p>Why are you returning <code>''</code> here? You could return <code>new_string</code> instead, since you'... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-11T22:56:03.003",
"Id": "268890",
"Score": "15",
"Tags": [
"python",
"beginner",
"python-3.x",
"strings"
],
"Title": "Comma Code, Project from \"Automate the Boring Stuff with Py... | 268890 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.