body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I don't know if my test cases at the bottom cover every case, or if my mathematical logic in the reducer function is exactly right (referring to the math that starts with <code>(d1 + d2 >= 10)</code>). More importantly I'm uncomfortable with the readability of this code as it's rather compact and difficult to par... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T12:38:26.967",
"Id": "516198",
"Score": "1",
"body": "There is a neat mathematical way. Number of carry operations when adding `x` and `y` in base `b` can be calculated using `(s(x) + s(y) - s(x+y)) / (b-1)` where `s(n)` is the sum ... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-01T19:09:43.100",
"Id": "261525",
"Score": "1",
"Tags": [
"javascript",
"interview-questions"
],
"Title": "Find the number of carry operations needed to add two numbers digit by digit"
} | 261525 |
<h2>taken from <a href="https://leetcode.com/problems/the-skyline-problem/" rel="nofollow noreferrer">leetcode.com</a>:</h2>
<p>A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return the s... | [] | [
{
"body": "<p>I noticed you have used stream library in most of your code, so I thought about increasing readability with less lines of code using streams if possible because other parts looks fine to me. In your <code>Solution</code> class you have the following method :</p>\n<pre><code>private List<List<... | {
"AcceptedAnswerId": "261554",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-02T04:46:49.253",
"Id": "261533",
"Score": "3",
"Tags": [
"java",
"object-oriented"
],
"Title": "SkylineProblem in Java"
} | 261533 |
<p>I have made this <strong>Pagination</strong> Class in JS which takes the following configurations :-</p>
<ul>
<li>Total records</li>
<li>Records per page</li>
<li>Visible pages</li>
</ul>
<p>The idea is simple that any instance created using this <strong>Pagination</strong> class should be easy to use and separate t... | [] | [
{
"body": "<ol>\n<li>I think Paginator need only one change page</li>\n<li>in most cases, an Ajax request is required and we have to take care of this callback (<code>render</code> - is callback )</li>\n<li>we have to create methods for change limit (<code>changeMax</code>)</li>\n<li>we have to create methods ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-02T06:45:51.380",
"Id": "261536",
"Score": "2",
"Tags": [
"javascript",
"pagination"
],
"Title": "Client side Pagination implementation in vanilla js"
} | 261536 |
<h2>Scenarios / Requirements:</h2>
<p>I am working on to convert the existing WebAPI Data Layer to <code>Dapper</code> from <code>EF</code>. The following are the major scenarios / my aim during the UoW implementation.</p>
<ol>
<li>Transaction handling for one database (database transaction).</li>
<li>Transaction handl... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-02T07:14:50.917",
"Id": "261537",
"Score": "0",
"Tags": [
"c#",
"repository",
"asp.net-web-api",
"dapper"
],
"Title": "Dapper UOW with Multiple Databases"
} | 261537 |
<h1>Basic Description</h1>
<h2>What is the program for?</h2>
<p>This is just a hobby project for me to improve at coding, not a serious one.</p>
<h2>What does the program do?</h2>
<p>It can take a chess position (not including variations like chess960 etc.), and generate all legal moves from it. Draw and checkmates are... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-02T14:32:23.317",
"Id": "516144",
"Score": "10",
"body": "Particularly for a new contributor this is an excellent first question - great formatting and layout."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-0... | [
{
"body": "<pre><code>std::map<std::string, int> perftDivide (gameState currentState, int depth) {\n std::map<std::string, int> output;\n</code></pre>\n<p>First thing I notice: <strong>name your types</strong>. You have a <code>map</code> as the result, and a local variable with the same kind o... | {
"AcceptedAnswerId": "261546",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-02T09:07:01.387",
"Id": "261538",
"Score": "18",
"Tags": [
"c++",
"performance",
"chess"
],
"Title": "Chess engine for C++"
} | 261538 |
<p>In a previous question, <a href="https://codereview.stackexchange.com/questions/261338/java-logger-of-doom">Java logger (of doom!)</a>, I had posted my own logger, written in Java. I have since taken the answers from that question and a few of my own things to update it.</p>
<p>New code:</p>
<pre><code>/*
* Syml, a... | [] | [
{
"body": "<p>Why use an <code>int</code> to indicate the log type when you can just use an <code>enum</code>\nThat way, you could just write the enum to the <code>OutputStreamWriter</code> directly (while avoiding the worry of receiving an incorrect logType: <code>IllegalArgumentException</code>):</p>\n<pre cl... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-02T13:05:44.907",
"Id": "261542",
"Score": "2",
"Tags": [
"java",
"file",
"logging",
"file-structure"
],
"Title": "Java logger (of doom!), updated"
} | 261542 |
<p>I need a program same as I wrote but using loops. (if else for etc.) . Program is that enter a number and get each digits of number like that: number is 123456. I'm beginner, I can't create the logic and can't combine loops. Can anybody help me about that situation?</p>
<pre><code>1.digits is 6
2.digits is 5
3.digi... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-02T16:35:56.977",
"Id": "516149",
"Score": "1",
"body": "Welcome to Code Review! Unfortunately, we don't write code to order, we simply _review_ code you've written, and might make suggestions that improve it. Depending on your problem... | [
{
"body": "<p>I suggested you post here; it qualifies as it is working/compiling code. In the original post on Stack Overflow people might answer you on explaining how to do looping. Here, we just review what you wrote.</p>\n<p><code>using namespace std;</code><br />\nDon't do that. There are posts here expl... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-02T16:31:05.203",
"Id": "261551",
"Score": "0",
"Tags": [
"c++",
"beginner"
],
"Title": "Get Each Digits of Number with Using Loops in C++"
} | 261551 |
<p>I had this <a href="https://codereview.stackexchange.com/questions/261387/python-trivia-game-getting-questions-and-answers-off-a-website" title="This Stackexchange post">trivia game</a>, and from the review I got I improved my game. One of the improvements I made was this short function, to check the correctness of ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-02T22:15:26.353",
"Id": "516167",
"Score": "2",
"body": "the requirements are not clear enough. e.g. will \"park in\" be a good answer in your example? is the order of the words important? e.g. will \"Wyoming Yellowstone\" have the sam... | [
{
"body": "<pre class=\"lang-py prettyprint-override\"><code> if matches_percentage >= percentage:\n return True\n else:\n return False\n</code></pre>\n<p>is a verbose way of writing</p>\n<pre class=\"lang-py prettyprint-override\"><code> return matches_percentage >= percentage\n</c... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-02T21:57:14.470",
"Id": "261561",
"Score": "0",
"Tags": [
"beginner",
"python-3.x"
],
"Title": "Short function to check if an entered answer is close to a correct one"
} | 261561 |
<p>When I need a singleton class in my Ruby code (for example, single logger for multiple classes) I usually use code like this:</p>
<pre><code>class Parent_Singleton
@singleton = nil
def self.new
@singleton || (@singleton = super)
end
end
</code></pre>
<p>This approach allows me to avoid using the module <... | [] | [
{
"body": "<p>The Singleton module in Ruby for instance also guarantees synchronised access, e.g. if multiple threads try to create an instance your implementation would not work.</p>\n<p><a href=\"https://github.com/ruby/ruby/blob/master/lib/singleton.rb#L112-L168\" rel=\"nofollow noreferrer\">https://github.c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T02:32:43.677",
"Id": "261563",
"Score": "2",
"Tags": [
"object-oriented",
"ruby",
"singleton"
],
"Title": "Singleton in Ruby without using Singleton module or class variable"
} | 261563 |
<p>I have a for loop where I either increment or decrement the value of <code>i</code> by 1 each iteration. If <code>start</code> is greater than <code>end</code> I have to decrement <code>i</code> and if <code>end</code> is greater than <code>start</code> I have to increment <code>i</code></p>
<p>I had written the for... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T06:47:57.340",
"Id": "516179",
"Score": "0",
"body": "Please [edit] your question so that the title describes the *purpose* of the code, rather than its *mechanism*. We really need to understand the motivational context to give goo... | [
{
"body": "<p>I'm not much of a C++ programmer, I usually just write in C, but this is what I'd do:</p>\n<pre class=\"lang-cpp prettyprint-override\"><code>#include <algorithm>\n#include <cstdio>\n\nvoid foo(int start, int end)\n{\n for (int i = std::min(start, end); i < std::max(start, end);... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T02:59:55.123",
"Id": "261564",
"Score": "0",
"Tags": [
"c++"
],
"Title": "cleaner for loop that accommodates direction"
} | 261564 |
<p>This program asks the user for a players name, # of goals, saves, games played, etc. This information is ten organized on a .txt file along with the time the information was logged. users can also compare the players based on # of goals, Assists and saves made.</p>
<p>If anything can be improved, cleaned or replaced... | [] | [
{
"body": "<h1><code>Path</code></h1>\n<p>The use of <code>Path</code> is a bit pointless.</p>\n<ul>\n<li>There is no need to use an absolute path to access the file.</li>\n<li>Converting the <code>Path</code> to a <code>String</code> seems wrong. Conversion to a <code>File</code> with the method <code>.toFile(... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T06:39:25.440",
"Id": "261568",
"Score": "2",
"Tags": [
"java",
"array",
"hash-map",
"file"
],
"Title": "Sports DataSheet"
} | 261568 |
<p>I got this question as a coding challenge and was unable to get it done under 50 milliseconds (my solution takes >100 ms) :D</p>
<p>Would you please review my code and share any idea how to do this within 50ms?</p>
<p>Problem Description
One of our customers, a multinational company that manufactures industrial a... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T08:45:50.220",
"Id": "516188",
"Score": "1",
"body": "`Aggregate cases that have the same event execution order and list the 10 variants with the most cases` - this phrase is not clear to me. Your method doesn't return anything and ... | [
{
"body": "<p>Disclaimer: I do not know Kotlin, only a bit of Java.</p>\n<h2>Extract the solution to a function</h2>\n<pre><code>private fun topTenCaseFlows(eventLogRows: List<EventLogRow>): List<Pair<String, Int>> {\n val grouped = eventLogRows.groupBy { it.caseId }\n val map = hashMapO... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T08:13:18.707",
"Id": "261570",
"Score": "2",
"Tags": [
"java",
"kotlin"
],
"Title": "Aggregate data from a huge list under 50ms"
} | 261570 |
<p>I've written this class to wrap a collection of bytes and interpret them as 16-bit floats. It's supposed to work like <code>memoryview(buf).cast('f')</code> or <code>array.array('f', buf)</code> I'm trying to avoid converting back and forth between values as much as possible. cPython does not currently support using... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T17:15:09.683",
"Id": "516232",
"Score": "1",
"body": "Why are you packing like this? Embedded application, network application, etc."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T09:46:12.170",
... | [
{
"body": "<p>Having studied further, I think the biggest thing I'm missing is a <code>__hash__</code> method like this:</p>\n<pre><code>def __hash__(self):\n if self.hbuf.readonly and self._hash is None:\n self._hash = hash((self.__class__.__name__, self.hbuf.tobytes()))\n return self._hash\n ... | {
"AcceptedAnswerId": "263822",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T11:01:13.267",
"Id": "261573",
"Score": "6",
"Tags": [
"python",
"python-3.x",
"floating-point"
],
"Title": "An IEEE half-float implementation in python similar to array.array... | 261573 |
<p>I have implemented Binary_Search in python (I think), and my own method for <code>range</code> objects. I want to know if there is any way to improve this code, here it is:</p>
<pre><code>def findAmountString(string, char):
amount = 0
for n in range(len(string)):
if string[n] == char: amount += 1
return am... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T12:18:13.687",
"Id": "516194",
"Score": "0",
"body": "Is there any use of the `findAmountString` function you have posted?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T12:41:46.580",
"Id": "516... | [
{
"body": "<ul>\n<li>Follow <a href=\"https://www.python.org/dev/peps/pep-0008/#function-and-variable-names\" rel=\"nofollow noreferrer\">PEP8</a> guidelines for naming functions and variables</li>\n<li>Avoid multiple statements on one line: <code>if string[n] == char: amount += 1</code></li>\n<li><strong>Docum... | {
"AcceptedAnswerId": "261578",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T11:50:04.660",
"Id": "261575",
"Score": "1",
"Tags": [
"python",
"python-3.x",
"reinventing-the-wheel",
"binary-search"
],
"Title": "Search Method In Python / Python 3.9"
... | 261575 |
<p>This project I'm dealing with will read the size of free memory segments and size of processes from a text file and then will try to allocate a memory partition for each process using the first-fit, best-fit and worst-fit allocation algorithms. Below is the first part of the code I wrote.</p>
<pre><code>import sys
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T15:53:35.133",
"Id": "516218",
"Score": "0",
"body": "Please show an example input file."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T18:13:31.927",
"Id": "516248",
"Score": "1",
"body"... | [
{
"body": "<p>I think from a prior question the input is:</p>\n<pre><code>300,600,350,200,750,125\n115,500,358,200,375\n</code></pre>\n<p>I believe the assignment asked for a simplification of the code as it is a little convoluted at the moment. I'll try to clean it up a bit.</p>\n<p>I've added what I guess are... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T13:03:21.787",
"Id": "261581",
"Score": "2",
"Tags": [
"python",
"memory-management"
],
"Title": "Contiguous memory allocation using first-fit algorithm"
} | 261581 |
<p>I'm trying to build out some DeFi position tracking pages in Google Sheets. I want to pull from the Zapper API (or other APIs) to track trades, positions, gains, losses, fees...etc. This is my first crack at tracking a position on SushiSwap.</p>
<p>I tried to make re-usable functions and organize the code so it's ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T15:12:16.460",
"Id": "516215",
"Score": "0",
"body": "Note that your question is still too generic. It seems your code is about stock data, yet the word \"stock\" isn't in the title. Why not? Please see [**How do I ask a good questi... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T13:21:40.643",
"Id": "261582",
"Score": "0",
"Tags": [
"javascript",
"array",
"google-apps-script",
"google-sheets"
],
"Title": "Pulling data from an API and working with it i... | 261582 |
<p>I have this code which I use to append data to a JSON file. It will be helpful if someone could suggest pointers on:</p>
<ul>
<li>Reducing file opening and closing</li>
<li>Make the <code>write_json</code> function efficient</li>
</ul>
<p>and other general pointers. Thanks a lot.</p>
<pre><code>#include <stdio.h&... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T15:48:59.327",
"Id": "516217",
"Score": "1",
"body": "Why are you `printf`-ing your entire output?"
}
] | [
{
"body": "<p>A few thoughts:</p>\n<ol>\n<li>You first open the file for reading. If this succeeds, the next thing you do (without closing the file) is another fopen with a different mode. I am not sure what you are trying to accomplish by doing this, but it doesn't look like it makes sense.</li>\n<li>I <em>th... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T15:27:01.537",
"Id": "261585",
"Score": "2",
"Tags": [
"c"
],
"Title": "Appending data to JSON file in C"
} | 261585 |
<p>The following code was written with the intent to be as <em>efficient</em> as possible, where efficiency includes speed of execution, memory usage, and lines of code, all in support of the primary design constraint that it can change the payload argument <em>buffer</em> in-place (from the calling function's perspect... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T19:16:52.127",
"Id": "516251",
"Score": "7",
"body": "\"efficiency includes [...] lines of code\" -- really? What exactly do you mean with that? You could write most of your code in a single line, but that's nonsense in most context... | [
{
"body": "<blockquote>\n<p>all in support of the primary design constraint that it can change the payload argument buffer in-place</p>\n</blockquote>\n<p>However, the current implementation is not in-place, it builds a string in temporary space and then copies that back over the input. From the point of view o... | {
"AcceptedAnswerId": "261591",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T16:10:07.747",
"Id": "261588",
"Score": "8",
"Tags": [
"performance",
"c",
"strings"
],
"Title": "Remove all unwanted characters from a string buffer, in-place"
} | 261588 |
<p>The program will read size of free memory partitions and size of processes from a text file and then will try to allocate a memory partition for each process using the first-fit algorithm.</p>
<p>Input example:</p>
<pre><code>300,600,350,200,750,125
115,500,358,200,375
</code></pre>
<p>My code for the implementation... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T17:11:04.847",
"Id": "516229",
"Score": "1",
"body": "Welcome to Code Review. What Python version did you write this for?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T17:11:50.377",
"Id": "5162... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T16:46:31.027",
"Id": "261590",
"Score": "2",
"Tags": [
"python",
"memory-management"
],
"Title": "Fit memory allocation"
} | 261590 |
<p>My function needs to check if some nested object is empty.
For flat objects, there is no need of recursion, and a very basic function could be the following (inspired to <a href="https://www.php.net/manual/en/function.empty.php" rel="nofollow noreferrer">PHP empty</a>):</p>
<pre><code>empty = function (mixedVar) {
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T04:25:35.130",
"Id": "518277",
"Score": "1",
"body": "This seems like a sort of odd use case. Do you really have objects with literally no values in it that are so incredibly large that they're locking up your program? Could you des... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T18:17:06.533",
"Id": "261593",
"Score": "0",
"Tags": [
"javascript"
],
"Title": "JavaScript optimize a function to check if a nested object is empty"
} | 261593 |
<p>This is for a cheap VPS I use for personal projects. I like having a message of the day displaying system info on login; I wanted to add the status of my docker containers to it, to see if all are running and whatnot.</p>
<p>The scripts I found online for this displayed all the containers, but since I run mailcow fo... | [] | [
{
"body": "<blockquote>\n<pre><code># colors\ngreen="\\e[1;32m"\nyellow="\\e[1;33m"\nred="\\e[1;31m"\nblue="\\e[36;1m"\n</code></pre>\n</blockquote>\n<p>You don't know what kind of terminal (if indeed a terminal) that output will be going to, so don't hard-code these term... | {
"AcceptedAnswerId": "269606",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T20:34:14.987",
"Id": "261597",
"Score": "1",
"Tags": [
"performance",
"bash",
"linux",
"docker"
],
"Title": "Bash script (to be used as a login MOTD message) that displays... | 261597 |
<p>The code below is a Haskell implementation of Needleman-Wunsch algorithm for sequence alignment (and string edit distance). It's an experiment in trying to closely imitate the dynamic programming method as it would be implemented in imperative languages. Hence my use of mutable arrays and ST monad.</p>
<pre class="l... | [] | [
{
"body": "<p>I wouldn't worry about using mutability here. Sometimes it pays to just be straightforward and stick closely to something that you know works.</p>\n<ul>\n<li><p>You're not using <code>ScopedTypeVariables</code>.</p>\n</li>\n<li><p>As far as the interface, <code>Costs</code> has no reason to be a <... | {
"AcceptedAnswerId": "262606",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-03T22:34:20.730",
"Id": "261599",
"Score": "3",
"Tags": [
"array",
"haskell",
"dynamic-programming"
],
"Title": "Haskell implementation of Needleman-Wunsch"
} | 261599 |
<p>I'm 16 years old and no one to help me, no one to give any advice or constructive criticism, I'm aimless. I'll leave the link to my last code (github), a program that sends an email to everyone registered in the database. I would like some advice and project/content ideas for me to evolve. Evaluate my project sincer... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T16:17:28.417",
"Id": "518371",
"Score": "1",
"body": "Just be aware that we can only review/comment on the code that is actually in the question, not all the code in the repository."
},
{
"ContentLicense": "CC BY-SA 4.0",
... | [
{
"body": "<p>Welcome in the fantastic world of development.</p>\n<p>There is this great acronym in software development: <strong>S.O.L.I.D.</strong>. You can refer to it at any time to evaluate the quality of your code.</p>\n<p>However, in a two classes project, many of them are overkill. But there is one that... | {
"AcceptedAnswerId": "262616",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T02:01:37.097",
"Id": "262601",
"Score": "2",
"Tags": [
"java",
"sql",
"email"
],
"Title": "program that sends an email to everyone registered in the database"
} | 262601 |
<p>This script gathers domains listed from sources in <a href="https://raw.githubusercontent.com/T145/the-blacklist/master/sources.json" rel="nofollow noreferrer">this JSON file</a> and compiles them into one text file. Text files that have a similar key under the <code>whitelists</code> directory will have any matchin... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-26T07:41:51.793",
"Id": "520162",
"Score": "0",
"body": "Do you need compatibility? Do you need to reduce dependencies other than POSIX document?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-27T14:29:21.... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T02:25:05.290",
"Id": "262602",
"Score": "2",
"Tags": [
"bash",
"linux",
"posix",
"sh",
"awk"
],
"Title": "The Blacklist v2"
} | 262602 |
<p>I'm implementing a system, which requires an order to be active.
I have a class called Yritys, which is the customer account who would have credits.</p>
<p>1 credit would mean 1 day of service use.</p>
<p>Yritys (company) has properties for credit (amount of credit) and OrderStartDate (when the original order was pl... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T10:43:03.847",
"Id": "518306",
"Score": "0",
"body": "`which requires an order to be active` active for what ? please give us more details on this part of your business requirement. and what does the credits used for in the system ?... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T02:59:13.850",
"Id": "262603",
"Score": "1",
"Tags": [
"c#",
"asp.net-mvc"
],
"Title": "Credit based order system"
} | 262603 |
<p>Given a (long) string <code>src</code>, generate substrings (up to) <code>len</code> characters long on demand by iterating over <code>src</code> and <em>shifting</em> the reading frame by <code>shift</code> characters every time.</p>
<p><a href="https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T13:38:25.623",
"Id": "518323",
"Score": "1",
"body": "Hi and welcome to Code Review. I rolled back the last two edits. For one the last edit you made incorporates feedback from an answer you have received. To avoid \"answer invalida... | [
{
"body": "<p>You should generally avoid multiple variable initializations on one line:</p>\n<pre><code>private int i = 0;\nprivate int j = Math.min(len, src.length());\n</code></pre>\n<p>is more readable.</p>\n<hr />\n<p><strong>EDIT:</strong> The following suggestion is left in for reference, but is based on ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T06:23:56.303",
"Id": "262604",
"Score": "3",
"Tags": [
"java",
"functional-programming",
"stream"
],
"Title": "Streaming substrings of a string"
} | 262604 |
<p>Design a program to calculate the salaries of a company's employees based on the following data:</p>
<ul>
<li>Number of hours worked.</li>
<li>The work shift performed: Morning (m), Afternoon (t), Night (n).</li>
<li>The ordinary hourly rate for each of the workers ($ 37.0).</li>
</ul>
<p>For the calculation of the ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T07:01:55.423",
"Id": "518283",
"Score": "0",
"body": "Welcome to Code Review! I changed the title so that it describes what the code does per [site goals](/questions/how-to-ask): \"*State what your code does in your title, not your ... | [
{
"body": "<p>Why do we convert hours worked to <code>int</code>? It seems unethical to steal the workers' partial hours.</p>\n<p>If we don't enter a valid shift identifier, then we silently pay the lowest rate instead of reporting the error.</p>\n<p>The variable names are completely uninformative. It's hard ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T06:30:43.177",
"Id": "262605",
"Score": "0",
"Tags": [
"python"
],
"Title": "Calculate salary from time worked"
} | 262605 |
<p>I am a bit concerned about style (functions, variable names, spacings, etc.). I am also not sure about whether I should return error or panic.
What do you think?</p>
<pre class="lang-golang prettyprint-override"><code>//SortStructs sorts user-made structs, given that "a" is a pointer to slice of structs
//... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T01:30:12.897",
"Id": "518727",
"Score": "0",
"body": "Did you write this just for fun to learn reflection, or is it something you intend to use in real code? The use of reflection for this kind of thing is rare and frowned on in Go,... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T07:32:00.027",
"Id": "262608",
"Score": "3",
"Tags": [
"sorting",
"go"
],
"Title": "I recently wrote sort of structs in golang"
} | 262608 |
<p>The first time I used <code>strtok</code>, it felt, well, weird. But after a while, I became quite used to it. In a way it was simple. Soon after reading a bunch of Stack Overflow comments and posts about this function, I came to realize that this isn't what I <em>should</em> use in the long run.</p>
<p>Personally, ... | [] | [
{
"body": "<blockquote>\n<pre><code> token = malloc(substring_length + 1 + sizeof(char *));\n assert(token);\n</code></pre>\n</blockquote>\n<p>This <code>assert()</code> is wrong. You're claiming that <code>malloc()</code> can't return a null pointer - but it can, and does.</p>\n<p>You'll need to examine <co... | {
"AcceptedAnswerId": "262622",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T12:26:34.823",
"Id": "262613",
"Score": "1",
"Tags": [
"c",
"strings",
"memory-management"
],
"Title": "A [non-destructive] better (not really) `strtok` function"
} | 262613 |
<p>I was working on one telgram bot, and when finally i made everything i discovered that it is extremely slow.
def s takes 5-7 seconds to get result and send it to user, i tried to optimise it with methods from other sites, but it didn't work.
How can i optimise it?</p>
<pre><code>import telebot
import pyscp
from goog... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T14:27:05.397",
"Id": "518330",
"Score": "0",
"body": "What does the code do? Why does a \"telegram bot\" need to fetch 5 urls ?"
}
] | [
{
"body": "<p>There are a number of issues, but I'm guessing that the major slowdown in <code>s()</code> is due to the unnecessarily repeated calls to <code>pyscp.wikidot.Wiki('scpfoundation.net')</code>.</p>\n<p>This web request is done once for each match in <code>searchlines</code> and then done 5 more times... | {
"AcceptedAnswerId": "262628",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T13:02:55.500",
"Id": "262615",
"Score": "2",
"Tags": [
"python",
"performance",
"python-3.x",
"telegram"
],
"Title": "Optimizing telegram bot"
} | 262615 |
<p>I'm doing the following challenge from leetcode.com, that requires merging a list of lists. <a href="https://leetcode.com/problems/merge-k-sorted-lists/" rel="nofollow noreferrer">https://leetcode.com/problems/merge-k-sorted-lists/</a></p>
<p>This is the challenge:</p>
<blockquote>
<p>You are given an array of k lin... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T16:14:51.800",
"Id": "518369",
"Score": "2",
"body": "Welcome to the Code Review Community. It would be helpful if you quoted the text of the programming challenge in the question and the `title` told us about what the code does. We... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T13:23:55.953",
"Id": "262618",
"Score": "0",
"Tags": [
"programming-challenge",
"racket"
],
"Title": "Merging a list of lists"
} | 262618 |
<p>code climate tells me this block of code has a Cognitive Complexity of 7 (exceeds 5 allowed). Any ideas how I would refactor this to reduce complexity?</p>
<pre><code>const validateDays = (param, days, dateValues) => {
if (!days || !param) {
return;
} else if (param === 'from' && dateValues) {
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T14:04:10.137",
"Id": "518326",
"Score": "0",
"body": "sometimes code just is as complex as it is. Do **you** think your code is too complex? Or do you just want to get CodeClimate to shut up?"
},
{
"ContentLicense": "CC BY-S... | [
{
"body": "<p>Since every <code>if</code> statement also has a <code>return</code>, you don't need the <code>else</code>, you can just start the next <code>if</code> without typing <code>else</code>.</p>\n<p>This reduces the "indentation" and keeps the code "flat" (for lack of better words) ... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T13:48:50.593",
"Id": "262621",
"Score": "0",
"Tags": [
"javascript",
"react.js"
],
"Title": "How to refactor and reduce complexity of this code"
} | 262621 |
<p>An Object-relational mapper built using PHP.</p>
<p><strong>This question is related to this old question.</strong>
(<a href="https://codereview.stackexchange.com/q/261272/218131">Object relational mapper - optimize in memory data representation and code improvements</a>)</p>
<h6>This was done for educational purpos... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-04T11:22:19.053",
"Id": "520772",
"Score": "0",
"body": "“_Mostly I'm bothered about using foreach loops in most places._” would you rather have a different loop style, or hope/expect to achieve the same functionality without a loop?"
... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T14:09:58.230",
"Id": "262623",
"Score": "0",
"Tags": [
"algorithm",
"php",
"library",
"orm"
],
"Title": "Object Relational Mapper - improvements to use in production"
} | 262623 |
<p>Below is an implementation of a UTF-8 string to UTF-16 string. Kind of like <code>MultiByteToWideChar</code> on Win32, but it's cross-platform and <code>constexpr</code>. Passing null as the output simply calculates the size. It works in my testing.</p>
<pre><code>#include <stddef.h>
namespace utf_converter {... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T15:59:14.680",
"Id": "518358",
"Score": "1",
"body": "Please do not edit code after the question has been answered, read [What should I not do when someone answers](https://codereview.stackexchange.com/help/someone-answers)"
},
... | [
{
"body": "<p>Good job on general organization: use of namespace and nested detail namespace, use of different sized char types, marking things with noexcept, etc.</p>\n<hr />\n<p>Error: Why do you return <code>false</code> when the function expects a <code>ptrdiff_t</code>?</p>\n<hr />\n<p>Architecture: mix... | {
"AcceptedAnswerId": "262656",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T14:31:27.080",
"Id": "262626",
"Score": "5",
"Tags": [
"c++",
"c++20",
"unicode"
],
"Title": "UTF-8 to UTF-16 (char8_t string to char16_t string)"
} | 262626 |
<p>I'm reading Bruce Molay's book on Unix programming, and as an exercise I've implemented a copy of the <code>tail</code> command.</p>
<p>My approach goes over the entire file once, to count newlines, then again to store their positions in an array, and finally a third time to print out the bytes past the position of ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T16:28:08.757",
"Id": "518374",
"Score": "0",
"body": "C++ might be a bit easier if you are coming from Python :)"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T16:45:08.083",
"Id": "518377",
... | [
{
"body": "<h1>You only need one pass</h1>\n<p>Your solution to have three passes over the input has some big problems. Most notably, if the input is very large, you also need to create a large temporary file. But you now also have to deal with issues surrounding temporary files, like what if I run two instance... | {
"AcceptedAnswerId": "262636",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T15:15:13.673",
"Id": "262629",
"Score": "3",
"Tags": [
"c",
"reinventing-the-wheel",
"linux",
"unix"
],
"Title": "Writing a tail command clone"
} | 262629 |
<p>I created an algorithm for generating Latin Square. The algorithm uses the first n permutations (Not n!) orderings of a distinct row of numbers. This is then assigned to a 2d list.</p>
<pre><code>import itertools
def latin_square(rows, numbers):
assert rows is not None, "row is required to not be None"... | [] | [
{
"body": "<p><strong>Functionality</strong></p>\n<p>Your code is incorrect, as you can see in your fourth test case:</p>\n<pre><code>latin_square(3, [3, 2, 1]) == [[3, 2, 1],\n [3, 1, 2],\n [2, 3, 1]]\n</code></pre>\n<p>This is not a latin square, sin... | {
"AcceptedAnswerId": "262637",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T15:24:53.687",
"Id": "262630",
"Score": "2",
"Tags": [
"python",
"python-3.x"
],
"Title": "Generating a Latin Square"
} | 262630 |
<p><a href="https://docs.rs/roux/1.3.5/roux/" rel="nofollow noreferrer"><code>roux</code></a> is a Rust library that wraps the Reddit API. Neither Reddit nor <code>roux</code> provides a stream-like interface for obtaining the latest submissions automatically, so that's what I've implemented here.</p>
<p>I'm learning R... | [] | [
{
"body": "<p>Your code is good for the most parts, however there are some improvements that can be made:</p>\n<p>The final line in your <code>main</code> method <code>submission_res.unwrap()</code> should be changed to handle the errors and maybe log them.</p>\n<hr />\n<p>Personally, I would change the structu... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T16:20:42.763",
"Id": "262635",
"Score": "4",
"Tags": [
"rust",
"asynchronous"
],
"Title": "Async streaming of Reddit posts"
} | 262635 |
<p>This code is for changing local user password on remote machines. According to security passwords of privilege accounts need to change once in a while. Script trying to connect to a machine and trying to change a password. Then build custom object with results of an attempt.</p>
<pre><code>function Set-UserPassword
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T23:32:10.330",
"Id": "518422",
"Score": "2",
"body": "[1] function parameter positions otta start with ZERO, not `1`. ///// [2] adding to an array with `+=` is generally a bad habit. either loop thru the list and assign the loop out... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T18:45:39.590",
"Id": "262643",
"Score": "0",
"Tags": [
"powershell"
],
"Title": "Changing password on remote machine. Try-catch, custom object building"
} | 262643 |
<p>A junior developer here.</p>
<p>I wrote a simple javascript custom element code here: <a href="https://codepen.io/rndbox/pen/mdWxryw" rel="nofollow noreferrer">https://codepen.io/rndbox/pen/mdWxryw</a> as clean as I could with some advice from <a href="https://www.youtube.com/watch?v=g2nMKzhkvxw" rel="nofollow noref... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T19:23:28.417",
"Id": "518480",
"Score": "0",
"body": "The video shows what \"clean code\" may look like but doesn't show how to get there. I would highly advise that you check out [Wealcome](https://www.linkedin.com/company/wealcome... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T19:01:56.287",
"Id": "262645",
"Score": "2",
"Tags": [
"javascript",
"ecmascript-6",
"plugin"
],
"Title": "Custom HTML Element with scrolling text"
} | 262645 |
<p>Sifting is used to create a Latin Square of distinct symbols. The sifting is implemented by swaps on an array. The symbols might be strings or integer, but they are required to be distinct. Notably, this requires deep copy so that the whole Latin Square is not sifted by the same 1.</p>
<pre><code>import copy
def ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T19:55:45.747",
"Id": "518400",
"Score": "2",
"body": "This is not a latin square. `[[0, 1, 2], [1, 0, 2], [2, 0, 1]]` has `2` in the 3rd column twice, and `0` in the second column twice. It looks like your test case was created w... | [
{
"body": "<p>The bug is that a swap between two elements will not result in a Latin square. Instead, (row + col) % (rows * cols) generates a unique number for each element of the Latin square.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
... | {
"AcceptedAnswerId": "262756",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T19:04:58.710",
"Id": "262646",
"Score": "-3",
"Tags": [
"python",
"python-3.x"
],
"Title": "Generating a Latin Square (Modified Algorithm)"
} | 262646 |
<p>The code is written in TypeScript.</p>
<pre><code>export function waitFor<T, R> (
reducer: (acc: R, value: T) => R,
initial: R,
condition: (accumulated: R) => boolean,
): OperatorFunction<T, R> {
return (source$: Observable<T>) => {
return new Observable<R>((subscriber) =... | [] | [
{
"body": "<p>Yes, this implementation looks sound to me.</p>\n<p>Also you should first try to implement new operators like this by combining existing operators, since that leaves less room for mistakes, oversights, and let you piggyback on all the years of improvements the library wend trough.</p>\n<p>You alre... | {
"AcceptedAnswerId": "262669",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T20:06:22.137",
"Id": "262649",
"Score": "0",
"Tags": [
"javascript",
"typescript",
"rxjs"
],
"Title": "A custom RxJS operator which emits (and completes) once a condition has ... | 262649 |
<p>I recently picked up C, because I am getting tired of the hell that is Java Enterprise development.
I decided that writing a Huffman compressor will be a great little exercise, and I have always wanted to write a compression algorithm.
I want some pointers(get it) on how to make the code more idiomatic, modular and ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T22:39:27.267",
"Id": "518419",
"Score": "1",
"body": "Why not C++? It would avoid some of the low-levelness that trips you up if you are used to Java (e.g. strings), is far less verbose, and potentially faster due to more extensive... | [
{
"body": "<p>Quite well-formatted, but does not quite escape your Java roots.<br />\nUnfortunately, they lead to unidiomatic code, inefficient code, and even bugs.</p>\n<ol>\n<li><p>A string in C is a data-structure, not a type. Specifically, it's a sequence of non-nul elements terminated and including the ter... | {
"AcceptedAnswerId": "262655",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T20:48:36.973",
"Id": "262651",
"Score": "1",
"Tags": [
"algorithm",
"c",
"compression"
],
"Title": "Huffman compressor in plain C"
} | 262651 |
<p>Can someone give me any suggestions over my code that I made for this task?
Also how much of 10 would rate it ?</p>
<p>Suppose a simply linked list whose node is of type node and
contains a student's name, registration number, and grade(vathmos), such as
shown below:</p>
<pre><code>struct node
{
char name [30];
int ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T09:07:03.090",
"Id": "518435",
"Score": "1",
"body": "Welcome to Code Review! The current question title, which states your concerns about the code, is too general to be useful here. Please [edit] to the site standard, which is for ... | [
{
"body": "<ul>\n<li><p>I suspect that the code works. However, most people will frown at <code>->next->next->next</code>. If you'd need to delete the third from last (or 6th, or 42nd), what would you do?</p>\n<p>Consider writing a more generic function,</p>\n<pre><code> struct node * delete(struct no... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T21:56:05.527",
"Id": "262652",
"Score": "1",
"Tags": [
"algorithm",
"c",
"homework"
],
"Title": "C code in Data structures"
} | 262652 |
<p>I'm 16 years old and no one to help me, no one to give any advice or constructive criticism, I'm aimless. I'll leave the link to my last code (github), a program that sends an email to everyone registered in the database. I would like some advice and project/content ideas for me to evolve. Evaluate my project sincer... | [] | [
{
"body": "<p>That's already a nice improvement. However there is a lot of <code>static</code> in your code. <code>static</code> is the "Uncle Ben" keyword; it has "great power but induce great responsibilities".</p>\n<p>Think back to the <em><strong>O</strong>pen Closed</em> principle of so... | {
"AcceptedAnswerId": "262746",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T22:06:56.870",
"Id": "262653",
"Score": "0",
"Tags": [
"java",
"sql",
"swing",
"email"
],
"Title": "Evaluate my program with Java Mail + Sql + Swing"
} | 262653 |
<p>I've created a server file, that keeps waiting for clients. When someone connects to the server, he can send messages to the server, and from the server it is broadcasted to all clients.</p>
<p>Can you criticize my simple chat? Any possible improvements and changes are welcome. I have 2 files:</p>
<p><strong>Server:... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T09:21:30.747",
"Id": "518438",
"Score": "1",
"body": "Incorporating advice from an answer into the question violates the question-and-answer nature of this site. You could post improved code as a new question, as an answer, or as a... | [
{
"body": "<ul>\n<li><code>text_type</code> is really an "encoding", not a type, so there is a better variable name than this</li>\n<li><code>server</code> should not be a global</li>\n<li><code>server</code> should be wrapped in a <code>with</code> - see <a href=\"https://docs.python.org/3/library/so... | {
"AcceptedAnswerId": "262662",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T23:00:34.867",
"Id": "262658",
"Score": "4",
"Tags": [
"python-3.x",
"socket"
],
"Title": "TCP chat room in Python 3"
} | 262658 |
<p>While reading <a href="https://people.eecs.berkeley.edu/%7Ebh/ss-toc2.html" rel="nofollow noreferrer"><strong>Simply Scheme</strong></a> by <em>Brian Harvey</em> and <em>Matthew Wright</em>:</p>
<blockquote>
<p><a href="https://people.eecs.berkeley.edu/%7Ebh/ssch2/functions.html" rel="nofollow noreferrer">Part I: Ch... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-04T23:14:21.027",
"Id": "262659",
"Score": "1",
"Tags": [
"beginner",
"reinventing-the-wheel",
"lisp",
"scheme",
"racket"
],
"Title": "Simply Scheme book: \"functions.scm\", ... | 262659 |
<blockquote>
<p>for some reason the function setlocale(LC_ALL, "English") doesn't work when using an input function,(getchar, scanf, fgets,..), to get a special character, (Ç, ã, õ, é,...).</p>
</blockquote>
<pre><code> #include <stdio.h>
#include <stdlib.h>
#include <locale.h>
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T03:15:31.110",
"Id": "518427",
"Score": "0",
"body": "Welcome. You did not review the existing code ?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T09:12:45.737",
"Id": "518436",
"Score": "0... | [
{
"body": "<h1><code>setlocale()</code> expects language tags</h1>\n<p>You call <code>setlocale(LC_ALL, "Portuguese")</code>, but unfortunately the system does not expect the English name for a language, but rather a so-called <a href=\"https://en.wikipedia.org/wiki/Language_localisation#Language_tags... | {
"AcceptedAnswerId": "262670",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T00:12:58.553",
"Id": "262660",
"Score": "0",
"Tags": [
"c",
"io",
"localization"
],
"Title": "how to make inputs work well with special characters using the locale.h library?"... | 262660 |
<p>I wrote the following Python library for getting a callable's argument names, testing whether a callable takes an argument with a given name, and filtering a <code>dict</code> down to just the keys that a callable accepts. You can see the entire code (tests etc.) <a href="https://github.com/jwodder/argset" rel="nof... | [] | [
{
"body": "<p><code>argset()</code> should be moved to a <code>@classmethod</code> pseudoconstructor in <code>ArgSet</code>. Otherwise, the most concerning thing about this code is that it exists at all. I find that metaprogramming is a sign that something, somewhere, has gone wrong in the design process. It ca... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T00:44:04.277",
"Id": "262661",
"Score": "2",
"Tags": [
"python",
"python-3.x",
"api"
],
"Title": "API design of library for argument inspection & filtering"
} | 262661 |
<p>Happily picked up Haskell a couple days back and working on the following use case.</p>
<p>Given a list of JSON objects with date fields and a start date, I want to create a list of weeks (here a tuple of dates, but improvements are welcome) from the start date to today plus a week, and count the number of days from... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T00:57:13.327",
"Id": "262663",
"Score": "1",
"Tags": [
"haskell",
"functional-programming",
"monads"
],
"Title": "Count number of days within each date range in a list of date ran... | 262663 |
<p>Note: this script requires <code>gmpy2</code>, if you are using Python 3.9.5 x64 on Windows 10 21H1 like me, then you need to download the pre-built <code>gmpy2</code> wheel from here: <a href="https://www.lfd.uci.edu/%7Egohlke/pythonlibs/" rel="nofollow noreferrer">https://www.lfd.uci.edu/~gohlke/pythonlibs/</a>.</... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T18:32:49.350",
"Id": "518475",
"Score": "1",
"body": "You may consider Machin's variety of formulas, starting with \\$\\dfrac{\\pi}{4} = 4\\arctan\\dfrac{1}{5} - \\arctan\\dfrac{1}{239}\\$, which converge in a blink of an eye."
}
... | [
{
"body": "<h1>Efficiency and accuracy</h1>\n<p>If the goal was to have the best function to calculate π, then you should just pick the algorithm which is known the converge the fastest, and optimize that as much as possible. There's not much point in wanting to optimize an algorithm you know isn't ever going t... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T10:56:13.743",
"Id": "262671",
"Score": "3",
"Tags": [
"python",
"performance",
"beginner",
"python-3.x",
"programming-challenge"
],
"Title": "Python 3 approximate pi usin... | 262671 |
<p>Could anyone help me with below logic implementation. I am new to Javascript and have been practicing advanced functions. The below code does the job but is there a better way to achieve the same? I want to make my code perfect.</p>
<p>I am grouping by location and then getting the sentiments count.</p>
<pre><code>/... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T11:13:12.660",
"Id": "518447",
"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": "<h1>Output format</h1>\n<p>For each location, you have a list of objects with a single sentiment.</p>\n<p>i.e.: <code>{ France: [ { dissatisfied: 1 }, { happy: 2 }, ... ] }</code></p>\n<p>To access how many are "happy" from France you would need to do something like</p>\n<pre><code>const ha... | {
"AcceptedAnswerId": "262673",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T10:56:41.617",
"Id": "262672",
"Score": "2",
"Tags": [
"javascript",
"beginner"
],
"Title": "Is there a better approach to group the props and get the count of an object of arrays... | 262672 |
<h2>Intro</h2>
<p>So I am writing a larger script where a part of it is checking user input. Maybe I have a menu where the user can choose different options, or maybe I want them to write in some number/s. After some thinking I decided to write an all encompassing function to handle all the different user inputs. In sh... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T17:35:10.940",
"Id": "518563",
"Score": "0",
"body": "Input for what particular purpose?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T17:40:50.593",
"Id": "518564",
"Score": "0",
"body"... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T11:45:00.343",
"Id": "262674",
"Score": "0",
"Tags": [
"python-3.x",
"parsing",
"user-interface"
],
"Title": "User input, floats, ints and ranges"
} | 262674 |
<p>I mainly write code for data analysis so don't think about or use OOP at all on the day job. I thought I'd have a go at a simple Monty Hall simulation in an object-oriented style to figure out how it works - specifically I based it on this: <a href="https://www.reddit.com/r/dailyprogrammer/comments/n94io8/20210510_c... | [] | [
{
"body": "<p>I'm by no means an expert and recognizing that something can be improved doesn't necessarily mean you know how. But let's give it a try anyway.</p>\n<p>For the OO approach:\nI would say there are 3 key elements in the Monty Hall problem (4 if the looping over games is also included) that we want t... | {
"AcceptedAnswerId": "262688",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T11:48:20.660",
"Id": "262675",
"Score": "6",
"Tags": [
"python",
"object-oriented",
"simulation"
],
"Title": "Monty Hall simulation - OOP"
} | 262675 |
<p><strong>Problem statement for better understanding</strong>:
Let's say we assign a unique number to each alphabet,</p>
<pre><code>a=1, b=2, c=3...z=26
</code></pre>
<p>then find the frequency of the sum of each word for all possible three letter words (with or without meaning). E.g.</p>
<blockquote>
<p>abc has sum ... | [] | [
{
"body": "<p>There are three things you are doing here:</p>\n<ul>\n<li>Three loops</li>\n<li>Sum</li>\n<li>Grouping and counting</li>\n</ul>\n<p>The way I would recommend to do these things in Kotlin are:</p>\n<p>One loop: <code>val loop = 1..26</code></p>\n<p>Three loops and sum: <code>loop.flatMap {x -> l... | {
"AcceptedAnswerId": "262699",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T12:44:36.243",
"Id": "262678",
"Score": "2",
"Tags": [
"functional-programming",
"kotlin"
],
"Title": "Using Functional programming to untangle deeply nested loops (Kotlin)"
} | 262678 |
<p>I am wondering if this is correct:</p>
<pre><code>VAR <- c("City")
data %>%
select(salary, age, VAR)
melt(id.vars = c("Salary2", "Age2","City")) -> finalData
</code></pre>
<p>I get the message:</p>
<pre><code>Note: Using an external vector in selections is ambigu... | [] | [
{
"body": "<p>Here the VAR created another instance that is not part of data. Remember in R, everything is a vector.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T15:33:50.233",
"Id": "518463",
"Score": "0",
"body": "Thank... | {
"AcceptedAnswerId": "262710",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T14:51:32.233",
"Id": "262682",
"Score": "1",
"Tags": [
"r"
],
"Title": "R coding: creating a name variable to use with select"
} | 262682 |
<p>I have a list of <code>n</code> cities and hourly weather prediction for each one of them for <code>h</code> hours. I'm writing a script to find a pair of cities which has the most similar weather. And to represent the similarity in terms of a percentage scale.</p>
<p>An example dataset with 5 hour forecast for 3 ci... | [] | [
{
"body": "<p>You probably want to replace</p>\n<pre><code>def main(): \n</code></pre>\n<p>with</p>\n<pre><code>if __name__ == "__main__":\n</code></pre>\n<p>This second form means only run the indented code if this module specifically is called, not if it is imported. I'm assuming after the provided ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T15:57:18.567",
"Id": "262684",
"Score": "2",
"Tags": [
"python",
"performance",
"pandas"
],
"Title": "Find the most similar pair of rows from a table"
} | 262684 |
<p>There are some Kiosk machines for people to take a survey. The survey is running by a 3rd party, so no way to get the data from them. To measure how much machines are in use I wrote a script to pull Edge-Chromium browsing history from a remote machine</p>
<pre><code>function Copy-FileRemotely
{
[CmdletBinding()]... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T20:38:05.970",
"Id": "518492",
"Score": "0",
"body": "just for my curiosity ... how does the cache give you \"how much machines are in use\"?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T20:55:30.7... | [
{
"body": "<p>To make what you have more readable, I would not create a helper function to replace <code>Copy-Item</code>:</p>\n<pre class=\"lang-sh prettyprint-override\"><code>$comps = "smz-F9246-DB", "xxx"\n\n$result = foreach ($comp in $comps) {\n Try { Copy-Item `\n -Path "\\\\... | {
"AcceptedAnswerId": "263345",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T16:36:11.237",
"Id": "262687",
"Score": "1",
"Tags": [
"powershell"
],
"Title": "Script to copy Egde-Chromium browsing history from a remote machine. Try-catch, custom object building... | 262687 |
<p>I am attempting to perform <a href="https://en.wikipedia.org/wiki/Median_filter" rel="nofollow noreferrer">Median Filter</a> with size 3 x 3 in C language. The function <code>MedianFilter33</code> has been implemented as follows.</p>
<p><strong>The experimental implementation</strong></p>
<ul>
<li><p>The basic struc... | [] | [
{
"body": "<ul>\n<li><p>Thou shalt not cast <code>malloc</code>. It is redundant (if you <code>#include <stdlib.h></code>), and may lead to hard-to-find bugs (if you don't).</p>\n</li>\n<li><p><code>sort_array</code> is allocated at each iteration, yet never <code>free</code>d.</p>\n<p>That said, I don't ... | {
"AcceptedAnswerId": "262691",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T17:37:20.973",
"Id": "262690",
"Score": "4",
"Tags": [
"c",
"reinventing-the-wheel",
"file",
"image",
"memory-management"
],
"Title": "Image Processing Median Filter i... | 262690 |
<p>A follow-up for <a href="https://codereview.stackexchange.com/q/262626/183642">this</a> previous question.</p>
<p>I took into account previous reviews, and tried to make a simple API. I had never done anything non-trivial with C++20 concepts and ranges until now, so I am sure I have a lot of things to fix. I added m... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T13:34:28.653",
"Id": "518626",
"Score": "0",
"body": "_there is no way to specify \"iterator for int\" or \"range of int\"_ Probably because the standard algorithms and most code people write won't be specific for collections of `i... | [
{
"body": "<p>It's better to include <code><cstddef></code> than the deprecated <code><stddef.h></code> in C++ code (that ensures the definitions are in the <code>std</code> namespace). Ironically, the code proceeds to use <code>std::nullptr_t</code> despite the fact that the C header makes no guar... | {
"AcceptedAnswerId": "262765",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T19:42:04.743",
"Id": "262692",
"Score": "4",
"Tags": [
"c++",
"c++20",
"unicode"
],
"Title": "UTF-8 to UTF-16 using C++20 concepts and ranges"
} | 262692 |
<p>I've tried to implement multithreaded pathfinding in an attempt to increase performance, but if anything, performance seems to actually decrease when I enable multithreading.</p>
<p>Is there anything I should do differently in order to see a performance gain from multithreading?</p>
<pre><code>using System;
using Sy... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T18:29:03.047",
"Id": "518784",
"Score": "0",
"body": "One tip: `_threads` collection isn't thread-safe, be sure not to damage while using it concurrently."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T20:02:02.277",
"Id": "262693",
"Score": "5",
"Tags": [
"c#",
"performance",
"multithreading",
"unity3d"
],
"Title": "Multithreaded pathfinding in Unity C#"
} | 262693 |
<p>I have a 200 line fully functional flappy bird code but I was told it's suppose to be 250 lines. I don't know what more I can add to the js of the game to improve it and make it longer. I was told I can maybe add a pause button but I only know how to do it through css and not through JS. any suggestions? I also thou... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T20:18:37.780",
"Id": "518485",
"Score": "5",
"body": "\"I have a 200 line fully functional flappy bird code but I was told it's suppose to be 250 lines.\", why are the number of lines important?"
},
{
"ContentLicense": "CC B... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "9",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T20:17:03.977",
"Id": "262694",
"Score": "2",
"Tags": [
"javascript"
],
"Title": "What to add to a Flappy Bird JavaScript code"
} | 262694 |
<p>I tested this algorithm on 9x9 boards and on average, if the board passed to the function is a (valid) solution, it takes 0.13-0.14 seconds for 1 million executions on my machine. I ran my code in Release mode in Visual Studio and timed it using <code>Stopwatch</code>. I found the idea to use summing of all digits i... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T22:24:05.140",
"Id": "518505",
"Score": "0",
"body": "Why do you want to make this faster? Why run it a million times? It should be good to run one time on a given puzzle and \"validate\" -> answer if it's a correct solution or not?... | [
{
"body": "<p>As it was stated by @harold and @iSR5 your current implementation is not bullet-proof. I will not repeat their suggestions.</p>\n<p>Rather I want to show you how to reduce repetition.<br />\nSo, let me share with you my revised version for <code>IsValidSudokuBoard9x9</code> then I will explain it:... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T20:58:25.000",
"Id": "262698",
"Score": "1",
"Tags": [
"c#",
"algorithm",
".net",
"validation",
"sudoku"
],
"Title": "Possible speed improvements for a Sudoku board valida... | 262698 |
<p>As a hobby project (and to learn the language), I'm working on a crypto library in Rust. The following is a component thereof, which implements encryption with and the cracking of the Caesar cipher.</p>
<p>My primary interest is whether the code follows best practices, with a secondary concern regarding its efficien... | [] | [
{
"body": "<p>Overall, your implementation looks good! Your code is well documented, it has unit tests and the use of the standard traits is also great.</p>\n<p><strong>Here are some of my suggestions:</strong></p>\n<p>The <code>value</code> field of <code>Letter</code> must be in the range 0-25, I would either... | {
"AcceptedAnswerId": "262808",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-05T22:00:21.940",
"Id": "262701",
"Score": "5",
"Tags": [
"beginner",
"rust",
"caesar-cipher"
],
"Title": "Caesar cipher/beginnings of a crypto library in Rust"
} | 262701 |
<p>In learning haskell, I'm writing a fuzzy menu. At the moment, my executable reads in a 'dictionary' from stdin, and ranks each word according to how well it fuzzily matches a search pattern given in the first CLI arg. The idea of the fuzzy matching algorithm is to split a pattern by its delimiters, and then match ea... | [] | [
{
"body": "<ol>\n<li>I think your use of do notation in the splitWord function is bad and I think your code is even correct by accident. Let me add parentheses to highlight it:</li>\n</ol>\n<pre class=\"lang-hs prettyprint-override\"><code>splitWord s = do\n let rest = splitWord (tail s)\n let f... | {
"AcceptedAnswerId": "262715",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T01:19:19.463",
"Id": "262704",
"Score": "1",
"Tags": [
"haskell"
],
"Title": "Fuzzy Finding in Haskell"
} | 262704 |
<p>Is it good practice to create many subtypes which are all exactly the same just for more descriptive class names? I did this but then I realised all my subtypes were redundant, and it seemed kind of like duplication. I deleted them all. Now I just use one type, and I tend to be able to write more reusable code and e... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T06:35:21.383",
"Id": "518518",
"Score": "1",
"body": "*create many subtypes which are all exactly the same just for more descriptive class names?* NO. You and I are the same type but have different **variable names**. We have dif... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T03:05:26.040",
"Id": "262705",
"Score": "0",
"Tags": [
"object-oriented",
"design-patterns",
"classes"
],
"Title": "Create Many Subtypes which are all exactly the same VS use just... | 262705 |
<p>Dear coding black belts,</p>
<p>My code is working but seems clunky.</p>
<ul>
<li>Take a random number from 1 to 99,999</li>
<li>Display it in 3D in a modified version of the <a href="https://en.wikipedia.org/wiki/The_Ciphers_of_the_Monks" rel="nofollow noreferrer">Cistercian numerals</a> from 13th century monks (ad... | [] | [
{
"body": "<h1>Avoid repeating yourself</h1>\n<p>There is <em>a lot</em> of code duplication in your program. This means you had to type in more than necessary, and the chance of bugs getting in your code has increased as well. Whenever you find you have lots of similar sections of code, find a way to reduce th... | {
"AcceptedAnswerId": "262749",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T04:48:39.987",
"Id": "262707",
"Score": "3",
"Tags": [
"python",
"matplotlib"
],
"Title": "3d Cistercian numbers mini game (MatPlotLib), inputting similar xyz coordinates 50 times... | 262707 |
<p>I have written the following code. It checks to see if the object contains the key where the key is present in the map.</p>
<pre><code>const myMap = new Map();
myMap.set(2, 'test1');
myMap.set(3, 'test1');
let cellToHighLight = [];
let contanins = false;
for (let a = 2; a <= 5; a++)
cellToHighLight.push({
'... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T19:08:49.493",
"Id": "518529",
"Score": "0",
"body": "Use `Set`. Make a set of all the keys of `myMap`, make a set of the `rowId` values in `cellToHighLight`. Then test the intersection of the two sets."
},
{
"ContentLicense... | [
{
"body": "<p>The Map() constructor can take an array of pairs, so you can set its starting values in one go.</p>\n<p>A little whitespace can go a long way to visually separate different parts of your code.</p>\n<p>I won't focus too much on your first for loop, as it looks like it was mainly meant to set up dum... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T19:03:36.263",
"Id": "262716",
"Score": "1",
"Tags": [
"javascript"
],
"Title": "Cleaning up and optimizing JavaScript code to check if an object contains a key that is present in a map"
... | 262716 |
<p>Just wrote this small ring buffer system for an embedded device using C++98. Looking for cc, advice and bugs.</p>
<p>Please check it out!</p>
<p><a href="https://github.com/Bambofy/EmbeddedRingBuffer" rel="nofollow noreferrer">https://github.com/Bambofy/EmbeddedRingBuffer</a></p>
<pre><code>/* Changelog ------------... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T11:26:36.027",
"Id": "518535",
"Score": "0",
"body": "There was a bit of a formatting problem with your code apparently, the current version should be better. Is there a reason your `ifndef` talks about a `RINGBUFFER_RINGBUFFER_H` (... | [
{
"body": "<p>This looks quite good, some minor changes could be made though:</p>\n<h1>Return <code>overrun_flag</code> instead of storing it</h1>\n<p>Especially on an embedded system, you don't want to store data unnecessarily. Instead of having a member variable <code>overrun_flag</code> and having <code>Appe... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T10:36:49.787",
"Id": "262717",
"Score": "2",
"Tags": [
"c++",
"circular-list",
"embedded",
"c++98"
],
"Title": "Ring buffer for Arduino"
} | 262717 |
<p>I have the following working code for a generic WebSocket component:</p>
<pre><code>import json
import aiohttp
import asyncio
import gzip
import asyncio
from threading import Thread
class WebSocket:
KEEPALIVE_INTERVAL_S = 10
def __init__(self, url, on_connect, on_msg):
self.url = url
self.... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T15:05:58.627",
"Id": "262722",
"Score": "1",
"Tags": [
"python",
"multithreading",
"websocket",
"asyncio"
],
"Title": "Building a generic WebSocket component in Python"
} | 262722 |
<p>I'm using PHP/Laravel and I have two controllers.</p>
<ul>
<li>Controllers/PaymentController</li>
<li>Controllers/PaymentExpressControler</li>
</ul>
<p>They both create an request which is exactly the same, but it has some differences.</p>
<p>Let's say, they both use <code>createRequest(Request $Request)</code> whic... | [] | [
{
"body": "<p>I would create another service layer that would handle the creation of the request and maybe the call to the third party api. Your controllers are there to create the best response to the http request not really to create the best response, create external requests, handle them, etc..</p>\n",
... | {
"AcceptedAnswerId": "262792",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T15:56:23.690",
"Id": "262724",
"Score": "2",
"Tags": [
"php",
"laravel"
],
"Title": "How to reduce a POST request duplicate in Laravel/PHP for payment system?"
} | 262724 |
<p>This is the simplest implementation of the 'DataGridBehavior' Class for column Filtering I could come up with:</p>
<pre><code> public static List<ColumnItem> GetColumnsFilter(DependencyObject obj) { ...}
public static void SetColumnsFilter(DependencyObject obj, List<ColumnItem> value) { ...}
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T21:17:32.770",
"Id": "518578",
"Score": "0",
"body": "Just a tip: for filtering I prefer `ICollectionView.Filter`. Something like [this](https://docs.microsoft.com/en-us/dotnet/desktop/wpf/controls/how-to-group-sort-and-filter-data-... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T16:09:13.960",
"Id": "262725",
"Score": "2",
"Tags": [
"c#",
"wpf",
"xaml"
],
"Title": "WPF DataGrid Column FIltering using Behaviors"
} | 262725 |
<p>I have several Dao classes, including a UserDao, below. The DAOs have many methods, but I'm focussing on <code>deleteUser</code>:</p>
<pre><code>@Override
public boolean deleteUser(Connection connection,String login) throws MySQLEXContainer.MySQLDBExecutionException, SQLException {
int rowNum = 0;
... | [] | [
{
"body": "<h3>What are you testing?</h3>\n<p>Consider whether or not mocking is really the way you want to go with testing your DAO. Often an integration test / in-memory database test can be simpler / more aligned with the way the DAO changes.</p>\n<p>If you do want to go down the mocking approach, then you ... | {
"AcceptedAnswerId": "262757",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T16:14:05.253",
"Id": "262726",
"Score": "3",
"Tags": [
"java",
"unit-testing",
"database",
"jdbc",
"junit"
],
"Title": "Testing DAO Delete User"
} | 262726 |
<h2>Background</h2>
<p>I am teaching a course at university level, and have lately been working on creating a home exam for my students. However, the institute has given clear instructions that collaboration is not allowed. In order to comply with this, I saw no other way than to give each student their own variant of ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T00:36:31.997",
"Id": "518583",
"Score": "2",
"body": "You're brave using tex. I would have used html."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T00:39:51.230",
"Id": "518584",
"Score": "0... | [
{
"body": "<p>OK. You still have undefined symbols but I'm going to push on.</p>\n<ul>\n<li>For your function signatures, consider PEP484 type hints. You've done this on, for example, <code>get_max_terminal_width</code> but not <code>regex_2_find</code></li>\n<li><code>get_terminal_size</code> returns a 2-tuple... | {
"AcceptedAnswerId": "262858",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T17:44:51.780",
"Id": "262728",
"Score": "7",
"Tags": [
"python-3.x",
"object-oriented",
"regex",
"console"
],
"Title": "Stop cheating on home exams using python"
} | 262728 |
<p>I am running an IoT fleet, and the need for checking the empty disk usage space has increased.</p>
<p>So I am using the following python code.</p>
<p>In addition to best practices, efficiency, readability, pythonic, etc.
I would love you to share your thoughts about:
Is it compliance with: "Robert Martin Single... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T18:38:55.743",
"Id": "518569",
"Score": "2",
"body": "FYI, [tag:python-2.x] says: \"Do not mix this tag with the python-3.x tag\" and [tag:python-3.x] says: \"Do not mix this tag with the python-2.x tag.\" Please pick a version, or ... | [
{
"body": "<p>Overall not bad! You've managed to avoid many of the "usual suspects" when it comes to Python scripting practices.</p>\n<ul>\n<li><code>make_logger</code> could use a return typehint</li>\n<li><code>display_disk_usage</code>, trivially modified to accept a mountpoint path, would be a mor... | {
"AcceptedAnswerId": "262771",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T17:50:13.217",
"Id": "262729",
"Score": "7",
"Tags": [
"python",
"python-3.x",
"status-monitoring"
],
"Title": "Python script for alerting disk usage and take action if needed... | 262729 |
<p>A while back, I answered <a href="https://stackoverflow.com/questions/62111137/deserialize-a-binary-tree-breadth-first-in-functional-programming">this question</a> on Stack Overflow that involved deserializing a binary tree breadth-first using functional programming (the question itself isn't relevant). I'd like to ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T18:56:46.333",
"Id": "262730",
"Score": "2",
"Tags": [
"functional-programming",
"scala",
"binary-tree"
],
"Title": "Deserialize a binary breadth-first in functional programming"
... | 262730 |
<p>I want to sort object list named schedules according to arrivalT. if arrivalT is equal, I want to sort according to burst, if arrivalT and bursT both equal I want to sort according to id. Is my custom comparitor implementaion correct?</p>
<pre><code>from functools import cmp_to_key
class Pair:
def __init__(self,... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T20:04:41.593",
"Id": "518572",
"Score": "2",
"body": "In terms of correctness insofar as correct results, you need to be at least somewhat confident that your implementation is correct before this is eligible for review. The purpose... | [
{
"body": "<h1>Tips and changes</h1>\n<ol>\n<li><p>Python has a style guide <a href=\"https://www.python.org/dev/peps/pep-0008/\" rel=\"nofollow noreferrer\">PEP 8</a> which explains in excruciating detail how to structure your code. I whole heartily recommend skimming through it and follow it.</p>\n<p>For inst... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T20:01:31.923",
"Id": "262732",
"Score": "0",
"Tags": [
"python"
],
"Title": "Is my custom operator for sorting in python correct?"
} | 262732 |
<p>I have turned a "classic" Bootstrap form into a "floating labels" form.</p>
<p>For this purpose, I had to <strong>move the labels below the form controls</strong>.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pr... | [] | [
{
"body": "<ol>\n<li>I don't see anything worrying about security;</li>\n<li>Regarding usability it looks pretty good too;</li>\n<li>Since you are using <code>placeholders</code> instead of <code>labels</code> I would remove all <code>labels</code> and work only with <code>inputs</code>. Like this:</li>\n</ol>\... | {
"AcceptedAnswerId": "263144",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T20:13:28.277",
"Id": "262733",
"Score": "2",
"Tags": [
"css",
"form",
"twitter-bootstrap"
],
"Title": "Bootstrap form with floating labels"
} | 262733 |
<p>first post here. I'm looking for some general input as to the correctness of what I'm trying to do here. Is this a good idea, bad idea, what could be plus points or negative aspects to this design?</p>
<p>If this is not the right forum for this question please advise where is best, thanks :)</p>
<p>What I'm envision... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-06T21:48:08.640",
"Id": "262735",
"Score": "1",
"Tags": [
"database",
"server",
"dart",
"parse-platform"
],
"Title": "Parse Back4App database as a master database change log rath... | 262735 |
<p>I've just written this to facilitate my Wget downloads and I was wondering if anyone can review it for me.</p>
<pre><code>@ECHO off
CLS
IF [%1] == [] GOTO missing_arg
IF [%2] == [] GOTO missing_arg
IF NOT EXIST %2% GOTO bad_dir
ECHO About to download %1 to %2
ECHO.
PAUSE
CLS
CD /d "%2"
wget64 --execute r... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T06:35:52.237",
"Id": "518744",
"Score": "1",
"body": "Looks good in overall. I'd only remove `pause`."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-09T22:23:13.577",
"Id": "518907",
"Score": "0... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T06:06:34.330",
"Id": "262743",
"Score": "3",
"Tags": [
"windows",
"batch"
],
"Title": "Batch file for Wget downloads"
} | 262743 |
<p>(<a href="https://codereview.stackexchange.com/questions/262658/tcp-chat-room-in-python-3">Previous question</a>)</p>
<p>I've created a server file, that keeps waiting for clients. When someone connects to the server, he can send messages to the server, and from the server it is broadcasted to all clients.</p>
<p>Ca... | [] | [
{
"body": "<p>There are a few things I'd like to point out</p>\n<h2>The Server class</h2>\n<ul>\n<li>It would be nice to be able to tell the server to listen on a different port, presumably by making the <code>Server</code> class' constructor take the port number as a parameter</li>\n<li>When you have a pair of... | {
"AcceptedAnswerId": "262774",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T12:22:37.037",
"Id": "262754",
"Score": "3",
"Tags": [
"python-3.x",
"socket"
],
"Title": "TCP chat room in Python3"
} | 262754 |
<p>This is meant to go in a <code>vulkan.hpp</code>-like strongly-typed wrapper for a pure C library.</p>
<p>A wrapped enum provides back and forth implicit conversion between itself and the enum, while otherwise behaving as an <code>enum class</code> would.</p>
<p>Wrapper utility:</p>
<pre><code>#include <type_trai... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T15:30:38.583",
"Id": "518669",
"Score": "4",
"body": "were you aware of the site policy that you are absolutely not, for any reason, supposed to edit the code in a post after it has been answered? Changes made after an answer may ca... | [
{
"body": "<p><code>typedef enum lib_status lib_status;</code><br />\nYou don't need that in a C++ header; the enumeration tag is already a stand-alone type name in C++.</p>\n<p>There is an obligatory commented needed grumbling about the need to define all the relational operators individually due to the need t... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T12:52:16.507",
"Id": "262755",
"Score": "1",
"Tags": [
"c++",
"c++17"
],
"Title": "Typesafe implicit wrapper for C enums"
} | 262755 |
<p>I am rather new to JavaScript and never really worked with promises before. My code works but I would like to learn if there is a better approach?</p>
<p>I want to implement the following functionality:</p>
<ul>
<li>Query DB to check if user is in a team</li>
<li>if yes, query DB for items belonging to that team</li... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T14:13:47.790",
"Id": "518642",
"Score": "1",
"body": "Welcome to the Code Review Community. It helps us give a better review when the title indicates what the code does."
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T13:15:34.643",
"Id": "262758",
"Score": "1",
"Tags": [
"node.js",
"promise"
],
"Title": "Calling promise-returning function within promise-returning function"
} | 262758 |
<p>Started learning C# second time. I have written a console program to calculate sum and count of even and odd numbers. Provided code :</p>
<pre><code>using System;
namespace Studying_
{
class Program
{
static void Main(string[] args)
{
uint evenNumbersCount = 0;
uint o... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T13:52:52.967",
"Id": "518632",
"Score": "0",
"body": "Have you tested the results? The first number will not be counted as you increment it before summing. The second one will be excluded as well. Shouldn't the range be inclusive?"
... | [
{
"body": "<p>You should try your program whith different values.\nWhen asked for the first number, enter "abcdef". Hit enter, and see what happens.</p>\n<p>In such a case, when you can't be sure that the string to parse is ok, use int.TryParse(...).</p>\n",
"comments": [
{
"ContentL... | {
"AcceptedAnswerId": "262763",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T13:16:21.783",
"Id": "262759",
"Score": "6",
"Tags": [
"c#",
"beginner"
],
"Title": "Calculate sum and count of even and odd numbers"
} | 262759 |
<p>A very easily stated problem that has a surprising number of gotchas - return a value that's midway between the two supplied values.</p>
<p>Depending on the types given, we need to be aware of</p>
<ul>
<li>arithmetic overflow and underflow</li>
<li>infinities</li>
<li>NaNs</li>
<li>rounding</li>
</ul>
<p>For pointer... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T15:23:56.870",
"Id": "518665",
"Score": "2",
"body": "[std::midpoint](https://en.cppreference.com/w/cpp/numeric/midpoint) was added in C++20, I believe."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07... | [
{
"body": "<ul>\n<li><code>_</code> as a namespace name is legal, but is it a good choice for the implementation-private namespace?</li>\n</ul>\n<p>This causes undefined behavior. Identifiers that start with an underscore are reserved in the global scope.</p>\n<ul>\n<li>I believe I can forward-declare the templ... | {
"AcceptedAnswerId": "262816",
"CommentCount": "15",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T14:05:10.833",
"Id": "262762",
"Score": "9",
"Tags": [
"c++"
],
"Title": "Find the mean of two values"
} | 262762 |
<p>I was looking into Python 3.10's <a href="https://www.python.org/dev/peps/pep-0622/" rel="nofollow noreferrer">Structural Pattern Matching</a> syntax, and I want to refactor one of my code that uses <code>if-else</code>, using structural pattern matching. My code works, but I'm trying to find out if there's a better... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T18:44:57.200",
"Id": "518699",
"Score": "1",
"body": "The reason why I mentioned the syntax `[(4 | 5), *rest]` is unfortunate is because it _slices_ the list which can be an expensive operation. Now, for every case you are performin... | [
{
"body": "<p>Like you, I am excited about Python's new pattern matching. Unfortunately,\nI don't think your use case is a good fit. Every tool has strengths\nand weaknesses. In this specific situation, ordinary <code>if-else</code> logic\nseems easier to write, read, and understand. For example:</p>\n<pre><cod... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T15:47:55.480",
"Id": "262769",
"Score": "3",
"Tags": [
"python",
"pattern-matching"
],
"Title": "Structural Pattern Matching syntax to match a value in a list"
} | 262769 |
<p>Hello developers i have a got a code which is compares two txt files find their differences and notes them but i am wanting to add a feature which creates two txt files first one is for changed records and other one is for unchanged records what should i do here? Here is my code:</p>
<pre class="lang-java prettyprin... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T19:43:29.597",
"Id": "518708",
"Score": "3",
"body": "Welcome to Code Review SE! This site is for reviewing already working code for improvements and optimizations, not solving problems with broken code or other issues. In fact, the... | [
{
"body": "<p>Welcom to Code Review!</p>\n<p>As @hyper-neutrino pointed, this site is to review working code. As such, here are some tips to improve the code you've provided:</p>\n<h1>Naming</h1>\n<p>Names are absolutely fundamental to help other developers (or even yourself after not working with the code whil... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T16:12:39.207",
"Id": "262770",
"Score": "-3",
"Tags": [
"java",
"file"
],
"Title": "Creating two txt file for changed and unchanged records"
} | 262770 |
<p>Scraping tables from the web get complicated when there are 2 or more values in a cell. In order to preserve the table structure, I have devised a way to count the row-number index of its xpath, implementing a nested list when the row number stays the same.</p>
<pre class="lang-py prettyprint-override"><code> def... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T16:55:20.313",
"Id": "518684",
"Score": "2",
"body": "Can you include all of your scraping code, or at least a representative sample of HTML that you're trying to parse?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationD... | [
{
"body": "<p>First: I would typically recommend that you replace your use of Selenium with direct <code>requests</code> calls. If it's possible, it's way more efficient than Selenium. It would look like the following, as a very rough start:</p>\n<pre><code>from time import time\nfrom typing import Iterable\nfr... | {
"AcceptedAnswerId": "262782",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T16:53:03.607",
"Id": "262772",
"Score": "3",
"Tags": [
"python",
"selenium",
"xpath"
],
"Title": "Getting xpath indices to count forward to preserve table structure"
} | 262772 |
<p><a href="https://codesandbox.io/s/react-quiz-kb1xb" rel="nofollow noreferrer">https://codesandbox.io/s/react-quiz-kb1xb</a></p>
<p>I was wondering what could be improved upon it. I am looking at how it's using Redux and how it's also using hooks and I don't really see anything wrong with it, but I am wondering if it... | [] | [
{
"body": "<p>There are many ways that you can use newer syntaxes to make this cleaner:</p>\n<ul>\n<li>Function component instead of class component.</li>\n<li>Replace <code>connect</code> with react-redux hooks.</li>\n<li>Create your actions with redux-toolkit.</li>\n<li>Write better loops with specific array ... | {
"AcceptedAnswerId": "266311",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T20:43:27.543",
"Id": "262779",
"Score": "2",
"Tags": [
"react.js",
"redux"
],
"Title": "React quiz app with Redux, React Router"
} | 262779 |
<p>EDIT: code snippet added, check the output in JS console</p>
<p>I wrote the following binary search algorithm in JS, for the first time in my experience. The variable <code>sampleObj</code> is a random object array in the form of: <code>[{index: 5, sample: 3}, {index: 8, sample: 1}, ...]</code>, the final <code>cons... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T02:23:14.407",
"Id": "518732",
"Score": "0",
"body": "Hi @user122973 - the obvious problem is there's a lot of \"assumptions\" in the code. e.g. something named _sampleObj_ is used as an array... not sure many people would think t... | [
{
"body": "<h2>Review</h2>\n<p>The general impression at first look is that the code is rather messy with poor formatting, poorly organised and a lot of noisy, redundant and/or long winded code.</p>\n<p>When testing the code I found bugs. The general rule at Code Review is that code should work to the best of ... | {
"AcceptedAnswerId": "262805",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-07T22:36:13.213",
"Id": "262780",
"Score": "4",
"Tags": [
"javascript",
"binary-search"
],
"Title": "JavaScript Binary Search -- first try"
} | 262780 |
<p>My code works just fine but it seems like I have too many variables which could confuse people from what the code does. Any ideas? Or does this look fine. Feel free to add any other tips to make my code more efficient.</p>
<p>This subroutine is for a button which when clicked rotates a players position. (The overall... | [] | [
{
"body": "<p>Sometimes you are in the need for a lot of variables. The best way to make your code not confusing for others is to name the variables meaningful and easy to distinguish.</p>\n<p>For example the variables</p>\n<pre><code>Dim positionOfPlayerRotating As String\nDim rotationOfPlayerRotating As Strin... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T04:51:39.167",
"Id": "262785",
"Score": "0",
"Tags": [
"performance",
"vb.net"
],
"Title": "Rotation Management Application"
} | 262785 |
<h2>What it does</h2>
<p>Calculates the mean difference for a list of any combination of ints (I think).</p>
<h2>What I want to know</h2>
<p>The only other way I can think of doing this is using recursion.</p>
<p>I’d like to know if there are other better ways to do this.</p>
<p>Also the reason I done this is because I... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T08:59:52.423",
"Id": "518756",
"Score": "0",
"body": "I would advice you against using list comprehensions for timestamps. Time can be a tricky thing to deal with, timezones, leap years, leap seconds. Etc. Again a [quick google sear... | [
{
"body": "<p>You can reduce a lot of your code just by using pythons builtin <code>abs</code> function. I also used list comprehension to shorted your code, so your entire loop code is now in one line.</p>\n<p>This also looks like a great candidate for a function. Now, you can pass any collection of numbers to... | {
"AcceptedAnswerId": "262788",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T06:06:03.417",
"Id": "262786",
"Score": "4",
"Tags": [
"python-3.x",
"mathematics"
],
"Title": "Mean difference calculator for any int combination"
} | 262786 |
<p>(This is follow-up <a href="https://codereview.stackexchange.com/questions/262759/calculate-sum-and-count-of-even-and-odd-numbers?noredirect=1#comment518761_262759">question</a>). I updated my console program code to calculate sum and count of even and odd numbers. Provided code :</p>
<pre><code>using System;
names... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T11:22:43.007",
"Id": "518763",
"Score": "0",
"body": "From what perspective do you want improvement(s)?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T13:00:48.550",
"Id": "518767",
"Score": ... | [
{
"body": "<p>I like that you use <code>Inclusive</code> as part of some names because it adds to clarity. When I see <code>n <= rangeEndInclusive</code> there is no doubt that it correctly used, whereas <code>n < rangeEndInclusive</code> or even <code>n <= rangeEndInclusive</code> would raise doubts.... | {
"AcceptedAnswerId": "262806",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T11:02:43.310",
"Id": "262789",
"Score": "0",
"Tags": [
"c#",
"beginner"
],
"Title": "Calculating sum and count of even and odd numbers (follow-up)"
} | 262789 |
<p>(See the previous version <a href="https://codereview.stackexchange.com/questions/213961/a-simple-clusterness-measure-of-data-in-one-dimension-using-java">here</a>.)</p>
<p>(See the next version <a href="https://codereview.stackexchange.com/questions/262932/a-simple-clusterness-measure-of-data-in-one-dimension-using... | [] | [
{
"body": "<h2>Tests</h2>\n<p>Unit tests are better than printing to the console. One example:</p>\n<pre><code>@Test\npublic void testReturn0WhenEquidistantPoints() {\n ClusternessMeasure cm = new ClusternessMeasure();\n List<Double> points = List.of(1.0, 2.0, 3.0, 4.0, 5.0);\n double expected = ... | {
"AcceptedAnswerId": "262871",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T12:04:09.970",
"Id": "262790",
"Score": "1",
"Tags": [
"java",
"machine-learning",
"numerical-methods"
],
"Title": "A simple clusterness measure of data in one dimension using... | 262790 |
<p>(See the previous version <a href="https://codereview.stackexchange.com/questions/250586/a-simple-c-winapi-program-for-terminating-processes-via-process-image-names-fo">here</a>.)</p>
<p><strong>What's new</strong></p>
<ol>
<li><code>get_last_err_msg</code> renamed to <code>MyGetLastErrorMessage</code></li>
<li>The ... | [] | [
{
"body": "<p>Copying and pasting from my previous answer, your (feasible) options for error string memory management are</p>\n<ul>\n<li>Make the caller contract such that the caller is responsible for calling <code>LocalFree</code>, or</li>\n<li>Have <code>get_last_err_msg()</code> accept a buffer and size ins... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T13:00:01.607",
"Id": "262793",
"Score": "1",
"Tags": [
"c",
"windows",
"winapi"
],
"Title": "A simple C WinAPI program for terminating processes via process image names - follow-u... | 262793 |
<p>I put this together for a task and thought some feedback would be useful.</p>
<pre><code>class Matrix<T : Ring<T>>(val size: Size, init: (x: Int, y: Int) -> T) : Ring<Matrix<T>> {
init {
require(size.x > 0 && size.y > 0) { "Zero size Matrix is invalid." ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T13:27:49.850",
"Id": "262796",
"Score": "1",
"Tags": [
"kotlin"
],
"Title": "Matrix implementation in Kotlin"
} | 262796 |
<p>I was looking at a dataset with a <code>year</code> column. I wanted all the years with matching a particular event. I then get a list of years which is not easy to read:</p>
<pre><code>2010, 2011, 2012, 2013, 2015, 2017, 2018, 2019, 2020
</code></pre>
<p>It would be much better to display them as:</p>
<pre><code>20... | [] | [
{
"body": "<p>I'm glad you asked this question, as I've had a difficult time finding the solution recently as well. However, I have now found that the solution is to use the <code>more_itertools</code> <a href=\"https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.consecutive_groups\" rel=\"n... | {
"AcceptedAnswerId": "262801",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T13:32:50.247",
"Id": "262797",
"Score": "5",
"Tags": [
"python",
"algorithm"
],
"Title": "Find all subranges of consecutive values in an array"
} | 262797 |
<p>I want to implement a client storage mechanism that is as persistent as a session cookie but with more storage capacity.</p>
<p>I am doing this by encrypting the data before storing it and saving the keys in a session cookie, when this session cookie is gone the data can not be restored. Data is stored in a permanen... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T14:11:01.420",
"Id": "262798",
"Score": "2",
"Tags": [
"javascript",
"session",
"encryption",
"browser-storage"
],
"Title": "Javascript client storage with the same persistenc... | 262798 |
<p>I have developed a game that allows you to play a full game of Tetris. I haven't really been getting the runs and plays. So I have a request for your reading... Can you possibly give me ideas and or make the code a little simpler.</p>
<p>Here's the code that I made:</p>
<pre class="lang-py prettyprint-override"><cod... | [] | [
{
"body": "<p><strong>Type annotations</strong> (<a href=\"https://www.python.org/dev/peps/pep-0484/\" rel=\"nofollow noreferrer\">PEP 484</a>) are a good idea to further increase the readability of your code. They also allow for type checking.</p>\n<hr />\n<p><strong><code>get_random_piece</code></strong></p>\... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T14:41:10.213",
"Id": "262802",
"Score": "3",
"Tags": [
"python"
],
"Title": "python - Tetris Game"
} | 262802 |
<p>I have a method where I fetch user input, check if certain values exist, and based on that build my own custom input object that I would use to search in a database. The code for the search method is as follows.</p>
<pre><code>public SearchDocumentResult searchData(EmployeeInput employeeInput) {
EmployeeInput ge... | [] | [
{
"body": "<pre><code>if (formSectionInput != null) {\n this.buildFormSectionInputForSearch(formSectionInput);\n }\n</code></pre>\n<p>can be replaced with:</p>\n<pre><code>Optional.ofNullable(formSectioninput).map(this::buildFormSectionInputForSearch);\n</code></pre>\n<p>I dont understand the need of ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T16:26:22.690",
"Id": "262807",
"Score": "0",
"Tags": [
"java",
"object-oriented",
"complexity",
"cyclomatic-complexity"
],
"Title": "Optimizing methods with multiple if checks... | 262807 |
<p>I have a daemon which I am able to interact with through a cli-client. The daemon will perform some tasks in future e.g. monitoring the rate at which files are added to a directory.</p>
<p>Right now when I add a new function I need to write</p>
<ol>
<li>The function I would like to trigger</li>
<li>A message format ... | [] | [
{
"body": "<p>Maybe its not the best approach, but it gets the work done:</p>\n<h1>Intended approach</h1>\n<p>Instead of having to declare/modify/delete functions every time a command is added/changed/deleted, the idea is to have a list with all command, and then create the corresponding cli commands dynamicall... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-06-08T16:50:49.490",
"Id": "262809",
"Score": "3",
"Tags": [
"python",
"design-patterns",
"console",
"ipc"
],
"Title": "CLI-Client for interacting with daemon"
} | 262809 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.