body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>This is quite a specific script I have written, for Kubernetes Cluster monitoring purposes (specifically the Nodes). Essentially, I need to ensure that the Nodes within a NodeGroup all have the same labels and label values, or else they will not be scaled out evenly for Node Scale out in the version of Kubernetes we...
[]
[ { "body": "<p>Regarding:</p>\n<blockquote>\n<p>I do not like the fact that the four NodeGroups are hardcoded in the\nscript but can't think how to achieve what I want with an array stored\nas an env var.</p>\n</blockquote>\n<p>We can start first by creating a dictionary with all the <code>node_groups</code> and...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-21T06:38:42.137", "Id": "264230", "Score": "4", "Tags": [ "python", "kubernetes" ], "Title": "Kuberhealthy Check - check NodeGroup labels are matching" }
264230
<blockquote> <p>Update at the end</p> </blockquote> <p>Is it possible to implement <code>IDisposable</code> pattern correctly while using object composition principle to promote code-reuse, reduce code duplication and hide <a href="https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T22:41:10.463", "Id": "522057", "Score": "2", "body": "`but never found someone suggesting such idea, any reason why?` Disposing/Memory Management is a pretty sensitive to implementation topic. The solution for 99% cases looks like o...
[ { "body": "<p>I think there is nothing wrong with your code, however I am unsure if it provides a significant benefit. What you are doing here is replacing one pattern with another, which is for sure simpler, but only marginally. So instead of one if and one SupressFinalize you need a FinalizeObject, DisposeOb...
{ "AcceptedAnswerId": "264335", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-21T09:27:57.447", "Id": "264232", "Score": "3", "Tags": [ "c#", "object-oriented", "design-patterns", ".net", "memory-management" ], "Title": "Implement IDisposable corre...
264232
<p>Python Noob building an automation irrigation system in Python for Raspberry Pi.</p> <p>Python has two functions in the most basic use case:</p> <ol> <li>on/off the LED (which will in future be a relay-&gt;pump) and</li> <li>Notifies &quot;This is out of water&quot; (which will in future be a HTTP post)</li> </ol> <...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-21T14:51:54.480", "Id": "521845", "Score": "1", "body": "Welcome to Code Review! Please [edit] your question so that the title describes the *purpose* of the code, rather than its *mechanism*. We really need to understand the motivati...
[ { "body": "<p>If I understand what you are trying to do, I think you can (1) remember the\nprior state, (2) print only on changes, and (3) select the message to\nprint based on the new state.</p>\n<pre><code>def water_level():\n messages = {\n False: &quot;The system has water&quot;,\n True: &q...
{ "AcceptedAnswerId": "264281", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-21T14:19:15.263", "Id": "264236", "Score": "4", "Tags": [ "python", "python-3.x", "raspberry-pi", "status-monitoring" ], "Title": "Loop to print changes in irrigation state t...
264236
<p>Hello programming gurus/reviewers, I attempted to solve the Minimum Window Substring (Leetcode 76) problem using Python 3. My solution involved using Counters and backtracking. On submission, the solution worked for all cases, other than the last test case where the strings were almost 10000 characters long. This la...
[]
[ { "body": "<h3 id=\"style-naming-comments-etc-k9ke\">Style, naming, comments, etc.</h3>\n<p>Great job! Yes, you could add some more type annotations, but never mind. You're good.</p>\n<h3 id=\"optimization-la92\">Optimization</h3>\n<p>Python is a great language in terms of readability... and not so great in ter...
{ "AcceptedAnswerId": "264248", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-21T14:36:32.730", "Id": "264237", "Score": "3", "Tags": [ "python-3.x", "programming-challenge", "time-limit-exceeded" ], "Title": "Attempting to solve minimum window substring p...
264237
<p>I have been coding in Java for about a month now and I'm seeking advice for my program on things I can improve. This project was mainly made for me to incorporate all the new things I learned and utilize them effectively. I appreciate any feedback :).</p> <p>About the program itself, it takes in a string and reverse...
[]
[ { "body": "<p>You should rewrite your <code>reverseString</code> to use the built-in <a href=\"https://devdocs.io/openjdk%7E15/java.base/java/lang/stringbuilder#reverse()\" rel=\"nofollow noreferrer\">StringBuilder.reverse()</a>.</p>\n<p>Your class structure is a little bit mixed up. The <code>Application</code...
{ "AcceptedAnswerId": "264244", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-21T14:47:29.143", "Id": "264238", "Score": "1", "Tags": [ "java", "performance", "beginner" ], "Title": "StringModifier - Reverses a string and returns information about it" }
264238
<p>This code was an answer to my own <a href="//stackoverflow.com/questions/68411538">question on SO</a>, however I am looking at the line <code>global X</code> and wondering if there is a better way to do this. I try to minimize the amount of global declarations in my code in order to avoid namespace collisions. I'm c...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-21T15:18:08.480", "Id": "521850", "Score": "2", "body": "Please clarify the purpose of the code. What problem does it solve? Perhaps taking a look at the [help/on-topic] will help in determining whether you posted your question in the ...
[ { "body": "<p>If you are not going to write anything to <code>X</code> (which it seems you are not doing), and just going to read from it, you should be good to just have all processes access the same variable without some locking mechanism.</p>\n<p>Now, <code>global</code> is not necesarily the way to go. Here...
{ "AcceptedAnswerId": "264245", "CommentCount": "7", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-21T14:56:59.287", "Id": "264240", "Score": "-1", "Tags": [ "python", "namespaces" ], "Title": "Compute pairwise Pearson's R in parallel with tasks separated by pairs of columns of an...
264240
<p>I'm developing a screen recording application using java. I've modified code from <a href="https://dzone.com/articles/screen-record-play-using-java" rel="nofollow noreferrer">https://dzone.com/articles/screen-record-play-using-java</a> where all the external jars required for this application are available.</p> <p>I...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-21T17:34:53.367", "Id": "521869", "Score": "0", "body": "Thanks for providing more information about the scenario. I [changed the title](https://codereview.stackexchange.com/revisions/264243/5) so that it describes what the code does p...
[]
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-21T15:56:44.517", "Id": "264243", "Score": "3", "Tags": [ "java", "memory-optimization" ], "Title": "screen recording application" }
264243
<p>I just wrote my pong DQN. It seems to work. I'm looking for a performance based review on anything that might slow down the training in complex models.</p> <p>main.py:</p> <pre class="lang-py prettyprint-override"><code>import gym import torch import torch.optim as optim import matplotlib.pyplot as plt from tensorb...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-21T16:53:10.370", "Id": "264246", "Score": "2", "Tags": [ "python", "machine-learning", "neural-network", "pong" ], "Title": "DQN implementation" }
264246
<p>I wrote some code and realized they share similar logic. I am struggling to share the logic and welcome any suggestions.</p> <pre><code>public List&lt;string&gt; SendTemplateAsSampleEmail(MtaConnection mtaConnection, ICollection&lt;EmailRecipient&gt; recipients, SimpleContentDto renderedContent) {...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-21T18:40:48.057", "Id": "521872", "Score": "1", "body": "You're missing code - including the definition for `HtmlSubjectPrefix`" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-21T18:45:35.240", "Id": "5...
[ { "body": "<p>There are many options. The most basic is to write a common routine with two frontends:</p>\n<pre><code>public List&lt;string&gt; SendTemplateAsSampleEmail(\n MtaConnection mtaConnection,\n ICollection&lt;EmailRecipient&gt; recipients,\n SimpleContentDto renderedContent)\n{\n if (strin...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-21T18:07:21.750", "Id": "264251", "Score": "-1", "Tags": [ "c#" ], "Title": "Factoring out common elements of an email transmission routine" }
264251
<p>Kind of a noob at Python here, and this is one of my first &quot;big&quot;(big for a beginner like me) project that I undertook with <a href="https://docs.python.org/3/library/tkinter.html" rel="nofollow noreferrer">Tkinter</a> and <a href="https://pynput.readthedocs.io/en/latest/index.html" rel="nofollow noreferrer...
[]
[ { "body": "<ul>\n<li><p>Format your code according to PEP-8, there are automatic checker and even automatic formatters for that.</p>\n</li>\n<li><p>This is often considered as code smell:</p>\n</li>\n</ul>\n<pre><code> def key_test(self, key):\n try:\n return key.name\n except:\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-21T19:30:09.023", "Id": "264257", "Score": "4", "Tags": [ "python", "beginner", "python-3.x", "tkinter" ], "Title": "Simple enemy movement simulation on Tkinter" }
264257
<p>After much prompting from <a href="https://stackoverflow.com/questions/68464998/is-this-use-of-concurrentdictionary-correct-and-safe?noredirect=1#comment120999877_68464998">this post</a> I wanted to build a simple, in-memory, thread-safe cache.</p> <p>The only caveat (as far as I was originally concerned) was the ne...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T05:43:07.970", "Id": "521903", "Score": "0", "body": "Looks almost fine. `InMemoryCache` can be readonly field not property. Also you can remove setters from all other properties then introduce a constructor for `CacheItem`." }, ...
[ { "body": "<p>No reason to have a public set on <code>public static CacheHelper Cache { get; set; }</code>\nnot anyway to set it so why expose it?</p>\n<p>I think CacheItem should be immutable. If calling Set with a CacheItem that IsFailureItem is true but later can be set to false, wouldn't effect time. Sam...
{ "AcceptedAnswerId": "264259", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-21T20:15:29.250", "Id": "264258", "Score": "2", "Tags": [ "c#", ".net", "thread-safety", "cache" ], "Title": "Simple MemoryCache implementation for thread safe caching" }
264258
<p>I am new to quant. finance and trying to calculate <code>trend</code>, <code>momentum</code>, <code>correlation</code> and <code>volatility</code>. Below are the functions I have created</p> <pre><code>import pandas as pd def roll_correlation(first_df, second_df, rolling_period): &quot;&quot;&quot; Rolling...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T03:32:41.417", "Id": "264264", "Score": "1", "Tags": [ "python", "pandas", "finance" ], "Title": "quant. code. to calculate trend, momentum, correlation and volatility in Pandas(P...
264264
<p>My code in Julia, almost identical as the Python code (see below), runs in 4.6 s while the Python version runs in 2.4 s. Obviously there is a lot or room for improvement.</p> <pre><code>function Problem12() #= The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triang...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T08:16:51.813", "Id": "521913", "Score": "0", "body": "What are compiler options for julia? Are you using interactive mode?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T08:32:38.693", "Id": "521...
[ { "body": "<p>You need the number of divisors, not divisors. So you don't need to gather all divisors, just remember the count. Increase it by 1 instead of push!/append, decrease instead of pop/</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T08:31...
{ "AcceptedAnswerId": "264347", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T07:41:09.383", "Id": "264270", "Score": "3", "Tags": [ "julia" ], "Title": "Project Euler #12 in Julia slower than Python?" }
264270
<p>I am completely new to JavaScript and I will be grateful for your comments on my Electron app (electron is a JS framework allowing to create of desktop apps).</p> <p>I needed to create an application that stores a small database and allows me to do simple operations on the data. I just include a small fraction of th...
[]
[ { "body": "<p>The easy stuff:</p>\n<ul>\n<li>Remove unnecessary comments. <code>loading view teams panel</code> - This comment adds nothing. If anything, it tells me that your code is not organized properly since you have to add these reminders. In the repo you have many more examples (for example <code>// JSON...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T08:22:42.983", "Id": "264275", "Score": "3", "Tags": [ "javascript", "beginner", "ecmascript-6", "electron" ], "Title": "Single user Electron application allowing basic CRUD o...
264275
<p>Recently I was assigned a URL shortener design problem while interviewing with a well known organization. Here is the exact problem statement:</p> <blockquote> <ol> <li><p>Build a simple URL shortener service that will accept a URL as an argument over a REST API and return a shortened URL as a result.</p> </li> <li>...
[]
[ { "body": "<p>Your code looks nice and readable in my opinion; I can understand most of what's going on. A few points I'm unsure about, however:</p>\n<p><strong>(1) Your exception handling seems a bit weird to me</strong></p>\n<p>In <code>filestore.py</code>, you catch all exceptions in your <code>__getitem__</...
{ "AcceptedAnswerId": "264278", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T09:23:43.717", "Id": "264277", "Score": "5", "Tags": [ "python", "object-oriented", "design-patterns", "interview-questions" ], "Title": "Designing an URL Shortener" }
264277
<p>I wrote the below as a solution to:</p> <h3 id="problem-lt3z">Problem</h3> <p>Find the highest product of three numbers in a list</p> <h3 id="constraints-s0r6">Constraints</h3> <ul> <li>Is the input a list of integers? <ul> <li>Yes</li> </ul> </li> <li>Can we get negative inputs? <ul> <li>Yes</li> </ul> </li> <li>Ca...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T12:49:17.553", "Id": "521931", "Score": "0", "body": "Just to make the last question clearer, I am asking \"If this were production code, what should or could I add that is currently missing?\"" }, { "ContentLicense": "CC BY...
[ { "body": "<p>Regarding readability, I'd say typing variables makes them harder to read. As is:</p>\n<pre class=\"lang-py prettyprint-override\"><code>mult = lambda x, y: x * y\n</code></pre>\n<p>I can already tell its a function with two arguments that returns their product. I think this just adds noise to tha...
{ "AcceptedAnswerId": "264293", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T12:46:12.903", "Id": "264279", "Score": "2", "Tags": [ "python-3.x", "algorithm", "complexity" ], "Title": "Find the highest product of three numbers in a list (Python)" }
264279
<p>I am working with <code>C#</code>, <code>Npgsql</code>, <code>EF Core</code> and <code>Postgres</code>.<br/> I defined an endpoint for a paginated search, where the filters and orderBy column are dynamic. The endpoint accepts a <code>PaginationOptions</code> instance:</p> <pre><code>public class PaginationOptions { ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T14:20:00.407", "Id": "521940", "Score": "0", "body": "Is the Guid-column the primary key?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T14:24:16.390", "Id": "521942", "Score": "0", "body...
[ { "body": "<p>Just a quick shot at</p>\n<pre><code>IDataReader reader = command.ExecuteReader();\nISet&lt;Guid&gt; guids = new HashSet&lt;Guid&gt;(paginationOptions.ItemsPerPage);\nwhile (reader.Read())\n{\n Guid guid = reader.GetGuid(0);\n if (!guids.Contains(guid))\n {\n guids.Add(guid);\n ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T14:01:53.307", "Id": "264280", "Score": "1", "Tags": [ "c#", "performance", "database", "entity-framework-core" ], "Title": "Database dynamic query" }
264280
<p>I completed the following question but it seems a lot of space complexity.</p> <p>Do you think is there a way to complete it with graph search or so?</p> <p>Thanks for the comments.</p> <p>Suppose we have some input data describing a graph of relationships between parents and children over multiple generations. The ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T17:31:22.983", "Id": "521956", "Score": "0", "body": "Can the number of nodes in the graph be taken as a parameter? Are the nodes always going to be labelled 1..n, where n is the number of nodes?" }, { "ContentLicense": "CC ...
[ { "body": "<p>Your space complexity looks like it is proportional to n (<code>O(n)</code>? I'm unsure of the notation). That doesn't seem bad to me, and I don't think it can be improved (but don't take my word for it, I'm not at all an expert). However, let me try cleaning up your code a bit. It's well-formatte...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T14:46:56.840", "Id": "264283", "Score": "1", "Tags": [ "java", "hash-map", "search" ], "Title": "Finding nodes with 0 or 1 parents - DFS or BFS" }
264283
<p>I've put together an example single file upload script that attempts to cover all the things PHP could check for prior to allowing a successful file upload. Is there anything else maybe now available in PHP 7.4+ I could use to make this more secure? For example, I use <code>filter_input</code> below even though I do...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T22:07:42.537", "Id": "522051", "Score": "2", "body": "Please do not describe the type of review that you are seeking in your title. Your title should only describe what your script does." }, { "ContentLicense": "CC BY-SA 4....
[ { "body": "<p>A few of my thoughts after quick top-to-bottom scan:</p>\n<p>Filtering REQUEST_METHOD is absurdly future-proof (you'd have to anticipate an evolution of the code where the literal contents are stored in a database and end up being output without validation to somebodies browser),\nbut somehow I l...
{ "AcceptedAnswerId": "264338", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T15:59:16.937", "Id": "264285", "Score": "1", "Tags": [ "php" ], "Title": "PHP File Upload Script" }
264285
<p>Coming from a Java/Scala background with a strong focus on <strong>OOP+FP</strong>, I recently started working with Excel+VBA to implement a front-end for a SaaS. It was like stepping way back in time, over two decades, in software engineering trying to understand how to use and exploit VBA.</p> <p>In the ensuing 3 ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T07:17:37.327", "Id": "521986", "Score": "1", "body": "Fwiw, the late Chip Pearson's [Functions for VBA arrays](http://www.cpearson.com/excel/vbaarrays.htm) cover edge cases very rigorously, although I cannot vouch for how performant...
[ { "body": "<p>Once you know you have an array it looks to me that this comparison is unecessary:</p>\n<pre><code>If (lngLBound &lt;= lngUBound) Then\n lngSize = lngUBound - lngLBound + 1 'Non-Empty, so return size\nEnd If\n</code></pre>\n<p>The reason being that if you have an uninitialized array then</p>\n<pr...
{ "AcceptedAnswerId": "264359", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T18:00:16.427", "Id": "264287", "Score": "2", "Tags": [ "array", "vba" ], "Title": "To what degree is my VBA Array size function safe, robust, and performant" }
264287
<p>This nice hack should allow you to split a tuple into N-element tuples, thereby effectively splitting a tuple into pairs, triples, ... For example, this allows you to split an input parameter pack, into N-element tuples. Your thoughts?</p> <pre><code>template &lt;std::size_t N&gt; constexpr auto split(auto&amp;&amp;...
[]
[ { "body": "<ol>\n<li><p>Corner-cases needing manual handling by the caller are the bane of correct and generic code.</p>\n<p>Remove them as possible, even if it would slightly complicate the implementation (it doesn't here). If it would impair efficiency that would necessitate more careful consideration, but mi...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T18:36:46.393", "Id": "264289", "Score": "2", "Tags": [ "c++", "template", "lambda", "c++20", "variadic" ], "Title": "splitting a tuple into N-element tuples" }
264289
<p>I have made a thread art generator that creates thread patterns from images. Mine is a bit different as it outputs an embroidery file (It embroiders quite nicely, though the settings need a lot of tweaking and the output file needs resizing) The code is quite inefficient, but that's python for you.</p> <pre><code>fr...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T02:25:00.873", "Id": "521973", "Score": "0", "body": "What do you want to improve?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T03:44:51.910", "Id": "521976", "Score": "0", "body": "It ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T19:13:47.150", "Id": "264292", "Score": "5", "Tags": [ "python", "python-3.x" ], "Title": "Thread Art Generation that Creates Embroidery Files" }
264292
<p>I have written a cryptographic hashing class named <code>Ccksum::DigestHasher</code> that allows the caller to select a hashing algorithm by name via OpenSSL's EVP interface. This class is the bread and butter of my <a href="https://gitlab.com/app-crypt/ccksum" rel="nofollow noreferrer">Ccksum</a> programming projec...
[]
[ { "body": "<p>This looks quite good already. However, some improvements can be made:</p>\n<h1 id=\"avoid-unnecessary-use-of-stringstreams-ke34\">Avoid unnecessary use of <code>stringstream</code>s</h1>\n<p>String streams are quite heavy, so using it to build small strings is perhaps not the way to go. Instead o...
{ "AcceptedAnswerId": "264315", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-22T22:49:58.477", "Id": "264299", "Score": "4", "Tags": [ "c++", "c++17", "cryptography", "openssl" ], "Title": "Cryptographic hashing class using OpenSSL's EVP interface" }
264299
<p>I started making a game in curses, but I feel like I am displaying the map inefficiently and ineffectively.</p> <p>Here's the code (only the relevant parts):</p> <pre><code>import curses world_map = [ '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T09:16:40.263", "Id": "521995", "Score": "0", "body": "If the water is the char that appears the most you can first fill the screen with it and than color only the things that are not water. You can also compare the prev frame to the...
[ { "body": "<p>Here's a slight refactoring of your code to improve readability and reduce repetitiveness. (I don't think anything I'm doing here will do much for you in terms of performance, sadly.)</p>\n<pre><code>import curses as c\nfrom itertools import product \n\nworld_map = [\n '000000000000000000000000...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T01:55:13.830", "Id": "264300", "Score": "3", "Tags": [ "python", "curses" ], "Title": "Displaying a \"map\" with curses and python" }
264300
<p>We wrote a code that parallelizes the divide phase of the mergesort algorithm. I.e. every recursive call is assigned to a thread but our teacher was disappointed because he said we should also parallelize the merge function. I have researched how one can do this and I found these (algorithm 3) <a href="https://stanf...
[]
[ { "body": "<pre><code>/**\n * helper routine: check if array is sorted correctly\n */\nbool isSorted(int ref[], int data[], const size_t size){\n</code></pre>\n<p>Review the standard library to be familiar with what all is in it. Specifically, look at <a href=\"https://en.cppreference.com/w/cpp/algorithm#Sor...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T02:01:42.307", "Id": "264301", "Score": "1", "Tags": [ "c++", "mergesort", "openmp" ], "Title": "Parallezing merge step and divide step in mergesort algorithm with OpenMP" }
264301
<p>I want to refactor this code to a better version without all this repetition, this code is working 100% the way it is right now but every refactoring effort is making it useless, any idea or can this be considered the maximum ?</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-bab...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T20:33:16.243", "Id": "522044", "Score": "1", "body": "So that we can advise you properly, please provide context so that we can understand what this code accomplishes." } ]
[ { "body": "<h2 id=\"reducing-source-complexity-8q1j\">Reducing source complexity</h2>\n<p>There is a rule in coding, <em>&quot;If it works leave it alone!&quot;</em></p>\n<p>However when developing code you should aim for simplicity in code, that includes keeping code D.R.Y. (Don't Repeat Yourself).</p>\n<p>Its...
{ "AcceptedAnswerId": "264308", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T02:59:40.640", "Id": "264302", "Score": "-1", "Tags": [ "javascript" ], "Title": "refactor multi if statements and checking for div existence in a better style" }
264302
<h2 id="question">QUESTION:</h2> <p>You will set up simultaneous thumb wrestling matches. In each match, two trainers will pair off to thumb wrestle. The trainer with fewer bananas will bet all their bananas, and the other trainer will match the bet. The winner will receive all of the bet bananas. You don't pair off tr...
[]
[ { "body": "<h3 id=\"recursion-is-good-only-if-you-know-its-depth-0fve\">Recursion is good only if you know its depth</h3>\n<p>If you have a tree with maximum depth of 100 or so - recursion is normal to traverse it. But here you can get a million steps of recursion for a stupid example of gcd(1,1000000). Change ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T06:54:18.720", "Id": "264310", "Score": "3", "Tags": [ "java", "array" ], "Title": "Google Foobar - \"Distract the Trainers\"" }
264310
<h3 id="origin-code-hf1w">origin code:</h3> <pre><code># add this class to make the code can be a reproducible example.In acutually environment all attribute could be True or False. class Capabilities: def __init__(self) -&gt; None: self.canEditCompany = True self.canDeleteCompany = True sel...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T14:01:02.683", "Id": "522013", "Score": "0", "body": "This doesn't have enough contextual information. What are you actually trying to do? Where do those boolean values come from - are they hard-coded, or set from process environmen...
[ { "body": "<p>I might be inclined to do something like this:</p>\n<pre><code>class Capabilities:\n def __init__(self) -&gt; None:\n self.canEditCompany = True\n self.canDeleteCompany = True\n self.canShareCompany = True\n self.canAddFiscal = True\n self.canAddCategory = Tru...
{ "AcceptedAnswerId": "264331", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T10:25:14.547", "Id": "264318", "Score": "5", "Tags": [ "python" ], "Title": "Assigning permissions to multiple endpoints for a user and company" }
264318
<p>I am looking for a simpler implementation of the following question.</p> <p>Could it get better?</p> <p>I am expecting the new solution via DFS again. Thanks.</p> <p>OA: Given a 2d matrix with chars and a target string.</p> <p>Check if the matrix contains this target string</p> <p>by only going right or down each ti...
[]
[ { "body": "<p>What I couldn't deduce from the problem description was the definition of &quot;going right&quot; in the last column (usually it means &quot;go the first cell of the next row&quot;) but here it'd might just as well be &quot;not allowed&quot;. Same question for &quot;going down&quot; by symmetry.</...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T11:35:27.533", "Id": "264319", "Score": "0", "Tags": [ "java", "matrix", "depth-first-search" ], "Title": "Given a 2d matrix with chars find the target string" }
264319
<p>Based on a previous post, <a href="https://codereview.stackexchange.com/questions/263626/accelerating-creation-of-matrices-and-finding-ways-for-optimal-scaling">Accelerating creation of matrices and finding ways for optimal scaling</a>, we managed to accelerate the way that I construct a matrix in Rcpp (inputs for e...
[]
[ { "body": "<p>Code review is normally meant to review complete and working code, not for getting answers to questions like &quot;how should I ...?&quot; However, since you presented code for all the alternatives you've come up with, I'll review it.</p>\n<h1 id=\"avoid-doing-things-you-have-to-fix-up-later-tpvn\...
{ "AcceptedAnswerId": "264330", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T12:59:20.203", "Id": "264322", "Score": "0", "Tags": [ "c++", "performance", "r", "rcpp" ], "Title": "An efficient way for removing rows with zero elements iteratively whi...
264322
<p>I started implementing the folowing Matrix class in order to get a better understanding of templates classes in general. For now, it lacks a lot of features, it does very basic things:</p> <ul> <li>addition</li> <li>multiplication (only matrix X matrix multiplication is available here)</li> <li>transpose</li> <li>co...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T18:35:58.400", "Id": "522036", "Score": "0", "body": "Very well elaborated. Thank you for that. Hopefully you will get some answers." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T19:23:16.190", ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T15:44:16.157", "Id": "264327", "Score": "1", "Tags": [ "c++11", "matrix", "template" ], "Title": "template Matrix class with Static or dynamic size" }
264327
<p>I implemented the Maximum Profit in Job Scheduling algorithm in JavaScript, but I'm having performance issue.</p> <p>The problem: We have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], obtaining a profit of profit[i].</p> <p>You're given the startTime, endTime and profit arrays, ret...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T18:50:50.457", "Id": "522126", "Score": "0", "body": "@radarbob Why 400%? Do you mind showing your solution?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T20:16:13.097", "Id": "522132", "Sco...
[ { "body": "<p>There are some readability concerns to me:</p>\n<ul>\n<li><code>startTime</code>, <code>endTime</code>, <code>profit</code> are all arrays. The names should be plural to make this obvious.</li>\n<li><code>possibleStarts</code> consists of both start and end. It's confusing. You could instead make ...
{ "AcceptedAnswerId": "264492", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T19:19:07.323", "Id": "264332", "Score": "1", "Tags": [ "javascript", "performance", "algorithm", "time-limit-exceeded" ], "Title": "Maximum Profit in Job Scheduling - Perf...
264332
<p>I wrote a short function to iterate over a list starting at a given index, then flipping back and forth between left and right values.</p> <pre class="lang-py prettyprint-override"><code>import itertools from typing import Generator def bidirectional_iterate(lst: list, index: int) -&gt; Generator: for left, ri...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-24T00:45:33.330", "Id": "522060", "Score": "3", "body": "Why is the expected output and the actual output different?" } ]
[ { "body": "<p>Here's an alternative approach that requires no conditional logic and does not create intermediate sub-lists — although at the cost of using a third-party\nlibrary:</p>\n<pre><code>from more_itertools import interleave_longest\n\ndef bidirectional_iterate(xs, index):\n left = range(index - 1, -...
{ "AcceptedAnswerId": "264341", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T19:34:43.787", "Id": "264334", "Score": "6", "Tags": [ "python", "iterator", "generator" ], "Title": "Bidirectional iterate over list in Python" }
264334
<p>Hello how can i send a token from the msg.sender to mycontract through a function inside my contract?</p> <ol> <li>i tried to do a transferFrom &quot;<code>IERC20(old_tokenAddress).transferFrom(msg.sender, address(this), query_oldBalance(msg.sender));</code>&quot; but i get: <code> execution reverted: ERC20: transf...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T09:17:36.633", "Id": "522171", "Score": "1", "body": "We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review. Please [**follow the tour**](https://CodeReview.StackExchan...
[ { "body": "<p><code>IERC20(_tokenAddress).transferFrom(msg.sender, address(this), old_balance);</code> was right but before call this func the user should approve the <strong>address</strong> of the <strong>new</strong> token <strong>ON</strong> the <strong>old</strong> token contract</p>\n", "comments": []...
{ "AcceptedAnswerId": "264400", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-23T21:30:26.527", "Id": "264337", "Score": "-3", "Tags": [ "solidity" ], "Title": "Send token from addressA to addressB through contract" }
264337
<p>So I have this piece of code that produces following error:</p> <pre><code>cannot return value referencing local variable `key_name` returns a value referencing data owned by the current function </code></pre> <p>I want it to evaluate the <code>Key</code> range and produce a map of strings, but it fails on the line ...
[]
[ { "body": "<p><code>short_key_name</code> is a <code>&amp;str</code> that was borrowed from <code>key_name</code>, a <code>String</code> allocated inside the loop and which will be dropped at the end of each loop iteration. Thus, it is <em>not</em> a <code>&amp;'static str</code>.</p>\n<p>You can use <code>Box:...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-24T00:13:21.897", "Id": "264339", "Score": "-1", "Tags": [ "rust" ], "Title": "Rust: lazy_static the strings from evdev codes" }
264339
<p>The first function will always try to correct the final result, while the second uses a conditional to know when to compensate. I think that in general the second function will be faster, but it will look a little worse than the first.</p> <pre class="lang-c prettyprint-override"><code>int floor_mod1(int a, int b) {...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-24T05:14:33.330", "Id": "522067", "Score": "2", "body": "Personally I prefer the first version which - at least for me - is easier to read. If you one day notice that you have a performance issue in the function you can take a look at ...
[ { "body": "<p>You can use <a href=\"https://godbolt.org/z/1cKbnqr3n\" rel=\"nofollow noreferrer\">Godbolt</a> to play around with the C code and see if anything makes the assembly look particularly better. (Seems like Clang is strangely much better than GCC at making this code branch-free.)</p>\n<p><em>Technica...
{ "AcceptedAnswerId": "264388", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-24T00:23:55.330", "Id": "264340", "Score": "3", "Tags": [ "c++", "performance", "c" ], "Title": "floor modulo or modulo rounding towards negative infinity" }
264340
<p>I am trying to build a model that allows me to estimate the spread of disease in the population. The setup is similar to the SIR model, with the difference that this model includes the stochastic component.</p> <p>I have written an algorithm to carry out the simulation, but the lead times are really high. Could you ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-24T15:28:01.370", "Id": "522088", "Score": "0", "body": "Please follow our guidelines WRT titling your question: https://codereview.stackexchange.com/help/how-to-ask" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "...
[ { "body": "<ol>\n<li>we should remove <code>dimnames</code> from matrix, as it slows sub-setting. They can be added after loops with: <code>dimnames(Pop_over_time) &lt;- list(1:Population, paste0(&quot;T&quot;,1:Time))</code></li>\n<li>working with characters is slower than integers, so we can replace <code>S/I...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-24T11:51:41.287", "Id": "264350", "Score": "2", "Tags": [ "performance", "r", "simulation" ], "Title": "Simulating disease spread in a population" }
264350
<p>With my VB.Net Windows Forms application, I would like to rotate and project a 3D object. The program works so far, which is why I'm reporting here and not Stack Overflow, but it's slow. I've already made two optimizations:</p> <p><strong>1.)</strong> All points that are on the back of the object, i.e. that cannot b...
[]
[ { "body": "<p>I can answer my question myself today. I let Visual Studio's own performance profiler work, and it found that most of the clock cycles (93%) are used for <a href=\"https://docs.microsoft.com/en-us/dotnet/api/system.drawing.graphics.drawline?view=netframework-4.8\" rel=\"nofollow noreferrer\">DrawL...
{ "AcceptedAnswerId": "264426", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-24T15:58:36.673", "Id": "264354", "Score": "1", "Tags": [ "performance", "asynchronous", "animation", "vb.net" ], "Title": "My 3D to 2D graphics algorithm is being a bit slow...
264354
<p>New Scala dev here. Is there a more idiomatic or efficient way to accomplish this in Scala?</p> <p>Given a list of the following strings, I need to obtain the unique 'main parts' once any parts including and after a &quot;-&quot; have been removed.</p> <p>The output should be a list of sorted strings. Also note bot...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T23:09:45.627", "Id": "522145", "Score": "0", "body": "Can you add some more context about why you're doing this? It'd be very helpful." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-28T03:53:49.277", ...
[ { "body": "<p>Maybe regex to the rescue?</p>\n<pre><code>val formatRegexp = &quot;([A-Za-z0-9]+)(-.*)?[;,]?&quot;.r\ndata.map(_.split(&quot; &quot;).map({\n case formatRegexp(value, _*) =&gt; value\n case _ =&gt; &quot;&quot;\n}).sorted.distinct.mkString(&quot; &quot;) )\n</code></pre>\n", "comments": [ ...
{ "AcceptedAnswerId": "264361", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-24T18:20:42.487", "Id": "264356", "Score": "1", "Tags": [ "beginner", "strings", "parsing", "scala" ], "Title": "Extracting items from comma/semicolon-delimited strings, disc...
264356
<p>I have been on the C++ learning grind for the last 2 weeks using caveofprogramming videos so don't judge too hard if this seems like a dumb question.</p> <p>My last lesson covered arrays and the assignment was to make a 10x10 times table using multidimensional arrays. I succeeded in making this times table but with ...
[]
[ { "body": "<p>If you're sure about the data that you want in your array, like the one you mentioned, each row is an arithmetic progression, then this can be done easily using loop.</p>\n<pre><code>int n = 10, m = 10; //you can take this as user input\nint animals[n][m];\nint indexRow, indexColumn;\nfor (indexRo...
{ "AcceptedAnswerId": "264368", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T01:10:40.030", "Id": "264362", "Score": "1", "Tags": [ "c++", "array" ], "Title": "Print a 10x10 times table" }
264362
<p>I am trying to learn Groovy and I did an attempt on implementing a simple Battleship game. Any feedback is welcome. I will start with the modal classes I have.</p> <p><strong>Modal classes</strong></p> <p>Coordinate.groovy</p> <pre><code>package biz.tugay.groovyship.modal import groovy.transform.Memoized /** * A ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T04:33:09.287", "Id": "264365", "Score": "0", "Tags": [ "groovy", "battleship" ], "Title": "Simple battleship game in Groovy" }
264365
<p>I'm playing around with understanding array looping speed. I'm trying to make the contenders equivalent and close to realistic.</p> <ul> <li>Is this a good approach?</li> <li>Are there other iteration approaches to test?</li> </ul> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-bab...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T12:36:29.153", "Id": "522188", "Score": "0", "body": "One issue is that this isn't a fair comparison, especially the array methods. `map` is used to transform one array to another. `reduce` is for reducing an array to one value. Sur...
[ { "body": "<h2 id=\"the-real-world-9vr3\">The real world</h2>\n<p>You can test one style against another and learn nothing about which is the more performant.</p>\n<p>Benchmarking JS code only has meaning when you are testing an actual real world example.</p>\n<p>Why, because even the smallest seemingly inconse...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T06:26:38.627", "Id": "264367", "Score": "2", "Tags": [ "javascript", "array", "benchmarking" ], "Title": "Is this a reasonable way to test/compare javascript loop speeds?" }
264367
<p>I've been trying to make a rubik's cube project and it succeeds nicely . The only problem(or something like that) is that i need to optimize my code for easier understanding and more flexibility. Here's my code to optimize:</p> <pre><code>[...]//Code for creating cubes int main() { [...]//some extra codes while ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T15:36:48.080", "Id": "522122", "Score": "1", "body": "My compiler complains when compiling `[...]`. Could you replace it with the actual code? If it is too much to fit, at least link it somewhere else?" }, { "ContentLicense"...
[ { "body": "<h1 id=\"use-an-enum-class-to-represent-the-axes-zaz4\">Use an <code>enum class</code> to represent the axes</h1>\n<p>Instead of using an <code>int</code>, declare an <a href=\"https://en.cppreference.com/w/cpp/language/enum#Scoped_enumerations\" rel=\"nofollow noreferrer\"><code>enum class</code></a...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T07:45:24.567", "Id": "264369", "Score": "3", "Tags": [ "c++", "opengl" ], "Title": "Rubik's Cube rotation with OpenGL" }
264369
<blockquote> <p>The cube, 41063625 (3453), can be permuted to produce two other cubes: 56623104 (3843) and 66430125 (4053). In fact, 41063625 is the smallest cube which has exactly three permutations of its digits which are also cube.</p> <p>Find the smallest cube for which exactly five permutations of its digits are c...
[]
[ { "body": "<h3 id=\"tend-to-use-one-style-opt9\">Tend to use one style</h3>\n<pre><code>perm for perm in perms if len(str(perm)) == len(str(cube))\n</code></pre>\n<p>and</p>\n<pre><code>filter(is_cube, perms)\n</code></pre>\n<p>are almost the same: an iterator that applies some filter. Don't confuse the reader ...
{ "AcceptedAnswerId": "264405", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T08:19:20.403", "Id": "264370", "Score": "0", "Tags": [ "python-3.x", "programming-challenge" ], "Title": "Cubic Permutations | Project Euler #62" }
264370
<p>This is a custom case insensitive nested dictionary class created by me, its main usage is to populate QTreeWidget and keep track of said QTreeWidget, the main incentive behind this class is to prevent case insensitive duplicates from entering the tree, and to report the indexes of the nested keys (<code>d = {'a': {...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T15:03:25.320", "Id": "522118", "Score": "0", "body": "`treefy` won't run; `fields` is undefined." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T15:14:46.370", "Id": "522119", "Score": "4", ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T08:42:59.777", "Id": "264371", "Score": "1", "Tags": [ "python", "performance", "beginner", "python-3.x" ], "Title": "Python case insensitive three level nested dictionary" }
264371
<p>Im just trying to setup my shader function in a class in a way that would make me work with it easier and in a more understandable way.</p> <p>In Shader.h:</p> <pre><code>#pragma once #include&quot;Includes.h&quot; #include&lt;unordered_map&gt; namespace GAME { enum class Shader_Type { NONE = -1, ...
[]
[ { "body": "<p>Various suggestions:</p>\n<ul>\n<li><p>Use the OpenGL types (e.g. <code>GLuint</code>, <code>GLint</code>) for the variables that need them. It's more portable, and the purpose of the variables is clearer.</p>\n</li>\n<li><p>Don't store the shader source inside the shader. We don't need it after c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T08:47:46.300", "Id": "264372", "Score": "0", "Tags": [ "c++", "opengl", "shaders" ], "Title": "Reviewing my shader class for efficient use" }
264372
<pre><code>#include &lt;iostream&gt; #include &lt;openssl/x509.h&gt; #include &lt;openssl/x509_vfy.h&gt; #include &lt;sstream&gt; #include &lt;sys/types.h&gt; #include &lt;sys/socket.h&gt; #include &lt;netdb.h&gt; #include &lt;string.h&gt; #include &lt;unistd.h&gt; #include &lt;vector&gt; #include &lt;string&gt; #in...
[]
[ { "body": "<h2 id=\"first-impression-hnhx\">First impression</h2>\n<p>Well I spend some time and while still there many issues left lets get to the most urgent ones:</p>\n<p>The most important rules in software development are divide&amp;conquer, you have one monolith class that is doing every thing which makes...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T12:51:10.297", "Id": "264375", "Score": "2", "Tags": [ "c++", "http", "https" ], "Title": "A C++ library that sends and receives data using HTTPS or HTTP" }
264375
<p>This question is complicated (at least for me who is new in machine learning and image processing).</p> <p>I need help in understanding, why my iterative process is minimising the ratio of inter-class scatter by intra-class scatter after Fisher-Rao discrimination, rather than maximising it.</p> <p>Background:</p> <p...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T21:23:12.270", "Id": "522137", "Score": "0", "body": "https://cs.stackexchange.com/q/142640/755" } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T13:16:02.363", "Id": "264376", "Score": "0", "Tags": [ "python", "machine-learning" ], "Title": "Ratio of intra-class scatter by inter-class scatter is getting minimised by linear dis...
264376
<p>I have a csv file that looks like this:</p> <pre><code> time, price 0 2021-07-23T20:00:00.000221421Z 368.06 1 2021-07-23T20:00:00.001131397Z 368.06 2 2021-07-23T20:00:00.008030544Z 368.06 3 2021-07-23T20:00:00.00807574Z 368.06 4 2021-07-23T20:00:00.008084129Z 368.06 ... ... ... 32435 2021-07-23T...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T13:16:54.170", "Id": "264377", "Score": "3", "Tags": [ "python", "pandas" ], "Title": "pandas.DaraFrame resample OHLC based on a non-time value" }
264377
<p><strong>Problem:</strong> Given two csv files <code>science_courses.csv</code> and <code>other_courses.csv</code>, which has students name and their respective course points. Calculate the CGPA and sort by the same (highest to lowest CGPA).</p> <p>sample file content:</p> <pre><code>science_courses.csv: Name,Physic...
[]
[ { "body": "<p>First of all: don't use Python2, it's end of life. The telltale sign that you're using it is the lack of parentheses to the print function.</p>\n<p>Since Python has a built-in library for reading CSV files, it would make sense to use it. The parsing would be more elegant and straightforward.</p>\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T14:47:43.523", "Id": "264379", "Score": "2", "Tags": [ "python", "csv" ], "Title": "Calculate students' GPAs and sort them, based on two CSV input files" }
264379
<p>I'm learning PHP and try to write some scripts as I go along. I wrote this script and it worked. I would like to know if this script can be improved.</p> <p>The purpose of the script below is to prompt the user to input the version of the backup file, and proceed to make a backup fo the Nextcloud directory.</p> <p>T...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T23:39:50.033", "Id": "522224", "Score": "0", "body": "Please do not edit the question, especially the code, after an answer has been posted. Changing the question may cause answer invalidation. Everyone needs to be able to see what ...
[ { "body": "<p>Just one quick remark: as per the <a href=\"https://www.php.net/manual/en/function.shell-exec.php\" rel=\"nofollow noreferrer\">docs</a> shell_exec returns the complete output as a string. And:</p>\n<blockquote>\n<p>This function can return null both when an error occurs or the program\nproduces n...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T15:16:52.320", "Id": "264380", "Score": "1", "Tags": [ "php" ], "Title": "backup file script in PHP" }
264380
<p>My goal is to write code that picks several random numbers from a range without repeating any previously chosen numbers. I figured out a functional solution for my problem but it seems very bulky and there must be a way to do this in fewer lines. Mine feels brute force and not very elegant and becomes super unwieldy...
[]
[ { "body": "<ul>\n<li>\n<blockquote>\n<p>if key4 != key1 and key4 != key2 and key4 != key3:</p>\n</blockquote>\n<p>If you append to <code>key_order</code> upon picking a non-duplicate value you can just use <code>in</code> instead.</p>\n</li>\n<li><p>You can then more simply use a for loop to select the number o...
{ "AcceptedAnswerId": "264385", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T15:43:50.663", "Id": "264382", "Score": "6", "Tags": [ "python", "python-3.x", "random" ], "Title": "Python code for eliminating options for random intergers as they get picke...
264382
<p>I have this Python code:</p> <pre class="lang-py prettyprint-override"><code>def main() -&gt; None: print(&quot;Welcome To UltiList!&quot;) lst = [] len_of_list = int(input(&quot;Enter the len of the list: &quot;)) while len(lst) &lt;= len_of_list: print(&quot;&gt;&gt; &quot;, end=&quot;&qu...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-27T07:01:32.940", "Id": "522245", "Score": "0", "body": "Please see *[What to do when someone answers](/help/someone-answers)*. I have rolled back Rev 2 → 1." } ]
[ { "body": "<p>Your 'switch statement' is bad because you've chosen to not use the same algorithm as your JavaScript example:</p>\n<blockquote>\n<pre class=\"lang-js prettyprint-override\"><code>const commands = {\n append: (arg)=&gt;lst.append(arg),\n remove: (arg)=&gt;lst.remove(arg),\n ...\n}\n</code></pre...
{ "AcceptedAnswerId": "264386", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T16:06:48.483", "Id": "264384", "Score": "1", "Tags": [ "python", "python-3.x" ], "Title": "Python program to manipulate a list based on user input" }
264384
<p>This is a problem from Daily Coding Problem. I have implemented it in Java. For a function <code>f</code> I have used <code>Runnable</code> interface.</p> <p>Problem:</p> <p>This problem was asked by Apple.</p> <p>Implement a job scheduler which takes in a function <code>f</code> and an integer <code>n</code>, and c...
[]
[ { "body": "<h2 id=\"basics\">Basics</h2>\n<p>First of all, you've got the basics right, being naming conventions, indentation, and a rather sane OOP structure. But you ask for review, so here I go.</p>\n<h2 id=\"reinventing-the-wheel\">Reinventing the wheel</h2>\n<p>You probably know the <code>Timer</code> clas...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T17:37:10.203", "Id": "264387", "Score": "1", "Tags": [ "java", "multithreading", "scheduled-tasks" ], "Title": "Daily coding problem: Job scheduler invoking a function after speci...
264387
<p>I have implemented a simple XOR encryption in Python. However I am not sure this is the right implementation or it can be further improved ?</p> <pre><code>from math import ceil from random import uniform from numpy import array, repeat, vectorize #---------- HELPER FUNCTIONS ----------# def addtrailingzero(byt...
[]
[ { "body": "<p>You're converting your text to ASCII ordinals (good-ish) but then converting those ordinals to binary-formatted strings (deeply ungood). A change of thinking is needed: rather than managing a string where every single character is either an ASCII &quot;1&quot; or an ASCII &quot;0&quot;, you need t...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T19:37:51.510", "Id": "264390", "Score": "3", "Tags": [ "python", "encryption" ], "Title": "Is this a true implementation of XOR in python?" }
264390
<p>I am new to python, and even more new to vectorization. I have attempted to vectorize a custom similarity function that should return a matrix of pairwise similarities between each row in an input array.</p> <p><strong>IMPORTS:</strong></p> <pre><code>import numpy as np from itertools import product from numpy.lib.s...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-25T20:40:09.753", "Id": "264393", "Score": "2", "Tags": [ "python", "numpy", "vectorization" ], "Title": "Vectorizing a working custom similarity function further using numpy" }
264393
<h1 id="benchmark-0438">Benchmark</h1> <p>An optimised 4x4 double precision matrix multiply using intel AVX intrinsics. Two different variations.</p> <p><a href="https://gist.github.com/juliuskoskela/1a5ce40794325b2dac4a2a072ce5d404" rel="nofollow noreferrer">Gist</a></p> <p>For quick benchmark (with a compatible syste...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T08:20:33.483", "Id": "522161", "Score": "0", "body": "You've clearly done your homework, but can you explain a bit about the expected usage patterns? For example, it makes a difference whether the operands/result are always expected...
[ { "body": "<p>It looks pretty good to me. I still have some notes to make.</p>\n<p>Let's start with, there are 5 arithmetic operations (per row) to do the work that 4 FMAs could do. How good or bad is that? Well basically not bad at all in the context of just a simple 4x4 multiplication, because there are also ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T00:31:32.057", "Id": "264397", "Score": "4", "Tags": [ "performance", "c", "assembly", "graphics", "x86" ], "Title": "4x4 double precision matrix multiply using AVX intrin...
264397
<p>i have created an object orientated Calculator without GUI.</p> <p>i have provided only the most important parts of the code. I want to add another review question for those parts (especially: <code>MathResult</code> and <code>Operands</code>)</p> <h2 id="interface-calculator">Interface Calculator</h2> <pre><code>pu...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T09:00:14.643", "Id": "522163", "Score": "1", "body": "I'd like to comment about the classes/interfaces architecture, but you've left out too many classes/interfaces to do that, e.g. `Operation`." }, { "ContentLicense": "CC B...
[ { "body": "<h2 id=\"naming\">Naming</h2>\n<p>What you call &quot;operation&quot;, in most cases I'd rename to be an &quot;expression&quot;.</p>\n<h2 id=\"documentation\">Documentation</h2>\n<p>You create a quite complex set of classes and interfaces, and the only hint about their usage is in the class and metho...
{ "AcceptedAnswerId": "264415", "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T06:30:02.730", "Id": "264403", "Score": "3", "Tags": [ "java", "object-oriented", "reinventing-the-wheel" ], "Title": "Java OOP Calculator (no GUI)" }
264403
<p>I would like to ask you to verify the following implementation of the <a href="https://en.cppreference.com/w/cpp/language/pimpl" rel="nofollow noreferrer">PIMPL</a> idiom. In this dummy implementation the stream is read into a string.</p> <p>X.h</p> <pre><code>#ifndef X_H #define X_H #include &lt;memory&gt; #includ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T15:43:50.940", "Id": "522200", "Score": "0", "body": "`mynamespace::X` doesn't look like __real code__ from a project you wrote or maintain, so isn't within scope for Code Review. See [help centre](/help/on-topic)." }, { "C...
[ { "body": "<pre><code> X();\n</code></pre>\n<p>Since we specify a value constructor, the compiler won't generate the default constructor. So we don't need to declare it <code>private</code> to prevent its use.</p>\n<hr />\n<p>The move operators can declared <code>= default</code>:</p>\n<pre><code> X(X&amp...
{ "AcceptedAnswerId": "264414", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T09:35:32.133", "Id": "264407", "Score": "3", "Tags": [ "c++", "c++11" ], "Title": "An implementation of the PIMPL idiom" }
264407
<p>This is the first time I have recoded in C for several years and I would like to know how clean my code is.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; #define EXIT_SUCCESS 0 void fizzbuzz(int n) { char result[9] = &quot;&quot;; // strlen(&quot;fizzbuzz&quot;) + 1 == 9 if (n % 3 == 0...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-27T09:21:40.827", "Id": "522264", "Score": "1", "body": "C/C++ are particularly unforgiving languages. It's your responsibility to abide by the rules or face the consequences. This is why, even in trivial cases, I would rather not deli...
[ { "body": "<blockquote>\n<pre><code> #define EXIT_SUCCESS 0\n</code></pre>\n</blockquote>\n<p>You are not permitted to define standard library names yourself. So just include <code>&lt;stdlib.h&gt;</code>, or omit the <code>return</code> from <code>main()</code> (remember, C will provide a success return if yo...
{ "AcceptedAnswerId": "264412", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T09:54:30.847", "Id": "264408", "Score": "7", "Tags": [ "c", "fizzbuzz" ], "Title": "Fizzbuzz in C lang" }
264408
<p>This is a Python case insensitive dictionary that is ordered and has integer indexes for the keys and values.</p> <p>I just wrote it today.</p> <p>It is ordered because I am using Python 3.9.6 and plain <code>dict</code> is already ordered by default.</p> <p>It prevents case insensitive duplicate keys from entering ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T14:31:50.253", "Id": "522193", "Score": "3", "body": "Why is this needed? Show the code that uses it and some example contents." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T18:51:35.860", "Id":...
[ { "body": "<p><strong>How can I make a custom data structure as fast as <code>dict</code>?</strong></p>\n<p>You can't (at least, not in CPython). CPython's <code>dict</code> is written in C, as are other <code>dict</code> variants in the standard library such as <code>collections.defaultdict</code>. If you want...
{ "AcceptedAnswerId": "264460", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T10:17:59.500", "Id": "264411", "Score": "0", "Tags": [ "python", "performance", "beginner", "python-3.x" ], "Title": "Python case insensitive dictionary" }
264411
<p>Im currently working on a filtering keywords. I have two lists which I called positive and negative.</p> <p>Scenarios:</p> <ol> <li>if <code>POSITIVE</code> matches and <strong>NOT</strong> <code>NEGATIVE</code>matches = <strong>True</strong></li> <li>if <code>POSITIVE</code> matches and <code>NEGATIVE</code>matches...
[]
[ { "body": "<p>That's a <em>lot</em> of regexes to compute. I'm going to suggest that you only run one regex, to split the string up into words; and from there represent this as a series of set operations.</p>\n<p>If I understand it correctly, you basically have two different cases in your filter words:</p>\n<ul...
{ "AcceptedAnswerId": "264430", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T14:07:41.413", "Id": "264419", "Score": "1", "Tags": [ "python-3.x" ], "Title": "Filtering string by given keywords" }
264419
<pre><code>class RadarChecker: def __init__(self) -&gt; None: self._issues = set() @property def issues(self) -&gt; Set[str]: return self._issues @property def _checkers(self) -&gt; Iterable[Callable]: return ( self._check_1, self._check_2, ...
[]
[ { "body": "<p>In this case, I would really keep it simple. I would drop the OOP and just write a simple function that validates the radar and returns a list of issues. To be clear:</p>\n<pre><code>def check_radar(radar: Radar) -&gt; Set[str]:\n return {\n *_check_1(radar),\n *_check_2(radar),\n...
{ "AcceptedAnswerId": "264432", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T18:28:35.330", "Id": "264425", "Score": "2", "Tags": [ "python", "object-oriented", "design-patterns" ], "Title": "Simple interface for collecting issues after a list of valid...
264425
<p>I have recently been learning Haskell, and wrote a minesweeper project as an exercise. Here is <a href="https://github.com/saxocellphone/minehask/blob/main/src/Game.hs" rel="nofollow noreferrer">link</a> to the project.</p> <p>Basically the code is separated into two parts, the pure part (no monads) and impure part ...
[]
[ { "body": "<h1 id=\"incomplete-player-interface\">Incomplete player interface</h1>\n<p>There is no way for a player to mark a square as mined. Technically, you can beat the game without, but that is not the point here?</p>\n<h1 id=\"missing-entry-point\">Missing entry point</h1>\n<p>You did not state an entry p...
{ "AcceptedAnswerId": "264467", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T19:26:46.327", "Id": "264429", "Score": "4", "Tags": [ "haskell", "minesweeper" ], "Title": "Minesweeper in haskell" }
264429
<p>I wanted to make a bounded slider since the ranged slider wxwidgets includes isnt very useful for my use case. I wanted a left and right bounded slider to control a dynamic way to control a graph or plot x-range.</p> <p>I got a good head start from a person who made a library in Python and ended up creating my own v...
[]
[ { "body": "<h1 id=\"move-class-sliderthumb-into-class-rangeslider-wer0\">Move <code>class SliderThumb</code> into <code>class RangeSlider</code></h1>\n<p>A <code>SliderThumb</code> is just an implementation detail of a <code>RangeSlider</code>, so you can nest it inside <code>class RangeSlider</code>. You can t...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T20:45:08.877", "Id": "264431", "Score": "2", "Tags": [ "c++", "gui" ], "Title": "Custom C++ wxWidget Ranged Slider" }
264431
<p>I recently tried to solve the first non-repeating character problem. Please tell me if my solution is valid. I'm aiming for O(n) with a single loop.</p> <p>My thinking is, it would be easy to tell you what the last non repeated character is, just:</p> <pre class="lang-none prettyprint-override"><code>loop each char ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T22:04:25.507", "Id": "522221", "Score": "0", "body": "Also, what are the constraints here? Are you aiming for a solution that just uses builtin types, or are solutions that use `collections`/`itertools` etc okay?" } ]
[ { "body": "<h2 id=\"style-7dcp\">Style</h2>\n<p>From <a href=\"https://www.python.org/dev/peps/pep-0008/#function-and-variable-names\" rel=\"noreferrer\">PEP 8</a>, function names should be lowercase and use underscores to separate words:</p>\n<pre><code>def first_non_repeater(s):\n ...\n</code></pre>\n<h2 i...
{ "AcceptedAnswerId": "264436", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-26T21:34:33.090", "Id": "264433", "Score": "10", "Tags": [ "python", "algorithm", "programming-challenge", "strings", "array" ], "Title": "First non-repeating Character, ...
264433
<p>I've just started to learn C++.</p> <p>I have this class and I don't know where to put the following two lines because of the catch:</p> <pre><code>delete[] chost; delete[] cport; </code></pre> <p>I think they are in the right place, but I have doubts because in C++ doesn't exist <code>finally</code>.</p> <p>Header:...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-27T14:21:39.657", "Id": "522285", "Score": "0", "body": "In addition to my answer, I'd recommend [my Code Project article](https://www.codeproject.com/Tips/5249485/The-Most-Essential-Cplusplus-Advice)." }, { "ContentLicense": "...
[ { "body": "<blockquote>\n<pre><code>Ephemeris::Ephemeris()\n{\n}\n</code></pre>\n</blockquote>\n<p>No need for a constructor if it does nothing.</p>\n<blockquote>\n<pre><code>Ephemeris::~Ephemeris()\n{\n if (telnet != nullptr)\n delete telnet;\n}\n</code></pre>\n</blockquote>\n<p>The test here is poin...
{ "AcceptedAnswerId": "264442", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-27T05:52:11.343", "Id": "264440", "Score": "3", "Tags": [ "c++", "c++11", "boost" ], "Title": "Connect to telnet server" }
264440
<p>I have a python script to archive some data (export from mongo to a local json file and then upload it to s3)</p> <p>Is there a better way to implement/improve the current flow? Each step should be be retried in case of failure and if the step is still failing after the set no of retries it shouldn't run the other s...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-27T14:48:00.273", "Id": "522286", "Score": "1", "body": "Without definitions for `metadata_ids`, `dump_snapshot`, etc. this is going to be difficult to meaningfully review." } ]
[ { "body": "<p>Nice code.</p>\n<h3 id=\"in-python-for-has-else-clause-aci5\">In Python, <code>for</code> has <code>else</code> clause</h3>\n<p>And I think it fits here perfectly. In</p>\n<pre><code>for retry in range(3):\n if ...:\n break\nelse:\n #else-part\n</code></pre>\n<p>the <code>else-part</c...
{ "AcceptedAnswerId": "264448", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-27T13:22:53.313", "Id": "264445", "Score": "1", "Tags": [ "python", "error-handling", "mongodb", "amazon-web-services" ], "Title": "Archiving MongoDB data to S3, with retryab...
264445
<p>In general my page is slow and has several points in the code that I believe can be improved, even in relation to the structure used. Anyway, the biggest problem is:</p> <p>The page I'm creating is very simple. The problem is that I created the entire first section - i.e. <code>&lt;div class=&quot;column ...&quot;&g...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-08-03T14:10:08.453", "Id": "524721", "Score": "0", "body": "By “_In general my page is slow_” in which ways is it slow? Slow to load all of the HTML, slow in having the JS operate? Slow to modify the code because of how large it is?" },...
[ { "body": "<h2>Copy-Pasted code</h2>\n<p>As you disclosed, the code has a lot of code that is copied and pasted. This violates the <a href=\"http://deviq.com/don-t-repeat-yourself/\" rel=\"nofollow noreferrer\"><em><strong>D</strong>on't <strong>R</strong>epeat <strong>Y</strong>ourself</em> principle </a>.</p>...
{ "AcceptedAnswerId": "265669", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-27T13:27:35.750", "Id": "264446", "Score": "1", "Tags": [ "javascript", "html", "ecmascript-6", "event-handling", "d3.js" ], "Title": "list of games to open radar match i...
264446
<p>I'm trying to write something like an adjusted run-length encoding for row-wise bit matrices. Specifically I want to &quot;collapse&quot; runs of 1s into the number of 1s in that run while maintaining the same number of 0s as original (right-padding as necessary). For example:</p> <pre><code>input_v = np.array([ [...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-27T18:54:55.590", "Id": "522300", "Score": "0", "body": "Why are you doing this? What are the dimensions of typical data you hope to compress in this way? Can you not just use Numpy's built-in sparse matrix support?" }, { "Cont...
[]
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-27T16:30:25.723", "Id": "264451", "Score": "0", "Tags": [ "python", "numpy", "matrix" ], "Title": "Vectorized code to find the position and length of runs of 1s in a bit matrix" }
264451
<p>Code is meant to be used in Windows .NET (tested with dotnet5.0) to dynamically load C library and return delegate of given function</p> <p>Code lower is result of my attempt to rewrite the <code>[DllImport]</code> annotations based header file, that was provided by 3rd party along with the DLL library itself, when ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-28T07:18:36.987", "Id": "522337", "Score": "0", "body": "*Avoid loading the DLL or the function multiple times, if caller requests the same DLL name or function name* then why don't you use `ConcurrentDictionary` to avoid loading the s...
[]
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-27T16:45:10.973", "Id": "264452", "Score": "1", "Tags": [ "c#", ".net" ], "Title": "Simplify LoadLibrary/GetProcAddress helper for dynamic parallel DLL instantiation" }
264452
<p>I had this as a project last school year and decided to try and optimize it. I'm curious to see how much I have learned; is this a good way of doing it?</p> <pre><code>import os dict = { # &quot;empId&quot;: [&quot;title&quot;, name] &quot;000001&quot;: [&quot;ceo&quot;, &quot;joe&quot;, &quot;smith&quot;], ...
[]
[ { "body": "<p>Starting with the last line:</p>\n<blockquote>\n<pre><code>menu()\n</code></pre>\n</blockquote>\n<p>Standard practice is to put this in a &quot;main guard&quot;, so that the file is usable from other programs:</p>\n<pre><code>if __name__ == '__main__':\n menu()\n</code></pre>\n<hr />\n<p>This b...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-27T19:03:07.137", "Id": "264454", "Score": "2", "Tags": [ "python", "python-3.x" ], "Title": "Employee directory" }
264454
<p>I've built a very simple personal website, everything is in a single file because it is very straightforward, but I think the JS script could be better structured. All it does is fetch some repos from the GitHub API and displays them in a horrible format.</p> <p>This is it (index.html):</p> <pre class="lang-js prett...
[]
[ { "body": "<p>First of all, kudos for making a single simple file!</p>\n<p>It was relatively straightforward to read as well, though I think mostly because of the well known api and that there isn't much code. Formatting was nice as well.</p>\n<p>Here's what I think could improve it:</p>\n<ul>\n<li>Since you're...
{ "AcceptedAnswerId": "264457", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-27T19:56:46.677", "Id": "264455", "Score": "2", "Tags": [ "javascript", "html", "css", "ecmascript-6", "ajax" ], "Title": "JS script fetching GitHub API for personal webs...
264455
<p>I am very new to <strong>Vue.js</strong>, I just stumbled on a very hard thing to do (at least for me) where Vue was complaining about mutating a prop (children shouldn't change parent props apparently). I was about to give up at 8~ hour mark, but then it worked! Then not only that, I came with another solution. Her...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-28T07:52:43.457", "Id": "522339", "Score": "1", "body": "Is `v-navigation-drawer` a component from Vuetify? What kind of property is `childSideNav`? When the event is emitted, what does the parent do about it? What happens exactly?" ...
[ { "body": "<h2>One-Way Data Flow</h2>\n<blockquote>\n<p><em>(children shouldn't change parent props apparently)</em></p>\n</blockquote>\n<p>Yes- this is explained in the documentation section for <a href=\"https://vuejs.org/v2/guide/components-props.html\" rel=\"nofollow noreferrer\"><strong>Components In-Depth...
{ "AcceptedAnswerId": "265672", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-28T06:38:46.557", "Id": "264464", "Score": "1", "Tags": [ "javascript", "comparative-review", "vue.js" ], "Title": "Which of these two Vuetify Navigation Drawer prevent prop muta...
264464
<p>I have a program that uses pandas to read csv files and then generates and saves graphical charts. I have been trying to follow the SOLID principles so I have tried to seperate responsibilities. So far the project has the structure of</p> <pre><code>GUI ├─ Service │ ├─ Business Logic │ │ ├─ DataReader │ │ ├─ Ch...
[]
[ { "body": "<p>I managed to find a solution I found that worked well for this case, I'm sure it's not the cleanest or most optimal but it worked for my case.</p>\n<p>Since the main problem was that generating seperate graphs required a new instance of the ChartGenerator class I made a class which would return a ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-28T09:33:14.707", "Id": "264469", "Score": "5", "Tags": [ "python", "csv", "pandas", "tkinter", "matplotlib" ], "Title": "GUI that reads data and generates/ saves charts" }
264469
<p>I am trying to find the &quot;Number of trailing zeros of N!&quot; (N factorial). In the python code I am trying to find the factorial first and then the number of trailing zeros. However, I am getting &quot;Execution Timed Out&quot; error.</p> <ol> <li>Why is this code giving the error? Is there anyway to optimize ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T14:47:52.547", "Id": "524443", "Score": "3", "body": "Coding problems like this are almost always challenging you to find a more clever solution than the obvious iteration/recursion. That's why they have execution time limits." },...
[ { "body": "<blockquote>\n<pre><code>if n==1 or n==0:\n return 1\n</code></pre>\n</blockquote>\n<p>That looks incorrect. 0! and 1! are both equal to 1, which has <em>no</em> trailing zeros, so we should be returning 0 there. If we had some unit tests, this would be more apparent.</p>\n<hr />\n<p>We don't ne...
{ "AcceptedAnswerId": "264471", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-28T09:48:43.290", "Id": "264470", "Score": "8", "Tags": [ "python", "python-3.x", "time-limit-exceeded" ], "Title": "Find the number of trailing zeros in factorial" }
264470
<p>I have created common function for CRUD operations.</p> <hr /> <ol> <li>I am using Sequelize JS, I have created all models in Sequelize</li> <li>I have written stored procedures in mysql for CRUD operations for each module/tables I have</li> </ol> <ul> <li><code>GetItems</code></li> <li><code>GetItemById</code></li>...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-08-02T23:06:14.983", "Id": "524700", "Score": "2", "body": "Please do not update the code in your question to incorporate feedback from answers, doing so goes against the Question + Answer style of Code Review. This is not a forum where y...
[ { "body": "<p>Your first two questions:</p>\n<ul>\n<li>You don't appear to be using almost a single feature of sequelize, so I can't understand why you would use it.</li>\n<li>What you have done is to put all your logic in the database, and have an application that's just a proxy for the database. If your appli...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-28T10:40:48.853", "Id": "264473", "Score": "1", "Tags": [ "node.js", "express.js" ], "Title": "Common CRUD function in node js using Express" }
264473
<p>I've been trying to learn a bit of JavaScript over the last few weeks, and inspired by <a href="https://codereview.stackexchange.com/questions/264433/first-non-repeating-character-with-a-single-loop-in-python">this current hot network question</a>, I tried creating a function for finding the first non-repeating char...
[]
[ { "body": "<p>that's my post! I'm glad you were inspired by it.</p>\n<p>As far as logic goes, this is a great and quite commonly agreed upon way to solve the problem in O(n) time, as long as the language you write it in maintains the order of insertion of a dictionary(which JS does). Well done.</p>\n", "com...
{ "AcceptedAnswerId": "264494", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-28T10:57:40.157", "Id": "264474", "Score": "2", "Tags": [ "javascript" ], "Title": "First non-repeating character in string" }
264474
<p>I'm writing a web crawler, and want to store the parts of a URL to a database using Entity Framework.</p> <p>Instead of trying to parse a URL into its component parts myself, I thought I could inherit from the <code>System.Uri</code> class and add a BaseEntity Id for the Entity Framework. But VS Code complains with ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-28T16:29:50.810", "Id": "522367", "Score": "1", "body": "To me this feels... odd. I'd rather have some kind of factory class or whatever to convert a `Uri` into a `Hyperlink`. Also: how does this even work when you retrieve data from t...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-28T13:18:29.813", "Id": "264477", "Score": "0", "Tags": [ "c#", "entity-framework-core" ], "Title": "Decompose URL components and store into a database" }
264477
<p>I wrote a program for Conway's Game Of Life in Java. Are there any improvements I could make?</p> <p>main class:</p> <pre><code>package main; import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferStrategy; public class GameOfLife { static Board board; static Window window; ...
[]
[ { "body": "<p>Welcome to the site! This looks good so far, here's a couple of smaller tips:</p>\n<h2 id=\"board.java-vrms\">Board.java</h2>\n<ul>\n<li><p>The cellsize doesn't change, so why not make it a constant like this:<br />\n<code>public static final int CELLSIZE = 4;</code><br />\nThis also makes the get...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-28T14:40:24.040", "Id": "264481", "Score": "4", "Tags": [ "java", "game-of-life" ], "Title": "Game Of Life program in Java" }
264481
<p>I have a dataframe which contains information of programmers like: country, programming languages. etc:</p> <pre class="lang-py prettyprint-override"><code>COUNTRY PROGRAMMING_LANGUAGE usa javascript uk python;swift;kotlin india python;ruby usa c++;c;assembly;python canada java...
[]
[ { "body": "<ul>\n<li>The construction of your dataframe could be improved; your <code>PROGRAMMER</code> column looks like it should be the index, and <code>np.float16</code> is not a good representation for what looks to be integer data.</li>\n<li>Not a good idea to <code>fillna</code> with a string and then co...
{ "AcceptedAnswerId": "265533", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-28T15:23:30.683", "Id": "264482", "Score": "1", "Tags": [ "python-3.x", "pandas", "jupyter" ], "Title": "Filtering data on a dataframe, Pandas-Jupyter" }
264482
<p>The code below works, but it seems it could be done better. Is there a better/more efficient way to do this?</p> <p>Given:</p> <ol> <li>All days off (&quot;relief days&quot;) will be consecutive.</li> <li>Relief days will be imported as a string. Days of week are represented by their first letter. &quot;S&quot; can ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-28T16:40:19.897", "Id": "522369", "Score": "0", "body": "Do you have a method header for this? It's best to show complete, runnable code, perhaps with a few test cases in a `main` to help clarify the behavior at a glance -- I'm not sur...
[ { "body": "<p>Your indentation has gone wrong here, and it's confusing:</p>\n<pre class=\"lang-java prettyprint-override\"><code> if (sl.equalsIgnoreCase(&quot;M&quot;)) {\n reliefDays = &quot;SUN MON&quot;;\n if (rdLength == 3) {\n reliefDays += &quot; TU...
{ "AcceptedAnswerId": "264496", "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-28T15:34:53.717", "Id": "264483", "Score": "0", "Tags": [ "java", "datetime" ], "Title": "Interpreting abbreviations for days of the week such that they are consecutive days" }
264483
<p>I created this sample and wanted any advice on how to make this code; cleaner, more effective, just overall better! I need to add the key word <code>and</code> only if the NegativeScheduleCalendar enum is before the ScheduleCalendar enum. The only way I was able to do this was to loop the list and checking if they a...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-28T16:24:28.727", "Id": "522365", "Score": "0", "body": "Why do you use `string.Format`? Why do `string Text =` instead of simply assigning directly? Why write `x = x + 1`?" } ]
[ { "body": "<ul>\n<li><p>You differentiate between 3 cases, but two of them do exactly the same thing. Instead, use a logical OR (<code>||</code> in C#) to combine the two conditions.</p>\n</li>\n<li><p>Use string interpolation instead of <code>String.Format</code>.</p>\n</li>\n<li><p>You can eliminate the temp ...
{ "AcceptedAnswerId": "264486", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-28T15:45:55.087", "Id": "264484", "Score": "0", "Tags": [ "c#" ], "Title": "Compare enum's and adding key word" }
264484
<p>I am trying to improve my file upload handler filter.</p> <h2 id="environment-gfny">Environment</h2> <p>Since any client-side validation is easily circumvented, there is none in this code, for ease of testing. Not even an <code>accept=&quot;image/*&quot;</code> on the <code>&lt;input&gt;</code> element. Production c...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-08-10T05:08:14.073", "Id": "525207", "Score": "0", "body": "I fail to see where do you checking the extension. Also, I'd like to see how that try to hack me thing is hacked with the extension check in place." }, { "ContentLicense"...
[ { "body": "<p>One way to be almost 100% secure against upload vulnerabilities is to convert the image yourself, maybe using a libary like <a href=\"https://imagemagick.org/script/convert.php\" rel=\"nofollow noreferrer\">ImageMagick</a>.</p>\n<p>That way it would be very difficult to add code to the file that a...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-28T18:15:35.863", "Id": "264487", "Score": "-1", "Tags": [ "php", "file" ], "Title": "Image upload filter for PHP" }
264487
<p>I decided to learn a little about AutoHotKey, to practice a little and learn about classes.</p> <p>I ended up writting a basic ini file parser.</p> <pre><code>Class Ini { ini_file := &quot;&quot; ini_data := {} __New(ini_file) { if ini_file { this.ini_file := ini_file ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-28T19:53:44.480", "Id": "264490", "Score": "1", "Tags": [ "parsing", "autohotkey" ], "Title": "Yet another .ini parser for AutoHotKey" }
264490
<p>This is LeetCode question 387 if anyone is interested. The task is to accept a string and find the first char that appears only once, and return its index. If no char appears only once then return -1. Examples are:</p> <pre><code>input: &quot;leetcode&quot; output: 0 input: &quot;loveleetcode&quot; output: 2 input...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T00:40:54.877", "Id": "522391", "Score": "0", "body": "I noticed there is another question asked on here today, I hope it is still appropriate to ask mine considering it is a different language and our logic is different. I am not us...
[ { "body": "<p>Other than applying the suggested variable and method naming changes for code clarity, you could store the duplicated characters in a hashset so that you can avoid evaluating those.</p>\n<p>In addition, this also enables evaluating only the remaining part of the string from the index you are curre...
{ "AcceptedAnswerId": null, "CommentCount": "10", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-28T21:44:39.360", "Id": "264495", "Score": "-1", "Tags": [ "c#", "strings" ], "Title": "Find first non repeating char in a string" }
264495
<p>I'm fairly new to time series databases in general and Influx in particular.</p> <p>My objective is to build a simple and general-use API that will allow me to write and read data from an Influx Database.</p> <p>I used Influx on a previous project and I found that building the API for the database was pretty mechani...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-30T02:44:55.893", "Id": "524466", "Score": "0", "body": "By politics do you perhaps mean policies?" } ]
[ { "body": "<ul>\n<li><code>Influx</code> should not be capitalized as it's a variable name</li>\n<li>None of this code:</li>\n</ul>\n<pre><code>with open(&quot;config.yaml&quot;, &quot;r&quot;) as ymlfile:\n cfg = yaml.load(ymlfile,Loader=SafeLoader)\nserver_URL=cfg[&quot;InfluxDB&quot;][&quot;server_URL&quo...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T00:28:49.347", "Id": "264498", "Score": "3", "Tags": [ "python", "performance", "beginner", "api", "database" ], "Title": "Data API with Influx-DB and FastAPI" }
264498
<p>Need a <code>ThrottledStream</code> for a project, created the following class (still not tested), wouldn't mind some opinions on the code and suggestions on how it can be improved:</p> <pre><code>public class ThrottledStream : Stream { private const int OneSecond = 1000; // 1000 milliseconds private readonl...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T11:43:01.120", "Id": "524414", "Score": "0", "body": "Using `Thread.Sleep` is inefficient. I would suggest `Task.Delay`. Accordingly, the code should be asynchronous." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T08:35:36.190", "Id": "265498", "Score": "0", "Tags": [ "c#", ".net" ], "Title": "ThrottledStream" }
265498
<p>I asked the same question on StackOverflow but was told to instead ask here since it was better suited. I have a function that I implemented. It is doing a lot of heavy lifting. I would like to optimise it or in other words try to find repeating code and simplify it a little bit. I'll show my implementation below:</...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T10:39:56.233", "Id": "524409", "Score": "2", "body": "What does the code do?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T10:45:36.023", "Id": "524410", "Score": "0", "body": "@MagnusJe...
[ { "body": "<p>I'm gonna guess that the code is really trying to find the diff between two tree structures. Futher, I'm assuming from the name &quot;typeObjCopy&quot; that the two trees have identical structure, just different labels. I.e. no added categories allowed. Hopefully this will still be helpful for you...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T10:33:07.263", "Id": "265501", "Score": "-1", "Tags": [ "javascript", "performance", "functional-programming", "react.js" ], "Title": "Simplifying and optimising function logi...
265501
<p>I am trying to pack around 50 files from a folder to zip file using PHP ZipArchive. Actually, only at most five files are ever changing. Others remain same static files. Should I zip the folder for every request or just replace those five files? Which one would be better for memory consumption and performance?</p> <...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-08-08T02:27:28.257", "Id": "525090", "Score": "0", "body": "“_Should I zip the folder for every request or just replace those five files?_” do you have easy acccess to determine which five files changed, or would it have to be calculated ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T11:02:44.467", "Id": "265503", "Score": "0", "Tags": [ "performance", "php" ], "Title": "Create ZipArchive from a directory of files" }
265503
<p>The task is:</p> <blockquote> <p>Given an array of integers, return the minimum required increment to make each element unique.</p> <p>Sample Input 1: [3, 4, 2, 2, 6]</p> <p>Sample Output 1: 3 (One of the 2s should be incremented to 5)</p> <p>Sample Input 2: [3, 4, 5]</p> <p>Sample Output 2: 0 (There is no duplicate...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T11:45:02.727", "Id": "524416", "Score": "5", "body": "\"My code works in the linear time since\". \"`arr.sort()`\" does not run in linear time, so your code is not linear." }, { "ContentLicense": "CC BY-SA 4.0", "Creatio...
[ { "body": "<p>As already mentioned by Peilonrayz, your algorithm's time complexity is <span class=\"math-container\">\\$\\mathcal{O}(n\\log{n})\\$</span>, because of <a href=\"https://en.wikipedia.org/wiki/Timsort#Analysis\" rel=\"noreferrer\"><code>sort()</code></a>. You also process the input array three time...
{ "AcceptedAnswerId": null, "CommentCount": "10", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T11:22:27.513", "Id": "265504", "Score": "5", "Tags": [ "python", "performance", "algorithm" ], "Title": "Given an array of integers, return the minimum required increment to make...
265504
<p>I'm using Spring-WebFlux with Spring-Security and I need to save data depending on the currently registered user. In order to do so, in my controller, I need to retrieve the data sent from both the frontend and the principal.</p> <p>After searching for a solution to my problem on the internet, I didn't find any clea...
[]
[ { "body": "<p>There is no problems at all with the supplied code.</p>\n<p>Nesting multiple <code>Mono</code>s is no problems and <code>flatMap</code>ing over them in a nested fashion is somewhat common.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 4...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T12:14:55.657", "Id": "265506", "Score": "0", "Tags": [ "spring" ], "Title": "Spring-WebFlux code to save per-user data" }
265506
<p>I am new to web development and I am making a small &quot;About Me&quot; website using html/css . I managed to do this layout : <a href="https://imgur.com/a/Kb0xPQA" rel="nofollow noreferrer">https://imgur.com/a/Kb0xPQA</a></p> <p>Although it did the job done, I am just concerned that with this layout/code will affe...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T14:18:34.050", "Id": "524438", "Score": "4", "body": "Welcome to Code Review! The current question title, which states your concerns about the code, is too general to be useful here. Please [edit] to the site standard, which is for ...
[ { "body": "<p><strong>You can do something like this:</strong></p>\n<p><div class=\"snippet\" data-lang=\"js\" data-hide=\"false\" data-console=\"true\" data-babel=\"false\">\r\n<div class=\"snippet-code\">\r\n<pre class=\"snippet-code-css lang-css prettyprint-override\"><code>*{margin:0;padding:0;}\n\n.item1{g...
{ "AcceptedAnswerId": "265544", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T12:23:04.277", "Id": "265508", "Score": "-1", "Tags": [ "html", "css" ], "Title": "Is there a correct way to do this layout in HTML/CSS" }
265508
<p>I have this watcher in my <code>app.vue</code> that makes sure the right theme <code>attribute</code> is set on the <code>html</code> tag. I have a nested if/else loop, and as you can see in the code below I have two different conditions but two times the same statements.</p> <p>Is there some way to code this is a m...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T14:41:48.777", "Id": "524441", "Score": "0", "body": "The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to **simply sta...
[ { "body": "<p>So you have a boolean, and from this boolean you go with either <code>themes.dark</code> or <code>themes.default</code>. Easy, extract a method that takes a boolean and properly calls <code>setThemeAttribute</code>.</p>\n<pre><code>function setThemeBoolean(bool) {\n setThemeAttribute(bool ? the...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T12:31:04.457", "Id": "265510", "Score": "-1", "Tags": [ "javascript", "vue.js" ], "Title": "JS - Same recurring statements in if-else" }
265510
<p>I'm trying to create a function to check multiple conditions of data. The function will return a list if the data is errors.</p> <p>Here is my idea:</p> <pre><code>error_lists = [] def check(A, B, C, D, E): check condition 1 for A if there is a error -&gt; error_list.append(1) check condition 2 for B ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T18:32:40.357", "Id": "524456", "Score": "1", "body": "Welcome to Code Review! It appears there is a slight flaw with the code: \"_NameError: name 'staff_id' is not defined_\" - it can be fixed by changing the case on the argument." ...
[ { "body": "<ul>\n<li><code>P_list</code> should be a set, not a list, based on its usage; it's only used for membership checks. You can also pre-bind to the <code>__contains__</code> member to get a function reference you can call, constraining the set to one purpose.</li>\n<li>Add PEP484 type hints</li>\n<li><...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T12:38:58.820", "Id": "265511", "Score": "2", "Tags": [ "python-3.x" ], "Title": "Create a function in Python to check for the data errors" }
265511
<p>I have a Asp.Net API (.NET Framework 4.7.2). We recently updated Autofac to version 6.2.0. Autofac does not like some of our classes that don't have a public constructor.</p> <p>Example class:</p> <pre><code>public sealed class User { private static readonly Lazy&lt;User&gt; Lazy = new Lazy&lt;User&gt;(() =&g...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T14:41:37.000", "Id": "524440", "Score": "2", "body": "https://stackoverflow.com/a/67643119/648075" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-30T03:29:36.920", "Id": "524467", "Score": "1", ...
[ { "body": "<p>Generally speaking, classes with private-only constructors are irrelevant in terms of DI. It makes no sense to include them in your container because the container can't do anything with them.</p>\n<p>The only exception here is when you register the specific instance of a type with the container, ...
{ "AcceptedAnswerId": "266158", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T12:40:22.750", "Id": "265512", "Score": "0", "Tags": [ "c#", "autofac" ], "Title": "Should I get Autofac to include classes that don't have a public constructor?" }
265512
<p>I was implementing the AAN algorithm for computing the 2D Discrete Cosine Transform on an 8*8 array. I perform both the forward and inverse AAN algorithms.</p> <p>My code is extremely fast compared to the naive DCT algorithm but I feel that my implementation could be faster. How can I improve the performance of my t...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-30T07:08:11.360", "Id": "524471", "Score": "1", "body": "What sort of things are in scope for improving the performance? Maybe SIMD? Fixed-point approximations?" } ]
[ { "body": "<p><strong>Performance</strong></p>\n<blockquote>\n<p>How can I improve the performance of my transforms?</p>\n</blockquote>\n<p>So far, only some small ideas.</p>\n<p><strong><code>float</code> vs. <code>double</code> math</strong></p>\n<p>Do not call run-time <code>double</code> functions and const...
{ "AcceptedAnswerId": "265534", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-29T19:21:23.693", "Id": "265527", "Score": "4", "Tags": [ "performance", "c", "image" ], "Title": "Faster AAN algorithm for calculating Discrete Cosine Transform" }
265527
<p>I'm developing a notepad with virtual keyboard integration. The purpose is to provide a free tool to type the Latin letters with diacritics. I came this far, but due my limitation and lack of coding knowledge I think will need partners to improve the app.</p> <p>I really appreciate your inputs and suggestions. Furth...
[]
[ { "body": "<p>This is already a fairly large program. Before expanding it further you're going to want to go back and clean up a collection of minor and major things:</p>\n<p>This program is written for a specific locale. It would be a good idea to be explicit about this locale:</p>\n<pre><code>from locale impo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-30T07:11:24.073", "Id": "265538", "Score": "2", "Tags": [ "python" ], "Title": "Virtual keyboard for typing Latin with diacritics characters" }
265538
<p>I want to:</p> <ol> <li>Hide areas of my template after search click.</li> <li>Return its original state with the cleaning of the input related to each button.</li> </ol> <p>I don't know if my code exploits all the resources of angular or js and looks clear/clean. To my mind it sounds repetitive.</p> <p>No forms of ...
[]
[ { "body": "<p>Simple solve. Create elems with flags.</p>\n<p>lets create object of elements with default settings. let be <code>true</code> by. default. And create 1 method for change state of elems.</p>\n<p>...</p>\n<pre><code>public elems = {\npid: true,\ndoc: true,\nrn: true\n}\n....\n\n toggle(elem, state)...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-30T08:35:57.760", "Id": "265539", "Score": "1", "Tags": [ "javascript", "html", "angular-2+" ], "Title": "Hidden html elements after search click" }
265539
<p>I wrote a Logistic Regression model that classifies MNIST digits.</p> <p>I used tensorflow &amp; keras only for import the dataset.</p> <pre><code>from tensorflow import keras import time import numpy as np (x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data() </code></pre> <p>I sliced the dataset ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-08-09T17:51:32.007", "Id": "525182", "Score": "0", "body": "It's almost always preferred to include all relevant code in the question itself (as opposed to linking to github). Also, be explicit about what currently dissatisfies you about ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-07-30T10:06:20.357", "Id": "265543", "Score": "0", "Tags": [ "python", "machine-learning" ], "Title": "Logistic Regression for MNIST binary classification" }
265543