body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>Implementation of a Caesar cipher is a popular exercise and there are <a href="/questions/tagged/caesar-cipher%20c%2b%2b">many implementations</a> posted here on Code Review.</p> <p>My version is intended to be efficient and portable (subject to some limitations, below).</p> <hr /> <pre><code>#include &lt;algorithm&...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-30T12:24:20.620", "Id": "531789", "Score": "0", "body": "An answer that improves any one of the \"ugly\" things is very welcome (even if it's just confirmation that the code functions correctly using EBCDIC)." } ]
[ { "body": "<h1>Avoid macros</h1>\n<p>There is absolutely no need for a macro here. Just write:</p>\n<pre><code>static const char *letters = &quot;abcdefghijklmnopqrstuvwxyz&quot;;\nauto alpha = reinterpret_cast&lt;const unsigned char *&gt;(letters);\n</code></pre>\n<p>And to access it safely:</p>\n<pre><code>ta...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-30T12:00:02.097", "Id": "269544", "Score": "4", "Tags": [ "c++", "caesar-cipher" ], "Title": "Portable and efficient Caesar cipher" }
269544
<p>I am trying to build a personal content aggregator and I started off with Reddit.<br /> My aim is to build something that is designed properly for this task so that I could add more sources and delivery options easily.</p> <p>If possible, I'd like you to focus your reviews on the design of the code (any other feedba...
[]
[ { "body": "<p>Your class tree is kind of scrambled. It doesn't make sense to have an abstract <code>connect</code> - not all sources will need connection, and any connection can just happen in the constructor.</p>\n<p><code>RedditSource.connect</code> is confused because it both sets a member - when best practi...
{ "AcceptedAnswerId": "269779", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-30T12:12:23.433", "Id": "269545", "Score": "0", "Tags": [ "python", "reddit" ], "Title": "Content aggregator with Python" }
269545
<p>first time posting here, as well as being new to coding in Java. I am trying to create a movie queue with an array that is able to contain 100 elements, but will only read and print the elements the user enters. I got the first section where a user enters a movie and it stores it and prints it working properly, I am...
[]
[ { "body": "<p>I changed the starting count to 0, because it felt more natural and moved the increment after the assignment.</p>\n<p>I also implemented Java 17 switch, this way you can drop the <code>break;</code> keywords, and a <strong>text block</strong>.</p>\n<pre class=\"lang-java prettyprint-override\"><co...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-30T13:56:47.117", "Id": "269549", "Score": "1", "Tags": [ "java", "array" ], "Title": "Removing a string element from an array when the array is set to 100 but only contains and prints t...
269549
<h1>Goal</h1> <p>My program takes a yaml config file as parameter <code>python myprogram.py cfg.yml</code>.</p> <ul> <li>all modules can access the cfg content with a simple module import</li> <li>the imported <code>config</code> behaves like the loaded top-level yaml dictionary for reading operations</li> </ul> <pre><...
[]
[ { "body": "<p>welcome to Code Review!</p>\n<p>I think this approach is a bit overkill. You could simply have a <code>config</code> dict in the <code>config_module</code>, and have a <code>config_module.load_config(file_str: str) -&gt; None</code> function:</p>\n<pre class=\"lang-py prettyprint-override\"><code>...
{ "AcceptedAnswerId": "269570", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-30T17:36:16.607", "Id": "269550", "Score": "1", "Tags": [ "python", "configuration" ], "Title": "Python - Share global variables across modules from user-defined config file" }
269550
<p>The problem is as below:</p> <blockquote> <p>Two archery teams A and B compete with the same number of members. If the score of team A[i] is higher than that of team B[i], the total score of team A will be +1, so given team A and B with any number of members, please calculate how total score of team A will be the hi...
[]
[ { "body": "<p>Several things.</p>\n<p>Firstly, the code as it is throws a syntax error. You can fix this by removing the <code>=&gt;</code>.</p>\n<p>Secondly, since you're not using the variables <code>i</code> and <code>j</code> except to index into the lists <code>a</code> and <code>b</code>, you can just use...
{ "AcceptedAnswerId": "269869", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-30T18:25:19.503", "Id": "269551", "Score": "2", "Tags": [ "javascript", "array", "sorting" ], "Title": "Sort one array base on another array" }
269551
<p>I have a Spring MVC controller but I'm not sure that it is a good or bad design. As far as I know, api versioning is missing but apart from that I implemented Swagger for documentation and added SpringSecurity and tried to follow YARAS(Yet Another RESTful API Standard) to build it but I need another eye on that to c...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-30T19:35:09.427", "Id": "531810", "Score": "1", "body": "Welcome to Code Review! The current question title, which states your concerns about the code, is too general to be useful here. Please [edit] to the site standard, which is for ...
[ { "body": "<p>I like to work with the request specific annotation. Also, you don't need <code>@RequestMapping</code>, unless you want to version your API with URL versioning or have some fixed path for all your endpoints.</p>\n<pre class=\"lang-java prettyprint-override\"><code>@Slf4j\n@Controller\n@RequiredArg...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-30T18:25:20.593", "Id": "269552", "Score": "3", "Tags": [ "java", "api", "spring", "spring-mvc" ], "Title": "A controller for a Game Service" }
269552
<p>I have made a program that does what the title explains. It also hashes the file to check for changes. I will be doing this for a project to keep track of files that has been changed when doing different things in that certain filetree. I need this to be done as an sqlite/python app to make information easily availa...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-30T23:10:01.807", "Id": "531821", "Score": "1", "body": "Why is this going to SQLite? What can it do that the filesystem itself can't?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-31T06:23:39.373", "...
[ { "body": "<p>Avoid hard-coding file paths like this:</p>\n<pre><code>path = &quot;C:\\\\Users\\Skaft\\\\Documents\\\\GitHub&quot;\n</code></pre>\n<p>That path should be parametric.</p>\n<p>Variable names like <code>isFolder</code> should be <code>is_folder</code> (snake_case) via PEP8.</p>\n<p>Run-time asserti...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-30T22:32:10.687", "Id": "269565", "Score": "4", "Tags": [ "python", "performance", "object-oriented", "file-system", "sqlite" ], "Title": "Code to scan filesystem, store ever...
269565
<p>This code compares data from two spreadsheets generated from our clinic's software. The goal is to eliminate all the rows from the <code>PaymentsSheet</code> (our most recent transactions) that are duplicated on the <code>InvoicesSheet</code> (already uploaded transactions) to avoid duplicating info when we upload i...
[]
[ { "body": "<p>One area of 'opportunity' for optimization is that the nested loops are not 'short-circuited' once a match is found. So, even though a matching payment/invoice pair have been found, the code continues to search through the remainder of the invoices every time. Also, the current code deletes a pa...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-31T03:06:33.250", "Id": "269566", "Score": "2", "Tags": [ "performance", "vba", "excel" ], "Title": "Comparing Multiple Columns to Remove Duplicates" }
269566
<p>For my project I have a sorted array of objects of timestamps (in milliseconds) and I need two functions. One function should find the closest time that doesn't go <em>over</em> a specific amount, and the other function should find the closest time that doesn't go <em>under</em> a specific amount. Also, they should ...
[]
[ { "body": "<h3>Simplify the logic</h3>\n<p>The simplest form of binary search function returns the index where the target value would be inserted to keep the list sorted. This would imply that:</p>\n<ul>\n<li>When an exact match exists in the list, its index is returned</li>\n<li>Otherwise the index of the next...
{ "AcceptedAnswerId": "269571", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-31T04:30:11.150", "Id": "269567", "Score": "1", "Tags": [ "javascript", "algorithm", "array", "binary-search" ], "Title": "Finding the closest values in a sorted list that do...
269567
<p>I've been trying this <a href="https://www.spoj.com/problems/FUSC/" rel="nofollow noreferrer">question</a> from SPOJ, which asks for the user to enter a number <code>n</code>, and they will receive a maximum <strong>fusc</strong> value that lies in between 0 to <code>n</code>. The conditions for the function are:</p...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-01T13:47:33.203", "Id": "531941", "Score": "0", "body": "Aside: when you write \"For any odd number, the value is F(n) = F(n/2) + F(n/2 + 1)\", I didn't realize at first that you were using integer division. But now I know. And now a...
[ { "body": "<h1>Don't mix C and C++ code</h1>\n<p>Your code is a mix of C and C++. While you can use functions from C's standard library in C++ code, I recommend you avoid it and write as much as possible using just functions from C++'s standard library. In particular:</p>\n<pre><code>#include &lt;iostream&gt;\n...
{ "AcceptedAnswerId": "269573", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-31T06:37:45.023", "Id": "269569", "Score": "3", "Tags": [ "c++", "time-limit-exceeded", "dynamic-programming" ], "Title": "Find maximum value of recursively-defined \"fusc\" func...
269569
<p>I wanted to have a factory-method, but without the <code>if</code> statements that are often seen in examples of this pattern. So I came up with this, and would like to know: is this a right approach, should there be any impovements?</p> <p>some things I considered:</p> <ul> <li>It is using Enum because that makes i...
[]
[ { "body": "<h3>Using enums in Python</h3>\n<p>The posted code doesn't take advantage of most of the benefits provides by enums in Python.</p>\n<p>The typical use case of enums is to make decisions depending on a given enum member.\nFor example,\nin the context of the posted code,\nI can imagine a <code>create_f...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-31T09:04:16.237", "Id": "269572", "Score": "2", "Tags": [ "python", "factory-method" ], "Title": "Factory pattern using enum" }
269572
<p>My game is a grid in which you have to change cells color by clicking on them. When I generate a grid I have to know all the possible combinations of blue and white cells my game allows, to know the difficulty level of the grid.</p> <p>Each time I create a scenario I have to update an important parameter which is gr...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-01T09:44:40.353", "Id": "531916", "Score": "1", "body": "I can see you tried your best, but I miss a clear explanation of what this code is used for. Is this some sort of game? *What problem does this code solve?* I cannot work on code...
[ { "body": "<p>OK, I tried my hand at your first function. I haven't got time for the others. First the code, then I'll try to explain it:</p>\n<pre><code>$gameSize = 5;\n$gameGrid = [[1, 0, 1, 0, 1],\n [1, 0, 0, 0, 1],\n [1, 0, 1, 0, 1],\n [1, 0, 0, 0, 1],\n [1, 1...
{ "AcceptedAnswerId": "269617", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-31T10:41:50.573", "Id": "269575", "Score": "0", "Tags": [ "performance", "php", "recursion" ], "Title": "PHP game - changing color of cells in a blue and white grid => updating g...
269575
<p>I am currently trying to better my understanding of python and good coding practices and would really like some input on a question i have been thinking over for weeks now.</p> <p>I am currently working on building a virtual microprocessor out of basic logic gates (And, Or,...). The idea is to assemble more and more...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-01T10:36:24.900", "Id": "531918", "Score": "0", "body": "@Reinderien I added more code as requested" } ]
[ { "body": "<p>In no particular order:</p>\n<ul>\n<li>Your input model is too complicated. Don't <code>isinstance(old_input, list)</code>; just assume that every component has a <code>Collection[]</code> (sized, iterable, unordered) of (potentially only one) input.</li>\n<li>Similarly, your output model is somet...
{ "AcceptedAnswerId": "269615", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-31T11:40:44.800", "Id": "269579", "Score": "6", "Tags": [ "python", "python-3.x" ], "Title": "Decorating __init__ for automatic attribute assignment: Safe and good practice?" }
269579
<blockquote> <p>Task description A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.</p> <p>For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary r...
[]
[ { "body": "<h3>Avoid unnecessary array creation</h3>\n<p>The code creates an array of the bit positions of ones in a first pass,\nto iterate over in a second pass to find the biggest gap.\nIt's not a big deal, since the size of the array is bound by the number of bits (32).\nBut it's unnecessary, because you co...
{ "AcceptedAnswerId": "269588", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-31T15:08:07.983", "Id": "269585", "Score": "3", "Tags": [ "javascript", "node.js" ], "Title": "Codility's biggest binary gap [100% score]" }
269585
<p>I was busy writing an answer for this <a href="https://codereview.stackexchange.com/questions/269541/i-made-a-simple-score-game-in-c-console">question</a> when I realized that I was busy creating a new solution without explaining what the original poster did wrong, again.</p> <p>So I decided to rather post what I ca...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-01T10:43:27.893", "Id": "531919", "Score": "0", "body": "From a bird view: 1) `== true` can be ommited 2) `Position` properties can be immutable like `get; init;`" } ]
[ { "body": "<p>I always find it a bit strange when people answer their own questions, but after looking at this a day later I made the following observation.</p>\n<h1>Using <code>Timer</code> and <code>lock</code> is stupid and unnecessary!</h1>\n<p>Consider changing <code>public Game</code> like so:</p>\n<pre><...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-31T19:32:49.140", "Id": "269591", "Score": "5", "Tags": [ "c#", "console" ], "Title": "C# Console Snake Game" }
269591
<p>I have been obtaining financial information on an annuity I have which is invested in multiple funds which are proprietary to the insurance company.</p> <p>The asset value is not available other than on their website.</p> <p>I have been obtaining the information using VBA and Internet Explorer. Due to the rumor tha...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-10-31T21:13:17.873", "Id": "269593", "Score": "2", "Tags": [ "vba", "excel", "web-scraping", "selenium", "webdriver" ], "Title": "My first vba-selenium code" }
269593
<p>Recently, I wrote a class which can load an .obj file into vector array, and save the vector array as an .obj file. The .obj file looks something like this:</p> <pre><code>v 0.041159 -0.342570 1.029412 //vertices position : x, y,z v 0.015579 -0.341674 1.077751 v 0.014664 -0.341184 1.031222 v 0.041923 -0.343100 1.073...
[]
[ { "body": "<h1>Header</h1>\n<p>The header file includes a couple of headers that it doesn't need:</p>\n<blockquote>\n<pre><code>#include &lt;fstream&gt;\n#include &lt;iostream&gt;\n</code></pre>\n</blockquote>\n<p>That said, I would consider including <code>&lt;iosfwd&gt;</code> and declaring functions that wor...
{ "AcceptedAnswerId": "269601", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-01T06:59:13.363", "Id": "269598", "Score": "6", "Tags": [ "c++", "beginner", "file" ], "Title": "Read and write triangulated surfaces" }
269598
<p>Last night I was practicing incrementing strings. What it needs to do is increment the last character if it is a digit or letter. Special characters are ignored.</p> <p>The code that I have written does the job but I have a feeling it can be accomplished in a more elegant way. Or a faster way.</p> <p>Can somebody su...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-01T11:09:13.507", "Id": "531924", "Score": "1", "body": "Is the intent to alter only the *last* character in the string or *each* character or the last known letter or digit, which may not be the last character in the string. Perhaps ...
[ { "body": "<p><strong>Update 2</strong></p>\n<p>Correct increment when invalid char (not digit nor letter) between valid chars.</p>\n<p><strong>Update</strong></p>\n<p>Without changing too much of code, you could solve it by using the mod operator. And by the tip from @upkajdt, it would be:</p>\n<pre><code>publ...
{ "AcceptedAnswerId": "269628", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-01T09:46:00.393", "Id": "269604", "Score": "3", "Tags": [ "c#", "strings" ], "Title": "string increment" }
269604
<p><strong>Hello everyone.</strong></p> <p>I wrote my own test module, which is responsible for measuring the timing of algorithms, I used it mainly for sorting algorithms this is so to say a very early beta version, which I would like to expand with various functionalities, in general I would like to take care of the ...
[]
[ { "body": "<p>If I had to summarise this code, it would be: magical, spooky and puzzling. It works (which is a great start!) but you can make life easier on yourself and your maintainers.</p>\n<p>You've invoked the root of all <code>eval</code>. Don't do this. There are many, many alternatives; the one I'll sho...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-01T13:08:58.633", "Id": "269611", "Score": "2", "Tags": [ "python" ], "Title": "Testing module for measuring time of function" }
269611
<p>My mission is to solve this:</p> <blockquote> <p>Write a function that will take an array of numbers, and will return the average of all numbers in the array that are prime number.</p> </blockquote> <p>So far I wrote this:</p> <pre><code>function average(a){ var arr=[]; var newarr=[]; var i,j,sum,sum1,average,...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-01T18:04:00.517", "Id": "531977", "Score": "1", "body": "I think `=!`, `=+` and many others are not operators in JavaScript. Can you please double-check the description? (I suspect these should be `!=` and `+=`, respectively. There are...
[ { "body": "<h3>Single responsibility</h3>\n<p>Try to organize your programs in a way that every function has a single responsibility. For example checking if a number is a prime or not stands out here as a clear example that should be in its own function:</p>\n<pre><code>function isPrime(num) {\n var factor;\n...
{ "AcceptedAnswerId": "269618", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-01T14:11:29.777", "Id": "269613", "Score": "3", "Tags": [ "javascript", "array", "primes" ], "Title": "Average prime number from array- Javascript" }
269613
<p>I need to estimate risk differences for marginal models. I have worked on the <a href="https://rdrr.io/cran/epitools/src/R/probratio.r" rel="nofollow noreferrer">Probratio function</a> to create an equivalent function for RDs that works.</p> <p>Please provide feedback on accuracy or comments to improve efficiency wh...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-01T17:06:31.587", "Id": "531971", "Score": "2", "body": "Welcome to Code Review! I [changed the title](https://codereview.stackexchange.com/revisions/269614/3) so that it describes what the code does per [site goals](https://codereview...
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-01T14:46:53.793", "Id": "269614", "Score": "1", "Tags": [ "performance", "r" ], "Title": "Estimating risk differences for marginal models" }
269614
<h1>Abstract</h1> <p>The bash shell utility <code>mkdir</code> is a tool used to create directories in most POSIX environments. I thought it would be fun to implement such functionality from C++ and maybe forge in some of my own features in the future. I will be using the C++ library Boost to handle the command line op...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-01T21:27:02.760", "Id": "531994", "Score": "0", "body": "I was looking at Boost Log as I was already using boost; I had considered using spdlog or glog but decided to consolidate my sources when writing." }, { "ContentLicense":...
[ { "body": "<h3>Exit codes</h3>\n<p>Invoking the help of commands is usually not considered an error, so an exit code of 0 would be expected.</p>\n<p>When the real <code>mkdir</code> fails to create a directory, it exits with a non-zero value.</p>\n<h3>Decompose work to functions</h3>\n<p>Currently the <code>mai...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-01T16:03:39.023", "Id": "269616", "Score": "7", "Tags": [ "c++" ], "Title": "C++ mkdir shell utility" }
269616
<p>I wrote a small program that connects to a minecraft rcon and provides an easy to use control panel. It is written in python 3.9 and uses the kivy module for the GUI.</p> <p>What could I improve in the code? Are the variable names easy to understand and if not, how could I improve them?</p> <p>Here is the main.py an...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T16:54:54.447", "Id": "532390", "Score": "1", "body": "I have rolled back Rev 2 → 1. Please see [_What to do when someone answers_](https://codereview.stackexchange.com/help/someone-answers)." } ]
[ { "body": "<p>It is unlikely that running the code from <code>connection_refused = True</code> onward in <code>MainWindow</code>'s static scope is a good idea. Maybe you intended on this being in the constructor? In which case you need an <code>__init__</code>.</p>\n<p>This loop:</p>\n<pre><code> connection_...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-01T21:34:19.887", "Id": "269622", "Score": "1", "Tags": [ "python", "python-3.x", "kivy" ], "Title": "easy to use control panel for minecraft rcon" }
269622
<p>Here is an implementation of binary search. Please give feedback on any part but a few specific areas I was wondering about.</p> <ol> <li>Is <code>size_t</code> used appropriately or should <code>int</code> or <code>unsigned int</code> be used instead?</li> <li>How can I shorten <code>selfTest()</code> and in genera...
[]
[ { "body": "<p><code>size_t</code> is in the <code>std</code> namespace, so should be written <code>std::size_t</code>.</p>\n<p>We don't need to include <code>&lt;cmath&gt;</code>.</p>\n<p><code>main()</code> should return non-zero if any of the tests failed.</p>\n<hr />\n<p>Length+size is one way to pass a coll...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T04:15:46.847", "Id": "269625", "Score": "0", "Tags": [ "c++", "unit-testing" ], "Title": "Binary search with self-test" }
269625
<p>I did the following</p> <ol> <li>Created DB and table in prepate_table function</li> <li>Extracted data from binance in GetHistoricalData function</li> <li>Saved the data to DB</li> </ol> <p>My code works fine but I want to optimize my code and remove redundant steps</p> <p><strong>My solution</strong></p> <pre><cod...
[]
[ { "body": "<ul>\n<li>By PEP8, <code>GetHistoricalData</code> should be <code>get_historical_data</code>; likewise for your local variables like <code>until_this_date</code></li>\n<li>Introduce PEP484 type hints, for instance <code>timedelta_days: Real</code> (if it's allowed to be floating-point) or <code>int</...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T06:21:59.040", "Id": "269626", "Score": "1", "Tags": [ "python", "database", "pandas" ], "Title": "Get data from binance api and save to ClickHouse DB" }
269626
<p>I have written a function that randomly picks one element from a set with different probabilities for each element, anyway it takes a dictionary as argument, the keys of the dictionary are the choices and can be of any type, the values of the dictionary are weights and must be non-zero integers. It randomly chooses ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T11:03:57.033", "Id": "532031", "Score": "0", "body": "The [docs](https://docs.python.org/3/library/functions.html#id) state: *Two objects with non-overlapping lifetimes may have the same id() value*. This might cause bugs in your cu...
[ { "body": "<p>I'd prefer a separation between &quot;distribution objects&quot; and sampling.</p>\n<pre class=\"lang-py prettyprint-override\"><code>class WeightedDiscrete:\n def __init__(self, weighted_items: dict):\n if not isinstance(weighted_items, dict):\n raise TypeError('The argument ...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T07:26:06.813", "Id": "269627", "Score": "0", "Tags": [ "python", "performance", "python-3.x", "random", "memoization" ], "Title": "Python 3 weighted random choice function...
269627
<p>I need to convert objects (potentially nested) and collections (<code>int[]</code>, <code>IEnumerable</code>s, <code>object[]</code>) into a query string that I can pass to a <code>GET</code> <code>HTTP</code> call.</p> <p>I didn't find any complete answer on SO so I had to merge some answers and add something to ma...
[]
[ { "body": "<p>I would suggest that you split the function into two parts. The first simply deals with formatting a single object and making it safe for the query string:</p>\n<pre><code>private static string FormatValue(object obj)\n{\n string value;\n if (obj.GetType() == typeof(DateTime))\n value...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T11:35:29.033", "Id": "269633", "Score": "2", "Tags": [ "c#" ], "Title": "Serialize nested objects and arrays to querystring" }
269633
<p>I have this code to remove duplicates (all occurrences) from an associative array, does PHP have methods to do this ? Or is there a way to improve the code ?</p> <p>I looked for array_unique, array_search, array_map, array_reduce...</p> <pre><code>$articles = [ [ &quot;id&quot; =&gt; 0, &quot;tit...
[]
[ { "body": "<blockquote>\n<h3><em>is there a way to improve the code ?</em></h3>\n</blockquote>\n<p>Instead of having two <code>foreach</code> loops:</p>\n<blockquote>\n<pre><code>foreach($duplicates as $duplicate) {\n foreach($references as $index =&gt; $reference) {\n if($duplicate === $reference) {\...
{ "AcceptedAnswerId": "269671", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T13:37:25.530", "Id": "269636", "Score": "2", "Tags": [ "php", "array" ], "Title": "remove ALL duplicate elements from an array" }
269636
<p>There are many debouncer and throttle implementations created using <code>Grand Central Dispatch</code>, and even one built into <code>Combine</code>. I wanted to create one using the new <code>Swift Concurrency</code> feature in Swift 5.5+.</p> <p>Below is what I put together with <a href="https://stackoverflow.com...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T15:22:31.357", "Id": "269642", "Score": "0", "Tags": [ "swift" ], "Title": "Debounce and throttle tasks using Swift Concurrency" }
269642
<p>This program converts from number system A to number system B as soon as you input something in it, as a rookie it took a lot of thinking to make it work a seamless and fool-proof way.</p> <p>It converts the number from base A to base 10 and then to base B because the formulas are always the same.</p> <p>It is base...
[]
[ { "body": "<p>In no particular order:</p>\n<ul>\n<li><code>numtoletter</code> and similar variables and method names should be <code>num_to_letter</code> (lower_snake_case)</li>\n<li><code>numtoletter</code> and <code>lettertonum</code> should not be written out like that, and should be formed via loops - which...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T15:25:50.103", "Id": "269643", "Score": "3", "Tags": [ "python", "tkinter", "number-systems" ], "Title": "Number system converter GUI" }
269643
<p>Below is my code:</p> <pre><code>private double GetImageValue(Bitmap Image) { double ImageValue = 0; for (int X = 0; X &lt; Image.Width; X++) { for (int Y = 0; Y &lt; Image.Height; Y++) { Color CurrentPixel = Image.GetPixel(X, Y); ImageValue += CurrentPixel.A + C...
[]
[ { "body": "<p>Bitmap data is stored in an unmanaged GDI object. Every time you call <a href=\"https://docs.microsoft.com/en-us/dotnet/api/system.drawing.bitmap.getpixel?view=windowsdesktop-5.0\" rel=\"nofollow noreferrer\"><code>GetPixel</code></a> the system needs to access this object. You can speed it up by ...
{ "AcceptedAnswerId": "269651", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T15:38:06.037", "Id": "269644", "Score": "4", "Tags": [ "c#", "image" ], "Title": "Get image value total" }
269644
<p>I have a List of Car with 2 props are String and Integer like this: (A,6) (B,2) (C,9) (D,17) (E,8) (F,17) (G,2)</p> <p>and the result look like this: (A,6) (D,17) (C,9) (B,2) (E,8) (G,2) (F,17)</p> <p>Purpose: Swap 2 obj that once has MIN Integer and once has MAX Integer in the List</p> <p>Here is my code:</p> <pre>...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T18:14:14.887", "Id": "532081", "Score": "0", "body": "Welcome to Stack Review, please provide an explanation with input and output about what your code does and if you can format the code because it is difficult to read at the momen...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T16:32:56.167", "Id": "269649", "Score": "0", "Tags": [ "java", "performance" ], "Title": "Swap MIN, MAX object in a list" }
269649
<p>For a hobby project I want to visualize the current crypto market in bubbles. The idea is to clone cryptobubbles.net. I've already made a prototype at the moment, but the frames are on the low side. How can I optimize my code to get more frames?</p> <p>The application is made in JavaScript with react and d3</p> <pre...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T17:30:38.907", "Id": "269650", "Score": "3", "Tags": [ "javascript", "performance", "react.js", "jsx", "data-visualization" ], "Title": "Cryptomarket data visualization" }
269650
<p>I'm at an intermediate-ish level in java programming in school (using repl.it), and I have a math related project I'm working on. After the user inputs their own measurements, &quot;calculating.......&quot; is outputted into the console and the periods are &quot;animated&quot; so to say. The code works fine but I'm ...
[]
[ { "body": "<ol>\n<li><p>Write a function. You have code that is repetitious? Write a function to hide it away!</p>\n<pre><code>private static void show_string(String s) {\n try {\n Thread.sleep(200);\n } catch (InterruptedException e) {\n e.printStackTrace();\n }\n\n System.out.print(s...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T17:56:19.030", "Id": "269653", "Score": "1", "Tags": [ "java" ], "Title": "I'm printing an \"animated\" ellipsis into the console but the code is incredibly clunky and repetitive, can I c...
269653
<p>I am creating a .NET Framework MVC EF application for PC components. I wanted to make full use of inheritance, polymorphism and generic repository pattern - but was wondering if my initial design implementation is the best way to go about it.</p> <p>The major sections of the codebase are below:</p> <hr /> <h1>Reposi...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T12:51:48.047", "Id": "532153", "Score": "1", "body": "Ask yourself the question what you gain by this repository layer. Current consensus leans to: nothing. Just use a context. Also, please mention the exact EF version and show the ...
[ { "body": "<blockquote>\n<p>but as you'll see in the controller class I end up declaring several\nrepository instances anyway.</p>\n</blockquote>\n<p>Whenever you use a middle-ware that uses a design pattern, try to not enclose it with the same design pattern, because it's assumed that design pattern has shippe...
{ "AcceptedAnswerId": "269699", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T18:05:45.190", "Id": "269654", "Score": "0", "Tags": [ "c#", ".net", "entity-framework", "polymorphism" ], "Title": "Entity Framework - component shop using polymorphism a...
269654
<p>As you might probably know, a Caesar cipher involves shifting/unshifting and wrapping up characters when they overflow the first or last letter of the alphabet, it's useful to have a function to just handle character shifting. So I wrote a function that I intend to use in other places and was hoping to see if there ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-27T15:58:33.617", "Id": "534082", "Score": "0", "body": "\"I wrote a function that I intend to use in other places and was hoping to see if there are any edge cases ... \" for that you don't need a code review, you need unit testing." ...
[ { "body": "<h2>Function design</h2>\n<p>The function itself is well named. The main problem is that it is specific to the ABC, while that is just one alphabet. I would make it generic and have a class accept an alphabet which then can be used anywhere. This makes it more valuable for reuse.</p>\n<p>Similarly, i...
{ "AcceptedAnswerId": "270451", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T18:23:56.053", "Id": "269655", "Score": "1", "Tags": [ "rust", "caesar-cipher" ], "Title": "A character shift function in Rust" }
269655
<p>I needed the ability to truncate the trailing end of path strings in a routine that builds new search paths as it recursively searches directories. After not finding what I was looking for I created function below.</p> <p>Expected behavior is that function <code>remove_trailing_chars()</code> will update <code>in</c...
[]
[ { "body": "<h3>Accessing array out of bounds</h3>\n<p>The code here may try access <code>in_dup[-1]</code> in some cases:</p>\n<blockquote>\n<pre><code>len = strlen(in_dup);\nint i = 0;\nwhile(rem[i])\n{\n if(in_dup[len-1] == rem[i])\n ^^^^^^^^^^^^^\n</code></pre>\n</blockquote>\n<p>That is, when the i...
{ "AcceptedAnswerId": "269661", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T18:30:19.957", "Id": "269656", "Score": "1", "Tags": [ "algorithm", "strings", "c99" ], "Title": "Function to remove set of trailing characters from string" }
269656
<p>I'm creating a program that finds the roots of Bhaskara’s formula and prints them.</p> <p>I'm looking for advice to improve my logic more and more.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;math.h&gt; int main () { double os; double four; int a; int b; int c; ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T07:56:15.410", "Id": "532124", "Score": "1", "body": "\"Bhaskara's formula\" seems to be another name for the quadratic formula." } ]
[ { "body": "<blockquote>\n<p>advice to improve my logic more and more.</p>\n</blockquote>\n<p><strong>Provide link</strong></p>\n<p>Rather than assume folks know of <em>Bhaskara’s formula</em>, provide a link, even in a code comment.</p>\n<p><strong>Use an auto formatter</strong></p>\n<p>Code lacks format consis...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T20:27:38.717", "Id": "269660", "Score": "1", "Tags": [ "beginner", "c", "programming-challenge" ], "Title": "Evaluate the roots of Bhaskara’s formula" }
269660
<p>I'm trying to move a large number of files. I get the path of source and destination from database.</p> <p>It takes hours to move images, and I was wondering if there is a faster way for moving large numbers of files.</p> <p>Table example:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T07:48:11.400", "Id": "532123", "Score": "0", "body": "Welcome to CodeReview! Which .NET and C# version are you using?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T08:05:03.583", "Id": "532125",...
[ { "body": "<p>Quick suggestion:</p>\n<ol>\n<li>Iterate through all the records in the database</li>\n<li>Group them by folder</li>\n<li>See if there are other items in the folders</li>\n<li>Moving folders is exponentially faster than individual files</li>\n<li>If the files are on different drives, or you are no...
{ "AcceptedAnswerId": "269688", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T21:20:27.370", "Id": "269665", "Score": "1", "Tags": [ "c#", "sql", "file-system" ], "Title": "Moving files according to paths in database" }
269665
<p>I have completed my project which models the paths of particles in a plasma experiencing a <a href="https://en.wikipedia.org/wiki/Magnetic_mirror" rel="nofollow noreferrer">force</a>. The program creates phase diagrams of a particle's perpendicular velocity against its parallel velocity from 0 to 180 degrees.</p> <p...
[]
[ { "body": "<ul>\n<li>Functions and type hints are your friend - use them</li>\n<li>Vectorise your separate alpha values and calculations to a single calculation for each of perpendicular and parallel arrays</li>\n<li><code>np.linspace(0, 180, int(round(180/1 + 1)))</code> is a slightly bizarre way of writing <c...
{ "AcceptedAnswerId": "269706", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T21:48:56.233", "Id": "269666", "Score": "4", "Tags": [ "python", "physics" ], "Title": "Phase diagrams of particles in a mirror" }
269666
<p>For a college assignment, I was tasked with the following (excerpt from provided code file):</p> <blockquote> <p>Find one string of characters that is not present in the list. You are provided a function that loads the strings from the provided file, <code>sequences.txt</code>. You may not use any libraries that ass...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T22:16:29.827", "Id": "532104", "Score": "0", "body": "I think you forgot to increment the string index. As is this would fail with the following input of 2 strings : 'AB', 'BA' . But would work with strings[idx][idx]." }, { ...
[ { "body": "<p>We should begin the habit of using a &quot;main guard&quot;:</p>\n<pre><code>if __name__ == &quot;__main__&quot;:\n result, should_be_false = find_excluded()\n print(result)\n print(should_be_false)\n</code></pre>\n<p>We don't need <code>strings[idx]</code>, since <code>enumerate()</code>...
{ "AcceptedAnswerId": "269712", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T21:55:52.977", "Id": "269667", "Score": "1", "Tags": [ "python", "python-3.x", "algorithm", "homework" ], "Title": "Generate a string that is not present in a list" }
269667
<p>I have written the following Sudoku checker in Python. I feel like this could be written much shorter and perhaps more efficient. Especially the part with <code>square_columns</code>.</p> <pre><code>rows = [] columns = [] squares = [] sudoku_sets = [] for i in range(9): if i == 0: row = input(&quot;Inpu...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-04T10:51:34.917", "Id": "532247", "Score": "1", "body": "Check out this answer from stackoverflow https://stackoverflow.com/a/17606526/13756061." } ]
[ { "body": "<p>Your code looks quite nice. Still there is some room for improvements.</p>\n<h1>Do not define variables in a single block at the beginning</h1>\n<p>This is a style from ancient C. Now the rule is to declare variables</p>\n<ul>\n<li>in the smallest possible scope</li>\n<li>as late as possible</li>\...
{ "AcceptedAnswerId": "269735", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-02T22:25:53.503", "Id": "269669", "Score": "1", "Tags": [ "python" ], "Title": "Sudoku Checker in Python" }
269669
<p>It's been a while since I've done any sort of programming, and my first time in Python. I'm just looking for any general feedback and tips since this is my first program.</p> <pre><code># rock, paper, scissors game import random playerWin = 0 aiWin = 0 guess = 0 print('You are playing rock, paper, scissors. If you ...
[]
[ { "body": "<p>First of all, great work! The program appears solid, the interface is decent and you handle bad input.</p>\n<p>I have a few suggestions for improvement:</p>\n<h3>UI/UX</h3>\n<ul>\n<li>The <code>&quot;1&quot;</code> <code>&quot;2&quot;</code> <code>&quot;3&quot;</code> <code>&quot;4&quot;</code> ap...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T02:33:21.043", "Id": "269675", "Score": "3", "Tags": [ "python", "beginner", "rock-paper-scissors" ], "Title": "Cliché Rock, Paper, Scissor, as first Python program" }
269675
<p>I've been working on a course assignment for 'The Odin Project' and was hoping to get a review of my code.</p> <p>As per the help guide, the code is fully functional.</p> <p>The criteria for this was pretty straight forward. Try to have as little global code as possible. (At this point I've learned about classes, an...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-10T11:49:13.130", "Id": "532801", "Score": "0", "body": "Thanks Sam for editing!" } ]
[ { "body": "<p>Welcome to Code Review, your game looks pretty nice!</p>\n<p>There is quite a lot of code to go through but here are some initial observations.</p>\n<h1>Constructor</h1>\n<p>You are using exactly the same code in the <code>GameBoard</code> constructor and in <code>boardReset</code>. You should rat...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T05:40:38.590", "Id": "269683", "Score": "3", "Tags": [ "javascript", "beginner", "ecmascript-6", "tic-tac-toe" ], "Title": "Tic Tac Toe in object oriented JavaScript" }
269683
<p>Continued from the previous <a href="https://codereview.stackexchange.com/questions/269569/find-maximum-value-of-recursively-defined-fusc-function/269573?noredirect=1#comment532093_269573">post</a> - a brute-force approach to calculating all the vectors from 0 to n.</p> <p>I've come up with yet another solution, aft...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T04:49:21.740", "Id": "532325", "Score": "0", "body": "It's worth mentioning that `fusc` is [Stern's diatomic series](https://mathworld.wolfram.com/SternsDiatomicSeries.html), [A002487](https://oeis.org/A002487), and so it would not ...
[ { "body": "<p>Prefer the C++ header <code>&lt;cmath&gt;</code>. This puts the relevant functions into the <code>std</code> namespace.</p>\n<p>Talking of namespace, several other identifiers are used without the necessary qualification (<code>std::uint64_t</code>, <code>std::max_element</code>).</p>\n<p>We use ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T06:09:51.143", "Id": "269684", "Score": "1", "Tags": [ "c++", "performance", "time-limit-exceeded", "vectors" ], "Title": "RE: Find maximum value of recursively-defined \"fusc...
269684
<p>I'm trying to create a stack library from scratch. It stores generic elements which are passed in <code>void*</code> pointers.</p> <p>This is the defined structure:</p> <pre><code>typedef struct stackObject { void* obj; struct stackObject *next; } StackObject_t; typedef struct stackMeta { StackObject_t ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T08:45:09.573", "Id": "532134", "Score": "0", "body": "What is the purpose of the `objsize` parameter? It seems to be unused, as you only store pointers to the objects." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDat...
[ { "body": "<h1>Data structure</h1>\n<p>We've implemented a stack using a linked list. That will work, but is likely less efficient than using a growable array.</p>\n<p>We only store pointers to the objects in the stack, meaning that we are dependent on the owners of those objects for lifecycle. If any of the ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T07:21:50.803", "Id": "269685", "Score": "3", "Tags": [ "c", "stack" ], "Title": "Stack API for generic values" }
269685
<p>For my game I need to roll some values with a die. A die is formally described as:</p> <blockquote> <p><strong>nDs[+a]</strong></p> <ul> <li><em>n</em> amount of die (optional, 1 of not set, zero must be set explicitly)</li> <li><code>D</code> is a fixed part representing this expression as die</li> <li><em>s</em> a...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T08:25:28.083", "Id": "532128", "Score": "6", "body": "IMO not good enough for an answer, so I'll put in in a comment: I plugged your `INPUT_VALIDATION_PATTERN` into [regex101](https://regex101.com/) and found that it matches `\"D\"`...
[ { "body": "<h3>Bug in the validation pattern</h3>\n<p>The <code>INPUT_VALIDATION_PATTERN</code> doesn't work correctly, as it matches the invalid input <code>&quot;D&quot;</code>. This is due to the pattern looking for any number of digits (<code>*</code>) after the <code>D</code>. Changing the pattern to look ...
{ "AcceptedAnswerId": null, "CommentCount": "16", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T07:54:11.037", "Id": "269687", "Score": "7", "Tags": [ "java", "object-oriented", "reinventing-the-wheel", "regex", "dice" ], "Title": "DnD Die in Java with regex" }
269687
<p>My task was to get the last 125 rows from an excel workbook.</p> <p>The rows are started from the 17th row and it goes until it can.</p> <p>Here's my code:</p> <pre><code>Sub Get_Data_From_File() Const START_ROW As Long = 17 Const NUM_ROWS As Long = 124 Dim FileToOpen As String Dim wb As Workbo...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T10:37:35.390", "Id": "532145", "Score": "0", "body": "The formulas in English: \n\n\nSzórás: STDEV(INDEX(DF17:DF2025;MATCH(MAX(DF17:DF2025);DF17:DF2025;1)):INDEX(DF17:DF2025;MAX(1;MATCH(MAX(DF17:DF2025);DF17:DF2025;1)-24)))\"\n\n\nÁ...
[ { "body": "<p>I don't know if this will work for your particular project, but my first instinct would be to create some hidden rows with values like the following</p>\n<p><a href=\"https://i.stack.imgur.com/nipm9.png\" rel=\"nofollow noreferrer\"><img src=\"https://i.stack.imgur.com/nipm9.png\" alt=\"enter imag...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T10:34:54.463", "Id": "269690", "Score": "1", "Tags": [ "vba", "excel" ], "Title": "Copy the last 125 rows from a selected excel file and paste into the used one" }
269690
<p>While setting up applications to communicate between various different trade partners and our WMS software I often have to parse very similar information from various different file formats. In this specific case i have to retrieve the tracking data from different files in csv, xml or json format. I've set up one te...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T22:41:03.070", "Id": "532219", "Score": "2", "body": "it would be more helpful to the reviewers if the code is written in plain English." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-04T08:20:39.973",...
[ { "body": "<p>For the purposes of international collaboration, for better or worse the de-facto language of software development is English, so:</p>\n<ul>\n<li>versanddaten -&gt; ShippingData</li>\n<li>vorlage -&gt; Template</li>\n<li>DateiEndung -&gt; FileExtension</li>\n</ul>\n<p>It is a great idea to localis...
{ "AcceptedAnswerId": "269740", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T12:03:10.027", "Id": "269691", "Score": "1", "Tags": [ "c#", "parsing" ], "Title": "Parsing data from different file formats" }
269691
<blockquote> <h2>Minimal Squares in a Rectangle</h2> <p>Given a rectangle of dimensions <span class="math-container">\$a\$</span> and <span class="math-container">\$b\$</span>, we want to divide it into the <em><strong>minimal</strong></em> number of covering squares. The following rectangle has a dimensions of 5 x 3. ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T18:43:22.143", "Id": "532405", "Score": "1", "body": "Instead of `=!`, `=>`, `=<`, `=%`, `=/`, `=*`, `=+`, did you really mean `!=`, `>=`, `<=`, `%=`, `/=`, `*=`, `+=`? Also, what is the `+-` operator? (if there really is such a thi...
[ { "body": "<p>This problem lends itself quite well to a recursive implementation. This would be the algorithm for <code>sqaures(length,width)</code>:</p>\n<ul>\n<li><p>If <code>length</code> &lt; <code>width</code>, then we have it wrong way around, so return the value of <code>squares(width,length)</code>.</p...
{ "AcceptedAnswerId": "269797", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T13:54:57.650", "Id": "269700", "Score": "1", "Tags": [ "javascript", "array" ], "Title": "Minimal Squares in a Rectangle" }
269700
<p>I'm reading &quot;Modern C++ Design&quot; (A. Alexandrescu, 2002). The author said &quot;the standard memory allocator is awful for small objects&quot;, but it has been two decades after the book has been out, glibc's malloc was really hard to beat.</p> <p>Anyway, inspired from that, I wrote a simple allocator for f...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T14:44:43.193", "Id": "532164", "Score": "0", "body": "Have you looked at the newer `memory_resource` interface?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T14:46:46.803", "Id": "532165", "...
[ { "body": "<h1>Missing alignment restrictions</h1>\n<p>A big issue with your allocator is that you don't ensure the storage is correctly aligned for type <code>T</code>. There are various ways to ensure storage is correctly aligned, but a simple way to do this is by using <a href=\"https://en.cppreference.com/w...
{ "AcceptedAnswerId": "269716", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T14:23:20.167", "Id": "269702", "Score": "4", "Tags": [ "c++", "memory-management" ], "Title": "C++ : Allocator for fixed size object" }
269702
<p>This is a follow-up to <a href="https://codereview.stackexchange.com/questions/269526/implementing-stdformat-part-2">this</a> question.</p> <p>Here I’m trying to do something useful with the format specifier. I guess I should have started with <code>width</code> and <code>precision</code> but foolishly decided to fi...
[]
[ { "body": "<p>You only need a <code>string_view</code> overload to take care of <code>string</code>, <code>const char*</code>, and <code>string_view</code> arguments.</p>\n<pre><code>data.a = x;\ntoBinary(oss, data.b);\n</code></pre>\n<p>That's <strong>undefined behavior</strong>.</p>\n<p>You ought to have a te...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T15:22:40.827", "Id": "269703", "Score": "1", "Tags": [ "c++", "c++20" ], "Title": "Implementing std::format - Part 3" }
269703
<p>I made a weather app in react and redux for an interview. The response was that I didn't use redux properly, and that it has unnecessary props. I'm not sure what they meant.</p> <p>The app is on github <a href="https://github.com/s-e1/weather-app" rel="nofollow noreferrer">https://github.com/s-e1/weather-app</a></p>...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T17:49:46.173", "Id": "269708", "Score": "2", "Tags": [ "interview-questions", "react.js", "jsx", "redux" ], "Title": "Proper way of using redux and props" }
269708
<p>I'm implementing a single linked list as close as it could be to <a href="//en.cppreference.com/w/cpp/container/forward_list" rel="nofollow noreferrer"><code>std::forward_list</code></a>. I would welcome a review and also more suggestions on what to test additionally.</p> <pre><code>#ifndef LINKED_LIST_HPP #define L...
[]
[ { "body": "<ol>\n<li><p>Remember the rule of three. The implicitly declared copy- and move- ctor and assignment are unsuitable for <code>LinkedList</code>.</p>\n</li>\n<li><p>Two-space indentation doesn't really stand out. Consider doubling it.</p>\n</li>\n<li><p>If you add trace-output to your code, the least ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T18:46:30.423", "Id": "269711", "Score": "2", "Tags": [ "c++", "linked-list", "reinventing-the-wheel", "template", "iterator" ], "Title": "Single-linked-list in C++ with it...
269711
<p>I made a simple battleship in C# console with a little AI ( just a little ) and The goal of this practice is improving my knowledge about OOP.</p> <p>Game Rules:</p> <p>1.You Attack To The Enemy then he Attacked You.</p> <p>2.if you do not find any ships with the help of Hint, one of your own ships will sink</p> <p>...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-04T12:27:20.503", "Id": "532259", "Score": "0", "body": "Why do you randomly switch the casing of your variable names? One minute your pascal casing (i.e. `Counter`) and the next you're camel casing (i.e. `index`, `indexOfAI`, etc). Ge...
[ { "body": "<p>Try to pay attention to how do you name things, because it's really important when other people read your code</p>\n<h4>Method names :</h4>\n<p>method names should <strong>always be a verb not a noun</strong>, because the method do things</p>\n<ul>\n<li><p><code>myGameEngine.Engine()</code> should...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-03T20:35:11.650", "Id": "269715", "Score": "1", "Tags": [ "c#", "game", "console" ], "Title": "I Made a Simple BattleShip Game On C# Console" }
269715
<h2>Updated previously posted string struct and utility functions</h2> <p>Previous link: <a href="https://codereview.stackexchange.com/questions/269062/user-friendly-string-struct-and-utility-functions/">User-friendly string struct and utility functions</a></p> <h4>What is updated ?</h4> <ul> <li>typedef of sstring is ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-04T14:18:38.103", "Id": "532274", "Score": "0", "body": "Why `_` begins so many `struct` member names?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T04:37:53.677", "Id": "532439", "Score": "0",...
[ { "body": "<blockquote>\n<p>conversion from c-style array strings to sstrings and vice-versa is now easily possible through sstr2cstr() and cstr2sstr() functions!</p>\n</blockquote>\n<p>Yes possible, but inefficient.</p>\n<p><code>cstr2sstr()</code> performs O(GLOBAL_MAX_CHAR_LIMIT) operations even when the C s...
{ "AcceptedAnswerId": "269747", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-04T07:11:48.577", "Id": "269720", "Score": "3", "Tags": [ "c", "strings" ], "Title": "User-friendly string struct and utility function - upated version" }
269720
<p>I'm trying to scrape arrival data from <a href="https://satudata.kemendag.go.id/balance-of-trade-with-trade-partner-country" rel="nofollow noreferrer">this website</a>. My script takes extremely long time to scrape the data. Is there any way I can speed up the scraping process?</p> <p>Here's my script:</p> <pre><cod...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-04T13:44:23.663", "Id": "532267", "Score": "0", "body": "What is the reason that your output is in Pandas format?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-04T14:45:52.607", "Id": "532278", "S...
[ { "body": "<p>It won't be practical to speed this process up since you're scraping a third-party website. Parallelizing requests and loading the server is ethically dubious so I think you don't have many options other than to be patient.</p>\n<p><code>getBalanceofTrade</code> should be <code>get_balance_of_trad...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-04T07:19:14.983", "Id": "269721", "Score": "3", "Tags": [ "python", "performance", "python-3.x", "web-scraping", "pandas" ], "Title": "Web scraping international trade data" ...
269721
<p>I have developed a web app which lets you transfer files from A device to B device, similar to airdrop's concept, working through the server and not peer-to-peer.</p> <p>I didn't go with a P2P solution because it requires a lot of time to make it work perfectly, and fallbacks in case it doesn't so I didn't really wa...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-09T18:36:32.877", "Id": "532725", "Score": "3", "body": "could you please explain more in detail why do you think there may be a problem with the handshake? I don't know js nor angular, but your description of key exchange seems like a...
[]
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-04T12:37:34.783", "Id": "269728", "Score": "1", "Tags": [ "typescript", "angular-2+", "websocket", "encryption" ], "Title": "My implementation of the Signal protocol for end-to-e...
269728
<p>I had to make a single-page application that fetches some figures via an endpoint, does some calculations, and displays them to an <code>HTML</code> page. Below is my implementation. I know there is a lot of room for improvement. Looking forward to any feedback.</p> <pre><code>const getNumberOfTitles = async (title:...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-04T13:50:33.630", "Id": "269729", "Score": "1", "Tags": [ "javascript", "typescript" ], "Title": "Implement a single page application which fetches data via an endpoint and displays to a...
269729
<p>I've been adding stuff a bit &quot;blindly&quot; to my controller and currently everything is working as it should, but the controller is gotten very messy. I'm using the gem <code>rails_best_practices</code> to tidy up my code, but it's currently not giving me any other fixes than moving some of the methods to the ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-04T20:17:00.487", "Id": "532305", "Score": "1", "body": "Welcome to Code Review! The current question title, which states your concerns about the code, is too general to be useful here. Please [edit] to the site standard, which is for ...
[ { "body": "<h1>Only have CRUD actions in your controllers</h1>\n<p>Your controllers should only use the default CRUD actions index, show, new, edit, create, update, destroy.</p>\n<p>So rather than doing this</p>\n<pre class=\"lang-rb prettyprint-override\"><code>class OffersController &lt; ApplicationController...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-04T18:23:25.470", "Id": "269738", "Score": "1", "Tags": [ "ruby", "ruby-on-rails", "controller", "e-commerce" ], "Title": "Rails controller to handle offers and payments for rent...
269738
<p><strong>Context:</strong> I am trying to perform a <code>scan()</code> on a DynamoDB table and apply some conditional operators to a filter expression. The operators however are passed in via AWS Lambda's event field. This means the operator is determined by an external user and my code needs to handle all possible ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-04T23:58:15.277", "Id": "532315", "Score": "0", "body": "Can you indicate where `Attr` comes from? I've been unable to find documentation on it." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T06:01:18.1...
[ { "body": "<p>Yes, you should simplify this. Make a dictionary whose key is any of the potential values for <code>conditionAPIParam</code>, and value is a non-bound class function reference.</p>\n<pre class=\"lang-py prettyprint-override\"><code>PARAMS = {\n 'gt': Attr.gt,\n 'lt': Attr.lt,\n 'eq': Attr...
{ "AcceptedAnswerId": "269750", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-04T20:39:34.560", "Id": "269743", "Score": "3", "Tags": [ "python" ], "Title": "Scanning a DynamoDB table using a filter expression with multiple possible comparison operators" }
269743
<p>I'm writing a GUI for different VME modules (electronics). There are several of them which are used for the data acquisition. For example, an ADC produces the digitized maximum voltage on its input. So I need a way to visualize this data. Almost always this way is a <em>histogram</em>. So I've chosen the <a href="ht...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T07:05:23.897", "Id": "532328", "Score": "2", "body": "Is there any repo I could clone and play with?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T12:05:49.853", "Id": "532353", "Score": "0"...
[ { "body": "<h2>Build</h2>\n<p>I believe build scripts are a major part of the code. If nobody can incorporate it into their build, then the piece code is useless. Yours is good, but it seems the default distribution provides pkg-config files. I tried to use <code>pkg_check_modules</code> inside cmake, but after...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-04T21:22:58.940", "Id": "269745", "Score": "3", "Tags": [ "c++", "multithreading", "gui", "qt" ], "Title": "Real time histogram using multithreading (Qt + Qwt)" }
269745
<p>I have referred to this for what constitutes as an Euler Cycle: <a href="https://xlinux.nist.gov/dads/HTML/eulercycle.html" rel="nofollow noreferrer">https://xlinux.nist.gov/dads/HTML/eulercycle.html</a></p> <p>This assignment required me to use Depth First Search and have the methods I have included. I am also requ...
[]
[ { "body": "<p>Given it seems to be <code>princeton.cs.algs4</code> course task I am not entirely sure what would be the best answer here. I'd assume you are suppose to learn and learning limited number of things at a time (here DFS and euler cycles?) is pretty good practice, so in terms of <em>what purpose does...
{ "AcceptedAnswerId": "269776", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T03:52:09.850", "Id": "269753", "Score": "0", "Tags": [ "java", "algorithm", "graph", "depth-first-search" ], "Title": "Recursive DFS to find Euler Cycle" }
269753
<p>I am a novice when it comes to C++ (as well as C++/CLI). I am trying to write a minimal 64-bit implementation of a List in C++ (using <code>unsigned __int64</code> as the index data type), to store <code>unsigned char</code> values (bytes), as well as a C++/CLI wrapper for it that I will use to later to talk to it i...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T10:52:52.407", "Id": "532346", "Score": "0", "body": "Apparently there is. :-). I've updated the code. I've been using this (https://docs.microsoft.com/en-us/cpp/dotnet/managed-types-cpp-cli?view=msvc-160) as a guide to the data typ...
[ { "body": "<p>I'm not sure why you don't simply use a <code>List&lt;byte&gt;</code> in C# or <code>std::vector&lt;std::uint8_t&gt;</code> in C++ as already mentioned by G.Sliepen.</p>\n<p>I'm going to ignore that for now and continue with the review.</p>\n<h1>Use the correct types.</h1>\n<p>You should use <code...
{ "AcceptedAnswerId": "269847", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T04:21:52.063", "Id": "269755", "Score": "1", "Tags": [ "c++", ".net", "c++-cli" ], "Title": "BigByteList with a managed wrapper" }
269755
<p>This code cleans up a big dataset into a very clean and a flat file that can be further used downstream like visualization.</p> <p>I am expecting to improve the code to essentially run it faster and cleanup the code to avoid any inefficient functions that should not take further resources than it should.</p> <p>The ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T08:02:53.393", "Id": "532333", "Score": "3", "body": "Welcome to Code Review! The current question title, which states your concerns about the code, is too general to be useful here. Please [edit] to the site standard, which is for ...
[ { "body": "<p>Any time that you have a section labelled <code>This part</code>, that's a good indication that you should have a function. Code like this should not exist in a flat file with no structure. Among many other reasons,</p>\n<ul>\n<li>once one of your subroutines finishes, any intermediate variables t...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T07:23:55.763", "Id": "269756", "Score": "0", "Tags": [ "python", "pandas" ], "Title": "Cleanup dataset for visualization" }
269756
<p>I was solving a DSA question, running median in a stream. And I decided to design my own stream class with additional features.</p> <pre><code>template&lt;typename T&gt; class ActionInterface{ public : virtual void process(const T element) = 0; }; template&lt;typename T,typename V&gt; class Action : pu...
[]
[ { "body": "<p>Where are the tests?</p>\n<hr />\n<p>The code doesn't compile - I needed to add a missing semicolon in <code>Solution::solve()</code> and prefix with some definitions:</p>\n<pre><code>#include &lt;vector&gt;\n#include &lt;string&gt;\n#include &lt;queue&gt;\n#include &lt;unordered_map&gt;\n#include...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T08:32:50.967", "Id": "269757", "Score": "0", "Tags": [ "c++", "algorithm", "object-oriented", "generics", "stream" ], "Title": "Stream that computes running median value" ...
269757
<p>I'm learning java this week. Please reviews my code for BMI calculator using java, need some your feedback. Thanks before!</p> <p>This Assignment:</p> <p><a href="https://i.stack.imgur.com/mJ0BS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mJ0BS.png" alt="BMI Calculator and expected output" /><...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T09:46:06.827", "Id": "532341", "Score": "3", "body": "You've hard coded the people's information, rather than prompting the user for it from the console. Since it's in the problem description it's probably part of what you're being ...
[ { "body": "<pre><code>public void bmiCalculation(double height, double weight) {\n\n // bmi algo = BMI = weight / height ** 2 * 703\n\n double newHeight = 1;\n double bmi = 0;\n for (int i = 0; i &lt; 2; i ++) {\n newHeight *= height;\n }\n bmi = weight / newHeight * 703;\n println(bmi);\n classifi...
{ "AcceptedAnswerId": "269762", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T09:32:42.693", "Id": "269759", "Score": "2", "Tags": [ "java", "homework", "eclipse" ], "Title": "Java BMI Calculator" }
269759
<p>Okay so I built this search page that searches for posts but my current code seems so bloated and inefficient.</p> <p>My script(search page)</p> <pre><code>if(isset($_GET['title']))$title = $_GET['title'];else{ $title = ''; } if(isset($_GET['ad_brand']))$brand = $_GET['ad_brand'];else{ $brand = ''; } if(isset($_GET[...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T12:04:16.193", "Id": "532352", "Score": "2", "body": "Could you elaborate a bit more on what this code does? The only thing we know, by combining two things you wrote, is: \"It searches for posts using multiple filter inputs.\". We ...
[ { "body": "<p>There is one thing that is not right in your application: tabs and <strong>indentation</strong>.</p>\n<p>Example:</p>\n<pre><code>if(isset($_POST['filter_button'])){\n if(isset($_POST['ad_brand']))\n $brand = $_POST['ad_brand'];\n else{$brand = '';}\n</code></pre>\n<p>So the code is h...
{ "AcceptedAnswerId": "269783", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T11:10:24.683", "Id": "269764", "Score": "0", "Tags": [ "php", "mysql" ], "Title": "PHP search multiple filter inputs" }
269764
<p>This question seems similar to this one: <a href="https://codereview.stackexchange.com/questions/241272/find-number-of-unique-paths-to-reach-opposite-grid-corner">Find number of unique paths to reach opposite grid corner</a> but is entirely not. For moving from upper-left corner to lower-right corner we are not rest...
[]
[ { "body": "<p>I would recommend that you change <code>struct Square</code> to <code>record Square</code>. This makes all the comparative stuff much easier.</p>\n<p>Then you can change your <code>Program</code> class to the following which uses recursion to find the paths. I have also added a timer to show progr...
{ "AcceptedAnswerId": "269774", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T11:55:56.870", "Id": "269767", "Score": "7", "Tags": [ "c#", "performance", "memory-optimization", "chess" ], "Title": "Find all possible ways a rook can move to a diagona...
269767
<p>Here's my attempt at leetcode's <a href="https://leetcode.com/problems/container-with-most-water/" rel="nofollow noreferrer">container with most water</a>.</p> <h3>Problem:</h3> <blockquote> <p>Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are d...
[]
[ { "body": "<p>Two minor things:</p>\n<p>Your type hint for <code>height</code> doesn't need to be <code>List</code>; since your algorithm (correctly) does not mutate <code>height</code>, you can generalize this to <code>Sequence</code>.</p>\n<p><code>(k for k in max_h_left)</code> and similar can be simplified ...
{ "AcceptedAnswerId": "269789", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T14:26:40.403", "Id": "269773", "Score": "6", "Tags": [ "python", "python-3.x", "programming-challenge" ], "Title": "Container with most water, with pre-computation of possible...
269773
<p>I wrote a function saving class which basically saves data of every function that's being called</p> <pre class="lang-py prettyprint-override"><code>import inspect import typing class SaveData: def __init__(self): self.data = [] def save_data(self, func, remove_self=False): f_inspect = ins...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T17:37:43.930", "Id": "532400", "Score": "3", "body": "This looks really generic, and - without seeing an actual use case - I can't come to any conclusion other than \"none of this should exist, and you should just use pickle directl...
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T16:32:18.167", "Id": "269782", "Score": "0", "Tags": [ "python", "python-3.x", "serialization", "meta-programming" ], "Title": "Class to save the parameters of every function ...
269782
<p>The following code bellow is a factory which creates two different objects for <code>marshalling</code> <code>cyphered</code> and <code>encoded</code> output or the plain text <code>default</code> output. I'm concerned with a few things:</p> <ul> <li>different switch arms may have different dependencies, e.g.<code>c...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-08T07:33:17.163", "Id": "532602", "Score": "1", "body": "Are there `import` statements that are relevant to this code?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-08T10:20:02.680", "Id": "532609", ...
[ { "body": "<p>After giving it another though I've refactored the code in the following fashion:</p>\n<ul>\n<li>extracted the switch branch conditions into separate functions</li>\n<li>got rid of switch by using an array of rules.</li>\n</ul>\n<p>The result is pretty similar to the following:</p>\n<pre><code>// ...
{ "AcceptedAnswerId": "269870", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T17:33:10.227", "Id": "269784", "Score": "1", "Tags": [ "go" ], "Title": "Factory to create default or cyphered and encoded output marshalers" }
269784
<p>Yesterday when I was showering I was thinking of branchless programming and a thought occurred to me, whether it's possible to write a branchless solution of the Fizbuzz problem. The constraints I put on myself were no if statements, no switches, no ternary operators and no loops. The code below seems to solve this ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-08T18:42:57.793", "Id": "532656", "Score": "0", "body": "\"Branchless Fizbuzz\"?? `(num % 3 && num % 5) && write(0, str, 5);` looks like branching code to me with its `&&`." } ]
[ { "body": "<p>You don't use it, but your restrictions don't seem to exclude it, so if you make use of the <code>||</code> operator things can be simplified.</p>\n<pre><code>void fizbuzz(int num)\n{\n !(num % 15) &amp;&amp; printf(&quot;fizbuzz\\n&quot;) ||\n !(num % 5) &amp;&amp; printf(&quot;buzz\\n&quot...
{ "AcceptedAnswerId": "269795", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T17:39:57.183", "Id": "269785", "Score": "3", "Tags": [ "c", "fizzbuzz" ], "Title": "Branchless Fizbuzz in Posix C (no if-s, ternaries, switches or loops)" }
269785
<p>I was wondering what might be the best way to inject Flask routes dependencies without a DI framework.</p> <p>I came up with something like this (<code>CalculationService</code> being the dependency I want to inject):</p> <pre><code>from typing import Protocol from flask import Flask app = Flask(__name__) class C...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T21:02:29.040", "Id": "269792", "Score": "1", "Tags": [ "python", "dependency-injection", "flask", "bootstrap" ], "Title": "Injecting dependencies in Flask routes without a DI ...
269792
<p>I've made a little app, YouTube Downloader, which does what the name says.<br /> I have three files as I am trying to get good enough in working with multiple files in one app. So even if it is really small I will try to separate it.</p> <p>I have some questions:</p> <ul> <li>Is my style acceptable?</li> <li>Is the ...
[]
[ { "body": "<p>&quot;MP3 or not&quot; isn't as informative as &quot;MP3 or MP4&quot;, so you should convert your checkbox to a couple of radio buttons.</p>\n<p>This is spooky:</p>\n<pre><code>sys.path.append(f'{os.path.dirname(__file__)}\\\\scripts')\n</code></pre>\n<p>and probably means that your directory stru...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T22:15:37.523", "Id": "269794", "Score": "7", "Tags": [ "python", "tkinter", "youtube" ], "Title": "YouTube Downloader with PyTube" }
269794
<p>I am working on an integration software. I will need to download a list of products and import it into my website. The list of products will be downloaded from <code>Constants.EndPoint</code> which contains a zipped xml document.</p> <p>I will be downloading this file periodically (once every 4 hours)</p> <p>I have ...
[]
[ { "body": "<p>Disposing of the unzipStream, archive and zipStream objects when exiting the using blocks, won't affect the <code>xml</code> document object.</p>\n<p>And a few notes:</p>\n<ol>\n<li><p>Constants.EndPoint - I guess it is defined somewhere in the sources. I suggest to retrieve information about the ...
{ "AcceptedAnswerId": "269836", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-05T23:32:19.367", "Id": "269796", "Score": "1", "Tags": [ "c#", "memory-management", "stream" ], "Title": "Download and unzip an XML document" }
269796
<p>I'm attempting to write an algorithm that will find the largest perfect squares of a given integer, subtracting their values from the total each time, as fast as possible. It's somewhat hard to explain, and I apologize for the somewhat ambiguous title, so I'll give some input/output examples:</p> <hr /> <ul> <li><st...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T03:42:51.617", "Id": "532432", "Score": "0", "body": "I set up commander Lambda's panels only five days ago, did he mess them up again already? Takes at most seven squares, no need to worry about speed I'd say." }, { "Conten...
[ { "body": "<h3>A note about <code>Math.sqrt</code></h3>\n<blockquote>\n<p>I feel as though <code>Math.sqrt()</code> can be a bit slow</p>\n</blockquote>\n<p>I thought, since <code>Math.sqrt</code> computes a precise <code>double</code>, maybe if you implement a custom <code>sqrt</code> that computes just up to ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T02:34:06.257", "Id": "269799", "Score": "5", "Tags": [ "java", "performance", "algorithm", "array" ], "Title": "Fastest function to find cumulative largest perfect squares of ...
269799
<p>I'm new to C and was trying to write a generic dynamic array which is type safe. I'm not sure if I pulled it off in the best way possible though.</p> <p>dynarray.h:</p> <pre class="lang-c prettyprint-override"><code>#ifndef h_DynArray #define h_DynArray #define DYNAMIC_ARR_SIZE 10 // Default size for dynamic arrays...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T04:45:31.447", "Id": "532443", "Score": "3", "body": "`$` is not part of the C standard's coding characters." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-08T19:52:09.000", "Id": "532659", "Sco...
[ { "body": "<p><strong>Big task</strong></p>\n<p>OP's goal of &quot;trying to write a generic dynamic array which is type safe.&quot; is admirable, but not a good task for someone new to C.</p>\n<p>I recommend to start with a <em>write a generic dynamic array</em> for <code>void *</code>.</p>\n<p>Later, research...
{ "AcceptedAnswerId": "269874", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T02:56:21.853", "Id": "269801", "Score": "3", "Tags": [ "beginner", "c", "type-safety" ], "Title": "Implementation of a type-safe generic dynamic array in C" }
269801
<p>I have this code that controls the user permissions provided to a user. In my case, I constructed a simple example of CRUD. When the admin checks the boxes, it will grant the user access to perform that operation. For example, if I provide the user the ability to create, they can do so.</p> <p>The code works but I b...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T11:18:58.187", "Id": "532453", "Score": "1", "body": "Welcome to CR! Please choose a title that describes the application's purpose, rather than the goal for the review. Thanks." } ]
[ { "body": "<p>The main points on your code that can be improved are described in the following sections. I can't really find anything that can improve the performance of your code, so i will focus more on how you can shorten your code and make it more readable.</p>\n<h4>Checkboxes state</h4>\n<p>You chose to st...
{ "AcceptedAnswerId": "269809", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T09:32:15.537", "Id": "269805", "Score": "0", "Tags": [ "object-oriented", "json", "react.js", "jsx", "authorization" ], "Title": "React code that controls user permiss...
269805
<p>I have this piece of code where it based on this condition:</p> <ol> <li>Box Color can only be in red, white and black</li> <li>If the box's type is A then any color is allowed</li> <li>Box's type C is not allowed at all</li> <li>For the gift, only green and blue color is allowed and the size cannot be small</li> <l...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T13:10:31.030", "Id": "532462", "Score": "0", "body": "Welcome to Code Review@SE. A `return` statement looks lacking context without a `def`, and the title doesn't follow site conventions: Please (re)visit [How do I ask a Good Questi...
[ { "body": "<p>Yes, this should be simplified. Prefer sets since you're doing membership checks, and write this as a boolean expression rather than a series of <code>if</code> checks with <code>return</code>s:</p>\n<pre><code>return (\n box.type != 'C'\n and (\n box.type == 'A'\n or box.color...
{ "AcceptedAnswerId": "269812", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T12:04:25.537", "Id": "269810", "Score": "1", "Tags": [ "python" ], "Title": "Checking whether box and gift colors satisfy the given criteria" }
269810
<p>My Pagination component provides buttons:</p> <ol> <li>5 around page (i.e: if current page is 3, then it will show button page 2 3 4 5 6)</li> <li>Prev/Next page</li> <li>Button to last page</li> </ol> <p><a href="https://i.stack.imgur.com/xZygs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xZyg...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-08T13:22:21.583", "Id": "532627", "Score": "0", "body": "So what is your question? what is the problem here?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-09T01:24:02.293", "Id": "532679", "Score"...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T12:16:10.000", "Id": "269811", "Score": "0", "Tags": [ "react.js", "jsx", "pagination" ], "Title": "Pagination component using React and Chakra UI" }
269811
<p>This inspired by this <a href="https://codereview.stackexchange.com/questions/269767/find-all-possible-ways-a-rook-can-move-to-a-diagonally-opposite-corner-without-g">C# question</a></p> <p>The basics is to calculate the total number of paths that a rook can take without revisiting a square to move to a diagonally o...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T14:10:23.390", "Id": "532469", "Score": "0", "body": "Using ```std::vector<std::vector<T>>``` for 2D grid is often repeated beginner-like decision. Prefer ```std::array<T, rows * cols> ``` (then you should use rows, cols as template...
[ { "body": "<h1>Use standard integer types</h1>\n<p>Don't use <code>typedef</code> to create your own fixed-size integer types. The standard library provides types like <a href=\"https://en.cppreference.com/w/cpp/types/integer\" rel=\"noreferrer\"><code>std::uint32_t</code> and <code>std::uint64_t</code></a> for...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T12:57:05.197", "Id": "269813", "Score": "6", "Tags": [ "c++", "performance", "c++20" ], "Title": "Find all possible ways a rook can move, C++ version" }
269813
<p>I'm building a tool that requires nested items. For that I use MySQL and Vue but that may not be important.</p> <p>Because MySQL does not really support nested data I created the nested part as JSON. To make the JSON file as small as possible I only store the IDs of the items with no additional data.</p> <h2>Nested ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T13:40:34.437", "Id": "532464", "Score": "0", "body": "Please share the SQL that defines your table. Also: what do the `id` and `children` fields actually represent?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate":...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T13:00:18.017", "Id": "269814", "Score": "0", "Tags": [ "mysql", "json", "nested" ], "Title": "Nested data as JSON - A good idea for scale?" }
269814
<p>As a part of <a href="https://github.com/morgwai/servlet-scopes" rel="nofollow noreferrer">library implementing websocket Guice scopes</a> I need to maintain an object related to each <code>HttpSession</code> called <code>sessionContextAttributes</code>. Currently <code>sessionContextAttributes</code> is stored as a...
[]
[ { "body": "<p>After some more research and thinking, it turned out that both of the above approaches are wrong ;-]<br />\nThe reason for both cases is that user <code>Filter</code>s may put <code>HttpSession</code> object into a wrapper, so neither synchronizing on it nor using it as a key in a <code>Concurrent...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T14:23:07.343", "Id": "269817", "Score": "2", "Tags": [ "java", "concurrency", "servlets" ], "Title": "synchronized access to HttpSession attribute vs static ConcurrentMap with Htt...
269817
<p>I am trying to look for a substring in a list of strings. My end result is an array that contains the presence of substring first based on <code>course.name</code> and then based on <code>course.description</code>. Is there a better way to write the following code?</p> <p>Firstly, I am looking for the substring in t...
[]
[ { "body": "<p>There are several inefficient elements in the implementation.</p>\n<h3>Use a <code>Set</code> instead of an array for fast lookups</h3>\n<p>The code uses <code>uniqueIds</code> to keep track of the ids seen so far.\nThe <code>uniqueIds.includes</code> does a linear scan over the items in the array...
{ "AcceptedAnswerId": "269831", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T14:52:43.610", "Id": "269822", "Score": "2", "Tags": [ "javascript", "strings", "sorting", "react.js", "typescript" ], "Title": "Function to find substring in a list o...
269822
<p>I came across this BMC Genomics paper: <a href="https://doi.org/10.1186/1471-2164-11-464" rel="nofollow noreferrer">Analysis of intra-genomic GC content homogeneity within prokaryotes</a></p> <p>And I implemented some Python functions to make this available as part of a personal project. The functions are these:</p>...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T18:02:40.703", "Id": "532494", "Score": "1", "body": "What are `ec`, `ec_gc`, `ec_non`, `ec_dif`?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T19:52:41.343", "Id": "532498", "Score": "1", ...
[ { "body": "<p>Quite interesting!</p>\n<p>You will benefit from introducing PEP484 type hints.</p>\n<p>Your docstring for <code>get_sequence_chunks</code> is way out of whack; you'll need to revisit your parameter names.</p>\n<p>There isn't a whole lot of benefit from tuple-combination assignment for your <code>...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T17:20:31.717", "Id": "269828", "Score": "4", "Tags": [ "python", "python-3.x", "numpy", "statistics", "bioinformatics" ], "Title": "Function to calculate the GC content va...
269828
<p>My requirement is implementing a <code>Queue&lt;T&gt;</code> (where <code>T</code> is a <code>Lexeme</code>) that is capable of insertion sort and insertion merge.</p> <p>The <code>Lexeme</code> interface:</p> <pre class="lang-kotlin prettyprint-override"><code>/** * A lexeme is the smallest piece of data it is pos...
[]
[ { "body": "<p>A couple improvements I've made, plus I bug I didn't notice.</p>\n<p>To ease lexeme's offsets retrieval, we provide destructuring capability:</p>\n<pre class=\"lang-kotlin prettyprint-override\"><code>interface Lexeme {\n ...\n\n // Provide destructuring capability\n operator fun component1(): ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T18:00:57.813", "Id": "269829", "Score": "2", "Tags": [ "java", "queue", "kotlin" ], "Title": "Merging and sorting queue/list implementation" }
269829
<p>As part of an assignment, I need to write a program which loads a colored image to the screen, converts it to HSI and displays each component in separate grayscale image.</p> <p>My program:</p> <pre><code>#!/usr/bin/env python3 import cv2 import numpy as np import math from PIL import Image from io import BytesIO f...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T18:41:33.783", "Id": "532496", "Score": "0", "body": "Seems right, except that you compute H in radian instead of degrees. Usually degrees are used so that it can be stuck in an integer array. Also, you can use array operations to c...
[ { "body": "<p>It would help future users to either add a hint comment that <code>cv2</code> comes from the pip package <code>opencv-contrib-python-headless</code>, or better yet write an appropriate <code>requirements.txt</code>.</p>\n<p><a href=\"https://www.thedrum.com/creative-works/project/clemenger-bbdo-lo...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-06T18:29:23.217", "Id": "269830", "Score": "2", "Tags": [ "python", "image" ], "Title": "Program which loads a colored image to the screen, converts it to HSI and displays each component...
269830
<p>The most famous library for Support Vector Machine (SVM) algorithm is libsvm (<a href="https://github.com/cjlin1/libsvm/" rel="nofollow noreferrer">https://github.com/cjlin1/libsvm/</a>), but I felt that its code style is too old, I rewrote in newer C++ as a hobby project.</p> <p>Link : <a href="https://github.com/f...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-07T12:28:53.650", "Id": "532546", "Score": "0", "body": "I would suggest the you use templates so that the same code can be used for `float` and `double`." } ]
[ { "body": "<h1>Split <code>SVMTrainData</code> instead of using a variant</h1>\n<p>I think you can avoid the variant by splitting <code>SVMTrainData</code> into a class that holds the full training data, and one that holds a subset of the data using references, perhaps named <code>SVMTrainSet</code>. Have an ea...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-07T01:34:57.550", "Id": "269837", "Score": "3", "Tags": [ "c++", "machine-learning", "numerical-methods", "c++20" ], "Title": "libsvm++ : Rewritten libsvm in newer C++" }
269837
<p>I would like to code review of my program. I would very much like to request a code review. I would like the directory.getfiles statement to retrieve only files with the specified name.</p> <p>Regards</p> <pre><code>using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-07T10:01:10.047", "Id": "532543", "Score": "5", "body": "\"I would like the directory.getfiles statement to retrieve only files with the specified name.\" What does it currently do?" }, { "ContentLicense": "CC BY-SA 4.0", "...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-07T09:03:43.963", "Id": "269842", "Score": "0", "Tags": [ "c#" ], "Title": "Program that retrieves icon name and create sql file" }
269842
<p>The mission:</p> <p>Zero Trim</p> <p>Write a function which trims multiple zero's sequences to a single zero digit. The return value is the updated array. You are not allowed to use another array, and you need to implement it with one pass over the array. In other words, each element in the array should change its i...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-08T09:13:32.063", "Id": "532606", "Score": "0", "body": "You didn't listed `===` in your allowed list but you are using it?" } ]
[ { "body": "<p>To make sure I understood the problem, I scribbled a simple solution.</p>\n<pre><code>// Trim multiple zero's sequences to a single zero digit. \n// The return value is the updated array. \nfunction zeroTrim(a){\n let j = 0;\n for (let i = 0; i &lt; a.length; i++) {\n if (a[i] !== 0 |...
{ "AcceptedAnswerId": "269849", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-07T12:15:37.583", "Id": "269845", "Score": "2", "Tags": [ "javascript", "algorithm", "array" ], "Title": "Zero Trim from array- JavaScript" }
269845
<p>There are already many Tic Tac Toe posts. But as far as I can tell, none of the ones in Haskell are complete with a GUI</p> <p>Here is my implementation with Gloss. <a href="https://gist.github.com/Agnishom/4f2bdcbedbb3714e847ee2d17810ccf6" rel="nofollow noreferrer">Gist Link for convenience</a></p> <pre class="lang...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-21T01:15:24.507", "Id": "533601", "Score": "1", "body": "two small tips: gloss has scale, you can use it instead of resize; don't do two options guards, specially if you need to re-evaluate a expression, that's what ifs are meant for."...
[ { "body": "<p>For tic-tac-toe the efficiency of the scoring function doesn't matter much; you can do exhaustive search (as in your <code>scorePosition</code>) because the search space is very small.</p>\n<p>Perhaps you could encode the positions as a product-of-sum type rather than a tuple of integers, which wo...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-07T14:30:35.180", "Id": "269850", "Score": "8", "Tags": [ "haskell", "tic-tac-toe", "gui", "state-machine", "state" ], "Title": "Haskell Tic-Tac-Toe (with automation and GUI)...
269850
<p>I am trying to learn rust and as such have been redoing some of the challenges on project Rosalind. This one relates to the challenge <a href="http://rosalind.info/problems/perm/" rel="nofollow noreferrer">Enumerating Gene Orders</a>.</p> <pre><code>fn all_combinations(mut combinations: Vec&lt;Vec&lt;usize&gt;&gt;, ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-07T19:46:38.337", "Id": "532581", "Score": "0", "body": "before any Rust comment, you don't need any vec to do that, first find a better algo" } ]
[ { "body": "<p>As already stated, not sure why you're returning vectors; the linked question asks for a number. And with that, you can use big-integers with simple calculations; some already do num-combin and num-perm efficiently behind the scenes.</p>\n<p>Ignoring the algorithm though (since that seems to be y...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-07T18:28:25.610", "Id": "269856", "Score": "2", "Tags": [ "recursion", "rust", "combinatorics" ], "Title": "Finding possible combinations for n<7 with rust" }
269856
<p>I'm a back-end developer (in PHP and Python) and I use JavaScript mostly for DOM manipulation.</p> <p>Now I'm writing a chat app in Node.js and I'm not sure if my code is the cleanest.</p> <p>Here is how it works:</p> <ul> <li>Users open the chat page;</li> <li>We will match them randomly to another user;</li> <li>T...
[]
[ { "body": "<p>In the ready function, don't add to queue, call queue-handler with id.\npop your queue-<strong>list</strong> and if not undefined you've got a match.\nelse add the user to the queue.</p>\n<p>Don't know if you need a <code>MATCH</code>-object at all. You're using it as temporary storage between fun...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-08T02:21:22.253", "Id": "269860", "Score": "4", "Tags": [ "javascript", "node.js" ], "Title": "Random matchmaking for a p2p chat application" }
269860
<p>I have a PHP API which echoes some data depending on the parameters in the URL:</p> <blockquote> <p>URL = &quot;MyWebsite.com/MyAPI.php/username/password&quot;</p> </blockquote> <p>When I try to access this API with Postman, I get the result within 5 seconds, however, using any Android device, I get the result at le...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-08T09:30:51.897", "Id": "532607", "Score": "0", "body": "Welcome to Stack Review, from your code you know you are receiving a json object , there is a specific reason why you chose to see it as a string and not a json object ?" }, ...
[ { "body": "<p>When approaching optimization problems (and it kinda is one as you want to make a call faster) its generally best to first make sure that <strong>you understand exactly what is happening</strong> so when in doubt - <strong>measure</strong> and <strong>debug</strong>.</p>\n<p>Before doing any chang...
{ "AcceptedAnswerId": "269872", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-08T09:02:41.347", "Id": "269867", "Score": "1", "Tags": [ "java", "android" ], "Title": "My Android app is really slow when getting simple data from PHP" }
269867
<p>I was on Hacker Rank for the first time and there was <a href="https://www.hackerrank.com/challenges/py-collections-namedtuple/problem" rel="nofollow noreferrer">a question</a> that required to get the inputs from STDIN and use <code>collections.namedtuple()</code>. It was my first time working with getting inputs f...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-08T22:24:03.117", "Id": "532672", "Score": "0", "body": "@200_success oh so thats what they meant by change the img to text data. Thanks for the edit." } ]
[ { "body": "<blockquote>\n<p>there was a question that required to get the inputs from STDIN and use <code>collections.namedtuple()</code></p>\n</blockquote>\n<p>Really? I don't think that HackerRank would enforce using a named tuple, and using a named tuple isn't hugely helpful here. Plus, if you <em>were</em> ...
{ "AcceptedAnswerId": "269888", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-08T09:12:25.020", "Id": "269868", "Score": "3", "Tags": [ "python", "python-3.x", "programming-challenge", "parsing" ], "Title": "Find the average score, given data in a tabl...
269868
<p>I have created the below script in which I'm trying to set up a class for handling a config file, but also defining some functions that I call from the class methods. Not sure if I'm following the best practices when creating a class.</p> <pre><code># Python3 program to show that we can create # instance variables i...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-08T10:39:06.340", "Id": "532610", "Score": "0", "body": "Hey! Is this a copy paste error: `r'\\\\path\\file.xlsx'` ?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-08T10:57:13.237", "Id": "532611", ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-08T10:21:06.953", "Id": "269871", "Score": "0", "Tags": [ "python", "python-3.x" ], "Title": "Python Class for config file parameters" }
269871
<p>In my .net core console application, I am reading multiple excel files and bulk copy data into a database table. It is working as it is expected, I wonder if there are any improvements to make it better. So I would be glad if you can share your comments.</p> <p>Thanks in advance.</p> <pre><code>class Program { ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-15T15:05:03.873", "Id": "533207", "Score": "2", "body": "Rather than extending the code in a question that has been answered, it might be better to ask a `follow on question` with a link to this question." } ]
[ { "body": "<h1>Missing classes</h1>\n<p>You have failed to include your definition of the <code>User</code> class in the code snippet so I had to create my own.</p>\n\n<pre class=\"lang-cs prettyprint-override\"><code>class User\n{\n public string GameCode { get; set; }\n public int Count { get; set; }\n ...
{ "AcceptedAnswerId": "269979", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-08T12:56:42.207", "Id": "269875", "Score": "2", "Tags": [ "c#", "excel", ".net-core" ], "Title": "Reading excel files and save data into database" }
269875
<p>my models</p> <pre><code>class AssessmentTest(BasicModel): title = models.CharField(max_length=120, unique=True) class UserTestResult(BasicModel): assessment_test = models.ForeignKey(AssessmentTest, on_delete=models.CASCADE, related_name='users_passed') user = models.ForeignKey(User, on_delete=models.C...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-08T14:32:10.863", "Id": "532621", "Score": "0", "body": "Looks like that should be a nested serialiser to me - you're embedding the results for `UserTest` in `AssessmentTest`. Take a look at the [docs](https://www.django-rest-framewor...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-08T13:46:33.527", "Id": "269877", "Score": "1", "Tags": [ "python", "django" ], "Title": "Reduce db queries" }
269877
<p>I am writing my own parser for fasta format. I can't use Biopython or anything else, because it's a part of an assigment and our teacher wants us to try to do it manually. For now, I have done this:</p> <pre><code>def read_file(fasta_file): &quot;Parse fasta file&quot; count = 0 headers = [] sequence...
[]
[ { "body": "<p>Your <code>read_file</code> returns headers and sequences implicitly correlated by their order. A model that is easier to work with is to make sequence class instances that each have their own header and sequence string.</p>\n<p>If you accept <code>fasta_file</code>, then why do you hard-code <cod...
{ "AcceptedAnswerId": "269927", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-08T15:11:55.457", "Id": "269880", "Score": "1", "Tags": [ "python", "parsing", "homework", "bioinformatics" ], "Title": "Python Fasta Parser using dictionaries without using ...
269880