body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I want some opinions about my code that implements store and update for a Laravel 8 form request. The <code>make</code> function is for storing the data and the <code>update</code> function is for updating the data.</p> <pre><code>&lt;?php namespace App\Http\Requests; use App\Models\Admin; use Illuminate\Foundati...
[]
[ { "body": "<blockquote>\n<pre><code>public function authorize()\n{\n return true;\n}\n</code></pre>\n</blockquote>\n<p>Should all users be able to perform such actions? Typically this method would ensure that the user has a certain role (e.g. admin).</p>\n<hr />\n<blockquote>\n<pre><code> if (request()-&g...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-13T14:53:26.060", "Id": "267970", "Score": "1", "Tags": [ "php", "validation", "laravel", "authorization" ], "Title": "Placing store and update logic in Laravel 8 form request" }
267970
<p>I implemented a solution for the problem below, but its performance is not good. I know I can find the solution online, I'm trying to understand what is causing the bad performance in <code>my code</code></p> <p>Problem: You have an undirected, connected graph of <span class="math-container">\$n\$</span> nodes label...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-13T15:37:19.227", "Id": "528362", "Score": "1", "body": "Many posts on this site might be about graph algorithms and a larger number might be about bad performance. Please [edit] to the site standard, which is for the title to simply s...
[]
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-13T15:23:14.493", "Id": "267971", "Score": "1", "Tags": [ "javascript", "performance", "graph" ], "Title": "Bad performance of a Graph Algorithm" }
267971
<p>I have an use case where I want to see how many slots have been used for a date in a restaurant. The slot can be deducted based either number of diners or per booking. Also I have to cater a case where a booking is made for multiple dates and then i have to consider those dates as well when checking how many slots h...
[]
[ { "body": "<h3>What made me stumble when reading</h3>\n<p>Your use-cases and problem description reads almost fluently and most of it sounds plausible.</p>\n<p>Though I rarely found names or words from your narrative in your code. Moreover, it sounds rather technically.</p>\n<p>Sometimes you don't need to trans...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-13T15:28:13.280", "Id": "267972", "Score": "1", "Tags": [ "java" ], "Title": "Java grouping based on date and counting" }
267972
<p>I have a button <code>btnSearch</code> and the event handler <code>btnSearch_Click</code> inside my asp.net web application, using web forms.</p> <p>(certain variables/controls have been renamed to generic variables)</p> <pre><code>protected void btnSearch_Click(object sender, EventArgs e) { string n1, n2, n3; ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-13T15:51:17.577", "Id": "528363", "Score": "0", "body": "Which technology is this? Web forms? Please be specific." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-13T15:54:35.720", "Id": "528364", "S...
[ { "body": "<p>I am not a web guy, so I will not answer the architecture part here.</p>\n<p>You could create a helper method to create urls with query strings:</p>\n<pre class=\"lang-cs prettyprint-override\"><code>public static string CreateUrl(\n string url, params (string name, string value)[] queryParams)...
{ "AcceptedAnswerId": "267977", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-13T15:35:19.057", "Id": "267973", "Score": "2", "Tags": [ "c#", "asp.net" ], "Title": "Best Practice for Button Event Handler" }
267973
<p>This question is an improvement of this one here: <a href="https://codereview.stackexchange.com/questions/267957/implementing-a-unique-ptr-ppp-stroustrup-exercise">Implementing a unique_ptr - PPP Stroustrup exercise</a></p> <p>Here's my new code, following the suggestions by @JDługosz.</p> <ul> <li><p>I agree with t...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-13T19:53:19.120", "Id": "528384", "Score": "5", "body": "Is the code cut off? It seems incomplete." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-13T20:33:57.983", "Id": "528388", "Score": "1", ...
[ { "body": "<p>Your move assignment leaks memory:</p>\n<pre class=\"lang-cpp prettyprint-override\"><code>Unique_Ptr&lt;int&gt; foo();\n\n...\n\nUnique_Ptr&lt;int&gt; p{new int{2}};\np = foo(); // &lt;- leaks the original int\n</code></pre>\n<p>I recommend you to add a <code>swap(Unique_Ptr ...
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-13T17:31:02.727", "Id": "267976", "Score": "3", "Tags": [ "c++", "reinventing-the-wheel", "c++14", "pointers" ], "Title": "Improving my implementation of a unique_ptr - PPP Strou...
267976
<p>I have been trying to implement a version of the Maybe functor in Typescript. I'm looking for feedback on whether I can improve the type safety of my implementation. I'm not particularly happy that types like <code>Just&lt;void&gt;</code> or <code>Nothing&lt;number&gt;</code> are not ruled out by the type-system, bu...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-13T20:34:58.077", "Id": "528389", "Score": "0", "body": "Ruling out `Nothing<number>` is quite simple: Make `Nothing` a non-generic object instead of a generic class. Then there can only ever be one `Nothing`." } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-13T18:24:14.700", "Id": "267978", "Score": "0", "Tags": [ "functional-programming", "typescript", "monads", "optional" ], "Title": "Typescript Maybe functor" }
267978
<p>I've been working on a collection of few open-source java libraries related to Guice. They are a collection of classes that I was previously copy/pasting/customizing across subsequent projects I was working on. Recently I've found some time to polish them a bit and put on GitHub, so maybe others will find them usefu...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-14T22:41:09.963", "Id": "528506", "Score": "0", "body": "About your code style: you have code style very different from the common Java code style, and as it is clearly not created to be useful to anybody but yourself, I wonder why I w...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-14T01:53:20.647", "Id": "267982", "Score": "0", "Tags": [ "java", "guice", "grpc" ], "Title": "java lib to easily build Guice scopes and gRPC scopes lib built on top of it" }
267982
<p>I'm actually developing bot in discord.py and the longer I'm developing this, the more often I'm asking myself 'Is this code well-organized? How could I improve this to make easier to understand this code in future?'</p> <p>There's code:</p> <pre><code>from reddit_memes import * from new_video_checker import * from ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-14T18:38:24.557", "Id": "528470", "Score": "0", "body": "FYI, about dpy: https://gist.github.com/Rapptz/4a2f62751b9600a31a0d3c78100287f1" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-14T19:18:16.057", ...
[ { "body": "<p>You shouldn't use comments to describe your function, but <a href=\"https://www.python.org/dev/peps/pep-0257/\" rel=\"nofollow noreferrer\">docstrings.</a></p>\n", "comments": [ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-14T10:31:50.603", "Id": "...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-14T08:50:14.683", "Id": "267987", "Score": "4", "Tags": [ "python", "python-3.x", "discord.py" ], "Title": "My DiscordBot project" }
267987
<p>The following code works perfectly. It just works very slowly. Is there any way to speed up/optimize this code?</p> <p>I think its the amount of loops but I am unable to figure out how to reduce the number of loops without hampering the functionality of the code.</p> <p>'''</p> <pre><code>Sub inland() Dim sort As W...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-14T11:25:18.860", "Id": "528423", "Score": "3", "body": "If you'll take a moment to take the [tour], you'll note that your post (especially the title) is supposed to tell us _what_ your code does in addition to what you'd like to have ...
[ { "body": "<p>Usually you can improve performance by copying the values from the sheet to an array, processing the array and then copying the values back to the sheet.</p>\n<pre class=\"lang-vb prettyprint-override\"><code>Option Explicit\nSub inland3()\n\n Dim ws As Worksheet\n Dim colBuch As Long, colNa...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-14T09:47:38.073", "Id": "267990", "Score": "-3", "Tags": [ "vba", "excel" ], "Title": "How to reduce the number of loops?" }
267990
<p>I got a number that can range be either 10, 20, 30, 40... up until 100.</p> <p>I'd like to make an array from that number. The array should be structured as follows:</p> <p>If the number is <code>10</code>, the array should be: <code>[0, 1, 2, 3 ... 10]</code></p> <p>If the number is <code>20</code>, the array shoul...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-14T14:38:28.460", "Id": "528440", "Score": "3", "body": "To anyone in the review queue: only the new suggested code seems to be working incorrectly. The original is claimed to be working. Please leave a comment if you think otherwise."...
[ { "body": "<p>The properly working code had a <code>for</code> loop. To minimize operations visually, we could use <code>Array.from()</code> method (see <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from\" rel=\"nofollow noreferrer\"><code>Array.from()</code> d...
{ "AcceptedAnswerId": "268014", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-14T11:53:04.660", "Id": "267994", "Score": "0", "Tags": [ "javascript", "array" ], "Title": "How to create an array with 10 elements based on a maximum value" }
267994
<p>recently I have been trying to educate myself on REST APIs.</p> <p>As a part of that, I have created a small project using FastAPI in python and I would love to hear some feedback about it.</p> <p>When I wrote this, I didn't take into consideration any design pattern, and honestly, I almost knew nothing about them -...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-15T09:48:54.887", "Id": "528528", "Score": "4", "body": "I have rolled back your last edit. Please don't change or add to the code in your question after you have received answers. See [What should I do when someone answers my question...
[ { "body": "<p>I'm not intimately familiar with FastAPI, but</p>\n<pre><code>raise HTTPException(status_code=status.HTTP_200_OK,\n detail=&quot;Welcome to PokeAPI&quot;)\n</code></pre>\n<p>is surely not the best way to return a string with a success code. Exceptions are exceptional. You should...
{ "AcceptedAnswerId": "268000", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-14T14:08:02.377", "Id": "267999", "Score": "5", "Tags": [ "python", "python-3.x", "api" ], "Title": "FastAPI project - CRUD operations on database" }
267999
<p>DbRecordset is a new class added to a <a href="https://pchemguy.github.io/SecureADODB-Fork/" rel="nofollow noreferrer">fork</a> of the <a href="https://rubberduckvba.wordpress.com/2020/04/22/secure-adodb/" rel="nofollow noreferrer">SecureADODB</a> library, which wraps the ADODB.Recordset class. It complements the fu...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-14T18:47:36.333", "Id": "528474", "Score": "1", "body": "\"It appears, however, that the actual number is not available from the recordset object, necessitating the use of backend-specific sources.\"\n\nActually there is a way to find ...
[ { "body": "<h3>Some ADODB pointers</h3>\n<h4>Querying the data</h4>\n<p>Keep in mind that a query may return an empty recordset. OpenScalar accesses the first record without any checks. Verify that RecordCount &gt; 0 (CSV backend, for example, ignores the MaxRecords attribute, so the recordset returned by OpenS...
{ "AcceptedAnswerId": "268071", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-14T16:08:51.233", "Id": "268004", "Score": "0", "Tags": [ "object-oriented", "vba", "adodb" ], "Title": "DbRecordset: Updatable recordset with transaction and affected rows count...
268004
<p>I made a Sudoku Solver after following some tutorials. Then I made a Sudoku generator and everything works. I also used classes to make it look more organized.</p> <p>I wanted to know what I can do better to optimize my code.</p> <p>I would like to make it faster and more readable but not at the cost of performance....
[]
[ { "body": "<p>I am not touching your <code>generate_board</code>. I had actually done similar kinda thing a few months back. Here's the code. It's faster if you exchange speed for memory.</p>\n<pre><code>board = [\n [8, 0, 0, 0, 0, 0, 0, 0, 0],\n [0, 0, 3, 6, 0, 0, 0, 0, 0],\n [0, 7, 0, 0, 9, 0, 2, 0, ...
{ "AcceptedAnswerId": "268008", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-14T17:34:59.070", "Id": "268007", "Score": "4", "Tags": [ "python", "performance", "classes", "sudoku" ], "Title": "Sudoku Solver and Generator in Python" }
268007
<p>According to an online judge, the limit has been exceeded. Could someone help me optimize my solution for the Greatest Common Divisor of <code>n</code> numbers:</p> <pre><code>#include &lt;iostream&gt; #include &lt;algorithm&gt; using namespace std; int main() { int n; cin &gt;&gt; n; int a[n]; for(...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-14T19:48:33.750", "Id": "528489", "Score": "0", "body": "Is this really a TLE problem or did the online judge misreport a compilation failure as TLE?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-14T20:45...
[ { "body": "<h1>Avoid non-standard functions</h1>\n<p>Instead of <code>__gcd()</code>, which is a non-standard function, use <a href=\"https://en.cppreference.com/w/cpp/numeric/gcd\" rel=\"nofollow noreferrer\"><code>std::gcd()</code></a>.</p>\n<h1>Avoid unnecessarily storing data</h1>\n<p>There is no reason to ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-14T19:29:21.437", "Id": "268012", "Score": "2", "Tags": [ "c++", "time-limit-exceeded" ], "Title": "GCD of n numbers" }
268012
<p>It's a simple program, the user is prompted to enter number of variables.</p> <p><a href="https://i.stack.imgur.com/K0Ymc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K0Ymc.png" alt="enter image description here" /></a></p> <p>Then the user is prompted to enter coefficients and constants. That ...
[]
[ { "body": "<ul>\n<li>Always put your imports at the top of the file</li>\n<li>Avoid importing splat <code>*</code>; either import specific symbols, or import the module (optionally with an alias) like <code>import tkinter as tk</code> and refer to symbols within its namespace like <code>tk.Button</code>.</li>\n...
{ "AcceptedAnswerId": "268027", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-14T23:21:51.753", "Id": "268015", "Score": "4", "Tags": [ "python", "tkinter" ], "Title": "Make a Simultaneous linear equation solver using Tkinter GUI" }
268015
<p>I am attempting to plot histograms for batch of images in Matlab. The file structure of input images and the experimental implementation are listed as below.</p> <ul> <li><p>File structure of input images</p> <p>The matlab code <code>HistogramPlotting.m</code> file is placed in the project root folder and there are ...
[]
[ { "body": "<p>There's not a whole lot of things to comment on this code. My biggest gripe with it is the comparison of a boolean value with <code>false</code>. I see this a lot, it is a common &quot;mistake&quot;. There always exist the following two equivalences, if <code>b</code> is a logical (Boolean) value:...
{ "AcceptedAnswerId": "268033", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-14T23:21:58.440", "Id": "268016", "Score": "1", "Tags": [ "file", "image", "file-system", "matlab", "data-visualization" ], "Title": "Batch generating histograms of image...
268016
<p>I'm currently reading about &quot;Lean controllers&quot;/&quot;Business logic on services&quot; and trying to refactor some legacy code. However I am struggling to apply what is taught in the tutorials to real code.</p> <p>Online examples are simple. But in real code, I have controllers that need to use filtering, s...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-15T07:42:23.543", "Id": "528524", "Score": "0", "body": "Hi. Welcome to Code Review! It is going to be difficult to give a meaningful review of just two functions. Consider giving more context. E.g. the views and models associated ...
[ { "body": "<p>What you are trying to achieve can be done with <a href=\"https://github.com/spatie/laravel-query-builder\" rel=\"nofollow noreferrer\">https://github.com/spatie/laravel-query-builder</a>.</p>\n<p>If you are to work on something custom, you'd want to re-create (or extend) what <code>laravel-query-...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-15T07:25:27.967", "Id": "268021", "Score": "1", "Tags": [ "php", "mvc", "laravel", "controller", "eloquent" ], "Title": "'Lean controller'/'Business logic on service' and fil...
268021
<p>I have this array with dates. All the dates are checked before creating the array with <code>preg_match</code> and <code>check_dates</code>.</p> <blockquote> <p>GoodDates (<br /> [0] =&gt; 2021-09-01<br /> [1] =&gt; 2021-09-02<br /> [2] =&gt; 2021-09-03<br /> [3] =&gt; 2021-09-06<br /> [4] =&gt; 2021-09-07<br /> [5...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-16T09:00:50.453", "Id": "528577", "Score": "0", "body": "With all your answers \n\n - I can delete my `checkdate` loop.\n - I have a better comprehension of how to sort a date array and some differents methods to do that.\n\nThanks to ...
[ { "body": "<p>Your date format is <code>Y-m-d</code> which means that you can safely sort these values as simple strings.</p>\n<p><code>rsort()</code> is all that you require. A native function will always be more concise and efficient than a custom (non-native) function.</p>\n<p>If your date string were not z...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-15T13:54:12.390", "Id": "268025", "Score": "2", "Tags": [ "php", "array", "sorting" ], "Title": "Sort array of dates" }
268025
<p>For a fake interview I decided to write Hangman. The first question I have is when reviewing someone's code for a job interview is it more important to write something short and sweet that gets the job done, or to write something using Dependency Injection and small OOP modules?</p> <p>Attached is a small example I ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-15T22:40:18.893", "Id": "528552", "Score": "1", "body": "short answer, it depends on the recruiter and the skills that they're looking for. Some would focus on following OOP concepts, design patterns, and other standards. Others will ...
[ { "body": "<p>Here are my observations</p>\n<h3><code>ValidGuess</code></h3>\n<ul>\n<li>I would suggest to either call it <code>ValidateGuess</code> or <code>IsGuessValid</code></li>\n<li>I would also suggest to use <a href=\"https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expression...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-15T16:59:18.847", "Id": "268028", "Score": "2", "Tags": [ "c#", "interview-questions", "hangman" ], "Title": "Fake Interview Scenario: Hangman" }
268028
<p>Imagine you want to reserve a classroom over several days. You get a schedule, from the school, telling you when a certain classroom is still free. To make it easy for your students, you want to reserve the classroom at the same time every day. Regrettably the schedule is long and complex, and you cannot figure out ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-18T00:33:32.427", "Id": "528669", "Score": "0", "body": "Why cannot I find in your code where specific slots are filled? I can see `$openTimeslots` at the top of the snippet, but where is the declaration of what is used? Why does the...
[ { "body": "<h2>General comments</h2>\n<p>This code looks well-written and after playing with it a few times I feel I grok it. Initially it seemed counter-intuitive to use the constant for <em>free</em> to denote timeslots that were <em>NOT</em> open but the comments next to the constants make it clearer.</p>\n<...
{ "AcceptedAnswerId": "268139", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-15T17:37:48.907", "Id": "268029", "Score": "3", "Tags": [ "php", "datetime" ], "Title": "Find common timeslots for consecutive days" }
268029
<p>I recently made a new project for <em>Chutes and Ladders</em> (the Hasbro version of <a href="https://en.wikipedia.org/wiki/Snakes_and_ladders" rel="nofollow noreferrer">Snakes and ladders</a>) and it is located here: <a href="https://github.com/vchittar/ChutesAndLadders" rel="nofollow noreferrer">https://github.com...
[]
[ { "body": "<p>thanks for sharing your code.</p>\n<h1>What I like</h1>\n<ul>\n<li>Dependency Injection</li>\n<li>Naming according to the conventions</li>\n<li>use of JVM provided fuctionality (<code>Collections.*()</code>)</li>\n</ul>\n<h1>what I'd improve</h1>\n<h2>OOP stuff</h2>\n<h3>Obsessive Interface creati...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-15T21:11:06.153", "Id": "268034", "Score": "2", "Tags": [ "java", "game", "spring", "maven" ], "Title": "Simple game of Chutes and Ladders" }
268034
<p>I'm reading a CSV using Haskell. I'm not sure if this is the appropriate way to do it.</p> <p>This is what I'm doing:</p> <ol> <li>Read rows from a CSV -&gt; return lazy byte string</li> <li>Parse the headers and rows from the CSV to a tuple -&gt; (headers, [Stock])</li> <li>Remove the headers -&gt; [Stock]</li> <li...
[]
[ { "body": "<p>Looks great overall, especially how you've included instructions on running it, even with sample data, makes this a great submission.</p>\n<hr />\n<p>The first thing I've noticed, is the error handling for opening files. <code>parseCsv</code> for example checks for the existence of the file - tha...
{ "AcceptedAnswerId": "268187", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-16T01:02:50.247", "Id": "268038", "Score": "4", "Tags": [ "haskell", "functional-programming", "csv" ], "Title": "Reading a CSV file using Haskell" }
268038
<p>My project has grown for a year and now comprises of 19 standard modules, 7 class modules 11 forms. Some of the forms appear to freeze when called but, in fact, they are just slow to respond, taking a couple of minutes, regardless of what is clicked, e.g. just a change of focus or triggering an event procedure. The ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-16T04:06:15.493", "Id": "528561", "Score": "0", "body": "Do you make your Excel file available?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-16T06:45:55.517", "Id": "528562", "Score": "0", "b...
[ { "body": "<p>The problem I encountered turned out to be unrelated to the code. Instead, interruption was caused by Excel's <em>AutoSave</em> function, possibly in tandem with a weak Internet connection.</p>\n<p>At this time I still don't know if simply turning off <em>AutoSave</em> would cure the problem. What...
{ "AcceptedAnswerId": "270036", "CommentCount": "11", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-16T01:10:52.253", "Id": "268039", "Score": "2", "Tags": [ "performance", "vba", "excel" ], "Title": "Forms to enter trading information" }
268039
<p>I have implemented Sieve of Eratosthenes in Java as follows. Is there a way I can modify the below code to make it more efficient?</p> <p>The current execution time is</p> <blockquote> <p>0.8481224 seconds</p> </blockquote> <pre><code>import java.util.LinkedList; public class LinkedListEx { public static void ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-16T08:47:06.770", "Id": "528574", "Score": "2", "body": "Whenever you're interested in execution time improvements, use a profiler tool to find out what parts of your program take the majority of time." }, { "ContentLicense": "...
[ { "body": "<h2>Datatype improvements</h2>\n<p>Of all the available <code>Collection</code> implementations, you chose to use <code>LinkedList</code> for your <code>ll</code> variable (by the way, <code>candidatePrimes</code> would be a better name). As you only use the <code>add(Object)</code> and the <code>rem...
{ "AcceptedAnswerId": "268046", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-16T08:20:20.233", "Id": "268043", "Score": "5", "Tags": [ "java", "performance", "sieve-of-eratosthenes" ], "Title": "Implementation of Sieve of Eratosthenes in Java" }
268043
<p>I've written a simple JS that takes care to animate an icon.</p> <p>At first I wrote it quickly and without paying attention to any kind of optimization:</p> <pre><code>import '../js/core/sidenav.js'; const SIDENAV_ITEM_USER = document.getElementById('sidenav-item-user'); const SIDENAV_ITEM_SEARCH = document.getEle...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-16T17:10:53.410", "Id": "528595", "Score": "1", "body": "All that isn't really necessary. It can be done much simpler with one line of CSS: `[aria-expanded=\"true\"] .arrow { transform: rotate(180deg) }`." }, { "ContentLicense"...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-16T12:32:24.883", "Id": "268052", "Score": "2", "Tags": [ "javascript", "performance", "html", "html5", "animation" ], "Title": "JS icons animation" }
268052
<p>I have written a simple server to host my page and CSS (CSS file is 22KB).</p> <p>Using sockets and TCP. Can any one please review it and give feedback on how can I make my server reliable using TCP and other C related feedback.</p> <pre><code>#include &lt;unistd.h&gt; #include &lt;stdio.h&gt; #include &lt;sys/socke...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-16T16:16:13.457", "Id": "528593", "Score": "0", "body": "question code edited" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-16T16:56:27.780", "Id": "528594", "Score": "0", "body": "Sendfile fu...
[ { "body": "<p>Some basic code-hygiene:</p>\n<ul>\n<li><p>Be consistent with formatting. Using different numbers of spaces for indenting is very sloppy. Personally I'd suggest &quot;tabs for indent, and spaces for alignment&quot;, but what really matters is consistency.</p>\n</li>\n<li><p>Don't insert random gap...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-16T16:12:47.433", "Id": "268053", "Score": "1", "Tags": [ "c", "linux", "socket", "server", "tcp" ], "Title": "Server hosting single page site using TCP sockets in C" }
268053
<p>I want to convert string to object array. Suppose I have following string.</p> <pre><code>const str = &quot;someValue,display&quot;; </code></pre> <p>I want to convert it like following.</p> <pre><code>[{ columnVal: &quot;someValue&quot;, display: true }] </code></pre> <p>if it's display then I want value as tru...
[]
[ { "body": "<p>This can be simplified by using <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment\" rel=\"nofollow noreferrer\">destructuring assignment</a> into an array, followed by simple assignment into the object <code>obj</code>. While it may not ...
{ "AcceptedAnswerId": "268057", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-16T16:46:54.110", "Id": "268054", "Score": "1", "Tags": [ "javascript", "strings", "array" ], "Title": "Convert string to object array javascript" }
268054
<p>I previously posted some code I've been working on and had a <a href="https://codereview.stackexchange.com/a/267844/243815">fantastic answer</a>, but as I didn't post the full code I was then unable to bring it all together using the much faster numpy implementation, so a review of the full code is much appreciated....
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-16T17:28:22.770", "Id": "528600", "Score": "1", "body": "Is C on the table? If not, why not?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-16T18:05:19.090", "Id": "528601", "Score": "0", "body...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-16T16:58:35.670", "Id": "268055", "Score": "1", "Tags": [ "python", "python-3.x", "numpy" ], "Title": "Using arrays more effectively with numpy" }
268055
<p>I have a collection of strings, all of which are three characters in length:</p> <pre><code>string[] test = { &quot;abc&quot;, &quot;bbc&quot;, &quot;cbc&quot;, &quot;aac&quot;, &quot;bac&quot;, &quot;ccc&quot; }; </code></pre> <p>I want to determine which <code>char</code> is present as the center character in the ...
[]
[ { "body": "<p>You don't need to use a dictionary. Instead, order by the count directly:</p>\n<pre class=\"lang-cs prettyprint-override\"><code>var champion = test.GroupBy(t =&gt; t[1])\n .OrderByDescending(g =&gt; g.Count())\n .First();\n</code></pre>\n<p>Note that this might...
{ "AcceptedAnswerId": "268059", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-16T17:27:08.783", "Id": "268058", "Score": "1", "Tags": [ "c#", "strings", "linq", "collections" ], "Title": "Is there a way to simplify getting the character that appears th...
268058
<p>I am doing this problem:</p> <blockquote> <p>You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad. Su...
[]
[ { "body": "<p>The problem is the famously known &quot;guess the number game&quot;. If we change the terminology of <code>isBadVersion</code> to:</p>\n<blockquote>\n<p>isBadVersion returns True if your guess is too high, and false if your number is too low.</p>\n</blockquote>\n<p>Then the challenge becomes obvio...
{ "AcceptedAnswerId": "268064", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-16T20:45:36.897", "Id": "268063", "Score": "3", "Tags": [ "python", "time-limit-exceeded" ], "Title": "Identify bad versions program" }
268063
<p>Suppose you have an <code>IO (Either String (String, [Int]))</code> and you want to filter the <code>[Int]</code>.</p> <p>Let's say we want to use the following filter:</p> <pre class="lang-hs prettyprint-override"><code>:t filter even Integral a =&gt; [a] -&gt; [a] </code></pre> <p>As far as I understand we need to...
[]
[ { "body": "<p>While <code>(fmap . fmap . fmap . filter) even</code> is certainly possible, there is a function for <code>Either</code> in <code>Control.Arrow</code> called <code>right</code>. The same module also contains <code>second</code>, which works on the second part of a pair.</p>\n<pre class=\"lang-hs p...
{ "AcceptedAnswerId": "268072", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-17T02:05:50.927", "Id": "268067", "Score": "4", "Tags": [ "haskell", "functional-programming" ], "Title": "Is there a better way to apply a filter over an Either right value?" }
268067
<p>I'm seeing a React course, we were studying fundamentals of javascript for a while. We saw how to access the content of an object and display it in console. My solution for the problem of displaying an unknown object was the following:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-18T18:24:03.887", "Id": "528703", "Score": "1", "body": "Most browsers already pretty-log nested objects in standard formats with collapseable tabs for large structures. There's also `console.log(JSON.stringify(obj, null, 2))`. Builtin...
[ { "body": "<p>Try this <code>testObject</code>. You may want to do something to test for recursion, e.g. an array or map that tracks objects that you have already seen.</p>\n<p><div class=\"snippet\" data-lang=\"js\" data-hide=\"false\" data-console=\"true\" data-babel=\"false\">\r\n<div class=\"snippet-code\"...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-17T02:38:23.883", "Id": "268068", "Score": "1", "Tags": [ "javascript", "performance", "recursion" ], "Title": "Recursively unpacking a javascript object" }
268068
<p>I develop a <a href="https://en.wikipedia.org/wiki/Content_management_system" rel="nofollow noreferrer">CMS</a>-agnostic PHP formatted HTML-CSS &quot;contact now&quot; panel, sticky in the bottom of a website screen.<br> The code is tested and works as can be seen from the following image.<br> I ask a review of the ...
[]
[ { "body": "<p>The CSS looks good to me, although I would reconsider using <code>z-index: auto;</code>. I assume you want your <em>contact-now</em> panel to always appear on top of other content, even if it is not included as the last element? In that case a high valid for <code>z-index</code> is needed. If you ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-17T05:32:43.647", "Id": "268069", "Score": "-1", "Tags": [ "php", "html", "css" ], "Title": "PHP processed, HTML-CSS, CMS-agnostic, contact now panel" }
268069
<p>I'm pretty new to python but after watching Mr Robot I felt inspired to make a CLI portscanner. With all the fancy console outputs you see in movies like a progress bar.</p> <p>It's finished and works nicely however I am not very happy with having to write twice <code>global host_IP</code> in <code>main()</code> and...
[]
[ { "body": "<blockquote>\n<p>It's finished and works nicely however I am not very happy with having\nto write twice global host_IP in main() and scan_tcp().</p>\n</blockquote>\n<p>I don't really understand the issue. The variable already has global scope since you assign it a None value on top of your code. Then...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-17T11:15:01.213", "Id": "268075", "Score": "2", "Tags": [ "python", "python-3.x", "multithreading" ], "Title": "Avoid global variable due to executor.map()" }
268075
<p>I had a coding assignment to write a Rock Paper Scissors game. The main task is not to show a solution but rather to test the coding style. The rules are such:</p> <h2>Problem:</h2> <p>rock is &quot;O&quot;, paper is &quot;[]&quot;, scissors is &quot;8&lt;&quot;. George and John play RPC(rock, paper and scissors) a ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-17T12:16:33.290", "Id": "528625", "Score": "1", "body": "Where is the code for the output? As there seems to be a bug in it. `George plays O John plays O the game outcome is O[] George points: 0` Should be `George plays O John plays []...
[ { "body": "<ul>\n<li>You should not bake hand literal strings in your logic; instead refer to your constants or better yet an <code>Enum</code></li>\n<li>You should try to reduce the amount of class state floating around. <code>index</code> and <code>current_hand</code> for instance are not good class members; ...
{ "AcceptedAnswerId": "268087", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-17T11:27:27.540", "Id": "268076", "Score": "1", "Tags": [ "python", "performance", "algorithm", "object-oriented", "programming-challenge" ], "Title": "Rock paper scissor...
268076
<p>I'm new at coding and I'm learning it on freeCodeCamp, that's the most hardest problem that I have already do at that site. After finishing it (after I vibrated as if I had won a world competition of something) I go straight to the internet to visualize another resolutions and try to understand and get better on cod...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-17T13:05:38.607", "Id": "528628", "Score": "0", "body": "I would start by creating a habit of trying to come up with good Variable names as this will help u a lot down the line when debugging. It also helps other people to read it in S...
[ { "body": "<p>First thing that stands out is that your function is 140 line long, which is just too much. You have put the comments in, which is good, but it would be simpler if you extracted that piece of code into a function.</p>\n<p>This for loop does three things:\nFilters the cash for return, calculates th...
{ "AcceptedAnswerId": "268147", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-17T12:56:29.233", "Id": "268078", "Score": "1", "Tags": [ "javascript", "beginner", "calculator" ], "Title": "JavaScript change calculator" }
268078
<p>I have a typescript function that executes an array of actions on a given string value. This is the code:</p> <pre><code> processValue(value: string, actions: Action[]): any { actions?.forEach((action: Action) =&gt; { switch (action.type) { case ActionType.Append: { ...
[]
[ { "body": "<p>I think that you are trying to create a pipe. Something like this would probably work:</p>\n<pre><code>interface Action {\n execute(value: string): string\n}\n\nclass AppendAction implements Action {\n constructor(private appendText: string) {}\n\n execute(value: string) {\n return value + t...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-17T14:00:01.013", "Id": "268079", "Score": "0", "Tags": [ "object-oriented", "design-patterns", "typescript", "visitor-pattern", "strategy-pattern" ], "Title": "Refactor type...
268079
<p>I was wondering if there is anything that I could do to make my code look cleaner and more descriptive for educational purposes?</p> <pre class="lang-py prettyprint-override"><code>def quick_sort(array, start, end): if start &lt; end: pivot_index = partition(array, start, end) quick_sort(array, s...
[]
[ { "body": "<p>Code is clear and straight forward to read. However, there are two assumptions here</p>\n<ol>\n<li>It will be used with data types for which &quot;&lt;=&quot; operation is defined. It is good idea to extract this part comparator and let caller decide how two members should be compared.</li>\n<li>a...
{ "AcceptedAnswerId": "268096", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-17T14:27:59.213", "Id": "268083", "Score": "3", "Tags": [ "python", "quick-sort" ], "Title": "Recursive quick sort in python" }
268083
<p>I wrote an implementation of the Linked list data structure. I mostly did this because it's the simplest collection data structure (at least the simplest to implement), and I wanted to practice implementing <code>IEnumerable&lt;T&gt;</code> and <code>IEnumerator&lt;T&gt;</code>. I also wanted to play around with gen...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-17T18:09:23.033", "Id": "528644", "Score": "1", "body": "The `ToString` method is very inefficient. Use either `string.Join` or `StringBuilder` instead of string concatenation." }, { "ContentLicense": "CC BY-SA 4.0", "Creat...
[ { "body": "<ul>\n<li>The <code>IEnumerator&lt;T&gt;.Current</code> property must have only a getter. I.e., you are not allowed to change the <code>Current</code> value from outside. Only <code>MoveNext()</code> and <code>Reset()</code> are allowed.\n<pre class=\"lang-cs prettyprint-override\"><code>public TData...
{ "AcceptedAnswerId": "268086", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-17T14:45:58.130", "Id": "268084", "Score": "0", "Tags": [ "c#", "beginner", ".net", "linked-list", "reinventing-the-wheel" ], "Title": "Linked List Implementation in C#" ...
268084
<p>We have been given two sorted arrays and a number K . We have to merge the two sorted arrays in the sorted manner and return the element at the Kth position.</p> <ul> <li>My approach is to use two variables which will tell us where are we in the two arrays.</li> <li>Start comparing arr1[arr1_index] with arr2[arr2_i...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-17T18:28:04.327", "Id": "528647", "Score": "2", "body": "Your title and function signature sound like you only need to find the \"kth element\", but your text says you have to merge the arrays. Which one is it?" }, { "ContentLi...
[ { "body": "<h3>Length is a property of the array</h3>\n<blockquote>\n<pre><code> static int KthElementInTwoArrays(int[] arr1,int arr1_length, int[] arr2, int arr2_length,int k){\n</code></pre>\n</blockquote>\n<p>It is unnecessary to pass the array lengths separately. In Java, the length is a property of the...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-17T18:23:00.440", "Id": "268090", "Score": "1", "Tags": [ "java", "algorithm", "array", "sorting", "mergesort" ], "Title": "Find Kth Element in the merged two sorted arrays?"...
268090
<p>This is my first day coding, and I need help with sorting a table in ascending/descending order. The idea is that when a column is clicked it will sort in ascending order, and then it is clicked again it will sort in descending order, then repeat.</p> <p>This is the function I have created so far.</p> <pre><code> ...
[]
[ { "body": "<p>You don't need a library or to implement your own sort routine. <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort\" rel=\"nofollow noreferrer\">Sorting</a> is built into arrays.</p>\n<pre><code>document.getElementById(&quot;usersId&quot;).rows.s...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-17T18:41:10.287", "Id": "268091", "Score": "0", "Tags": [ "javascript", "performance", "beginner", "sorting", "dom" ], "Title": "Sort table with ascending or descending order...
268091
<p>My teacher gave us this game to make. basically, the computer needs to generate randomly 5 letters and there would be 5 players if the player guesses the correct letter given by the computer It would print &quot;good job&quot; else &quot;good luck next time&quot;, I would appreciate it if you could make my code a bi...
[]
[ { "body": "<p>My first feedback is that this is an incredibly stupid, un-fun game. Not your fault, but come on here teachers. It's not that hard to make an actually fun game that beginners can write.</p>\n<p>Please clarify whether you are using Python 2 or Python 3 when asking for review. I'm going to assume Py...
{ "AcceptedAnswerId": "268111", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-17T20:45:52.637", "Id": "268093", "Score": "4", "Tags": [ "python" ], "Title": "A small python game" }
268093
<p>I implemented an enumerate() method for C++ containers similar to Python's enumerate to iterate through a range with an index and the actual value.</p> <p>I have the following questions:</p> <ul> <li>Does the usage of the <code>Const</code> template parameter make sense for this scenario?</li> <li>Do I need addition...
[]
[ { "body": "<p>Your code can likely be replaced by Boost's existing template implementation of the same thing, <code>adapters::indexed</code>. Read their code for an idea of anything you might want to change--it's typically quite efficient and portable, although sometimes at the expense of readability.</p>\n<p><...
{ "AcceptedAnswerId": "268117", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-17T21:36:29.867", "Id": "268097", "Score": "4", "Tags": [ "c++", "c++17", "iterator" ], "Title": "Python's enumerate for C++" }
268097
<p>I am new to golang and I tried to implement <a href="https://en.wikipedia.org/wiki/Cache_replacement_policies#First_in_first_out_(FIFO)" rel="nofollow noreferrer">various cache replacement algorithms</a> (FIFO, FILO, LRU, MRU, LFU) in a generic or flexible fashion. I added some tests as well. My implementation uses ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-17T22:53:07.673", "Id": "268102", "Score": "2", "Tags": [ "go", "cache" ], "Title": "Simple implementation of various cache replacement policies" }
268102
<p>This is a range class, similar in functionality to the range function in python. It was originally made to work with just range-based for loops, like so:</p> <pre><code>for(auto i : range(256)) // do some code </code></pre> <p>but was workshopped by some people better at C++20 than me into being able to be used ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-18T05:59:32.643", "Id": "528673", "Score": "1", "body": "Hi. Welcome to Code Review! The \"workshopped by some people better at C++20 than me\" suggests that this isn't your code. Can you confirm that this is in fact [code that you ...
[ { "body": "<h1>Unnecessary restriction of the <code>value_type</code></h1>\n<p>You restrict the <code>value_type</code> of a <code>range</code> to the integral types, but I see no reason why that is necessary. It would work equally well with <code>float</code> and <code>double</code>, and any other type that yo...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-18T05:48:58.703", "Id": "268108", "Score": "5", "Tags": [ "c++", "c++20" ], "Title": "C++20 python-like \"range\" class" }
268108
<p>I've created a full Tic tac toe game in Tkinter that has single and multiplayer modes. The single player mode then has a hard and easy difficulty. The easy difficulty is just choosing a random open spot and the hard difficulty uses the minimax algorithm. On top of all that, the grid size for the game is adjustable, ...
[]
[ { "body": "<ul>\n<li><code>ttt</code> is not a good class name and should probably be renamed to <code>TicTacToe</code>. Conversely, <code>Tictactoe</code> is not a good name for a module and should be lowercase.</li>\n<li>Add PEP484 type hints to your signatures, such as <code>size: int</code>.</li>\n<li><code...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-18T07:44:33.110", "Id": "268109", "Score": "1", "Tags": [ "python", "game", "tic-tac-toe", "tkinter" ], "Title": "Tic Tac Toe game with an adjustable grid size in Tkinter" }
268109
<p>I am learning Haskell and I implemented a recursive function that generates possible strings by length and array (e.g. <code>['a'..'z']</code>):</p> <pre><code>comb :: Int -&gt; [a] -&gt; [[a]] comb 0 _ = [] comb 1 r = map (:[]) r -- convert &quot;abc..&quot; to [&quot;a&quot;,&quot;b&quot;...] comb n r = [i:s | i ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-17T21:23:14.217", "Id": "530784", "Score": "1", "body": "This function is called `replicateM` in `Control.Monad`" } ]
[ { "body": "<p>It looks very good already!</p>\n<p>I think it is nicer to have a single base-case, which is possible if you change the <code>comb 0 _</code> case:</p>\n<pre class=\"lang-hs prettyprint-override\"><code>comb :: Int -&gt; [a] -&gt; [[a]]\ncomb 0 _ = [[]]\ncomb n r = [i:s | i &lt;- r, s &lt;- comb (...
{ "AcceptedAnswerId": "268113", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-18T10:09:34.677", "Id": "268112", "Score": "3", "Tags": [ "beginner", "haskell", "recursion", "combinatorics" ], "Title": "Generate possible combinations by range and length"...
268112
<p>I have been learning Ruby for 2 weeks. Today my bootcamp teacher taught Ruby Class and gave me homework. I coded simple library program. But I think the code is smelling bad. How can do better the code?</p> <pre><code> class Book attr_reader :book_name, :author_name, :page_count, :more, :book_array def initializ...
[]
[ { "body": "<h1>Consistency</h1>\n<p>Sometimes you use accessor methods, sometimes you access instance variables directly. Sometime you use whitespace around operators, sometimes you don't. Sometimes you use space after a comma, sometimes you don't. Sometimes you use an empty argument list and sometimes you use ...
{ "AcceptedAnswerId": "268133", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-18T15:31:13.583", "Id": "268120", "Score": "0", "Tags": [ "ruby" ], "Title": "Library Program in Ruby with Class" }
268120
<p>I built a <code>ButtonStepper</code> component and it's sharing quite a bit of the same logic, so I was wondering if it could be refactored better. It's sharing quite a bit of code with <code>incrementDisabled</code> and <code>decrementDisabled</code> because I have to account for the button color changing from blac...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-18T15:40:35.767", "Id": "268121", "Score": "0", "Tags": [ "react.js", "typescript", "react-native" ], "Title": "TypeScript + React Native: Button Stepper Component" }
268121
<p>I am trying to calculate the time difference between samples that a satellite takes at the same location. I have data currently in a Pandas DataFrame that has latitude, longitude, and time of the sample. Here is a snapshot of the data (it has some extra columns that can be ignored):</p> <pre><code> JulianDay ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-24T16:38:51.517", "Id": "529167", "Score": "0", "body": "You will get much better answers faster if you provide a full runnable snippet with some reasonable test data." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate":...
[ { "body": "<p>I was recently able to resolve this by removing one of my constraints. In the original post I noted that I need to include the start and end time to make up for low simulation time. The actual solution to low simulation time is quite simple; increase the simulation time. I also add a condition tha...
{ "AcceptedAnswerId": "268965", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-18T19:47:18.113", "Id": "268125", "Score": "2", "Tags": [ "python", "performance", "pandas" ], "Title": "Finding the difference in one column in a Pandas GroupBy" }
268125
<p><a href="http://minmaxia.com/c2/" rel="nofollow noreferrer">Clickpocalypse 2</a> is kind of dungeon crawler game but with minor controls. Script's purpose to automate what is left.</p> <p>To try it out:</p> <ol> <li>Open &quot;Clickpocalypse 2&quot; as separate browser window (not a tab, game have to be in active ta...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-18T23:11:37.707", "Id": "268128", "Score": "2", "Tags": [ "javascript" ], "Title": "Clickpocalypse 2 automation script" }
268128
<p>The function below is written in Lua and returns the list of buffers from the current neovim session, it also allows the option to specify a optional table (object) as a parameter, with a <code>listed</code> property to filter the type of buffer returned by the function (only listed buffers, or every single one).</p...
[]
[ { "body": "<p>The only case when you <em>don't</em> want a buffer included is when</p>\n<ul>\n<li><code>options.listed</code> is <em>truthy</em> and</li>\n<li><code>is_listed</code> is <em>falsy</em></li>\n</ul>\n<p>In <strong>every other case</strong> you want it included. If my understanding is correct you ca...
{ "AcceptedAnswerId": "268289", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-19T00:36:10.873", "Id": "268130", "Score": "0", "Tags": [ "lua" ], "Title": "Get list of buffers from current neovim instance" }
268130
<p>This code counts the number of possible positions in the game of <a href="https://en.wikipedia.org/wiki/Cram_(game)" rel="nofollow noreferrer">Cram</a> on a <code>mxn</code> board.</p> <p><strong>EDIT 1</strong>: In the original question I mistakenly mentioned that this number is equal to the number of domino tiling...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-19T01:47:33.097", "Id": "268132", "Score": "1", "Tags": [ "c", "array", "hash-map", "bitwise", "bitset" ], "Title": "Counting Cram game positions in C" }
268132
<p>I am working on a program that the user can use to track the parameters of his body (such as weight, waist size). I have a code that builds a chart based on these data. I would like to hear criticism on my code. What I don't like :</p> <ol> <li>MeasurementCHartHelperю - It seems to me that this is not a very good ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-19T04:39:15.493", "Id": "268135", "Score": "0", "Tags": [ "android", "kotlin" ], "Title": "Code to plot chart with data" }
268135
<p>I'm starting an object orientated game engine in Java. My plans for the engine is to be able to split things easily into multi-core loads. My idea is that a Unique (interface with a <code>GetUID()</code> method) gets passed in. The Unique can also implement any number of other interfaces. In this case, the unique ca...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-03T09:13:07.767", "Id": "529778", "Score": "1", "body": "If you disagree with your question being closed, please point out why. If that doesn't have the required effect, a flag can be raised. Not the other way around, please. Previous ...
[ { "body": "<h2>Overall review</h2>\n<p>I think it's too early to give a profound review of your architecture, so here's only what I found at a quick glance. It would be helpful to see the interface definitions besides the <code>Engine</code> class, at least (with Javadoc, please).</p>\n<h2>Naming conventions</h...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-19T04:45:56.577", "Id": "268136", "Score": "-1", "Tags": [ "java", "game", "multithreading", "interface" ], "Title": "A simple java game engine" }
268136
<p>I have written simple command line project with Spring. And from what I think quality of code is pretty poor. I see what I could improve to remove duplicated code, but somehow I have no idea what would be proper way to do it.</p> <p>So I will copy/paste only code which I think need refactoring. Thos are three separa...
[]
[ { "body": "<p>common Interface\nclasses that share the same behaviour should implement the same interface. That applies to <code>Movie</code>, <code>Book</code> and <code>Song</code>. Their interface is <code>ReviewProvider</code>:</p>\n<pre><code>public interface IdProvider {\n long getId();\n}\n\npublic in...
{ "AcceptedAnswerId": "268174", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-19T10:30:01.923", "Id": "268140", "Score": "1", "Tags": [ "java", "spring", "hibernate" ], "Title": "Refactoring duplicated code with abstraction and generics" }
268140
<p>I have a school project question (for Python) that goes like this:</p> <p>Given a string_input such as &quot;abcd&amp;1-4efg&quot;, the function must remove the &quot;&amp;1-4&quot; and insert the string slice from 1 to 4 where the &quot;&amp;1-4&quot; was.</p> <p>eg. if string_input = &quot;abcd&amp;1-4efg&quot;,</...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-19T13:32:01.423", "Id": "528752", "Score": "0", "body": "The top-level function is not properly indented. – Is it intentional that you `import string` in the middle of a function?" } ]
[ { "body": "<p>Indeed there is. For such tasks you should use regex expressions.</p>\n<pre><code>import re\n\nWILDCARD_REGEX = &quot;&amp;[0-9]+-[0-9]+&quot;\n\n\ndef get_text_without_wildcards(text):\n return re.sub(WILDCARD_REGEX, &quot;&quot;, text)\n\n\ndef find_wildcard(text):\n wildcard = re.search(W...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-19T10:31:20.883", "Id": "268141", "Score": "2", "Tags": [ "python", "python-3.x" ], "Title": "Function to replace all \"&int-int\" with the respective string slices in an input string" }
268141
<p>I'm doing a past-year lab test in preparation for my upcoming test and I came across this question that took me a while to solve.</p> <p>It asks the programmer to create a function, trace_contacts(), that takes in 2 parameters (patient, history), and outputs a list of people who may have been infected (either direct...
[]
[ { "body": "<p>I think you went at it from the wrong direction. While I am not completely sure how your algorithm works and if everything in it is necessary, I think you can generify it a bit.</p>\n<p>What the problem seems to require is simulation of the days passed. You have a set of infectious people, a set o...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-19T11:18:19.057", "Id": "268144", "Score": "2", "Tags": [ "python", "python-3.x" ], "Title": "Contact Tracing Function" }
268144
<p>I've implemented a map using a Patricia tree, using <code>u64</code> as keys. I would like general feedback on my code, but I have one thing that I think could be implemented in a lot cleaner way, but I can't figure out how to do it:</p> <p>As a Patricia tree is a full binary tree (meaning all internal nodes have ex...
[]
[ { "body": "<p>The <code>Node::_TemporaryUnused</code> is very sad.</p>\n<p>You need to use it here:</p>\n<pre><code>let old_node = mem::replace(node, Node::_TemporaryUnused);\n</code></pre>\n<p>You can look at how <code>std::mem::replace</code> is implemented</p>\n<pre><code>unsafe {\n let result = ptr::read...
{ "AcceptedAnswerId": "268316", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-19T12:25:39.707", "Id": "268148", "Score": "1", "Tags": [ "rust", "binary-tree" ], "Title": "Patricia tree implementation in Rust" }
268148
<p>I am writing a chess <a href="https://github.com/wawaroutas/chess" rel="nofollow noreferrer">project</a> using C++ and SDL. In this method I calculate all available moves a <a href="https://en.wikipedia.org/wiki/Knight_(chess)" rel="nofollow noreferrer">Knight</a> can make and I want to refactor it. I basically move...
[]
[ { "body": "<h1>Use <code>Position</code>s for steps as well</h1>\n<p>You can avoid the duplication by using <code>Position</code>s to represent the steps as well:</p>\n<pre><code>Position directions_double[] = {{-2, 0}, {2, 0}, {0, -2}, {0, 2}};\n...\nfor (auto double_step: directions_double) {\n ...\n te...
{ "AcceptedAnswerId": "268150", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-19T12:27:29.400", "Id": "268149", "Score": "4", "Tags": [ "c++", "chess" ], "Title": "Clean up Knight Movement method in a chess project with duplicate code" }
268149
<p>What follows is an evaluator for a toy expression language. The language includes functions of a single variable (with lexical binding), along with numbers and a way to apply functions to expressions. For the sake of simplicity, bound variables are represented using De Bruijn indices.</p> <p>The main questions I hav...
[]
[ { "body": "<p>There is one part that immediately that immediately catches attention: all <code>impl fn</code> don't use <code>Self</code>, <code>&amp;Self</code> or <code>&amp;mut Self</code> as first attribute, but a wrapped variant:</p>\n<pre class=\"lang-rust prettyprint-override\"><code>impl Expr {\n pub...
{ "AcceptedAnswerId": "268155", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-19T14:33:30.253", "Id": "268152", "Score": "5", "Tags": [ "recursion", "rust", "language-design" ], "Title": "Simple expression evaluator in Rust" }
268152
<p>I'm having trouble with the slow computation of my Monte Carlo simulation code. Based on the pycallgraph, the bottleneck seems to be the module named <code>miepython.mie_S1_S2</code> (highlighted by pink), which takes around 0.5 seconds per call. <a href="https://i.stack.imgur.com/sASh1.png" rel="nofollow noreferrer...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-19T17:09:54.270", "Id": "528757", "Score": "0", "body": "Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking." ...
[ { "body": "<p>By a very wide margin, the slowest part of your code is this loop:</p>\n<pre><code>for k in range(nangles):\n pi_nm2 = 0\n pi_nm1 = 1\n for n in range(1, nstop):\n tau_nm1 = n * mu[k] * pi_nm1 - (n + 1) * pi_nm2\n\n S1[k] += (2 * n + 1) * (pi_nm1 * a[n - 1]\n ...
{ "AcceptedAnswerId": "268165", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-19T17:01:04.367", "Id": "268154", "Score": "2", "Tags": [ "python", "numba" ], "Title": "How to speed up this Numba-based code?" }
268154
<p>Ok, so here's the code: Please, comment if there are mistakes</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;windows.h&gt; main() { int h, m, s; int d = 1000; printf(&quot;Set the Clock time: \n&quot;); scanf(&quot;%d%d%d&quot;, &amp;h,&amp;m,&amp;s); if (h &gt; 24 || m &gt; 60 || s &g...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-19T18:30:42.033", "Id": "528763", "Score": "3", "body": "Welcome to Code Review. Did you test this code? Does it appear to work correctly for you? What prompted you to write this?" } ]
[ { "body": "<h1>Incorrect input validation</h1>\n<p>Your code allows someone to enter the time &quot;24:60:60&quot;, and your program will accept it. I also see that the clock is meant to display times from 01:00:00 to 24:59:59, but it will also accept 0 as the hour. To ensure you only accept inputs for times th...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-19T18:17:37.930", "Id": "268159", "Score": "0", "Tags": [ "c" ], "Title": "Clock in C language" }
268159
<p>I built 2048 in Python with Pygame and it works as expected.</p> <p>I wanted to know where I could -</p> <ul> <li>Optimize the performance.</li> <li>Improve the UX.</li> <li>Or just improve the code readability.</li> </ul> <p>My file directory -</p> <pre class="lang-py prettyprint-override"><code>2048 - | - c...
[]
[ { "body": "<p><a href=\"https://i.stack.imgur.com/kiRXr.png\" rel=\"nofollow noreferrer\"><img src=\"https://i.stack.imgur.com/kiRXr.png\" alt=\"play screen\" /></a></p>\n<p>I've been playing this for ?? hours without loss, so I'm going to call it here; that's proof of two things:</p>\n<ul>\n<li>it's fun and ad...
{ "AcceptedAnswerId": "268169", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-19T19:03:54.637", "Id": "268160", "Score": "5", "Tags": [ "python", "performance", "2048" ], "Title": "2048 in Python Pygame" }
268160
<p>I need help making my Python code easier to read. My friend and I are creating a stock market simulator. This is the function for the buying mechanic.</p> <p>The purpose of this section is to simulate a buying process. If the user wants to buy a specific stock, they just type its name into the terminal. It then asks...
[]
[ { "body": "<p>There are a few major issues with your code:</p>\n<h2>Your code is really very messy</h2>\n<ul>\n<li>You are repeating a lot of code which can be wrapped in a function.</li>\n</ul>\n<p>You can store all your prices and owned shares in a <code>dict</code> as follows:</p>\n<pre><code>prices = {\n ...
{ "AcceptedAnswerId": "268172", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-19T20:52:54.963", "Id": "268164", "Score": "0", "Tags": [ "python", "python-3.x" ], "Title": "The buying mechanic for a stock market simulator" }
268164
<p><strong>1. Task</strong></p> <p>Using standard input I read four rows of data:</p> <ul> <li>number of elements (elements are numbered from 1 to n)</li> <li>n numbers corresponding to cost of moving each element</li> <li>n numbers corresponding to current position of each element (from 1 to n)</li> <li>n numbers corr...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-20T18:38:01.193", "Id": "528811", "Score": "0", "body": "Is this online somewhere for testing?" } ]
[ { "body": "<h2>Style: Parsing the file</h2>\n<p>It's okay to be strict in expecting things in exactly the right format here. There should be no blank lines (or possibly, always exactly one blank line at the end) so the if check seems unneccesary. Your original is fine too, but I personally would shorten this to...
{ "AcceptedAnswerId": "268930", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-19T22:49:51.487", "Id": "268167", "Score": "3", "Tags": [ "python", "sorting" ], "Title": "Sorting algorithm in the element cost model Python" }
268167
<p>In my Python projects, I often define parameters in a TOML, YAML, or JSON file. Those parameters are loaded into a dictionary which is utilized by various functions in the project. See below for some examples. I'm curious on how others would approach this and if there are better ways to work with functions and param...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-20T03:51:42.370", "Id": "528771", "Score": "0", "body": "Use example 1, but please show all of your code." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-20T04:19:40.247", "Id": "528772", "Score": "...
[ { "body": "<p>What is missing is context. Example one is fine, but what if it contained 10 or 15 parameters? That means that you probably have some objects hiding in there.</p>\n<p>The problem with the second example is that you pass the whole params object in, but only need feedstock. calc_feedx(feedstock) wou...
{ "AcceptedAnswerId": "268194", "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-20T00:37:53.510", "Id": "268168", "Score": "0", "Tags": [ "python", "configuration" ], "Title": "Utilize values in a parameters file for function inputs" }
268168
<p>I implemented a basic dynamic array using C++.</p> <p>When deleting an element and shifting the others, the last element will be twice repeated (the original still exists after copying). I want to avoid memory leaking by deallocating the last element of the array. Currently, I do this by shrinking once after a numb...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-20T11:54:32.060", "Id": "528791", "Score": "0", "body": "Do you have any specific reason for not using `std::vector<int>` or one of the other standard containers?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "202...
[ { "body": "<p>First of all, there is a major problem with your class: it does not respect the <a href=\"https://en.cppreference.com/w/cpp/language/rule_of_three\" rel=\"noreferrer\">rule of three/five/zero</a>:</p>\n<ul>\n<li><p>it has a non trivial destructor that destroys memory allocated in constructor</p>\n...
{ "AcceptedAnswerId": "268177", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-20T03:37:40.890", "Id": "268171", "Score": "6", "Tags": [ "c++", "array", "memory-management" ], "Title": "Dynamic array implementation using C++" }
268171
<p>I defined the following context provider:</p> <pre><code>import { Context, createContext, FC, useContext, useEffect, useState } from &quot;react&quot;; import { element, list, browse } from &quot;../Components/Controls/Controls&quot;; export interface ControlsState { shownTab: &quot;Durchsuchen&quot; | &quot;Elem...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-20T10:04:13.700", "Id": "528784", "Score": "0", "body": "doing OOP in react is already starting you on the wrong path, considering react was built with functional programming at its core. you should instead separate your state by varia...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-20T08:46:12.920", "Id": "268178", "Score": "0", "Tags": [ "react.js", "state" ], "Title": "Encapsulation React state" }
268178
<p>Alice and Borys are playing tennis and it is unknown who <em>served</em> the first <em>game</em>. After each game, the serve changes to other player. If the server wins the game, then it is said that s/he <em>holds</em> the serve and if the <em>receiver</em> wins the game then it is said that s/he <em>breaks</em> th...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-20T22:15:26.517", "Id": "528816", "Score": "2", "body": "Unfortunately, [codereview.se] requires that [code must be working as intended, to the best of the author's knowledge](https://codereview.meta.stackexchange.com/a/3650/1581). So,...
[ { "body": "<p>One thing that I often forget to do as well is to simply reference the source or reason of the program. If this was an assignment, you could include that in the JavaDoc of the class.</p>\n<pre><code>public class KBreaksInTennis {\n</code></pre>\n<p>This is not very clear to the user; it's better t...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-20T09:11:21.337", "Id": "268179", "Score": "-1", "Tags": [ "java", "programming-challenge" ], "Title": "Serving In Tennis" }
268179
<p>My coding background is mostly from C and I've noticed that I tend to &quot;use C++ as it was C&quot; quite a lot. So this is a very small project I've written to improve my understanding of best practices in C++. I'm looking for a general review, with focus on:</p> <ul> <li>How well is it following standard C++ bes...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-24T17:26:21.967", "Id": "529174", "Score": "1", "body": "Have you red this? https://stackoverflow.com/a/1120224/14065" } ]
[ { "body": "<h1>Answers to your questions</h1>\n<blockquote>\n<ol>\n<li>Should I move the functionality of <code>Parse()</code> to the constructor and just throw an exception if the file cannot be opened? Does it make sense to have the constructor open, read, and parse the file?</li>\n</ol>\n</blockquote>\n<p>Si...
{ "AcceptedAnswerId": "268183", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-20T09:58:42.560", "Id": "268180", "Score": "2", "Tags": [ "c++", "beginner", "csv" ], "Title": "Simple lightweight CSV reader in C++" }
268180
<p>This logic checks accessGroup and if accessGroup is equal to &quot;Admin&quot; then it only checks if result.Admin or baccess is true but if accessGroup is anthing else it will need to check two other objects result.Admin == true || result.PowerUser. Is there any other way to do this if condition?</p> <pre><code>if ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-20T13:23:12.403", "Id": "528797", "Score": "0", "body": "`if (baccess || (accessGroup == \"Admin\" ? result.Admin : (result.Admin || result.PowerUser)))`" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-20T1...
[ { "body": "<p>this looks like it will have the same effect</p>\n<pre><code>if (baccess || result.Admin || (accessGroup != &quot;Admin&quot; &amp;&amp; Result.PowerUser))\n</code></pre>\n<p>though i suspect what you mean to do is AND (&amp;&amp;)</p>\n<pre><code>if (baccess &amp;&amp; (result.Admin || (access...
{ "AcceptedAnswerId": "268197", "CommentCount": "7", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-20T12:09:33.187", "Id": "268184", "Score": "0", "Tags": [ "c#" ], "Title": "Method if condition logic" }
268184
<p>I am attempting to find the maximum value and its location in multidimensional array using Matlab. There are functions <code>findMax3</code>, <code>findMax4</code>, <code>findMax5</code> and <code>findMax6</code> for dealing with different dimension cases.</p> <p><strong>The experimental implementation</strong></p> ...
[]
[ { "body": "<p>Did you consider what would happen if there are more than one element in the array with the same maximum value? <code>max</code> returns one of them, but your <code>find</code> will return the index to all of them.</p>\n<p>One solution is to use <a href=\"https://www.mathworks.com/help/matlab/ref/...
{ "AcceptedAnswerId": "268243", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-20T23:58:42.790", "Id": "268200", "Score": "1", "Tags": [ "array", "matlab" ], "Title": "Finding max number and location in multidimensional array in Matlab" }
268200
<p>Trying to make a little 2D engine I can play with. The end goal is a simple multiplayer PVP game just using shapes. I will make one version using ECS and one using OOP for learning. This is the shell of the ECS version using Pong as a demo. Before I jump into the user interface I am wondering what people smarter tha...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-21T06:38:09.587", "Id": "528829", "Score": "0", "body": "Hi. Welcome to Code Review! I'm having trouble understanding what this is actually supposed to do at the moment. It's a game engine that implements Pong but without a user int...
[ { "body": "<h1>Avoid writing unnecessary wrappers</h1>\n<p>It seems that a lot of the code you are writing is wrappers around other types. For example, <code>Box2D::Body</code> is just a wrapper around a <code>b2Body</code>. While sometimes wrapping an existing type in a new one might be the right thing to do, ...
{ "AcceptedAnswerId": "268207", "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-21T06:23:27.543", "Id": "268204", "Score": "2", "Tags": [ "c++", "state-machine", "sfml", "entity-component-system", "pong" ], "Title": "Game States / Pong: SFML Box2D En...
268204
<p>The following code uses <a href="https://github.com/oliver-moran/jimp" rel="nofollow noreferrer">jimp</a> to merge images, located in the <code>./in</code> folder, with <code>dots.png</code>. Then it autocrops the images. Finally, they are written into the <code>./out</code> folder.</p> <pre><code>import * as fs fro...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-21T07:54:01.500", "Id": "268205", "Score": "1", "Tags": [ "javascript", "image", "typescript", "processing" ], "Title": "Merge and autocrop images with Jimp" }
268205
<p>I wanted a <code>$PWD</code> shrinking for my <code>$PROMPT</code> with the following requirements:</p> <ul> <li><code>$HOME</code> is replaced by ~</li> <li>All subpaths except the last one are replaced by their initial letters</li> <li>Reasonably efficient</li> </ul> <p>This is my attempt, with tests:</p> <pre><co...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-21T08:42:33.480", "Id": "268206", "Score": "2", "Tags": [ "strings", "shell", "zsh" ], "Title": "zsh function for shrinking $PWD with $HOME replacement" }
268206
<p>I have written the following code for the question (from <em>Problem Solving With C++</em>):</p> <blockquote> <p>A store sells carpet for $2.75 per meter. If a customer buys more than 10m of carpet, they get a discount of 15% on every additional meter of carpet they purchase. Write a program that inputs the carpet l...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-22T16:38:16.873", "Id": "528957", "Score": "1", "body": "You might want to check for bad input: `if (!(std::cin >> length)) { ... }`" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-22T21:22:33.847", "Id...
[ { "body": "<p>The code is longer and more complex than necessary. Here is what it could look like instead:</p>\n<pre><code>#include &lt;iostream&gt;\n#include &lt;iomanip&gt;\n#include &lt;numeric&gt;\n\nint main()\n{\n // Define the relevant constants\n static constexpr double cost_per_meter = 2.75;\n ...
{ "AcceptedAnswerId": "268215", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-21T09:58:20.827", "Id": "268211", "Score": "10", "Tags": [ "c++", "beginner" ], "Title": "C++ code for calculating the cost of carpet" }
268211
<p>I completed my Notes Saver project in python tkinter and now I want to get it reviewed.</p> <p>I want to how I could -</p> <ul> <li>Improve my hashing system.</li> <li>Improve my notes encryption system.</li> <li>Improve the UX.</li> <li>Improve code readability</li> <li>Improve performance.</li> </ul> <h2>Working D...
[]
[ { "body": "<p>This seems like it took some effort to get to the current state. Good work!</p>\n<p>The code looks reasonably clean. If the functions do what their name says they do, I'm happy that they all do one thing and will be easy to change if needed.</p>\n<p>I think it would be worth looking at two big pic...
{ "AcceptedAnswerId": "268218", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-21T10:01:55.913", "Id": "268212", "Score": "1", "Tags": [ "python", "tkinter", "user-interface", "encryption" ], "Title": "Notes Saver Application in tkinter python" }
268212
<p>One year and a half ago I posted the second iteration of this script for a review here:</p> <p><a href="https://codereview.stackexchange.com/q/236530/104270">Editing system files in Linux (as root) with GUI and CLI text editors #2</a></p> <hr /> <p>Since then, it has been &quot;hibernated&quot; as I had way too much...
[]
[ { "body": "\n<ol>\n<li><p>The print error function is only useful to a point, I have rather removed it and used direct in-place constructs instead, so this function has been removed:</p>\n <strike>\n<pre class=\"lang-sh prettyprint-override\"><code>sudoedit_err () { ... ; exit 1; }\n</code></pre>\n </strike>\n<...
{ "AcceptedAnswerId": "268452", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-21T10:40:05.807", "Id": "268213", "Score": "1", "Tags": [ "linux", "posix", "sh", "text-editor" ], "Title": "Editing system files in Linux (as root) with GUI and CLI text edi...
268213
<p>I have <a href="https://coderodde.github.io/rodioning.js/" rel="nofollow noreferrer">this page</a>. I wish to hear comments on how to make it more idiomatic, for the most part. The code follows:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;rodioning.js&lt;/title&gt; &lt;style type=&quot;...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-22T19:40:10.527", "Id": "528965", "Score": "1", "body": "You can use a regular expressions to replace the values in `dealWithEntities` or simply use `escape`." } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-21T12:37:11.597", "Id": "268216", "Score": "0", "Tags": [ "javascript", "html" ], "Title": "Havin fun with Javascript: rodioning.js" }
268216
<p>Searching for a solution to my problem I've read many posts regarding templates in <strong>Qt</strong> (including those on SE) and didn't find a complete solution (or I should say a complete example of a solution) so this post. It is not only to review the code but I think it could be useful for others with similar ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-21T15:13:02.270", "Id": "528871", "Score": "0", "body": "\"The presented code is a MRE.\" The only meaning of MRE that I know is https://en.wikipedia.org/wiki/Meal,_Ready-to-Eat . I don't find any code-related meanings for such an acr...
[ { "body": "<p>Not Qt related but...</p>\n<p>See <a href=\"https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rh-override\" rel=\"nofollow noreferrer\">Core Guidelines C.128</a>.</p>\n<p><code>virtual ~Int();</code><br />\nshould be:<br />\n<code>~Int() override =default;</code></p>\n<p...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-21T12:57:18.063", "Id": "268217", "Score": "1", "Tags": [ "c++", "template-meta-programming", "qt" ], "Title": "Handle C++ templates in Qt5" }
268217
<p>I have written two functions that output a date-time string for any given non-negative integer.</p> <p>The integer is treated as representing total number of seconds in a given time period, the first function converts that duration to week-day-hour-minute-weekday format (w weeks, d days, HH:mm:ss, dddd), using a mat...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-21T16:19:14.530", "Id": "528885", "Score": "0", "body": "That calendar is normally described as a [proleptic Gregorian calendar](https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar), as used by ISO 8601." } ]
[ { "body": "<p>This runs in 6ms on my system. Therefore any efficiency changes are likely to have minimal effect. Having said that, your use of the MONTHS tuple is more complex than it needs to be. I have made several changes but important ones to note are the change to MONTHS and the introduction of DIYSF (days...
{ "AcceptedAnswerId": "268255", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-21T13:55:05.113", "Id": "268220", "Score": "0", "Tags": [ "python", "python-3.x", "datetime", "reinventing-the-wheel", "converting" ], "Title": "Python 3 integer seconds ...
268220
<p>I started learning Python a few weeks ago and coded this &quot;Connect 4&quot; game.</p> <p>What could I have done better? How efficient is this code and how could I improve on that?</p> <pre><code>from collections import defaultdict from termcolor import colored from time import sleep class Board: def __init__...
[]
[ { "body": "<p>There are a lot of issues with your code. I will try to cover all of them.</p>\n<h2>Logic Repetiton</h2>\n<ul>\n<li>In your <code>start_game()</code> function, you are repeating the almost same loop for both players.</li>\n</ul>\n<p>You can make a <code>current_player</code> and use it instead of ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-21T15:49:29.093", "Id": "268227", "Score": "3", "Tags": [ "python", "python-3.x", "game", "connect-four" ], "Title": "Terminal based \"Connect 4\" game in Python" }
268227
<p>I am writing a parser for a custom mesh format for fluid dynamics simulation library, the mesh file contains 3D points (vertices) for the simulation mesh, for example:</p> <pre><code>[points 4] 2.426492638414711e-07,-0.0454127835577514,0.737590325020352 -0.02408935296003224,-0.02309953378412839,0.7378945938955059 -1...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-21T16:44:49.840", "Id": "528894", "Score": "0", "body": "Perhaps your profiler sees your code spending a lot of time checking for 'e' simply because that's a common case, and the actual bottleneck is with your while loop in general?" ...
[ { "body": "<h1>Unnecessary use of <code>this-&gt;</code></h1>\n<p>In C++, you almost never have to use <code>this-&gt;</code> in your code.</p>\n<h1>Potentially lots of function call overhead</h1>\n<p>The function <code>ScanNumber()</code> will call <code>NextChar()</code> a lot of times. Maybe it is a simple f...
{ "AcceptedAnswerId": "268248", "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-21T16:17:05.833", "Id": "268229", "Score": "2", "Tags": [ "c++", "parsing", "lexical-analysis", "lexer" ], "Title": "Optimize lexer/parser bottleneck in C++" }
268229
<pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt; #include &lt;complex&gt; #include &lt;vector&gt; #include &lt;cmath&gt; /* adapted from https://stackoverflow.com/questions/55421835/c-binomial-coefficient-is-too-slow */ template&lt;typename T = int, typename U = unsigned long long int&gt; in...
[]
[ { "body": "<p>One suggestion that I think is good is to cache the Ncr results.</p>\n<pre class=\"lang-cpp prettyprint-override\"><code>struct Ncr {\n using T = long double;\n static std::vector&lt;T&gt; &amp;fact() {\n static std::vector&lt;T&gt; _fact{1};\n return _fact;\n }\n\n static std::vector&lt...
{ "AcceptedAnswerId": "268236", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-21T16:55:04.570", "Id": "268231", "Score": "5", "Tags": [ "c++" ], "Title": "Binomial Theorem implementation, including complex numbers" }
268231
<p>I wanted to know if someone can find a better way to code this in C++ using 1 or 2 dimensional arrays instead of <code>int</code> tables. It has to be a static 7x7 array where the user can make a 3x3 or 5x5 or 7x7 magic square.</p> <p>Static allocation and is allocated on a stack and not a heap, and static array or ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-22T05:13:26.777", "Id": "528926", "Score": "0", "body": "didn't get what magic square means, can u explain that?" } ]
[ { "body": "<h2>a bad habit</h2>\n<blockquote>\n<p><code>using namespace std;</code></p>\n</blockquote>\n<p>Don't get into this habit. It can lead to name collisions. It's best to specify the full namespace where necessary, e.g. <code>std::cout &lt;&lt; ...</code></p>\n<hr />\n<h2>prefer std::array to c-style ar...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-21T23:10:47.927", "Id": "268241", "Score": "2", "Tags": [ "c++" ], "Title": "Coding a magic square using 1d or 2d arrays using static allocation" }
268241
<p>I want to have a config class with immutable lists. Is it ok to create it like this?</p> <pre><code>import os from dataclasses import asdict, dataclass from itertools import chain from typing import Optional, Tuple, Mapping ENV = Mapping[str, str] @dataclass(frozen=True) class Config: a_types: Tuple[str, ...] ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-22T10:32:44.910", "Id": "528933", "Score": "4", "body": "Please add the entire code: imports, constants, and so on :) And perhaps add some more context as to how you'll want to use this." }, { "ContentLicense": "CC BY-SA 4.0", ...
[ { "body": "<p>I guess the idea is that &quot;in production&quot; configuration is taken from the environment, but in tests you can pass it in explicitly instead? If so, that seems fine.</p>\n<p>If the intent is, rather, that some callers will pick up environment variables, while other callers ignore them, users...
{ "AcceptedAnswerId": "268257", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-22T09:30:54.840", "Id": "268247", "Score": "0", "Tags": [ "python" ], "Title": "Config with immutable lists" }
268247
<p>I am using ngx-datatable to load large volumes of records. However, the larger the volume, the longer it takes. I read somewhere that you can speed it up by sorting then assigning it to the data source. Could someone please assist me with finding the best way to improve the performance of this process? Below is the ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-22T12:22:02.803", "Id": "528935", "Score": "2", "body": "How large volume are you talking about? Is pagination an option for you?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-23T07:24:12.963", "Id": ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-22T11:42:39.523", "Id": "268250", "Score": "0", "Tags": [ "c#", "typescript", "asp.net-core", "asp.net-web-api" ], "Title": "Improving the Speed of loading records into a ngx-dat...
268250
<p>In our software we have some functions that return information through lvalue reference parameters, which, in some cases, are irrelevant for the calling code. For that reason, I tried to come up with an object that can be used instead of a previously declared dummy variable, similar to <code>std::ignore</code> with ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-22T14:34:01.340", "Id": "528944", "Score": "0", "body": "Welcome to the Code Review Community. We only review real working code from your project, and the usage examples appear to be theoretical in nature which is off-topic. Please rea...
[ { "body": "<p>What's wrong with just writing:</p>\n<pre><code>int main()\n{\n X ignore;\n foo(ignore);\n\n return 0;\n}\n</code></pre>\n<p>What benefit is gained by adding a wrapper around the unused argument?</p>\n<hr />\n<p>As for your wrapper presented, what does it <em>do</em>? It appears to be an...
{ "AcceptedAnswerId": "268254", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-22T12:54:12.183", "Id": "268252", "Score": "3", "Tags": [ "c++", "template-meta-programming" ], "Title": "Object to ignore unused function output parameters" }
268252
<p>I'm really new to code optimization and JS. And I like to learn with clean code. I would like to ask for help on optimizing my code.</p> <p>The code below parses the value of four inputs as floating point numbers and adds them together. The sum is then displayed in an output element.</p> <pre><code> if(document.get...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-22T16:44:41.197", "Id": "528959", "Score": "2", "body": "@konijn - I don't remember if I had seen this relevant meta post until now: [_Do we need \"acronym tags\" (\\[dry\\], \\[solid\\], etc.)?_](https://codereview.meta.stackexchange....
[ { "body": "<p>From a short review;</p>\n<ul>\n<li><p>You should declare your variables with <code>const</code> or <code>let</code></p>\n</li>\n<li><p>There is a ton of copy-pasted code in there</p>\n</li>\n<li><p><code>'commission-field'</code> is not a great name for your element, I would just call it <code>co...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-22T15:56:09.400", "Id": "268258", "Score": "0", "Tags": [ "javascript", "calculator" ], "Title": "income calculator" }
268258
<p>I wrote this Pagination Section. It shows links to pages 123456789 and so on on SERP (Keyword Search Result Pages). Like you see on Google SERPs. Even though they work, I'm not sure I finished them to the best or valid practices. I'm worried about the encoding functions (<code>raw_urlencode</code>, <code>urlencode</...
[]
[ { "body": "<p>Your questions are very detailed, I might even say, a bit too detailed for reviewing. The code you have is not very complex, but it contains quite a few things I noticed:</p>\n<ul>\n<li>Why is <code>$i = '1';</code> a string, when all it ever contains is a number?</li>\n<li>Some of the variable na...
{ "AcceptedAnswerId": "268285", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-22T17:38:53.757", "Id": "268261", "Score": "2", "Tags": [ "php", "comparative-review" ], "Title": "URL & HTML encodings on pagination" }
268261
<p>I've been teaching myself Java programming. I thought it would be an interesting exercise to program a simple utility for procedurally generating dungeon levels. This program creates a small, random number of dungeon levels and displays them via clicking a <code>JComboBox</code> that switches between custom panels e...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-25T02:48:35.523", "Id": "529204", "Score": "0", "body": "@Martin Frank, thank you for your detailed review. I will go read all the links you posted to educate myself further." }, { "ContentLicense": "CC BY-SA 4.0", "Creatio...
[ { "body": "<p>very nice code for a beginner, thank you very much for sharing. so some issues with your code i see:</p>\n<h2>class <code>Exit</code></h2>\n<p>well you have a place holder in your <code>Room</code> for instances of the <code>Exit</code> but you never create any instance of this class (no code with...
{ "AcceptedAnswerId": "268321", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-23T03:16:48.423", "Id": "268271", "Score": "3", "Tags": [ "java", "beginner" ], "Title": "Simple Swing tool which displays a few procedurally generated dungeon levels" }
268271
<p>I'm developing an embedded solution (STM32L4R5 MCU - Cortex-M4F: 120 Mhz / 640 kb of ram) featuring a parallel NAND Flash (MICRON) interface and my platform lacks hardware ECC computation powerful enough to handle page sizes of 8KB so I elected to use software ECC. This <a href="https://github.com/osmocom/atmel-asf-...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-23T07:57:13.843", "Id": "529001", "Score": "2", "body": "You'll need to provide platform specific info: what kind of CPU are you using, how much cache if any, etc." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "20...
[ { "body": "<h3>Shift the constants not the variable</h3>\n<blockquote>\n<pre><code> if (column_sum &amp; 1) { even_column_code ^= 7; odd_column_code ^= 0;} column_sum &gt;&gt;= 1;\n if (column_sum &amp; 1) { even_column_code ^= 6; odd_column_code ^= 1;} column_sum &gt;&gt;= 1;\n if (column_sum &amp...
{ "AcceptedAnswerId": "268282", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-23T07:34:03.700", "Id": "268277", "Score": "5", "Tags": [ "performance", "c", "embedded" ], "Title": "Software ECC embedded with a parallel NAND Flash interface" }
268277
<p>I have two functions:</p> <ul> <li>one fetch the API and get back the data (async function)</li> <li>the other use this data to filter and display information (dropdown function)</li> </ul> <p>The problem is the drop down function is very slow when filtering. How can I please optimise this function ? This line takes...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-23T08:50:02.957", "Id": "268281", "Score": "1", "Tags": [ "javascript", "leaflet" ], "Title": "Filter and display dropdown based on data from API call" }
268281
<p>I have just finished an assignment and would like to know what best practices I might be missing in my code. Any help would be hugely appreciated.</p> <pre><code>import random random.seed(42) def alphabet_position(text_): def numeric_position(char_): # Built in method for getting the alphabet position ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-23T14:17:03.230", "Id": "529034", "Score": "2", "body": "What do `alphabet_position`, `count_smileys` and the Bingo stuff have to do with each other? It seems they're completely unrelated. Also: What are they supposed to do? Task descr...
[ { "body": "<p>As pointed out <a href=\"https://stackoverflow.com/a/69300095/16759116\">at stackoverflow</a>, your method</p>\n<pre><code>random.choice([i for i in range(1, self.initial_size)\n if i not in self.picked_balls])\n</code></pre>\n<p>for picking the next ball is rather inefficient. Your ...
{ "AcceptedAnswerId": "268295", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-23T09:23:05.687", "Id": "268283", "Score": "2", "Tags": [ "python", "python-3.x" ], "Title": "Find alphabet position, count smileys, and play bingo with assertion testing" }
268283
<p>I have a small program that is creating a counterpart of existing data files, unzips them and then changes the names of the files. This process runs on a remote desktop server (windows).</p> <p><strong>I have one problem:</strong> The runtime of this program is really slow, to create a counterpart of one directory a...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-23T16:10:08.927", "Id": "529042", "Score": "0", "body": "How many files per directory are we talking about, roughly? For benchmarking purposes." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-27T07:16:35.04...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-23T09:38:16.540", "Id": "268286", "Score": "2", "Tags": [ "python", "performance" ], "Title": "Python code that is unzipping files" }
268286
<p>I'm using a <code>long</code> as a bitset to represent a game board. If a field is set (<code>X</code>) the corresponding bit is set, if it's empty (<code>-</code>), it's not. The fields are numbered from left to right starting from <code>0</code>.</p> <p>For example, the following board</p> <pre><code>0 1 2 X...
[]
[ { "body": "<h2>The questions / replacement algorithms</h2>\n<blockquote>\n<p>Is there a more efficient way to perform the rotations?</p>\n</blockquote>\n<p>All the major rotate/flip/transpose operations on bitboards can be <a href=\"https://www.chessprogramming.org/Flipping_Mirroring_and_Rotating\" rel=\"nofoll...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-23T11:12:10.567", "Id": "268288", "Score": "0", "Tags": [ "java", "performance", "bitwise", "bitset" ], "Title": "Transformations on a game board represented as a bitset" }
268288
<pre><code>import random import string def random_char(y): return ''.join(random.choice(string.ascii_uppercase) for x in range(y)) p1 = str(random.randrange(1, 99)) p2 = str(random_char(5)) p3 = str(random.randrange(1, 9)) p4 = str(random_char(2)) p5 = str(random.randrange(1, 9)) p6 = str(random_char(1)) # Y p...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-23T11:55:01.000", "Id": "529023", "Score": "0", "body": "Do you want this to be `1-2 digits + 5*random uppercased letters + ...` or it can be any random string?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-...
[ { "body": "<p>In your <code>random_char</code> function, you don't use <code>x</code> at all. Replace it with <code>_</code> (it's conventional in python to use <code>_</code> for throwaway variables). <code>y</code> could also be renamed to something more descriptive. The name of the function could also be ren...
{ "AcceptedAnswerId": "268292", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-23T11:51:19.193", "Id": "268290", "Score": "1", "Tags": [ "python", "random" ], "Title": "Generate random string to match a specific pattern" }
268290
<p>I receive .pem key as one string which needed to be formatted to be able to create signature</p> <pre><code>const input = '-----BEGIN RSA PRIVATE KEY-----somekey-----END RSA PRIVATE KEY-----' const newStr = str.replace(/-----BEGIN RSA PRIVATE KEY-----/g, '-----BEGIN RSA PRIVATE KEY-----\n').replace(/-----END RSA PRI...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-23T12:29:17.840", "Id": "529026", "Score": "0", "body": "Can you clarify what you mean by \"needed to be formatted\"? Perhaps it would be better to show example input and expected output (obviously don't show a real private key, thoug...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-23T12:18:23.507", "Id": "268291", "Score": "0", "Tags": [ "javascript", "regex" ], "Title": "Format pem key one line string in JS" }
268291
<p>I am trying to create an API wrapper for recharge (A Shopify subscription service), I am using the HTTParty gem</p> <pre><code>module RechargeAPI require 'httparty' BASE_URI = 'https://api.rechargeapps.com' API_TOKEN = 'my_token' class Client include HTTParty base_uri BASE_URI headers 'X-Recharg...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-23T14:43:58.810", "Id": "529036", "Score": "0", "body": "Welcome to Code Review! The current question title is too general to be useful here. Please [edit] to the site standard, which is for the title to simply state **the task accompl...
[ { "body": "<p>I think you should have three classes:</p>\n<ol>\n<li>A class responsible for your HTTP requests to Shopify in general.</li>\n<li>A class that calls your HTTP class to make the requests; it calls the right URLs and creates the domain objects.</li>\n<li>The Customer class, which should be more inde...
{ "AcceptedAnswerId": "268867", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-09-23T14:07:39.847", "Id": "268294", "Score": "1", "Tags": [ "object-oriented", "ruby", "ruby-on-rails", "api" ], "Title": "Refactoring Ruby recharge REST API wrapper by using c...
268294