body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>If you already know the start and ending character positions of text you want to replace, this bypasses the need to calculate the length. It just helps eliminate a step by not requiring you to calculate the length because this uses <code>start_num</code> and <code>end_num</code> directly as parameters. It can be use...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-26T18:11:46.843", "Id": "513180", "Score": "0", "body": "This is working code. I created it for those who would prefer to use the Replace function with a start and end character position and not need to calculate length in their code. ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-26T18:11:46.843", "Id": "260041", "Score": "1", "Tags": [ "vba", "excel" ], "Title": "Replace2 using start and end rather than length" }
260041
<p>I have been working on where I create a payload of dicts with different values as store, name etc etc which you will see very soon. The idea is that with the payload I send to this script, it should see if the values is in the payload (dict) and if it is then add it into discord embed. As simple as it sounds.</p> <p...
[]
[ { "body": "<p>If I were a smart man I'd give up on recommending that you stop using a payload dictionary for internal data representation and instead use classes, but I'm not a smart man. Please. I implore you. We're not in JavaScript - objects don't have to be dictionaries. This could be well-represented by a ...
{ "AcceptedAnswerId": "260159", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-26T18:19:01.007", "Id": "260043", "Score": "3", "Tags": [ "python", "python-3.x", "discord" ], "Title": "Creating embed for Discord reading from dictionary" }
260043
<p>I have implemented Battleship in Python by using lists. I have used threading to prevent <code>KeyboardInterrupt</code>, so the player can't cheat by using control-c and stuff.</p> <p>How can I simplify this code?</p> <pre><code>import random import sys from threading import Thread import keyring master_break = key...
[]
[ { "body": "<h1>Preface</h1>\n<p>At first glance, your code is unnecessarily convoluted. I see that you tagged the question as beginner, so I'll cut you some slack. But as a general warning, if you're developing a simple application/game, and you have a nesting of <code>if/else</code> <strong>15</strong> indenta...
{ "AcceptedAnswerId": "260245", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-26T20:04:52.110", "Id": "260047", "Score": "4", "Tags": [ "python", "beginner", "python-3.x", "battleship" ], "Title": "Python Battleship" }
260047
<p>I want to implement a function <code>take_upto_n(A, n)</code> such that for e.g.</p> <pre><code>take_upto_n([1,2,3,4], 8) returns [1,2,3,2] take_upto_n([1,2,4,3], 8) returns [1,2,4,1] take_upto_n([1,2,3,4], 100) returns [1,2,3,4] take_upto_n([1,2,3,4], 3) returns [1,2,0,0] </code></pre> <p>Assume <code>A</code> cont...
[]
[ { "body": "<p>Your regular Python implementation generally looks reasonable, and unless numpy\noffers a performance boost that you really need, I would not recommend it for\nthis use case: the brevity/clarity tradeoff seems bad.</p>\n<p>My biggest suggestion is to consider clearer names. A function with signatu...
{ "AcceptedAnswerId": "260061", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-26T20:39:30.807", "Id": "260048", "Score": "3", "Tags": [ "python", "numpy" ], "Title": "Selecting a quantity from a list" }
260048
<p>My latest project is a Rock Paper Scissors Game that I made in The Odin Project course. It's a web version, made with HTML, CSS and JS. I would appreciate to read your opninions, especially with regards to the JS.</p> <p>The Game to play: <a href="https://amina-mari.github.io/rock-paper-scissors/" rel="nofollow nore...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-26T21:52:00.713", "Id": "260050", "Score": "0", "Tags": [ "javascript", "html", "css", "dom", "rock-paper-scissors" ], "Title": "Rock Paper Scissors Game in JavaScript" }
260050
<p>So there's another question about storing information about a trading card game, but in my situation I have to store not only raw tournament information but a lot of statistics I've extracted from it:</p> <p><strong>Web Scraper &gt; SQL Database</strong></p> <p>Tournaments</p> <ul> <li>Format (different collections ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-26T23:12:47.807", "Id": "513199", "Score": "0", "body": "Welcome to Code Review! The post mentions _SQL Server_ yet the [postgresql tag](https://codereview.stackexchange.com/tags/postgresql/info) is used- should the [sql-server tag](ht...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-26T22:33:32.563", "Id": "260052", "Score": "0", "Tags": [ "sql", "database", "postgresql" ], "Title": "MTG Metagame Schema" }
260052
<p>Would someone review this code, and confirm that it is indeed recursive? I'm learning computer science and going through different types of algorithms. Right now, I'm focusing on recursion want to ensure that this 'recursive palindrome' method is truly recursive. I've passed six different strings as a test, three th...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T05:40:29.237", "Id": "513217", "Score": "3", "body": "Please define palindrome! As I understand it, both empty string and single letter word are palindromes..." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "202...
[ { "body": "<p>You really didn't need to include the second snippet that you know is not working.</p>\n<p>However, the first snippet is not working correctly either although you thought it does. That's because you didn't write enough tests. The main problem with your implementation is that is treats empty string...
{ "AcceptedAnswerId": "260064", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T00:19:08.907", "Id": "260057", "Score": "-1", "Tags": [ "javascript", "recursion", "palindrome" ], "Title": "Recursive Palindrome in JavaScript" }
260057
<p>For a small project of mine, I will be needing to work a lot with braille translation. To do that, I have already finished a small program that I can use to translate braille into English letters. To make the whole thing a little more modular, I exported all my braille logic into a small module:</p> <pre><code>from ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T14:53:08.900", "Id": "513254", "Score": "1", "body": "`GUI.THEME_COLOR` is undefined" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T17:49:25.487", "Id": "513271", "Score": "0", "body": "a...
[ { "body": "<p>First a few small things:</p>\n<p>If you expect this to be used in other programs, it should be documented: comments to explain implementation choices and details and docstrings to explain how to use the classes and functions in the module.</p>\n<p>A small suggestion: When modeling something, it i...
{ "AcceptedAnswerId": "260099", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T00:39:58.430", "Id": "260058", "Score": "8", "Tags": [ "python", "python-3.x", "reinventing-the-wheel" ], "Title": "Braille Mini-Library in Python" }
260058
<p>I’m currently building myself a website using GitHub pages.</p> <p>I wanted to have a theme system, and recently rebuilt my implementation.<br /> It now manages a <code>&lt;style&gt;</code> tag with ID <code>theme</code> in the <code>&lt;head&gt;</code> tag.<br /> I rebuilt it to add support for custom themes, but t...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T01:49:15.847", "Id": "260059", "Score": "2", "Tags": [ "typescript" ], "Title": "I’d like some feedback on my theme system implementation in TypeScript for my website" }
260059
<p>I've been practising trying to write my code neater, so decided to build a practice GUI, the code works, However, how could I tidy this up in terms of separating out the different parts of the GUI, such as a separate defs for labels, Combobox etc? or using a function for the 'with open' section.</p> <pre class="lang...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T10:09:10.107", "Id": "513239", "Score": "0", "body": "the comments do not add additional information, I would just remove them." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T06:19:54.523", "Id":...
[ { "body": "<pre><code>if __name__ == &quot;__main__&quot;:\n GUI(root)\n root.mainloop()\n</code></pre>\n<p>instead of</p>\n<pre><code>def main():\n GUI(root)\n root.mainloop()\n\nmain()\n</code></pre>\n<p>it's the &quot;pythonic&quot; way of accomplishing what you've written.</p>\n", "comments"...
{ "AcceptedAnswerId": "260283", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T09:43:09.407", "Id": "260066", "Score": "4", "Tags": [ "python", "tkinter", "gui", "user-interface" ], "Title": "PATM Generator GUI" }
260066
<p><strong>Introduction:</strong></p> <p>So far, the game works well, and my only major concerns, are a bullet system (including a function where you click the mouse to shoot the bullets), and a collision system between the zombies and bullets, as I've tried many different ways to go about those two issues, with no luc...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T14:40:20.393", "Id": "513252", "Score": "0", "body": "You seem to have skipped some of those recommendations, particularly creating a player class and moving global code into functions." }, { "ContentLicense": "CC BY-SA 4.0"...
[ { "body": "<h1>Colliding</h1>\n<p>For now, let's assume that your bullets travel in a straight line from left to right, or from right to left.</p>\n<p>Your zombies have a position, <code>self.x</code> and <code>self.y</code>. In addition, they also have an image that you draw on the screen (<code>images['l_zomb...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T12:39:19.440", "Id": "260069", "Score": "4", "Tags": [ "python", "game", "pygame", "collision" ], "Title": "Revised Top-Down Dungeon RPG" }
260069
<p>I have a start and end date. I would like to return a list of tuples, which have the start and end dates of each month.</p> <pre><code>Input start_date = '2020-10-14' end_date = '2021-03-26' Output [('2020-10-14', '2020-10-31'), ('2020-11-01', '2020-11-30'), ('2020-12-01', '2020-12-31'), ('2021-01-01', '2021-01-...
[]
[ { "body": "<p>None of this code should deal in strings, except <em>maybe</em> the final output stage. It can all be thrown away in favour of a single generator function that uses the highly-useful <code>dateutil</code> library. Also type hints will help:</p>\n<pre><code>from datetime import date\nfrom typing im...
{ "AcceptedAnswerId": "260075", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T14:59:02.023", "Id": "260070", "Score": "2", "Tags": [ "python" ], "Title": "Return list of tuples of date ranges" }
260070
<p>I am checking three elements on the DOM to see if they are empty or not so that I can run only the Ajax calls that I should run and save on overall bandwidth. The code works but it &quot;smells bad&quot;. Here is my source.</p> <pre class="lang-javascript prettyprint-override"><code>const processValues = (area, city...
[]
[ { "body": "<p>After speaking with some friends, this is seen as the best solution. One adjustment to the return values was required however; change the casing from camel case to title case. I am also using constants to make sure that return values can be consistently used properly.</p>\n<pre class=\"lang-javasc...
{ "AcceptedAnswerId": "260078", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T15:06:13.933", "Id": "260071", "Score": "0", "Tags": [ "javascript", "jquery" ], "Title": "Check Three Dom Elements to See if they are empty or not and return detailed result" }
260071
<p>I live in the buildings that have 50 people in it and for each floor splits into 2 groups each group is from ~9 people. I'm trying to build an Xamarin app (IOS, ANDROID ,Win10,maybe web app) to make it easier to us to communicate.</p> <p><strong>Explaining the way i did my DB as it is:</strong></p> <p>The shopping t...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T15:27:39.883", "Id": "513259", "Score": "0", "body": "Welcome to CodeReview. Just to make sure: does your code work as expected?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T15:32:59.097", "Id"...
[ { "body": "<p>There are quite a few naming issues in your code. You may want to think about installing a spell check extension in your IDE to help you catch these. I'm an appalling speller so I've got extra spell checks <em>everywhere</em> (IDE, browser etc.)</p>\n<p>Naming is <em>so</em> important and the thin...
{ "AcceptedAnswerId": "260103", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T15:19:02.623", "Id": "260073", "Score": "2", "Tags": [ "c#", "mysql", "asp.net-web-api", "dapper", ".net-5" ], "Title": "Dapper with shops and payers" }
260073
<p>I am using PySpark in Azure DataBricks to try to create a SCD Type 1.</p> <p>I would like to know if this is an efficient way of doing this?</p> <p>Here is my SQL table:</p> <pre><code>CREATE TABLE dbo.Countries ( CountryId bigint IDENTITY, ShortName nvarchar(max) NULL, FullName nvarchar(max) NULL, CapitalCi...
[]
[ { "body": "<p>A random scattering of things:</p>\n<ul>\n<li><code>CapitalCities</code> is suspicious and suggests an improperly normalized schema. One would expect a separate table with a foreign key if a country needs to represent multiple capitals. Either that or this is just misnamed and you only need to rep...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T15:35:44.150", "Id": "260076", "Score": "3", "Tags": [ "python", "python-3.x", "sql-server", "apache-spark" ], "Title": "PySpark SCD Type 1" }
260076
<p>This is a follow-up question to <a href="https://codereview.stackexchange.com/questions/259814/encryption-decryption-algorithm">this</a> one.</p> <p>I have tried to implement all the recommended things in the answers (except commenting, and not being OS specific). Again, if you see anything that needs improvement, o...
[]
[ { "body": "<ul>\n<li><p>Consider adding PEP484 type hints. I needed to go through this to make some sense of the values you're passing around.</p>\n</li>\n<li><p><em>not being OS specific</em> - indeed. Your call to <code>cls</code> has dubious security value, and if you deem it to have such value, it's better ...
{ "AcceptedAnswerId": "260090", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T15:39:02.737", "Id": "260077", "Score": "2", "Tags": [ "python", "reinventing-the-wheel", "cryptography" ], "Title": "Encryption/Decryption algorithm #2" }
260077
<p>I made Tic Tac Toe in Python. Standard code review, please tell me ways to improve. I am very new to Python, so please do not criticize very roundabout ways. Thanks.</p> <pre><code>board = [] for x in range(3): board.append([' '] * 3) def print_board(board): x = 1 print(' A B C') print() d...
[]
[ { "body": "<p>Naming of variables is perfect and you are following the python convention - and that is really good because it makes the code easier to read.</p>\n<p>I've executed the code and I've noticed that when you insert an invalid input two things may happen</p>\n<ol>\n<li>Input &quot;1A&quot;; Output: &...
{ "AcceptedAnswerId": "260117", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T19:23:20.600", "Id": "260084", "Score": "3", "Tags": [ "python", "beginner", "python-3.x", "game", "tic-tac-toe" ], "Title": "Tic Tac Toe in Python 3.x" }
260084
<p>I previously implemented a Merge Sort for arrays, so after fixing up my code for the array-based merge sort I have now implemented a merge sort for a basic singly-linked list data structure which only contains the pointer to the data and a pointer to the next &quot;Node&quot;. I have tried to use the advice given on...
[]
[ { "body": "<ul>\n<li><p>No naked loops. Every loop represents an important algorithm, and as such deserves a name. For example, the loops in <code>split_list</code> really are</p>\n<pre><code> uint32_t list_length(struct Node *);\n</code></pre>\n<p>and</p>\n<pre><code> struct Node * advance(struct Node *, uin...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T21:15:13.800", "Id": "260087", "Score": "2", "Tags": [ "algorithm", "c", "linked-list", "pointers", "mergesort" ], "Title": "Merge Sort for Linked List Criticism in C" }
260087
<p>This code should query the github api and filter, out of the last 1000 commits, which ones include and exclude certain words from the top 3 repositories in a given organization.</p> <p>For example, I could query the endpoint <code>/search</code> with parameters such as <code>org:facebook</code> and <code>include:fix...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T13:57:17.937", "Id": "513479", "Score": "0", "body": "Does the code work as expected?" } ]
[ { "body": "<p><code>if request.method == 'POST':</code> is redundant; delete it.</p>\n<p>Your</p>\n<blockquote>\n<p>your request is missing the 'org', 'include' or 'ignore' parameters</p>\n</blockquote>\n<p>is less than helpful. Why not tell the user exactly what they're missing?</p>\n<p>This <code>except</code...
{ "AcceptedAnswerId": "260092", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T21:50:04.387", "Id": "260089", "Score": "2", "Tags": [ "python", "json", "api", "flask" ], "Title": "Query the github api and filter the last 1000 commits which include an...
260089
<p>As a way to learn PySimpleGUI, and eventually tkinter, I re-implemented a computing cluster CPU load monitor I wrote long ago. I'm looking for any feedback on whether it's well-written, but in particular I have concerns about two areas:</p> <p>One, whether the organizational structure is correct. As objects, Cluster...
[]
[ { "body": "<p>Code looks nice. I would keep classes on the same level.<br />\nIt seems more readable when you can read smaller part of code.</p>\n<p>But your code looks like mix of <code>Cluster Simulator</code> + <code>GUI Monitor</code> and in real situation they would be two separated elements. You would hav...
{ "AcceptedAnswerId": "260222", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-27T22:34:00.040", "Id": "260091", "Score": "2", "Tags": [ "python", "python-3.x" ], "Title": "PySimpleGUI app to monitor cluster CPU load" }
260091
<p>Discord is a popular VoIP/IM service. Discord provides an API and hosts your servers for free unlike other popular VoIP software like Mumble and TeamSpeak.</p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-28T07:42:54.863", "Id": "260104", "Score": "0", "Tags": null, "Title": null }
260104
For programs interacting with Discord.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-28T07:42:54.863", "Id": "260105", "Score": "0", "Tags": null, "Title": null }
260105
<p>I created a quick function to convert <code>n</code> bytes into binary for my student. She is not on that level yet, but I think it would be best for her if my demonstrative functions aren't trash.</p> <pre><code>void binary (void* p, size_t nBytes) { int iBit = 0; int iByte = 0; putchar('['); ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T19:38:13.870", "Id": "513520", "Score": "2", "body": "Do you really want `\"[]\\n\"` for `binary(0,0)`? How about `\"\\n\"` instead?" } ]
[ { "body": "<p>It's not terrible as it stands, but I think there are some ways it might be improved.</p>\n<h2>Include all needed files</h2>\n<p>The function needs several <code>#include</code> files that are not listed. Specifically, it needs these:</p>\n<pre><code>#include &lt;stddef.h&gt;\n#include &lt;stdio....
{ "AcceptedAnswerId": "260118", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-28T10:14:29.953", "Id": "260111", "Score": "6", "Tags": [ "c", "converting", "unit-conversion", "binary" ], "Title": "Bytes to binary conversion function" }
260111
<p>I'm a beginner trying to get a better understanding of golang so I decided to write an atom feeder that runs from the terminal.</p> <p>I am using the <a href="https://github.com/mmcdole/gofeed" rel="nofollow noreferrer">gofeed</a> library to parse the atom feeds and the <a href="https://github.com/rivo/tview" rel="n...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-28T10:42:02.363", "Id": "260113", "Score": "2", "Tags": [ "beginner", "unit-testing", "go", "mocks" ], "Title": "A terminal based atom feed reader written in golang" }
260113
<p>This is my solution to a <a href="https://stackoverflow.com/questions/67266356/caclulate-certificate-chain-from-leaf-and-pool">question I asked on stackoverflow</a>.</p> <p>The scenario is as follows: I got my X509 certificate and a pool of other X509 certificates. Now I want to calculate the chain of trust, startin...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-28T11:07:35.803", "Id": "260115", "Score": "1", "Tags": [ "c++", "qt", "openssl" ], "Title": "Use OpenSSL and Qt to build the correct X509 certificate chain based on a pool and a lea...
260115
<p>In this react component I'm trying to display one message on the screen at a time. This message has a 'bold' substring in it which should be accounted for. There's 2 endpoints here,</p> <ul> <li><p><code>message</code> to retrieve a message, and</p> </li> <li><p><code>bold</code> which retrieves what is bold (with <...
[]
[ { "body": "<p><em>note: this took me longer then I expected and there may be some syntax errors, but contains the general idea</em></p>\n<p>Once your component starts having complex logic, it's a good indication to start breaking it up.</p>\n<p>Here I propose putting your logic in some different files:</p>\n<ul...
{ "AcceptedAnswerId": "260140", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-28T12:53:25.677", "Id": "260120", "Score": "1", "Tags": [ "javascript", "react.js", "api" ], "Title": "Query messages and 'bold' part of a message. Show one query at a time but g...
260120
<h2>Goal</h2> <p>I needed to interact with microcontrollers (<a href="https://en.wikipedia.org/wiki/ESP8266" rel="nofollow noreferrer">ESP8266</a> &amp; <a href="https://en.wikipedia.org/wiki/ESP32" rel="nofollow noreferrer">ESP32</a>) via the Serial interface, so I wrote a small interactive shell with the <a href="htt...
[]
[ { "body": "<h1>#define</h1>\n<p>Don't use <code>#define</code> for constants!</p>\n<pre><code>#define MAX_COMMAND_SIZE 30\n</code></pre>\n<p>should be:</p>\n<pre><code>constexpr size_t MAX_COMMAND_SIZE = 30;\n</code></pre>\n<p>(I have some discussion on this point on a <a href=\"https://www.codeproject.com/Tips...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-28T13:37:53.367", "Id": "260122", "Score": "7", "Tags": [ "c++", "c", "shell", "arduino" ], "Title": "Interactive shell for Arduino" }
260122
<p>I'm new to Haskell, and this is one of the more interesting programs I've made with it so far. I understand there are already solutions to this problem that use much less code, but to me this one seems fairly intuitive. Are there any ways I can improve this code to be more readable or efficient?</p> <pre class="lang...
[]
[ { "body": "<p>Spacing! Separate function definitions with blank lines.</p>\n<p>I'd use <code>a, b, c</code> for type variables and <code>x, y, z</code> for variables.</p>\n<p>A <code>.</code> looks cleaner than a <code>$</code>.</p>\n<pre class=\"lang-hs prettyprint-override\"><code>putStr . unlines . map show ...
{ "AcceptedAnswerId": "260141", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-28T15:15:43.450", "Id": "260125", "Score": "1", "Tags": [ "beginner", "haskell", "reinventing-the-wheel", "fibonacci-sequence" ], "Title": "Generating the N-bonacci numbers" ...
260125
<p>I am trying to build a class similar to <code>std::shared_ptr</code> just to learn and improve my way of thinking. I am hoping that you can tell me if this implementation is correct? If so, how can I improve it?</p> <p>Here is the code:</p> <pre><code>#include &lt;iostream&gt; #include &lt;map&gt; template&lt;typen...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T03:11:24.590", "Id": "513551", "Score": "1", "body": "You know `std::map` isn't thread-safe, right? So you're intentionally only making a single-threaded version of shared_ptr, not trying to get all the lock-free atomics right? Th...
[ { "body": "<p>It will leak memory. Aside from not having move constructor or assignment, a big problem is that the assignment operator does not decrease the count for the assigned to object (&quot;<code>this</code>&quot;, the value on the left of the equals sign). The result is that the memory allocated when <c...
{ "AcceptedAnswerId": "260133", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-28T17:09:36.877", "Id": "260126", "Score": "11", "Tags": [ "c++", "beginner", "reinventing-the-wheel" ], "Title": "A practice shared_ptr implementation" }
260126
<p>Given the classical problem to find triplets that sum to zero in an array. Is my Scala implementation correct and executed in O(N^2)? If yes, why? Can someone make a running time analysis.</p> <p>What other ways could we solve this issue? With duplicated elements and not using the two pointer technique?</p> <pre><co...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T17:23:24.947", "Id": "513624", "Score": "0", "body": "I think the idea behind the algorithm is sound, and very clever - good job. However, I don't think it accounts for multiple instances of the same value. {-3, 1, 1, 2} for example...
[ { "body": "<p>Your solution also works with O(n ^ 2), except you need to cover few cases as mentioned in the comments above.</p>\n<p>A small solution that could make things look neat:</p>\n<p><strong>Efficient <code>O(n ^ 2)</code> ThreeSum Solution In Scala</strong></p>\n<pre><code>object Solution {\n import ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-28T21:29:14.967", "Id": "260132", "Score": "2", "Tags": [ "algorithm", "functional-programming", "scala" ], "Title": "Is My Function to Find Triplets in Scala running in O(N^2)" }
260132
<p>I have some problems with code for my classes. Even though it works correctly, I run out of time for half of the examples. Here's the task (I really did my best trying to translate it):</p> <p>You have a permutation of numbers 1,2,...,n for some n. All consecutive numbers of permutations together create sequence a₁,...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T13:34:52.240", "Id": "513475", "Score": "1", "body": "Not sure whether I understand the problem statement. Will the input always be a permutation of 1..n? (IOW, will every number from 1 to n appear exactly once?)" }, { "Cont...
[ { "body": "<p>There's some straightforward and common C++ problems immediately obvious:</p>\n<ul>\n<li><p><code>using namespace std;</code> - avoid that; it makes your code more fragile. It doesn't even make it shorter!</p>\n</li>\n<li><p>Streaming input without checking. If you use <code>&gt;&gt;</code>, it'...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-28T22:42:04.923", "Id": "260138", "Score": "0", "Tags": [ "c++", "algorithm", "time-limit-exceeded" ], "Title": "Count the number of arithmetic progressions within a sequence" }
260138
<p>I'm trying to solve a problem of how to group name objects. A name has firstName and lastName properties. Need to group the name objects that have identical lastnames and a similar firstName(aka Tom Smith and Thomas Smith should be grouped together). Case doesn't matter. The firstName equivalency is provided by a st...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T22:23:42.490", "Id": "513534", "Score": "0", "body": "Welcome to Code Review! I rolled back your last edit. After getting an answer you are not allowed to change your code anymore. This is to ensure that answers do not get invalidat...
[ { "body": "<p>If you have a simple <code>groupBy</code> function, and group by a string <code>key</code> with format <code>[lastName]|[firstNameKey or firstName]</code>, it'd be cleaner. The following is my version of the code:</p>\n<p><div class=\"snippet\" data-lang=\"js\" data-hide=\"false\" data-console=\"t...
{ "AcceptedAnswerId": "260148", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T02:22:58.577", "Id": "260145", "Score": "1", "Tags": [ "javascript" ], "Title": "Group by lastName and variable firstName" }
260145
<p>As a part of my bash routine I am printing some message in terminal regarding status of the workflow. The message in splited into two parts (part 1: begining of the task, part 2: status of its finishing)</p> <pre><code>echo -n &quot;Dataset is being processed ! &quot;; execution of some AWK script; echo &quot; Proce...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T14:03:23.870", "Id": "513480", "Score": "2", "body": "Micro-review - `printf %s` is more portable than `echo -n`." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T07:35:44.327", "Id": "513564", ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T13:33:09.163", "Id": "260154", "Score": "1", "Tags": [ "bash", "awk" ], "Title": "Printing of status message during execution of the bash script" }
260154
<p>I'm currently working on a grade calculator for a university (professionally), and I am wondering if anyone can suggest an improvement to the following query? Here is my database:</p> <p><a href="https://i.stack.imgur.com/N0Gnw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N0Gnw.png" alt="enter ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T15:12:41.810", "Id": "513486", "Score": "1", "body": "Additionally, you haven't shown the definition of your table(s), without which it's hard to give a good review. I recommend you include these definitions (preferably as SQL stat...
[ { "body": "<p>Minor stuff: your backticks are distracting, and unnecessary in most (all?) cases. I'd delete them.</p>\n<p>Your use of <code>TRUNCATE</code> seems like a formatting concern and not a query concern. I'd expect that a query like this just return a full, floating-point number, and leave it up to the...
{ "AcceptedAnswerId": "260162", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T14:33:59.373", "Id": "260155", "Score": "1", "Tags": [ "sql", "mysql" ], "Title": "Calculate course module credits from individual assessment scores" }
260155
<p>As part of a text buffer implemented as a piece table, there is an often called procedure to flatten a nested list of character lists. The function is part of constructing substrings of the buffer for display, copying, and cutting.</p> <p>I have been using a procedure based on Dan D.'s StackOverflow answer here: <a ...
[]
[ { "body": "<p>So, I started looking at it in a different way, filtering out all <code>'()</code> before flattening. Then I found\n<a href=\"https://stackoverflow.com/a/13333430/193509\">this</a> answer by Óscar López, which is almost exactly what I needed.</p>\n<p>Here's what finally worked:</p>\n<pre><code>;; ...
{ "AcceptedAnswerId": "260199", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T14:58:42.340", "Id": "260156", "Score": "0", "Tags": [ "algorithm", "scheme" ], "Title": "Flattening a List containing Empty Lists" }
260156
<p>This is my custom function to join strings from an array into one string. We can provide normal separator and the last one. <code>JoinStringsIntoArray(&quot;, &quot;, &quot; and &quot;, words...)</code></p> <pre><code>func JoinStringsIntoArray(sep string, lastSep string, words ...string) string { lastElementIndex :=...
[]
[ { "body": "<p>The Go standard library <code>strings</code> package has a <code>Join</code> function:</p>\n<pre><code>func Join(elems []string, sep string) string\n</code></pre>\n<p>Your function is a simple extension of <code>strings.Join</code>:</p>\n<pre><code>func JoinLast(elems []string, sep, lastSep string...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T16:30:29.550", "Id": "260160", "Score": "1", "Tags": [ "strings", "array", "go" ], "Title": "Go Lang custom convert array into string with two separators" }
260160
<p>I've coded this <code>@Stateless</code> session bean:</p> <pre><code>package br.eti.rslemos; import java.util.function.Supplier; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import javax.ejb.TransactionAttributeType; @Stateless public class FunctionalEJB { @TransactionAttribute(Transacti...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T18:42:53.043", "Id": "260163", "Score": "0", "Tags": [ "java" ], "Title": "The Functional Enterprise Java Bean 3" }
260163
<p>I am new in C and I have to do a project which reads data from a <strong>.txt</strong> file and created <em>linked list of structures</em> to different operation on that structures (CRUD). The file contains data of rooms in a hotel and its guests with below pattern:</p> <pre><code>--- 203 1 103.52 # Michal Novak Mal...
[]
[ { "body": "<p>Because you're updating <code>head</code> and <code>gstHead</code> every time you insert Room and Guest, you always get <code>head</code> and <code>gstHead</code> as the last element you've inserted.</p>\n<p>Update <code>head</code> and <code>gstHead</code> only once so that they point head of the...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T19:38:07.840", "Id": "260164", "Score": "0", "Tags": [ "c", "linked-list" ], "Title": "How to have a nested struct as linked list in C?" }
260164
<p>The point is to get the serial number of one of the hard drives on Windows. My code is based on <a href="https://docs.microsoft.com/en-us/windows/win32/wmisdk/example--getting-wmi-data-from-the-local-computer" rel="nofollow noreferrer">an example from MSDN</a>. I tried to make it an exception-safe, self-contained fu...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T22:23:18.680", "Id": "513533", "Score": "0", "body": "good show using `std::unique_ptr` for COM. I've found that most people have not stumbled onto that trick. Good adding RAII to COM VARIENT, but shouldn't that be part of the `CO...
[ { "body": "<pre><code>if (FAILED(hres)) return ::std::nullopt;\nsvc.reset(pSvc);\n</code></pre>\n<p>It bothers me that this is repeated, and more generally, you need boilerplate to <em>use</em> one of the COM Wrappers. Ideally, <code>&amp;svc</code> would return the thing that the COM calls actually wanted. S...
{ "AcceptedAnswerId": "260170", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T20:49:42.103", "Id": "260165", "Score": "2", "Tags": [ "c++", "c++17", "windows", "winapi", "com" ], "Title": "Getting hard-drive serial number on Windows" }
260165
<p>I frequently need to find then remove something from some <code>Vec&lt;&gt;</code> type struct field. Does the following represent an idiomatic approach to doing this?</p> <pre class="lang-rust prettyprint-override"><code>struct Roster{ names: Vec&lt;String&gt; //.. } impl Roster{ pub fn remove_name(&am...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T10:44:34.073", "Id": "513576", "Score": "2", "body": "The question is now answered and thus there's little point in closing it, but your question is skirting the rules a bit. Please take a look at the [help/on-topic] and note we don...
[ { "body": "<p>There is a method that directly does what you want: <a href=\"https://doc.rust-lang.org/std/vec/struct.Vec.html#method.retain\" rel=\"nofollow noreferrer\"><code>Vec::retain</code></a>.</p>\n<pre class=\"lang-rust prettyprint-override\"><code> pub fn remove_name(&amp;mut self, name: &amp;str){\...
{ "AcceptedAnswerId": "260172", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T21:18:34.603", "Id": "260168", "Score": "-2", "Tags": [ "rust" ], "Title": "Idiomatic Approach to Filter Struct Field - Rust" }
260168
<p>Where I have, let us say an object, that I will only use once, what is considered general best practice in terms of declaring it as var vs. simply putting the object directly into the method it will be used in? I'm thinking this is going to come down to &quot;which do you think is more readable&quot;, but given my l...
[]
[ { "body": "<p>In this specific scenario, I would definitely go with your first approach. Putting a large amount of data right in the middle of your logic makes it extremely difficult to follow the logic.</p>\n<p>To answer the general question of &quot;should data associated with a specific function go inside it...
{ "AcceptedAnswerId": "261048", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T22:27:29.563", "Id": "260169", "Score": "0", "Tags": [ "javascript" ], "Title": "Mapping values. Should a single use variable be declared as a variable at all?" }
260169
<p>This is a follow up question to <a href="https://codereview.stackexchange.com/questions/260077/encryption-decryption-algorithm-2">Encryption/Decryption algorithm #2</a> and <a href="https://codereview.stackexchange.com/questions/259814/encryption-decryption-algorithm">Encryption/Decryption algorithm</a>.</p> <p>In m...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-06T20:12:56.540", "Id": "514102", "Score": "0", "body": "The best thing to do with encryption is to not do it yourself. Use a popular package from a reputable source. If you don't trust them - encrypt twice with two different algorithm...
[ { "body": "<blockquote>\n<p>Is that just for type hints?</p>\n</blockquote>\n<p>Correct, everything in the typing module is used for type hints. These are useful when using something like mypy, but the python interpreter will just ignore all of these.</p>\n<blockquote>\n<p>Would it be faster to use numpy arrays...
{ "AcceptedAnswerId": "260405", "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T22:48:18.360", "Id": "260171", "Score": "0", "Tags": [ "python", "reinventing-the-wheel", "cryptography" ], "Title": "Encryption/Decryption algorithm #3" }
260171
<p>This a small project for a beginner, it basically generate symbols digits letters depending on the user input I want to make the code better and learn from my mistakes.</p> <pre><code>import string import random asklenght = 0 asku = int(input(&quot;Please choose a method:\n 1)Digits \n 2)Letters \n 3) Symbols \n 4...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T15:32:20.503", "Id": "513613", "Score": "0", "body": "I don't have any feedback beyond what FMC already said. I built a password generator, if you want something else to reference to https://github.com/adholmgren/password_gen. It's ...
[ { "body": "<p>One of the easiest ways to improve code is to reduce repetition. The\nmost-repeated elements in your code are <code>random.choice</code> and <code>outputpass</code>. You\ncan reduce bulk by importing what you need rather than importing a module containing\nwhat you need.</p>\n<pre><code>from rando...
{ "AcceptedAnswerId": "260176", "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T23:30:10.493", "Id": "260173", "Score": "9", "Tags": [ "python", "beginner" ], "Title": "A password generator" }
260173
<p>I was thinking about this problem where you should <strong>make a function that takes an array and a target value and then it will find all the pair values that sums up to that target value.</strong></p> <p>Of course there is the naive way using nested loops, but I want to avoid the O(n²) time complexity so I have c...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T08:07:50.607", "Id": "513566", "Score": "0", "body": "You're missing a definition of `vector` - is that supposed to be `std::vector`?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T23:05:13.877", ...
[ { "body": "<p>This is a typical LeetCode problem. I would write an O(n) solution as follows:</p>\n<pre><code>#include &lt;unordered_set&gt;\n#include &lt;utility&gt;\n#include &lt;vector&gt;\n\ntemplate &lt;typename T&gt;\nstd::vector&lt;std::pair&lt;T, T&gt;&gt; twoSum(const std::vector&lt;T&gt;&amp; arr, cons...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T00:27:04.420", "Id": "260174", "Score": "-1", "Tags": [ "c++", "algorithm" ], "Title": "Finding all pairs of elements in an array that sum to a target value using multiple pointers" }
260174
<p>So I am pretty new to JavaScript and I thought I might make an animation demonstrating a planet orbiting a sun in an elliptical orbit using Kepler's laws.</p> <p>I am struggling to get the speed right. So I want the speed of the planet to be slower further away from the sun, and faster closer to the sun.</p> <p>Wit...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T03:15:04.270", "Id": "513552", "Score": "0", "body": "Other than looking at applied math, can you be a little more specific about what you want from a review of the code snippet?" }, { "ContentLicense": "CC BY-SA 4.0", "...
[ { "body": "<h2>Review</h2>\n<h3>Orbit</h3>\n<p>You are incorrectly calculating the position of the planet.</p>\n<p>The eccentric anomaly which you attempt to calculate with a linear, integrated 2nd derivative, in the function <code>this.updateTheta</code> will never work as the solution in non linear. That said...
{ "AcceptedAnswerId": "260209", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T02:04:11.293", "Id": "260178", "Score": "2", "Tags": [ "javascript", "canvas" ], "Title": "Javascript speed of an animated object (planet orbiting sun)" }
260178
<p>I got a question:</p> <p>Design a parking system. There are 3 types of parking spaces: big, medium and small.</p> <p>Implement <code>ParkingSystem class(int big, int medium, int small)</code>. Constructor takes a number of places of types. So <code>ParkingSystem(1,2,3)</code> means there are 1 big place, 2 medium an...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T05:24:13.010", "Id": "513554", "Score": "1", "body": "Welcome to Code Review. Do you have testcases with your code?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T06:05:40.100", "Id": "513561", ...
[ { "body": "<h2>this.</h2>\n<p>There's a lot of <code>this.</code> references in your code. Typically in Java you only use <code>this.</code> where you need to in order to disambiguate variables. Consider removing them as they're only adding noise to your code.</p>\n<h2>always True</h2>\n<p>Your <code>park</co...
{ "AcceptedAnswerId": "260189", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T05:16:06.263", "Id": "260181", "Score": "2", "Tags": [ "java", "algorithm", "object-oriented", "design-patterns" ], "Title": "Parking places design" }
260181
<p>I'm hoping to get feedback on my current code from someone more experienced in Django, and in the concepts I'm trying to implement. Let me preface by saying that I am a novice to Django. This is my first time using the framework.</p> <p>Here's the gist of my goals in my project:</p> <ul> <li>Create a web application...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T06:21:26.657", "Id": "260182", "Score": "3", "Tags": [ "python", "beginner", "api", "django" ], "Title": "Logical next step in Django newsfeed web app" }
260182
<p>From searching online I have identified two ways to get the user email, but I don't know if either has pro's/con's beyond Option.1 being a larger number of lines of code?</p> <p><strong>Option.1</strong></p> <p>I have a dedicated <code>ClaimsPrincipalExtension.cs</code> class, which I can call from anywhere in my ap...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T08:12:56.257", "Id": "513567", "Score": "3", "body": "The first option hides the `System.Security.Claims` from the consumer-side, which is good. You can make that function as generic as the second one by parameterizing the `ClaimTyp...
[ { "body": "<p>I frequently write extension methods for IPrincipal and ClaimsPrincipal objects (depending on .NET framework version). Creating an abstraction for a business concept is a good idea, because it centralizes this knowledge (think: Single Source of Truth). If this happens to change in the future, you ...
{ "AcceptedAnswerId": "260196", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T07:21:37.700", "Id": "260183", "Score": "2", "Tags": [ "c#", "security", "asp.net" ], "Title": ".Net 5.0 Get User Email From Claims" }
260183
<p>I am working on a project, the previous programmer used this method to save photos, videos, etc.</p> <pre><code> if (empty($data['large_image'])) { $large_image = $article-&gt;large_image;} else { if ($request-&gt;hasFile('large_image')) { //uploads $cover_img_large = $data['cover_img_large']; //echo '&l...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T14:35:38.357", "Id": "513604", "Score": "0", "body": "Welcome to Code Review! Is the first snippet part of a controller method? could you please [edit] to include more code - e.g. it might help reviewers to know where `$request`, `$...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T08:52:14.660", "Id": "260185", "Score": "3", "Tags": [ "php", "comparative-review", "laravel" ], "Title": "class uploade file(photo,video,..) laravel" }
260185
<p>Small project i made to practice my c++, im a beginner and want to know all about optimizing code.</p> <p>Enemy starts off with 10 HP and we can damage them for 1 HP by pressing F1, If their HP is below their max they regenerate 1 point each second.</p> <pre><code>#include &lt;time.h&gt; #include &lt;Windows.h&gt; #...
[]
[ { "body": "<p>Don't write <code>using namespace std;</code>.</p>\n<p><code>maxHP</code> should be <code>constexpr</code> or at least <code>const</code>. In general, use <code>const</code> where you can.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T09:13:32.533", "Id": "260186", "Score": "1", "Tags": [ "c++", "beginner", "windows" ], "Title": "Enemy damaging with regen system" }
260186
<p>I have a dataset which I divided into two sections horizontally. Column A of first section is the input variable and Column A of second section is the target variable. I am trying to build a Denoising Autoencoder that is trained using the target variable. Column A consists of string values which are one-hot encoded ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T12:06:35.470", "Id": "513585", "Score": "0", "body": "Have you done some testing? Does it seem to work correctly, as far as you can tell? It's worth telling us how you tested, as that can give clues to what you might have overlook...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T09:54:05.417", "Id": "260187", "Score": "0", "Tags": [ "python", "pandas", "machine-learning", "keras" ], "Title": "Keras: Using Autoencoders for prediction" }
260187
<p>I have class structure to read the data from resource bundle (property files).</p> <pre><code>import java.util.Locale; import java.util.Objects; import java.util.ResourceBundle; /** * The class will be used to read the resource bundle to achieve localization * and internationalization * */ public class Resource...
[]
[ { "body": "<p>I don't see the need to implement sub classes in your code example above. You need inheritance only if you add specific implementation on the sub class. All you need is to create an interface to encapsulate the resolver (<code>IResourceBundle</code>) for abstraction, then create a factory for them...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T12:21:00.790", "Id": "260193", "Score": "1", "Tags": [ "java", "inheritance" ], "Title": "Reading data from multiple different resource bundle property files in Java" }
260193
<p>Similar to <a href="https://en.wikipedia.org/wiki/High_Capacity_Color_Barcode" rel="nofollow noreferrer">Microsoft's HCCB</a> before its discontinuation near 2015, Im trying to make a 2D barcode that uses RGB pixels to encode more than two possible states (Black/White).</p> <p>Theoretically, at 100% data capacity, y...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T15:03:23.037", "Id": "513610", "Score": "0", "body": "8 bits per channel is an arbitrary assumption - many printers and monitors support 10 bits or more (not that any more than 5 is likely to be reliably differentiated for data enco...
[ { "body": "<p>This:</p>\n<pre><code>static uint8_t rgb[3];\nreturn rgb;\n</code></pre>\n<p>is a problem. Two different callers assuming to have two different copies of the return array will actually only have one, and that breaks re-entrance. Better off to return by value instead of return by reference in this ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T12:50:24.300", "Id": "260194", "Score": "3", "Tags": [ "c" ], "Title": "Making pixels of RGB barcode suitable for scanning" }
260194
<p>My requirement is to format the input values to a particular format as &quot;##.###/##.###&quot; Example - My input value can have alphabets, alphanumeric, numeric</p> <ol> <li>Expired -- &gt; if alphabet, output as three space</li> <li>2 --&gt; only numeric, add &quot;/&quot; + &quot;0&quot; to format as &quot...
[]
[ { "body": "<p>You don't need to use <code>Regex</code> for this, and your regex doesn't cover most of cases anyway. You can simply splitting the input and try parse them into decimals. If they contains any invalid inputs then return three spaces (<code>&quot; &quot;</code>) otherwise print it in <code>&quot;00...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T13:29:19.073", "Id": "260195", "Score": "2", "Tags": [ "strings", ".net", "regex", "vb.net" ], "Title": "String formatting" }
260195
<p>I wrote a N-dim matrix (tensor) class, based on my previous 2D matrix implementation(<a href="https://codereview.stackexchange.com/questions/253908/2d-matrix-in-c20-and-strassens-algorithm">2D Matrix in C++20 and Strassen&#39;s algorithm</a>), accepting many helpful reviews from here.</p> <p>MatrixBase.h</p> <pre><c...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T15:45:04.573", "Id": "513615", "Score": "1", "body": "It looks like you know what you're doing. My only issue reading it is design comments (lack of): in particular, why is `T` being passed to the base class template? It's like a ...
[ { "body": "<p>This is looking very good. I especially like the improvement of <code>submatrix()</code>. Still, there are a few things I mentioned in my review of the 2D class that I'll repeat here, as well as add a few other remarks.</p>\n<h1>Avoid restricting template types too much</h1>\n<p>I see you are usin...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T13:47:36.013", "Id": "260197", "Score": "7", "Tags": [ "c++", "matrix", "c++20" ], "Title": "C++20 : N-dimensional minimal Matrix class" }
260197
<p>Team, My code: works and does the job. delete partition by unmounting paths if it is not root and is present in defined list in vars.</p> <p>caveat: I have observed that at times some devices are left unmounted and when I rerun task they then get deleted. not sure what is the issue.</p> <p>steps:</p> <ol> <li>loops ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T17:59:37.763", "Id": "260204", "Score": "0", "Tags": [ "ansible" ], "Title": "deleting list of devices using ansible" }
260204
<p>I wrote a program to convert float to it's binary IEEE754 representation in C.</p> <p>Any improvements to this is appreciated</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; void binary(float num) { int n = *(int *) &amp;num; //Evil bit hack from Quake3 Q_sqrt function int size = sizeof(n) ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T15:17:14.840", "Id": "513734", "Score": "0", "body": "try the itoa() function" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-05T18:31:42.463", "Id": "514026", "Score": "0", "body": "C--, is ...
[ { "body": "<h2>IEEE754 conformance</h2>\n<p>Compilers aren't required to support IEEE754 decimals. Most implementations do, but regardless, it's better to check for maximum portability. If you're using C99 or later, the macro <code>__STDC_IEC_559__</code> is defined whenever IEEE754 is supported.</p>\n<hr />\n<...
{ "AcceptedAnswerId": "260207", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T18:28:17.057", "Id": "260206", "Score": "1", "Tags": [ "c", "floating-point", "binary" ], "Title": "Float to binary conversion" }
260206
<p>I am trying to implement 3D Discrete Cosine Transformation calculation in Matlab with parallel computing <code>parfor</code>. The formula of 3D Discrete Cosine Transformation is as follows.</p> <p><img src="https://i.stack.imgur.com/Zq2fb.png" alt="" /></p> <p><strong>The experimental implementation</strong></p> <p>...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-21T01:43:45.297", "Id": "515074", "Score": "1", "body": "I don’t have time to write a full answer, but I’ll leave three short comments: (1) `parfor` is always best used as the outer loop. (2) Vectorize your code. (3) The DCT is separab...
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-30T22:43:28.033", "Id": "260212", "Score": "1", "Tags": [ "performance", "algorithm", "matrix", "matlab" ], "Title": "Parallel 3D Discrete Cosine Transformation Implementation in...
260212
<p>This code returns a string of binary in 4-digit forms for a given hex in the form of string</p> <pre><code>def str_bin_in_4digits(aString): retStr = '' for i in aString: retStr = retStr+&quot;{0:04b}&quot;.format(int(i, 16))+&quot; &quot; return retStr.strip() </code></pre> <p>for example,</p> <p...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-01T06:39:41.683", "Id": "513644", "Score": "0", "body": "this question better fit to portal [stackoverflow.com](https://stackoverflow.com/)" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-01T15:00:44.277", ...
[ { "body": "<p>I don't know if there is faster or less memory consumption method but you can write it more elegant using list</p>\n<pre><code>def str_bin_in_4digits(aString):\n\n data = []\n\n for i in aString:\n data.append( &quot;{0:04b}&quot;.format(int(i, 16)) )\n\n retStr = &quot; &quot;.joi...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-01T04:17:54.807", "Id": "260215", "Score": "4", "Tags": [ "python" ], "Title": "Converting hex to binary in the form of string" }
260215
<p>I have written the below method to replace some of the email domains like <code>@gmail.com</code> and <code>@yahoo.com</code> with a given text.</p> <pre><code>public static string RemovePersonalInfo(string input) { string[] tokens = input.Split(new char[] { ' ', '\t', '\r', '\n' }); string output = string.E...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-01T07:35:51.903", "Id": "513647", "Score": "1", "body": "hi, I'm trying to understand the limitations here. I'm wondering why you use c# if you can't even use basic c#/.net functions? If you want to use the basic programming languages ...
[ { "body": "<ul>\n<li><p>Performance wise using string concatination (<code>output += </code>) inside a loop isn't the best choice because for each <code>output += </code> a new string is created because strings are immutable. Using a <code>StringBuilder</code> would be the way to go. But instead of returning a ...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-01T04:34:35.453", "Id": "260216", "Score": "0", "Tags": [ "c#", "homework", "asp.net", "asp.net-core", ".net-core" ], "Title": "How to replace the given email address with a ...
260216
<p>I am writing a Go package that handles communication with BoltDB as a part of some larger project. I have 2 methods for interacting with DB.</p> <pre><code>func Lookup(path string) (string, bool) {} func RegisterUrl(path, url string) error {} </code></pre> <p>Lookup makes a request to database to retrieve correspond...
[]
[ { "body": "<p>I think the code could benefit a struct for the database instead of global state.\nYou can use a New method instead of init() where you pass in the params, which would differet from test and production.</p>\n<p>I also demonstrated that you can keep the connection open and reuse it within the struc...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-01T06:29:04.980", "Id": "260217", "Score": "1", "Tags": [ "unit-testing", "go", "database" ], "Title": "BoltDB Lookup and Add methods and advice on unit testing" }
260217
<p>I have these 2 version of code. Both are looking for all primes under a certain ceiling value.</p> <p>The first is testing against the set of all odd numbers. The second in testing against the set of all 6k-1 and 6k+1.</p> <p>In theory, the second version should be faster than the first. However the result states ot...
[]
[ { "body": "<p>The difference averages to .2 microseconds per number checked.</p>\n<p>To see if its the inner loop, try unrolling it in the second program:</p>\n<pre><code>...\nfor i in range(5, ceiling+1, 6):\n # test only against factors less than the square root\n # just use the sqrt of the bigger numbe...
{ "AcceptedAnswerId": "260239", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-01T06:40:25.040", "Id": "260218", "Score": "1", "Tags": [ "python", "algorithm", "python-3.x", "primes", "search" ], "Title": "Python Prime Search Slower Optimization" }
260218
<p>I got my code working with vanilla JavaScript, however I'm new to JS, so I don't know if the code is robust or not. Any advice to improve the code is welcome.</p> <p><strong>Note:</strong> I just noticed a bug. The code removes the image from the DOM (is it the right term?) but it still submits the images that I del...
[]
[ { "body": "<p>Welcome to Code Review! Good on you for opening up to constructive criticism.</p>\n<p>Buckle up, this will be a long one ;)</p>\n<hr />\n<h1> The Question</h1>\n<p>Let us start with your question:</p>\n<blockquote>\n<p>[...] I don't know if the code is robust or not. Any advice to improve the code...
{ "AcceptedAnswerId": "260300", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-01T11:33:54.693", "Id": "260224", "Score": "2", "Tags": [ "javascript" ], "Title": "File uploads with image previews and remove link using Array and readAsDataURL" }
260224
<p>I'm practicing saving and reading serializable objects when a friend told me serializable objects have no use in real life, that I'd better focus on JSON or XML to serialize my objects when I came across this situation:</p> <p>I want to preload some FileFilters to use them in a JFileChooser dialog and I want these F...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T04:03:13.397", "Id": "513697", "Score": "2", "body": "I don't think you are really asking for a code review. Rather, I think this is a general question about 1) whether serialization of lambdas presents a security issue, and 2) if ...
[ { "body": "<p>I'm going to answer my own question. Never do this!. I have just tried saving a new Filefilter object with this filter:</p>\n<pre><code>.addFilter(&quot;Delete files, Delete all files&quot;,f-&gt;f.delete());\n</code></pre>\n<p>And when selected, it deletes all the files in the current directory....
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-01T17:52:39.940", "Id": "260228", "Score": "0", "Tags": [ "java", "swing", "lambda" ], "Title": "Correct use of Serializable with lambda functions" }
260228
<p>I am new to c# and decided to write a classic todo app. The implementation of my application now is like this: there is a Task class that describes the task. The List class acts simultaneously as a storage and has methods for creating, deleting, and displaying tasks. How good is this approach, how can you do better ...
[]
[ { "body": "<p>As a very basic application this is fine, however, if the program becomes more complicated and you want to add a data base and asynchronous programming you will run into conflicts with some of the class names. For instance the Task class is supplied by the C# library for <a href=\"https://docs.mic...
{ "AcceptedAnswerId": "260236", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-01T20:27:33.293", "Id": "260232", "Score": "1", "Tags": [ "c#" ], "Title": "Todo application implementation" }
260232
<p>In order to help with learning C++, I have been re-implementing games from old ZX80 books in C++. Here' the description of one I'm currently working on:</p> <blockquote> <p>You are a starship captain. You have crashed your ship on a strange planet and must take off again quickly in the alien ship you have captured. ...
[]
[ { "body": "<h1>Define simple member functions in the header files</h1>\n<p>If you define member functions inside the class definition, they can be inlined by the compiler. For simple functions, like <code>CountDown::is_finished()</code>, this will generate much more efficient code, even on a Z80.</p>\n<h1>Unnec...
{ "AcceptedAnswerId": "260259", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-01T20:38:16.223", "Id": "260233", "Score": "4", "Tags": [ "c++", "game" ], "Title": "ZX80 game in C++" }
260233
<p>Is there a way to simplify my code underneath? Basically I'm drawing a series of rectangles against each other on a mouse dragged event. The negative numbers are read from a 2D array in an other class (Board). I'm using positive numbers for dots (you need to connect dots with beams/blocks) also in an other class. Th...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-01T23:17:47.383", "Id": "513685", "Score": "0", "body": "you can put the code that different between cases in the case statement (in this case the set color part). And put the rest of the code after the switch. Don't forget to filter t...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-01T20:42:25.057", "Id": "260234", "Score": "1", "Tags": [ "javafx" ], "Title": "Reduce repetition of code for drawing on a canvas in JavaFx" }
260234
<p>I am building an application that needs to load 100-200 images (really only limited by performance) and display them to the user in a sort of gallery. A good analogy would simply be Google Images. In a linear implementation loading 100 images takes roughly 3-6 seconds, during which the GUI is frozen. I tried offload...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-04T22:09:32.747", "Id": "513954", "Score": "0", "body": "I am using 3 instances of the ImageManager in an app and realized that I am spawning like 15 subprocesses, which seems excessive. So I added a timeout to the processes similar to...
[]
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-01T21:06:51.580", "Id": "260235", "Score": "4", "Tags": [ "python", "multithreading", "concurrency", "multiprocessing", "pyqt" ], "Title": "PyQt load images in background pro...
260235
<pre><code>public (List&lt;Order&gt;, Dictionary&lt;int, string&gt;, Dictionary&lt;int, string&gt;) GetOrders(int RestaurantID, int StartID) { List&lt;Order&gt; Orders = null; Dictionary&lt;int, string&gt; MenuItemsXml = null; Dictionary&lt;int, string&gt; OrderHistoryXml = null; str...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T19:24:52.983", "Id": "513751", "Score": "1", "body": "I don't know what your database looks like but I suspect that the timeouts are caused by the table structure and a SQL statement that is possibly overcomplex. You have joins, one...
[ { "body": "<p>Quick remarks:</p>\n<ul>\n<li><p>Please follow the <a href=\"https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/naming-guidelines\" rel=\"nofollow noreferrer\">Microsoft naming guidelines</a>. Parameters should be camelcase, same with local variables.</p>\n</li>\n<li><p>Don't write...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-01T22:53:38.203", "Id": "260237", "Score": "3", "Tags": [ "c#", "sql-server", "connection-pool" ], "Title": "Retrieving restaurant orders from SQL Server" }
260237
<p>I was trying to attempt below given challenge. I tried multiple ways to solve the problem but none of them were good enough to pass the time limit. Please advise if you have any idea to improve on this.</p> <p><strong>Problem:</strong> You are visiting a building of N floors. On every floor, only one ladder of speci...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-04T08:22:11.437", "Id": "513872", "Score": "0", "body": "The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to **simply sta...
[ { "body": "<p>I was finally able to reduce it enough to return result for 1 million inputs in around 10 secs.</p>\n<pre><code>class Program\n{\n static void Main(string[] args)\n {\n int T = Convert.ToInt32(Console.ReadLine());\n StringBuilder sb = new StringBuilder(&quot;&quot;);\n f...
{ "AcceptedAnswerId": "260255", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T04:45:38.830", "Id": "260242", "Score": "1", "Tags": [ "c#", "algorithm", "programming-challenge", "dynamic-programming" ], "Title": "I want reduce the time complexity for...
260242
<p>I wrote a brute-force attack on passwords using video cards for any algorithms with a 32-bit block and a 64-bit key, the password is only in BCD format, in the kernel source code the TEA algorithm, the project is written in c ++ builder 10.4, on a Radeon RX560 video card, a full brute-force attack from 0000000000000...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T08:11:54.887", "Id": "260247", "Score": "1", "Tags": [ "c++", "opencl" ], "Title": "brute force algorithm keys with 32bit block and 64bit key using OpenCL" }
260247
<p>I made a simple simulation of a falling ball. Is it possible to somehow improve or optimize this code? What tips can you give for development?</p> <pre><code>#include &lt;iostream&gt; #include &lt;cstdlib&gt; #include &lt;cmath&gt; using namespace std; int timeFallingBall() { static int time(0); return ++ti...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T11:19:10.283", "Id": "513717", "Score": "5", "body": "Note that the time it takes for a ball to hit the ground can be calculated exactly: `t = std::sqrt(2 * h / g)`." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate"...
[ { "body": "<ul>\n<li><p><code>using namespace std;</code> is a bad habit to get into, as it can lead to name-collisions and other issues. It's best to explicitly qualify the names we need where necessary, e.g. <code>std::cout</code>.</p>\n</li>\n<li><p>A few more line-breaks would be useful in the code. Think o...
{ "AcceptedAnswerId": "260250", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T09:02:26.117", "Id": "260249", "Score": "8", "Tags": [ "c++", "beginner", "physics" ], "Title": "Simulation of a falling ball" }
260249
<p>I tried to add Dijkstra's algorithm to a js game. First when I got it working it was very very Laggy (5-10 fps) and the browser would crash.. After adding a lot more improvements I got it to like 50-60 fps with 200 tiles (see GRID_SPREADING in script bellow). When I turn off this algorithm I have 120-144 fps, but I ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T13:15:35.463", "Id": "513719", "Score": "0", "body": "There is too much missing from the code to do a meaningful review. Variables `doPathfind, nearestEnemy, enemyMovedPath, realPgrids, pgrids, builds` and functions `sleep, dist4, c...
[ { "body": "<p>As most of the detail needed to workout what is going on, is missing, (See my comment on question) one can only review what one can see.</p>\n<p>Your request to resolve laggy code is impossible to address without makes a lot of guesses.</p>\n<h2>Bugs.</h2>\n<p>There is no path through the function...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T10:45:49.583", "Id": "260252", "Score": "1", "Tags": [ "javascript", "performance" ], "Title": "Dijkstra's algorithm is slow. (For loops)" }
260252
<p>Given an array arr[] of integers of size N that might contain duplicates, the task is to find all possible unique subsets.</p> <p>Link to the judge: <a href="https://practice.geeksforgeeks.org/problems/subsets-1587115621/1#" rel="nofollow noreferrer">LINK</a></p> <p>Note: Each subset should be sorted.</p> <p><strong...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-04T19:59:24.507", "Id": "513938", "Score": "0", "body": "It's more like your algorithm is O(2^N * N^2)" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-05T12:12:49.553", "Id": "513994", "Score": "0",...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T11:00:58.260", "Id": "260253", "Score": "1", "Tags": [ "python", "algorithm", "python-3.x", "bitwise" ], "Title": "Generating Unique Subsets using Bitmasking" }
260253
<p>To get some practice with the Windows API and <code>ctypes</code>, I decided to write a program capable of injecting and running shellcode inside of another specified process.</p> <p>An example:</p> <pre><code>C:\Users\Admin\Desktop&gt;python inject.py -n explorer.exe -s shellcode.txt Remote memory address: 0x40a000...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T14:46:43.377", "Id": "513730", "Score": "0", "body": "Thanks for the reminder that `next` accepts a default argument - that's handy" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T15:05:14.330", "...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T13:54:34.857", "Id": "260257", "Score": "4", "Tags": [ "python", "python-3.x", "windows" ], "Title": "Process Injector using ctypes and the Windows API" }
260257
<p>Is there any room for improvements in this code. I am new to programming (python3), learning and practicing functions related to arguments recently.</p> <pre><code>def make_pizza(*toppings, **pizza_info): &quot;&quot;&quot;Creating a dictionary for pizza information&quot;&quot;&quot; pizza = {} pizza_t...
[]
[ { "body": "<p>You can use standard copy functions instead of manually copying:</p>\n<pre><code>from copy import copy\n\ndef make_pizza(*toppings, **pizza_info):\n pizza = pizza_info.copy()\n pizza['toppings'] = copy(toppings) \n return pizza\n</code></pre>\n<p>And maybe use a dict-comprehension for ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T14:27:43.980", "Id": "260258", "Score": "2", "Tags": [ "python", "python-3.x" ], "Title": "Pizza ordering system" }
260258
<p>I've started learning Clojure a few days ago and I wrote this code that factorises numbers. How do I make it better? Is there any way to avoid doing it with a loop? Is that how I am supposed to code in Clojure?</p> <pre><code>(defn classify [n] (loop [n n i 2 f []] (cond (= n i) (conj f...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T17:35:02.847", "Id": "513747", "Score": "0", "body": "This is functional. `loop` is the functional way to \"loop\" in Clojure. `doseq` for example would be the \"bad\", imperative way of doing things." } ]
[ { "body": "<p>Maybe a slightly more functional way to express your algorithm is ...</p>\n<pre><code>(defn classify [n]\n (letfn [(factors-from [i from]\n (cond\n (= i 1) '()\n (zero? (mod i from)) (cons from (factors-from (quot i from) from))\n :else (recur i (...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T16:37:59.563", "Id": "260266", "Score": "-1", "Tags": [ "functional-programming", "clojure" ], "Title": "Factorise numbers" }
260266
<p><strong>Hey Guys</strong>,<br> I'm in the process of building a console program in C ++ that allows users to:</p> <ul> <li>sort a sequence of numbers loaded from a TXT file</li> <li>save sorted sequence in a new TXT file</li> <li>measure the sorting time for individual algorithm</li> </ul> <p>I decided to write such...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T22:08:59.960", "Id": "513759", "Score": "0", "body": "What is \"Incredibly Precise\" about this?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T23:45:47.017", "Id": "513768", "Score": "2", ...
[ { "body": "<h1>Questions (+ design review)</h1>\n<h2>Could anyone do some little code review please?</h2>\n<p>The biggest issue I see with your current design is that you are using <a href=\"https://en.wikipedia.org/wiki/God_object\" rel=\"noreferrer\">the “god object” anti-pattern</a>. Your <code>Sorter</code>...
{ "AcceptedAnswerId": "260277", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T18:17:04.483", "Id": "260268", "Score": "2", "Tags": [ "c++", "algorithm", "sorting" ], "Title": "C++ Incredibly Precise Sorter | Efficiency and speed of sorting algorithms" }
260268
<p>I have some python scripts to run on different computers. To avoid struggles with different paths and filenames I made specific config-files (DConfig, AConfig and MConfig) and another script that decides which config to use. It works, but I guess, there are better ways to do this. Any ideas?</p> <pre><code>import os...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T21:56:05.590", "Id": "513757", "Score": "0", "body": "`dirData` etc. are used by other scripts importing this config files." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-03T02:15:19.093", "Id": "51...
[ { "body": "<p>You have a value (<code>hostname</code> in this case) that you want to use to select among\nvarious data choices (config modules in this case). When you have situations\nlike this, use a data structure. <strong>Sensible\ndata is always simpler than logic</strong>. For example, see <a href=\"https:...
{ "AcceptedAnswerId": "260275", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T19:58:34.833", "Id": "260270", "Score": "3", "Tags": [ "python", "python-3.x" ], "Title": "Managing configs to use scripts on different computers" }
260270
<p>My bash script mounts two VeraCrypt volumes, rsyncs their contents, and dismounts them. The script takes two parameters, the path for both the source and backup veracrypt volumes. I wrote this script so rsync wouldn't have to copy an entire volume if there was a single change in it.</p> <p>This is my second time wit...
[]
[ { "body": "<p>Some suggestions:</p>\n<ul>\n<li><code>#!/usr/bin/env bash</code> is a more portable <a href=\"https://stackoverflow.com/a/10383546/96588\">shebang line</a>.</li>\n<li><code>function prepare_volumes_for_exit()</code> can be simplified to <code>prepare_volumes_for_exit()</code>.</li>\n<li>Using <co...
{ "AcceptedAnswerId": "260279", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-02T21:27:41.687", "Id": "260274", "Score": "1", "Tags": [ "bash", "linux" ], "Title": "Bash script for mounting and backing up VeraCrypt volumes" }
260274
<p>I'm learning sorting algorithms and wrote my own implementation of <a href="https://en.wikipedia.org/wiki/Insertion_sort" rel="nofollow noreferrer">Insertion Sort</a>. Is it optimal? Is there anything that can be done better?</p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;algorithm&gt;...
[]
[ { "body": "<p>Your <code>insertionSort()</code> is OK, but I would write:</p>\n<pre><code>template&lt;std::forward_iterator Iter&gt;\nvoid insertion_sort(Iter first, Iter last) {\n for (Iter it = first; it != last; ++it)\n std::rotate(std::upper_bound(first, it, *it), it, std::next(it));\n}\n\ninserti...
{ "AcceptedAnswerId": "260311", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-03T02:56:25.980", "Id": "260280", "Score": "0", "Tags": [ "c++", "sorting", "insertion-sort" ], "Title": "Is my Insertion Sort optimal?" }
260280
<p>The previous question was not clear enough so I will try to clarify it more in this follow-up question.<br /> <strong>I tried the multiple pointers technique to solve the problem that find pair of values that sums up to a target value.</strong></p> <blockquote> <p><strong>We are assuming that:</strong></p> <ul> <li>...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-03T05:37:37.777", "Id": "513781", "Score": "0", "body": "Does this answer your question? [Finding all pairs of elements in an array that sum to a target value using multiple pointers](https://codereview.stackexchange.com/questions/2601...
[ { "body": "<h2><code>using namespace std;</code></h2>\n<p>There are lot of good answers why you shouldn't use it. <a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\">See here</a></p>\n<hr />\n<h2>Use <code>std::pair&lt;int, int&gt;</code></h2>\n<p>Since you...
{ "AcceptedAnswerId": "260293", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-03T03:35:42.637", "Id": "260282", "Score": "0", "Tags": [ "c++", "algorithm" ], "Title": "Finding all pairs of elements in an array that sum to a target value using multiple pointers...
260282
<p>I want to optimize this for loop for correcting coordinates of an image, it takes too long which is not suited for my system. I have done some profiling, the numpy roots is taking most of the time (near to 90%). Could someone suggest some optimization or vectorization of the code? Or a better alternative?</p> <pre><...
[]
[ { "body": "<p>This is more of a suggestion as I don't have the time to code it, but it is perhaps too long for a comment.</p>\n<p>From your code it seems that it is assumed that this fifth degree polynomial has only a single real root. It must have one, because the complex ones must come in conjugate pairs, but...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-03T08:24:00.283", "Id": "260285", "Score": "1", "Tags": [ "python", "performance", "image", "vectorization" ], "Title": "Correcting coordinates of an image with polynomial root i...
260285
<p>I decided to not use heap in my program and create a custom memory manager to retrieve memory chunks from a big global array of uint8_t(u8). I chose u8 since 8 bits is a byte. The very big MEMORY_BLOCK_SIZE is not a problem since in Release builds the compiler will remove the unused bytes. I keep track of free memor...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-03T21:55:19.647", "Id": "513837", "Score": "0", "body": "in the `request` function, shouldn't it be `if(lookups && sizes)` rather than `if(!lookups && sizes)`" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05...
[ { "body": "<p>Please, please, don't rename NULL, uint8_t and uint64_t. It makes your code super hard to read. If you really don't want to type all that out then do a find replace after you're done coding.</p>\n<p>Well aware that checking if(!x) is the same as if(x == NULL) and if(x == 0). But ultimately, I have...
{ "AcceptedAnswerId": "260370", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-03T08:28:04.773", "Id": "260287", "Score": "0", "Tags": [ "performance", "c", "memory-management", "memory-optimization" ], "Title": "Fixed memory manager in C" }
260287
<p><b>Background:</b></p> <p>This is supposed to be the sole worker thread to carry out long-lasting jobs in a GUI application. The GUI thread should be able to schedule tasks in a non-blocking manner and the tasks should que-up until the thread gets around executing them. I tried my best to make it exception safe.</p>...
[]
[ { "body": "<h1>Remove redundant comments</h1>\n<p>You added a lot of comments to the code, but many of them are not very useful. Comments should be used to explain what the code does if this is not clear from reading the code itself. But for example:</p>\n<pre><code>std::queue&lt;Task&gt; _toDo;\n</code></pre>\...
{ "AcceptedAnswerId": "260314", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-03T10:02:39.280", "Id": "260291", "Score": "3", "Tags": [ "c++", "multithreading", "c++17" ], "Title": "Asynchronous dispatch queue" }
260291
<p>I am using <code>psycopg2</code> &amp; <code>sqlalchemy</code> to connect to a database and extract information from a table as follows:</p> <pre><code>def db_connection(): eng = db.create_engine('my_URI') conn = eng.connect() return eng, conn def table_conn(): engine, connection = db_co...
[]
[ { "body": "<p>You should avoid doing <code>[0]</code> after your query. Instead, add a <code>.limit(1)</code> at the end of your <code>select</code>.</p>\n<p>SQA supports named column references on individual result tuples. So in addition to supporting <code>[5]</code>, which is (as you've identified) a bad ide...
{ "AcceptedAnswerId": "260306", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-03T11:05:32.043", "Id": "260296", "Score": "1", "Tags": [ "python", "python-3.x", "sqlalchemy" ], "Title": "Filtering data from an exisiting table using psycopg2+sqlalchemy" }
260296
<p>The following code generates a report showing performance of clan members in a game called Clash Royale. Everything is pretty self-explanatory, we are working with a lot of https requests, arrays and sorting.</p> <pre class="lang-js prettyprint-override"><code>const https = require(&quot;https&quot;); const clanTag ...
[]
[ { "body": "<p>Cool project!</p>\n<p>Good work so far.</p>\n<p>Clean code is important and that's one of the things I struggle with. A lot.</p>\n<p>From your code, I can see that you would benefit a lot from that too.</p>\n<pre><code>const token = &quot;TOKEN_HERE&quot;;\n</code></pre>\n<p>Tokens and sensitive i...
{ "AcceptedAnswerId": "260304", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-03T11:17:08.767", "Id": "260297", "Score": "2", "Tags": [ "javascript", "performance", "array", "sorting", "node.js" ], "Title": "Generating a performance report for clan...
260297
<p>This is a fairly standard project based on Jekyll/Liquid. I'm trying to iterate over data object to include pages with different variables.</p> <p>And since <code>{% include %}</code> and <code>%{ include_relative }%</code> tags are not permissive in terms of different symbols. This approach doesn't work:</p> <p><c...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-03T12:00:27.927", "Id": "260298", "Score": "1", "Tags": [ "jekyll", "liquid" ], "Title": "iterating over json object in Jekyll to render pages with different variables" }
260298
<pre><code>from itertools import permutations def next_bigger(n): nlist = list(str(n)) perm = permutations(nlist,len(str(n))) perm = set(perm) listofperm = [] nlist = int(&quot;&quot;.join(nlist)) for x in perm: form = int(&quot;&quot;.join(x)) if form &lt; nlist: con...
[]
[ { "body": "<p>It's not so much the implementation.</p>\n<p>With problems like these (typical coding competition ones) it's always the same, that you have to find a clever algorithm instead of writing down as code a straightforward implementation of the problem description.</p>\n<p>I haven't myself analyzed the ...
{ "AcceptedAnswerId": "260307", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-03T12:21:28.260", "Id": "260299", "Score": "0", "Tags": [ "python", "algorithm", "time-limit-exceeded", "combinatorics" ], "Title": "Get the next bigger number by rearranging...
260299
<p>My question arises from <a href="https://math.stackexchange.com/questions/4122113/finding-the-top-sums-of-values-from-multiple-lists">this post</a> on MSE where I have provided an answer to solve the question :</p> <blockquote> <p>There are multiple lists given. The number of lists is arbitrary. Each list contains n...
[]
[ { "body": "<p>I have written a new solution to the problem based on the same principles of the code in my question, but this time using a dictionary with keys equal to the seen sums and the indices as values. This is better because I don't need to sort anything, while in the other solution I need to sort every ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-03T16:19:17.567", "Id": "260310", "Score": "0", "Tags": [ "python", "performance", "algorithm", "complexity" ], "Title": "Finding unique top sums from multiple lists" }
260310
<p>I've been teaching myself Python and decided to make a Tic Tac Toe game for a bit of practice. Any criticisms or pointers are welcome!</p> <pre><code>class TicTacToe: &quot;&quot;&quot;A class for playing tic tac toe&quot;&quot;&quot; def __init__(self): self.values = [&quot;-&quot;, &quot;-&quot;, &quot;-&...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-03T20:43:11.960", "Id": "513829", "Score": "2", "body": "have you missed a `else: return false` in `winner()` ? Relying on the null value is perhaps not advisable" } ]
[ { "body": "<h1>Visuals</h1>\n<p>You can try</p>\n<pre><code>self.values = [[&quot;-&quot; for _ in range(3)] for _ in range(3)]\n</code></pre>\n<p>This will let you set up a 3x3 grid without having to draw the whole thing.</p>\n<p>Now you can also do</p>\n<pre><code> def show_board(self):\n board_str ...
{ "AcceptedAnswerId": "260315", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-03T16:38:31.987", "Id": "260312", "Score": "7", "Tags": [ "python", "beginner", "game", "tic-tac-toe" ], "Title": "A beginner's first Tic Tac Toe implementation" }
260312
<ol> <li>Given an array of unique numbers find the combinations</li> <li>Doing a shallow copy in the code to avoid changes to the passed obj by reference</li> <li>This has a run time of <span class="math-container">\$O(n \times \text{#ofcombinations})\$</span> - can this be done better -- iteratively and easy to unders...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-08T16:35:36.103", "Id": "514200", "Score": "0", "body": "Step 2 says \"Doing a deep copy...\", but `copy.copy()` does a shallow copy, which is fine in this case." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021...
[ { "body": "<p>First, a side note. What you call <code>combination</code> is usually called <code>subset</code>.</p>\n<p>In a set of <span class=\"math-container\">\\$n\\$</span> elements an average length of a subset is <span class=\"math-container\">\\$\\dfrac{n}{2}\\$</span>. That is, generating a single subs...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-03T22:29:56.697", "Id": "260318", "Score": "7", "Tags": [ "python", "python-3.x" ], "Title": "Generate combinations of a given sequence without recursion" }
260318
<p><strong>The Problem</strong></p> <p>I am trying to determine numerically how many possible ways a number of books can be arranged on a shelf. Specifically, there are x3 categories &quot;<em>physics</em>&quot;, &quot;<em>sci-fi</em>&quot;, and &quot;<em>travel</em>&quot;. Each contains <code>N_phys</code>, <code>N_sc...
[]
[ { "body": "<p>I don't really understand your question. So I'll take things to the extreme and assume there are n1 books, n2 categories, n3 super categories... etc.</p>\n<p>This whole hierarchy can be represented as a rooted tree, and the number of valid permutations would be the number of postorder traversals o...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-03T23:37:40.113", "Id": "260320", "Score": "4", "Tags": [ "array", "random", "simulation", "matlab" ], "Title": "Finding number of possible arrangements of books on a shelf with ...
260320
<p>I am relearning data structures while trying to implement them on my own while also trying to get better at C++ as although I have knowledge of C, OOP is still non-inituitive to me.</p> <p>In this simple Vector implementation, I double the array size if it becomes equal to the capacity and half it when it becomes le...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-04T05:07:14.940", "Id": "513850", "Score": "0", "body": "Wow, I just found out that std::vector also has insert and erase methods. What an ineffective methods they are. Consider the example from cpp reference - erase odd numbers from v...
[ { "body": "<pre><code>const int MIN_CAPACITY = 16;\nconst int GROWTH_FACTOR = 2;\nconst int SHRINK_FACTOR = 4;\n</code></pre>\n<p>these should be part of the class, not global variables that affect everything and pollute the namespace when your header is included.</p>\n<p>And use <code>constexpr</code> now.</p>...
{ "AcceptedAnswerId": "260344", "CommentCount": "9", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-04T03:54:45.563", "Id": "260324", "Score": "4", "Tags": [ "c++", "beginner", "vectors" ], "Title": "Custom Vector Implementation in C++" }
260324
<p>In this source code, i have writena program, using for loops, to print an english ruler whose length is given by the user. So what i want to know is that is it possible to modify this program, to print the ruler in a more logical way And if so, how can it be done, without applying reculsions ?</p> <p>This is the pro...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-04T07:57:46.373", "Id": "513867", "Score": "1", "body": "@aghast Please do not edit code in the question. Reviewers can comment on any aspect of the code including whitespace. By editing the code you can either give reviewer more point...
[ { "body": "<p>The task you are solving is quite simple. So I don't think there's any great change possible. Here are a few things:</p>\n<ol>\n<li><p>You might want to consider accepting command-line parameters (<code>argc</code> and <code>argv</code>) to determine the number of dashes and the dash height.</p>\n...
{ "AcceptedAnswerId": "260357", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-04T04:50:16.163", "Id": "260325", "Score": "1", "Tags": [ "c" ], "Title": "C program to print a vertical english ruler whose length is given by the user" }
260325
<p>I have some code that populate <code>EventfulConcurrentQueue</code> which is <code>ConcurrentQueue</code>. So I need to save all data from <code>EventfulConcurrentQueue</code> to a database.</p> <p>I think to use sort of multithreading model in order to dequeue items. So <code>EventfulConcurrentQueue</code> should...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-04T08:00:43.000", "Id": "513868", "Score": "1", "body": "Could you please format your code?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-04T08:29:06.370", "Id": "513875", "Score": "1", "body"...
[ { "body": "<p>I think the <code>EventfulConcurrentQueue</code> was not designed for this use case.</p>\n<p>From the consumer perspective:</p>\n<ul>\n<li>Things that are not in use\n<ul>\n<li><code>IsEmpty</code></li>\n<li><code>Enqueue</code></li>\n<li><code>ItemEnqueued</code></li>\n<li><code>ItemDequeued</cod...
{ "AcceptedAnswerId": "260332", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-04T07:38:27.330", "Id": "260326", "Score": "2", "Tags": [ "c#", "multithreading", "queue" ], "Title": "The multithreading model to clean ConcurrentQueue in C#" }
260326
<p>I am learning Python and I wrote a functional breadth-first search algorithm which I wanted to be as general as possible. I wrote some code to draw a grid and visually show the path found.</p> <p>My code will tell you about my coding abilities so please bear that in mind when providing any feedback; either way I wil...
[]
[ { "body": "<p>The app is pleasantly functional! I was not able to find any bugs. Improvements are a mix of aesthetic, organizational and best-practices.</p>\n<p>You seem not to use these at all:</p>\n<pre><code>from pygame.locals import *\nfrom collections import namedtuple\n</code></pre>\n<p>so delete them.</p...
{ "AcceptedAnswerId": "260351", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-04T07:52:56.547", "Id": "260329", "Score": "4", "Tags": [ "python" ], "Title": "Is my breadth-first search function any good? (Python demo included!)" }
260329
<p>My question is have i gotten the three-layered architecture right with error handling etc. I have a webpage containing different resources. The code works but I am not sure if have structured it correct.</p> <p>This is a function located in the BLL</p> <pre><code>createPost: function (accountId, title, body, callbac...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-04T12:17:38.940", "Id": "513888", "Score": "0", "body": "Welcome to Code Review. I edited your javascript snippets, please include the javascript framework you are using if there is one with the corresponding tag." } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-04T09:43:25.113", "Id": "260331", "Score": "2", "Tags": [ "javascript", "node.js", "mvc", "express.js" ], "Title": "Right structure, three-layered architecture webdevelopment" }
260331
<p>I'm learning competitive programming and came across this question on LeetCode : <a href="https://leetcode.com/problems/knight-probability-in-chessboard/" rel="nofollow noreferrer">688. Knight Probability in Chessboard</a></p> <blockquote> <p>On an n x n chessboard, a knight starts at the cell (row, column) and atte...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-04T23:30:54.750", "Id": "513956", "Score": "1", "body": "At a high level, the linked answer is faster than yours because of `@functools.lru_cache` -- in other words, [memoization](https://en.wikipedia.org/wiki/Memoization). During the ...
[ { "body": "<p>Both answers basically try all k-length paths and count the number of paths that remain on the board compared to all possible paths.</p>\n<p>A major difference between your answer and the recursive solution you link to is what is cached (i.e., memoized). You code caches the possible moves from a ...
{ "AcceptedAnswerId": "260361", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-04T10:55:08.710", "Id": "260333", "Score": "4", "Tags": [ "python", "programming-challenge", "time-limit-exceeded" ], "Title": "Calculate probability that knight does not attempt...
260333
<p>I made this over the course of a week and a half, to use it for some Project Euler problems. My goal was to make something relatively efficient that could be used as easily as a builtin type. I also tried to make the code fully portable.</p> <p>I used c++20 because of the spaceship operator, implicit comparisons and...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-04T12:27:45.280", "Id": "513890", "Score": "1", "body": "If you use C++20 then write it with modules instead of a header." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-04T12:31:40.953", "Id": "513891"...
[ { "body": "<pre><code> if(a.negative!=b.negative){\n return false;\n }\n return std::equal(a.container.begin(),a.container.end(),b.container.begin(),b.container.end());\n}\n</code></pre>\n<p>For the last line, doesn't <code>vector</code>'s <code>operator==</code> do what you need?</p>\n<p>So you...
{ "AcceptedAnswerId": "260350", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-05-04T12:10:28.790", "Id": "260335", "Score": "6", "Tags": [ "c++", "beginner", "c++20", "bigint" ], "Title": "Header only bigint library written in c++20" }
260335