body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<h1>Introduction</h1> <p>Sometimes, especially in more complex class structures, I feel uncertain in some way whether undiscovered circular dependencies might exist.</p> <p>So I thought about how I can easily have their existence checked.</p> <hr /> <h1>The idea behind</h1> <p>I came up with the idea of using a central...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-06T10:42:23.047", "Id": "259153", "Score": "2", "Tags": [ "vba" ], "Title": "Check for circular dependencies" }
259153
<p>This is my function to generate all possible unique combinations of positive numbers these have sum equal to N.</p> <p>For example:</p> <ul> <li><p>If the input is <code>4</code></p> </li> <li><p>The output should be: <code>[ '4', '1+3', '1+1+2', '1+1+1+1', '2+2' ]</code></p> </li> </ul> <p>You can try it online <a ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-06T12:30:04.693", "Id": "511029", "Score": "0", "body": "The code you provide in question does not work. Undeclared variable `l` (second last line of function `f`) is that meant to be `result`? You should fix the code befor you can get...
[ { "body": "<ul>\n<li>Your code does not perform very well, I suppose because of the double recursion within the <code>f</code>-method.</li>\n<li>It lacks <em>readability</em>: let's say you return to this code a year later: how long would it take to understand what you actually wanted to do?</li>\n<li>Always us...
{ "AcceptedAnswerId": "259206", "CommentCount": "10", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-06T10:50:59.370", "Id": "259154", "Score": "2", "Tags": [ "javascript", "algorithm", "node.js", "combinatorics" ], "Title": "Generate all possible unique combinations of pos...
259154
<p>My requirements are:</p> <ol> <li>Create a .net 5 class that encapsulates a task runner (i.e. a wrapper around a Task object)</li> <li>The class should be thread-save</li> <li>Consumer of the class should be able to know if the task is running</li> <li>Consumer should be able to start/stop and start again the runner...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-06T19:36:18.843", "Id": "511075", "Score": "0", "body": "Few comments: 1) `await Task.Delay(Timeout.Infinite);` - there's no a normal way to handle that. The only way to stop any executing (even hung) code is running it on a separate O...
[ { "body": "<p>Here are my observations/questions:</p>\n<ul>\n<li><code>TaskWorker</code>:\n<ul>\n<li>This name does not tell me anything\n<ul>\n<li>Is it a <em>thing</em> which works on a <code>Task</code>?</li>\n<li>Is there a <code>TaskManager</code> or <code>TaskDispatcher</code> which distributes the tasks ...
{ "AcceptedAnswerId": "259502", "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-06T11:21:37.247", "Id": "259158", "Score": "1", "Tags": [ "c#" ], "Title": "Create a cancelable Task background runner class" }
259158
<p>In a Knex query (PSQL) method I used <code>.modify()</code> to be able to run a <code>if(...)</code> to conditionally run a <code>whereIn()</code> when the condition is true and present from a request.</p> <p>The method is used to determine a status of a conversation based on messages status. As mandatory we have <c...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T06:57:20.943", "Id": "511233", "Score": "1", "body": "You have to be careful when using a join for this type of query as multiple members of the given type will change the number of rows in the group (although not an issue here). I ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-06T13:08:03.150", "Id": "259163", "Score": "0", "Tags": [ "javascript", "postgresql" ], "Title": "Knex query method which conditionally run a whereIn() in the query with .modify() to hav...
259163
<p>I am translating this <a href="https://en.cppreference.com/w/cpp/algorithm/next_permutation" rel="nofollow noreferrer">next permutation</a> algorithm in C++:</p> <blockquote> <pre class="lang-cpp prettyprint-override"><code>template&lt;class BidirIt&gt; bool next_permutation(BidirIt first, BidirIt last) { if (fi...
[]
[ { "body": "<p>In no particular order:</p>\n<ul>\n<li><p>Create test cases so you can have some confidence while refactoring.</p>\n</li>\n<li><p>Don't create empty structs (<code>Solution</code>) just to give them functions. <code>next_permutation</code> is perfectly fine as a free function. If you <em>have</em>...
{ "AcceptedAnswerId": "259187", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-06T13:45:20.030", "Id": "259168", "Score": "4", "Tags": [ "rust", "combinatorics" ], "Title": "Rust implementation of next-permutation" }
259168
<p>Ive been learning c for the past few weeks, I made a simple turn-based game to show off what I know. Is there anything I can do to improve the code or make the game run better?</p> <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;math.h&gt; #include &lt;w...
[]
[ { "body": "<h2>Formatting &amp; Conventions</h2>\n<p>Always run your code through an autoformatter. On Linux, I use clang-format, and on Win10 I use VSCode's autoformatting intellisense features. I'm not sure of your exact setup, but formatting is big.</p>\n<p>Next, variable names. The variable <code>choose</co...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-06T19:43:05.147", "Id": "259177", "Score": "4", "Tags": [ "beginner", "c", "game" ], "Title": "Simple CMD turn-based game made in C" }
259177
<p>I want to present books that has chapters and sections, and contents in each book, chapter and section.</p> <p>This is my schema:</p> <pre><code>type BookId = string type ChapterId = string type SectionId = string type ContentId = string export type SourceId = | ChapterId | SectionId | BookId type Book = { id:...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-06T21:02:53.660", "Id": "259180", "Score": "0", "Tags": [ "javascript", "typescript" ], "Title": "Show contents in a book chapter and sections in a highly normalized repository" }
259180
<p>Example of use:</p> <pre><code>var users = await usernames.SelectTaskResults(GetUserDetails, 4); </code></pre> <p>where <code>GetUserDetails(string username)</code> is a method that calls HttpClient to access an API and returns a User object. The <code>SelectTaskResults</code> returns the awaited tasks. At most, the...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-07T15:29:03.430", "Id": "511178", "Score": "4", "body": "Welcome to Code Review! I rolled back your last edit. After getting an answer you are not allowed to change your code anymore. This is to ensure that answers do not get invalidat...
[ { "body": "<p>A TPL inside <code>async</code> implementation: mixing of implementaion concepts makes the code complicated or even buggy. Finally <code>Parallel.ForEach</code> is blocking the current thread which isn't allowed in <code>async</code> programming.</p>\n<p>Also avoid blocking operations on <code>Tas...
{ "AcceptedAnswerId": "259184", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-06T22:23:34.760", "Id": "259181", "Score": "3", "Tags": [ "c#", "iterator", "async-await", "task-parallel-library" ], "Title": "Throttled execution of an enumeration of Tasks...
259181
<p>It's only my second code in C so far. I've some knowledge about this language, dynamic memory allocation etc. but I'm still far to be good in it. Earlier I used to program in Java, so I could have passed some habits from there. In general - what should I change to make this code somehow more perfect, what I shouldn'...
[]
[ { "body": "<h1>General Observations</h1>\n<p>Performance could be improved by reading all the contacts into memory at the start of the program and writing all the contacts back to a file at the end of the program. Searching a file for a duplicate is more time consuming then searching memory. This does however d...
{ "AcceptedAnswerId": "259233", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-07T06:58:33.190", "Id": "259192", "Score": "2", "Tags": [ "c" ], "Title": "Contact Management System in C" }
259192
<p>I have a use case, where I want to take screenshots via <em>scrot</em> without leaving behind residual files:</p> <pre><code>&quot;&quot;&quot;Takes screenshots.&quot;&quot;&quot; from pathlib import Path from subprocess import check_call from tempfile import TemporaryDirectory from digsigclt.os.posix.common impor...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-07T10:31:14.533", "Id": "511137", "Score": "1", "body": "The problem is that `scrot` silently doesn't write to an existing file, not that you can't read the contents. You could just run it in the temporary directory and do `-e 'echo $n...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-07T08:32:10.720", "Id": "259193", "Score": "0", "Tags": [ "python", "python-3.x" ], "Title": "Return screenshot data from subprocess without residual files" }
259193
<p>I have written a function that copies memory from one destination to another. I would like you to view my code and tell me if I have to fix something. That's the code:</p> <pre><code>void* memCopy(void* destination, const void* source, size_t size) { double *a = (double*)source, *b = (double*)destination; vo...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-07T10:31:29.940", "Id": "511138", "Score": "2", "body": "I'm not a fan of `while` loops for anything other than (near-)infinite loops. Is there a reason you used them instead of `for` loops? For reference, [this is how one version of `...
[ { "body": "<p>Your code doesn't compile cleanly with GCC:</p>\n<pre><code>move.c: In function 'memCopy':\nmove.c:16:15: warning: comparison of distinct pointer types lacks a cast\n while (a2 &lt; end)\n ^\n</code></pre>\n<p>Also 2 brief points:</p>\n<ol>\n<li>Why reinvent the wheel? Most imple...
{ "AcceptedAnswerId": "259196", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-07T09:58:39.120", "Id": "259194", "Score": "2", "Tags": [ "c", "reinventing-the-wheel", "memory-management" ], "Title": "My own function for copying memory in C" }
259194
<p>I'm working on a mini-framework in Python, designed largely for backend REST APIs. One important aspect I'm working on now is testing, and I'm designing a drop-in backend replacement that switches it from using an actual database on the backend to using an in-memory data store. The goal is to simplify testing sinc...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T20:03:13.540", "Id": "511577", "Score": "0", "body": "When posting bounties filling out the optional box is a good idea. You can explain what you feel is lacking in the existing answers and helps you get the feedback you want. Since...
[ { "body": "<p>If I were to program your class I'd focus on defining operators separately to the table.\nPreferably in a class which looks like normal Python code.</p>\n<p>If you were to change your operators from <code>=</code> to, say, <code>eq</code> we could just define a class and use <code>getattr</code>.\...
{ "AcceptedAnswerId": "259211", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-07T11:49:02.847", "Id": "259198", "Score": "4", "Tags": [ "python", "python-3.x" ], "Title": "In memory \"table\" filtering in Python" }
259198
<p>The purpose of this code is apply a function to each selected cell. This works on contiguous and non-contiguous selections.</p> <h2>function assignText(value, prepend)</h2> <p>Returns a closure that encapsulates the original parameter values and a callback function which takes a single cell as a parameter. This cl...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-07T12:20:09.513", "Id": "259199", "Score": "1", "Tags": [ "excel" ], "Title": "Appending and Prepending Text to All Selected Cells" }
259199
<p>For the past week or two I have been working on a small library that aims to ease development of SFML games, and after finishing it I would love to get some feedback on it. I don't have access to any tutors so feedback is very valuable to me when trying to get better at coding. Thanks in advance to anyone who sets s...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T00:18:18.903", "Id": "511223", "Score": "2", "body": "Hi @JensB - SFML? perhaps add a link?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T08:45:23.033", "Id": "511239", "Score": "1", "bo...
[ { "body": "<p>I have never written such a system but I worked a bit with Qt framework that does similar things. And does them well enough to suggest studying its source code. I personally learned a lot from it. Below are moments that I notices</p>\n<h2>Signals and slots</h2>\n<p>From my experience, they make li...
{ "AcceptedAnswerId": "259274", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-07T12:55:08.157", "Id": "259201", "Score": "3", "Tags": [ "c++", "game", "library" ], "Title": "Small library for SFML to streamline program flow" }
259201
<h2>Project Description:</h2> <p><em>Chess without checks: A chess variant where you can take the enemy king.</em></p> <p>This engine implementation is for chess without checks. Since checks don't exist, expect the code to not account for pinned pieces. Kings can move to dangerous squares (and be captured next turn). C...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T13:16:52.473", "Id": "511268", "Score": "1", "body": "Some general thoughts: don't use `new` in hot code (search), don't use vector or list (prefer c-arrays, you may pre-allocate 6 arrays for the 3 moves you search (6 ply). In gener...
[ { "body": "<p>Note: this is just a review of <code>graphics.h</code> and <code>graphics.cpp</code>.</p>\n<h1>Apply RAII consistently</h1>\n<p>I see you used <code>std::unique_ptr</code> for <code>window</code> and <code>renderer</code>, but you did not use smart pointers for <code>boardTexture</code> and <code>...
{ "AcceptedAnswerId": null, "CommentCount": "10", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-07T12:57:01.043", "Id": "259202", "Score": "15", "Tags": [ "c++", "performance", "algorithm", "chess", "sdl" ], "Title": "Chess engine for chess without checks in C++" }
259202
<p>Here is the problem:</p> <blockquote> <p>Given a numpy array 'a' that contains n elements, denote by b the set of its unique values ​​in ascending order, denote by m the size of array b. You need to create a numpy array with dimensions n×m , in each row of which there must be a value of 1 in case it is equal to the...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-07T18:29:43.493", "Id": "511195", "Score": "0", "body": "Please do not edit the question with suggestions from answers. If you want a new round of feedback with updated code, you can post a new question." }, { "ContentLicense":...
[ { "body": "<p><strong>Remove <code>sorted</code></strong></p>\n<p>From the docs: <a href=\"https://numpy.org/doc/stable/reference/generated/numpy.unique.html\" rel=\"nofollow noreferrer\"><code>numpy.unique</code></a> returns the sorted unique elements of an array.</p>\n<p>You can simply remove the call to <cod...
{ "AcceptedAnswerId": "259209", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-07T15:29:29.543", "Id": "259207", "Score": "4", "Tags": [ "python", "array", "numpy" ], "Title": "Creating nxm index list of array a" }
259207
<p>Today I have learned alot and still learning. I have came to a situation where I have realized that I have created a database with multiple functions that does similar stuff but different queries. However by looking at the code we can see a similar &quot;path&quot; of these functions and I have tried and tried to kn...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-07T20:14:24.467", "Id": "511203", "Score": "0", "body": "Why are your functions not methods on `QuickConnection`?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-07T20:24:59.190", "Id": "511206", "S...
[ { "body": "<p>Don't hard-code <code>DATABASE_CONNECTION</code> in your source. The connection parameters need to live outside of it, for configurability and security.</p>\n<p>Nearly every comment that you have is more harmful than having no comment at all - this:</p>\n<pre><code>class QuickConnection:\n &quo...
{ "AcceptedAnswerId": "259217", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-07T18:41:17.647", "Id": "259212", "Score": "2", "Tags": [ "python-3.x" ], "Title": "Mutilple functions connected to database" }
259212
<p>I made a module called &quot;matrix-py&quot; in python to add, subtract, multiply, transpose matrices</p> <p>I want to know how to improve the code quality and if there's something wrong about my code</p> <p>here's the code on github: <a href="https://github.com/FaresAhmedb/matrix-py" rel="nofollow noreferrer">https...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-07T23:18:15.223", "Id": "511221", "Score": "0", "body": "Why not `numpy`?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T00:01:22.820", "Id": "511222", "Score": "1", "body": "reinventing-the...
[ { "body": "<p>Interesting project, writing it python does come with some limitations. Numpy is mostly written in C and there are good reasons for it. The memory management is much better and most of the array-manipulation routines can be done in-place instead of copying back and forth. AFAIK, there is no equiva...
{ "AcceptedAnswerId": "259230", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-07T22:55:22.247", "Id": "259220", "Score": "4", "Tags": [ "python", "python-3.x", "reinventing-the-wheel" ], "Title": "Python: Matrix Manipulation module" }
259220
<p>While answering <a href="https://codereview.stackexchange.com/a/259114/231235">this code review question</a>, I proposed a solution with <code>List&lt;DataTable&gt;</code>. I am trying to encapsulate this data structure into a &quot;DataGridView Undo/Redo Manager&quot; class <code>DataGridViewManager</code> and ther...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T18:26:47.353", "Id": "511290", "Score": "1", "body": "As for me, making `DataTable` copy on each cell edit isn't a good idea. What if I have 10x1000 table, then i edit it for few hours? At least every single editing/redo/undo operat...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-07T23:52:05.300", "Id": "259222", "Score": "1", "Tags": [ "c#", "object-oriented", ".net", "winforms", ".net-datatable" ], "Title": "DataGridView Undo/Redo Manager in C#" }
259222
<p>Here's an example script I wrote for Instagram (Facebook)'s Basic Display API. I did this for myself because I haven't used Instagram's API since their Legacy API was disabled, and I needed to familiarize myself for upcoming projects. It's super easy to understand and is meant for learning purposes. It covers every ...
[]
[ { "body": "<h1>Overall feedback</h1>\n<p>It might be wise to put all the functions and constants into a class for the sake of encapsulation. That way the constants can be namespaced. Perhaps it would be wise to have a constant for the base URLs - for example:</p>\n<pre><code>const API_URL = 'https://api.instagr...
{ "AcceptedAnswerId": "259228", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T01:49:54.903", "Id": "259223", "Score": "1", "Tags": [ "php", "api", "curl", "oauth", "instagram" ], "Title": "Instagram Basic Display API Full Example PHP" }
259223
<p>I have two functions. Both have to have unique elements, one with <code>Integers</code> and the other a <code>String</code> which returns a list of <code>Char</code>. My runtime is currently quite high and I'm not allowed to use imports, but I was wondering how to improve them:</p> <pre><code>uniqueInt:: [Int] -&gt;...
[]
[ { "body": "<p>Firstly you might want to make use of a Haskell feature to combine both functions into one:</p>\n<pre><code>unique :: Eq a =&gt; [a] -&gt; [a]\nunique [] = []\nunique xs = [x | (x,y) &lt;- zip xs [0..], x `notElem` (take y xs)]\n</code></pre>\n<p>Now let's talk about performance. Obviously lists ...
{ "AcceptedAnswerId": "259237", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T06:18:03.913", "Id": "259227", "Score": "1", "Tags": [ "strings", "haskell" ], "Title": "Unique elements, long runtime Haskell" }
259227
<p>I build this simple function, <a href="https://www.python.org/dev/peps/pep-0008/#introduction" rel="noreferrer">trying to use PEP 8 Style</a>, something that I discovered recently thanks <a href="https://codereview.stackexchange.com/questions/255805/filtering-a-list-based-on-a-suffix-and-avoid-duplicates">to this pr...
[]
[ { "body": "<p>Overall, it looks fine. I probably would've written it a little differently, and I'll explain the differences.</p>\n<pre><code>import datetime\n\ndef get_current_quarters():\n &quot;&quot;&quot;A function that returns an array\n with all the actual year quarters\n &quot;&quot;&quot;\n current_...
{ "AcceptedAnswerId": "259234", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T09:06:30.533", "Id": "259231", "Score": "10", "Tags": [ "python", "python-3.x", "datetime" ], "Title": "Return quarters of current year" }
259231
<p>I wrote the code to log in php to the admin panel. Everything works as it should. But I am not sure if it is well written code and if it is safe. I care about security. I have read a lot about it but I am still not sure. Please, help me.</p> <pre><code>&lt;form method=&quot;post&quot;&gt; &lt;input type=&quot;ema...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T18:16:28.633", "Id": "511289", "Score": "0", "body": "I don't think there is a lot to review here. What you presented is the general flow of validation but it does not allow us to judge the overall security. For instance, the code f...
[ { "body": "<p>The devil is in the details, and you are omitting a lot of details from your code that usually go wrong. That said, I at least saw the following issues in your code:</p>\n<p><code>session_regenerate_id</code> regenerates the... id... of the session. I am not sure why you do this, but it is not nec...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T11:33:55.043", "Id": "259235", "Score": "3", "Tags": [ "php", "html", "security", "authentication", "session" ], "Title": "Security of the login code on the website" }
259235
<p>My current project is a <em>Settlers of Catan</em> server in Haskell. I often manage to achieve my goals within Haskell, but the code is getting messier as the project grows.</p> <p>My question is about the <code>placeBuilding :: Board -&gt; Building -&gt; VertexCoordinate -&gt; Board</code> function that places a b...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T22:22:41.453", "Id": "511320", "Score": "1", "body": "Have you thought about using a [map](https://hackage.haskell.org/package/containers-0.6.2.1/docs/Data-Map-Strict.html) to map coordinates to buildings? i.e. `vertices :: Board ->...
[ { "body": "<p>I'm not super familiar with Catan, having played it only once in my life and not even to completion, but a grid's a grid, and hex grids can be modeled using three axes instead of the usual two. The data structure you're searching for is an <code>Array</code>. (Or a <code>Vector</code>, if you wann...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T12:55:37.870", "Id": "259239", "Score": "1", "Tags": [ "haskell", "comparative-review" ], "Title": "Changing an element in a list when a predicate holds" }
259239
<p>To bootstrap our application we have a configuration stored in a JSON file. This config holds different settings, like definition of endpoints (e. g. an API or SMS gateway etc.) or some default values for login.</p> <p><strong>endpoint.ts</strong></p> <pre><code>export const isEndpoint = (candidate: any): candidate ...
[]
[ { "body": "<p>If you're worried that someone may replace your schema during build, you should also be worried that someone might replace any other file as well. That's pure paranoia...</p>\n<p>I would say the typescript way is to write the config in typescript as well. If that's not an option, then sure go for ...
{ "AcceptedAnswerId": "259387", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T12:59:15.387", "Id": "259240", "Score": "0", "Tags": [ "json", "typescript", "angular-2+" ], "Title": "Verify application configuration from JSON file with matching type using...
259240
<p>I've created an <code>IValueConverter</code> in order to Bind to the index value of a Collection.</p> <p>However it seems to be rather slow/infefficient and I wonder if there is a better/different way to do this.</p> <pre><code>public class IndexValueConverter : IValueConverter { public object Convert(object val...
[]
[ { "body": "<p>The best way to optimize that is store indexes directly in the source data. So, the <code>int</code> public Property in the <code>ADataModel</code>. It's rather faster to refill indexes there with O(n) complexity than with O(n<sup>2</sup>) using Converter.</p>\n<p>The code can be a bit optimized: ...
{ "AcceptedAnswerId": "259259", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T13:54:08.440", "Id": "259242", "Score": "1", "Tags": [ "c#", "xaml", "xamarin" ], "Title": "Index IValueConverter Optimisation" }
259242
<p>I'm new to coding and working on a text based game moving from room to room. The code works in pycharm but according to an instant feedback program I entered it into, it gave some tips on it and I am not exactly sure how how to improve upon it. Here is what it gave me:</p> <ol> <li>The Great Hall string is a key in ...
[]
[ { "body": "<p>Overall I don't think the code is that bad, considering what is the purpose; but if you want to expand your game I think the greatest issue is the data structure.</p>\n<p>It'd be very easy to misplace some room or call it in a different way if you have to repeat yourself every time, so I suggest y...
{ "AcceptedAnswerId": "259276", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T14:59:39.797", "Id": "259245", "Score": "4", "Tags": [ "python" ], "Title": "Python text based game room to room movement" }
259245
<p>I have a list of key:</p> <pre><code>list_date = [&quot;MON&quot;, &quot;TUE&quot;, &quot;WED&quot;, &quot;THU&quot;,&quot;FRI&quot;] </code></pre> <p>I have many lists of values that created by codes below:</p> <pre><code>list_value = list() for i in list(range(5, 70, 14)): list_value.append(list(range(i, i+10,...
[]
[ { "body": "<p>One alternative approach is to take advantage of <code>enumerate()</code> -- which allows\nyou to iterate over what could be thought of as a <code>zip()</code> of a list's indexes and\nvalues. To my eye, this version seems a bit clearer and simpler.</p>\n<pre><code>days = ['MON', 'TUE', 'WED', 'TH...
{ "AcceptedAnswerId": "259249", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T15:13:32.127", "Id": "259246", "Score": "3", "Tags": [ "python", "hash-map" ], "Title": "Create a dictionary from a list of key and multi list of values in Python" }
259246
<p>I'm having doubts about which is the best strategy to manage the many service clients in this web app.</p> <p><strong>&quot;Best&quot; in terms of a good compromise between user's device RAM and Javascript execution speed (main thread ops).</strong></p> <p>This is what I'm doing right now, this is the main file:</p>...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T16:40:43.380", "Id": "511474", "Score": "0", "body": "Thank you. I updated. Can you help me?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-28T15:14:58.447", "Id": "515711", "Score": "1", "b...
[ { "body": "<p><strong>Angular</strong><br />\nIf you use Angular you are able to use store. For example <a href=\"https://www.ngxs.io/\" rel=\"nofollow noreferrer\">ngxs</a> or <a href=\"https://ngrx.io/docs\" rel=\"nofollow noreferrer\">ngrx</a> modules for your application.</p>\n<p>One more way in angular use...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T15:14:52.697", "Id": "259247", "Score": "1", "Tags": [ "design-patterns", "comparative-review", "typescript", "protocol-buffers" ], "Title": "How can I refactor for handling m...
259247
<p>I've learned that in C++17, std::invoke isn't constexpr. To make a constexpr version, I <em>could</em> copy the implementation provided here: <a href="https://en.cppreference.com/w/cpp/utility/functional/invoke" rel="nofollow noreferrer">https://en.cppreference.com/w/cpp/utility/functional/invoke</a> , OR I can comp...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T15:56:53.570", "Id": "259248", "Score": "2", "Tags": [ "c++", "performance", "reinventing-the-wheel", "c++17", "sfinae" ], "Title": "Improving constexpr invoke function C+...
259248
<p>The goal of each frame of the animation to be the same length as the one before it, regardless of the amount of processing that takes place as the frame is being built.</p> <p>This is a little animation demo that I wrote to show off the basics of a game loop in Python. With a newbies eyes in mind I have tried to kee...
[]
[ { "body": "<h2>Typos</h2>\n<p><code>Globla</code> -&gt; <code>Global</code></p>\n<p><code>Tookkit</code> -&gt; Toolkit?</p>\n<p><code>millesconds</code> -&gt; <code>milliseconds</code></p>\n<h2>Nomenclature</h2>\n<p>By the PEP8 standard, your functions and variables would be called</p>\n<pre><code>win_width\nwi...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T17:51:47.843", "Id": "259250", "Score": "3", "Tags": [ "python", "python-3.x", "game", "animation", "tkinter" ], "Title": "Frame Pacing and Animation in Python/tkinter" }
259250
<p>I build a small web-app using flask for my parents to text their customers about promotions. I am using Twilio API. I just finished the <code>myapp.com/new-campaign</code> page and I would like to have some suggestions as it's my first full stack applicaton as I just added a new feature: estimated cost of the campai...
[]
[ { "body": "<h2>Typos</h2>\n<p><code>caled everytime</code> -&gt; <code>called every time</code></p>\n<p><code>MAX_CARACTERS_PER_SEGMENT</code> -&gt; <code>MAX_CHARACTERS_PER_SEGMENT</code></p>\n<p><code>max_caracters</code> -&gt; <code>max_characters</code></p>\n<p>And my first language is not French, but shoul...
{ "AcceptedAnswerId": "259333", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T18:05:16.720", "Id": "259252", "Score": "1", "Tags": [ "python", "javascript", "object-oriented", "flask" ], "Title": "text-messaging app using twilio" }
259252
<p>I have created a thread before regarding the similar code review I had before <a href="https://codereview.stackexchange.com/questions/259212/mutilple-functions-connected-to-database/259217?noredirect=1#comment511273_259217">Previous code review</a> - I have updated a small piece of advice I got from previous answer ...
[]
[ { "body": "<p>Please just delete these:</p>\n<pre><code>&quot;&quot;&quot;\nCheck if link exists\n:param store:\n:param link:\n:return:\n&quot;&quot;&quot;\n</code></pre>\n<p>I'm guessing that your IDE is creating this template for you, with the expectation that you write meaningful documentation for the parame...
{ "AcceptedAnswerId": "259263", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T19:45:39.913", "Id": "259255", "Score": "1", "Tags": [ "python-3.x", "sql" ], "Title": "Multiple functions connected to SQL" }
259255
<p>I have a table called dfmt that lists the location, revenue and franchise. I want to find the franchise pairs that operate together in more than one location.</p> <p><a href="https://i.stack.imgur.com/EnNQB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EnNQB.png" alt="Some sample data" /></a></p...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T21:47:02.510", "Id": "511316", "Score": "0", "body": "Hi @anon - not sure what the R has to do with it - perhaps remove it from the question and put in some sample data.." }, { "ContentLicense": "CC BY-SA 4.0", "Creation...
[ { "body": "<p>Something like this - use group by to gather all the &quot;franchise pairs&quot; and you count how many have locations..</p>\n<pre class=\"lang-sql prettyprint-override\"><code>SELECT X.fr, X.fr2, COUNT(X.loc) as count FROM \n(\n select T1.fr, T2.fr2, T1.loc from dfmt T1 join (select fr as fr2, l...
{ "AcceptedAnswerId": "259260", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-08T20:54:11.060", "Id": "259258", "Score": "-1", "Tags": [ "sql", "join" ], "Title": "SQL JOIN QUERY with more than one items in common: Find the franchise pairs that operate togethe...
259258
<p>Since writing your own C++ game engine seems to be really popular these days (seriously just look at the amount of people presenting their WIPs on YouTube) I figured I'd try it myself.</p> <p>My mental model of an event system looks like this:</p> <ul> <li><code>Events</code> are basically signals that tell you that...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-09T06:21:45.280", "Id": "511337", "Score": "1", "body": "Welcome to CodeReview! Could you please elaborate why do you think *it's horrible*?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-09T08:23:47.547",...
[ { "body": "<p><strong>Why?</strong></p>\n<p>What's it actually for? What sort of &quot;event&quot; are we dealing with, and why do we need to delay dealing with that event, instead of just calling a function directly?</p>\n<p>Why do we need event type erasure, instead of dealing with specific event types, e.g. ...
{ "AcceptedAnswerId": "259271", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-09T02:06:50.533", "Id": "259265", "Score": "2", "Tags": [ "c++", "c++17", "event-handling", "polymorphism" ], "Title": "C++: Event system for game engine" }
259265
<p><strong>Code is Working Review and Recommend What Are Best Practice</strong></p> <p><strong>What I am trying to achieve.</strong></p> <ol> <li><p>API with Flask that runs any python file from the current directory.</p> </li> <li><p>Run the file and get output in JSON</p> </li> </ol> <p>Below is the code for the app....
[]
[ { "body": "<p>To be honest this code looks pretty dangerous. <code>exec</code> is dangerous in its own right, and using it in conjunction with user-provided input makes an explosive combination.</p>\n<p>One flaw is the <strong>path traversal</strong> vulnerability. For example, providing a file name like &quot;...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-09T03:41:56.830", "Id": "259266", "Score": "2", "Tags": [ "python-3.x", "json", "flask" ], "Title": "Run python File With get request flask API" }
259266
<p>I'm trying to implement a <code>re_sub</code> and it's been quite tricky for me to do. I wanted to take the python code to replace a string -- <code>re.sub(r&quot;;.+&quot;, &quot; &quot;, s)</code> -- and do it in C. Examples of grabbing a single regex match were pretty easy to find (and do) but doing multiple mat...
[]
[ { "body": "<p>You were so close! So close to having re-entrant code. You declare <code>buffer</code> as a global, but also pass it into a function. It should be easy enough to just move it to <code>main</code> and keep your functions as-is.</p>\n<p>You have two different pointer offset styles (right next to eac...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-09T04:32:52.107", "Id": "259267", "Score": "2", "Tags": [ "c" ], "Title": "Doing a re_sub in C using pcre" }
259267
<p>I need to split a string by a separator but don't want to split if the separator is prefixed by the escape string.</p> <p>For example:</p> <p><code>&quot;This works\\ but it\\ isn't pretty.&quot;</code> with <code>&quot; &quot;</code> as the separator and <code>&quot;\\&quot;</code> as the escape string should produ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-09T18:10:05.110", "Id": "511409", "Score": "0", "body": "does your code work ?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-09T18:14:29.613", "Id": "511410", "Score": "1", "body": "yes, it do...
[ { "body": "<p>One approach that's simple, but is a bit of a dirty trick: first replace sequences of <code>escape+separator</code> with a string that's never going to occur in your text (for example a NUL byte <code>&quot;\\x00&quot;</code>), then do the split, then do the reverse replace on each token. For exam...
{ "AcceptedAnswerId": "259382", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-09T08:13:31.020", "Id": "259270", "Score": "1", "Tags": [ "strings", "go", "escaping" ], "Title": "Golang - Splitting a string by a separator not prefixed by an escape string" }
259270
<p>I wrote a short function that should check if user input does contain any bad words that I predefined inside <code>$bad_words</code> array. I don't even care to replace them - I just want to ban if there are any. The code seems to work as it should - in the example below will detect the quoted string <code>badword</...
[]
[ { "body": "<p>Two things I have noticed:</p>\n<ol>\n<li><p>You remove all non-alpha-numeric characters, apart from the dash and space characters. I don't see what this adds to your filter? Clearly all the other characters are never part of your swear words, so why bother to remove them? It could, in theory, hav...
{ "AcceptedAnswerId": "259343", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-09T09:49:39.037", "Id": "259273", "Score": "1", "Tags": [ "php", "strings", "array" ], "Title": "PHP strpos() as a way to implement an swear word filter" }
259273
<p>While I understand that &quot;<a href="https://vlang.io/" rel="nofollow noreferrer">V</a> is a simple language,&quot; I find myself repeating a lot of stuff. For instance the whole first block, &quot;measure column widths,&quot; could beautifully be accomplished by two simple list comprehension lines in Python. Is t...
[]
[ { "body": "<p>V <a href=\"https://github.com/vlang/v/blob/master/doc/docs.md#array-for\" rel=\"nofollow noreferrer\">already has</a> a built-in enumeration for plain arrays:</p>\n<pre><code>for i, a in arr {\n}\n</code></pre>\n<p>Which removes six unnecessary lines of code.</p>\n<p>List comprehension would remo...
{ "AcceptedAnswerId": "259485", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-09T15:24:53.140", "Id": "259283", "Score": "2", "Tags": [ "beginner", "matrix", "v-language" ], "Title": "Convert a matrix (\"DataFrame\") to printable string" }
259283
<p>The <a href="https://vlang.io/" rel="nofollow noreferrer">V programming language</a> is closely related to Go.</p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-09T16:05:06.420", "Id": "259284", "Score": "0", "Tags": null, "Title": null }
259284
For code written in the V programming language.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-09T16:05:06.420", "Id": "259285", "Score": "0", "Tags": null, "Title": null }
259285
<p>I'm new to Haskell, and I figured that pairwise summation is something I could do easily. I wrote this:</p> <pre><code>pairwiseSum :: (Num a) =&gt; [a] -&gt; a pairwiseSum [] = 0 pairwiseSum [x] = x pairwiseSum (x:xs) = (pairwiseSum (everyOther (x:xs))) + (pairwiseSum (everyOther xs)) everyOther :: [a] -&gt; [a] ev...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-09T23:31:16.367", "Id": "511424", "Score": "1", "body": "I must be missing something, but this appears to compute the sum of the input list. If you wanted to make a list of the pairwise sums you could do something like `pairwiseSums xs...
[ { "body": "<p>Your code doesn’t have great complexity. I think it’s <span class=\"math-container\">\\$\\mathcal{O}(2^n)\\$</span>, but I’m rusty so maybe somebody can come in with an assist. The thing to remember is that Haskell lists are linked lists and laziness doesn’t get you out of paying the cost of walki...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-09T19:13:01.860", "Id": "259289", "Score": "2", "Tags": [ "beginner", "haskell" ], "Title": "Pairwise summation in Haskell" }
259289
<p>I wrote my first working website in ReactJs as a beginner and I have a few questions.</p> <p>First question is about <code>meta-tags</code>. I used <code>react-snap</code> for generate <code>meta-tags</code>, because it was the only solution I have found so far, that didnt use server side rendering. But, I have two ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-10T11:16:22.577", "Id": "514315", "Score": "1", "body": "You ask multiple questions in one post. This is genius." } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-09T21:32:06.217", "Id": "259292", "Score": "2", "Tags": [ "javascript", "performance", "beginner", "react.js" ], "Title": "My first website in ReactJS" }
259292
<p>There are systems that when you duplicate an asset, the new assets are created with an index, so that the name do not collide. For instance, if I have an asset called <code>House</code>, and I press &quot;Duplicate&quot;, a new asset will be created called <code>House (1)</code>, and if I press again, it will be cal...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T04:00:48.313", "Id": "511431", "Score": "3", "body": "Hi @EnriqueMorenoTent - `isValid` - is more like isUnused or isUnique or isAvailable ?? Validity and Availability are two separate orthogonal concepts ... (for instance does put...
[ { "body": "<ol>\n<li><p>Potential infinite loop<br />\nIf the <code>isValid</code> method is faulty, i.e always returns false, we'd have an infinite loop on our hands. How do we fix it? I'd fix it in coding in some (configurable but not necessary) upper limit, say 255, so if we tried 255 times, and it still fai...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-09T22:00:07.363", "Id": "259294", "Score": "0", "Tags": [ "c#" ], "Title": "Generating unique names for things like filenames" }
259294
<p>I want to create clickable rows in an html table. Each row should be a link leading to a different page. I can of course add <code>onclick</code> handler, but that will create kind of a crappy UI - poor accessibility, no keyboard navigation, no right/middle click...</p> <p>I found a better way to do it. Instead of u...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-09T23:50:15.527", "Id": "511425", "Score": "2", "body": "it's no longer a table - it's something that looks like a table - see this question over at Stack Overflow https://stackoverflow.com/questions/2617895/actual-table-vs-div-table" ...
[ { "body": "<p>If it's a table, make it a <code>&lt;table&gt;</code>. Write a traditional <code>&lt;tbody&gt;</code> containing <code>&lt;tr&gt;</code>, in turn containing <code>&lt;td&gt;</code>, in turn containing individual <code>&lt;a&gt;</code>. Then the text will be links. This is simpler, doesn't require ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-09T23:46:41.493", "Id": "259295", "Score": "0", "Tags": [ "html", "css", "dom" ], "Title": "Using <a> element instead of <tr> to get clickable rows" }
259295
<p>I am trying to get an array of all regex matches. For example, something like this:</p> <pre><code>PATTERN: (\d+)[a-z]+ STRING: 123asd RESULT: [&quot;123asd&quot;, &quot;123&quot;] ^ ^ full capture group 1 </code></pre> <p>Additionally, if there are multiple matches, it sh...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T07:47:27.553", "Id": "511439", "Score": "1", "body": "For reviewers: [related](https://codereview.stackexchange.com/q/259267/52915)" } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T05:19:20.890", "Id": "259300", "Score": "1", "Tags": [ "c" ], "Title": "Doing a re.findall with pcre library" }
259300
<p>I am solving one binary search problem in <a href="https://leetcode.com/problems/search-in-rotated-sorted-array/" rel="nofollow noreferrer">LeetCode</a>.</p> <p>I have accomplished such code:</p> <pre class="lang-rust prettyprint-override"><code>struct Solution; impl Solution { pub fn search(nums: Vec&lt;i32&gt;...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T09:36:00.443", "Id": "511442", "Score": "1", "body": "FYI: nowadays idiomatic Rust code is commonly called *rusty*." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T12:38:34.800", "Id": "511449", ...
[ { "body": "<p>As always, the interface provided by LeetCode is atrocious. In order to make your code Rusty, I recommend writing your own interface first and then call it within the implementation of LeetCode's interface. Here's why.</p>\n<p>The full interface of the <code>search</code> function, imposed by Le...
{ "AcceptedAnswerId": "259687", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T08:47:12.273", "Id": "259303", "Score": "1", "Tags": [ "algorithm", "rust", "binary-search" ], "Title": "How to make this special binary-search algorithm more rusty?" }
259303
<p>I have a function that takes in a string and based on the string hits different APIs to fetch images.</p> <p>I have solved it by writing an interface and then as the return type of the function, it returns a <code>Promise&lt;Interface&gt;</code> as shown in the code below.</p> <pre class="lang-js prettyprint-overrid...
[]
[ { "body": "<p>The problem here is that the interface <code>IAnimal</code> is not what those apis return. You want to return that interface from your function, but those APIs should have their own interface representing the response data.</p>\n<pre><code>interface DogApiResponse {\n message: string\n status: s...
{ "AcceptedAnswerId": "259305", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T08:57:16.190", "Id": "259304", "Score": "2", "Tags": [ "typescript", "promise", "interface" ], "Title": "Typescript : Adding types to a function that takes in a string and ret...
259304
<p>The following is just a working example.</p> <p>I have a DataFrame containings a monotonous growing function. Some of the values are actuals, some are forecasted.</p> <p>I need to filter specific actuals values based on a set of milestones and I have to avoid to take forecasted values from the dataframe</p> <p>I cre...
[]
[ { "body": "<p>One way to refactor the loop is to locate the desired rows with <a href=\"https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.idxmax.html\" rel=\"nofollow noreferrer\"><strong><code>idxmax()</code></strong></a> and then index them in one shot:</p>\n<pre class=\"lang-py prettyprint-overri...
{ "AcceptedAnswerId": "259429", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T11:41:44.097", "Id": "259306", "Score": "3", "Tags": [ "python", "pandas" ], "Title": "Filtering a DataFrame based on two logical conditions, first one numpy array values, second ...
259306
<p>I made a snake game implementation in console with rust. Would like to hear what I'm doing wrong and what can be improved.</p> <p><strong>main.rs</strong></p> <pre><code>mod apple; mod board; mod game; mod position; mod snake; pub const TAIL_SIGN: char = '#'; pub const HEAD_SIGN: char = 'O'; pub const APPLE_SIGN: c...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T13:53:15.057", "Id": "259307", "Score": "1", "Tags": [ "game", "rust", "snake-game" ], "Title": "Snake game in console" }
259307
<p>I've written a simple Hash Table implementation in C, in order to use it in an IRC bot, so mostly storing nicknames, channel names, etc (small strings). I'm using linear probind to resolve collision.</p> <p>Here is the public API (<code>hash.h</code>):</p> <pre class="lang-c prettyprint-override"><code>#pragma once ...
[]
[ { "body": "<p>Just a few points for now, I will extend my answer over the weekend:</p>\n<ol>\n<li>I think you should think about the max size of your table anyway. I mean you can't have 4 billion nodes in there.</li>\n<li>This is connected to the size. If you only have to resize your table maybe once or twice, ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T15:14:35.873", "Id": "259312", "Score": "2", "Tags": [ "algorithm", "c", "hash-map" ], "Title": "Hash Table implementation in C using linear probing for collisions" }
259312
<p>I'm learning Rust by implementing basic data structures and algorithms. I implemented a binary heap (max heap):</p> <pre class="lang-rust prettyprint-override"><code>mod binary_heap { #[derive(Debug)] pub struct MaxHeap&lt;T&gt; { pub data: Vec&lt;T&gt;, } impl&lt;T&gt; MaxHeap&lt;T&gt; ...
[]
[ { "body": "<p>The overall implementation looks good!</p>\n<p>Here are some of my suggestions:</p>\n<ul>\n<li>The field <code>data</code> can be private.</li>\n<li>A <code>as_vec</code> method can be implemented to return a reference to <code>data</code>.</li>\n<li>A <code>peek</code> method can be implemented t...
{ "AcceptedAnswerId": "261284", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T15:44:34.167", "Id": "259315", "Score": "6", "Tags": [ "rust", "heap" ], "Title": "Binary Heap Implementation in Rust" }
259315
<p>I just started doing preparation for interviews, but im having trouble recognizing the optimal solution</p> <p><strong>Problem:</strong> For a given IP Address, replace every &quot;.&quot; with &quot;[.]&quot;</p> <p><strong>Example:</strong></p> <pre><code>Input: address = &quot;1.1.1.1&quot; Output: &quot;1[.]1[.]...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T16:08:26.803", "Id": "511471", "Score": "2", "body": "Using built-in functions is generally good practice and it's really (!) hard to beat their performance with self-written Python code (since they are implemented in C, not Python)...
[ { "body": "<p>If you are in an interview using Python, assume that the interviewer is\nreasonable and wants you to write fluent Python code. That means, among\nother things, taking advantage of the language's built-in powers:</p>\n<pre><code>def defrang(ip):\n return ip.replace('.', '[.]')\n</code></pre>\n<p...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T16:03:39.223", "Id": "259316", "Score": "2", "Tags": [ "python", "comparative-review" ], "Title": "Which solution of the two is the most efficient? Is there a better one? (IP Address ...
259316
<p>I thought of doing the following to mock/test functions in Go and wanted some advice. Let's say you have an interface for a repository:</p> <pre><code> type Creator interface { CreateUser(User) (*User, error) } type Updater interface { UpdateUser(User) (*User, error) } ty...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T20:10:33.580", "Id": "511492", "Score": "1", "body": "This code is working and I've written it. I just copied the relevant parts for review." } ]
[ { "body": "<p>This seems fine to me: it's nice and simple, and I've seen this pattern used &quot;in the wild&quot; before. One thing you could do is, in the <code>MockUserRepo</code> proxying functions, if the function variable is nil, either execute a default implementation, or return a more specific error (or...
{ "AcceptedAnswerId": "259407", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T16:18:08.297", "Id": "259317", "Score": "2", "Tags": [ "unit-testing", "go" ], "Title": "Mocking Interfaces Golang" }
259317
<p>I have been working with requests where I as easy as it is. Scraping the webpage and add it into a dict and print the payload if we find a new value or not.</p> <pre><code>import json import re import requests from selectolax.parser import HTMLParser payload = { &quot;store&quot;: &quot;Not found&quot;, &q...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T16:54:12.990", "Id": "511476", "Score": "1", "body": "If you do not add the actual link I cannot help you improve your DOM navigation. If the link does not include an authentication token there is no security risk." }, { "Co...
[ { "body": "<ul>\n<li>You have not described the purpose of <code>payload</code>. If this is a JSON payload going to some other web service, <code>Not found</code> is a poor choice for a missing value and <code>None</code> would be more appropriate</li>\n<li>You never use <code>payload['store']</code></li>\n<li>...
{ "AcceptedAnswerId": "259328", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T16:23:43.380", "Id": "259318", "Score": "2", "Tags": [ "python-3.x" ], "Title": "Scrape webelements" }
259318
<p>I'm trying to write a factory class that essentially provides a user-friendly frontend to creating objects of different kinds depending on keywords. So the user will just have to import this module, and then use <code>module.factory.make_new</code> with the relevant keywords.</p> <p>The directory structure will be p...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T19:25:24.207", "Id": "511484", "Score": "0", "body": "(1) What project directory structure does this code expect? (2) The `import_module()` function takes a module name as its first argument, but you are calling it `subtype_name`. W...
[ { "body": "<p>If a factory pattern is indeed called for - much of the time it is not - there is an easier way that needs neither <code>importlib</code> nor explicit registration calls.</p>\n<p>If you follow something like this layout:</p>\n<pre><code>mypackage/\nmypackage/__init__.py\nmypackage/tracker_factory....
{ "AcceptedAnswerId": null, "CommentCount": "12", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T17:04:05.120", "Id": "259320", "Score": "3", "Tags": [ "python", "python-3.x" ], "Title": "Python factory class with dynamic imports" }
259320
<p>This is based on this <a href="https://leetcode.com/problems/unique-paths-ii/" rel="nofollow noreferrer">leetcode question</a>. I get the correct answer, but I know it could be much, much cleaner. I also know there is supposed to be an O(n) space solution, but I'm not sure how to implement cleanly.</p> <p>It is a ...
[]
[ { "body": "<p>Nice solution, few suggestions:</p>\n<ul>\n<li><p><strong>Duplicated code</strong>: the functions <code>len(memo)</code> and <code>len(memo[0])</code> are called several times. When working with a matrix is common to call <code>m</code> the number of rows (<code>len(memo)</code>) and <code>n</code...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T20:12:01.793", "Id": "259326", "Score": "4", "Tags": [ "python", "algorithm", "dynamic-programming" ], "Title": "Unique Paths II, dynamic programming problem, O(n^2) time, O(n^2) ...
259326
<p>The ideas are</p> <ul> <li>When multiple async calls are made, to be able to start consuming from the first resolving one regardless in what order the promises are fired.</li> <li>To construct a modern emitter of async values to be consumed by the <code>for await</code> loop.</li> <li>One may achieve this functional...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T23:35:51.550", "Id": "511517", "Score": "0", "body": "I would remove \"speed' from the title. It's possible that a slow promise started a long time ago actually finishes first" } ]
[ { "body": "<h2>Issues</h2>\n<h3>Lost resolution</h3>\n<p>You are issuing promises without a guarantee of being able to handle all or some of the resolving promises.</p>\n<p>This will happen if promises resolve before you start the <code>for await</code> loop.</p>\n<p>The offending code is in the line <code>this...
{ "AcceptedAnswerId": "259357", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T21:25:05.813", "Id": "259330", "Score": "1", "Tags": [ "javascript", "iterator", "async-await", "promise", "generator" ], "Title": "Racing promises and consuming them ...
259330
<p>I have decided to make snake game as my first project with C++ (using OOP) and I didn't follow any tutorial while doing it, now I am frustrated and need to know if it the code is good or not and what can be improved in it?</p> <p><strong>Map class header file:</strong></p> <pre><code>#pragma once #include &lt;vector...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T22:50:22.320", "Id": "511513", "Score": "0", "body": "_if it the code is good or not and what can be improved in it?_ - yes, great; we can answer that. However: re. _It also have some bugs that I can't fix till now_ - that part is o...
[ { "body": "<p>If this is your first C++ project, then congratulations, it is not a bad attempt at all! However, there are still a lot of areas where your code can be improved. I'll list some of those below. I recommend you try to improve your code based on these suggestions, and the consider creating a new code...
{ "AcceptedAnswerId": "259399", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T22:42:12.880", "Id": "259332", "Score": "3", "Tags": [ "c++", "object-oriented" ], "Title": "Snake game built from scratch" }
259332
<p>This is a follow-up question for <a href="https://codereview.stackexchange.com/q/251909/231235">A get_extents helper function for Boost.MultiArray in C++</a>. In order to retrieve, manipulate and calculate size information in each dimension from <a href="https://www.boost.org/doc/libs/1_75_0/libs/multi_array/doc/use...
[]
[ { "body": "<p>Is that creating a temporary multi-dimensional array just to get the extents? It looks like the test code creates a multi-array of doubles with <code>30 * 30 * 30 * 30 * 2 * 5 * 10</code> elements... if my math is right that's a ~618MB memory allocation to copy 7 numbers. D:</p>\n<p>If we're alrea...
{ "AcceptedAnswerId": "259358", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-10T23:58:45.173", "Id": "259336", "Score": "0", "Tags": [ "c++", "array", "recursion", "boost", "c++20" ], "Title": "extents_to_array and array_to_extents functions for B...
259336
<p>I wrote a barebones version of <code>wc</code> in rust. <code>wc</code> is a program that counts the number of characters, words, and lines in a file and outputs those values to the command line. Here is an example of the output:</p> <pre><code> 9 25 246 Cargo.toml 52 163 1284 src/main.rs 61 188 1530 tota...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T09:55:14.787", "Id": "522175", "Score": "0", "body": "Glad I am not the only one doing this ;-) https://github.com/jonasthewolf/wc" } ]
[ { "body": "<p><code>InputFile</code> doesn't appear to be a file — a better name might be <code>Statistics</code>.</p>\n<p><code>usize</code> is conventionally used for indexes and sizes instead of <code>u32</code>.</p>\n<p><a href=\"https://stackoverflow.com/q/40006219/9716597\">Don't take an argument by <code...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T01:12:21.983", "Id": "259338", "Score": "7", "Tags": [ "beginner", "parsing", "rust" ], "Title": "Count characters, words, and lines in files (wc in rust)" }
259338
<p>I have written a code snippet to use <code>HashMap&lt;String, Vec&lt;&amp;String&gt;&gt;</code> as the main data structure, and finally, I want to return a collected <code>Vec&lt;Vec&lt;String&gt;&gt;</code>, I can archive it by a for-loop, it there any pure iterator way to do this? (I have tried several times, but ...
[]
[ { "body": "<pre><code> unsafe {\n key.as_bytes_mut().sort();\n }\n</code></pre>\n<p>This works as long as you are working in Ascii, but will have undefined behavior if there is any unicode in the string.</p>\n<pre><code> (*map.entry(key).or_insert(vec![])).push(s);\n</code></pre>\n<p>You don't need...
{ "AcceptedAnswerId": "259340", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T03:24:53.620", "Id": "259339", "Score": "0", "Tags": [ "rust", "reference" ], "Title": "How to collect reference values from hashmap?" }
259339
<p>Here is my solution for <a href="https://adventofcode.com/2020/day/4" rel="nofollow noreferrer">Advent of Code 2020, Day 4</a>, Part 1 in C. I tried using fscanf or fgets, but couldn't find a nice of doing it, so I ended up using getc. Is there a way of using fscanf or fgets that makes this code better? Also, how d...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T09:21:31.820", "Id": "511535", "Score": "0", "body": "Please include the specification directly into the question. It must not be necessary to follow the link in order to understand your question." } ]
[ { "body": "<h1>Split your program into multiple functions</h1>\n<p>You can improve the readability and maintainability of your program greatly by splitting it into multiple functions that each do a simple, well-defined task. For example, you can reduce <code>main()</code> to:</p>\n<pre><code>int main()\n{\n ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T04:20:28.300", "Id": "259342", "Score": "1", "Tags": [ "c" ], "Title": "My solution for Advent of Code 2020, Day 4, in C" }
259342
<p>I've written my Huffman archiver in modern c++ (at the moment of writing), could you review it, please?</p> <p>this is the main routine:</p> <pre><code>#ifndef ENCODING_HUFFMAN_ENCODING_H_ #define ENCODING_HUFFMAN_ENCODING_H_ #include &lt;cassert&gt; #include &lt;istream&gt; #include &lt;iterator&gt; #include &lt;m...
[]
[ { "body": "<h1>This should be a function, not a class</h1>\n<p>Your <code>class HuffmanEncoder</code> only has a public constructor, and it does everything. That means the whole <code>class</code> can just be replaced by a single function that does what the constructor did. This also means that there is no reas...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T07:23:51.683", "Id": "259345", "Score": "5", "Tags": [ "c++" ], "Title": "huffman archiver in the moder c++ + good architecture" }
259345
<p>I'm learning about how to create a good and clean code. I just need to review something like that, and I really not sure how can I fix this code into a clean code.</p> <pre><code>bool isValidUserName(const std::string&amp; username) { bool valid = false; if (username.length() &gt;= MIN_NAME_LENGTH) { ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T10:51:49.217", "Id": "511540", "Score": "0", "body": "Is this your own code? Also, what do you mean by \"arrow code\"? I don't see any arrows." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T11:48:14....
[ { "body": "<p>We can avoid the excessive indentation by returning early.</p>\n<p>Instead of checking for validity:</p>\n<pre><code>if (username.length() &gt;= MIN_NAME_LENGTH)\n{\n ... additional nested checks...\n}\n</code></pre>\n<p>we reverse the check and return as soon as possible:</p>\n<pre><code>if (u...
{ "AcceptedAnswerId": "259354", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T10:34:51.870", "Id": "259352", "Score": "8", "Tags": [ "c++" ], "Title": "Checking if a username is valid" }
259352
<p>I am trying to replace in an adapted code from internet, a tread pooling class, named <code>ThreadPool</code>:</p> <pre><code>void ThreadPool::Wait() { // we're done waiting once all threads are waiting while (m_threads_waiting != m_threads.size()) { ; } } </code></pre> <p>where <code>m_threa...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T15:17:27.237", "Id": "511553", "Score": "3", "body": "The replaced code is correct and it is better than the old one." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T15:19:31.500", "Id": "511554",...
[]
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T13:15:11.110", "Id": "259355", "Score": "0", "Tags": [ "c++", "multithreading" ], "Title": "Replace while(true); with std::condition_variable" }
259355
<h2>Use case</h2> <p>This is an event loop and signaling system I created for a piece of software which will have multiple asynchronous server/clients/event-emitters/ui, some of those components will have their own event loop running on a separate thread, some will just post events in the main thread event loop.</p> <p...
[]
[ { "body": "<p><strong>Usage of Condition Variable</strong></p>\n<p>I never write <code>condition_variable</code>'s wait like this:</p>\n<pre><code> while (_queue.empty())\n _messagePresent.wait(lk);\n</code></pre>\n<p>It is much better to write it as:</p>\n<pre><code> _messagePresent.wait(lk, [this]()...
{ "AcceptedAnswerId": "259370", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T15:38:52.190", "Id": "259359", "Score": "3", "Tags": [ "c++", "multithreading", "event-handling", "lambda", "signal-handling" ], "Title": "C++ event loop and thread si...
259359
<p>This code review is for my <a href="https://github.com/plammens/SEMarathonBot" rel="nofollow noreferrer">Stack Exchange Marathon Bot project</a>, a Telegram bot for playing a dumb little game involving the Stack Exchange network. Since the codebase is not that small, in this post I want to focus on only one aspect, ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T04:22:54.830", "Id": "511602", "Score": "0", "body": "Note: I've removed your telegram-bot & python-telegram-bot tags. Not every project deserves its own tag. Perhaps a case can be made for the tag `telegram` (it appears we already ...
[ { "body": "<p>Disclaimer: I'm currently the maintainer of <code>python-telegram-bot</code>.</p>\n<hr />\n<p>Hi.</p>\n<p>TBH I haven't tried to understand every detail of what you presented. I'd still like to comment on the design you chose to use methods of your custom classes as callbacks. More precisely I fin...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T15:41:39.507", "Id": "259360", "Score": "2", "Tags": [ "python", "python-3.x", "object-oriented", "design-patterns", "telegram" ], "Title": "Stack Exchange Marathon Bot – ...
259360
<p><a href="https://github.com/python-telegram-bot/python-telegram-bot" rel="nofollow noreferrer"><code>python-telegram-bot</code></a> is a Python library that provides a Python interface to the <a href="https://core.telegram.org/bots/api" rel="nofollow noreferrer">Telegram bot API</a>, as well as providing additional ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T15:44:21.670", "Id": "259361", "Score": "0", "Tags": null, "Title": null }
259361
<p>A <a href="https://core.telegram.org/bots" rel="nofollow noreferrer">Telegram bot</a> is a third-party program that is accessible through Telegram as a non-human user which can interact with users and chats by sending messages, administrating a group, sending media, etc. Programs that run a Telegram bot interact wit...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T15:50:34.390", "Id": "259363", "Score": "0", "Tags": null, "Title": null }
259363
A Telegram bot is a third-party program that is accessible through Telegram as a non-human user which can interact with users and chats by sending messages, administrating a group, sending media, etc.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T15:50:34.390", "Id": "259364", "Score": "0", "Tags": null, "Title": null }
259364
<p>This shell script, with only a few configurations, has the goal of initializing a project on Gitlab.com without having to go through the go through the website's ui.</p> <p>This means: Let's say you just a project with a few source files, but you haven't done anything with git yet. The goal of this script is to allo...
[]
[ { "body": "<p>Welcome to CodeReview.SE and thanks for submitting your script for a code review!</p>\n<h1>Good points</h1>\n<ul>\n<li>Good output conveying how progress is being made.</li>\n<li>Clear variable names</li>\n</ul>\n<h1>Suggestions</h1>\n<ul>\n<li>Are there limitations for what characters can be in a...
{ "AcceptedAnswerId": "259411", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T15:59:06.810", "Id": "259366", "Score": "2", "Tags": [ "bash", "git" ], "Title": "Initialize a gitlab project both locally and remotely with a single command" }
259366
<p>Where should i put print statements describing the flow of the program? Is there any convetion or code style for this?</p> <p>Should they be in higher level functions?</p> <pre><code>def create_collage(): print('finding images ...') image_paths = get_image_paths() print('loading images ...') images ...
[]
[ { "body": "<p>This is a basic but important question.</p>\n<p>Most functions can be arranged to operate purely in the realm of computation:\nthey take data as input, return data as output, and have no side effects in the\n&quot;real world&quot;. Examples of side effects would include interacting with the file\n...
{ "AcceptedAnswerId": "259371", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T17:47:19.783", "Id": "259368", "Score": "0", "Tags": [ "python" ], "Title": "Code style: Should prints be high or low level?" }
259368
<p>As an exercise to get to know C a bit more, I decided to implement a dynamic array implementation in C99 with generic support.</p> <p>Everything is implemented with series of macros. The array_list struct definition itself is an anonymous struct, which allows client (user) to have very easy access to it. When capaci...
[]
[ { "body": "<h1>Answers to your questions</h1>\n<blockquote>\n<p>I'm currently mostly looking for: 1) Readability,</p>\n</blockquote>\n<p>Macros make things less readable, both for humans and for source code editors. It is a necessary evil if you still want this kind of somewhat type-safe dynamic array in C. Thi...
{ "AcceptedAnswerId": "259397", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T19:59:59.060", "Id": "259374", "Score": "2", "Tags": [ "c", "array", "generics" ], "Title": "Dynamic generic array list implementation in C99" }
259374
<p>The prompt is: that I should write a program for a customer management system for registering customers (in C programming language).</p> <p>The program should allow registration management members to:</p> <ul> <li>Add customer record (id, name, age, gender and city) to the file.</li> <li>Print customer details (ID, ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T22:14:08.147", "Id": "511586", "Score": "0", "body": "Hi @A.R.A I guess the obvious problem is dealing with non-ascii characters - think about all those Arabic, Thai, Japanese, Chinese, Russian and others who wouldn't be able to ent...
[ { "body": "<h2>Domain-specific types</h2>\n<p>Instead of</p>\n<pre><code>char gender[6];\n</code></pre>\n<p>if you're intent on constraining to two genders, you're better off making an <code>enum</code>. However, it's in general a poor choice to do this; instead just accept a free string and don't bother writin...
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T20:15:46.340", "Id": "259376", "Score": "2", "Tags": [ "c", "homework" ], "Title": "Customer management system for registering customers in C" }
259376
<p>I worked on a problem from Automate the Boring Stuff Chapter 7:</p> <blockquote> <p>Write a regular expression that can detect dates in the DD/MM/YYYY format. Assume that the days range from 01 to 31, the months range from 01 to 12, and the years range from 1000 to 2999. Note that if the day or month is a single dig...
[]
[ { "body": "<p>You can import and use <a href=\"https://docs.python.org/3/library/datetime.html\" rel=\"nofollow noreferrer\"><code>datetime</code></a> rather than validating date yourself.</p>\n<pre class=\"lang-py prettyprint-override\"><code>&gt;&gt;&gt; import datetime\n&gt;&gt;&gt; datetime.date(2020, 9, 9)...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T21:56:14.847", "Id": "259377", "Score": "5", "Tags": [ "python", "beginner", "regex" ], "Title": "Date Detection Regex in Python" }
259377
<p>In a current project of I have multiple modules that need to read from and write to a <code>config.json</code> file, where the settings are saved as nested dictionaries. I chose <code>json</code> here, because I want the config file to be human-readable.</p> <p><strong>Simplified example config.json:</strong></p> <p...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T22:52:25.530", "Id": "511588", "Score": "0", "body": "Why are you only allowed to get items from dictionaries? Why are lists on anything else that implements `__getitem__` not allowed?" }, { "ContentLicense": "CC BY-SA 4.0",...
[ { "body": "<ol>\n<li><p>Rather than <code>os</code> and <code>os.path</code> use <a href=\"https://docs.python.org/3/library/pathlib.html#concrete-paths\" rel=\"nofollow noreferrer\"><code>pathlib.Path</code></a>.</p>\n<pre class=\"lang-py prettyprint-override\"><code>def _save_config_data(content):\n CONFIG...
{ "AcceptedAnswerId": "259403", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T22:35:40.100", "Id": "259380", "Score": "2", "Tags": [ "python", "python-3.x" ], "Title": "Singleton handler for reading and writing configuration.json" }
259380
<p>I don't program much in c, but cobbled together some code from different places in google. I'm sure this is backwards especially in how it works with strings and directory files. Please let me know what the best practices would have been.</p> <pre><code>/* usbresetall -- reset all of the usb devices on bus 001 */ #...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T06:05:57.920", "Id": "511607", "Score": "0", "body": "Welcome to CodeReview. Does your code work as expected?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T16:07:26.120", "Id": "511656", "Sc...
[ { "body": "<h1>Use consistent indentation</h1>\n<p>I don't know if the <a href=\"https://en.wikipedia.org/wiki/Indentation_style\" rel=\"nofollow noreferrer\">indentation style</a> of the code you pasted here is as you wrote it, but if it looks the same in your code editor, you should definitely try to fix it a...
{ "AcceptedAnswerId": "259394", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-11T23:17:23.277", "Id": "259383", "Score": "2", "Tags": [ "beginner", "c", "strings", "file-system" ], "Title": "C code to reset all usb devices (because ubuntu laptop disabl...
259383
<p>For my current job, I've been told that soon I'm going to be porting our Python code to Cython, with the intent of performance upgrades. In preparation of that, I've been learning as much about Cython as I can. I've decided that tackling the Fibonacci sequence would be a good start. I've implemented a Cython + Itera...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T03:31:44.800", "Id": "511601", "Score": "5", "body": "Yes you can; there is a \\$O(\\log n)\\$ algorithm, but it has nothing to do with Cython." } ]
[ { "body": "<p>Using one less variable seems faster:</p>\n<pre class=\"lang-py prettyprint-override\"><code>cdef int fib_c(int n):\n if n == 0:\n return 0\n cdef int a = 0\n cdef int b = 1\n for _ in range(n - 1):\n a, b = b, a + b\n return b\n</code></pre>\n<p>Running your test on m...
{ "AcceptedAnswerId": "259390", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T01:35:05.957", "Id": "259384", "Score": "2", "Tags": [ "python", "performance", "python-3.x", "fibonacci-sequence", "cython" ], "Title": "Cython Fibonacci Sequence" }
259384
<p>I have a Vec with value default [0], and then I want to append into the vec with an iterator which is read from stdin, now my code is not performant since I use an insert to shift all the values behind index 0, how to improve this code with rusty style?</p> <pre class="lang-rust prettyprint-override"><code>#[allow(u...
[]
[ { "body": "<p>I have got an answer with <code>chain</code></p>\n<pre class=\"lang-rust prettyprint-override\"><code>fn main() {\n let mut scan = Scanner::default();\n let n: usize = scan.next();\n let mut arr = vec![0];\n let mut arr: Vec&lt;i32&gt; = arr.into_iter().chain((0..n).map(|i| scan.next()...
{ "AcceptedAnswerId": "259404", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T06:20:29.950", "Id": "259391", "Score": "1", "Tags": [ "rust", "stream" ], "Title": "How to append values into existed Vec with iterator" }
259391
<p>I have been working on where I want to improve my knowledge to do a safe JSON scraping. By that is that I could pretty much do a ugly workaround and wrap it into a try-except but that is not the case. I would like to know where it goes wrong and how I can improve the code I have been working with:</p> <pre><code>imp...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T14:59:48.917", "Id": "511650", "Score": "0", "body": "_I would like to know where it goes wrong_ - does it complete without error?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T15:28:01.260", "I...
[ { "body": "<ol>\n<li><p>You need functions.<br />\nFunctions help to split up your code and make understanding how everything fits together easier.</p>\n<p>You should have a function for:</p>\n<ol>\n<li><p>Getting the page.</p>\n</li>\n<li><p>Parsing the JSON with your helpful error message.</p>\n</li>\n<li><p>...
{ "AcceptedAnswerId": "259418", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T08:09:48.633", "Id": "259393", "Score": "1", "Tags": [ "python-3.x", "json" ], "Title": "Get data from JSON values" }
259393
<p>I have a 4 list of posts. I am trying to load more posts (clones of the &quot;original&quot; ones) when I reach the bottom of the container.</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprin...
[]
[ { "body": "<h2>Too complex</h2>\n<p>Always strive to keep source code complexity as low as possible.</p>\n<p>The implementation of <code>InfiniteScroll</code> is way too complex.</p>\n<p>It should not be an instantiatable object as it only works if there is one instance, and will only work once.</p>\n<ul>\n<li>...
{ "AcceptedAnswerId": "259425", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T08:41:22.037", "Id": "259395", "Score": "2", "Tags": [ "javascript", "observer-pattern" ], "Title": "Pure JavaScript infinite scroll" }
259395
<p>I wrote this simple shell in C for a university assignment on operating systems (My guess is that it's just the beginning and the next assignments will add to this code).</p> <p>The program prints the prompt to the user, receives an input and try to execute it. The program ends when the input is 'done', and prints s...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T15:11:59.280", "Id": "511653", "Score": "0", "body": "The `SENTENCE_LEN` constant doesn't seem to be defined anywhere in the code. Are you perhaps missing a header file?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationD...
[ { "body": "<h1>Answers to your questions</h1>\n<blockquote>\n<p>Should the main be broken into more functions?</p>\n</blockquote>\n<p>Yes. Keep it as high level as possible. Basically, it should look like:</p>\n<pre><code>int main() {\n char sentence[...];\n\n while (fgets(sentence, sizeof sentence, stdin) ...
{ "AcceptedAnswerId": "259479", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T09:00:45.460", "Id": "259396", "Score": "5", "Tags": [ "beginner", "c", "homework", "shell" ], "Title": "Parsing and Simple Shell in C" }
259396
<p>What I am wanting to do, is record the status of a HTTP call, so that I can give the user some feedback in the UI, rather than either succeeding silently, or showing a grim error.</p> <p>What I have done is created a <code>Result</code> class. For ease, I will show the simple class, but I also have this as a generic...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T11:34:22.250", "Id": "511630", "Score": "0", "body": "Since the \"success/fail\" nature of the result can be defined based on the HTTP status code alone, why separately record the two? By default, HTTP 2xx is a success and HTTP 4xx ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T09:22:45.993", "Id": "259398", "Score": "1", "Tags": [ "c#", "asp.net-core" ], "Title": "Record status of http call to show in the UI" }
259398
<p>I got this data structure and I am checking to see which properties are true, then I am adding the <code>key</code> for all the properties that are true to that object on a new property called <code>combined</code></p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> ...
[]
[ { "body": "<p>I have improved it with this:</p>\n<p><div class=\"snippet\" data-lang=\"js\" data-hide=\"false\" data-console=\"true\" data-babel=\"false\">\r\n<div class=\"snippet-code\">\r\n<pre class=\"snippet-code-js lang-js prettyprint-override\"><code>const data = [\n {\n keyword: 'banana',\n yellow...
{ "AcceptedAnswerId": "259412", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T11:56:09.430", "Id": "259405", "Score": "2", "Tags": [ "javascript", "object-oriented", "array", "ecmascript-6" ], "Title": "Combine data from array of objects" }
259405
<p>The objective was to write a locale-independent function that prints floating-point numbers (i.e. one that always uses <code>.</code> as a decimal point regardless of the locale) that was going to be used in <a href="https://gitlab.com/kirbykevinson/jamtext/-/blob/master/src/util/print-number.c" rel="nofollow norefe...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-19T07:16:39.430", "Id": "512315", "Score": "1", "body": "If it's acceptable to support only single-threaded applications, consider avoiding all the complexity by temporarily changing `LC_NUMERIC` to C locale (use `setlocale(LC_NUMERIC,...
[ { "body": "<p><strong>Implementation simplicity</strong></p>\n<p>As code is incorrect in too many cases, simplicity assessment is moot.</p>\n<p><strong>Ability to be used on different sorts of streams (writing into a file, a string, etc)</strong></p>\n<p>Code assumes it can pass a <code>void *</code> like a <co...
{ "AcceptedAnswerId": "259679", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T12:28:34.473", "Id": "259408", "Score": "4", "Tags": [ "c", "reinventing-the-wheel", "floating-point" ], "Title": "Locale-independent float print function" }
259408
<pre><code>template&lt;typename T&gt; class object_pool { public: explicit object_pool(std::size_t initial_size = 1048u); object_pool(const object_pool&amp;) = delete; object_pool(object_pool&amp;&amp;) = delete; ~object_pool(); object_pool&amp; operator=(const object_pool&amp;) = delete; object_pool&a...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T16:27:07.667", "Id": "511659", "Score": "1", "body": "If you have unit tests for this code it would help us review the code if they were posted as well." } ]
[ { "body": "<p><strong>unique_ptr ownership / lifetime issues</strong>:</p>\n<p>Normally, <code>std::unique_ptr</code> indicates single ownership of an object and thus gives the user certain expectations of how they can safely use it. But here the <code>object_pool</code> &quot;owns&quot; the object (or at least...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T15:13:33.260", "Id": "259414", "Score": "2", "Tags": [ "c++", "memory-management" ], "Title": "C++ object pool that returns a smart pointer on request" }
259414
<p>I implemented the Dijkstra algorithm from scrath and wonder if I can save some code? The whole algorithm is <a href="https://gist.github.com/eduOS/1a4655504366cbaf3644d8dc9dcc8d26" rel="nofollow noreferrer">here</a>.</p> <p>n is the number of nodes, and m the number of edges. 1 ≤ ≤ 10^4, 0 ≤ ≤ 10^5, ̸= , 1 ≤ , ≤...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T16:09:15.773", "Id": "259415", "Score": "2", "Tags": [ "python", "algorithm", "graph", "pathfinding", "dijkstra" ], "Title": "Dijkstra from scratch" }
259415
<p>Here is the problem,</p> <blockquote> <p>Given a 2D numpy array 'a' of sizes n×m and a 1D numpy array 'b' of size m. You need to find the distance(Euclidean) of the 'b' vector from the rows of the 'a' matrix. Fill the results in the numpy array. Follow up: Could you solve it without loops?</p> </blockquote> <pre><...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-13T18:24:02.510", "Id": "511803", "Score": "0", "body": "Use a combination of [array broadcasting](https://numpy.org/doc/stable/user/theory.broadcasting.html?highlight=broadcast#array-broadcasting-in-numpy) and [universal functions](ht...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T16:40:39.607", "Id": "259417", "Score": "0", "Tags": [ "python", "numpy", "matrix", "vectors" ], "Title": "Finding the Euclidean distance between the vectors of matrix a, and ...
259417
<p>I know this is a bit elementary, but I am highly uncomfortable writing Scheme code, and I want to make sure that what I'm doing is good practice. I know mutation is frowned upon in Scheme.</p> <p>I have no other source of review so I have come to you all.</p> <pre class="lang-lisp prettyprint-override"><code>(defin...
[]
[ { "body": "<p>When you catch yourself using nested <code>if</code>s, that's usually a sign you'd be better served by the cond form. (which is actually way more powerful than nested <code>if</code> due to a few quirks)</p>\n<p>Here's how I'd clean that up</p>\n<pre><code>(define (filter-lst fn lst)\n (cond ((nu...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T17:36:56.500", "Id": "259419", "Score": "1", "Tags": [ "functional-programming", "reinventing-the-wheel", "scheme" ], "Title": "\"filter\" function in Scheme" }
259419
<p>Hi I have a requirement where in I have to call two different client methods from same api in .NET Core and I have structured my code as follows. THis is working fine but Please give me your valuable inputs or suggestions for improvements.</p> <p>I am using HTTPClientFactory to create my clients as shown below:</p...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T17:42:34.830", "Id": "511663", "Score": "0", "body": "Could you fix the typos in the code first?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T17:55:44.183", "Id": "511664", "Score": "1", ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T17:36:59.563", "Id": "259420", "Score": "3", "Tags": [ "c#", "asp.net-web-api", ".net-core" ], "Title": "Calling multiple clients from API controller methods?" }
259420
<p>I'm creating a Discord Bot and i made a !love command which is testing the love rate between 2 persons or entities.</p> <p>Example : !love Peignoir Emma</p> <p>Result: The loverate between Peignoir and Emma is x%</p> <p>Here's the code :</p> <pre><code>@bot.command(name=&quot;love&quot;, aliases=[&quot;l&quot;]) asy...
[]
[ { "body": "<pre><code>for y in range(len(wordBanList)):\n if(Personne1 == wordBanList[y] or Personne2 == wordBanList[y]):\n printIt = 0\n</code></pre>\n<p>This code is checking to see if Personne1 or Personne2 are in wordBanList and has O(len(wordBanList)) runtime time. You can change ...
{ "AcceptedAnswerId": "259427", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T17:57:30.943", "Id": "259422", "Score": "7", "Tags": [ "python" ], "Title": "Discord.py Bot : Sends with the loverate between 2 persons" }
259422
<pre><code>import java.util.Scanner; class Main { public static void main(String[] args) { int tries = 0; boolean iterated = false; String temp = &quot;&quot;; String holder = &quot;&quot;; System.out.println(&quot;Welcome to the guessing game! Guess one letter at a time. Y...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T21:03:20.760", "Id": "511690", "Score": "0", "body": "Welcome To Code Review, I formatted your java code and added the `hangman` tag to your post." } ]
[ { "body": "<p>I reworked your code a little. Here are the results from one test run.</p>\n<pre><code>Welcome to the guessing game! Guess one letter at a time. You have 5 incorrect guesses remaining.\nThe Secret Word Is: ------ (6)\nYour Guess: a\nThe word does not contain the letter a.\nYou have 4 incorrect g...
{ "AcceptedAnswerId": "259576", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T19:07:55.103", "Id": "259426", "Score": "2", "Tags": [ "java", "hangman" ], "Title": "string guessing game in java" }
259426
<p>I'm recently started learning Node.js and I'm trying to write a simple Todo app using Mongoose. Since I'm also try to learn Typescript I wanted to combine my basic knowledge on both topics and I encountered a problem with defining interfaces for data models.</p> <p>I have a simple Todo model:</p> <pre class="lang-js...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T19:45:10.583", "Id": "259428", "Score": "0", "Tags": [ "typescript", "mongoose" ], "Title": "Mongoose virtual field declaration in Typescript interfaces" }
259428
<p>I have a project which we need to migrate from an on-prem solution to the AWS cloud. Currently, the software is running on a single instance. It's working fine but the business want the software to be Highly Available (HA). As part of the HA, the program will be installed on a shared file system (AWS EFS) and mount ...
[]
[ { "body": "<p>Consider your system in three parts:</p>\n<ul>\n<li>Core OS (all files on ec2)</li>\n<li>Your App (I would keep the core app files on ec2 - reasons below - but your way would work)</li>\n<li>Data (I would have only &quot;data&quot; on EFS)</li>\n</ul>\n<p><strong>Answer Part 1:</strong> php.ini li...
{ "AcceptedAnswerId": "259748", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T20:15:35.463", "Id": "259430", "Score": "2", "Tags": [ "php", "mysql", "amazon-web-services" ], "Title": "PHP filesystem on a shared file system" }
259430
<p>I know there are if, then, else and switch.</p> <p>But the code below is a mixture of if, then else, else if, else.</p> <pre><code>@HostListener('document:keydown', ['$event']) onKeydown(event: KeyboardEvent) { let index = 0; if (this.selectedItemIndex === null || this.selectedItemIndex &lt; 0) { this.change...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-13T03:13:26.753", "Id": "511715", "Score": "0", "body": "To make code more readable, a good 1st step is to assign names to your conditions. For example: `this.selectedItemIndex === null || this.selectedItemIndex < 0` might become `hasN...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T20:50:52.433", "Id": "259431", "Score": "2", "Tags": [ "javascript", "typescript" ], "Title": "How to reduce the Cognitive Complexity of this code based on Thomas J. McCabe’s Cyclomat...
259431
<p>I am creating a program that will be given a text file as output with the board's dimension and the piece id along with the piece width and length. The goal is to arrange all blocks in the board correctly. Currently, my program takes forever to come up with a solution. I need help optimizing or figuring out what I n...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-13T03:15:31.443", "Id": "511716", "Score": "5", "body": "Welcome to CR! I note the comment in your code `#TODO: Bug in this function. Positions are not correct after solution is found.`. Does your code actually work? This site is for w...
[]
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T21:08:25.727", "Id": "259432", "Score": "3", "Tags": [ "python", "algorithm", "sorting", "breadth-first-search" ], "Title": "Breadth First Search Block Puzzle" }
259432
<p>I just implemented a generic concurrent queue in C, and I'd like some feedback on my implementation, as well as the logic in handling generic data and concurrency.</p> <p>buffer.h</p> <pre><code>#ifndef BOUNDED_BUFFER_H #define BOUNDED_BUFFER_H #include &lt;stdlib.h&gt; typedef struct _boundedBuffer BoundedBuffer;...
[]
[ { "body": "<h1>Don't start names with an underscore</h1>\n<p>The C language reserves some <a href=\"https://en.cppreference.com/w/c/language/identifier\" rel=\"nofollow noreferrer\">identifiers</a> starting with one or two underscores. While your code may work, it is best to avoid it. It's also more common to w...
{ "AcceptedAnswerId": "259932", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T21:14:32.360", "Id": "259433", "Score": "3", "Tags": [ "c", "concurrency", "queue" ], "Title": "Generic concurrent bounded buffer in C" }
259433
<p>I wrote an implementation of a shared pointer. I would like a review of it.</p> <p>It seems to work, but running it through Valgrind shows that that it leaks memory somewhere in my tests, but I don't know where.</p> <p>Here is my .h file:</p> <pre><code>#include &lt;stdexcept&gt; //Try to create a smart pointer? Sh...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T22:00:04.293", "Id": "511699", "Score": "0", "body": "HI @Ragov - surely if you have a refCount you use that for exists (don't need the ptrToPtr then). AND the dCast gives a un-counted pointer so is risky - you want to keep people ...
[ { "body": "<h1>Data members</h1>\n<p>I don't see the point of the <code>T** ptrToPtr</code> member variable. Every instance of <code>*ptrToPtr</code> can be replaced by <code>ptr</code>. Remove that member and you have one less thing to <code>delete</code>.</p>\n<p><strike>Why is <code>refCount</code> a pointer...
{ "AcceptedAnswerId": "259450", "CommentCount": "8", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-12T21:25:00.507", "Id": "259434", "Score": "0", "Tags": [ "c++", "beginner", "c++14", "pointers" ], "Title": "C++ Simple Shared Pointer Implementaion" }
259434