body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I have a function that sums two arrays element-wise and stops if the sum at a certain index is greater strictly than 1. This function is called lot of times (15817145 times for a small simulation and expects to grow a lot more as the simulation size grows). Profiling my code shows that it is among the five most cons... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-12T18:38:28.590",
"Id": "514486",
"Score": "2",
"body": "You have framed this as a question of speed. But you also say the lists have 100 or fewer elements (ie, tiny) and the function is called several times (meaning unclear, but it al... | [
{
"body": "<p>Does it make sense (in the context of your program execution) to split your task into two stages?</p>\n<p>Check for the presence of <code>(1, 1) in zip(lis1, lis2)</code>, and if <code>False</code>, then pass the generator to the array: <code>array('H', (i + j for i, j in zip(lis1, lis2)))</code>.... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-12T17:44:45.610",
"Id": "260663",
"Score": "0",
"Tags": [
"python"
],
"Title": "addition of two list elementwise with abortion if condition satisfied python"
} | 260663 |
<p>-I have a ListView, and its SelectedItem property is bound to EmployeeModel SelectedEmployee in my VM, and it implements the Set method from MVVM Light. (Basically, <code>OnPropertyChanged</code>, but the MVVM Light version.)</p>
<p>-I have three more ListViews (more, but for simplicity's sake, we'll say three.) T... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T05:58:24.940",
"Id": "514516",
"Score": "0",
"body": "Please tag the appropriate language."
}
] | [
{
"body": "<p>Few syntax improvements first:</p>\n<pre class=\"lang-cs prettyprint-override\"><code>private EmployeeModel _selectedEmployee;\npublic EmployeeModel SelectedEmployee\n{\n get => _selectedEmployee;\n set\n {\n if (Set(ref _selectedEmployee, value))\n {\n Messen... | {
"AcceptedAnswerId": "260719",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-12T18:39:19.673",
"Id": "260667",
"Score": "1",
"Tags": [
"c#",
"wpf",
"mvvm",
"databinding"
],
"Title": "Updating Multiple Collections In ViewModel Based On A Single ListVie... | 260667 |
<p>I have a medium sized project that uses a class hierarchy that essentially boils down to:</p>
<pre><code>class Mach
{
public:
virtual ~Mach();
//...
virtual void common_action() =0;
//... A lot of common actions
//...
};
class MachStrato : public Mach
{
public: //...
// ...Implementation o... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-12T19:53:03.390",
"Id": "514491",
"Score": "1",
"body": "This seems like a theoretical exercise. Is this indeed theoretical or is it actually part of an existing project? Please take a look at the [help/on-topic]."
},
{
"Conten... | [
{
"body": "<h1>Design/code review</h1>\n<p>There is nothing to review in the first section… because there’s just no code there. The only comment to make is:</p>\n<pre><code>virtual void common_action() override { /* ... */ }\n</code></pre>\n<p>Use <code>virtual</code> <em><strong>OR</strong></em> <code>override... | {
"AcceptedAnswerId": "260679",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-12T19:23:51.420",
"Id": "260669",
"Score": "0",
"Tags": [
"c++",
"pointers",
"polymorphism",
"object-detection"
],
"Title": "Inquiring possible alternatives to custom hierarc... | 260669 |
<p>As some part of my application needs connection to database I wanted to create tests that use mocks to avoid running special instance of database just for testing. That gave me a glimpse of how can I use mocks and I played with them a bit.</p>
<p>I wanted to test express router:</p>
<pre class="lang-js prettyprint-o... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T05:57:46.100",
"Id": "514515",
"Score": "0",
"body": "Please follow out guidelines: https://codereview.stackexchange.com/help/how-to-ask"
}
] | [
{
"body": "<p>As long as the real implementation that is being mocked here is also unit tested. And the mock is configured to match the expected behavior of the real implementation. You should be fine.</p>\n<p>However you gotta remember to change all mock configuration when expectations of the real implementati... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-12T19:36:31.280",
"Id": "260670",
"Score": "0",
"Tags": [
"unit-testing",
"typescript"
],
"Title": "Unit test using mocks"
} | 260670 |
<p>I have a use case where I try to initialize a <code>Player</code> object within a <code>try</code> block.
The relevant excerpt of the <a href="https://github.com/Programmieren-2/battleship/blob/37f99fd1b3e97886e5a3351205d37d802c48b35c/src/proto/GameServer.cpp#L100" rel="nofollow noreferrer">current, working code</a>... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-12T20:30:29.300",
"Id": "514492",
"Score": "3",
"body": "This seems like a good use case for [std::optional](https://en.cppreference.com/w/cpp/utility/optional)."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-12T20:20:02.250",
"Id": "260672",
"Score": "1",
"Tags": [
"c++",
"error-handling",
"c++17",
"raii",
"scope"
],
"Title": "Access object initialized within try block afterwards... | 260672 |
<p>Made a console game in C++ called "Epic dungeon", which my friend did a year ago in JS. I decided to do it in order to gain experience (in fact, I did it because I would have stopped learning C++ if I hadn't done something, because studying for so long and not doing anything can quickly get boring) I did i... | [] | [
{
"body": "<p>Only a superficial review for now:</p>\n<ul>\n<li>If you really want to learn C++, you should start with OOP included. Whereas C++ is technically a multi-paradigm language, most of the reason to use C++ over C is for its OOP.</li>\n<li>Conversely, if you don't actually care about OOP, this should ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-12T20:42:07.020",
"Id": "260673",
"Score": "1",
"Tags": [
"c++",
"beginner",
"game"
],
"Title": "Console Game \"Epic Dungeon\""
} | 260673 |
<p>I had a piece of code that solved really simple problem - it formated two dates to look better on a webpage. It looked like this:</p>
<pre><code>function formatDateRange(
days: { firstDay: string, lastDay: string }
): string {
let first, last;
first = dayjs(days.firstDay); //dayjs parses string that formatte... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T00:43:23.510",
"Id": "514502",
"Score": "0",
"body": "I think it's a neat solution, it can be modular if `callable`, `pipe` and `apply` are candidates to be called in other tasks. However in fact it's more code than what you had pre... | [
{
"body": "<p>I personally prefer the first one, but this is very subjective. From a person reading the code for the first time, I can skim over the first version and have a good general idea of what the code is about. For the second version, I see a bunch of abstract functions and it takes me longer to see wha... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-12T20:50:36.237",
"Id": "260674",
"Score": "1",
"Tags": [
"functional-programming",
"typescript"
],
"Title": "Format multiple dates to look good in text, using functional approach"
} | 260674 |
<p>This question is a follow up of <a href="https://codereview.stackexchange.com/questions/260335/header-only-bigint-library-written-in-c20/">Header only bigint library written in c++20</a>.</p>
<p>I've made all (or almost all) the corrections suggested in the answers, plus some minor change here and there and a modifi... | [] | [
{
"body": "<p>I tried this code with a simple <code>main()</code>:</p>\n<pre><code>#include <iostream>\nint main()\n{\n bigint a(1'048'576);\n bigint b = a*a*a*a;\n std::cout\n << b/a/a/a\n << '\\n';\n}\n</code></pre>\n<p>This allocated 47,580 bytes more than <code>std::... | {
"AcceptedAnswerId": "260698",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-12T21:59:14.830",
"Id": "260678",
"Score": "1",
"Tags": [
"c++",
"beginner",
"c++20",
"bigint"
],
"Title": "(FOLLOW-UP) Header-only bigint library written in c++20"
} | 260678 |
<p>How are you doing? I have to make a script to parse an xml input file to a json file. I tried to do my best, but it will be nice if you could check it and help me to improve it. The idea is that I don't have use objectify of libraries that converts files directly. I have to write this scritps with at least this prop... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T03:16:02.433",
"Id": "514505",
"Score": "1",
"body": "Can you show an excerpt of the XML you're parsing?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T03:31:52.670",
"Id": "514508",
"Score":... | [
{
"body": "<p>There's a lot going on here, and the problem is very ill-specified. I understand that you've been asked to do this (where's the original problem description?) for a job application, so maybe they've left a bunch open to interpretation, but anyway:</p>\n<p>Usual claims floating around on the intern... | {
"AcceptedAnswerId": "260725",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T02:18:25.327",
"Id": "260686",
"Score": "3",
"Tags": [
"python",
"interview-questions",
"json",
"xml"
],
"Title": "Python script to parse XML file into Json"
} | 260686 |
<p>This is my first post here. I seek to improve my way of writing Python and C++ code. I hope I can also contribute to others when I have increased my skill.</p>
<p>Here is a python function I have for a neural network I have implemented. I feel it become a bit cumbersome. The intention is to weight positive labels in... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T12:47:11.243",
"Id": "514607",
"Score": "0",
"body": "The code does not compile since it is missing the `import` statements. Here at Code Review we prefer self-contained compilable code snippets that allow us reviewers to run the co... | [
{
"body": "<p>It looks like you need to calculate the same thing over and over again. Instead of doing this separately for the positive, the negative and all labels (not sure that is the correct word), you could do it once and then use that once you need to calculate the sums:</p>\n<pre><code>def loss_function(... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T07:33:20.150",
"Id": "260693",
"Score": "2",
"Tags": [
"python",
"neural-network",
"pytorch"
],
"Title": "Loss function in python is a bit cumbersome"
} | 260693 |
<p>I have following code:</p>
<pre><code>public class Worker : BackgroundService
{
public Worker()
{
}
protected async override Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
var task1 = Task.Run(() =>
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T08:45:35.287",
"Id": "514527",
"Score": "1",
"body": "Are `MethodOneAsync` and `MethodTwoAsync` CPU-bound or IO-bound?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T08:47:34.833",
"Id": "514528"... | [
{
"body": "<ul>\n<li>Async method out-of-the-box is using multiple threads for continuations. (Everything after <code>await</code> is continuation). Exception of this rule if existing <code>SynchronizationContext</code>. Don't <code>Task.Run</code> asynchronous I/O-bound operation, do it only for synchronous CP... | {
"AcceptedAnswerId": "260716",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T08:20:23.340",
"Id": "260695",
"Score": "1",
"Tags": [
"c#",
"task-parallel-library",
".net-core"
],
"Title": "Execute .NET Core 3.1 background worker tasks simultaneously"
} | 260695 |
<p>I'm trying to implement a sql-like in-memory database.</p>
<p>Here is my code:</p>
<pre class="lang-rust prettyprint-override"><code>#[derive(Debug)]
enum DataPoint {
Int(i32),
Float(f64),
Text(String),
Null,
}
#[derive(Debug)]
struct Table {
name: String,
rows: Vec<Vec<DataPoint>&g... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T08:33:34.063",
"Id": "260697",
"Score": "3",
"Tags": [
"beginner",
"rust"
],
"Title": "Add rows to a table in rust (code may not be safe?)"
} | 260697 |
<p>I've been learning C as my first language and recently I decided to learn how to create Win32 apps written in C. I Quickly realized, though, that my biggest challenge wasn't writing the Win32 app itself, but more how to implement logic and design into the program.</p>
<p>I would therefore really appreciate any feedb... | [] | [
{
"body": "<p>It looks like something from the early 90s! There's a lot to dislike about the "style" including Hungarian notation falling out of favor, but I'll pass on that since this subgenere might have its own unique standards.</p>\n<p>But I would like to point out that your code is very repetiti... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T09:03:40.300",
"Id": "260699",
"Score": "0",
"Tags": [
"beginner",
"c",
"calculator",
"winapi"
],
"Title": "Simple Win32 API Calculator in C"
} | 260699 |
<p>I am a beginner programmer ( just recently picked it up ). I just completed my first ever project, that is creating a Blackjack game in Python. I would like to know your opinions about it and how it can be improved! Thanks in advance. This code is original and I made it myself without any external assistance.</p>
<p... | [] | [
{
"body": "<p>I felt the code was well written! Pretty modular, cleanly written code and very verbose print statements and a well-established interactive gameplay. :D</p>\n<h3>Overall</h3>\n<p>For a longer game, it might be a bit more readable to write the same code but using a Blackjack class or something simi... | {
"AcceptedAnswerId": "261094",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T10:45:48.280",
"Id": "260702",
"Score": "9",
"Tags": [
"python",
"beginner"
],
"Title": "My Blackjack Game in Python"
} | 260702 |
<p>I'm getting started with Python and one of the beginner projects to learn the language was a password generator (one of the dozens already in CodeReview). I have a C# and JS background so I want to make sure I'm doing things the Python way.</p>
<p>Technically the <code>include_punctuation</code> and <code>include_di... | [] | [
{
"body": "<blockquote>\n<p>Is there a cleaner way to "include" symbols and digits, I just appended them to a list.</p>\n</blockquote>\n<p>Cast (rather than wrap) <code>ascii_letters</code> etc. to a set.</p>\n<blockquote>\n<p>Is there anything built-in to exclude one list from another?</p>\n</blockqu... | {
"AcceptedAnswerId": "260707",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T12:52:02.677",
"Id": "260704",
"Score": "6",
"Tags": [
"python"
],
"Title": "Password Generator with injected password model"
} | 260704 |
<p>I'm trying to write code that reads data from a CSV and pushes it to a Salesforce application using the API. My code processes the data in a for loop, but it takes a long time (3 hours) to run the function. What can I do to optimize my code to run faster?</p>
<p>Here's an example of my code which reads Patient Diagn... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T19:12:22.683",
"Id": "514567",
"Score": "0",
"body": "If your code is processing 200k records and it takes 3h to do so, then 99% of that time will be in `BulkUpsert` method. Did you try comment it out and run your code to see the re... | [
{
"body": "<p>In addition to the post by @aepot, I made the following changes which reduced the completion time significantly.</p>\n<p>I used a dictionary instead of a list to query patient Id. Querying a large list of objects in for loop is what really slowed down the processing. Here's what the code looks lik... | {
"AcceptedAnswerId": "260763",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T13:40:37.597",
"Id": "260705",
"Score": "1",
"Tags": [
"c#",
"performance",
"linq"
],
"Title": "Reading data from a CSV and pushing it to a Salesforce application"
} | 260705 |
<p>I created a class in a separate .h and .cpp file with the idea of having an array of 3 monsters with each monster having different stats( name; health; damage). The problem is that the constructor should change the properties but when I try to call them in the main file only the 3rd monster's properties are changed.... | [] | [
{
"body": "<p>Don't write <code>using namespace std;</code>.</p>\n<p>You are passing <code>std::string</code> by value, which copies the string. Generally you want to pass as <code>const std::string&</code>, or better yet <code>std::string_view</code>. (Though in the case of a properly written constructor... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T13:51:05.577",
"Id": "260706",
"Score": "0",
"Tags": [
"c++",
"constructor"
],
"Title": "Made a monster array for a text based game with a class constructor C++"
} | 260706 |
<p>I've watched a <a href="https://youtu.be/MdtYi0vvct0?t=1218" rel="nofollow noreferrer">talk by Fedor Pikus on design patterns</a> held at CppCon 2019. Motivated by this, I wrote my own visitor implementation and some helpers which allow me to create a visitor from a couple of lambdas.</p>
<p>My goal is to reduce the... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T08:55:26.370",
"Id": "514600",
"Score": "0",
"body": "`b->accept(v);`, `virtual void accept(IVisitor& v) const = 0;` should these be `visit` instead of `accept`? And `struct Base()` doesn't make sense?"
},
{
"ContentLicense"... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T15:40:54.827",
"Id": "260714",
"Score": "6",
"Tags": [
"c++",
"lambda",
"visitor-pattern"
],
"Title": "Create 'classical' visitor from lambdas"
} | 260714 |
<p>When one writes c++ code to manipulate LinkedLists, Trees, etc. one creates a tmp pointer that points to the start/root and changes that pointer as one traverses along.</p>
<p>What would be the equivalent way of doing that in smart pointers?</p>
<p>For example, I wrote a Trie code using unique_ptrs to understand how... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T22:36:13.793",
"Id": "514578",
"Score": "4",
"body": "The smart point is there to show ownership. As long as you are not using simple pointers to indicate ownership you are fine. It is totally fine to use simple pointers as you move... | [
{
"body": "<p>The details of <code>TrieNode</code> don't need to be visible outside of <code>Trie</code>, so I recommend making it a private (or protected) member type <code>Trie::Node</code>.</p>\n<hr />\n<p>We don't need to write a constructor, if we initialise the root node with the value we want:</p>\n<pre>... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T21:41:29.967",
"Id": "260722",
"Score": "2",
"Tags": [
"c++",
"c++17",
"pointers"
],
"Title": "Storing a copy of unique_ptr"
} | 260722 |
<p>I was curious on how I could create a random string and have it have a set prefix. Lets say, as an example, 3456. This question is more referring to how I would join two strings together, my prefix and my random string.</p>
<p>To give a more comprehensive exmaple of what i'm looking for, let's say I generate the s... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T04:17:45.267",
"Id": "514591",
"Score": "1",
"body": "Instead of creating a random string separately and then joining it with the prefix. You might want to allocate space for the new string including the prefix. Copy the prefix to t... | [
{
"body": "<p>When you do <code>rand()%n</code> you will get a random number in the range [0, n-1] but the distribution will not be uniform. Some values will be more likely than others. This is more easily illustrated if we drop the number of random bits from 32 to 4, i.e. <code>RAND_MAX=15</code>. And we want ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T04:01:35.577",
"Id": "260726",
"Score": "1",
"Tags": [
"c",
"strings"
],
"Title": "Create a random string with a set prefix"
} | 260726 |
<p>I wrote this code to simply visualise what happens to an image when it gets put through repeated convolutional filters is a CNN.</p>
<p>The code works fine and produces the expected result but the it is also very inefficient.</p>
<p>One thing I can't figure out is when we want to apply convolutional filters to the i... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T07:11:41.097",
"Id": "260728",
"Score": "0",
"Tags": [
"python",
"algorithm",
"matrix"
],
"Title": "Algorithm for efficient creation of submatrices from original matrix"
} | 260728 |
<p>I know this has been done many times before, but this is my existing code taken from a sample I found to async process a list of tasks. I've seen Task.Run in use before in many examples, but I'm assuming that in most cases, the workload will be IO bound and therefore the Task scheduler is not clever enough to know w... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T13:12:58.683",
"Id": "514843",
"Score": "0",
"body": "I've now updated to include the linked semaphore token as previously it was cancelling on the token passed in which is incorrect. It now cancels either from the parent caller or ... | [
{
"body": "<p>First let me share with you my revised version then I will detail the changes what I've made:</p>\n<pre><code>public static async Task ThrottledConcurrenctForeach<T>(\n this IEnumerable<T> toBeProcessedItems, Func<T, Task> asyncOperation,\n int maxDegreeOfConcurrency, Cance... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T09:14:20.883",
"Id": "260729",
"Score": "4",
"Tags": [
"c#",
".net",
"async-await"
],
"Title": "ForEachAsyncSemaphore asynchronously processing tasks but enable fast fail"
} | 260729 |
<p>Related: <a href="https://codereview.stackexchange.com/questions/123275/find-all-distinct-subsets-that-sum-to-a-given-number">Find all distinct subsets that sum to a given number</a></p>
<p>This code is supposed to efficiently generate all subsets of a list such that the subset's values sum to a particular target va... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T13:25:05.793",
"Id": "514609",
"Score": "1",
"body": "This is a [knapsack problem](https://en.wikipedia.org/wiki/Knapsack_problem), one of many variations and similar to the [subset sum problem](https://en.wikipedia.org/wiki/Knapsac... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T09:46:48.927",
"Id": "260730",
"Score": "6",
"Tags": [
"algorithm",
"design-patterns",
"rust"
],
"Title": "Efficiently generate distinct subsets which sum to a particular value"
} | 260730 |
<p>I'm doing a hobby project for fun recently, it's a GitHub webpage using Jekyll.</p>
<p>One of the main component of my site is displaying Chinese characters with their Sino-Vietnamese pronunciation. I use <code><ruby></code> elements to render these texts, for those who don't know, you can read its <a href="ht... | [] | [
{
"body": "<p>Some improvements:</p>\n<ul>\n<li>completely remove the JS function and replace with CSS (thanks to <a href=\"https://stackoverflow.com/a/38877801/10805680\">this SO answer</a>); this greatly reduces loading time</li>\n<li>wrap one <code>ruby</code> for each pair <code>rb</code> & <code>rt</co... | {
"AcceptedAnswerId": "263461",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T10:35:07.070",
"Id": "260732",
"Score": "4",
"Tags": [
"jquery",
"html",
"css"
],
"Title": "HTML <ruby> elements word spacing using jQuery"
} | 260732 |
<p>This playbook aims to verify if a specific file exists in a specific directory and, if not, to create it.
Neither the file nor the directory may exist before the verification.
After the process is finished, I would like to have a statement that ell me that the file exists.
See what I came up with and please give me ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-21T08:43:50.407",
"Id": "528843",
"Score": "0",
"body": "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 the title to simply stat... | [
{
"body": "<p>So the goal of Ansible is, usually, <a href=\"https://en.wikipedia.org/wiki/Idempotence\" rel=\"nofollow noreferrer\">idempotence</a>. That is the whole point and intent with most of the Ansible modules. Ansible also uses declarative yaml, which is a fancy way of saying "describe the end-stat... | {
"AcceptedAnswerId": "268040",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T11:16:55.670",
"Id": "260733",
"Score": "0",
"Tags": [
"ansible"
],
"Title": "Make my ansible play book better"
} | 260733 |
<p>I am trying to solve a set of differential equations in x,y,z, I have made simple kutta 2 code in python before but not with 3 variables. I am not sure if what i have done is an acceptable way to adjust for 3.
Here is what i have so far: (i have not entered the exact solution as i do not know it)</p>
<pre><code>impo... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T14:23:32.227",
"Id": "514613",
"Score": "1",
"body": "Anyway, this will not run: your `velfun` expects four parameters but you only ever pass three."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-15T06:... | [
{
"body": "<p>This is an interesting problem but I'm afraid that my feedback will be somewhat limited:</p>\n<ul>\n<li>Consider vectorizing your <code>velfun</code> to be represented with matrix multiplications</li>\n<li>Your <code>x</code>/<code>y</code>/<code>z</code> should be combined into one matrix</li>\n<... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T11:56:51.200",
"Id": "260734",
"Score": "3",
"Tags": [
"python",
"mathematics"
],
"Title": "Runge Kutta 2 Python ODE fluid flow"
} | 260734 |
<p>My code does a DFS on the given graph and prints all possible paths for a given start and end node. My question is how can this be improved?</p>
<ol>
<li>Can some form of memoization be used here? There are cases where a path from a certain source - destination is already found and will be an intermediate path for a... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-15T10:46:37.457",
"Id": "514659",
"Score": "0",
"body": "Is there any additional details needed?"
}
] | [
{
"body": "<ol>\n<li>I don't think memoization will be useful here. Any correct algorithm is going to be <em>O(n!)</em>, nothing you do can reduce that fundamentally because you still have to <em>output</em> all the paths.<br />\nTrying to cache stuff you already output is just going to make the space-costs wor... | {
"AcceptedAnswerId": "260856",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T13:54:11.470",
"Id": "260737",
"Score": "8",
"Tags": [
"python",
"performance",
"recursion",
"graph",
"memoization"
],
"Title": "Find all paths in a graph"
} | 260737 |
<p>I currently I have this code</p>
<pre><code>if (this.showAllOnlineFriends === false) {
this.showAllOnlineFriends = true;
} else {
this.showAllOnlineFriends = false;
}
</code></pre>
<p>When you press a button, it will toggle a boolean on or off. Is there a more readable way to write this?</p>
| [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T16:25:56.577",
"Id": "514624",
"Score": "3",
"body": "Generally for a good code review it is better to include more code in your question."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-15T04:35:04.877"... | [
{
"body": "<p>Value flipping is traditionally just done with a negation:</p>\n<pre><code>this.showAllOnlineFriends = !this.showAllOnlineFriends\n</code></pre>\n<p>That is a common, good practice way to do it. It is highly recognizable and easy to understand</p>\n",
"comments": [],
"meta_data": {
"... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T14:22:51.820",
"Id": "260738",
"Score": "0",
"Tags": [
"typescript"
],
"Title": "toggle boolean with if statement"
} | 260738 |
<p>Recently I had to do an IKM C++ assessment to qualify for a job. Some of the questions seemed strange to me, so I'll be doing a few posts here to discuss.</p>
<p>The first one is related to use of std::unordered_set. From what I remember it went something like:</p>
<blockquote>
<p>A programmer is using a struct to c... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-24T16:20:48.710",
"Id": "515338",
"Score": "1",
"body": "The questions (how does on reply to the interview question?) seem to have no bearing on what you expect to gain from a **review** of this code. As such, Code Review is not the p... | [
{
"body": "<p>Defining an <code>operator==</code> for your own type <em>is</em> overloading. The overload set includes all the built-in signatures.</p>\n<p>Based on how you worded it, I agree with (1). It is not true that you <em>must</em> define <code>operator==</code> for that struct in order to use it with... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T15:13:22.907",
"Id": "260740",
"Score": "0",
"Tags": [
"c++",
"stl"
],
"Title": "IKM C++ assessment asks about std::unordered_set, part #1"
} | 260740 |
<p>this is my first <code>F#</code> program, very simple concept but took me a few minutes to get it. I'm new to functional programming so I'd appreciate if you could have a look at and comment the code.</p>
<p>Suggest changes or any code smells?</p>
<pre><code>module FSharpFun.PrintSentenceInLines
open System
let pr... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T18:09:53.227",
"Id": "514633",
"Score": "0",
"body": "`Array.iter` instead of `Array.map` is a more appropriate here. Then we can eventually get rid of the last `|> ignore`. Finally and less important, we could inline `printEveryWor... | [
{
"body": "<p>Sometimes the code itself reads just as simply as a name for a function, so you could inline all of this and reduce the urge for the reader to jump up to a function definition to check what exactly a function is doing:</p>\n<pre><code>splitIntoWords\n</code></pre>\n<p>vs</p>\n<pre><code>fun s ->... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T15:16:20.977",
"Id": "260741",
"Score": "3",
"Tags": [
"beginner",
"functional-programming",
"f#"
],
"Title": "Print each word of a sentence in a new line"
} | 260741 |
<p>IntelliJ warns me that I should avoid using return. If <code>sender</code> is empty, the function should not continue parsing the bytes.</p>
<p>The return value of <code>keyType()</code> is an <code>Option</code>.</p>
<p>What is a better way to return Left in case of an error, without using a return statement?</p>
<... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-15T03:51:52.943",
"Id": "514652",
"Score": "1",
"body": "The posted code does not compile. Code posted on Code Review should be complete and, to the best of your knowledge, correct. It should be ready to be evaluated for clarity, style... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T16:06:44.900",
"Id": "260745",
"Score": "0",
"Tags": [
"scala"
],
"Title": "Either without return in Scala"
} | 260745 |
<p>To put it simply, I'm making a hangman game and it works as it is, it correctly outputs what I want it to, and I have no problem with submitting it now. I only wish to make it more efficient, and I doubt it's at max efficiency as it is. So here it is.</p>
<pre><code>"""
This code runs a hangman game f... | [] | [
{
"body": "<p>Welcome to CodeReview! Your general structure is already pretty good and the comments made the code easy to read. Here are some key suggestions and explanations. The full code can be found at the bottom.</p>\n<hr />\n<p><strong>Comments</strong></p>\n<p>Comments should generally not (have to) expl... | {
"AcceptedAnswerId": "260751",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T17:31:00.127",
"Id": "260748",
"Score": "4",
"Tags": [
"python",
"performance",
"game",
"hangman"
],
"Title": "Hangman Game Efficiency"
} | 260748 |
<p>I want to create a COM server to expose scipy to VBA code, as performing integration is kinda difficult and I don't know of any good VBA/COM libraries for this. My objectives are:</p>
<ul>
<li>As portable as possible</li>
<li>Fast</li>
<li>Maintainable</li>
</ul>
<p>Here's the python:</p>
<pre class="lang-py prettyp... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T19:15:54.507",
"Id": "514637",
"Score": "0",
"body": "What problem did you intend to solve with this? Python can do a lot of direct communication with Office software, ignoring VBA altogether."
},
{
"ContentLicense": "CC BY-... | [
{
"body": "<h2>Deferred Imports</h2>\n<p>Why is <code>import win32com.server.register</code> only imported during <code>__main__</code>? It should be inexpensive and clean to just leave it at the top with everything else. I'd also de-namespace <code>from win32com.server.register import UseCommandLine</code> but... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T18:02:07.003",
"Id": "260749",
"Score": "5",
"Tags": [
"python",
"beginner",
"vba",
"com"
],
"Title": "Simple python COM server to expose scipy integration to VBA"
} | 260749 |
<p>This project's goal is to parse through a large file containing data. I parse that data into a list containing a dictionary. I then do calculations based on that data and optionally plot it for visualization purposes. I use the data for simple calculations to the rewards based on their performance. I wrote this so t... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-28T08:12:27.460",
"Id": "515677",
"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>For starter, it seems that the code searches for the relevant index of the current <code>dict</code> object:</p>\n<pre><code>for worker_data in files_workers:\n index = files_workers.index(worker_data)\n</code></pre>\n<p>but:</p>\n<ol>\n<li>you can easily use <a href=\"https://docs.python.org/3... | {
"AcceptedAnswerId": "261308",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T19:23:39.513",
"Id": "260752",
"Score": "0",
"Tags": [
"python",
"performance"
],
"Title": "Optimizing Iteration of List and Dictionaries Python"
} | 260752 |
<p>I am trying to solve Euler project problem 277 using python 3.8. First, I will show my program and than ask specific questions for enhancements.</p>
<p>The problem is a modified version of Collatz sequence. The general rule of the new one is:</p>
<ul>
<li><p><span class="math-container">\$ a_{n+1} = \, \,\, \frac {a... | [] | [
{
"body": "<h2>Creating a list out of a string</h2>\n<pre><code>wordList = []\nfor i in "UDDDUdddDDUDDddDdDddDDUDDdUUDd":\n wordList.append(i)\n</code></pre>\n<p>can be shortened to:</p>\n<pre><code>wordList = list("UDDDUdddDDUDDddDdDddDDUDDdUUDd")\n</code></pre>\n<h2>Algorithm</h2>\n<p>Th... | {
"AcceptedAnswerId": "260794",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T19:36:27.090",
"Id": "260753",
"Score": "5",
"Tags": [
"python",
"collatz-sequence"
],
"Title": "Project Euler Problem #277"
} | 260753 |
<h3>Context</h3>
<p>I have an array of maximum-fixed-size, <code>size</code>, containers of items; these items are either pointers to objects or an index of the same array, (but no loops.) When the current container is full, to add an object, a new container will be created and a contiguous block of some of the items w... | [] | [
{
"body": "<p>so from my understanding, in the move function you want to:</p>\n<ol>\n<li>move a continuous set of bits from bit_map_a to bit_map_b</li>\n<li>set any moved bits in bit_map_a to 1</li>\n<li>set any unwritten bits in bit_map_b to 0</li>\n</ol>\n<p>To clean this up I would break the problem into sma... | {
"AcceptedAnswerId": "266589",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-14T22:28:51.207",
"Id": "260755",
"Score": "3",
"Tags": [
"c",
"unit-testing",
"bitwise",
"bitset"
],
"Title": "Move an unaligned bit-addressed range into another bitmap"
} | 260755 |
<p>Problem Statement:</p>
<p>Write a server (“Application”) in Java that opens a socket and restricts input to at most 5 concurrent clients. Clients will connect to the Application and write any number of 9 digit numbers, and then close the connection. The Application must write a de-duplicated list of these numbers to... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T00:51:59.370",
"Id": "514737",
"Score": "0",
"body": "When does it need to be submitted?"
}
] | [
{
"body": "<p>Thanks for sharing your code. It is a pretty good approach to the problem, so I have just a few point I'd like to mention.</p>\n<h3>"In band signalling"</h3>\n<p>Your code uses a special value from the quantity to signal a special condition. As many other OO languages, java has the <em>E... | {
"AcceptedAnswerId": "261049",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-15T04:06:26.613",
"Id": "260758",
"Score": "2",
"Tags": [
"java",
"multithreading",
"concurrency",
"queue",
"socket"
],
"Title": "Write deduplicated 9-digit numbers from ... | 260758 |
<p>I have written a relatively small <a href="https://msgpack.org/index.html" rel="noreferrer">msgpack</a> implementation in C++, with performance that is not too bad, so I decided to write a NAPI wrapper around it, but the performance is just horrible. I am guessing this is because I'm having to find the type of every... | [] | [
{
"body": "<h2>Profiling:</h2>\n<p>We could use a library like <a href=\"https://github.com/wolfpld/tracy\" rel=\"noreferrer\">Tracy</a> to do the sort of profiling you mention in the question. But it's quicker to ask "what's taking the most time" and get an answer with a profiler like <a href=\"http:... | {
"AcceptedAnswerId": "260768",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-15T05:38:45.543",
"Id": "260759",
"Score": "12",
"Tags": [
"c++",
"c++11",
"node.js",
"c++17",
"c++14"
],
"Title": "Simple NAPI wrapper around self written C++ msgpack, h... | 260759 |
<p>I have come with such a code for checking IP addresses. But would like to know how clean and good it is from 1 to 10. What I care about are readability and simplicity. Please give me any feedback.</p>
<p>Should I go here with unittests?</p>
<pre class="lang-py prettyprint-override"><code>import re
import logging
lo... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-15T13:32:42.860",
"Id": "514666",
"Score": "0",
"body": "Where and how is this going to be used?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T21:02:54.230",
"Id": "514785",
"Score": "0",
"... | [
{
"body": "<h1>When to use <code>is not</code></h1>\n<p>Your usage of <code>is not</code> is incorrect. You want to use <code>==</code> when you're testing <strong>equality</strong>, like when you check if <code>s</code> doesn't equal a <code>'0'</code>. You want to use <code>is not</code> when checking for <st... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-15T09:26:12.993",
"Id": "260761",
"Score": "7",
"Tags": [
"python",
"regex",
"validation"
],
"Title": "readable validation with python regex and simple logic"
} | 260761 |
<p>This is a short Celcius to Fahrenheit conversion calculator that calculates the average of all entries before exiting. This program performs exactly to the required specification.</p>
<p>I have some concern about the cleanliness of the multiple variable declaration and initialization to zero in a single line. I've s... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T16:33:57.467",
"Id": "514856",
"Score": "1",
"body": "The assignment of zero in the declaration of auto variables is unnecessary. This was one of the explicit things Java changed from C because it was a source of many bugs."
}
] | [
{
"body": "<blockquote>\n<p><code>double celciusInputs, fahrenheitInputs = celciusInputs = 0;</code></p>\n</blockquote>\n<p>Variables declared and initialized this way are hard to read. Prefer:</p>\n<pre><code>double celciusInputs = 0;\ndouble fahrenheitInputs = 0;\n</code></pre>\n<hr />\n<blockquote>\n<p><code... | {
"AcceptedAnswerId": "260776",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-15T11:40:27.467",
"Id": "260764",
"Score": "1",
"Tags": [
"java",
"beginner"
],
"Title": "Learning Java: Celcius to Fahrenheit Conversion"
} | 260764 |
<p>I have been asked to implement a HASHMAP in C++ in a job interview (home assignment).</p>
<p>I'm a bit unsure about exception safety, but this is what I came up with:</p>
<h3>Block.h</h3>
<pre><code>#ifndef BLOCK_H
#define BLOCK_H
#include <deque>
#include <map>
#include <mutex>
#include <iostr... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-15T20:28:19.443",
"Id": "514687",
"Score": "0",
"body": "You know `std::map` is normally a balanced (red-black) tree, right? That sounds like overkill for each bucket of a hash table; hash tables normally perform well when they're usa... | [
{
"body": "<ol>\n<li><p>Building-blocks only ever interact directly with the user in two circumstances:</p>\n<ul>\n<li><p>A violation of program invariants is detected and the program must be shut down immediately to avoid further damage.<br />\nNormal output is wrong for that, logging and error-stream resp. er... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-15T11:50:24.933",
"Id": "260765",
"Score": "5",
"Tags": [
"c++",
"reinventing-the-wheel",
"hash-map"
],
"Title": "Hashmap implementation in C++"
} | 260765 |
<p>I have a energy meter which sends the kWh count periodically every few seconds via a serial port.
To store this data I write the counter value and the calculated average power of the last 10s in a influxdb measurment.</p>
<p>To calculate the power i use a loop that compares the current counter value with the one 10s... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-15T13:04:41.160",
"Id": "260769",
"Score": "2",
"Tags": [
"python",
"asynchronous"
],
"Title": "Read Data from a serial port and write to influxdb"
} | 260769 |
<p>I made a function in which 17 players are counting to number N. Function as a parameter takes a number N and returns which player is going to say N. If current number is divisible by 9 the counting order is reversed, and if current number is divisible by 17 the next player is skipped. I made this code, but is a litt... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-15T17:39:52.477",
"Id": "514673",
"Score": "1",
"body": "I have taken the liberty to change the question title (inspired by what I found [here](https://austinwsmith.wordpress.com/2017/04/29/pseudo-code-game/)). Feel free to edit the t... | [
{
"body": "<h3>General remarks</h3>\n<ul>\n<li><p>The computation should be separated from the program output. That increases the clarity of the program, and makes the functions better testable. In your case, <code>func playertold</code> should return the result instead of printing it.</p>\n</li>\n<li><p>Type a... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-15T14:34:59.477",
"Id": "260770",
"Score": "3",
"Tags": [
"swift",
"ios"
],
"Title": "Determine final player in a counting game"
} | 260770 |
<p>I am following some java training where I am asked to write a websocket server which accepts orders to be placed and matched with previous orders.
The matching engine is unit tested separately.
There should be integration tests which check the server accepts messages and send replies.</p>
<p>Below is an example of s... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-15T14:38:03.530",
"Id": "260771",
"Score": "0",
"Tags": [
"java",
"spring",
"websocket",
"integration-testing"
],
"Title": "java integration test wait for websocket message and v... | 260771 |
<p>I wrote this ~100 line script recently, where I tried out Python's <code>asyncio</code> library. When it comes to asynchronous programming in Python, I just have 2 days of experience. I spent the last two days reading about it for the first time.</p>
<p>Based on all my readings and understanding, I think, there is n... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T22:37:14.727",
"Id": "530876",
"Score": "0",
"body": "I don't think there is anything inherently wrong or dangerous with nested `asyncio.gather` calls. However I think this question may be more suited to SO"
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-15T15:53:59.317",
"Id": "260773",
"Score": "1",
"Tags": [
"python",
"asynchronous",
"concurrency",
"async-await"
],
"Title": "Are nested calls to `asyncio.gather()` dangerous?"
} | 260773 |
<p>I <a href="https://codereview.stackexchange.com/questions/83135/designing-a-coffee-machine">saw this post</a> and tried to do my attempt. This is the requirement of task:</p>
<blockquote>
<p>Design a coffee machine which makes different beverages based on set
ingredients. The initialization of the recipes for each d... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T08:17:15.220",
"Id": "514741",
"Score": "1",
"body": "Rainer's answer is correct, you misunderstood the beverage/ingredient separation. It's hard to review this further without rewriting the core logic, which defeats the purpose of ... | [
{
"body": "<p>I think you misunderstood the task.</p>\n<p>In the original task, there was a clear distiction between drinks and ingredients. There was a list of ingredients, each with a name, a price and a stock. There was a separate list of drinks, each consisting of a name and a list of ingredients. Customers... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-15T17:03:50.037",
"Id": "260775",
"Score": "1",
"Tags": [
"c#",
"object-oriented",
"interview-questions",
"simulation",
"inheritance"
],
"Title": "C# Coffee Machine"
} | 260775 |
<p>I am attempting to build an Android APP with the custom serializable class <code>User</code>. The public method <code>Save</code> is to save class instance information and the public method <code>Load</code> is to load saved information from the specified file.</p>
<p><strong>The experimental implementation</strong>... | [] | [
{
"body": "<p>Just a couple of points with your unit tests.</p>\n<h2>Test cases</h2>\n<p>It's unusual to see <code>extends TestCase</code>. This appears to have been the way it worked in JUnit 3, no I'd expect each of your test cases to be annotated with <code>@Test</code>. There's more discussion <a href=\"h... | {
"AcceptedAnswerId": "260785",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-15T21:23:19.897",
"Id": "260782",
"Score": "2",
"Tags": [
"java",
"object-oriented",
"unit-testing",
"android",
"serialization"
],
"Title": "Android app class serializati... | 260782 |
<p>I wrote this code to make a non-blocking manager along with pipeline operations using asyncio, my main concern is to catch received items producer, and when the received operation is complete. I want to return all together and merged if keys matches, however, I have a doubt where should I have to join the data at th... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-15T21:52:56.457",
"Id": "260783",
"Score": "2",
"Tags": [
"python",
"reinventing-the-wheel",
"producer-consumer",
"data-mining"
],
"Title": "producer-consumer Pipeline problem im... | 260783 |
<p>I'm new to C# and I've just created a passwords generator. I'm not sure if my code is following best practices, etc.</p>
<p>The schematic of the program is simple. How many passwords of x length can be created with y characters, that's it. An example, following [a-z0-9], 2 to the power of 36 = 68719476736 generated ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T03:36:11.457",
"Id": "514694",
"Score": "3",
"body": "\"How many passwords of x length can be created with y characters\" is not a password generator. What is it supposed to do? I would be astounded if 13 else ifs and 7 nested for... | [
{
"body": "<h3>Problem Size</h3>\n<p>This is an exponential problem in <code>passwordLength</code>. Your on-screen output and file output is going to take a maximum of 62^7 = 3,521,614,606,208 words, each "New password: " + 7 + "\\n", minimum 22 bytes in UTF-8, that's over 70 TiB. I would ch... | {
"AcceptedAnswerId": "260896",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T01:14:27.970",
"Id": "260787",
"Score": "3",
"Tags": [
"c#"
],
"Title": "Does my passwords generator in C# make sense?"
} | 260787 |
<p>As part of the hiring process (QA position), I received as a homework assignment (which involves independent study) the following task:</p>
<blockquote>
<p>Create a full automation test suite (in Python3), so that when
our developers finish writing the code, we will all be able to immediately test the code.</p>
<p>N... | [] | [
{
"body": "<p><strong>Application.py</strong></p>\n<p>Your mock application has a few problems. There are also some improvements to be made regarding code style and structure.</p>\n<hr />\n<h2>Bugs</h2>\n<p><code>--isSorted</code> and <code>--getAll</code> will currently not work with the spelling specified by ... | {
"AcceptedAnswerId": "260805",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T01:55:01.533",
"Id": "260788",
"Score": "5",
"Tags": [
"python",
"unit-testing"
],
"Title": "Create a full automation test suite using a mock file"
} | 260788 |
<p>My first implementation of merge sort in C++.</p>
<p>I'm looking for any sort of optimization and/or conventional practice tips, such as using the appropriate data types and naming my variables appropriately.</p>
<pre><code>#include <iostream>
void print_array(int[], size_t);
void merge_sort(int[], size_t, s... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T22:11:38.457",
"Id": "514794",
"Score": "0",
"body": "I think you mean it's a merge function written in C, with a `main` that uses C++ just for `cin` and `cout`."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2... | [
{
"body": "<ul>\n<li><p>The single most important advantage of merge sort is its stability. The elements compared equal retain their original order. Your code loses stability. If <code>l[i]</code> compares equal to <code>r[j]</code>, the latter is merged first.</p>\n</li>\n<li><p>Your code assumes closed ranges... | {
"AcceptedAnswerId": "260891",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T03:42:16.903",
"Id": "260791",
"Score": "3",
"Tags": [
"c++",
"sorting",
"reinventing-the-wheel",
"mergesort",
"c++20"
],
"Title": "Trying for an efficient and readabl... | 260791 |
<p>I'm trying to copy data from a worksheet to another worksheet with some modifications made on the fly.
Here are the details of the stuff I'm trying to do:</p>
<ol>
<li><p>Open the file from where I'm going to copy data from (<code>xlsPath</code>) using OpenFileDialog</p>
</li>
<li><p>Check the sheet's cell value V6.... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-19T03:45:27.093",
"Id": "514892",
"Score": "0",
"body": "I have rolled back your last edit. Please do not update the code in your question to incorporate feedback from answers, doing so goes against the Question + Answer style of Code ... | [
{
"body": "<p>It's not a good way to group all things in one method. You should really work with the best practices such as dividing the work into smaller parts, and group all related parts together based on role and responsibility. Then, check wither each group needs a method or class, or which design patter w... | {
"AcceptedAnswerId": "260824",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T06:20:15.850",
"Id": "260796",
"Score": "5",
"Tags": [
"c#",
"excel"
],
"Title": "Can my excel to excel data copy code with some with data manipulation be more efficient?"
} | 260796 |
<p>We have recently migrated from SQL Server 2008 R2 to SQL Server 2017 web edition. I am not a SQL developer but enthuses to learn.</p>
<p>Since many of our scrips are of old SQL format, I am searching for some alternative to leverage new T-SQL formats to help optimize the codes.</p>
<p>Below is one example which I be... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T13:21:54.533",
"Id": "514713",
"Score": "0",
"body": "use of `TOP` should have a `ORDER BY` clause. [Reference](https://docs.microsoft.com/en-us/sql/t-sql/queries/top-transact-sql?view=sql-server-ver15#:~:text=When%20you%20use%20TOP... | [
{
"body": "<p>To start, here is a potential formatting that makes the query less of a tragedy to read:</p>\n<pre class=\"lang-sql prettyprint-override\"><code>SELECT TOP 200\n 'Recoup', ERH_DOC_DATE, ERH_DOCNO, ERH_RECV_FROM, ERD_BLH_ID,\n BLD_CODE, A.ERD_ALLOWED_AMT, A.ERD_PAID_INS_AMT\nFROM TRN_ERA_HEAD... | {
"AcceptedAnswerId": "269306",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T08:35:57.043",
"Id": "260797",
"Score": "2",
"Tags": [
"sql",
"sql-server",
"t-sql"
],
"Title": "Complex reporting query suggestion needed for different approach as per latest... | 260797 |
<p>I've encountered a situation with an if-else clause. Specifically, the positive case has only 1 expression, whereas the negative case is a sequence of statements wrapped in braces. Like this:</p>
<pre><code>if( i >= list->count ) *result = 0; else
{
*result = i * 32 + 31;
while( mask >> (*result ... | [] | [
{
"body": "<p>I would say that the strong argument against the first example is that the <code>else</code> block starts right below the <code>if</code> and can be confused with a <code>then</code> block at first sight.</p>\n<p>It's not about the order of the clauses, but only about formatting.\nThis is has the ... | {
"AcceptedAnswerId": "260799",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T09:11:12.623",
"Id": "260798",
"Score": "0",
"Tags": [
"c",
"formatting"
],
"Title": "Very unorthodox placement of if-else clauses in C for handling special cases"
} | 260798 |
<p>I am new at C programming, so I would appreciate it if you could highlight the problems in my code. My biggest concern is wrong memory allocation.</p>
<p>There are some code snippets, where I repeat my code. Is there another way to get rid of them?</p>
<p>Github repo <a href="https://github.com/ekato993/str/tree/mai... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T11:57:32.273",
"Id": "514706",
"Score": "0",
"body": "If your biggest concern is the memory correctness, it would be very helpful to show the test suite too (presumably you've run that under Valgrind or similar?) - then we'd be abl... | [
{
"body": "<p>I don't see any need for the <em>header</em> to include <code><stdlib.h></code>. It should compile just fine without that, and only the implementation needs to include it.</p>\n<blockquote>\n<pre><code>unsigned int length;\nunsigned int capacity;\n</code></pre>\n</blockquote>\n<p>However, pe... | {
"AcceptedAnswerId": "260803",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T11:27:39.907",
"Id": "260802",
"Score": "6",
"Tags": [
"c"
],
"Title": "String lib in C"
} | 260802 |
<p>The <code>Character</code> class is the base class, which is the superclass of <code>Enemy</code> and <code>Hero</code>.</p>
<p>Here is part of <code>Character.java</code>, the rest of it are just auto generated setters and getters.</p>
<pre><code>public class Character implements java.io.Serializable{
private i... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T14:09:56.197",
"Id": "514720",
"Score": "0",
"body": "I see way too many static methods. Ideally, the only static method in your code should be the main method."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2... | [
{
"body": "<h2>Comments</h2>\n<p>Comments should be reserved for extra information that's not contained in the code, really you're looking for 'why' you are doing something. Unnecessary comments add noise to the code which can be distracting, hiding the important bits of your code. More often than not, commen... | {
"AcceptedAnswerId": "260831",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T13:15:18.380",
"Id": "260806",
"Score": "2",
"Tags": [
"java",
"beginner",
"adventure-game"
],
"Title": "a text-based Role-Playing Game with java"
} | 260806 |
<p>My code generates 9 random characters, grouping them into 3 letter groups from an array of permissible characters in the form:</p>
<pre><code>A4b-c56-7de
</code></pre>
<p>Ie, 9 upper and lower letters/numbers, separated in groups of 3 with a '-' in between. However, since I need this for other generic stuff later on... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T19:39:07.740",
"Id": "514779",
"Score": "0",
"body": "Yes, it's ok to use .map() twice in a row - there are many instances where it can greatly improve readability to do so. Some people might hesitate because of performance, but it ... | [
{
"body": "<h2>Functions</h2>\n<p>Programmers are lazy. So much so that most of what makes a modern language is all about doing more with less effort.</p>\n<p>The important concept to understand is the use of functions.</p>\n<ul>\n<li>Functions let you break complex problems into smaller manageable parts.</li>\... | {
"AcceptedAnswerId": "260819",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T13:22:28.883",
"Id": "260807",
"Score": "1",
"Tags": [
"javascript"
],
"Title": "Using Chained Array Functions to Generate A '-' Separated Random Alpha-Numeric Code"
} | 260807 |
<p>I'm having trouble on a question from Hackerrank, this solution works for smaller lists but seems to collapse when the list grows to 200,000 where I get the error "Wrong Solution". <a href="https://www.hackerrank.com/challenges/fraudulent-activity-notifications/problem" rel="nofollow noreferrer">The proble... | [] | [
{
"body": "<p>Yes, deciding for each day in isolation is easy enough. And produces reusable and well-defined abstractions.</p>\n<p>Unfortunately, it costs you. Specifically, it needs too long. Use a running-total, thus each day needs only subtracting one trailing day, adding the last day, and comparing to that ... | {
"AcceptedAnswerId": "260851",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T15:37:20.777",
"Id": "260811",
"Score": "1",
"Tags": [
"c++",
"programming-challenge"
],
"Title": "Hackerrank: Fraudulent Activity Notifications"
} | 260811 |
<p>This is the task:</p>
<pre><code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid') # Plot style
# Some 'magic' so that the notebook will reload external python modules;
# see
# http://stackoverflow.com/questions/1907993/autoreload-of-modules-in-ipython
%load_e... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T17:05:24.303",
"Id": "260813",
"Score": "0",
"Tags": [
"python",
"python-3.x",
"numpy",
"pandas",
"data-visualization"
],
"Title": "Plotting 2 types of data from DataFrame... | 260813 |
<p>I want to share and get some feedback on a simple advertisement blocking program I wrote for my school project, named <a href="https://github.com/karlvfx/stopads" rel="nofollow noreferrer">StopADS!</a>. The main idea of this code is to remove advertisements from websites to make the web browsing experience smoother.... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T20:41:10.067",
"Id": "514732",
"Score": "1",
"body": "Welcome to the Code Review Community. While we can use code repositories as references, any code that you want reviewed must be embedded in the question, so the only thing we can... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T17:22:33.583",
"Id": "260814",
"Score": "0",
"Tags": [
"javascript"
],
"Title": "Simple advertisement blocker I did for my school project"
} | 260814 |
<p>following code below works fine but feels kind of a mess. Any one has a better way to do this?</p>
<p>I am creating a basic "Enter Pin" to unclick screen on an app. So if the user enters the 1st digit, then ellipse1 should be filled. And if the user enters the 2nd digit, then ellipse1 and ellipse2 should b... | [] | [
{
"body": "<p>you could change the helper method to use <code>switch</code> if you're using C# 7.0 or higher then you can do this :</p>\n<pre><code>switch(PinNumber)\n{\n case 1 when valueList.Count == 0: \n case 2 when valueList.Count == 0 || valueList.Count == 1:\n case 3 when valueList.Cou... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T17:54:06.310",
"Id": "260816",
"Score": "1",
"Tags": [
"c#",
"algorithm",
"object-oriented",
"mvvm",
"xamarin"
],
"Title": "checking is ellipse is filled or not"
} | 260816 |
<p>Is this code clean and optimized? When taking memory snapshots, it seems a bit high.
Anything I have done wrong or can do to optimize it?</p>
<pre><code>#pragma once
#include <iostream>
#include <windows.h>
#include <sstream>
#include <Psapi.h>
// Author: https://github.com/TheRacc2
// Other... | [] | [
{
"body": "<h1>Make <code>bytes_to_size()</code> reentrant</h1>\n<p>Since <code>bytes_to_size</code> returns a pointer to a static buffer, it is not <a href=\"https://en.wikipedia.org/wiki/Reentrancy_(computing)\" rel=\"nofollow noreferrer\">reentrant</a>. This will be a problem if you have multiple threads thr... | {
"AcceptedAnswerId": "260865",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T21:14:12.603",
"Id": "260821",
"Score": "3",
"Tags": [
"c++",
"error-handling",
"c++17",
"windows"
],
"Title": "Custom Error Handler Library in C++"
} | 260821 |
<pre><code># get rank which takes the users rank as an argument and determines
# if it is valid input
def getRank(x):
# make a list of the acceptable choices
choices = ['l','m','h']
# convert the users rank to lowercase
x = x.lower()
# create a while True loop that only runs if x is not in the choi... | [] | [
{
"body": "<p>Your <code>getRank</code> function could use a little flexibility. If the user inputs <code>low</code>, their input is rejected as incorrect. To solve this you can take the first character of the string passed. Since you index the string at 0, input like <code>l</code> will still work.</p>\n<p>You... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T22:17:50.443",
"Id": "260823",
"Score": "3",
"Tags": [
"python"
],
"Title": "This program asks users to rank an item and validates the rank"
} | 260823 |
<pre><code>char* join(char** strings, size_t num_strings, char* seperator)
{
int cache = 0;
int count = 0;
for(int i = 0; i < num_strings; i++){
cache += strlen(strings[i]);
}
char * joined = malloc((cache + num_strings * strlen(seperator) + 1) * sizeof(char));
for(int j = 0; j < n... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T23:00:32.383",
"Id": "514733",
"Score": "2",
"body": "Are you purposely avoiding `strcat` and `memcpy`?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T23:06:08.827",
"Id": "514734",
"Score": ... | [
{
"body": "<blockquote>\n<pre><code>char* join(char** strings, size_t num_strings, char* seperator)\n</code></pre>\n</blockquote>\n<p>The inputs can be <code>const</code> as they should not be modified by this function: <code>const char* join(const char** strings, size_t num_strings, const char* seperator)</cod... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T22:31:01.390",
"Id": "260825",
"Score": "2",
"Tags": [
"beginner",
"c"
],
"Title": "String join function C"
} | 260825 |
<p>Recently, I made this gif opener using tkinter:</p>
<pre><code>import tkinter as tk
from tkinter import filedialog as fd
import time
import threading
def getfile():
file = fd.askopenfilename()
window = tk.Toplevel()
def run_gif():
i = 0
while True:
try:
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T16:39:06.650",
"Id": "514767",
"Score": "0",
"body": "Why is there a `sleep()`?"
}
] | [
{
"body": "<p>Your problem may be similar to this one:</p>\n<p><a href=\"https://stackoverflow.com/questions/50904093/gif-animation-in-tkinter-with-pill-flickering-on-every-other-frame\">https://stackoverflow.com/questions/50904093/gif-animation-in-tkinter-with-pill-flickering-on-every-other-frame</a></p>\n<p>I... | {
"AcceptedAnswerId": "260918",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-16T22:52:59.167",
"Id": "260826",
"Score": "2",
"Tags": [
"python",
"performance",
"tkinter"
],
"Title": "Is there any way to stop the lag in this Gif opener?"
} | 260826 |
<p>Given any series of numbers, for example 1,2,3,4,5 and given the arithmetic operands + - * / including parenthesis, what would be the most optimal way to build a tree that contains all permutations and all expressions for these numbers and operators? It doesn't have to be in a specific programming language like Java... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T05:46:11.337",
"Id": "514738",
"Score": "0",
"body": "Is your goal to find the expression that produces the result or is it to build the tree and then search it? Building a complete in-memory tree for this sole purpose seems unoptim... | [
{
"body": "<p>Using infix expressions makes the code very complicated. If you were using postfix (commonly known as <a href=\"https://en.wikipedia.org/wiki/Reverse_Polish_notation\" rel=\"nofollow noreferrer\">RPN</a>) you could calculate each permutation for the operands and for each permutation, calculate eve... | {
"AcceptedAnswerId": "260837",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T01:50:16.393",
"Id": "260832",
"Score": "3",
"Tags": [
"java",
"algorithm",
"tree",
"combinatorics"
],
"Title": "Building a tree containing all permutations of arithmetic ... | 260832 |
<h2>Link to revised (ver 2) question</h2>
<p>This question contains the first version of the code for the task
explained below. The revised version is at <a href="https://codereview.stackexchange.com/questions/260882/c-exception-class-for-error-reporting-compatible-with-c98-through-c20-ve">C++ exception class for erro... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T07:59:27.330",
"Id": "514740",
"Score": "2",
"body": "Welcome to Code Review! We need to know *what the code is intended to achieve*. To help reviewers give you better answers, please add sufficient context to your question, includi... | [
{
"body": "<ul>\n<li><p>The <code>std::string</code> constructor and copy-constructor can throw, so we can't mark the <code>MyError</code> constructor or copy-constructor <code>noexcept</code>. More to the point, we should avoid throwing in these functions - we don't want to throw the wrong exception type at th... | {
"AcceptedAnswerId": "260844",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T04:51:57.923",
"Id": "260835",
"Score": "8",
"Tags": [
"c++",
"exception",
"c++20",
"portability",
"c++98"
],
"Title": "What should a C++ error reporting exception cla... | 260835 |
<p>Was given a take-home test as part of a job interview, which I failed due to a supposed lack of tests, logging, error handling and packaging. But I did touch upon all of these.. suggested time spent was only 2 hours. The task was to create a command line tool in Python that integrates with a trading API.</p>
<p>Not ... | [] | [
{
"body": "<p>One way to improve the structure would be to modularize your code. Once your client is a "real" module, you can convert your <code>main.py</code> into a <code>__main__.py</code> which offers some advantages when it comes to execution convenience.</p>\n<p>Why have an <code>AbstractAPICli... | {
"AcceptedAnswerId": "260859",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T06:14:36.677",
"Id": "260839",
"Score": "3",
"Tags": [
"python",
"python-3.x",
"interview-questions",
"console",
"client"
],
"Title": "Simple command line API client f... | 260839 |
<p>I have been learning Python/Flask for the past 5 months outside of full time work and have just finished a first complete version of an app:</p>
<ul>
<li>Working site: <a href="https://rubiks-cube-solver.herokuapp.com/" rel="nofollow noreferrer">https://rubiks-cube-solver.herokuapp.com/</a></li>
<li>Github link: <a ... | [] | [
{
"body": "<p>You should put your <code>Configure Memcache</code> section into a function to clean up the global namespace, even if you unconditionally call it from the global namespace.</p>\n<p>Likewise, instead of commenting out</p>\n<pre><code># TEMPORARY FOR FLASK LOCAL TESTING ONLY.\n# Configure session to... | {
"AcceptedAnswerId": "260863",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T06:40:04.067",
"Id": "260840",
"Score": "4",
"Tags": [
"python",
"html",
"css",
"flask",
"bootstrap-4"
],
"Title": "Python Rubiks cube solver - general code comments"
... | 260840 |
<blockquote>
<ol>
<li>Write a <code>Greeter</code> class with <code>greet</code> function that receives a <code>name</code> as input and outputs <code>Hello <name></code>. The signature of <code>greet</code> should not change throughout the kata. You are allowed to construct <code>Greeter</code> object as you ple... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T09:15:00.763",
"Id": "514742",
"Score": "2",
"body": "I’m voting to close this question because the code to review is hosted somewhere else.\nPlease take the [tour](/tour), have a look around, and read through the [help center](/hel... | [
{
"body": "<p>In the original code you call <code>timeProvider.provide()</code> several times resulting in (slightly) different times in a case where you should be comparing the same time each time. While this may not be problematic in this specific case, it could lead to very difficult to track bugs.</p>\n<hr ... | {
"AcceptedAnswerId": "260864",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T08:33:58.893",
"Id": "260841",
"Score": "5",
"Tags": [
"java",
"programming-challenge",
"comparative-review"
],
"Title": "Spliting Greeter class to multiple small classes"
} | 260841 |
<p>I'm trying to implement authentication with "Remember me" option using Spring and Kotlin. I would really appriciate if someone could help me find potential issues with that implementation as well as improvements to the code.</p>
<p>Let's start with sign in API. It accepts 3 parameters, <code>email: String<... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T14:12:21.197",
"Id": "514761",
"Score": "1",
"body": "Can you confirm that the code is complete and that it functions correctly? If so, I recommend that you [edit] to add a summary of the testing (ideally as reproducible unit-test c... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T09:33:59.660",
"Id": "260843",
"Score": "1",
"Tags": [
"authentication",
"kotlin",
"spring",
"jwt"
],
"Title": "Signing in with \"Remember me\" option implemented with Spring ... | 260843 |
<p>I am new to using PHP OOP and decided to start learning by converting something I wrote in procedural PHP. So now I need your opinion and recommendations for my first work.</p>
<p>One of the main reasons I chose this project, is that it has a lot of repetitive SQL queries, with small differences (like a date interva... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T13:08:17.220",
"Id": "514755",
"Score": "4",
"body": "The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to **simply sta... | [
{
"body": "<p>I'll focus on <code>SalesRepresentatives</code> class, because that seems to be your main concern.</p>\n<h1>Documentation</h1>\n<p>There is none. Note that "Get TargetLevel" for a function named <code>getTargetLevel()</code> doesn't add anything.</p>\n<h1>Getter/Setter Asymmetry</h1>\n<p... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T10:37:55.640",
"Id": "260845",
"Score": "3",
"Tags": [
"beginner",
"php",
"object-oriented",
"sql"
],
"Title": "New in PHP OOP and need opinion am I doing it the right way"
} | 260845 |
<p>This function should take in a string and a number as parameters and 'rotate' the string to the equivalent alphabet letter that is located at the letter position + 'rotation' parameter.</p>
<p>E.g.: <code>"stackoverflow" --- "fgnpxbiresybj"</code></p>
<pre><code>def caesar(inputString, rotation =... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-19T06:57:40.497",
"Id": "514901",
"Score": "1",
"body": "Not really a programming issue, but Ceasar's Cipher has the property that when it is applied twice, you get the original results back. In other words, the rotation is always 13 a... | [
{
"body": "<p>I don't think the code is right to transform all characters this way. I think the transform we have should be restricted to lower-case letters, and we should have a similar one (wrapping at <code>'Z'</code>) for upper-case letters.</p>\n<p>I guess this shows a shortage of test cases containing up... | {
"AcceptedAnswerId": "260870",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T10:40:08.230",
"Id": "260846",
"Score": "8",
"Tags": [
"python",
"caesar-cipher"
],
"Title": "Caesar cipher using ASCII character codes"
} | 260846 |
<p>This is a follow-up question for <a href="https://codereview.stackexchange.com/q/260782/231235">Android app class serialization</a>. Some problems have been mentioned in <a href="https://codereview.stackexchange.com/a/260785/231235">forsvarir's answer</a>. Then, I am following <a href="https://junit.org/junit5/docs/... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T22:21:41.883",
"Id": "514799",
"Score": "0",
"body": "I've voted to close this question at the moment, because your unit tests really don't look like they work. All of them seem to be expecting a `NoSuchAlgorithmException` to be th... | [
{
"body": "<h2>Unittests are (executable) documentation</h2>\n<h3>The name of a test method should read like a sentence from the requirements.</h3>\n<p>Beginners should stick with the pattern suggested by <a href=\"https://www.amazon.de/Art-Unit-Testing-Roy-Osherove/dp/1617290890\" rel=\"nofollow noreferrer\">R... | {
"AcceptedAnswerId": "260866",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T16:38:12.120",
"Id": "260860",
"Score": "0",
"Tags": [
"java",
"object-oriented",
"unit-testing",
"android",
"classes"
],
"Title": "Unit tests for User class with JUni... | 260860 |
<p>I'm rather new to front-end & jquery selector. While what I am doing works, I'm unsure it's necessarily robust. FYI, the backend & templates are built on Django. The auto-naming conventions in Django forms (which is what gives the elements here their names) are pretty stable. However some of that naming (for... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T16:56:48.703",
"Id": "260861",
"Score": "0",
"Tags": [
"jquery",
"html",
"django"
],
"Title": "Jquery selector - robustness of the syntax"
} | 260861 |
<p>I have been learning python since being in lockdown, this is the first Tkinter application I've built without consulting the internet or seeking help anywhere.</p>
<p>It is a time converter where you can select the input unit via a checkbox and the other entry windows will fill with the correct conversion.</p>
<p>I'... | [] | [
{
"body": "<p>One issue I can see on first glance is the <code>*</code>. It's considered bad practice to import everything like that, and here is why from <a href=\"https://stackoverflow.com/q/2386714/13552470\">this</a> Stack Overflow post:</p>\n<blockquote>\n<ul>\n<li>Because it puts a lot of stuff into your ... | {
"AcceptedAnswerId": "260910",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T17:42:38.407",
"Id": "260862",
"Score": "1",
"Tags": [
"python",
"tkinter",
"gui",
"unit-conversion"
],
"Title": "Time Converter - Python Tkinter - General comments on cod... | 260862 |
<p>I wrote a function to return the first <strong>n</strong> length sequence which occurs twice in the digits of pi. Along with the repeated sequence, I want the indices of the first and second occurrences. For example, if <strong>n</strong> is <code>1</code>, code returns <code>(1, 0, 2)</code> and if <strong>n</stron... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-19T02:25:32.483",
"Id": "514889",
"Score": "3",
"body": "If you expect to call `repeat` many times, it might be worth building a `suffix tree` once, and the running the queries on the tree. A suffix tree can also let you answer similar... | [
{
"body": "<blockquote>\n<p>How do I make it simpler and faster?</p>\n</blockquote>\n<p>A more efficient approach:</p>\n<ul>\n<li>Iterate on <code>pi</code> with a sliding window of size <code>n</code>.</li>\n<li>Save each sequence (and the starting position) in a lookup map</li>\n<li>Return as soon as you find... | {
"AcceptedAnswerId": "260879",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T20:20:02.397",
"Id": "260869",
"Score": "7",
"Tags": [
"python",
"performance",
"algorithm",
"breadth-first-search"
],
"Title": "Find the first repeating sequence in digit... | 260869 |
<p>EDIT: I turned down the brightness on my monitor using the graphics options for the video card. This solved the issue. How this setting changed is a mystery...</p>
<p>I am leaving this up because googling it leads down some difficult and unhelpful paths.</p>
<p>ORIGINAL:</p>
<p>Google maps has become washed out. I c... | [] | [
{
"body": "<blockquote>\n<p>I am looking for ... entirely different fixes that are better.</p>\n</blockquote>\n<p>Turn the brightness down using your operating system, graphics card software, or monitor.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA ... | {
"AcceptedAnswerId": "260894",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-17T21:45:38.950",
"Id": "260873",
"Score": "3",
"Tags": [
"javascript",
"css",
"user-interface",
"google-maps"
],
"Title": "Make roads contrast with Google Maps"
} | 260873 |
<p>I am brand new to Rust and want to know if there are any convention violations in my code and ways how I can make it more readable:</p>
<pre class="lang-rust prettyprint-override"><code>use std::io;
fn main() {
let mut vec: Vec<i32> = Vec::new();
loop {
println!("Enter any number, 0 to te... | [] | [
{
"body": "<pre class=\"lang-rust prettyprint-override\"><code>io::stdin().read_line(&mut num);\n</code></pre>\n<p>Here you are ignoring the <code>Result</code> from <code>read_line</code>; you should have seen a compiler warning about this. Add <code>.unwrap()</code> or <code>.expect()</code> to check the ... | {
"AcceptedAnswerId": "260899",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T03:58:59.600",
"Id": "260881",
"Score": "6",
"Tags": [
"rust"
],
"Title": "Rust Simple Stats Program"
} | 260881 |
<p>This question contains revised code from the question
<a href="https://codereview.stackexchange.com/questions/260835/what-should-a-c-error-reporting-exception-class-have-to-be-portable-across-lan">What should a C++ error reporting exception class have to be portable across language versions?</a>.
I summarize what is... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T05:07:45.040",
"Id": "260882",
"Score": "1",
"Tags": [
"c++",
"exception",
"c++20",
"portability",
"c++98"
],
"Title": "C++ exception class for error reporting, compatible... | 260882 |
<h3>Code</h3>
<pre><code>insertAt :: a -> [Int] -> [a] -> [a]
insertAt x indices xs = go 0 xs
where
go _ [] = []
go j (y:ys)
| nextIndex `elem` indices = y : x : go (nextIndex + 1) ys
| otherwise = y : go nextIndex ys
where
nextIndex = j + 1
</code></pre>
<h3>Questions</h3>
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T10:47:41.627",
"Id": "514833",
"Score": "1",
"body": "If `indices` list might be large, consider using `Data.Set Int` instead of `[Int]` ."
}
] | [
{
"body": "<p>Is it intended that <code>insertAt 999 [1] [1..10]</code> inserts 999 at index 1, but <code>insertAt 999 [0] [1..10]</code> does nothing. Shouldn't it insert a value at index 0?</p>\n<p>Also, it looks like certain other insertions don't work correctly:</p>\n<pre><code>> insertAt 999 [2,5,6,7] ... | {
"AcceptedAnswerId": "260956",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T05:09:48.930",
"Id": "260883",
"Score": "3",
"Tags": [
"beginner",
"haskell",
"linked-list",
"functional-programming"
],
"Title": "Insert value into multiple locations in ... | 260883 |
<p>I need to validate based on some condition if if failed then I need to return from that block. Please find below code</p>
<pre><code>private String validate() {
String test = validateName();
if (!test.isEmpty()) {
return test;
}
test = validateAddress();
if (!test.isEmpty()) {
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T06:38:24.733",
"Id": "514815",
"Score": "0",
"body": "I would like to downvote your post but unfortunately my reputation points are too low..."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T07:16:49.... | [
{
"body": "<p>What is the result of <code>validate....</code> ? If it is an error message, why whould skip validating the rest? Better to join them in a <code>List</code>.</p>\n<pre><code>List<String> errors = new ArrayList<>();\nString nameError = validateName();\nif (!nameError.isEmpty()) {\n e... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T05:35:11.253",
"Id": "260884",
"Score": "-1",
"Tags": [
"java"
],
"Title": "Removing multiple return from method"
} | 260884 |
<p><strong>Good morning guys!</strong></p>
<p>I've just got done fixing my <a href="https://codereview.stackexchange.com/questions/260641/robot-oop-class-in-python">previous version of this code</a>, and here we are with the "final" version. How would I improve it further?</p>
<p>I wanted to create the board,... | [] | [
{
"body": "<p>Your <code>check_position</code> function could use some more improvements. First, I would rename it to something like <code>game_round</code>. Then I would get rid of dealing with indices and directly deal with the robots, and finally I would make the list of robots a parameter of the function:</... | {
"AcceptedAnswerId": "260890",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T06:48:53.230",
"Id": "260885",
"Score": "3",
"Tags": [
"python",
"object-oriented"
],
"Title": "Robot OOP Class in Python part 2"
} | 260885 |
<p>As part of my recent transition from c# to java i decided to write a small converter implementation to translate DTO objects to entities. I'm fully aware of already existing solutions, especially in spring boot, but decieded to create this class as part of my learning process to write projects in java.</p>
<blockquo... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T14:31:44.643",
"Id": "514847",
"Score": "1",
"body": "Java naming conventions seem to vary, however for `boolean` there's often some combination of `is`, `has`, `can`, either in the field name, or the accessor methods (not necessari... | [
{
"body": "<h2>Boolean</h2>\n<p>As I've said in my comment, naming conventions in Java can vary, however particularly with boolean fields there may not be a direct get/set mapping to the property method names.</p>\n<h2>Mirrors</h2>\n<p>Your converter only really works if your DTO and your Entity have the same f... | {
"AcceptedAnswerId": "260935",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T08:46:07.273",
"Id": "260889",
"Score": "2",
"Tags": [
"java"
],
"Title": "Generic converter for plain java objects"
} | 260889 |
<p>I find myself often use warp reduction in CUDA, then needing to broadcast (share) the scalar result amongst all threads. My question is, what is the idiomatic way to do so with clean expressive code that is also efficient? I wrote this simple template to do so, please review and comment. Or if you know a better w... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T16:35:53.423",
"Id": "514857",
"Score": "0",
"body": "\"Warp reduction\" indicates that there may be only 32 threads. Is that (always) the case, or are there more threads you want to share the result with?"
},
{
"ContentLice... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T11:35:55.120",
"Id": "260892",
"Score": "2",
"Tags": [
"cuda"
],
"Title": "CUDA broadcast function for scalar"
} | 260892 |
<p>I wrote this code that takes the vessel coordinates and checks them against every possible port coordinates. If the distance between the vessel and the port coordinates is within x meters (in this example, it has to be less than 3 km), then add that <em>port</em> and the <em>distance_to_the_port</em> to the data fra... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T13:51:54.583",
"Id": "514845",
"Score": "2",
"body": "_In my real code, I use a different one_ - so show your real code?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T13:53:57.117",
"Id": "51484... | [
{
"body": "<p>You need to drop your use of <code>geopy</code>. So far as I can see it does not support vectorised inverse geodesics. Instead use <code>cartopy</code> which inherently supports this.</p>\n<p>The following example code uses random instead of real data, but with the same size as your real data, and... | {
"AcceptedAnswerId": "260950",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T11:58:31.480",
"Id": "260893",
"Score": "1",
"Tags": [
"python",
"pandas"
],
"Title": "Check if any of the coordinates are within a certain distance using apply in Python pandas w... | 260893 |
<p>What I need to do is to return the prime numbers that are dividers of a some numbers in a list, so if</p>
<pre><code>I = [12, 15] # result = [[2, 12], [3, 27], [5, 15]]
</code></pre>
<p>and this is the code that I used for that:</p>
<pre><code>def sum_for_list(lst):
r = []
for num in lst:
for i in r... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T13:48:38.807",
"Id": "514844",
"Score": "1",
"body": "Welcome to Code Review! The current question title, which states your concerns about the code, is too general to be useful here. Please [edit] to the site standard, which is for ... | [
{
"body": "<p>Here are some suggestions for improving readability of your code. The more readable / easily understandable your code is, the easier it is to properly review regarding performance.</p>\n<hr />\n<p><strong>Naming</strong></p>\n<p>This is probably the most important point regarding your code. More o... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T13:28:07.487",
"Id": "260897",
"Score": "0",
"Tags": [
"python",
"programming-challenge",
"time-limit-exceeded"
],
"Title": "Return the prime numbers that are dividers of a some n... | 260897 |
<p>I am working on a small to-do app with Vue (v 2.x.x). I list 5 todos from jsonplaceholder initially.</p>
<p>I can add more todos, delete them or mark them as done.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-cod... | [] | [
{
"body": "<p>You are doing things in a very procedural way, like how you change TODO-items and then calculate the number of unsolved TODOs. When using Vue, there is a better way to do it, namely using <a href=\"https://vuejs.org/v2/guide/computed.html\" rel=\"nofollow noreferrer\">computed properties</a></p>\n... | {
"AcceptedAnswerId": "260915",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T13:52:21.553",
"Id": "260898",
"Score": "1",
"Tags": [
"javascript",
"vue.js"
],
"Title": "Vue.js todo app"
} | 260898 |
<p>I have installed <a href="https://wiki.geekworm.com/X735" rel="nofollow noreferrer">Geekworm x735</a> on my Raspberry Pi, it uses the script below with an infinite loop to determine if the power button has been pressed. I know there are some Linux utils that watch for file changes (inotifywait, watch, fswatch to nam... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T15:14:05.140",
"Id": "514848",
"Score": "1",
"body": "That's not really a code review question. You could find out how they work by looking at the sources. Shortly: They don't work this way but use Linux-specific notification mechan... | [
{
"body": "<p>Polling like this is a very inefficient mechanism, but for pseudo-files in <code>/sys/</code>, you may find that the usual kernel interfaces as used by <code>inotifywait</code> and the like don't get notified of changes in the same way that they do for real storage-backed files. So it may be that... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T14:54:02.090",
"Id": "260901",
"Score": "0",
"Tags": [
"performance",
"bash",
"linux"
],
"Title": "Watch for file changes in Linux"
} | 260901 |
<p>I have a Python function like so:</p>
<pre><code>def get_values(n: int) -> list:
"""
:param n: the maximum absolute value
:return: sorted list of all the positive and negative permutations up to size n
"""
if n < 0:
return []
if n == 0:
ret... | [] | [
{
"body": "<p>This is how you can do this without appending four times</p>\n<pre><code>def get_values(n: int) -> list:\n """\n :param n: the maximum absolute value\n :return: sorted list of all the positive and negative permutations up to size n\n """\n if n < 0:\n return ... | {
"AcceptedAnswerId": "260912",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T15:06:17.900",
"Id": "260902",
"Score": "9",
"Tags": [
"python"
],
"Title": "Python algorithm to return all two-tuple permutations of numbers up to n"
} | 260902 |
<p>Hey everyone I was redirected here from Stack Overflow for this question.</p>
<p>I am completely new to thread synchronization using condition variables and pthreads in Linux.</p>
<p>Here is the code I wrote and I will explain the main idea behind it :</p>
<pre class="lang-cpp prettyprint-override"><code>#include &l... | [] | [
{
"body": "<p><strong>Use the standard library where possible:</strong></p>\n<p>The standard library exists because it's... standard. It's code that lots of people need to use frequently, and if it didn't exist, people would be stuck implementing at least a subset of it themselves in every program (like you are... | {
"AcceptedAnswerId": "260934",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T15:31:01.457",
"Id": "260903",
"Score": "2",
"Tags": [
"c++",
"multithreading",
"producer-consumer"
],
"Title": "Single Producer - Multiple Consumers in C++11 using Linux Thre... | 260903 |
<p>I stumbled into an idea for creating a simple class that would entirely avoid streaming of any data unless some condition is met. The idea here is that a <code>ConditionalOStream</code> object can be constructed around an instance of a <code>std::ostream *</code> and, optionally, a <code>bool</code> indicating whet... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T16:29:29.970",
"Id": "514854",
"Score": "2",
"body": "A bigger issue is computing the stuff that would be streamed out. `logfile << format_fancy_report(x)` can be expensive just to throw away. So, in general, such things are best ... | [
{
"body": "<h3>Your <code>ConditionalOStream</code> is not a <code>std::ostream</code>:</h3>\n<p>The advantage is that formatting will be completely skipped if it doesn't have a target.<br />\nThe disadvantage is that all functions expecting a <code>std::ostream</code> must be modified to accept this new type.<... | {
"AcceptedAnswerId": "260936",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T15:47:29.643",
"Id": "260906",
"Score": "3",
"Tags": [
"c++",
"c++11",
"stream"
],
"Title": "Conditional Output Streaming in C++"
} | 260906 |
<p>This is a follow-up question for <a href="https://codereview.stackexchange.com/q/260782/231235">Android app class serialization</a>. As <a href="https://codereview.stackexchange.com/a/260785/231235">forsvarir's updated answer</a> mentioned "<em>A <code>static</code> load that returns a new instance of a <code>U... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T16:09:03.850",
"Id": "260909",
"Score": "0",
"Tags": [
"java",
"object-oriented",
"android",
"file",
"serialization"
],
"Title": "Android app class serialization with stat... | 260909 |
<p>I have created simple code in which it takes flat file (txt) and eliminate the noise and error and only return clean rows, i.e. return flat file with the data I am interested in. it works fine but since I am a beginner I am sure my code is not efficient. I would appreciate if you can guide me into making it more pro... | [] | [
{
"body": "<p>Soooo. First, this has nothing to do with Pandas (you included the library but then didn't use it); and your use of Numpy is dubious. I'm going to suggest that you skip Numpy altogether.</p>\n<p>A brief laundry list of things that should change:</p>\n<ul>\n<li>Use lower_snake_case for function and... | {
"AcceptedAnswerId": "260923",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T16:24:50.833",
"Id": "260911",
"Score": "1",
"Tags": [
"python-3.x",
"numpy"
],
"Title": "Python utility to clean noise from flat text files"
} | 260911 |
<p>So I made this script for my calculator, so that I can just write whatever formula I want and the calculator would just ask for the missing pieces to do the calculations.</p>
<p>I made it so that it would be very easy to fill in, I just go to the end of the list, give it a name and the formula. That's it!</p>
<p>The... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-19T00:43:17.683",
"Id": "514881",
"Score": "0",
"body": "The code seems incomplete. `SWIDTH` is not defined. Also, what version of Python are you targeting?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05... | [
{
"body": "<h1>Data structures</h1>\n<p>You’re using the wrong data structure to contain your shapes and formulas. <code>list_shapes</code> is a list of lists, but the first item of every list is different from the other items in the list. Different kinds of things should be stored in the same container.</p>\... | {
"AcceptedAnswerId": "260926",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T17:49:28.027",
"Id": "260916",
"Score": "4",
"Tags": [
"python",
"mathematics",
"math-expression-eval"
],
"Title": "Formula filler and calculator"
} | 260916 |
<p>When starting an ipython repl for my project at work, I pretty much always want it started in the project root, not adjacent to the file for the buffer I'm viewing (this is python and module loading depends on cwd). While I can always start the repl and then <code>%cd /my/project/root</code> that is a pain the 50th ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T19:44:51.693",
"Id": "260919",
"Score": "1",
"Tags": [
"lisp",
"elisp"
],
"Title": "Emacs lisp advice to start ipython repl in the project root"
} | 260919 |
<p>This is a problem based on the game "NGU Industries" in which the objective is to build a factory. Each tile can hold either a production building or a "beacon" which increases the production of buildings near to it in a given offset pattern. In other words, adding a beacon increases the producti... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-19T05:48:23.707",
"Id": "514896",
"Score": "0",
"body": "A beam search is not guaranteed to return an optimal solution unless the beam width is infinite."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-19T0... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T20:12:45.420",
"Id": "260920",
"Score": "3",
"Tags": [
"python",
"breadth-first-search"
],
"Title": "2D Map Optimization via Beam Search in Python"
} | 260920 |
<p>Yesterday I started following the <a href="https://handsonopencl.github.io/" rel="nofollow noreferrer">hands-on OpenCL course</a>. I now got to the point where we are requested to reimplement an approximation algorithm for Pi in OpenCL (in steps, up to a vectorized implementation). I have done so and wanted to get a... | [] | [
{
"body": "<p>Addressing question #2, you can move the parallel sum out of the for loop, and only do it once.</p>\n<p>Use another <code>double16</code> variable (initialized to all zeros), accumulate the sum into it during the loop body. Then, once the loop is done, do the parallel sum to initialize <code>work_... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-18T20:56:40.023",
"Id": "260922",
"Score": "1",
"Tags": [
"opencl"
],
"Title": "OpenCL approximation of Pi using vectorized implementation"
} | 260922 |
<p>Assume a multi-line file (<code>myInput.txt</code>) with lines comprising one or more words.</p>
<pre><code>echo -e "Foo\nFoo bar\nFoo baz\nFoo bar baz\nBar\nBaz\nBaz qux\nBaz qux quux\nQux quux" > myInput.txt
</code></pre>
<p>I wish to remove all one-word lines that are identical with the first word of... | [] | [
{
"body": "<pre class=\"lang-py prettyprint-override\"><code># Get all lines with more than one word\nmore_than_one = list(compress(myList, [len(e.strip().split(" "))>1 for e in myList]))\n</code></pre>\n<ul>\n<li>The function <code>split</code> splits by whitespaces by default, there is no need to... | {
"AcceptedAnswerId": "260928",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-19T00:35:32.167",
"Id": "260924",
"Score": "4",
"Tags": [
"python",
"strings"
],
"Title": "Pythonic way of removing one word entries from compound list"
} | 260924 |
<p>Code</p>
<pre><code>if (source.length > 0) {
if (
source[0].mandatory === true &&
this.allInputs.documentsType !== "mandatory"
) {
item.mandatory = !item.mandatory;
} else if (
source[0].mandatory === false &&
this.allInputs.documentsTy... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-19T15:39:52.630",
"Id": "514936",
"Score": "4",
"body": "I would leave it as is since there are already answers here, but in the future it would benefit reviewers to have a bit more information about the code in the description. From [... | [
{
"body": "<p>I don't know much javascript or typescript. But this seems to be a basic problem.</p>\n<p>So, I will give it a try in phased manner:</p>\n<blockquote>\n<p>Level 1: Clean up, by merging conditions</p>\n</blockquote>\n<pre><code>if (source.length > 0) {\n if ((source[0].mandatory === true &... | {
"AcceptedAnswerId": "260931",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-19T07:57:47.923",
"Id": "260930",
"Score": "3",
"Tags": [
"javascript",
"typescript"
],
"Title": "Assistance requested to refactor a section of Typescript code for readability"
} | 260930 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.