body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I have made a simple Kotlin application called Rock-Paper-Scissor-Lizard-Spock. The application takes in user input and check if belongs to given set of array. If it belongs then it compares user input and random value from array to generate result. Else it prints error and asks for user input again. My code is work...
[]
[ { "body": "<p>Whenever you see repetitious code like your very long if/else statement, you can probably make it a lot simpler. In this case, you can create a collection to concisely store what beats what as a list of relationships. This is a lot more maintainable if you are debugging later or find that you need...
{ "AcceptedAnswerId": "257584", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-23T06:37:40.103", "Id": "257557", "Score": "4", "Tags": [ "kotlin" ], "Title": "Rock-Paper-Scissor-Lizard-Spock in Kotlin" }
257557
<p>Is there any better way to re-write my code :</p> <pre><code>class ContactView(viewsets.ViewSet): @action(methods=['get'], detail=False) def filter(self, request, pk=None): search = request.query_params.get('search') print(search) queryset = Contact.objects.all().filter( ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-23T09:00:33.940", "Id": "508721", "Score": "0", "body": "Welcome to CodeReview. Could you please elaborate on *better*? From what aspect?" } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-23T08:51:46.443", "Id": "257559", "Score": "0", "Tags": [ "python", "django" ], "Title": "Contacts viewset" }
257559
<h1><a href="https://github.com/camurban/pterasoftware" rel="noreferrer">Ptera Software</a></h1> <p><em>A Flapping Wing Aerodynamics Simulator Written in Python</em></p> <p><a href="https://i.stack.imgur.com/1KzjB.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/1KzjB.gif" alt="output" /></a> <a href="https://...
[]
[ { "body": "<p>I concur with your conclusions with your goals, especially 1-3.</p>\n<p>I think it's fantastic.</p>\n<p>For goal 5 it's hard to say. I've the feeling it <em>is</em> quite a niche project\nin a way. For example I haven't got a clue of how many people are\ngenerally working in that area, let alone...
{ "AcceptedAnswerId": "257702", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-23T08:51:50.427", "Id": "257560", "Score": "11", "Tags": [ "python", "performance", "numpy", "simulation", "numba" ], "Title": "From Hummingbirds to Ornithopters: Simulat...
257560
<p>I have programmed a function to split strings, and it gives the expected output. I am looking forward to write better code and I was told here is a good place to start.</p> <p>Here's my program:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; char **split(char *str) { ...
[]
[ { "body": "<p>First, I'll address your issue within the main function. Where you've marked your issue, <code>sizeof(ss)</code> isn't returning the number of elements, it's returning the size of the ss variable which is a pointer. It's the same as <code>sizeof(char *)</code> (which is typically 8 on most platfor...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-23T12:17:51.140", "Id": "257569", "Score": "4", "Tags": [ "algorithm", "c", "strings", "functional-programming" ], "Title": "Split function using C and dynamic memory allocation"...
257569
<p>So I am trying to create a small C# application which generates a deck of cards, and ask to the user if they want to shuffle the deck, and then display 1 card at a time to the user. Would this be effective use of classes 4 rules of oop? Thanks</p> <pre><code>using System; using System.Collections.Generic; using Syst...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-23T14:59:29.790", "Id": "508735", "Score": "0", "body": "At the first glance I would say the abstractions and encapsulation are nailed. On the other hand it does support only one type of card set (French-suited cards). In case of OOP i...
[ { "body": "<p>Sorry for quick review. Work is pressing but rather than a conversation in comments, this will have to suffice.</p>\n<p>There are lots of examples of C# and card games here at CR. Maybe you could search for them and review since many of those answers are quite good.</p>\n<p>The better answers us...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-23T14:39:41.597", "Id": "257575", "Score": "3", "Tags": [ "object-oriented" ], "Title": "game in oop mini game" }
257575
<p>I have a C code, that takes edges of weighted graph and some point a<br> It returns minimal distances from point a to others and previous point in way, which have minimal length (best way).</p> <p>For example, if best way is a → b → c:</p> <ul> <li>previous point for a is null/-1/-2 ...</li> <li>previous point for b...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T00:24:49.330", "Id": "508796", "Score": "0", "body": "Can you mention the algorithm you implemented? I think Dijkstra's algorithm should be enough for most cases and much easy to implement. Thanks." }, { "ContentLicense": "C...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-23T15:43:20.163", "Id": "257578", "Score": "0", "Tags": [ "performance", "algorithm", "c" ], "Title": "Shortest path algorithm for weighted graphs, targeting web-assembly" }
257578
<p>I'm writing C++ Windows code that will start a process, then read its stdout and stderr, separately, into buffers.</p> <p>If I try to just read the streams one at a time it may hang if the child process is trying to write to the other stream. So I learned I need to create named pipes, and then make calls to ReadFile...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-23T17:44:45.763", "Id": "257581", "Score": "2", "Tags": [ "c++", "stream", "winapi", "child-process" ], "Title": "Reading stdout and stderr of a sub process using Win32, Overlapp...
257581
<p>I have implemented a radix sort algorithm in Python 3. It first finds the maximum number of digits in the list, then changes them to strings and adds 0's. For example, [7, 23, 107, 1, 53] to ['007', '023', '107', '001', '053']. I then make a new matrix, [[] * 10]. I append the numbers with last digit of 0 in lst[0]...
[]
[ { "body": "<pre><code> #flattened list, reusing lst to save memory\n lst = []\n</code></pre>\n<p>That doesn't save memory. The caller of the current <code>helper</code> call still has a reference to the &quot;old&quot; list, so it'll remain in memory in addition to this new one. You'll have one li...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-23T19:12:46.070", "Id": "257588", "Score": "4", "Tags": [ "python", "python-3.x", "sorting", "radix-sort" ], "Title": "Radix Sort Speed" }
257588
<p>I am writing an object oriented shape detector, first time in Python. I come from a Java background. Can you provide any coding advice?</p> <p><a href="https://www.pyimagesearch.com/2016/02/08/opencv-shape-detection/" rel="nofollow noreferrer">https://www.pyimagesearch.com/2016/02/08/opencv-shape-detection/</a></p> ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-23T22:18:58.160", "Id": "508787", "Score": "1", "body": "Could you include your imports as well? Where is `DrawingItem` defined? What is `cv2`?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-23T22:23:12.03...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-23T20:22:06.813", "Id": "257591", "Score": "1", "Tags": [ "python", "python-3.x" ], "Title": "Python shape detector code" }
257591
<p>I wrote an HTML parser in JavaScript, where it takes an a string that represents the HTML</p> <pre class="lang-js prettyprint-override"><code>const html = `&lt;div&gt; &lt;div&gt; foo &lt;/div&gt; &lt;div&gt; bar &lt;/div&gt; &lt;/div&gt;` </code></pre> <p>And it should output an object like this</p> <pre class="la...
[]
[ { "body": "<h2>General review points</h2>\n<ul>\n<li>Use semicolons</li>\n<li>Try to avoid Array iterator functions in favor of for of. Generally use array iterators when you want the iteration to be an expression.</li>\n</ul>\n<p>Apart from that the code looks good and is an elegant solution to parsing simple ...
{ "AcceptedAnswerId": "257706", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-23T20:28:53.073", "Id": "257592", "Score": "3", "Tags": [ "javascript", "html", "json" ], "Title": "HTML parser written in JavaScript that takes in strings and output a DOM tree ...
257592
<p>I have:</p> <ul> <li>A dataframe with Identifiers (<code>TermId</code>) and Search Terms (<code>SearchTerm</code>).</li> <li>A list of text strings (<code>MyText</code>). This likely would be a column (series) in a dataframe.</li> </ul> <p>I for every string in <code>MyText</code> I want to get a count of hits for ...
[]
[ { "body": "<p>An idiomatic approach would be to put <code>MyText</code> in a dataframe (if not already) and <a href=\"https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.assign.html\" rel=\"nofollow noreferrer\"><strong><code>assign()</code></strong></a> the results of <a href=\"https://pandas.pydata....
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T01:59:00.400", "Id": "257601", "Score": "2", "Tags": [ "python", "beginner", "regex", "pandas" ], "Title": "Martix of Counts of Regex Hits Over a List of Strings" }
257601
<p>In this program, I have done automation using Selenium, to find english meaning of each sanskrit word from a dictionary website.</p> <p>The function <code>eng_meaning</code> accepts the word and using selenium and BeautifulSoup scarps the website and find english meaning.</p> <pre><code>def eng_meaning(word): &q...
[]
[ { "body": "<p>The most obvious bottleneck in your code is that you are calling the function <code>eng_meaning</code> in a loop, but that function creates a new Selenium instance everytime, which is an expensive operation. Imagine that you are searching in Google then systematically closing and reopening your br...
{ "AcceptedAnswerId": "257638", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T06:37:21.280", "Id": "257603", "Score": "2", "Tags": [ "python", "performance", "beautifulsoup", "selenium", "automation" ], "Title": "Scrape and parse dictionary webs...
257603
<p>im developing a program that will read text files and convert it to JSON format dynamically. Users are able to input the key name and their respective digit to slice the index from a raw text file. Everything is working fine when reading a small size file, but whenever the text files is huge, the program will load l...
[]
[ { "body": "<ul>\n<li><p>Keys names, and start and end indices do not ever change. It makes no sense to test them at each iteration. Move all the error checking fragments outside of the loop.</p>\n<p>Same applies to <code>content</code> slicing. Compute the boundaries beforehand.</p>\n</li>\n<li><p>The first lin...
{ "AcceptedAnswerId": "257642", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T06:46:16.153", "Id": "257604", "Score": "0", "Tags": [ "python", "json" ], "Title": "Make a loop faster when reading large text files" }
257604
<p><em>Why after declaring a variable for String array, it can be passed to a method that accepts object array? Now, <code>String</code> is a class by itself so I assumed a long time ago that all variable is object at a sense. But many argued with me about it. But here it shows the same kind of behaviour.</em></p> <p><...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T10:32:34.770", "Id": "508831", "Score": "3", "body": "Did you write this? Do you always indent your code like this? What is the goal of the code? Please take a look at the [help/on-topic]." } ]
[ { "body": "<p>String extends Object type: <a href=\"https://docs.oracle.com/javase/7/docs/api/java/lang/String.html\" rel=\"nofollow noreferrer\">https://docs.oracle.com/javase/7/docs/api/java/lang/String.html</a>\nThis means that String's superclass is Object, so any function that requires an Object as paramet...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T08:15:45.970", "Id": "257605", "Score": "-1", "Tags": [ "java", "object-oriented" ], "Title": "Can A String array be passed as a parameter to a method that takes object array as argum...
257605
<p>I asked <a href="https://stackoverflow.com/questions/66769861/how-is-my-almostincreasingsequencesequence-code-incorrect-codesignal">this</a> question on Stackoverflow as well, but I think it's best suited here because my code needs optimization instead of error checking (that I previously thought).</p> <p>I've made ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-31T01:17:58.013", "Id": "510470", "Score": "0", "body": "Please define \"almost\"." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-31T01:18:54.193", "Id": "510471", "Score": "0", "body": "Since ...
[ { "body": "<h2>Checking if a list is strictly increasing</h2>\n<p>The inner loop checks if a list (in this case <code>newList</code>) is strictly increasing:</p>\n<pre class=\"lang-py prettyprint-override\"><code>j = 0\nin_order = True\nwhile j &lt; len(newlist) - 1:\n if newlist[j+1] &lt;= newlist[j]:\n ...
{ "AcceptedAnswerId": "257660", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T08:26:16.123", "Id": "257606", "Score": "3", "Tags": [ "performance", "python-3.x" ], "Title": "My 'almostIncreasingSequence(sequence)' code is too slow for lists that have 10000+...
257606
<p>I want to use <code>python -c</code> to remove wheel files from the <code>dist/</code> directory in my project. (*)</p> <p>Actually, I use the following command:</p> <pre class="lang-sh prettyprint-override"><code>python -c &quot;from pathlib import Path; [p.unlink() for p in Path('dist').glob('Pascal_Scraper-*.whl'...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T09:25:02.513", "Id": "508824", "Score": "0", "body": "Is there a reason you want to use `python -c` for this? I think `rm dist/Pascal_Scaper-*.whl` would be clearer." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate"...
[ { "body": "<p>If you need to use python for being crossplattform and if you need to do this in one line then this is the way to go, yes.</p>\n<p>For some reason</p>\n<p>Alternatives to consider:</p>\n<ul>\n<li>put the code in a file so you can make it more readable</li>\n<li>create a Makefile and run this under...
{ "AcceptedAnswerId": "257674", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T09:07:16.300", "Id": "257607", "Score": "0", "Tags": [ "python", "python-3.x", "console" ], "Title": "for loop in one line (for python -c)" }
257607
<p>Pydantic is a Python package used for data validation and settings management using Python type annotations. Enforcing typehints and providing errors when invalid data is encountered at runtime.</p> <p>The package is also available as plugin.</p> <p><a href="https://pydantic-docs.helpmanual.io/" rel="nofollow norefe...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T10:38:17.013", "Id": "257610", "Score": "0", "Tags": null, "Title": null }
257610
Package for data validation and settings management.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T10:38:17.013", "Id": "257611", "Score": "0", "Tags": null, "Title": null }
257611
<p>I have written my own take on <a href="https://semver.org/" rel="nofollow noreferrer">semantic versioning</a>. Parsing it is not really hard, but I feel like my parsing could be more optimal, more readable and feel more like a parser. Currently, there is this <code>unread</code> method that I don't see in most parse...
[]
[ { "body": "<p>On the whole, the code was easy to read, and the tests were concise (apart from the fully qualified <code>be.imgn.common.base.Version.valueOf</code> call. Here's a few things to think about.</p>\n<h2>Object Lifetime</h2>\n<p>The <code>VersionParser</code> class takes in a <code>String</code> and ...
{ "AcceptedAnswerId": "257620", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T12:24:32.300", "Id": "257614", "Score": "3", "Tags": [ "java" ], "Title": "Parsing Semver versions" }
257614
<p>I created a simple minesweeper game in c#, and wanted to know how to improve it. I didn't really understand how to make it so everything besides the zero opens up.</p> <p>How would I make my class Board better?</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T14:48:07.627", "Id": "508850", "Score": "1", "body": "Ok, i will edit it" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T16:22:59.380", "Id": "508864", "Score": "4", "body": "Please add th...
[ { "body": "<p>As far I understand you need to intersect your 5x5 board with a 3x3 square with a center in <code>mine1</code>.<br />\nIt could be achieved via 2D loop (2 nested loops).</p>\n<ol>\n<li><p>First (optional), if you use an old version of .NET that don't have the <a href=\"https://docs.microsoft.com/e...
{ "AcceptedAnswerId": "257639", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T13:20:37.570", "Id": "257615", "Score": "2", "Tags": [ "c#", "game", "console", "minesweeper" ], "Title": "Minesweeper in C# Console - Board Implementation" }
257615
<p>I have a class that inherits from Dictionary&lt;Tkey, TValue&gt;.</p> <p>I need my Value part of the KeyValue pair to be a a Tuple (int, bool )</p> <pre><code>public class IssueRowValidationDictionary : Dictionary&lt;string, (int, bool)&gt; { public IssueRowValidationDictionary() : base() { } ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T15:07:08.747", "Id": "508852", "Score": "1", "body": "Far from PC but try `Dictionary<string, (int RowNumber, bool Value)>`, then try `issueRowValidationDictionary['keyRef'].RowNumber`" }, { "ContentLicense": "CC BY-SA 4.0",...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T14:45:47.577", "Id": "257619", "Score": "1", "Tags": [ "c#" ], "Title": "Inheriting from Dictionary class with tuple as value" }
257619
<p>Is there a better way to refactor my below code where I have many conditions in if and else statement</p> <p>The reason for refactoring is to make code cleaner and readable</p> <pre><code> public static PaymentOptions GetPaymentOptions_Auto(TestConfigurationCDO testConfiguration, int siteId) { var paymentOpti...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T16:36:58.553", "Id": "508868", "Score": "0", "body": "@canton7 - Can you please help me?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T17:03:28.377", "Id": "508873", "Score": "0", "body"...
[ { "body": "<ol>\n<li><p>Extract the statements into methods.\nLike:\n<code>paymentAuto.IsKlarnaPayment()</code></p>\n<p>This would shorten the <code>if</code> statements a bit.</p>\n</li>\n<li><p>At the end you have</p>\n<pre><code>else if (paymentAuto.PaymentType == PaymentMethod.PayPalExpress)\n{\n payment...
{ "AcceptedAnswerId": "257622", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T16:34:17.777", "Id": "257621", "Score": "1", "Tags": [ "c#" ], "Title": "Is there a way to refactor the c# code having multiple conditions?" }
257621
<p>This is my first attempt at open source contribution via a Python discord bot, built to analyse user-uploaded log files and give quick, at-a-glance information for support staff.</p> <p>The PR is here: <a href="https://github.com/Ryujinx/ryuko-ng/pull/3" rel="nofollow noreferrer">https://github.com/Ryujinx/ryuko-ng/...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T16:47:00.230", "Id": "257625", "Score": "1", "Tags": [ "python", "python-3.x" ], "Title": "Nintendo Switch emulator log analysis Discord bot" }
257625
<p>Please review my php paypal payment gateway code.</p> <p>Are there any bugs in the code? Any security risks? How could this code be improved?</p> <p>Brief instructions to be able to run the code:</p> <ol> <li>install xampp and configure</li> <li>create directory within htdocs dir named innovations-r-us</li> <li>cd ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T17:40:39.783", "Id": "257626", "Score": "0", "Tags": [ "php", "e-commerce" ], "Title": "PHP paypal payment processing code" }
257626
<p>Given two vectors of ints, write a program to determine whether one vector is a prefix of the other.</p> <ul> <li>For vectors of unequal length, compare the number of elements of the smaller vector.</li> <li>For example, given the vectors containing 0, 1, 1, 2, and 0, 1, 1, 2, 3, 5, 8, respectively, your program sho...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T15:26:48.647", "Id": "508961", "Score": "0", "body": "The title is a bit ambiguous. Do you mean that for two vectors you need to figure out which is a prefix, or **if** one is a prefix of the other? If so, do you need to tell which ...
[ { "body": "<pre><code>const decltype(ivec1.size()) size = ivec1.size() &lt; ivec2.size() ? ivec1.size() : ivec2.size();\n</code></pre>\n<p>Could just be:</p>\n<pre><code>const auto size = std::min(ivec1.size(), ivec2.size());\n</code></pre>\n<hr />\n<pre><code>const std::vector&lt;int&gt;&amp; bigVec = smallVec...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T17:59:41.163", "Id": "257629", "Score": "4", "Tags": [ "c++", "vectors", "iteration" ], "Title": "Given two vectors of ints, determine whether one vector is a prefix of the other"...
257629
<p>I'm working on a solution that is correct but inefficient.</p> <p><a href="https://app.codility.com/programmers/task/leader_slice_inc/" rel="nofollow noreferrer">https://app.codility.com/programmers/task/leader_slice_inc/</a></p> <p>This is my code :</p> <pre><code>public static void main(String[] args) { int[] ...
[]
[ { "body": "<p>Nice solution, find below my suggestions.</p>\n<hr />\n<p>Creating a list from a set:</p>\n<pre><code>List&lt;Integer&gt; listaLideresOrdenada = new ArrayList&lt;Integer&gt;();\nlistaLideresOrdenada.addAll(listaLideres);\n</code></pre>\n<p>The set can be passed directly to the constructor of <code...
{ "AcceptedAnswerId": "257736", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T18:02:18.423", "Id": "257630", "Score": "2", "Tags": [ "java", "performance", "programming-challenge", "array" ], "Title": "Molybdenum2019 challenge efficient implementati...
257630
<p>I have some code that manipulates a Pandas Dataframe containing Covid-19 vaccine data and displays it on Matplotlib.</p> <p>The data is here: <a href="https://covid.ourworldindata.org/data/owid-covid-data.csv" rel="nofollow noreferrer">https://covid.ourworldindata.org/data/owid-covid-data.csv</a> (downloads CSV).</p...
[]
[ { "body": "<p>The loop and <code>countries</code> section can be replaced with a single <a href=\"https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.filter.html\" rel=\"nofollow noreferrer\"><strong><code>DataFrameGroupBy.filter</code></strong></a>:</p>\n<ul>\n<li><c...
{ "AcceptedAnswerId": "258808", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T19:12:04.580", "Id": "257631", "Score": "3", "Tags": [ "python", "csv", "pandas", "matplotlib" ], "Title": "Manipulating Pandas Dataframe with vaccination data from CSV to...
257631
<p>While posting this, I noticed there are <em>quite</em> a few similar C hash table implementations here already. So I figured one more wouldn't hurt. :-) In any case, I'm writing a teaching article on &quot;how to implement a hash table in C&quot;, and I'm wondering if I can get some feedback on my implementation (<c...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T21:27:08.533", "Id": "509007", "Score": "1", "body": "Is there any reason why you would use FNV1 and not use FNV1a?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T21:45:05.083", "Id": "509012", ...
[ { "body": "<ul>\n<li><p><code>// Don't use these fields directly</code> means that they do not belong to the public interface. Consider declaring</p>\n<pre><code> typedef struct ht ht;\n</code></pre>\n<p>in <code>ht.h</code>, and spelling it out in <code>ht.c</code>. Ditto for <code>hti</code>.</p>\n<p><code>_...
{ "AcceptedAnswerId": "257649", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T20:10:19.577", "Id": "257634", "Score": "5", "Tags": [ "c", "hash-map", "collections" ], "Title": "Hash table implemented in C with open addressing" }
257634
<p>Background: In tcsh we can use single quotes inside single quote like this (like it said <a href="https://unix.stackexchange.com/questions/187651/how-to-echo-single-quote-when-using-single-quote-to-wrap-special-characters-in">here</a>):</p> <pre><code>echo 'It'\''s Shell Programming' </code></pre> <p>I want to creat...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T08:57:19.993", "Id": "508936", "Score": "0", "body": "Beside the fact that I find it weird do do this \"on the fly\" in Java (outside of a more complex application) have you ever heard of [regular expressions](https://docs.oracle.co...
[ { "body": "<p>I'd suggest a Solution based on <em>regular expressions</em> like this:</p>\n<pre><code>import static org.junit.Assert.assertThat;\n\nimport java.util.Optional;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\nimport org.hamcrest.CoreMatchers;\nimport org.junit.Test;\n\npublic ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T20:22:40.217", "Id": "257636", "Score": "6", "Tags": [ "java" ], "Title": "Implementing a method that escapes single quotes in a string" }
257636
<p>I'm pretty darn new to C# and to be honest in programming.</p> <p>I'm experimenting on making a cash register type program and I picked WPF because its been recommended as better than Forms when it comes to resizing and graphics stuff.</p> <p>I'm looking for feedback on how I could better my XAML.</p> <pre><code> ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T23:03:35.450", "Id": "508895", "Score": "2", "body": "Welcome to Code Review! I [changed the title](https://codereview.stackexchange.com/revisions/257643/2) so that it describes what the code does per [site goals](https://codereview...
[ { "body": "<p>Have you tried <strong>Suggested Actions</strong></p>\n<p>There is a new feature called <strong>Suggested Actions</strong> that enables easy access to common properties when a control is selected. This feature is available in <a href=\"https://visualstudio.microsoft.com/vs/preview/\" rel=\"nofoll...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T22:50:43.310", "Id": "257643", "Score": "2", "Tags": [ "c#", "beginner", "wpf", "xaml" ], "Title": "Cash register form" }
257643
<p>Many times I have copy and pasted from a guide that had the following instruction:</p> <blockquote> <p>$ echo &quot;Execute xyz&quot;</p> </blockquote> <p>and would get the error</p> <blockquote> <p>$: command not found</p> </blockquote> <p>So I created a bash script to ignore the '$' at the beginning; The solution ...
[]
[ { "body": "<p>Cute idea. It's not so simple, though.</p>\n<p>For example, compare the outputs of</p>\n<pre><code>echo 'a b'\n</code></pre>\n<p>with</p>\n<pre><code>$ echo 'a b'\n</code></pre>\n<p>(because of word splitting).</p>\n<p>Also, it fails for compound commands like</p>\n<pre><code>for i in a b c ; ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-24T22:58:32.727", "Id": "257645", "Score": "0", "Tags": [ "bash", "linux" ], "Title": "Linux bash script to ignore '$'" }
257645
<p>A couple months ago I made an interactive dijktra visualizer that allowed the user to setup the map nodes and run the algorithm. I thought it was a good way to solidify my algorithm and html/css knowledge. I'd like for you guys to test my application out and give any advice in any way I could make it better.</p> <p>...
[]
[ { "body": "<p>I don't know if there is a way to avoid the nested loop in this case because you need to do a calc that involves every inner loop index with every outer loop index.</p>\n<p>But I think that is not necessary to calculate <code>row * mapWidth</code> in every iteration in the inner loop, once that bo...
{ "AcceptedAnswerId": "257681", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T00:43:56.917", "Id": "257650", "Score": "1", "Tags": [ "javascript", "html", "css" ], "Title": "Dijktra's Algorithm Visualizer" }
257650
<p>Here is my shot at <a href="https://www.cis.upenn.edu/%7Ecis194/spring13/hw/08-IO.pdf" rel="nofollow noreferrer">Homework 8</a> of <a href="https://www.cis.upenn.edu/%7Ecis194/spring13/hw/08-IO.pdf" rel="nofollow noreferrer">CIS-194</a> (from Spring '13). The problem is about a hierarchy of employees at a company (a...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T09:29:02.293", "Id": "508938", "Score": "0", "body": "@bisserlis \"Employee\" in my post is a URL that leads to the file https://www.cis.upenn.edu/~cis194/spring13/extras/08-IO/Employee.hs" }, { "ContentLicense": "CC BY-SA 4...
[ { "body": "<p>Unfortunately, there is a bug in <code>glCons</code>. The employee's fun should get added, not replace the current fun level:</p>\n<pre><code>glCons :: Employee -&gt; GuestList -&gt; GuestList\nglCons emp (GL a b) = GL (a ++ [emp]) (empFun emp)\n -- ^\n</code></pre>\n<p>But let's stay...
{ "AcceptedAnswerId": "258807", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T01:43:36.243", "Id": "257652", "Score": "2", "Tags": [ "beginner", "haskell", "tree", "dynamic-programming" ], "Title": "Haskell Dynamic Programming on a Tree" }
257652
<p>I'm a beginner both in Python and Tensorflow.</p> <p>I made a toy neural network to learn both.</p> <p>The objective of the NN is to identify the module c, or separation between lines defined by random points, and the width ε of each line, as show on this image, which shows a single sample taken from the ones used t...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T03:21:45.157", "Id": "257653", "Score": "3", "Tags": [ "beginner", "python-3.x", "tensorflow" ], "Title": "Toy neural network give poor results" }
257653
<h1>Introduction</h1> <p>I have implemented an algorithm that applies auto tiling to a 2D tile map for a game, selecting the correct tiles according to their neighborhood. Given a string representation in a classic roguelike form such as this</p> <p><a href="https://i.stack.imgur.com/G9q8D.png" rel="nofollow noreferrer...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-21T11:38:18.173", "Id": "512538", "Score": "0", "body": "You could also just create a giant jump table with all possible combinations for your algorithm." } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T04:33:04.837", "Id": "257655", "Score": "3", "Tags": [ "c++", "c++17", "iteration" ], "Title": "Algorithm for auto tiling of tiles in a 2D tile map" }
257655
<p>I'm a rookie in c++ programming. Recently, caesar ciphers caught my eye. I ended up making a rot&lt;N&gt; text converter, where N is any value between 2 and 25. Please keep in mind that I'm still new to programming and don't know advanced level stuff. All your feedbacks will be appreciated. FYI, this was developed i...
[]
[ { "body": "<pre><code>std::string user_input;//user input string\n</code></pre>\n<p>In C++ you don't need to declare variables before you use them. I would strongly recommend doing so, otherwise readers will have problems with the text. You certainly should not use namespace / global variables unless they are r...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T05:38:31.443", "Id": "257659", "Score": "1", "Tags": [ "c++", "beginner", "caesar-cipher" ], "Title": "caesar cipher (rot<2-25>)" }
257659
<p>I'd like to emplace a lambda which captured a unique-pointer into a container, but it failed to compile under GCC 7.3.0 as C++17. From the error messages, it's calling the copy constructor of <code>unique_ptr</code> when constructing function.</p> <p><a href="https://wandbox.org/permlink/ECFI05J8obWMqhxE" rel="nofol...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T07:33:47.507", "Id": "508928", "Score": "1", "body": "Welcome to CodeReview. Please try to stick to use english only." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T21:24:52.567", "Id": "509005",...
[]
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T07:04:43.673", "Id": "257663", "Score": "5", "Tags": [ "c++", "lambda" ], "Title": "Emplace a lambda which captured a unique_ptr into container like queue" }
257663
<p>here I leave my code for a repository pattern with NHibernate and Autofac. I would like to receive some feedback about it. Especially about the session handling with NHibernate. By now I don't like the way that is implemented. Currently the session is created in an IHttpModule on the beginning of the request. Could ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T08:00:25.147", "Id": "257665", "Score": "2", "Tags": [ "c#", ".net", "asp.net-web-api", "autofac" ], "Title": "How to make a good session handling with NHibernate?" }
257665
<p>this is my very first pandas/matplotlib code and I would be grateful if you can review my code and share your thoughts or ideas for improvement. Please focus on code, not the features of resulting chart. Thank you for you opinion.</p> <p>The purpose of code is to create <a href="https://en.wikipedia.org/wiki/Gantt_c...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-28T18:29:59.710", "Id": "510261", "Score": "1", "body": "Note that your `Duration` is small enough to be `.astype('uint8')`. Also you can encode your `Category` explicitly `.astype('category')`. Not too relevant for this data, but usef...
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T08:03:49.570", "Id": "257666", "Score": "3", "Tags": [ "python", "pandas", "matplotlib" ], "Title": "Modified Gantt Chart" }
257666
<p>I want to generate wind data with the use of MCMC. The results I am getting are quite off from the measured mean values not sure why.</p> <h3>SIMULATE WIND DATA</h3> <pre><code>## Import the packages ######## from sklearn.cluster import KMeans ### Let's generate some &quot;wind&quot; data from Weibul ### Wind_sim=n...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T08:43:28.273", "Id": "257667", "Score": "0", "Tags": [ "python-3.x", "markov-chain" ], "Title": "Markov Chain Monte Carlo (MCMC) wind simulate" }
257667
<p>I am currently using a <code>SimpleConnectionPool</code> from <code>psycopg2</code> to lease transactions to a PostgreSQL database and would like a review of my current implementation.</p> <h3>Code</h3> <pre class="lang-py prettyprint-override"><code>from contextlib import contextmanager from dataclasses import data...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T11:44:35.803", "Id": "257671", "Score": "2", "Tags": [ "python", "postgresql", "connection-pool" ], "Title": "Simple Connection Pooling with psycopg2" }
257671
<p>I created a tic-tac-toe game implementaiton in rust. What I can do to make this tic-tac-toe code a better code?</p> <p><strong>game.rs</strong></p> <pre><code>pub struct Board { board: Vec&lt;Vec&lt;char&gt;&gt;, } pub struct Cell { x: usize, y: usize, } pub enum ErrCoordinates { InvalidSub, } pub ...
[]
[ { "body": "<p>I see you've absorbed many things I mentioned in my <a href=\"https://codereview.stackexchange.com/a/257434/188857\">last review</a>\n— well done!</p>\n<p>Coincidentally (or perhaps not, since tic-tac-toe is a common exercise\nfor beginners), I wrote <a href=\"https://codereview.stackexchange.com/...
{ "AcceptedAnswerId": "259006", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T11:59:50.973", "Id": "257672", "Score": "3", "Tags": [ "beginner", "rust", "tic-tac-toe" ], "Title": "Tic-tac-toe implementation" }
257672
<p>I have a below snippet, here I am using <code>array.find</code> to find the first success case and end it. So here is the code snippet</p> <pre><code>const USERS_LIST = [ { key: &quot;john&quot;, location: &quot;dublin&quot;, }, { key: &quot;joe&quot;, subKeys: [ { key: &quot;jane...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T14:26:46.177", "Id": "508956", "Score": "0", "body": "Welcome to Code Review! To give reviewers a better picture of what the code does please describe how the result of calling `USERS_LIST.find()` is ultimately used, as well as defi...
[ { "body": "<p>Another way to write the same thing is:</p>\n<pre><code>const findUser = list =&gt; list.find(u =&gt; {\n if(u.subKeys) {\n return findUser(u.subKeys);\n }\n if(checkEligible({action: u.key}) {\n callback(u);\n return true; // necessary to stop the loop\n }\n});\n\nfindUser(USERS_LIST...
{ "AcceptedAnswerId": "257685", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T12:52:12.943", "Id": "257675", "Score": "2", "Tags": [ "javascript" ], "Title": "Finding the right property value from array of objects" }
257675
<p>I'm currently trying to do data quality checks in python primarily using <code>Pandas</code>.</p> <p>The code below is fit for purpose. The idea is to do the checks in Python and export to an Excel file, for audit reasons.</p> <p>I perform checks like the below in 4 different files, sometimes checking if entries in ...
[]
[ { "body": "<p>It seems difficult to comment on the <em>meaningfulness</em> of your proposed solution. You are the one to decide on that since you know the context around your problem. With that being said, I'm afraid there is not much to go on here.</p>\n<p>Nevertheless, one observation I make about your code i...
{ "AcceptedAnswerId": "258980", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T14:45:01.970", "Id": "257676", "Score": "0", "Tags": [ "python", "pandas" ], "Title": "Function to perform checks on data" }
257676
<p>don't blame me I am trying to learn, the code works but I am not sure it is well optimized. Please tell me if you see something wrong. My goal is to achieve most optimized code (and learn something in between).</p> <ol> <li>User register -&gt; check if username or email exists , if not = insert into database</li> <l...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-29T21:37:57.010", "Id": "510385", "Score": "0", "body": "Perhaps you're thinking why nobody is responding to your question? Well, I think it's because there's not much to comment on. You've used prepared statements and the standard way...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T14:48:46.100", "Id": "257677", "Score": "1", "Tags": [ "performance", "php", "pdo" ], "Title": "Registration and login via PDO" }
257677
<p>I am cleaning a HTML string to encode the less than sign (&lt;) to a HTML entity (<code>&amp;lt;</code>), but leaving the HTML tags as they are. An example is converting <code>&quot;&lt;div&gt;Total &lt; 500&lt;/div&gt;&quot;</code> to <code>&quot;&lt;div&gt;Total &amp;lt; 500&lt;/div&gt;&quot;</code>.</p> <p>There'...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T15:24:29.033", "Id": "508960", "Score": "2", "body": "Welcome to CodeReview! Have you tested your implementation against other inputs as well?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T20:17:52....
[ { "body": "<ul>\n<li><p>Every time you call <code>Substring</code>, <code>Remove</code>, <code>Replace</code> or any other method which modifies the <code>string</code>, you create new <code>string</code> instance with new memory allocation. Because <code>string</code> is immutable. All <code>string</code> oper...
{ "AcceptedAnswerId": "257737", "CommentCount": "10", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T14:54:44.387", "Id": "257678", "Score": "1", "Tags": [ "c#", "strings", "html", "encoding" ], "Title": "Method encodes all less than (<) characters in a HTML string, but ...
257678
<p>I have a dataframe <code>data</code> with several columns and for each columns there are 10 years of daily data on average, something around 4000 rows then. The dataframe looks like this:</p> <pre><code>Date A B C ... YYYY-MM-DD 123.4 56.7 89.0 YYYY-MM-DD 12.34 -5.6 NaN ... </cod...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-31T14:00:36.533", "Id": "510510", "Score": "2", "body": "You're doing exhaustive search which is the \"last resort\" of numerical optimization. How smooth are your data? How likely is it that a more traditional numerical optimizer woul...
[ { "body": "<p><strong>Answer, part one</strong></p>\n<p>It looks like about half the loops can be avoided by doing the <code>True</code> and <code>False</code> cases at the same time. These differ only by the multiplication by -1 at the end of <code>fct</code>. That suggests that results of of a <code>True</c...
{ "AcceptedAnswerId": "258924", "CommentCount": "9", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T16:01:39.923", "Id": "257682", "Score": "0", "Tags": [ "python", "performance" ], "Title": "Find the 4 best parameters of a function to have the best cumulative sum" }
257682
<p>Staying true to the mantra: <em>&quot;The third time you do something, you automate&quot;</em>, I've built up a decent collection of shell scripts that live in <code>~/bin</code>. Some of these scripts contain useful boilerplate code, or just stuff I can't bring myself to memorise (like colour output stuff). Other s...
[]
[ { "body": "<p><strike>Use a shebang</p>\n<pre class=\"lang-bsh prettyprint-override\"><code>#!/usr/bin/env bash\n</code></pre>\n<p></strike> I see you're already doing that.</p>\n<p>In bash, prefer <code>[[...]]</code> over <code>[...]</code>. The double bracket <a href=\"https://www.gnu.org/software/bash/manua...
{ "AcceptedAnswerId": "257687", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T16:11:16.673", "Id": "257683", "Score": "0", "Tags": [ "bash", "shell" ], "Title": "Small bash script to quickly edit scripts in $PATH" }
257683
<p>The Julia package <a href="https://github.com/JuliaDynamics/DrWatson.jl" rel="nofollow noreferrer">DrWatson.jl</a> is aimed at scientific computing and data analysis. It describes itself as &quot;scientific project assistant software&quot;. I recently decided giving it a try and like the functionality so far.</p> <p...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T17:46:25.197", "Id": "257689", "Score": "0", "Tags": [ "macros", "julia" ], "Title": "Automatic saving of workspace variables for `DrWatson.jl`" }
257689
<p>Hi everyone I'm trying to reduce the complexity of some of my Python code. The function below aims to compute the validation and test loss for a variety of PyTorch time series forecasting models. I won't go into all the intricacies but needs to support models that return multiple targets, an output distribution + st...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T18:13:06.300", "Id": "508975", "Score": "0", "body": "Welcome to Code Review! We need to know *what the code is intended to achieve*. To help reviewers give you better answers, please add sufficient context to your question, includi...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T18:05:12.250", "Id": "257691", "Score": "1", "Tags": [ "python", "python-3.x", "machine-learning" ], "Title": "validation and test loss for a variety of PyTorch time series foreca...
257691
<p>I feel like this code could be cleaned up more or it could be shorter but and more understandable. Any advice/suggestion is appreciated.</p> <pre><code>public string GetIPVersions(NetworkInterface @interface) { string ipVersions = &quot;&quot;; if (@interface.Supports(NetworkInterfaceComponent.I...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T07:12:10.197", "Id": "509032", "Score": "2", "body": "The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to **simply sta...
[ { "body": "<p>Switching the logic <code>@interface.Supports</code> vs <code>!@interfaceSupports</code> is confusing the code.</p>\n<p>The decision to add a space is better as a distinct statement. Blending this decision with the addition of the IPv6 text obscures the meaning of the code.</p>\n<p>With just two ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-25T22:41:02.940", "Id": "257697", "Score": "-2", "Tags": [ "c#" ], "Title": "What can I do better to clean this code up, make it smaller? Just started practicing clean code, need advice" }
257697
<p>Hello StackExchange community, I am curious if there is a better solution than mine for this exercise below:</p> <p><em>Enter a regex that matches all the items in the first column (positive examples) but none of those in the second (negative examples).</em></p> <p><strong>Positive Examples:</strong></p> <pre><code>...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T07:12:46.183", "Id": "509033", "Score": "3", "body": "The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to **simply sta...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T02:35:01.530", "Id": "257705", "Score": "2", "Tags": [ "strings", "regex" ], "Title": "Is there a better pattern to match those words with regex?" }
257705
<p>I have a function that creates filters for some data. The filters get added to an array and then (later) chained through the <code>reduce</code> function (the chaining part not part of my question).</p> <p>The data I receive are all strings but can actually be numbers, eg <code>{name:&quot;-45.6&quot;}</code>. If it...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T09:37:14.637", "Id": "509041", "Score": "1", "body": "To convert to a number only if value is a number use the function `const convertToNumber = value => isNaN(value) ? value : Number(value);`" } ]
[ { "body": "<p>One problem with <code>Number(value);</code> is that it casts <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Falsy\" rel=\"nofollow noreferrer\">falsy</a> values as <code>0</code> and <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Truthy\" rel=\"nofollow noreferrer\">trut...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T03:04:29.687", "Id": "257707", "Score": "0", "Tags": [ "javascript" ], "Title": "Write a clean convertToNumber function, if value is a number" }
257707
<p>As a side project, I'm working on a Bokeh web application to display public bikeshare data on a map. The data is updated every 2 minutes using a periodic callback. Below is the full implementation. I'm using PyBikes (<a href="https://github.com/eskerda/pybikes" rel="nofollow noreferrer">https://github.com/eskerda/py...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T03:17:39.257", "Id": "257708", "Score": "2", "Tags": [ "python", "beginner", "python-2.x", "unit-testing" ], "Title": "Interactive, real-time bikeshare web application with Bo...
257708
<p>I got the C++ implementation of depth-first search (DFS) from <a href="https://www.geeksforgeeks.org/depth-first-search-or-dfs-for-a-graph/" rel="nofollow noreferrer">here</a> and made slight modifications to it. The modified code is as follows:</p> <pre><code>#include &quot;stdafx.h&quot; #include &lt;iostream&gt; ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T16:27:15.483", "Id": "509077", "Score": "0", "body": "You need to learn the visitor pattern." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T16:32:17.597", "Id": "509078", "Score": "2", "b...
[ { "body": "<blockquote>\n<p>What further improvements can I make to this code?</p>\n</blockquote>\n<p>The code is rather bad - the site you read it from tends to have lots of bad/amateur articles.</p>\n<ol>\n<li><p>The graph class:</p>\n<pre><code>std::map&lt;int, bool&gt; visited;\nstd::map&lt;int, std::list&l...
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T06:33:47.200", "Id": "257710", "Score": "7", "Tags": [ "c++", "c++11", "search", "depth-first-search" ], "Title": "C++ implementation of depth-first search" }
257710
<p><strong>Situation:</strong> I have implemented a factory design pattern in Python as below. There are different screens which have different configurations. One can register the screen in the factory and get the screen in case correct configuration is passed to respective factory class method.</p> <p><strong>Questio...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T15:19:33.117", "Id": "509071", "Score": "0", "body": "The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to **simply sta...
[ { "body": "<h2>IScreens is a callable</h2>\n<p>Actually, your <code>IScreens</code> class (interface) contains only one abstract method (the <code>main</code> method), so this class is a kind of callable.\nInstead of creating a specific class, you can use <code>collections.Callable</code>:</p>\n<pre class=\"lan...
{ "AcceptedAnswerId": "257728", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T07:30:03.900", "Id": "257713", "Score": "0", "Tags": [ "python", "object-oriented", "design-patterns", "abstract-factory" ], "Title": "Factory / Builder Design Pattern in ...
257713
<p>This is a datasource for Achievements that can be toggled to be viewed within a grid or list layout. Thoughts/notes</p> <ul> <li>This code was previously duplicated in two different ViewControllers.</li> <li>Should the CollectionLayout code go in here?</li> <li>Should the SectionHeader and layout toggle button deleg...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T11:26:48.227", "Id": "257723", "Score": "1", "Tags": [ "swift" ], "Title": "Subclassed DiffableDataSource" }
257723
<p>I was studying resnet and wanted to program it with pytorch</p> <p>I searched for some examples(github, google) but it was hard to understand the code completely</p> <p>So I programmed resnet myself and it works.</p> <p>But I want to check just in case if I did something wrong</p> <p>Can I get some code reviews and ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T12:55:16.127", "Id": "257727", "Score": "1", "Tags": [ "python", "pytorch" ], "Title": "resnet with pytorch" }
257727
<p>I have a <code>.txt</code> file that looks like this:</p> <pre><code>SHT1 E: T1:30.45°C H1:59.14 %RH SHT2 S: T2:29.93°C H2:67.38 %RH SHT1 E: T1:30.49°C H1:58.87 %RH SHT2 S: T2:29.94°C H2:67.22 %RH SHT1 E: T1:30.53°C H1:58.69 %RH SHT2 S: T2:29.95°C H2:67.22 %RH </code></pre> <p>I want...
[]
[ { "body": "<p><strong>Disclaimer:</strong> I know this is a very liberal interpretation of a code review since it suggests an entirely different approach. I still thought it might provide a useful perspective when thinking about such problems in the future and reducing coding effort.</p>\n<p>I would suggest the...
{ "AcceptedAnswerId": "257747", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T13:43:27.720", "Id": "257729", "Score": "3", "Tags": [ "python", "python-3.x", "parsing", "pandas" ], "Title": "Parsing a text file into a pandas DataFrame" }
257729
<p>I'm not that advanced in PHP or OOP concept so I'm facing some issues.</p> <p>I'm working on a project where it's using <code>AltoRouter</code> to call the functions based on the route. So I have a controller for each <code>function</code> that calls a <code>class</code> later on. For example, this is how it's done ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T15:19:06.733", "Id": "509070", "Score": "2", "body": "The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to **simply sta...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T13:48:55.023", "Id": "257730", "Score": "1", "Tags": [ "php", "object-oriented" ], "Title": "Improving php code with OOP paradigms" }
257730
<p>I've designed this game, it's my first project. It's a spin-off from &quot;The Pig Game&quot; in a JavaScript course. I tweaked the HTML and CSS templates of the Pig Game for the UI, but I did the game design and coding from scratch. You can play the game here: <a href="https://jeffparadox.000webhostapp.com/" rel="n...
[]
[ { "body": "<p>First of all, great job on the game! Even though it's a simple concept it feels really well realized by you.</p>\n<p>Let's go over your questions one by one:</p>\n<h2>1. UI &amp; UX</h2>\n<p>Well done on this one! Simple, clean design, sufficient spacing on elements, consistent styling, nice visua...
{ "AcceptedAnswerId": "258840", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T14:11:50.847", "Id": "257731", "Score": "3", "Tags": [ "javascript", "random" ], "Title": "Catch The Rabbit Game: How to Create Non-Repeating Randomization? (JavaScript, CSS, HTML...
257731
<p>Below is my attempt to check if two types are the same without template instantiations.</p> <pre><code>#include &lt;cstddef&gt; template&lt;class, class&gt; struct twoTypes; template&lt;class T&gt; std::size_t isSame(twoTypes&lt;T,T&gt;*); bool isSame(void*); template&lt;class T, class U&gt; using checkIfSame = dec...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T14:51:15.610", "Id": "509068", "Score": "2", "body": "What benchmarks? What compiler version and flags? Why do you need this?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T15:15:44.283", "Id": "...
[ { "body": "<p>If you're using clang or GCC ≥10, you can use the <code>__is_same(type1, type2)</code> intrinsic.</p>\n<p>For portability:</p>\n<pre class=\"lang-cpp prettyprint-override\"><code>#if !defined(__is_same) &amp;&amp; (!defined(__clang__) || !defined(__GNUC__) || __GNUC__ &lt; 10)\n#define IS_SAME(T1,...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T14:33:54.987", "Id": "257733", "Score": "1", "Tags": [ "c++", "performance", "reinventing-the-wheel", "template" ], "Title": "Check if two types are the same without template ...
257733
<p><strong>Context (optional)</strong><br> In my job, we are interested in identifying particular events that may occur during the degradation of a physical system over its lifetime. Specifically, these are referred to as:</p> <ul> <li>Knee onset (the beginning of nonlinear degradation phase)</li> <li>Knee point (point...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T16:36:44.160", "Id": "509080", "Score": "1", "body": "Welcome to Code Review. Do you have a usage example with your class?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T17:27:23.093", "Id": "509...
[ { "body": "<p>Here are a few comments and observation about the code:</p>\n<h3>Write docstring</h3>\n<p>In many IDEs or REPLs getting help on an object returns the object's doctring. For example, in Jupyter or IDLE typing <code>help(KneeFinder)</code> would display the doctring for the <code>KneeFinder</code> c...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T15:26:24.230", "Id": "257734", "Score": "5", "Tags": [ "python", "object-oriented" ], "Title": "Python OOP code for identifying knees in data" }
257734
<p>My C++ solution for <a href="https://www.hackerrank.com/challenges/making-candies/problem" rel="nofollow noreferrer">HackerRank's &quot;Making Candies&quot; problem</a>, reproduced below, is as optimized as I can make it and appears similar to what others say are optimal solutions. However, six of the test cases sti...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T18:15:42.873", "Id": "509096", "Score": "3", "body": "Links can rot over time. Please improve the question by including a synopsis of the problem your code is solving." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDat...
[ { "body": "<h1>Unlearn bad behavior taught by competitive coding sites</h1>\n<p>Competitive coding sites unfortunately teach some bad coding habits. You did not include your whole program, the <code>#include</code>s are missing for example. If you did <code>#include &lt;bits/stdc++.h&gt;</code>, <a href=\"https...
{ "AcceptedAnswerId": "258859", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T16:45:50.317", "Id": "257739", "Score": "2", "Tags": [ "c++", "performance", "time-limit-exceeded", "mathematics", "complexity" ], "Title": "Can I further optimize thi...
257739
<p>I have cleanly separated functionality of a message bus - namely the diagnostics (optional), sending, decoding and the bus driver, I need to now bind this together and have done so with a <code>MessageBus</code> class.</p> <p>It feels anemic though, with a lot of pass through methods.</p> <p>On the flip side it is n...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T23:10:17.560", "Id": "509121", "Score": "1", "body": "A fast tip: you can optimize out all `async` State Machines here as you have only one `await` and no code after it and it's not inside `using` or `try-catch` statement. For examp...
[ { "body": "<p>I think what i was missing was a &quot;builder&quot; class that could take care of the construction, and allow the interfaces to be returned.</p>\n<p>Not all transport types needed to be &quot;started&quot;, so i left that concern to the builder of the specific bus (i.e. MQTT transport would have ...
{ "AcceptedAnswerId": "258932", "CommentCount": "9", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T17:05:54.367", "Id": "257740", "Score": "5", "Tags": [ "c#", "design-patterns" ], "Title": "Anemic class that binds functionality" }
257740
<p>This code succeeds in downloading log text files from multiple URLs. Can this be made more efficient?</p> <pre><code>let private downloadLogs toDirectory = let createFileDirectories (url : string) = let directory = $@&quot;{toDirectory}\{url.Substring(13, 3)}&quot; try if not (Direc...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-29T06:28:41.910", "Id": "510300", "Score": "2", "body": "In what way? Execution speed? Memory Usage? Code Verbosity? Idomaticism?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-29T12:44:45.647", "Id": ...
[ { "body": "<p>There appears to be more options for parallelization and async here, and I think the fold overcomplicated what you were trying to do.</p>\n<pre class=\"lang-fs prettyprint-override\"><code>#if false\n#r $&quot;FSharp.Data&quot;\n#endif\nopen System.Net\nopen System.IO\nopen FSharp.Data\n\nlet d01...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T17:38:22.213", "Id": "257742", "Score": "0", "Tags": [ ".net", "f#", ".net-core" ], "Title": "Downloading multiple log files" }
257742
<p>Hello fellow programmers, I am currently implementing a function and wanted to know if there was anything I could change to simplify the code, make it more readable, or to optimize the running time and memory usage. My current implementation works as expected, without any bugs.</p> <p>The function I am implementing ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-30T20:39:46.653", "Id": "510446", "Score": "1", "body": "@aepot Anonymous types have structural comparison by default." } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T18:30:22.570", "Id": "257745", "Score": "1", "Tags": [ "c#", "performance", "linq" ], "Title": "Optimizations on a function that fIlters a list of connections" }
257745
<p>I've recently started programming in C and as my first serious program I thought I'd create a simple calculator. To make it a bit more complex I decided not to use the functions included in math.h (like pow) but to create these functions by myself. Let me know if there is something I can do to improve this code.</p>...
[]
[ { "body": "<p><strong><code>power()</code> problems</strong></p>\n<p><code>double power()</code> does not return a value.</p>\n<p>Incorrect result when <code>y</code> is not a value in the <code>int</code> range.</p>\n<p>Code attempts a linear power calculation: O(y). Research <a href=\"https://en.wikipedia.or...
{ "AcceptedAnswerId": "257752", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T18:53:43.563", "Id": "257749", "Score": "5", "Tags": [ "beginner", "c", "calculator" ], "Title": "My first program in C. A simple command-line calculator" }
257749
<p>I'm writing my own library, that is for asynchronous network communication. and then, wanna write my own HTTP proxy server for load-balancing connections to backend servers with it.</p> <p>when I'm using <code>docker</code> at my work in company, I thought that &quot;if the <code>apache</code> have REST API for addi...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T12:45:40.477", "Id": "510158", "Score": "0", "body": "The code you implemented so far looks a lot like what C++20's [ranges library](https://en.cppreference.com/w/cpp/ranges#Example) provides." }, { "ContentLicense": "CC BY-...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T18:59:05.797", "Id": "257750", "Score": "0", "Tags": [ "c++", "asynchronous", "async-await" ], "Title": "Idea for writing asynchronous data processing chains easier (similar to `R...
257750
<ol> <li>I want to generate a random date of birth [mm/dd/yyyy]which will represent an age equal to less than 18years old</li> <li>My requirement is to dynamically generate test data [date of birth] to negatively test a system which needs a date of birth (age) to be always greater than 18 years old</li> <li>The system ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T09:28:53.830", "Id": "510150", "Score": "0", "body": "Do you really need *random* dates for testing? Usually, good tests focus on the boundary conditions, so you'd want to use dates including exactly 18 years, the same ±1day, and a...
[ { "body": "<p><code>datetime.date</code> has a <code>.replace()</code> method that returns a copy with some values changed. This can be used to get the date 18 years ago.</p>\n<pre><code>end_date = date.today()\nstart_date = end_date.replace(year=end_date.year - 18)\n</code></pre>\n<p><code>datetime.date.toord...
{ "AcceptedAnswerId": "257758", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T21:09:30.250", "Id": "257753", "Score": "0", "Tags": [ "python", "datetime" ], "Title": "Code to generate a random date of birth which will always represent an age less than 18 ye...
257753
<p>I have a some code in which eslint thrown an error of the type: <code>import/no-cycle</code>, but I don't understand where this cyclic dependency comes from.</p> <p>The exact error thrown is: <code>ESLint: Dependency cycle via ../types:7=&gt;./Jobs:1(import/no-cycle)</code>.</p> <h3>File 1. jobs/Jobs</h3> <pre class...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T23:56:09.453", "Id": "509123", "Score": "2", "body": "All code in an imported module is executed irrespective of what reference you are importing. If you dont give the references to import eg`import {} from \"./Jobs\"` `import {} ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-26T22:39:58.953", "Id": "257754", "Score": "0", "Tags": [ "javascript", "typescript" ], "Title": "Understanding import/no-cycle problem in eslint" }
257754
<p>This is a follow-up question for <a href="https://codereview.stackexchange.com/q/253556/231235">A recursive_transform Template Function Implementation with std::invocable concept in C++</a> and <a href="https://codereview.stackexchange.com/q/254096/231235">A recursive_transform Template Function Implementation with ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T00:00:13.790", "Id": "257757", "Score": "3", "Tags": [ "c++", "recursion", "template", "lambda", "c++20" ], "Title": "A recursive_transform Template Function with Unwrap L...
257757
<p>I've been interested in making fully repeatable, reproducible game states. This led me into the world of DDD, and specifically, the concept of Aggregates + Event Sourcing (although that's not necessarily a DDD concept). In this context, the state of the Aggregate is reconstituted from a sequence of Domain Events, ea...
[]
[ { "body": "<p>Very interesting question! Makes me want to read more about the DDD topic, which I should :-)</p>\n<p>For now at least to answer one of your questions:</p>\n<p>Not sure for <code>plus</code>, but <code>times/div</code> operator is definitely okay to use for different types. It's typical for multip...
{ "AcceptedAnswerId": "259176", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T03:29:10.673", "Id": "258757", "Score": "2", "Tags": [ "functional-programming", "kotlin", "ddd" ], "Title": "A Stateless Immutable Event-Driven DDD Pattern in Kotlin" }
258757
<p>My code currently:</p> <pre><code>import os import pandas as pd from selenium import webdriver from tabulate import tabulate from datetime import datetime import time from bs4 import BeautifulSoup as bs start = datetime.now() browser = webdriver.Chrome() class GameData: def __init__(self): self.date...
[]
[ { "body": "<p>Some quick comments. Since your request is about readability, you can do three things at least:</p>\n<ul>\n<li>get rid of unused variables eg: <code>start = datetime.now()</code></li>\n<li>improve the naming conventions for your variables: variables like <code>cont</code> or <code>conti are</code>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T11:17:57.500", "Id": "258761", "Score": "2", "Tags": [ "python" ], "Title": "Scraping game data from web" }
258761
<p>This program tokenizes an arithmetic expression specified in infix notation. It is one of my personal projects and I would love to receive expert advice.</p> <p>After compiling, you can run the program with one command-line argument:</p> <pre class="lang-sh prettyprint-override"><code>$ tokenize &lt;arith_expr&gt; <...
[]
[ { "body": "<p>Your <code>is_operator</code> function can be rewritten as</p>\n<pre><code>return token == '+' || token == '-' || token == '*' || token == '/' || token == '^';\n</code></pre>\n<p>Much cleaner, in my opinion.</p>\n<hr />\n<p>The program has a memory leak. Your <code>tokenize</code> function allocat...
{ "AcceptedAnswerId": "258768", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T11:37:06.390", "Id": "258763", "Score": "5", "Tags": [ "algorithm", "c", "calculator", "lexer" ], "Title": "Tokenize arithmetic expression in C" }
258763
<p>This is an algorithm regarding the <a href="https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta%E2%80%93Fehlberg_method" rel="nofollow noreferrer">RKF method</a>:</p> <pre><code>import numpy as np class rkf(): def __init__(self,f, a, b, x0, atol, rtol, hmax, hmin): self.f=f self.a=a self....
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T13:32:06.243", "Id": "510166", "Score": "1", "body": "This looks like an excerpt of a class method. Please show all of your code." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T16:05:39.343", "Id...
[ { "body": "<p>All these lines are really weird:</p>\n<pre><code>a4 = 9.230769230769231e-01 # 12/13\n</code></pre>\n<p>Unless you have a good reason (which I'd then state in the code as a comment) to do that, just write <code>a4 = 12/13</code> instead.</p>\n<p>Gonna be the same anyway:</p>\n<pre><code>&gt;&...
{ "AcceptedAnswerId": "258860", "CommentCount": "8", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T12:19:32.753", "Id": "258764", "Score": "5", "Tags": [ "python", "python-3.x", "numpy", "numerical-methods" ], "Title": "Optimizing an implementation of the RKF method" }
258764
<p>I am working on a small side-project since a couple of weeks, I am using Flask but trying to use as few libraries as possible and no ORMs (for learning purposes.</p> <p>I am currently working on the User service on my application and currently stuck in the registration email confirmation part regarding my design.</p...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-31T23:39:10.723", "Id": "510572", "Score": "0", "body": "Your formatting seems off - as written Python would fail to interpret this. Please double-check your indentation." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDat...
[ { "body": "<p>It's unstated, so I have to assume that you're using <code>itsdangerous</code> and its implementation of <a href=\"https://itsdangerous.palletsprojects.com/en/1.1.x/url_safe/?highlight=urlsafetimedserializer\" rel=\"nofollow noreferrer\">URLSafeTimedSerializer</a> .</p>\n<p>You ask:</p>\n<blockquo...
{ "AcceptedAnswerId": "258946", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T12:28:41.403", "Id": "258765", "Score": "2", "Tags": [ "python", "object-oriented", "design-patterns", "flask" ], "Title": "Python: separation of concern User Model and Us...
258765
<p>I wrote below piece of code generating dummy data loaded to MongoDB.</p> <p><strong>2 issues :</strong></p> <p>1.customer class has subscriber class so it nested with one level customer--&gt; subsciber. I think i'm not doing right:</p> <pre><code>self.subscriber = Subscriber().returnJson() </code></pre> <p>it does w...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T15:32:48.847", "Id": "258770", "Score": "1", "Tags": [ "python", "mongodb", "multiprocessing" ], "Title": "Python/Mongo - Generating dummy data" }
258770
<p>What do you think of the following function to offer an alternative to fgets, looking for insights about portability, safety, readability and performance:</p> <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt; #include &lt;errno.h&gt; int sc_gets(char *buf, int n) { int count = 0; char ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T17:50:48.957", "Id": "510191", "Score": "0", "body": "If you are going to use implementation specific API `__glibc_unlikely()` it is probably best to wrap them in a macro to provide alternatives for implementations that don't have t...
[ { "body": "<ul>\n<li><p>The function does not handle end-of-file correctly. <code>stdin</code> is just a stream, and could be closed like any other stream. For example, type <code>Ctrl-D</code>. Or</p>\n<pre><code> echo -n a | ./a.out\n a????????\n</code></pre>\n<p>Keep in mind that reading beyond end-of-file...
{ "AcceptedAnswerId": "258786", "CommentCount": "9", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T17:01:43.410", "Id": "258772", "Score": "3", "Tags": [ "c" ], "Title": "fgets without the line return" }
258772
<p>I made myself a function to check if a string is a path or an URL:</p> <pre class="lang-py prettyprint-override"><code>import os def isPath(s): &quot;&quot;&quot; @param s string containing a path or url @return True if it's a path, False if it's an url' &quot;&quot;&quot; if os.path.exists(s): ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T21:22:09.657", "Id": "510210", "Score": "0", "body": "`file:///path/to/file` is perfectly valid path, as is `.dir/file`" } ]
[ { "body": "<p>Some high level comments:</p>\n<ul>\n<li>Checking if a string is a url (or a path) is usually done using regular expressions that can be found online. Not sure what's the scope of this function, but it can be seen as reinventing the wheel and might miss some uncommon cases</li>\n<li>The method nam...
{ "AcceptedAnswerId": "258782", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T17:21:22.950", "Id": "258773", "Score": "3", "Tags": [ "python", "python-3.x", "url" ], "Title": "Function for checking if a string is a path or an URL be improved" }
258773
<p><strong>Problem</strong></p> <p>Output a receipt of purchased items. Inputs:</p> <ul> <li>products_text_path: Products are found in a text file in <code>&lt;barcode&gt;:&lt;name&gt;:&lt;price&gt;</code> line format.</li> <li>purchased_items_set: The purchased items are given as a list of integer barcodes. Same item ...
[]
[ { "body": "<ul>\n<li>Indentation is not a multiple of 4, while PEP8 establishes that it should.</li>\n<li>No entry-point to your script (if __ name __ == '__ main __'...).</li>\n<li>Parse_product was getting the name before the barcode, while the question establishes the order is the opposite one.</li>\n<li>Cla...
{ "AcceptedAnswerId": "258790", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T19:01:39.120", "Id": "258775", "Score": "8", "Tags": [ "python", "performance", "python-3.x" ], "Title": "Print receipt from cash register in Python" }
258775
<p>This is meant to be a drop in replacement for getline as it's not crossplatform. I am trying to do as minimal work as possible in here including only calling strlen once at the very end to calculate the size of the final block.</p> <p>returns -1 for error, 0 for EOF, 1 for success</p> <p>The way it works it by setti...
[]
[ { "body": "<ul>\n<li><p>Do not put the sentinel characters in every iteration. Set them before the loop, and after a successful reallocation.</p>\n<p>Also, <code>(*line)[*capacity - 2] = 0;</code> is redundant. Indeed, if <code>(*line)[*capacity - 1]</code> remains <code>1</code> we don't care, and if it turns ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T20:00:29.800", "Id": "258778", "Score": "2", "Tags": [ "c" ], "Title": "C fgets_line of arbitrary length" }
258778
<p>I am coding a JS Mandelbrot Set viewer and am looking for suggestions on how to improve my code. I already did some cleanup and got the execution time from 7s to about 160ms on my computer.</p> <p>Some info about my Code:</p> <ul> <li>Complex numbers are stored as an array where the first number is the real part and...
[]
[ { "body": "<h2>Review</h2>\n<p>Some bad habits and inappropriate data structures used.</p>\n<ul>\n<li><p>It is a very bad habit to leave commented code in your source.</p>\n</li>\n<li><p>Only use arrays when all the items represent the same thing.</p>\n<p>Using arrays to hold structured data makes code very har...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T20:42:09.263", "Id": "258781", "Score": "2", "Tags": [ "javascript", "performance" ], "Title": "JS Mandelbort Set Viewer" }
258781
<p>I've just taken the leap over to RTK instead of 'vanilla' redux and am blown away by how much less code I need to write. I'm not entirely sure how to structure my slices, however, and figured I'd ask for a small code review so I do not accidentally start breaking conventions from the start. This is how one of my sli...
[]
[ { "body": "<blockquote>\n<p>I am blown away by how much less code I need to write</p>\n</blockquote>\n<p>I'm going to blow your mind even more because you actually do not need to <code>dispatch</code> any actions inside <code>createAsyncThunk</code>. It does that for you!</p>\n<p>The &quot;pending&quot; action...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T21:09:57.270", "Id": "258784", "Score": "5", "Tags": [ "react.js", "redux" ], "Title": "Redux Toolkit Structure with TS" }
258784
<p>So i've been working on Tetris in python. The code is not finished but it does run some basic tests. I have showed several people my code on Disocrd and one person had a a lot to say about my code. He was confused as to why i have two classes for Tetris pieces. He didn't understand my wall-kick data structure. A...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-28T05:47:31.323", "Id": "510224", "Score": "0", "body": "`from typing import Dict, List, Tuple, NewType` is a common practice, instead of writing multiple import statements." }, { "ContentLicense": "CC BY-SA 4.0", "Creation...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T22:16:38.890", "Id": "258787", "Score": "0", "Tags": [ "python", "tetris" ], "Title": "Tetris in python" }
258787
<p>I'm trying to practice some functional techniques. I haven't worked much in Haskell, so any language-specific tips would be very appreciated, but what I care for even more are general tips towards my approach that I can carry between functional languages. Performance is not a big concern of mine right now.</p> <p>I ...
[]
[ { "body": "<p>All the indexing can be deleted. You only need the transpose function plus a custom function that grabs the diagonals of a matrix (list of lists, all of the same length).</p>\n<pre><code>import Data.List (transpose)\n\n-- | The 'diagonals' function returns the diagonals of a matrix\ndiagonals :: [...
{ "AcceptedAnswerId": "258794", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-27T23:49:27.037", "Id": "258789", "Score": "4", "Tags": [ "haskell", "functional-programming" ], "Title": "Connect-Four winner-checking algorithm" }
258789
<p>I want to solve the following task --- I am given a vector of integers. I want to 'compress' this list, where the elements will be replaced with numbers <code>0</code> through <code>n - 1</code>, where <code>n</code> is the number of unique elements in the vector, such that the relative ordering among the elements i...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-28T02:47:49.170", "Id": "510222", "Score": "0", "body": "Your example (and expected output) is confusing and difficult to understand." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-28T04:05:27.177", "I...
[ { "body": "<h1>Algorithm improvements</h1>\n<p>I really don’t understand what this algorithm is supposed to be doing. Your description of it is incomplete and vague (for example, you say <code>vector[index1] &lt; vector[index2]</code>… but what is <code>index1</code> and <code>index2</code>?), and the single ex...
{ "AcceptedAnswerId": "258796", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-28T00:39:51.817", "Id": "258791", "Score": "5", "Tags": [ "c++", "algorithm", "vectors" ], "Title": "Compressing a vector into a specific range" }
258791
<p>I am on my second iteration of the famous &quot;Number Of Islands&quot; graph problem on Leetcode.</p> <p><a href="https://leetcode.com/problems/number-of-islands/" rel="nofollow noreferrer">https://leetcode.com/problems/number-of-islands/</a></p> <pre><code>Given an m x n 2D binary grid grid which represents a map ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-28T08:57:22.007", "Id": "510234", "Score": "0", "body": "Hi! Refer to https://codereview.stackexchange.com/help/how-to-ask for good titling. Edit suggested!" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-2...
[ { "body": "<p>My suggestions:</p>\n<ul>\n<li><p>The variables <code>m</code> and <code>n</code> are initialized but never used</p>\n</li>\n<li><p>The function <code>get_neighbors</code>:</p>\n<pre class=\"lang-py prettyprint-override\"><code>def get_neighbors(coord: Tuple[int, int]) -&gt; List[Tuple]:\n delt...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-28T04:06:35.710", "Id": "258793", "Score": "4", "Tags": [ "python", "graph" ], "Title": "Leetcode: number of islands" }
258793
<p>I'm working on a project of mine which required multiple calls to <code>strncat()</code>, and it came to me that it'd have been much easier if C also had something like <code>&quot;file://&quot; + getenv(&quot;HOME&quot;) + filename</code> for string generation. So I built a function that works in a similar fashion,...
[]
[ { "body": "<p>It looks like this code needs a couple of headers to be included before it will compile:</p>\n<pre><code>#include &lt;stdarg.h&gt;\n#include &lt;stdlib.h&gt;\n#include &lt;string.h&gt;\n</code></pre>\n<p>It also only works on platforms that have <code>strdup()</code>. It would be easy to make it ...
{ "AcceptedAnswerId": "258800", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-28T04:50:14.787", "Id": "258795", "Score": "5", "Tags": [ "c", "strings", "variadic" ], "Title": "C function that emulates string concatenation operator '+' in Python or Go" }
258795
<p>I tried to make a Pong game in Java. It's my first game I have ever programmed, and I would be very pleased if you would take the time to advise me on what I could do better next time. Thank you so much :) .</p> <p>Here is my code:</p> <p>Start.java:</p> <pre><code>import java.awt.EventQueue; public class Start { ...
[]
[ { "body": "<p>Code looks clean, some variables should maybe have a little bit better name, some comments would be nice, overall very good for your first game.</p>\n<p>Some points:</p>\n<ul>\n<li><p>You should use a <em>package</em>, this makes it also easier to create a <em>jar</em>, and <em>jars</em> are good ...
{ "AcceptedAnswerId": "258867", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-28T16:27:01.033", "Id": "258805", "Score": "5", "Tags": [ "java", "beginner", "game", "pong" ], "Title": "Pong Game project" }
258805
<p>This is my first post on this forum. I have read the guidelines and will try to adhere to them, but I apologize if I miss something. The code I am posting is intended to duplicate the output of &quot;date -u&quot; in the XV6 OS. It does this, with the exception of dates before the 1700s (This wasn't relevant to th...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-31T21:05:44.067", "Id": "510557", "Score": "1", "body": "@Toby Speight OP here has incorrect code for either set of rules for `check_leap()`. The change from Juliann to Gregorian calendar and it leap year rules only begin in 1582. T...
[ { "body": "<h2>XV6 bizarreness</h2>\n<p>XV6 has made at least one ill-advised decision in forcing a non-standard signature of <code>printf</code> that requires a file descriptor be passed in. Maybe they should have omitted <code>printf</code> entirely and made you use <code>fprintf</code> instead, but anyway: a...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-28T16:47:36.927", "Id": "258806", "Score": "3", "Tags": [ "beginner", "c", "reinventing-the-wheel", "homework" ], "Title": "Date program for xv6- improvement and testing" }
258806
<p>It's been a while I have been on here and I hope I still understand the rules. I have recently started learning PHP and WordPress for a Whatsapp Chatbot integration. I have created a webhook on my WordPress site that returns a JSON, which is consumed by Google Dialogflow(Chatbot engine).</p> <p>For example, my webho...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-29T00:08:12.387", "Id": "510281", "Score": "0", "body": "This question may be closed for asking for \"general best practices\"." } ]
[ { "body": "<p>Do you can use a converter tool to help you understand the conversion structure, ex.: <a href=\"https://wtools.io/convert-json-to-php-array\" rel=\"nofollow noreferrer\">wtools.io</a>.\nIn this case, the PHP array structure for your json is similar that it:</p>\n<pre><code>$innerarr = array (\n '...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-28T18:08:30.690", "Id": "258811", "Score": "-1", "Tags": [ "php", "json" ], "Title": "Best Practice: creating a nested associative array JSON in PHP" }
258811
<p>I wanted to have a function called timeit which can measure the time of execution of n iterations of any other function. I still learning C++ but I come up with that : Any thought ?</p> <pre><code>#include&lt;chrono&gt; using namespace std; template&lt;typename output, typename ...ArgsT, typename ...Input&gt; doub...
[]
[ { "body": "<p>The big thing you're missing here is perfect forwarding. When you receive the argument pack, it may contain one or more rvalue references. But when you pass <code>args...</code> to the function you're timing, you've given a name to the pack, so even though what you received were rvalue references,...
{ "AcceptedAnswerId": "258816", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-28T20:10:42.387", "Id": "258814", "Score": "1", "Tags": [ "c++" ], "Title": "Function measuring time of another function" }
258814
<p>I am writing a simple wrapper around <code>fetch</code>.</p> <pre class="lang-js prettyprint-override"><code>async function apiCall( endpoint: string, { data, headers: customHeaders, ...customConfig }: { data?: Object; headers?: Object } = {} ) { const config = { method: data ? 'POST' : 'GET'...
[]
[ { "body": "<p>If you need to account for mixed response types (in your case &quot;unknown errors&quot; or JSON-formatted errors), then you could consider checking the Content-Type of the response. See <a href=\"https://stackoverflow.com/questions/37121301/how-to-check-if-the-response-of-a-fetch-is-a-json-object...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-28T22:01:10.100", "Id": "258820", "Score": "1", "Tags": [ "javascript", "json", "http" ], "Title": "A simple wrapper around fetch" }
258820
<p>After a bit of struggling I've come up with the code</p> <pre class="lang-py prettyprint-override"><code> import discord import os import subprocess as sub import psutil client = discord.Client() my_path = os.getcwd() program_instance = False currently_installed = os.path.isdir(&quot;web-application&quot;) def ru...
[]
[ { "body": "<p>This depends on the nature and purpose of the process.</p>\n<p>For example, you might schedule your process as a coroutine, and cancel its execution with <code>Future.cancel</code>: <a href=\"https://docs.python.org/3/library/asyncio-future.html#asyncio.Future.cancel\" rel=\"nofollow noreferrer\">...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-28T23:47:14.680", "Id": "258822", "Score": "2", "Tags": [ "python" ], "Title": "How to simplify a discord bot remote tool" }
258822
<p>I have implemented a custom concurrent queue on top of GCD which offers two additional pieces of functionality:</p> <ol> <li>Limit the maximum number of concurrently executing tasks.</li> <li>Give manual control over which enqueued task is scheduled for execution next.</li> </ol> <p>An <code>OperationQueue</code> co...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-29T09:41:32.290", "Id": "510327", "Score": "0", "body": "If I understand it correctly, the `block` callback is called when an execution slot is available, and that returns the index of the next work item to be executed. But how does t...
[]
{ "AcceptedAnswerId": null, "CommentCount": "14", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-29T01:33:30.103", "Id": "258824", "Score": "2", "Tags": [ "swift", "asynchronous", "concurrency", "queue", "grand-central-dispatch" ], "Title": "Fixed-width non-FIFO Dispatc...
258824
<p>The code below is a Python module to flatten JSON-like structure (nested dictionaries and lists) to a single string. It also provides partial result in the form of flat list of strings. This flattening is intended to be used to generate commands for the command line variant of the Check Point Management API: <a href...
[]
[ { "body": "<ul>\n<li>I agree with your assessment here; <code>isinstance(value, _CONVERTIBLE_TO_STR)</code> (where <code>_CONVERTIBLE_TO_STR = (str, int, float)</code>) is simpler and better than <code>_is_convertible_to_str(value)</code>. It is also a little bit faster. I determined this by measuring execution...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-29T02:07:59.813", "Id": "258825", "Score": "6", "Tags": [ "python", "python-3.x", "strings", "json", "converting" ], "Title": "Flatten JSON to string" }
258825
<p>I want to determine the number of distinct subarrays that can form having at most a given number of odd elements. Two subarrays are distinct if they differ at even one position. The subarray is a contiguous position of an array. Please give some suggestions to improve the time and space complexity.</p> <pre class="l...
[]
[ { "body": "<p>Welcome to Stack Review, the first thing I see in your code is:</p>\n<pre><code>class result { ..your code }\n</code></pre>\n<p>Instead of <code>result</code> you should use <code>Result</code> as a classname because as specified in <a href=\"https://www.oracle.com/java/technologies/javase/codecon...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-29T05:41:22.957", "Id": "258828", "Score": "3", "Tags": [ "java", "algorithm", "array", "dynamic-programming" ], "Title": "Count the number of distinct subarrays" }
258828
<pre><code>import csv class CSV: def __init__(self,title, row=[]): self.row = row self.title = title def create(self): csvfilename = &quot;{}&quot;.format(self.title) csvFileObj = open(csvfilename, 'w' , encoding='utf-8-sig', newline='') csvWriterObj = csv.writer(csvFileObj...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-29T10:55:01.833", "Id": "258833", "Score": "1", "Tags": [ "python-3.x", "csv" ], "Title": "Open and update csv file" }
258833
<p>Hi there I would like to know if there's a better way of specifying an array of objects on a mongoose schema.</p> <p>This is what I have at the moment:</p> <pre><code>const mongoose = require('mongoose') const photoCode = mongoose.Schema( { value: { type: String, trim: true, unique: true }, status: { ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-29T13:29:15.107", "Id": "510345", "Score": "0", "body": "The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to **simply sta...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-29T11:36:45.807", "Id": "258835", "Score": "0", "Tags": [ "mongoose" ], "Title": "How to best reference a mongoose schema into another schema" }
258835