body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>The goal is to transpose the excel file that comes in the following form</p> <p><a href="https://i.stack.imgur.com/Svd49.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Svd49.png" alt="enter image description here" /></a></p> <p>into this</p> <p><a href="https://i.stack.imgur.com/PlbRB.png" rel="n...
[]
[ { "body": "<h2>TL;DR</h2>\n<p>Instead of looping through each pizzeria and merging temporary subframes, it's more idiomatic to manipulate/map the columns at once.</p>\n<p>The bulk of the work is just changing the original columns (left) to be filled/dropped/sorted/renamed (right):</p>\n<pre class=\"lang-none pr...
{ "AcceptedAnswerId": "270190", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-17T18:44:21.350", "Id": "270174", "Score": "3", "Tags": [ "python", "excel", "pandas" ], "Title": "Transposing an Excel sheet with pandas adding additional information for a diff...
270174
<p>I have (for example) the following license plate image: <a href="https://i.stack.imgur.com/ibnL8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ibnL8.png" alt="enter image description here" /></a></p> <p>And I want to segment the characters. The code I have so far consists of me using <code>cv2.M...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-19T21:30:44.077", "Id": "533549", "Score": "1", "body": "I'm not sure I understand the logic of using the height as a key... Are you saying that all letters and numbers to be extracted are exactly the same height in pixels? That cannot...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-17T20:26:33.657", "Id": "270175", "Score": "3", "Tags": [ "python", "opencv" ], "Title": "Segment characters from license plate image according to regions with same height" }
270175
<p>I have this calculator. The user is asked to provide three numbers as well as the numeric operation they wish to perform. Based on this input, a certain case will be executed. The calculator is supposed to cover the basic arithmetic options such as + - * / as well as that &quot;dividing or multiplying numbers are st...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-18T00:50:00.257", "Id": "533384", "Score": "0", "body": "*dividing or multiplying numbers are stronger actions than adding or subtracting numbers* \"precedence\" is word you want. It means \"priority of action\" As in: \"multiplica...
[ { "body": "<p>Welcome to the site! The best way to learn is to experiment and have fun!</p>\n<p>The key to simplifying code is to find patterns. This will be easier to find if we sort all the <code>if</code> statements by operation like the following:</p>\n<pre><code>if (rechenoperator1 == &quot;+&quot; &amp;&a...
{ "AcceptedAnswerId": "270181", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-17T20:44:41.090", "Id": "270177", "Score": "1", "Tags": [ "c#", "calculator" ], "Title": "How can I implement this calculator in a better way?" }
270177
<p>My assignment was to write a function that computes the value of an expression written in infix notation. We assume that we are using the four classical arithmetic operations +, -, * and / and that each binary operation is enclosed in parentheses.</p> <p>My stack:</p> <pre><code>class Stack: def __init__(self): ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-17T22:24:20.600", "Id": "533377", "Score": "3", "body": "Are you [KermitTheFrog](https://codereview.stackexchange.com/users/241883/kermitthefrog)? Because your `Stack` is almost exactly the same as in [Kermit's question](https://codere...
[ { "body": "<ul>\n<li><p>Python <code>list</code>s are stacks. I'd recommend removing the <code>Stack</code> class.</p>\n</li>\n<li><p>You should split tokenization away from evaluation.\nWhilst the tokenization you need is quite simple, tokenization can get quite complicated.\nNot only will you shoot yourself i...
{ "AcceptedAnswerId": "270184", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-17T21:50:17.993", "Id": "270180", "Score": "1", "Tags": [ "python", "python-3.x", "homework", "math-expression-eval" ], "Title": "Evaluating infix expression with brackets" }
270180
<p>I'm a Python novice. The system I'm using is called IBM <a href="http://ibm.com/docs/en/mam/7.6.1.2" rel="nofollow noreferrer">Maximo Asset Management</a>. In Maximo, we can write Python scripts that utilize Maximo's Java API/methods. So the script is technically a <a href="https://www.jython.org/" rel="nofollow nor...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-17T22:43:14.220", "Id": "270182", "Score": "1", "Tags": [ "python", "python-2.x", "status-monitoring", "jython" ], "Title": "Script to check a web service" }
270182
<p>this is my first ansible playbook.</p> <p>it installs docker in swarm mode and automatically joins the cluster.</p> <p>could you guys please review my code and show me where it can be improved?</p> <pre><code>- hosts: all tasks: - name: Add apt key apt_key: url: https://download.docker.com/linux/...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-30T02:48:32.430", "Id": "534260", "Score": "0", "body": "A couple queries: 1. What version of ansible are you using? 2. Why are you not using the docker_swarm module?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": ...
[ { "body": "<p>I have done some Ansible tasks 5 years ago, so I looked at your code just out of interest, and I didn't read any documentation. Here are some things I noted by just looking at the code:</p>\n<p>The task <code>apt_key</code> looks strange to me. The basic idea of a GPG key is that it provides a tru...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-17T23:49:09.983", "Id": "270183", "Score": "3", "Tags": [ "beginner", "installer", "yaml", "docker", "ansible" ], "Title": "Ansible playbook to install Docker Swarm" }
270183
<p>This code is Cholesky decomposition in numerical linear algebra.</p> <pre><code>function LLT = Cholesky(A) if is_pos_def(A) == 1 disp('Cholesky Decomposition is used only for positive definite matrixes') else n = rank(A); L = zeros(rank(A)); L(1,1) = sqrt(A(1,1)); for...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-18T09:01:35.880", "Id": "533400", "Score": "2", "body": "Welcome to Code Review! I changed the title so that it describes what the code does per [site goals](/questions/how-to-ask): \"*State what your code does in your title, not your ...
[ { "body": "<p>First I'll point out some general code improvements, then we'll get into vectorization.</p>\n<p>There is a bug in your code, in case the first condition is true:</p>\n<pre class=\"lang-matlab prettyprint-override\"><code>function LLT = Cholesky(A)\n if is_pos_def(A) == 1\n disp('Cholesky...
{ "AcceptedAnswerId": "270234", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-18T08:25:10.217", "Id": "270188", "Score": "2", "Tags": [ "mathematics", "matlab" ], "Title": "Cholesky decomposition" }
270188
<p>This code converts a 3-letter English month abbreviation to its numeric equivalent (as a string).</p> <pre class="lang-java prettyprint-override"><code>public static String numericMonth(String monthInFull) { monthInFull = monthInFull.toUpperCase(); if (monthInFull.equals(&quot;JAN&quot;)) { return &quot;01&quot;...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-18T22:06:00.927", "Id": "533463", "Score": "0", "body": "Using a `switch` statement would remove much of the repetition in your code. Whether or not using an `enum` here is beneficial or appropriate would require more context for how/...
[ { "body": "<p>Some improvement ideas:</p>\n<ol>\n<li>You could consider using <code>java.time</code> api, however to use <code>DateTimeFormatter</code> you'd have to use builder, quite heavily configure it (as it would require defaults for year and day, not to mention its case sensitive) and <code>Month</code> ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-18T15:01:43.110", "Id": "270196", "Score": "0", "Tags": [ "java" ], "Title": "Convert month name to numeric string" }
270196
<p>After having a good experience with virtualenvwrapper built on top of the venv, I thought maybe it could be benefitial to have similar shortcuts for standard activities with git which could be time saving as opposite to typing many commands.</p> <p>I've given it a try like the following:</p> <p>Start session (sync c...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-18T17:35:43.410", "Id": "533437", "Score": "0", "body": "Regarding the main vs. master branch, you could (A) see which branch exists in the repo but you might have to choose one if both are there or (B) use a config file in the repo to...
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-18T15:02:54.760", "Id": "270197", "Score": "2", "Tags": [ "bash", "git", "macros" ], "Title": "Fast git change sets with git wrapping scripts" }
270197
<p>This is original Code</p> <pre><code>if($(&quot;#dcl#dynamicID#&quot;).length &gt; 0){ var dcl = document.getElementById(&quot;dcl#dynamicID#&quot;); if(dcl.addEventListener){ dcl.addEventListener(&quot;click&quot;,function(e){ showDelete(this); (e.preventDefault) ? e.preventD...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-18T19:07:23.573", "Id": "533450", "Score": "0", "body": "Welcome to Code Review! It would benefit reviewers to have a bit more information about the code in the description. From [the help center page _How to ask_](https://codereview.s...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-18T17:45:30.380", "Id": "270198", "Score": "0", "Tags": [ "javascript", "jquery" ], "Title": "jquery function updated from javascript" }
270198
<p>Hello I'm relatively new to VBA and I have this macro to VLookup information into corresponding cells in the sheet that works, the issue is that it depends on a For Loop to iterate through 10s of thousands of rows. This is taking a significant amount of time to iterate and I know I'm asking a good amount of it but I...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-18T20:59:47.687", "Id": "533454", "Score": "0", "body": "Wouldn't it be faster to have the formulas built in to the sheet? I don't see anything here that requires the use of VBA. You should use tables that automatically fill in formula...
[ { "body": "<p><strong>Code Style</strong></p>\n<p>Avoid multiple variable declarations in a single line, like <code>Dim MARCLastRow As Long, FTLastRow As Long, x As Long</code>.</p>\n<p>It is generally not recommended to include the variable type in the variable name (e.g. <code>ws</code> in <code>MARCws</code>...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-18T20:29:13.743", "Id": "270202", "Score": "4", "Tags": [ "performance", "vba", "excel" ], "Title": "VLOOKUP Macro to reformat data between sheets preserving the connection to the so...
270202
<p>I have put together <a href="https://github.com/lancejpollard/normalize-ast.js/blob/make/index.js" rel="nofollow noreferrer">this complete runnable source code</a> with an example set of <a href="https://github.com/lancejpollard/normalize-ast.js/blob/make/test.js" rel="nofollow noreferrer">test expressions</a> which...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-19T14:04:52.457", "Id": "533516", "Score": "0", "body": "How is [this branch](https://github.com/lancejpollard/normalize-ast.js/blob/de18f76499a60aabfffab563bb9dd99e7986ae21/index.js) in terms of refactoring (and making more robust)?" ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-19T01:34:59.800", "Id": "270208", "Score": "3", "Tags": [ "javascript", "algorithm" ], "Title": "How to remove a lot of the duplication in this JavaScript AST transformer?" }
270208
<p>Consider the following piece of code I wrote (a templated Linked List):</p> <pre class="lang-java prettyprint-override"><code>package com.data_structures; public class LinkedList&lt;NodeDataType&gt; { public LinkedList() { super(); } class LinkedListNode&lt;DataType&gt; { private DataT...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-19T06:00:18.160", "Id": "533471", "Score": "0", "body": "With the language you are most comfortable with, do you know the way to avoid the _separate logic_?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-1...
[ { "body": "<h1>Template Type Parameter</h1>\n<p>You've used <code>NodeDataType</code> for your <code>LinkedList</code> template type parameter, and <code>DataType</code> for your <code>LinkedListNode</code> template type parameter. Why are these different?</p>\n<p>Considering your code is littered with <code>L...
{ "AcceptedAnswerId": "270239", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-19T04:49:34.930", "Id": "270210", "Score": "2", "Tags": [ "java", "performance", "linked-list" ], "Title": "Finding better logic for addition and removal of Nodes in a Linked Lis...
270210
<h1>Front Matter</h1> <p>I'm learning Scala and have not gotten used to functional programming and the language. I'm hoping a review of my naively implemented code can help me bridge my object-oriented ways to something more functional and Scala-prescribed.</p> <p>I've uploaded all of my code here: <a href="https://gi...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-19T07:08:25.673", "Id": "533477", "Score": "2", "body": "The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to **simply sta...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-19T06:47:31.883", "Id": "270213", "Score": "0", "Tags": [ "beginner", "functional-programming", "scala", "data-mining", "etl" ], "Title": "Relational join of two datasets" }
270213
<p>I'm testing to use a fluent builder pattern for generating a pdf file using AbcPDF. I've looked at several methods of accomplishing this and I'd be very glad to get some input on what I've written so far to see if I'm going in the right direction or if there's some criticism.</p> <p>The idea is that I have a builder...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-19T07:54:14.133", "Id": "533482", "Score": "1", "body": "Welcome to Code Review! Could you please share with the following class definitions as well: `DocumentInformation`, `CustomerInformation`, `ProjectInformation` and `Doc`?" }, ...
[ { "body": "<p>Maybe I misunderstand your intent but I can see lots of boilerplate code.</p>\n<h3>Builder vs Fluent</h3>\n<p>There is a common misunderstanding that these concepts are the same. Let's see what wikipedia says about them</p>\n<blockquote>\n<p>The builder pattern is a design pattern designed to prov...
{ "AcceptedAnswerId": "270219", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-19T07:32:25.500", "Id": "270215", "Score": "2", "Tags": [ "c#", "design-patterns", "pdf" ], "Title": "Using fluent builder pattern for generating pdf" }
270215
<p>I have to write a program in python that will take a number and print a right triangle attempting to use all numbers from 1 to that number. For example:</p> <pre><code>Enter number: 10 Output: 7 8 9 10 4 5 6 2 3 1 Enter number: 6 Output: 4 5 6 2 3 1 Enter number: 20 Output: 11 12 13 14 15 7 8 9 10 4 5 6 2 3 1 </co...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-19T11:43:43.367", "Id": "533499", "Score": "2", "body": "One liner with a bit of maths to find x(x+1)/2 = n: lambda x: [print(\\*range(1+i*~-i//2, 1+i*-~i//2)) for i in range(int(((1+8*x)**.5-1)/2), 0, -1)]" }, { "ContentLicens...
[ { "body": "<h3>Optimized != pythonic</h3>\n<p>Optimized means &quot;spending less resources&quot;. &quot;Pythonic&quot; means &quot;using idiomatic Python features&quot;. Sometimes they come together, sometimes don't. Pythonic code is clean and maintainable, while optimized can be very unclear and need many com...
{ "AcceptedAnswerId": "270221", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-19T11:13:24.437", "Id": "270218", "Score": "1", "Tags": [ "python", "python-3.x" ], "Title": "Printing reverse number triangle" }
270218
<p>JSFiddle: <a href="https://jsfiddle.net/EddTally/jsa69f7r/3/#&amp;togetherjs=zMFpAQcRTt" rel="nofollow noreferrer">https://jsfiddle.net/EddTally/jsa69f7r/3/#&amp;togetherjs=zMFpAQcRTt</a></p> <p>Those who cannot access JSFiddle:</p> <pre><code>/** * Utilizes recursion to search through an item of any type (currentl...
[]
[ { "body": "<p>I think you are overcomplicating things. You do not need separate logic for <code>objects</code> and <code>arrays</code>. The following should do the job:</p>\n<pre><code>function filterItem(item, value) {\n if (typeof item == 'object' || Array.isArray(item)) {\n for (let i in item) {\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-19T11:54:35.603", "Id": "270220", "Score": "2", "Tags": [ "javascript" ], "Title": "Recursive Filter/Search function" }
270220
<p>I have a class <code>Scholar</code> which is basically a teacher in a university. I have to calculate the yearly salary of a scholar instance where the formula is <code>12-month salary + bonus</code><br/> the bonus is determined by the academic_position <br/> if the teacher is:</p> <ul> <li>a Professor --&gt; bonus ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-20T17:28:04.707", "Id": "533583", "Score": "0", "body": "It's likely that it doesn't even make sense to set such an instance variable in the constructor. But we can't really advise you properly based on the tiny code excerpt you've sho...
[ { "body": "<p>If you have to stick to using this specific structure, I'd do it like this:</p>\n<pre class=\"lang-py prettyprint-override\"><code>class Scholar:\n _ACADEMIC_POSITIONS_BONUS_MAP = {\n 'Professor': 70000,\n 'Associate Professor': 50000,\n 'Assistance Professor': 30000,\n ...
{ "AcceptedAnswerId": "270224", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-19T12:41:45.070", "Id": "270222", "Score": "2", "Tags": [ "python", "object-oriented", "constructor" ], "Title": "Setting instance variable for salary bonus based on academic pos...
270222
<p>I decided to implement a solver for linear systems of equations based on the gaussian elimination and reduction to upper triangular form. The gaussian elimination is quite simple to implement but the function to go from a &quot;gauss-eliminated&quot; matrix (upper triangular form) to a solution is excessively compli...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-19T14:21:44.770", "Id": "270226", "Score": "0", "Tags": [ "python", "performance", "reinventing-the-wheel", "numpy", "linear-algebra" ], "Title": "Solving a linear system wit...
270226
<p>Environnement :</p> <ul> <li>Rails 6.1.4.1</li> <li>db : PostgreSQL</li> </ul> <p>Hi everyone, I've been working on this for some hours now and want to know how other Rails developpers would react to this type of project structure.</p> <p>Goal of the code structure :</p> <ol> <li>Permit API high versionability by : ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-20T03:23:11.113", "Id": "533557", "Score": "0", "body": "I think this would evolve in a big mess if the app anything but trivial and all the meta programming is extremely hard to understand. I don't see much benefit of this design." ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-19T14:49:22.883", "Id": "270228", "Score": "0", "Tags": [ "ruby-on-rails", "api", "rest" ], "Title": "Highly versionable API" }
270228
<p>I've implemented a thread pool using C++20. I'm fairly new to concurrently/multi-threaded programming and wanted to work on a project that I could learn from while also getting to know some of the new features available in C++20.</p> <p>To that end I've specifically made use of:</p> <ul> <li><code>std::binary_semaph...
[]
[ { "body": "<h1>Unnecessary abstractions</h1>\n<p>Why is there a <code>class thread_pool_impl</code>, and then a single type alias to that class:</p>\n<pre><code>using thread_pool = thread_pool_impl&lt;dp::thread_safe_queue&gt;;\n</code></pre>\n<p>This indirection doesn't do anything useful as far as I can see, ...
{ "AcceptedAnswerId": "270242", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-19T22:21:52.283", "Id": "270236", "Score": "5", "Tags": [ "c++", "multithreading", "thread-safety", "concurrency", "c++20" ], "Title": "C++20 Thread Pool" }
270236
<h3>Intro</h3> <p>This is a spiritual successor to the question <a href="https://codereview.stackexchange.com/questions/262728/stop-cheating-on-home-exams-using-python">Stop cheating on home exams using python</a></p> <p>The details are not important, but I decided to reimplement everything using dataclasses. My script...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-21T00:41:36.083", "Id": "533600", "Score": "0", "body": "`The user may have written a badly formated value for number of candidates` <- I did read your previous question, but just to clarify, your students will not be users of the scri...
[ { "body": "<p>Your <code>uni.py</code> is your &quot;main file&quot;; fine. As such, it should have a <code>#!/usr/bin/env python3</code> shebang. The nicer option is to make a proper module directory tree containing a <code>__main__.py</code> such that running <code>python -m uni</code> runs your module's main...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-20T15:18:19.640", "Id": "270244", "Score": "2", "Tags": [ "python", "python-3.x", "configuration" ], "Title": "Stop exam cheating using python: Part 2 - Argparse and config" }
270244
<p>This is my code to extract data from the DOL website for a project I'm doing for my portfolio. The code does extract all of the data that I need, however it runs really slowly. I think it took like 15 minutes for it to finish extracting everything. I would really appreciate if someone could just point me in the righ...
[]
[ { "body": "<p>To keep the review short, if you can get the data from an API instead of scraping, that's always going to be the faster option.</p>\n<p>Luckily, in this case there is such an API. Open the site with Chrome developer tools and request data for an arbitrary state. You will see that the website calls...
{ "AcceptedAnswerId": "270264", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-20T15:49:54.413", "Id": "270245", "Score": "1", "Tags": [ "python", "performance", "selenium" ], "Title": "Web Scraping DOL with Selenium" }
270245
<p>Although I have long experience of other languages, I've not used C until playing around with microcontrollers using the Arduino IDE. I'm a bit uncomfortable with my use of pointers in conjunction with C strings.</p> <p>Since this is a microcontroller project, I want to avoid the String class and try to write code t...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-21T16:34:27.230", "Id": "533621", "Score": "1", "body": "Re *\"write code that will be reasonably efficient\"*: Why do you assume that? Using C strings can become very very slow [if not used correctly](https://www.joelonsoftware.com/20...
[ { "body": "<p>Well, there are some concerning points about your code:</p>\n<ol>\n<li><p>You are not using <code>const</code> where appropriate. It is there to help you avoid obvious bugs, like overwriting constants. Crank up the warning-level, and the compiler warns about assigning string-constants to mutable p...
{ "AcceptedAnswerId": "270252", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-20T18:38:24.140", "Id": "270248", "Score": "3", "Tags": [ "c", "strings", "formatting", "pointers" ], "Title": "Simple string manipulation in C (for small microcontrollers)" ...
270248
JScript is a scripting language based on the ECMAScript standard, created by Microsoft and implemented in a range of environments. You would expect this tag to accompany questions regarding these environments, such as Windows Script Host (WSH), Active Server Pages (ASP) and HTML Applications (HTA).
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-20T18:39:37.170", "Id": "270250", "Score": "0", "Tags": null, "Title": null }
270250
<p>I wrote the code below as a Kata to practice the <a href="https://clean-code-developer.com/grades/grade-1-red/#Integration_Operation_Segregation_Principle_IOSP" rel="nofollow noreferrer">Integration Operation Segregation Principle (IOSP, <code>clean-code-developers.com</code>)</a>. I would like to have some feedback...
[]
[ { "body": "<h2>Mixed concerns</h2>\n<p>Rather than just letting the client create instances of the <code>SortedListMerger</code> class, there's a private constructor and a singleton map construction mechanic.</p>\n<p>If you really need to be able to construct the merger, based around the runtime class informati...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-20T20:43:46.183", "Id": "270256", "Score": "3", "Tags": [ "java", "programming-challenge", "mergesort" ], "Title": "IOSP Kata: merge two sorted arrays without iterators" }
270256
<p>While playing with a <a href="https://codereview.stackexchange.com/questions/252659/fast-native-memory-manipulation-in-vba">VBA project</a> involving Windows APIs, I have noticed some odd behavior: API calls under Excel 2016/VBA7/x64 appeared to be much slower than under Excel 2002/VBA6/x32. Since I wanted to follo...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-21T15:25:49.760", "Id": "533615", "Score": "2", "body": "This is clearly good detailed research, but I think you would do better if you could make an even simpler minrepro and post it over on stack overflow. Something like _\"Here is a...
[]
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-20T23:12:11.070", "Id": "270258", "Score": "2", "Tags": [ "performance", "vba", "excel", "winapi" ], "Title": "Evaluate performance of DLL calls from VBA" }
270258
<p>I just joined here. I have been doing python for a couple of weeks and I would like for some experienced programmers to review my code. I made this for a school project and I am proud of it. The code below works well but I would like to know what things I can improve on. Thank you for taking the time to review this....
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-21T09:56:47.680", "Id": "533607", "Score": "2", "body": "This is really good for someone just starting out! Keep it up!" } ]
[ { "body": "<p>As a beginner, you have done fantastic!</p>\n<p>There is always something to improve, in your code, mainly, performance.</p>\n<ul>\n<li><code>print()</code></li>\n</ul>\n<p>Instead of priniting again and again, create a string of output, and print it in a single call. It is way faster than printin...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-21T06:21:04.937", "Id": "270261", "Score": "3", "Tags": [ "python", "beginner", "game", "tic-tac-toe" ], "Title": "Python TIC TAC TOE Project" }
270261
<p>I have implemented generic doubly linked list in C language in which you can store any data type you want. Just like in C++ and Java, where a list can store any data type, like - string, int, long, structure, etc., you can do the same using this program.</p> <p>Can someone please review the code.</p> <p>The code is ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-21T11:49:11.277", "Id": "533608", "Score": "1", "body": "I see you can add and delete nodes, but what about finding nodes, accessing the front or back of the list, and iterating over nodes?" }, { "ContentLicense": "CC BY-SA 4.0...
[ { "body": "<p><code>get_error_string()</code> needs to return <code>const char*</code>, since it returns pointers to string literals.</p>\n<p>It should probably be implemented using <code>switch</code>. My preference is not to have a <code>default</code> case when dealing with enumerations (which the errors sh...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-21T06:46:51.743", "Id": "270262", "Score": "1", "Tags": [ "c", "linked-list", "generics" ], "Title": "Generic doubly linked list in C" }
270262
<p>I have a simple project that I built that protects the routes/pages of the website by using the if and else statement and putting each page with a function <code>withAuth()</code>, but I'm not sure if that is the best way to protect routes with nextjs, and I noticed that there is a delay in protecting the route or p...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-25T09:20:25.017", "Id": "533908", "Score": "1", "body": "Hello, welcome to CR! This code looks like a stub, which is great for StackOverflow, but not great for CodeReview. There really isn't enough to work with (what you have looks goo...
[ { "body": "<p>Obviously <code>AuthContext</code> from <code>@context/auth</code> is a blackbox to me here, so I'm unable to know if there's a server side auth capability. However, if you're able to retrieve the session server side, then with Next.js, you can use <a href=\"https://nextjs.org/docs/basic-features/...
{ "AcceptedAnswerId": "270389", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-21T08:57:18.897", "Id": "270263", "Score": "1", "Tags": [ "javascript", "security", "react.js" ], "Title": "Protect Routes/Page with NextJS" }
270263
<p>I'm currently learning C/C++ and I saw this question on Reddit on how to create a linked from an array and decided that would make a good exercise for learning the absolute basics of C, so without looking at the answers I wrote this.</p> <p>Anyways, preamble aside, here's the code:</p> <pre class="lang-c prettyprint...
[]
[ { "body": "<h1>Use the correct types</h1>\n<p>Use <code>size_t</code> instead of <code>int32_t</code> for the array size and index. Using <code>int32_t</code> will limit it to arrays containing 2,147,483,647 elements even if you compiled it for 64-bit mode.</p>\n<p>Also, note that it does not make sense to chec...
{ "AcceptedAnswerId": "270276", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-21T12:50:52.657", "Id": "270268", "Score": "1", "Tags": [ "c", "array", "linked-list" ], "Title": "Create a linked list from an array, and also free that list" }
270268
<p>Could you please have a look at our naive bayes model. We look at a corpus of emails where an email is either spam or not. To classifiy we naively assume a bag of words and estimate prior probabilities through maximum likelihood. The model defintion can be found <a href="https://en.wikipedia.org/wiki/Naive_Bayes_cla...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-21T14:22:35.590", "Id": "270270", "Score": "2", "Tags": [ "python", "python-3.x" ], "Title": "Naive Bayes spam classifier improvements" }
270270
<p><strong>Edit</strong>: A new and improved version can be found in <a href="https://codereview.stackexchange.com/questions/270439/custom-implementation-to-provide-an-immutable-range-of-a-container-without-copyi">this question</a>, based on the feedback!</p> <hr /> <p>I needed to pass a const reference to part of a <c...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T05:24:11.183", "Id": "533662", "Score": "1", "body": "Some C++ programmers will find the void arguments offensive." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T06:12:54.230", "Id": "533663", ...
[ { "body": "<h1>You are implementing <code>std::span</code></h1>\n<p>What you are trying to implement is basically C++20's <a href=\"https://en.cppreference.com/w/cpp/container/span\" rel=\"nofollow noreferrer\"><code>std::span</code></a>. It might be worthwhile to look at how it is implemented, and copy its int...
{ "AcceptedAnswerId": "270272", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-21T14:49:05.223", "Id": "270271", "Score": "4", "Tags": [ "c++11", "iterator", "vectors" ], "Title": "Custom implementation to provide an immutable range of a vector without copy...
270271
<p>Given 2 values and an array, I must return the minimal distance between the indices of both values, as efficiently as I can in terms of run time and space.</p> <p>This is my solution:</p> <pre><code> public static int minDist (int[] a, int x, int y) { int index_one = a[0]; int index_two = a[0]; for(int i = ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-21T18:54:58.353", "Id": "533637", "Score": "4", "body": "The code finds _some_ distance between `x` and `y`. It is not necessarily minimal." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T07:47:38.760", ...
[ { "body": "<p>This code does not do what you want it to do, there is no check for the <em>minimum</em> distance. I'm not going to review code that does not exist. However, I will review the rest of the code.</p>\n<h2>Naming conventions</h2>\n<ul>\n<li>Variable names should be descriptive. <code>int[] a</code> d...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-21T17:14:09.923", "Id": "270273", "Score": "0", "Tags": [ "java", "performance", "array" ], "Title": "Find the minimal distance between two values in an array" }
270273
<p>There are many template engines but my question is: Why do they still exist? Can we not achieve the same job with readily available JavaScript Template Literals?</p> <p>So influenced from <a href="https://2ality.com/2015/01/template-strings-html.html" rel="nofollow noreferrer">this blogpost</a>, I have come up with ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-21T20:07:45.857", "Id": "533643", "Score": "0", "body": "What does this do? The table looks nothing like `data`?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-21T20:59:00.320", "Id": "533645", "Sc...
[ { "body": "<p>A short review;</p>\n<p><em>Do you think this is reasonable in daily JavaScript?</em></p>\n<p>Probably not, for a few reasons</p>\n<ul>\n<li><p>You need a function per record type since this wires metadata and styling so tightly</p>\n</li>\n<li><p>There is a ton of HTML tooling out there, none of ...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-21T18:04:09.457", "Id": "270275", "Score": "2", "Tags": [ "javascript", "template" ], "Title": "Using JS Template Literals as for a simple Templating Engine" }
270275
<pre><code>/// #include &lt;stdio.h&gt; void ConvertNumberToBinary(int Number, int *Array) { for(int I = 0; I &lt; 32; ++I) { int ZeroOrOne = Number%2; if(ZeroOrOne &lt; 0) { ZeroOrOne = 1; } *(Array + I) = ZeroOrOne; Number = (Number &...
[]
[ { "body": "<h1>Formatting conventions</h1>\n<p>It is your program and you are free to format it any way you want to, but sticking to conventions makes it easier for others to read.</p>\n<p>I personally prefer my function definitions and <code>for</code> loops on one line unless they are very long. Most people u...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-21T20:49:48.430", "Id": "270278", "Score": "0", "Tags": [ "c++", "bitwise", "binary" ], "Title": "Converting whole numbers to binary in C/C++" }
270278
<h3>The feature</h3> <p>Here is a Grid class representing a 2d grid.<br /> The class will get templated once it reach a satisfactory state.<br /> At this time the cells are <code>int</code> values.</p> <p>This Grid class allow for iteration by rows using simple range-for syntax.</p> <pre><code> Grid grid(8, 8); ...
[]
[ { "body": "<blockquote>\n<pre><code>RowIterator operator++(int)\n{\n auto self = *this;\n ++* this;\n return *this;\n}\n</code></pre>\n</blockquote>\n<p>We should be returning the previous value (<code>self</code>), rather than <code>*this</code>.</p>\n<hr />\n<p><code>Grid</code> owns storage using a ...
{ "AcceptedAnswerId": "270284", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T00:46:01.483", "Id": "270281", "Score": "2", "Tags": [ "c++", "array", "iterator", "c++20" ], "Title": "2d Grid - Iterating by Rows / Cells" }
270281
<p>At the moment, it is simply massive. I already reduced the size by about a hundred lines but it still seems way too big... Would appreciate some help :)</p> <pre><code>using System; class Program { static int turns = 1; static int player = 2; static char[] board = { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T13:08:31.330", "Id": "533683", "Score": "2", "body": "There is a bug in `Introduction` method, the condition `input1 != \"y\" || input1 != \"n\"` is always true the game never start" }, { "ContentLicense": "CC BY-SA 4.0", ...
[ { "body": "<p>There are a couple of issues that we need to address before we can start looking at ways to simplify the code.</p>\n<p>As already mentioned in the comments, you should modify the following line in <code>Introduction</code> to prevent an infinite loop:</p>\n<pre><code>while (input1 != &quot;y&quot;...
{ "AcceptedAnswerId": null, "CommentCount": "13", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T09:25:20.770", "Id": "270285", "Score": "2", "Tags": [ "c#", "tic-tac-toe" ], "Title": "How can I shorten my tic tac toe game?" }
270285
<p>I need to handle different states of a complex GUI control (such as NORMAL, DRAGGING, MARKING, ...). I came upon this idea:</p> <pre><code>void dispatch(auto const i, auto&amp;&amp; ...f) noexcept(noexcept((f(), ...))) { std::underlying_type&lt;std::remove_const_t&lt;decltype(i)&gt;&gt; j{}; ((j++ == i ? (f()...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T08:59:41.810", "Id": "533771", "Score": "0", "body": "Here's a [better](https://github.com/user1095108/generic/blob/master/dispatch.hpp) implementation." } ]
[ { "body": "<p>I don't get it.<br />\n<code>j</code> is the same type as the underlying type of <code>i</code> but without the <code>const</code>, and you could have made that clearer by using an explicit template parameter so you could leave the <code>const</code> out of the deduced type.<br />\nBut the only th...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T13:42:35.953", "Id": "270289", "Score": "0", "Tags": [ "c++", "gui" ], "Title": "handling different states of a complex gui control" }
270289
<p>This is a simple Python 3 program that verifies whether a string is a valid IPv6 address or not, parses IPv6 address to its hexadecimal and decimal values, and converts an integer to IPv6 format.</p> <p>I am writing a webscraper, and to reduce network IO bound time complexity I need to programmatically lookup DNS re...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T16:45:45.850", "Id": "533717", "Score": "1", "body": "Have you considered using [ipaddress](https://docs.python.org/3/library/ipaddress.html)? In particular, the [conversion integer and string](https://docs.python.org/3/library/ipad...
[ { "body": "<blockquote>\n<p>I have written this simple regex</p>\n</blockquote>\n<p>Ish. You haven't written it in a very simple way. Write it on multiple lines, add comments.</p>\n<p><code>65536 ** i</code> seems like a less obvious way of accomplishing 1 bit-shifted left by 16*i.</p>\n<p>This:</p>\n<pre><code...
{ "AcceptedAnswerId": "270346", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T14:12:57.793", "Id": "270290", "Score": "1", "Tags": [ "performance", "python-3.x", "programming-challenge", "reinventing-the-wheel", "converting" ], "Title": "Python ...
270290
<p>This macro calculates some basic figures from a given set of data. But it runs very slow probably due to me referencing the sheet again and again. Does anyone have a better idea on how to optimize this code:</p> <pre><code>Sub Handler_Fees() Dim strFile, tarFile As String Dim Source As Workbook Dim Target As This...
[]
[ { "body": "<p>A little observation:</p>\n<p>When many variables are declared in one line it must be specified the type of each one. There are two lines in your code that doesn't accomplish this.</p>\n<pre><code>Dim strFile, tarFile As String\nDim ThisCell, ThatCell, WhichCell As Range\n</code></pre>\n<p>The cor...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T14:14:28.657", "Id": "270291", "Score": "0", "Tags": [ "vba", "excel" ], "Title": "Macro which performs a series of operations on a given set of data" }
270291
<p>I'm using TypeScript for my Vue app and have a custom type I'm working with</p> <pre><code>type MyCustomType = { fooProperty: string, barProperty: string /* ... other fields ... */ }; </code></pre> <p>This type holds a bunch of properties acting as a &quot;composite key&quot;. So the combination of all p...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T15:02:20.843", "Id": "533704", "Score": "0", "body": "Why not add primary keys on database table and do an INSERT IGNORE?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T15:04:55.267", "Id": "5337...
[]
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T14:45:05.857", "Id": "270293", "Score": "2", "Tags": [ "javascript", "typescript" ], "Title": "Create a collection of truly unique objects of custom type" }
270293
<p>I made a custom Binance API wrapper (<code>BinanceRestClient</code>) which uses <code>IHttpClientFactory</code> in order to prevent socket exhaustion, while also ensuring that DNS changes are respected.</p> <p>I looked at the implementation of a deprecated API wrapper (<a href="https://github.com/glitch100/BinanceDo...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T10:31:10.043", "Id": "533775", "Score": "0", "body": "Why is `BinanceApiProcessor` implemented as disposable? I don't see any cleanup. Same applies for `BinanceRestClient`." }, { "ContentLicense": "CC BY-SA 4.0", "Creati...
[ { "body": "<p><code>BinanceApiProcessor</code> and <code>BinanceRestClient</code> are the same, and they've got me confused as I thought they were separate classes, but then I got that feeling that one of them might act as base class of the other. Then, after reading both multiple times, I saw that <code>Binanc...
{ "AcceptedAnswerId": "270327", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T14:46:11.107", "Id": "270295", "Score": "0", "Tags": [ "c#", ".net", "asp.net-core" ], "Title": "Custom Binance API wrapper around IHttpClientFactory" }
270295
<p>Added the problem link below and my implementation of it. Took me a few hours to program. I have added comments to explain my thought process. <a href="https://cs50.harvard.edu/x/2021/psets/6/dna/" rel="nofollow noreferrer">Problem Link</a> Goal - To implement a program that identifies to whom a sequence of DNA belo...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T17:09:21.613", "Id": "533720", "Score": "2", "body": "While the question is excellent (perfect match for the site)! We ask that every question is _self contained_, what happens if your link dies? Please include the problemstatement ...
[ { "body": "<p>Your code seems to work properly on the whole test suite provided which is a very good start.</p>\n<p>Also, splitting the logic in 2 parts, one preprocessing the counts and the other performing the comparison is a great way to proceeed.</p>\n<p>However, there are still various way to improve the c...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T16:56:22.707", "Id": "270298", "Score": "1", "Tags": [ "python", "beginner", "algorithm", "programming-challenge" ], "Title": "DNA Challenge from CS50" }
270298
<p>Alright, this is one of my first real projects in python, it's basically a one-way chat where the server sends away an encoded message. The logic of it is pretty simple and I know there is some unnecessary code in there. I have also made a simple client who receives the messages and decrypts it, based on if the user...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T18:14:39.627", "Id": "533729", "Score": "1", "body": "I would encourage you to edit your question to explain how the code is intended to be used. I ran it and a window pops up with two text boxes. What should I do? I typed something...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T18:01:22.633", "Id": "270302", "Score": "0", "Tags": [ "python", "tkinter", "socket", "encoding" ], "Title": "One-way chat which encode messages, this is the server side" }
270302
<p>The code below takes a list of users and displays two lists</p> <ol> <li>Refused users</li> <li>Admitted users</li> </ol> <p>Sample output:</p> <blockquote> <p>Refuse: Phil, Lola.</p> <p>Admit: Chris, Anne, Colin, Terri, Sam, Kay, Bruce.</p> </blockquote> <p>Any feedback is highly appreciated.</p> <pre><code>const p...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T18:32:32.957", "Id": "533732", "Score": "4", "body": "Please state the specification for the code. What does it do? The title should state the purpose of the code/application." } ]
[ { "body": "<p>Avoid performing side-effects in the middle of a ternary expression. If you're not using the resulting value of the ternary operation, then you're using it wrong and should be using an ordinary if-then instead.</p>\n<p>Also, be consistent with your usage of semicolons, and let/const.</p>\n<p><div ...
{ "AcceptedAnswerId": "270313", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T18:08:46.863", "Id": "270303", "Score": "0", "Tags": [ "javascript", "functional-programming", "ecmascript-6" ], "Title": "Processing list of users- filtering out from refused...
270303
<p>I've implemented a menu system where all input calls ultimately go through <code>io_getline</code>, a function which reads a line of input up to the max buffer size or newline (the rest of the line is discarded if it exceeds the buffer size) and returns the number of characters written, or -1 if an EOF is encountere...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T19:01:36.870", "Id": "533733", "Score": "0", "body": "The project this is from is [mpassw](https://gitlab.com/bradenbest/mpassw/). A Metroid password generator I've been writing for the past couple weeks. It works on both Linux and ...
[ { "body": "<p><strong>Redundant code</strong></p>\n<p><code>getchar_eof()</code> essentially mimics <code>getchar()</code> and <code>feof()</code>. It fails to work well when <code>ferror()</code> is true or <code>stdin</code> is re-opened.</p>\n<p><code>getchar()</code> already returns <code>EOF</code> when <...
{ "AcceptedAnswerId": null, "CommentCount": "11", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T18:35:46.817", "Id": "270304", "Score": "0", "Tags": [ "c", "console", "portability" ], "Title": "Line-wise input, EOF handling, and behavioral differences between implementation...
270304
<p>As a smaller part of a programming challenge, I am writing a function in Python that takes two parameters, a given number and a size constraint. The function yields a generator that produces the integer partitions of the given number up to the size constraint. I have a working solution that is derived from the rule_...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T07:02:47.500", "Id": "533757", "Score": "1", "body": "Welcome to Code Review@SE. *How-to* questions rarely are a good [fit for this site](https://codereview.stackexchange.com/help/on-topic). In your question, please clearly state wh...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T19:52:52.950", "Id": "270305", "Score": "-1", "Tags": [ "python", "combinatorics", "generator" ], "Title": "Size Constrained Integer Partitions of a Given Number" }
270305
<p>I've been practising my coding skills because I have an interview coming up. The HackerRank challenge has 16 test cases; the code passes 9 of them and the other 7 time out.</p> <p>If you go to <a href="https://www.hackerrank.com/domains/data-structures" rel="nofollow noreferrer">HackerRank Problems Data Structures</...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T20:57:04.653", "Id": "533736", "Score": "0", "body": "@Emily_L. I would definitely appreciate any comments or answers you care to contribute, I'm not sure I'm using the correct algorithm for performance." }, { "ContentLicens...
[ { "body": "<p>Yes, brute-force is a sub-optimal solution.</p>\n<p>A better way:</p>\n<ol>\n<li><p>Decompose each query <code>a b k</code> into two parts:</p>\n<ul>\n<li>At index a, add k</li>\n<li>At index b + 1, add -k</li>\n</ul>\n</li>\n<li><p>Store those sub-queries in one vector.</p>\n</li>\n<li><p>Sort th...
{ "AcceptedAnswerId": "270332", "CommentCount": "7", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T20:51:16.313", "Id": "270307", "Score": "1", "Tags": [ "c++", "performance", "programming-challenge", "time-limit-exceeded" ], "Title": "HackerRank \"Array Manipulation\" ...
270307
<h2>Code:</h2> <pre><code># read file of first agrument import sys, os try: data = open(sys.argv[1]).read() except: data = open(&quot;File.txt&quot;).read() sys.argv.append(&quot;File.txt&quot;) dct = {&quot;@&quot;: data, &quot;E&quot;: &quot;0&quot;} iteration = 0 RESET = False define = False printf = False replac...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T18:30:37.853", "Id": "533817", "Score": "1", "body": "Do you have a name for your programming language, and a sample program in that language?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T18:41:16....
[]
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T22:52:32.877", "Id": "270310", "Score": "-3", "Tags": [ "python-3.x", "interpreter" ], "Title": "Making programming language" }
270310
<p>I've been trying to implement a simple Boost PMR allocator that has a fixed amount of memory. My first implementation (which can be found <a href="https://github.com/irods/irods/blob/master/lib/core/include/fixed_buffer_resource.hpp" rel="nofollow noreferrer">here</a>) had undefined behavior and did not handle memor...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T14:52:45.297", "Id": "533787", "Score": "0", "body": "You're using Boost.PMR instead of std::pmr, with C++17?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T15:03:07.620", "Id": "533789", "Sc...
[ { "body": "<blockquote>\n<pre><code> static_assert(std::is_same_v&lt;ByteRep, char&gt; ||\n std::is_same_v&lt;ByteRep, unsigned char&gt; ||\n std::is_same_v&lt;ByteRep, std::uint8_t&gt; ||\n std::is_same_v&lt;ByteRep, std::byte&gt;);\n</code></pre>\n</blockq...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T23:00:05.220", "Id": "270311", "Score": "2", "Tags": [ "c++", "memory-management", "c++17", "memory-optimization", "boost" ], "Title": "Fixed-size memory allocator" }
270311
<p>I created a method to return a copy of <code>List&lt;T&gt;</code>, basically I convert the <code>List&lt;T&gt;</code> into an array <code>T[]</code>, then perform the copy with the <code>arrayCopy(T[])</code> method and back convert again in <code>List&lt;T&gt;</code>.</p> <p>I want to know if the code will be run s...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T11:22:51.120", "Id": "533777", "Score": "2", "body": "You're not creating a copy of a List. You're creating a new list with the same elements as the original list. The difference is important as \"a copy\" would imply that the resul...
[ { "body": "<p>Given that <code>arrayCopy</code> has exactly one line, it's not clear that there's much value in having it extracted as a method.</p>\n<p><code>toArray()</code> is <a href=\"https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#toArray()\" rel=\"noreferrer\">documented<...
{ "AcceptedAnswerId": "270314", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-22T23:37:11.030", "Id": "270312", "Score": "4", "Tags": [ "java", "array", "generics", "casting" ], "Title": "Method for create a copy of List<T>" }
270312
<p>I am working with Raspberry Pi and I made this little Python script that plays sound while you hold down a button and it keeps repeating while you hold it. and no matter when you stopped holding button, the next time you press it it should start from beginning.</p> <p>This code works, but I fear it is slowly leaking...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T17:00:13.977", "Id": "533807", "Score": "2", "body": "What is not clear to me is why you continuously do `del mp3` to then re-instantiate it after. It's defined on the top of the script and that should suffice. Not saying this is th...
[ { "body": "<p>I suppose you are using <a href=\"https://github.com/20tab/mpg123-python\" rel=\"nofollow noreferrer\">this wrapper</a>, which appears to be somewhat minimalistic. To &quot;rewind&quot; the sound file it should suffice to re-instantiate the class like this before starting the loop again:</p>\n<pre...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T08:04:58.647", "Id": "270318", "Score": "0", "Tags": [ "python", "memory-optimization", "raspberry-pi" ], "Title": "Possible memory leak in Python script which plays sound while h...
270318
<p>I have a collection which, after the code has ran, looks something like the following:</p> <pre><code>[ { title: 'alpha', lines: [ { *some object* } ] }, { title: 'bravo', lines: [ { *some object* } ] }, { title: 'charl', lines: [ { *some object* } ] }, { title: 'delta', lines: [ { *some object*, *some objec...
[]
[ { "body": "<p>In general I think something feels off with your data structure and the naming of your parameters / variables is extremely difficult to understand (e.g. what is an <code>a_or_b</code>?).</p>\n<p>Anyway, you could structure your code a bit more object oriented and extract helper methods. I don't kn...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T10:14:43.033", "Id": "270322", "Score": "1", "Tags": [ "ruby" ], "Title": "Code for appending to a certain index of an array" }
270322
<p>I need to write a function to count numbers of nests in an iterable. I reached my goal but wondering if there's any more neat/faster solution (maybe even a library or so?). Besides I'm afraid that my code is error prone.</p> <p>Let's analyze two examples:</p> <pre class="lang-py prettyprint-override"><code>dct_test ...
[]
[ { "body": "<p>I think we could make use of recursivity, as well as dunder (double underscore) attribute.\nFor example</p>\n<pre><code>def is_iterable(a):\n if &quot;__iter__&quot; in a.__dir__():\n print(&quot;I am an iterable ! You can do `for x in a`&quot;)\n else:\n print(&quot;I am not a...
{ "AcceptedAnswerId": "270335", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T10:39:17.077", "Id": "270323", "Score": "6", "Tags": [ "python", "beginner" ], "Title": "Counting 'absolute' nesting levels of an iterable" }
270323
<p>I have the following function that returns StaffQualifications where either the qualification is expiring or the qualification type is expiring, but this section doesn't seem to sit well with me as it splits up the SQL string... Should this be two separate functions perhaps even though 95% of the query is the same?...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T11:57:01.300", "Id": "533780", "Score": "1", "body": "We need to know *what the code is intended to achieve*. To help reviewers give you better answers, please add sufficient context to your question, including a title that summaris...
[ { "body": "<p>I think the best thing to do would be to extract the logic outside of the string building and pass it in. You could do this either inline as per below or with <code>sprintf</code> or Heredoc.</p>\n<pre><code>/**\n * @param ?Qualification $qualification\n * @param ?QualificationType $qualification...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T11:40:14.537", "Id": "270325", "Score": "-1", "Tags": [ "doctrine", "php7", "symfony4" ], "Title": "Find qualifications that are expiring" }
270325
<p><strong>Let's suppose I have 2 <code>repositories</code>:</strong></p> <ul> <li>first is responsible for creating job and return <code>jobId</code></li> <li>second is responsible for creating log and take <code>jobId</code> as argument</li> </ul> <p><strong>My goal is to:</strong></p> <ul> <li>save <code>Job</code> ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T15:55:06.620", "Id": "533800", "Score": "2", "body": "Unfortunately none of them is correct. If one of the `save` command fails then the other is not rolled back. So both changes should be tackled under the same DbContext to be abl...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T14:49:07.513", "Id": "270329", "Score": "0", "Tags": [ "c#", ".net", "asp.net-mvc" ], "Title": "Best approach to combine repositories logic" }
270329
<p>I wrote this script partly as an exercise in learning Bash and partly because I needed a tool to find specific versions of library files and copy them to a particular device.</p> <p>The script takes parameters that control its operation. First, it searches for the file specified by the user. Then it displays the sea...
[]
[ { "body": "<p>Thanks for submitting this for a code review. I like the indentation and documentation in your code.</p>\n<p>The biggest problem I see with this is dealing with filenames that haves spaces in them. Your <code>select</code> line will almost certainly break. The <code>find</code> command will let ...
{ "AcceptedAnswerId": "270343", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T16:05:50.780", "Id": "270331", "Score": "5", "Tags": [ "beginner", "bash" ], "Title": "Librarian script to find and copy a file" }
270331
<p>I'm using (non-boost) Asio 1.18.1 and C++17. Forgive the boost tag, there wasn't a more specific one.</p> <p>I have a <code>async_connect_with_retry</code> composed asynchronous operation:</p> <pre class="lang-cpp prettyprint-override"><code>/// Calls resolver.async_resolve(...), async_connect(socket, ...), and (on ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T17:08:19.513", "Id": "270333", "Score": "2", "Tags": [ "c++", "asynchronous", "c++17", "socket", "boost" ], "Title": "A reuseable reconnecting TCP socket with Asio" }
270333
<p>I'm trying to implement sum of 2 array using multi threading.</p> <p>I expected that when I use more threads it will be faster than when I use one thread, but that isn't the case.</p> <pre><code>public static int[] a = new int[100]; public static int[] b = new int[100]; public static int[] c = new in...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T20:47:40.417", "Id": "533835", "Score": "0", "body": "perhaps you're not aware of `Task` and `async` tasks on `NET 4+` as they're the better version of using `Thread` on the old versions of `NET`." }, { "ContentLicense": "...
[ { "body": "<h1>Joining threads</h1>\n<p>After starting a thread, you have to call <code>join</code> to make sure it is done with its work. I see you have commented <code>join</code> out and I can guess why. The correct way to do this is to first start <b>all</b> the threads and then join them like so:</p>\n<pr...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T20:16:16.213", "Id": "270338", "Score": "2", "Tags": [ "c#", "performance", "multithreading" ], "Title": "Sum of 2 arrays using multi threading" }
270338
<p>I want to edit Windows <strong>hosts</strong> file in the best way for the end user, using a batch-only solution. I ended up with this script, which works fine, but since I don't have enough knowledge, the syntax is very poor. So please, may you take a look and tell me how to improve it, especially the <code>=999</c...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-24T00:34:43.893", "Id": "533839", "Score": "0", "body": "Oof. Why batch? If you're specifically targeting Windows, PowerShell is more ergonomic." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-24T03:29:00.7...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-23T21:47:51.613", "Id": "270342", "Score": "1", "Tags": [ "performance", "algorithm", "windows", "batch" ], "Title": "In a search of perfect batch script for editing the hosts fi...
270342
<p>I started learning classes and operator overloading in C++. To test my skills I decided to make a Fraction class with all necessary operations.</p> <p>I would appreciate improvements and suggesstions on my implementation.</p> <p>Here is the code -</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #inc...
[]
[ { "body": "<p>Generally, making your binary arithmetic operators member function a you have here is an issue because the two arguments are treated differently. The right argument will undergo implicit conversions, but the left will not! So, given a <code>Fraction f</code> and <code>int y</code> you could writ...
{ "AcceptedAnswerId": "270378", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-24T07:38:45.073", "Id": "270347", "Score": "2", "Tags": [ "c++", "object-oriented", "overloading", "rational-numbers" ], "Title": "Fractions in C++" }
270347
<p>I have a string like the one below from which I am extracting the tariff name.</p> <p><code>const url = &quot;https://any-api/supplier/tariffSelectionG_E5449168?t=randomChars&quot;</code></p> <p>So from the above string, I want text <code>tariffSelectionG_E5449168</code> and I am using the code below at the moment, ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-24T10:42:27.653", "Id": "533856", "Score": "3", "body": "You could leverage named capturegroups like `re = /https.*?supplier\\/(?<param>.*)\\?/g; re.exec(supplyUrl).groups[\"param\"]` to retrieve the same result more compact." }, {...
[ { "body": "<p>Super short review;</p>\n<ul>\n<li>The code should handle the presence or the absence <code>?</code> in a transparent way</li>\n<li>The code should probably check for <code>/supplier/</code> instead of <code>?</code></li>\n</ul>\n<p>That leaves me with</p>\n<pre><code>function extractTariffName(ur...
{ "AcceptedAnswerId": "270362", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-24T09:21:00.133", "Id": "270349", "Score": "6", "Tags": [ "javascript", "parsing", "ecmascript-6" ], "Title": "Extracting a part of a URL path" }
270349
<p>I have tried my hand with implementing simple quadrature formulas in C++.</p> <p>Definite integral: <span class="math-container">$$\int_a^b f(x) dx$$</span> Domain of integration <span class="math-container">\$[a, b]\$</span> divided into <span class="math-container">\$n\$</span> intervals of equal length <span clas...
[]
[ { "body": "<blockquote>\n<p>I wonder whether the #include &quot;NewtonCotesFormulas.cpp&quot; at the end of the NewtonCotesFormulas.h header file could be somehow avoided. I used it because without I'd get linking errors.</p>\n</blockquote>\n<p>Yea, that's simply wrong. You need to give both that CPP file and ...
{ "AcceptedAnswerId": "270360", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-24T15:31:06.550", "Id": "270354", "Score": "14", "Tags": [ "c++", "object-oriented", "numerical-methods", "factory-method" ], "Title": "Numerical integration in C++: Newton-C...
270354
<p>My Data consists of rows containing a Length/Duration in Minutes, a Begin &amp; EndTime. The precision is 1min (or larger).</p> <p>the table looks something like that:</p> <pre><code>CREATE TABLE public.&quot;TimeSeries&quot; ( &quot;Id&quot; uuid NOT NULL, &quot;BeginTime&quot; timestamptz NOT NULL, &qu...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-24T16:51:29.997", "Id": "533877", "Score": "2", "body": "Thanks for this great question - particularly for including your table definitions, which many new users overlook. I hope you get some good reviews, and I hope to see more of yo...
[ { "body": "<p>It's unwise to have a <code>LengthMin</code> in your table - this is redundant, and can be found as the difference between the begin and end time fields.</p>\n<p>None of your column or table names need quoting, and in most cases you also don't need to prefix the <code>public.</code> namespace.</p>...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-24T15:46:31.250", "Id": "270358", "Score": "2", "Tags": [ "sql", "datetime", "postgresql", "interval" ], "Title": "Find coherent datetime ranges in postgresql" }
270358
<p>I'm learning Objects calisthenics and I was practicing with the typical Tic Tac Toe game, I was wondering if you could gimme feedback about my mistakes (Algorithmic problems, logic, and especially OOP following Objects calisthenics rules). Thanks in advance!</p> <ul> <li>Only One Level Of Indentation Per Method</li>...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T10:29:43.090", "Id": "533987", "Score": "0", "body": "Which version of C# are you using?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T13:30:10.360", "Id": "534002", "Score": "0", "body"...
[ { "body": "<p>I think there are some good pointers in calisthenics rules, but <a href=\"https://en.wikipedia.org/wiki/KISS_principle\" rel=\"nofollow noreferrer\">KISS</a> principles should always trump.</p>\n<p>Consider the following example:</p>\n<pre><code>class Animal\n{\n public Animal(string type, stri...
{ "AcceptedAnswerId": "270440", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-24T19:06:20.820", "Id": "270366", "Score": "3", "Tags": [ "c#", "object-oriented" ], "Title": "TicTacToe Objects calisthenics OOP" }
270366
<p>In this code the angle between the minute and hour hands of an analog clock are found and calculated and the smaller angle between them returned. This code works perfectly and I am getting back the results I expect.</p> <p>We were told to do this and any testing if necessary.</p> <p>I got asked this in an interview ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-24T23:16:05.663", "Id": "533885", "Score": "1", "body": "`\"0930\"` will raise an `ArrayIndexOutOfBoundsException`. Also, `\"12:00:59\"` incorrectly returns 0.0 degrees." } ]
[ { "body": "<p>Declare variables close to where they're used. <code>hour</code> and <code>min</code> are declared and then ignored for half the body of the method. They can be assigned at declaration time, rather than being set to 0 first. And consider making them <code>final</code>, as they should not be reassi...
{ "AcceptedAnswerId": "270370", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-24T19:31:41.757", "Id": "270367", "Score": "3", "Tags": [ "java", "interview-questions", "computational-geometry" ], "Title": "Find smaller angle between minute and hour hands of...
270367
<p>I am currently working on a chess console app. However i feel like i got some inefficient code. For example: In order to find out whether an enemy is in check I start iteration over all pieces and all their possible moves. I am glad to get any advice regarding the structure syntax etc. on my project.</p> <p><a href=...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-25T13:41:34.337", "Id": "533915", "Score": "5", "body": "Please include all the code that you want to be reviewed in the body of the question. We can use links as references, but we can't review the code of the links." } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-24T19:55:33.807", "Id": "270368", "Score": "0", "Tags": [ "c#", "performance", "object-oriented", "chess" ], "Title": "Thinking about the efficiency of my chess program" }
270368
<p><a href="https://www.hackerrank.com/challenges/climbing-the-leaderboard/problem" rel="nofollow noreferrer">Climbing the Leaderboard</a></p> <blockquote> <p>An arcade game player wants to climb to the top of the leaderboard and track their ranking. The game uses Dense Ranking, so its leaderboard works like this:</p> ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-25T00:22:20.913", "Id": "533887", "Score": "0", "body": "Are you sure the code works at all?" } ]
[ { "body": "<p><strong>Removing duplicates efficiently</strong></p>\n<pre><code>ranked=[i for n, i in enumerate(ranked) if i not in ranked[:n]]\n</code></pre>\n<p>This line creates a copy of <code>ranked</code> at each iteration, which makes it inefficient.\nSince <code>ranked</code> is already sorted, create a ...
{ "AcceptedAnswerId": "270377", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-24T23:02:08.233", "Id": "270371", "Score": "1", "Tags": [ "python", "programming-challenge", "time-limit-exceeded", "binary-search" ], "Title": "HackerRank - Climbing the Lea...
270371
<p>I have implemented few functions in C language that manipulate strings. These functions are not present in the standard C library.</p> <hr /> <h2>string_library.c</h2> <pre><code> #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &quot;string_library.h&quot; /* * get_input_from_stdin_and_discard_extra_...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-25T09:28:40.407", "Id": "533909", "Score": "2", "body": "Would you show us the header too? I doubt it contains anything too controversial, but it's always helps, for a full review." } ]
[ { "body": "<h2><code>get_input_from_stdin_and_discard_extra_characters</code></h2>\n<blockquote>\n<pre><code> c = getchar();\n</code></pre>\n</blockquote>\n<p><code>c</code> is a <code>char</code>, so we lose the ability to distinguish <code>EOF</code> here. We need to use <code>int</code> for that.</p>\n<p...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-25T05:18:41.920", "Id": "270376", "Score": "4", "Tags": [ "c", "strings" ], "Title": "Functions in C language that manipulate strings, not present in the standard C library" }
270376
<p>I have several products. A product can have 1 or more images. In each image, we have content slot. I don't want duplication per content slot in a product.</p> <p>My code works fine. I'm just wondering what will be a better way to do this or improvement on my code?</p> <p>Codesandbox is here <a href="https://codesand...
[]
[ { "body": "<p>The filtering of options logic can be simplified a bit. Instead of first checking that the product slot array exists and has a truthy length, just allow the array's <code>.find</code> method to handle empty arrays, using Optional Chaining to access this deeply into the <code>product</code> object....
{ "AcceptedAnswerId": "270498", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-25T08:51:38.317", "Id": "270379", "Score": "2", "Tags": [ "ecmascript-6", "react.js", "redux" ], "Title": "Filter Options in React" }
270379
<p>I'm learning rust (coming from C++) and playing around with different small algorithms to understand the ownership &amp; borrowing concepts better. Currently, I'm having difficulties finding the idiomatic way to reuse a Vector after iterating over it in a for-loop. This is the (very verbose) code I currently have:</...
[]
[ { "body": "<p>welcome to the Rust community.</p>\n<p>Rust's borrow checker analyzes the control flow of your code. However, it does not take into account the state of your variables (<code>current_node</code> and <code>found_child</code> in your example). That would be something like symbolic execution.</p>\n<p...
{ "AcceptedAnswerId": "270463", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-25T09:59:37.053", "Id": "270380", "Score": "3", "Tags": [ "beginner", "rust", "trie" ], "Title": "Building a trie from a vector of strings in Rust" }
270380
<p>The following is a put controller I wrote to update a document.</p> <p>What I am updating is a particular array in the Model: The <code>issues</code> array. The schema for the Model is given below.</p> <p>It works and updates the <code>issues</code> array of the document.:</p> <ol> <li><p><strong>If the array gets v...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-25T11:22:22.300", "Id": "270382", "Score": "0", "Tags": [ "performance", "mongodb", "express.js", "mongoose" ], "Title": "Updating an array inside a document using Mongoose and E...
270382
<p>This is follow-up on <a href="https://codereview.stackexchange.com/questions/220557/sql-odbc-bind-to-c-classes-row-wise">SQL (ODBC) bind to C++ classes row-wise</a></p> <p>The main idea behind this code is to minimize the number of ODBC API calls, because profiling shows significant amount of time is spent in interm...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-25T15:54:52.273", "Id": "533922", "Score": "0", "body": "Are there some missing `#include` lines that got missed?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-25T19:03:48.607", "Id": "533933", "S...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-25T14:51:29.310", "Id": "270384", "Score": "2", "Tags": [ "c++", "c++20", "odbc" ], "Title": "SQL (ODBC) bind to C++ classes row-wise (follow-up)" }
270384
<p>This question is a supplement to my previous question: <a href="https://codereview.stackexchange.com/questions/270323/counting-absolute-nesting-levels-of-an-iterable">Counting 'absolute' nesting levels of an iterable</a>.</p> <p>I would like to expand functionality of counting nests in order to get values from given...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-25T19:48:48.973", "Id": "533934", "Score": "1", "body": "Too short for a review. But two minor nitpicks. Your use of Pascal Case is not idomatic to python (functions should use snake_case), nor is your overuse of comments. Please expl...
[ { "body": "<p>Your previous question dealt with counting the number of levels in a nested\ndata structure. This question deals with collecting values from a specific\nlevel (sort of). In both cases, your conceptualization of the problem strikes\nme as somewhat unintuitive, at least based on my experience with l...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-25T15:09:40.070", "Id": "270386", "Score": "2", "Tags": [ "python", "beginner" ], "Title": "Getting values from a given level of a nested collection" }
270386
<p>I am new to react and I tried to implement a TODO application using react state and props. I need somebody to just review the code and suggest improvements in the code. Currently I have not added any CSS to it, I am focusing more on react practices. code sandbox link- <a href="https://codesandbox.io/s/adoring-archim...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-25T19:39:32.150", "Id": "270392", "Score": "2", "Tags": [ "beginner", "react.js", "jsx", "to-do-list" ], "Title": "To-do application in React" }
270392
<p>I'm implementing some simple algorithms (e.g. two-sum) in OCaml and I am unsure why my OCaml solution is running much slower than the equivalent Python version.</p> <p>My OCaml version:</p> <pre class="lang-ml prettyprint-override"><code>open Base let two_sum_hash lst target = let rec loop tbl counter = function...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-25T21:16:17.903", "Id": "270395", "Score": "0", "Tags": [ "performance", "algorithm", "ocaml", "k-sum" ], "Title": "OCaml implementation of two-sum" }
270395
<p><a href="https://i.stack.imgur.com/HEF6e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HEF6e.png" alt="example" /></a></p> <p>given a number and two dimensional array the method will check if the number is in the array the array is quadratic circular size n x n and each quarter of the array cont...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T02:39:20.150", "Id": "533959", "Score": "1", "body": "Given that the 2d array is not sorted either vertically or horizontally, how can a binary search that treats the input as a single array work?" }, { "ContentLicense": "CC...
[]
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-25T21:37:29.260", "Id": "270396", "Score": "0", "Tags": [ "java", "performance", "array" ], "Title": "finding a value in circular two dimensional array" }
270396
<p>take an array of two numbers who are not necessarily in order, and then add not just those numbers but any numbers in between. For example, [3,1] will be the same as 1+2+3 and not just 3+1.</p> <pre><code>function sumAll(arr) { let start = arr[0]; let end = arr[1]; if (start &gt; end) { let temp = start; ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T09:27:43.393", "Id": "533977", "Score": "3", "body": "There's absolutely no reason to use recursion for this. What is this code used for? Is this a school assignment?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate...
[ { "body": "<h2>Recursion</h2>\n<p>Recursion in JavaScript is just a toy and should be avoided when ever possible.</p>\n<p><strong>Why?</strong></p>\n<ul>\n<li><p>Untrustable. JavaScript has a very limited call stack and recursive code can quickly consume the call stack. For example <code>getSum(1, 10000)</code>...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T01:17:47.680", "Id": "270400", "Score": "2", "Tags": [ "javascript", "recursion" ], "Title": "Arithmetic progression using Recursion" }
270400
<p>This is my first real personal application and I'm just looking for some outside feedback. Completely built in Python, this is a Pokédex for the Pokémon Mystery Dungeon series. I hope to eventually publish to the Android app store. If you choose to check it out... don't be nice. Tell me how bad it is, (just make sur...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T08:20:09.087", "Id": "533971", "Score": "2", "body": "Welcome to Code Review! The current question title, which states your concerns about the code, is too general to be useful here. Please [edit] to the site standard, which is for ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T04:41:34.333", "Id": "270403", "Score": "1", "Tags": [ "python", "beginner", "pokemon" ], "Title": "Pokédex by a Python novice" }
270403
<p>So to check my Python knowledge I am building a cricket scoreboard in Python. My scoreboard could be able to can be used to store previous matches ' scores. A work in progress as of now. But as of now, it is a 50/50 success. I might have done 50% of the work already, but I am can't move forward. I have my code on Gi...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T07:54:19.093", "Id": "533968", "Score": "1", "body": "Hello at Code Review@SE. Please heed [How do I ask a Good Question?](https://codereview.stackexchange.com/help/how-to-ask)" } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T05:01:49.487", "Id": "270404", "Score": "0", "Tags": [ "python" ], "Title": "Building a Cricket Scoreboard from Python" }
270404
<p>My boss asked me, a <strong>Polar researcher</strong> whose major is biology (surprise!), to do a coding work which I am NOT really good at, for our satelite data processing module. (I'm not even sure why he asked me to do this in the first place...sigh...corporate culture)</p> <p>He said</p> <ol> <li><p>his codes h...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T08:19:41.330", "Id": "533970", "Score": "2", "body": "We need to know *what the code is intended to achieve*. To help reviewers give you better answers, please add sufficient context to your question, including a title that summaris...
[ { "body": "<p><code>try</code>/<code>except</code> are used for error handling,</p>\n<pre><code>try:\n do_something()\nexcept:\n # an error occured.\n pass\n</code></pre>\n<p>So that if <code>do_something()</code> throws an error (<a href=\"https://docs.python.org/3/tutorial/errors.html\" rel=\"nofollow nore...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T05:19:13.073", "Id": "270405", "Score": "0", "Tags": [ "error-handling", "classification" ], "Title": "classifying codes + adding __str__ and exception handling (try~except)" }
270405
<p>I have implemented a library which makes Java Swing programming easier. I am just posting the library. There is a program that uses this library to implement examples of many Swing components but I cannot include that program here because the total size will become more than the allowed limit of 65K characters. I wi...
[]
[ { "body": "<p>There's a lot of code here, so here's a few things to get started with...</p>\n<h2>Comments</h2>\n<ul>\n<li><p>Consider JavaDoc for function description comments that the clients of your library might want to know, such as <code>// if width is 0 then the frame is maximized horizontally</code>. The...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T06:52:38.143", "Id": "270406", "Score": "0", "Tags": [ "java", "swing" ], "Title": "Java Swing Library" }
270406
<p>This is in continuation of my previous post for code review of Java Swing Library: <a href="https://codereview.stackexchange.com/questions/270406/java-swing-library">Java Swing Library</a></p> <p>Since the limit on total number of characters is 65K, I split my program in two parts. The first was Java Swing Library a...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-29T07:01:59.443", "Id": "534201", "Score": "0", "body": "Is this a real code review or a trick question? all your code is named `example` - is it for real?" } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T07:42:58.447", "Id": "270408", "Score": "1", "Tags": [ "java", "swing" ], "Title": "Examples of many Java swing components in one program" }
270408
<p>Background:</p> <p>Hello, I'm a student (since 2 months) and I've created a small MVP of a weather application. So now I'm refactoring my code because it looks hideous and it is hard to work with.</p> <p>The problem:</p> <p>In the snippet I will provide you will see that I repeat code for a .map(), which I know is n...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T09:55:04.173", "Id": "533982", "Score": "0", "body": "Welcome to code review. Please check the [ask] page." } ]
[ { "body": "<h1>Hey Jonathan, welcome to Code Review!</h1>\n<p>There's an easy way to turn those two <code>map</code>s into one. I'm going to tell you how, and give you some general tips as a bonus. Buckle up!</p>\n<br/>\n<hr />\n<br/>\n<h1>➰ <a href=\"https://youtu.be/PGNiXGX2nLU?t=61\" rel=\"nofollow noreferre...
{ "AcceptedAnswerId": "270457", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T09:13:23.517", "Id": "270411", "Score": "1", "Tags": [ "javascript", "html", "hash-map", "react.js", "jsx" ], "Title": "React - Component rendering weather data" }
270411
<p>As already written in the title I want to count the numbers in the range (x+1, y) where x and y are integers, in which the sum of the digits in odd places have the same parity of the ones in even places. I made this code:</p> <pre><code>def findIntegers(x, y): count = 0 for k in range(int(x)+1, int(y)+1...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T11:23:41.837", "Id": "533994", "Score": "1", "body": "And clarify the task; is x excluded from the range and y included?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T02:45:23.210", "Id": "53405...
[ { "body": "<h3>Use type hints and unit tests</h3>\n<p>They are simple and make your code better.</p>\n<h3>Some improvements and pythonification</h3>\n<p><code>odd_sum</code> and <code>even_sum</code> are initialized with zeroes before adding to them, so you can simply initialize them instead of adding:</p>\n<pr...
{ "AcceptedAnswerId": "270428", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T10:25:13.987", "Id": "270414", "Score": "6", "Tags": [ "python", "performance", "integer", "interval" ], "Title": "Count the numbers in a range in which the sum of the odd...
270414
<p>For a program I'm writing, it requires a lot of printing and receiving user input. I've found it cumbersome to keep specifying the type strings in <code>printf</code>, and having to write another <code>printf</code> before using <code>scanf</code> to receive input. I've decided to write two macros, <code>print</code...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T13:56:23.407", "Id": "534005", "Score": "0", "body": "I don't think the C11 tag is necessary for code that works fine with current standard C (i.e. C17)." } ]
[ { "body": "<p>This looks like a missed opportunity. I was hoping to see something that would usefully handle re-trying when the input can't be parsed, but instead we have a macro that throws away the return value from <code>scanf()</code>, so that we have no idea whether it was successful or not.</p>\n<p>I'm n...
{ "AcceptedAnswerId": "270418", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T11:47:57.413", "Id": "270416", "Score": "2", "Tags": [ "c", "macros", "c11" ], "Title": "Simplified print and input macros in C" }
270416
<p>Modules for FPGAs for generating a pseudo-random bit sequence are presented. The first module generates a bit sequence. The third module speeds up the generation by transferring the bus to, for example, a multiplexer which is controlled by a faster device. Hence this bus is serialized into a bit sequence.</p> <p>prb...
[]
[ { "body": "<p>I get compile errors on 2 different simulators (Cadence and Synopsys) from these 2 lines in the testbench:</p>\n<pre><code>logic prbs = '0;\nlogic prbs_n = '0;\n</code></pre>\n<p>Since you connect those signals to the module instance output ports, you should not set them to any value in the de...
{ "AcceptedAnswerId": "270442", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T12:59:20.153", "Id": "270417", "Score": "2", "Tags": [ "verilog", "fpga", "hdl", "prbs", "systemverilog" ], "Title": "pseudo-random binary sequence (prbs)" }
270417
<p>I want to simplify some code I have written but not sure how to go about doing it. When my workbook opens it checks the current date and compares it to dates I have on a sheet. If the current date is &lt;= date on sheet it writes the date range to a cell. My issue is I have 13 If statements and would like to simply/...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T14:51:09.843", "Id": "534009", "Score": "2", "body": "Welcome to CodeReview. Your current title applies to virtually every question on this site, so the usual practice is to title your post with what the code is doing." }, { ...
[ { "body": "<p><strong>DRY</strong></p>\n<p>There is an important software principle called &quot;Don't Repeat Yourself&quot; (DRY). Writing software with frequent use of Copy-Paste is the antithesis of DRY. Not only does it cause repeated expressions with minor differences per copy - it results in code that i...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T14:38:29.170", "Id": "270421", "Score": "3", "Tags": [ "vba", "excel" ], "Title": "Checking if date falls within a date range then write the date range to a cell" }
270421
<p>Is this the correct way to calculate leap years in a range of [y,x) ?</p> <pre><code>def bis(y1,y2): mas = max(y1,y2) mini = min(y1,y2) k=0 for i in range(mini,mas): if i % 4 == 0 and i % 100 != 0: if i % 400 != 0: k=k+1 return k print(bis(1904,1957...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T17:24:36.913", "Id": "534025", "Score": "3", "body": "No. Consider the year 2000 and compare your code to [StackOverflow](https://stackoverflow.com/a/30714165/55857) on this topic." } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-26T16:52:01.040", "Id": "270425", "Score": "-4", "Tags": [ "python" ], "Title": "Leap year in python brief code" }
270425
<p>This project is based off the shunting yard algorithm and has additional features such as negative value parsing. It's like a scientific calculator. I am looking to improve this project by getting rid of potential errors and optimizing code. I have tried many cases and have fixed the broken ones I've seen. However, ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T05:56:12.287", "Id": "534059", "Score": "1", "body": "Hello at Code Review@SE. Applying an unnamed tolerance to decide outputting `0`, but not `±i` without a numerical value looks paradox. Please explicitly state what you think *red...
[ { "body": "<p>Well, stop passing <code>string</code> <strong>by value</strong>.<br />\nActually, use <code>string_view</code> for parameters (by value).<br />\nWhy does str2int take a <code>const char*</code> rather than a <code>string</code> or <code>string_view</code>? Again, just make it take a <code>string...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T00:13:04.847", "Id": "270433", "Score": "2", "Tags": [ "c++", "performance", "algorithm", "math-expression-eval", "complex-numbers" ], "Title": "Shunting Yard Calculator -...
270433
<p>All 3 ids are basically the same button but different divs, but I had to rename them to accomplish what I was looking for. Is there a way to write this better? Any help is much appreciated.</p> <pre><code>$(document).ready(function(){ $(&quot;#open_iptvbasic&quot;).click(function(){ $(&quot;#iptv-channel...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T02:41:53.973", "Id": "534052", "Score": "6", "body": "Welcome to CodeReview. On this site, every question falls into \"can I write this better\", so we generally want titles to reflect the code in the question. See [ask]. Specifi...
[]
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T02:05:01.373", "Id": "270434", "Score": "-2", "Tags": [ "javascript", "jquery", "html", "css" ], "Title": "Is there a way to write this better?" }
270434
<p>I'm developing a REST API using Azure Functions with .NET 5 (Isolated) and I want to add an OpenAPI spec for each route. But it looks like this:</p> <pre class="lang-csharp prettyprint-override"><code>namespace AzureFunctionsREST.API.Functions { public class ReporterFunction : BaseFunction { private ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T16:10:35.843", "Id": "534084", "Score": "0", "body": "Please do not update your question after an answer has been posted. See https://codereview.stackexchange.com/help/someone-answers ." }, { "ContentLicense": "CC BY-SA 4.0"...
[ { "body": "<p>The sad truth is there is no nice solution for this (at least according to my knowledge).</p>\n<p>But there are some tiny tricks which you can apply to make your code more concise:</p>\n<ul>\n<li>Use type alias to abbreviate attribute names</li>\n<li>Use constant classes to capture constant values...
{ "AcceptedAnswerId": "270438", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T08:57:20.747", "Id": "270437", "Score": "3", "Tags": [ "c#", ".net", "azure" ], "Title": "C# duplicated attributes on Azure Functions with OpenAPI specifications" }
270437
<p>I needed to pass a const reference to part of a <code>std::vector</code> without copy. I posted the previous version in my <a href="https://codereview.stackexchange.com/questions/270271/custom-implementation-to-provide-an-immutable-range-of-a-vector-without-copying">earlier question</a>, thank you for the great supp...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T13:38:06.983", "Id": "534074", "Score": "0", "body": "Thanks, I corrected it" } ]
[ { "body": "<p>With C++17 the compiler should be able to deduce the template type automatically by using the following:</p>\n<pre><code>template &lt;typename Iterator&gt;\nclass ConstVectorSubrange {\npublic:\n using T = typename Iterator::value_type;\n // ...\n}\n\nint main() \n{\n std::vector v{ 1, 2,...
{ "AcceptedAnswerId": "270446", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T11:55:49.403", "Id": "270439", "Score": "7", "Tags": [ "c++", "template", "iterator", "collections" ], "Title": "Custom implementation to provide an immutable range of a c...
270439
<p>I have created a simple abstract class called <code>expr_node</code> which will serve as a base class for any expression-related nodes.</p> <p>My goal is to create a simple deleter that can delete the allocated memory from the derived class in which would be recursive in some cases.</p> <p>Rules and constraints (NOT...
[]
[ { "body": "<p>A much simpler approach would be to create virtual destructors for <code>unary_op_node</code> and <code>binary_op_node</code> like the following:</p>\n<pre><code>struct unary_op_node : expr_node {\n expr_node* operand;\n // ...\n virtual ~unary_op_node() override {\n delete operand...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T13:39:40.000", "Id": "270443", "Score": "0", "Tags": [ "c++", "expression-trees" ], "Title": "Deleter for Simple Expression Tree in C++" }
270443
<blockquote> <p>Given an array <span class="math-container">\$a\$</span> of integers, find minimum sum obtained after performing <span class="math-container">\$K\$</span> <em>operation</em>s. In this context <em>operation</em> involves choosing an element <em>a[i]</em>, multiply it by <span class="math-container">\$2\$...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T15:23:30.170", "Id": "534078", "Score": "0", "body": "Welcome to the Code Review Community. We only review code that is working as expected, there are other sites that will help you debug your code. Please read [Where can I get help...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T13:48:22.940", "Id": "270444", "Score": "-2", "Tags": [ "python" ], "Title": "Minimize sum of array after performing K operations(Python)" }
270444
<p>I wrote a program with Python that converts decimal positive numbers to binary and puts the result in a list. I have a problem with decimal 0 because the result I get is <code>[]</code> instead of <code>[0]</code>. It works just fine with every number except for 0. How can I improve it to make it work with 0 too?</p...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T14:45:55.553", "Id": "534077", "Score": "0", "body": "please this is urgent!!!!!" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T15:24:23.760", "Id": "534079", "Score": "0", "body": "Welco...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T14:04:48.887", "Id": "270445", "Score": "-4", "Tags": [ "python" ], "Title": "Python program to convert decimal to binary" }
270445
<p>Here is my A* algorithm. I tried hard to implement it generically, but come up only with one idea to use lambdas for heuristic and next nodes (neighbours / successors) functions. I know that using good heuristic function is the key to speed up, but here i'm trying to squeeze everything from current implementation no...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T20:26:13.550", "Id": "534104", "Score": "0", "body": "The `not` operator confused me for a second until I remembered about alternative operators. I'm not sure if it's considered good practice to use them?" }, { "ContentLicen...
[ { "body": "<h2>Linear search through the whole heap</h2>\n<blockquote>\n<pre><code>// find the node with the same data as child\nauto it = std::find_if(opened.begin(), opened.end(), [&amp;child](auto&amp;&amp; node) {\n return node-&gt;data == child;\n});\n</code></pre>\n</blockquote>\n<p>This is a clear iss...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T16:13:53.250", "Id": "270452", "Score": "4", "Tags": [ "c++", "performance", "pathfinding", "a-star" ], "Title": "Improving generic A* algorithm performance" }
270452
<p>I have a base view model which implements an Mode View View model pattern.</p> <pre><code> public interface IBaseViewModel&lt;T&gt; { #region public properties BaseViewModelProperties BaseVMProps { get; set; } T Model { get; set; } #endregion #region public methods Task Init(); Task I...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T23:39:33.430", "Id": "534120", "Score": "1", "body": "Welcome to Code Review? Please tell us, and also make that the title of the question. See [ask]." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-28T1...
[]
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T18:57:00.053", "Id": "270454", "Score": "-1", "Tags": [ "interface" ], "Title": "Interface Segregation Principle" }
270454
<p>So I tried implementing a easily extendable solution for <a href="https://www.geeksforgeeks.org/sqrt-square-root-decomposition-technique-set-1-introduction/" rel="nofollow noreferrer">Sqrt decompostion</a>, I deduced that only identity value, operation and block update logic change and rest of the code is same. So ...
[]
[ { "body": "<h1>Design review</h1>\n<p>Your design is mostly sound. It can be simplified a little bit, and optionally made a bit more rigorous, but the basic design is not bad.</p>\n<p>The name for what you’re doing is <a href=\"https://en.wikipedia.org/wiki/Modern_C%2B%2B_Design#Policy-based_design\" rel=\"nofo...
{ "AcceptedAnswerId": "270460", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T21:51:36.553", "Id": "270455", "Score": "2", "Tags": [ "c++", "c++11", "template", "c++14" ], "Title": "C++ template and inheritance - Generic Sqrt Decomposition" }
270455