body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>As I was writing, I realized I have multiple classes polling for file descriptors in its own thread - lots of duplicate code like, synchronization, creating array of pollfds etc.</p>
<p>I've decided to remove the duplicate code by writing the following class, which takes care of polling fds in the background. Any th... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-04T08:40:57.203",
"Id": "527830",
"Score": "1",
"body": "@TobySpeight I've updated the question with example usage. Please note I've just written it from top of my head - might not compile."
}
] | [
{
"body": "<h1>Start the thread in the constructor</h1>\n<p>Starting and stopping the thread on demand requires being very careful not to trigger any race conditions. But there is no reason not to have the thread running all the time, if it's just blocked waiting on a command on the sync fd, it doesn't use any ... | {
"AcceptedAnswerId": "267686",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-04T06:55:04.327",
"Id": "267668",
"Score": "2",
"Tags": [
"c++",
"linux"
],
"Title": "Polling FDs in a helper thread, dynamically adding/removing the descriptors"
} | 267668 |
<p>The class in this post returns a directed cycle in a <em><strong>financial loan graph</strong></em>. A financial loan graph consists of nodes and directed arcs. If there is an arc <span class="math-container">\$(u, v)\$</span> with weight <span class="math-container">\$w = w(u, v)\$</span>, then we interpret it as t... | [] | [
{
"body": "<p>Couldn't this class just have static methods and members? You wouldn't need to create an instance every time you want to DFS and you reset the internal sets/maps after each search anyways. I'm not sure about how you plan on using this class later on or if it still works if everything is static, so... | {
"AcceptedAnswerId": "267732",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-04T07:35:11.090",
"Id": "267669",
"Score": "1",
"Tags": [
"java",
"algorithm",
"graph",
"depth-first-search"
],
"Title": "Loan graph simplification in Java: the recursive DFS... | 267669 |
<p>This post presents the loan graph implementation. The class belongs to <a href="https://github.com/coderodde/lgs" rel="nofollow noreferrer">this GitHub repository</a>.</p>
<p><strong><code>net.coderodde.loan.model.Node</code>:</strong></p>
<pre><code>package net.coderodde.loan.model;
import java.util.HashMap;
impor... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-04T08:18:27.863",
"Id": "527829",
"Score": "0",
"body": "(How about an `interface Node` covering \"just the graph side\"?)"
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-04T07:39:57.360",
"Id": "267670",
"Score": "0",
"Tags": [
"java",
"graph"
],
"Title": "Loan graph simplification in Java: the graph data structures"
} | 267670 |
<p>In this post, I will present an interesting (to me) algorithm for reducing the number of arcs in a <a href="https://coderodde.wordpress.com/2015/07/20/minimizing-the-amount-of-bank-transactions-in-a-static-loan-graph/" rel="nofollow noreferrer">financial loan graphs</a>. (The class belongs to <a href="https://github... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-04T07:45:19.740",
"Id": "267671",
"Score": "0",
"Tags": [
"java",
"algorithm",
"graph"
],
"Title": "Loan graph simplification in Java: an arc minimization algorithm"
} | 267671 |
<p>I've started learning Python several months ago. This code uses Google API to send URLs to Googlebot.</p>
<p>I appreciate it if someone can review my code, and advice better practices in classes/method structure, sending requests and logging responses.</p>
<p>How to start the program (<a href="https://github.com/drk... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-04T11:47:19.033",
"Id": "527836",
"Score": "0",
"body": "Welcome to the Code Review Community. The title should be a brief introduction into what the code does rather than your concerns about the code. Please read [How do I ask a good ... | [
{
"body": "<ul>\n<li>Add PEP484 type hints, such as <code>get_domain() -> str</code></li>\n<li>The exception handling here:</li>\n</ul>\n<pre><code> try:\n input(f'Please add OWNER rights in GSC resource to: {key_data["client_email"]} \\nand press Enter')\n\n ex... | {
"AcceptedAnswerId": "268119",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-04T08:54:02.190",
"Id": "267674",
"Score": "1",
"Tags": [
"performance",
"python-3.x",
"google-api"
],
"Title": "Sending requests via Google Indexing API (Python)"
} | 267674 |
<p>I have User entity that has relationship to other entities(Order,Profile)
When I assemble entity from dto and back I need assemble order and profile entity too.</p>
<p>User entity:</p>
<pre><code>@Table(name = "user_info")
@Entity
@Getter
@Setter
public class User implements Serializable {
private stat... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-05T01:19:01.763",
"Id": "527870",
"Score": "0",
"body": "This question actually reads like it should belong to stackoverflow rather than codereview."
}
] | [
{
"body": "<h3>Entity Relationships</h3>\n<p>First you could draw the ER diagram to visualize entity-relations.\nAn UML class-diagram for <code>Order</code> could do, like this:</p>\n<pre><code>,----------------.\n|Order |\n|----------------|\n|customer: User |\n|orderedAt : Date|\n|items: Car[] |... | {
"AcceptedAnswerId": "267706",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-04T09:23:34.153",
"Id": "267675",
"Score": "2",
"Tags": [
"java",
"converting",
"repository",
"hibernate",
"dto"
],
"Title": "Is it good way to user dao when assembling d... | 267675 |
<p>I recently got fascinated by the world of micro controllers, and chose to do a simple clock project to see what is what. First attempt I used .Net nanoframework since I'm a C# coder by day, but I haven't been able to figure out how to make it execute fast enough.</p>
<p>I ported my code to C++ and used PlatformIO to... | [] | [
{
"body": "<h1>Make <code>class QuadDigitDisplay</code> do what it says</h1>\n<p>The <code>QuadDigitDisplay</code> class doesn't actually handle displaying four digits, it only sets the pins that enable each digit. It would be nice if this class actually handled everything necessary to drive the quad digit disp... | {
"AcceptedAnswerId": "267682",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-04T09:56:30.090",
"Id": "267679",
"Score": "4",
"Tags": [
"c++",
"embedded"
],
"Title": "Clock display controlled by esp32"
} | 267679 |
<p>Any sequence of characters starting with a non-whitespace character and ending with any of the following is considered to be a sentence by this program :-</p>
<ol>
<li>a full stop <code>'.'</code> followed by whitespace</li>
<li>an exclamation mark <code>'!'</code> followed by whitespace</li>
<li>a question mark <co... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-05T07:38:48.873",
"Id": "527874",
"Score": "2",
"body": "Be careful when editing your code that you don't invalidate the answers, which breaks the question-and-answer nature of this site. See [What should I do when someone answers my ... | [
{
"body": "<p>There's no need to cast the return value from <code>malloc()</code> family of functions - in C, <code>void*</code> is convertible to any kind of object pointer without a cast.</p>\n<p>The error handling is very primitive - when allocation fails, I'd expect at least some message to <code>stderr</co... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-04T13:08:54.630",
"Id": "267683",
"Score": "1",
"Tags": [
"c"
],
"Title": "Counting and printing sentences and words"
} | 267683 |
<p>I am attempting to make three-dimensional discrete cosine transformation spatial frequency components illustration. The 3D cubes is used to present the level of each coefficient. The more bright the cube, the higher value of its coefficient, and vice versa. The 3D inverse discrete cosine transformation is used here ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-04T15:50:50.437",
"Id": "527843",
"Score": "1",
"body": "In the equation at the top of the post, you probably meant to sum over k, not x. You also have two copies of the `plot3dcube` function. I maybe have time tonight to write a revie... | [
{
"body": "<p>Your DCT computation can be made significantly more efficient, though for these small array sizes it doesn't matter a whole lot. I'll tackle this in the 2nd part of this answer. First I'll discuss some MATLAB syntax and style improvements.</p>\n<blockquote>\n<pre><code>OutputCollection{x, y, z} = ... | {
"AcceptedAnswerId": "267720",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-04T13:58:33.413",
"Id": "267685",
"Score": "3",
"Tags": [
"algorithm",
"image",
"matrix",
"matlab",
"data-visualization"
],
"Title": "Three-dimensional DCT spatial freque... | 267685 |
<p>I have a higher-order function to create another function given a regular expression:</p>
<pre><code>export function createParser<T extends { [k: string]: number }>(
regExp: RegExp
) {
return function (content: string): T {
const matchArray = [...content.matchAll(regExp)];
if (matchArray.length ==... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-04T15:35:05.943",
"Id": "267689",
"Score": "1",
"Tags": [
"functional-programming",
"typescript"
],
"Title": "TypeScript generic higher-order function returned function returned type"
} | 267689 |
<p>I've implemented a custom trait on <code>std::path::Path</code> (and by extension <code>std::path::PathBuf</code>) with a method which turns the struct into a file url and a trait on <code>std::path::PathBuf</code> which constructs a PathBuf from a file url.</p>
<p>Would love some feedback on the code, especially an... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-04T18:16:58.033",
"Id": "267694",
"Score": "1",
"Tags": [
"rust",
"encoding"
],
"Title": "Convert PathBuf to file URL in Rust"
} | 267694 |
<p>Given a vector <code><Vec<usize>></code> of indices indicating where to split a string as follows:</p>
<pre><code>println!("{:?}", idxs);
[2, 1, 6, 2, 5, 2, 2, 1]
</code></pre>
<p>And the following string (The Series column in the <a href="https://download.bls.gov/pub/time.series/jt/jt.txt" rel... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-05T11:42:47.427",
"Id": "527882",
"Score": "0",
"body": "I see you edited the code slightly from the version on SO, but it still [doesn't perform as advertised](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=a8... | [
{
"body": "<p>In Rust, we tend to make use of iterators rather than recursion. Map, filter, reduce, etc. are your friends, especially if you don't like loops. Also, when working with parameters, slices tend to be preferable over Vecs (though returning is usually a concrete collection). Another thing is that we ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-04T18:44:52.730",
"Id": "267696",
"Score": "3",
"Tags": [
"functional-programming",
"rust"
],
"Title": "Split string at given positions"
} | 267696 |
<p>So I am still learning a lot of things and wanted to see if someone wanted to look over my code and tell me if there are ways to improve things and maybe make the code a little cleaner.</p>
<p><strong>Here is what the piece of code does</strong>:</p>
<ol>
<li>When a user scrolls to the middle of the page, it will op... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-05T02:27:05.930",
"Id": "267701",
"Score": "0",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Set cookie once modal opens on page scroll"
} | 267701 |
<p>Please be gentle with me-- I just began learning to code a few weeks ago as a hobby in order to support my other hobby of learning general relativity, so this is the first bit of code I've ever written. I would love to keep getting better at coding, though, so any feedback on ways to improve my code would be much a... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-06T15:03:47.503",
"Id": "527928",
"Score": "0",
"body": "Please replace your output screenshot with a text block."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-06T15:18:31.493",
"Id": "527930",
"S... | [
{
"body": "<ul>\n<li>In general, have your classes on top of the file, and then all the code. Don't have them inbetween.</li>\n<li>In Python, if we know a variable won't change, and we just have it as a reference or only read from it, we call it a constant. By convention, we use all uppercase names for those: <... | {
"AcceptedAnswerId": "267704",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-05T04:43:19.383",
"Id": "267702",
"Score": "5",
"Tags": [
"python",
"sympy",
"latex"
],
"Title": "Calculate general relativity-related tensors/arrays using metric tensor as input... | 267702 |
<p>I finished LeetCode 05 with simplified (for ease of implementation) <a href="https://en.wikipedia.org/wiki/Longest_palindromic_substring#Manacher%27s_algorithm" rel="nofollow noreferrer">Manacher's algorithm</a>. IMHO it should keeps <span class="math-container">\$\mathcal{O}(n)\$</span> time and space complexity. H... | [] | [
{
"body": "<p>At least in the worst case you can get <span class=\"math-container\">\\$\\mathcal{O}(n^2)\\$</span>. For some strings (like 'aaaaaaaaa') any substring is going to be symmetric. That's why <code>symRadius</code> function may take <span class=\"math-container\">\\$\\mathcal{O}(n)\\$</span>. So in w... | {
"AcceptedAnswerId": "267834",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-05T08:00:23.983",
"Id": "267703",
"Score": "0",
"Tags": [
"performance",
"algorithm",
"kotlin"
],
"Title": "LeetCode 05 with Manacher's algorithm"
} | 267703 |
<p>I have a class representing meter readings:</p>
<pre><code>public class MeterReading
{
public double AccountId { get; set; }
public DateTime MeterReadingDateTime { get; set; }
public double MeterReadValue { get; set; }
}
</code></pre>
<p>I also have a collection of <code>MeterReadings... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-05T12:22:46.640",
"Id": "527885",
"Score": "0",
"body": "Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking."
... | [
{
"body": "<p><strong>1. Document your code</strong></p>\n<p>While it seems a bit boring and useless to do now, in 6 months you will read your code again and it will take some time to remember what this class/field/property is used for...</p>\n<p>The minimum would be to document with XML comments all the public... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-05T09:35:47.263",
"Id": "267705",
"Score": "2",
"Tags": [
"c#",
"asp.net",
"classes"
],
"Title": "Parse meter readings from CSV file"
} | 267705 |
<p>Recently I started to learn Rust. I come from a mostly Java background, but spent roughly the last two years in Go. I am working on converting a small microservice that reads data from Kafka and stores data in a map locally. Right now I'm working on the Kafka piece, and while I've got it working it doesn't look like... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T12:21:47.117",
"Id": "527985",
"Score": "0",
"body": "Make your function return (for example) a `Result<(), String>` and use question mark operator. String is easy to use and format to include whatever error data you want to see whe... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-05T17:55:47.123",
"Id": "267711",
"Score": "0",
"Tags": [
"error-handling",
"rust"
],
"Title": "Rust Error Handling - Can this error handling be made cleaner?"
} | 267711 |
<p>I'm playing with the Real mode and was trying to code something when suddenly I exceeded the <code>510</code> boundary (<code>.org 510</code>) of the <code>512</code> boot sector size for BIOS and <code>as</code> warning popped out:</p>
<pre><code>code.s: Assembler messages:
code.s:<line num>: Error: attempt t... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T02:00:43.633",
"Id": "528018",
"Score": "1",
"body": "Funny that you should talk about \"overlapping in memory\", because that's exactly what would happen if you loaded the 2nd sector at `0x7c00` + `0x100`. In other words, you got a... | [
{
"body": "\n<h2>Improvements</h2>\n<ul>\n<li><p>When BIOS starts your bootloader (after it got loaded at linear address 7C00h), the only register that has a defined meaning is the <code>%dl</code> register. It contains the bootdrive code.<br />\nFrom this follows that it is up to you to setup the segment regi... | {
"AcceptedAnswerId": "267776",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-05T18:07:26.237",
"Id": "267712",
"Score": "3",
"Tags": [
"assembly",
"x86"
],
"Title": "GNU assembly (AT&T syntax) bootloader load the next sector from floppy"
} | 267712 |
<p>I obtain strings that contain chat messages, and they sometimes have formatting codes imbedded in them. A formatting code is a <code>§</code> followed by a character, and this character then defines how the code will affect the following text. Colour codes can occur at the very end of the String, a common case of a ... | [] | [
{
"body": "<p>Quite straightforward code, no bells or whistles. Your implementation removes a lone § if it is at the end of the string (e.g. "this gets removed §"). Is it supposed to do that? I would rename <code>newMessage</code> to <code>cleanMessage</code> as the message is not new, just a cleaned ... | {
"AcceptedAnswerId": "267717",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-05T23:16:35.087",
"Id": "267713",
"Score": "3",
"Tags": [
"java"
],
"Title": "Remove Minecraft formatting codes from a String"
} | 267713 |
<p>I'm making a program that can add 2 terms that the user types.</p>
<p>I think I've got identifying or evaluating the terms down. I used classes because I just recently learned it and I also heard it was good practice in order to make your programs shorter. But, when it comes to adding 2 terms together (which is the ... | [] | [
{
"body": "<p><strong>General</strong></p>\n<p>Attributes, variable names, function names and function arguments should be lowercase / <code>snake_case</code>.</p>\n<p>You should wrap your main procedure in a main function, as well as a <code>if __name__ == '__main__'</code> guard. <a href=\"https://stackoverfl... | {
"AcceptedAnswerId": "267722",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-06T02:52:13.250",
"Id": "267715",
"Score": "1",
"Tags": [
"python",
"beginner",
"python-3.x",
"mathematics"
],
"Title": "Ask 2 terms from user and add them"
} | 267715 |
<p>This <a href="https://stackoverflow.com/a/61842546/1068446">StackOverflow answer</a> gives a good suggestion for reproducting the 'after state updates, fire this callback' functionality that the old class component <a href="https://reactjs.org/docs/react-component.html#setstate" rel="nofollow noreferrer">setState fu... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-06T03:15:32.123",
"Id": "267716",
"Score": "0",
"Tags": [
"react.js"
],
"Title": "This custom hook to reproduce the callback functionality of this.setState"
} | 267716 |
<p>The <a href="https://en.wikipedia.org/wiki/Disjoint-set_data_structure" rel="nofollow noreferrer">Wikipedia page on Disjoint-Set data structures</a> presents <span class="math-container">\$4\$</span> distinct algorithms for finding the root node of the tree, and <span class="math-container">\$2\$</span> distinct alg... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-16T08:44:38.093",
"Id": "530694",
"Score": "0",
"body": "Why prefer `abstract class` to `interface` for `[defining] the API`?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-16T17:54:03.830",
"Id": "530... | [
{
"body": "<p>There aren't many best practices on how to package classes, a rule of thumb is to package classes of a module/feature together in a way so that they aren't strongly coupled together. If you were to make a <code>...disjointset.impl</code> and a <code>...disjointset.abstr</code> pack for example, yo... | {
"AcceptedAnswerId": "267784",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-06T04:34:10.783",
"Id": "267718",
"Score": "3",
"Tags": [
"java",
"algorithm",
"comparative-review",
"library"
],
"Title": "Comparing 8 different Disjoint-Set data structure ... | 267718 |
<p>I have recently learned about using PDO. I created a db class which could handle common actions like create, update, delete and select. Is this method a correct way to connect to the database using prepared statements?</p>
<pre><code><?php
class Db {
private $db_host = DB_HOST;
private $db_user = DB_USERNAME;
p... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-06T06:41:26.713",
"Id": "527919",
"Score": "1",
"body": "\"Can Someone just review my code if this method is correct\" Does it produce the correct output? It seems like you did test it. What are your real concerns?"
},
{
"Conte... | [
{
"body": "<h2>Canonical advice from a helpful post</h2>\n<p>As was mentioned in a comment there is a post with helpful advice for classes like this: <a href=\"https://phpdelusions.net/pdo/common_mistakes\" rel=\"nofollow noreferrer\">Your first database wrapper's childhood diseases</a> (written by <a href=\"h... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-06T05:39:52.363",
"Id": "267719",
"Score": "7",
"Tags": [
"php",
"object-oriented",
"mysql",
"database",
"pdo"
],
"Title": "Connect to MYSQL database in PHP with prepared sta... | 267719 |
<p><em>Hi,
I asked this question over <a href="https://stackoverflow.com/q/69044784">on stack overflow</a>. However, they closed the thread and suggested to ask it on code review. So here I am :)</em>
<em>The code below is an updated version of my original code, incorporating suggestions made on stack overflow.</em></p... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T00:22:23.903",
"Id": "527952",
"Score": "2",
"body": "Just to be sure, you are aware that a CSV file structure is a bit more complex than that, and that fields can be quoted, and will be if they contain double quotes, the separator ... | [
{
"body": "<blockquote>\n<pre><code>#define MAX_LINE_WIDTH 100\n</code></pre>\n</blockquote>\n<p>Arbitrary limits such as this are difficult to get right. No matter how large you make it, the real world somehow always manages to find data that exceeds the limit.</p>\n<p>In this case, as we use this limit with ... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-06T10:37:10.783",
"Id": "267725",
"Score": "4",
"Tags": [
"c",
"file-system",
"memory-management"
],
"Title": "CSV file reader"
} | 267725 |
<p>Here is a template class to calculate various CRC checksums.
I go out my way to achieve a good C++ encapsulation for a <a href="https://barrgroup.com/downloads/code-crc-c" rel="noreferrer">C style code </a>.</p>
<p>Any advice or suggestion is welcome.</p>
<pre><code>//crc.hpp
#ifndef __CRC_HEADER_H__
#define __CRC_H... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-06T13:17:16.717",
"Id": "527925",
"Score": "1",
"body": "Do you have the test suite that goes with this? It's probably worth including it the same review, as that helps us understand what testing you've done, and what you've missed. ... | [
{
"body": "<p>Here are some things that may help you improve your code.</p>\n<h2>Understand the nature of templates</h2>\n<p>In modern C++, putting headers in a header file and the implementation in a <code>.cpp</code> file is common and ingrained. However, in this case, it's also not correct. The reason is t... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-06T12:11:48.940",
"Id": "267729",
"Score": "5",
"Tags": [
"c++",
"c++11",
"template",
"checksum"
],
"Title": "C++ template class to calculate CRC"
} | 267729 |
<p>I have this type of table:</p>
<pre class="lang-php prettyprint-override"><code>$this->data = [
0 => [
'reference' => 'ABC123',
'title' => 'lorem',
'parent' => 12,
],
1 => [
'reference' => 'ABC456',
'title' => 'ipsum',
'parent' => 42,
],
2 => [
'ref... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-06T15:35:51.920",
"Id": "527931",
"Score": "0",
"body": "For a given reference, if present multiple times, can it have different titles?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T06:24:26.897",
... | [
{
"body": "<h2>Broad review</h2>\n<p>It seems this code is part of a class method, yet it is difficult to know anything about the method or class other than the fact that it has a <code>data</code> member.</p>\n<p>Consider following <a href=\"https://www.php-fig.org/psr/psr-1/\" rel=\"nofollow noreferrer\">PSR-... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-06T12:26:25.537",
"Id": "267730",
"Score": "1",
"Tags": [
"performance",
"php",
"array"
],
"Title": "PHP Group associative Array duplicates and make subarrays of different values"
} | 267730 |
<p>As the title, I am building a pre-loader for Wordpress that will deliver performance boosts in loading, as well as metrics such as Google Page Speed.</p>
<p>Now, this is something that we do at work, and I could quite easily copy what has been used there but feel it is 'stolen knowledge'. I could be writing anything... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-06T13:33:27.957",
"Id": "267731",
"Score": "0",
"Tags": [
"php",
"wordpress"
],
"Title": "Building a pre-loader for performance gains in Wordpress"
} | 267731 |
<p>Given a rectilinear path, find if it has a loop. A rectilinear path is made up of made up of alternating horizontal and vertical segments.</p>
<p>Input => Ordered set of points representing ra ectilinear path. Points have been sanitised to ensure that they represent alternating horizontal and vertical segments. T... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T11:00:32.337",
"Id": "527980",
"Score": "0",
"body": "*“For loop there must be crossing between horizontal and vertical line segments”* – What about the path (1, 0) -> (3, 0) -> (3, 1) -> (0, 1) -> (0, 0) -> (2, 0) ?"
},
{
"... | [
{
"body": "<p>I'm not going to really talk much about the algorithm for the first part, and more about Python usage.</p>\n<ul>\n<li><code>line_segment</code> needs to be <code>LineSegment</code> by PEP8</li>\n<li><code>__start_point</code> should not be double-underscored, and should not be declared at the stat... | {
"AcceptedAnswerId": "267765",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-06T16:54:38.213",
"Id": "267737",
"Score": "5",
"Tags": [
"python",
"python-3.x",
"algorithm",
"computational-geometry"
],
"Title": "Detect loop in rectilinear path"
} | 267737 |
<p>I am doing a project for a calculator in JavaScript.</p>
<p>Here is the project GitHub page: <a href="https://github.com/florinpop17/app-ideas/blob/master/Projects/1-Beginner/Calculator-App.md" rel="nofollow noreferrer">https://github.com/florinpop17/app-ideas/blob/master/Projects/1-Beginner/Calculator-App.md</a></p... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-06T19:18:22.813",
"Id": "267739",
"Score": "0",
"Tags": [
"javascript",
"html",
"css",
"calculator"
],
"Title": "Calculator with vanilla procedural JavaScript"
} | 267739 |
<p>I am trying to solve the <a href="https://www.hackerrank.com/challenges/climbing-the-leaderboard/problem" rel="nofollow noreferrer">Climbing the leaderboard problem</a> on Hacker Rank. My code passes all the test cases except Test Cases 6 to 9, which I assume are using large data sets.</p>
<p>I'm using binary search... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-06T20:22:03.440",
"Id": "527946",
"Score": "0",
"body": "Welcome to Code Review! Please explain / summarize what the challenge task is, so that the question makes sense even if the link goes dead."
},
{
"ContentLicense": "CC BY... | [
{
"body": "<p>I see three ways to improve your runtime. I have never done this problem so I can't guarantee that it will be enough to pass all the tests.</p>\n<h2>Sorted input</h2>\n<p>The leaderboard scores are sorted in decreasing order. Your duplicate-removal code converts a sorted list to a set to remove du... | {
"AcceptedAnswerId": "267741",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-06T19:28:03.667",
"Id": "267740",
"Score": "0",
"Tags": [
"python",
"python-3.x",
"programming-challenge",
"time-limit-exceeded",
"binary-search"
],
"Title": "Climbing th... | 267740 |
<p>I am just beginning to learn Python, this is my own take on a <a href="https://en.wikipedia.org/wiki/Caesar_cipher" rel="noreferrer">Caesar cipher</a> just looking at Python docs. I would like to know how I could have made it better and how would you rate this. Is it any good?</p>
<pre><code>#caeser cipher
import s... | [] | [
{
"body": "<h1>Alphabet list</h1>\n<p>Alphabet doesn't need to be a <code>list</code>, you can just use the <code>ascii_lowercase</code> string:</p>\n<pre class=\"lang-py prettyprint-override\"><code># just a copy\nalphabet = string.ascii_lowercase\n\n# two copies\nalphabet = string.ascii_lowercase * 2\n\n\n# a... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-06T22:31:38.653",
"Id": "267742",
"Score": "5",
"Tags": [
"python",
"beginner",
"python-3.x",
"caesar-cipher"
],
"Title": "Caesar cipher using Python"
} | 267742 |
<p>I'm getting into backend with postgresql and I would like to know how much of my example would fit for a real website database, just for storing and then displaying it on website.</p>
<pre class="lang-sql prettyprint-override"><code>create table clients (
id BIGSERIAL PRIMARY KEY,
first_name VARCHAR(50) NOT ... | [] | [
{
"body": "<p><code>serial</code> / <code>bigserial</code> are deprecated and you should instead use a <code>generated always as identity</code> <a href=\"https://www.postgresql.org/docs/current/ddl-generated-columns.html\" rel=\"nofollow noreferrer\">clause</a> on an integer-type column.</p>\n<p>It looks like ... | {
"AcceptedAnswerId": "267758",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-06T23:22:41.630",
"Id": "267743",
"Score": "1",
"Tags": [
"sql",
"postgresql"
],
"Title": "Simple website sql database"
} | 267743 |
<p>I wan't to set different type of users in my app, two main types: <strong>Customers</strong> and <strong>Employee</strong>, and the Employee User's have two different role: <strong>Driver</strong> and <strong>Responsable</strong>.<br />
So I extended the <strong>AbstractBaseUser</strong> model to get a Customized Us... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T01:34:40.287",
"Id": "267745",
"Score": "0",
"Tags": [
"python",
"django"
],
"Title": "User's models with different roles"
} | 267745 |
<p>This code was done to allow a user to input, edit, search, delete and print a report of all the products in the company. Is there any way to improve my code?</p>
<pre><code>public class Admin
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String me... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T08:32:44.530",
"Id": "527971",
"Score": "0",
"body": "Uhh... is your company ok with you posting the source of an internal tool online? It seems like a generic tool, nothing too closely business-related, but you still might get in t... | [
{
"body": "<h2>Naming Conventions</h2>\n<p>Methods in Java use <code>lowerCamelCase</code>, as seen in your ReportData class. <code>PascalCase</code> ist only used for classes, so the method names in the Products class should be changed</p>\n<h2>Confusing names</h2>\n<ul>\n<li><code>Products</code> isn't a clas... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T01:43:29.257",
"Id": "267746",
"Score": "0",
"Tags": [
"java",
"object-oriented"
],
"Title": "Inventory maintenance for a company"
} | 267746 |
<p>In the process of migrating an ancient CoffeeScript codebase to TypeScript, I'm <em>also</em> attempting to abandon lodash/underscore.js-alikes in favour of modern JavaScript-standard-library-features (or shims thereof.)</p>
<p>One thing my codebase makes a lot of use of, though, is <code>map()</code> over <em><code... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-24T12:36:10.563",
"Id": "529115",
"Score": "0",
"body": "There are type definitions for lodash available online: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/lodash/common/collection.d.ts"
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T03:33:16.590",
"Id": "267747",
"Score": "0",
"Tags": [
"typescript",
"generics",
"lodash.js"
],
"Title": "Map over an Object's keys/values, returning a new Object, ala Array#map"
... | 267747 |
<p>I have the following algorithm to calculate certain ratios of "work", "low work" and "no work" over a set date range (<code>startDate</code>, <code>endDate</code>). The algorithm works fine, but when I increase the date range it obviously runs slower because it has to loop over every da... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T07:12:36.940",
"Id": "527967",
"Score": "0",
"body": "Could you please share with us the definitions of `WorkTime` and `DateSharedWork`?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T07:54:39.800",
... | [
{
"body": "<p>Just a few quick shots...</p>\n<ul>\n<li><p>Instead of having <code>DateTime check15</code> which leads to the assumption there may be some more <code>DateTime</code> structs laying around like check1...check15 you could just juse <code>currDate</code> which by the way should be renamed to <code>c... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T04:29:56.430",
"Id": "267748",
"Score": "-1",
"Tags": [
"c#",
"performance",
"algorithm"
],
"Title": "Calculate certain ratios of \"work\", \"low work\", and \"no work\" over larg... | 267748 |
<p>I am writing a function that I would use to handle parameters with options for use later in another project.</p>
<p>A sample input would be similar to this:</p>
<pre><code>foo bar --baz con str --w=1920 --h=1080
</code></pre>
<p>From the example above I would expect <code>foo</code> and <code>bar</code> to be not pa... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T06:10:06.477",
"Id": "267749",
"Score": "1",
"Tags": [
"javascript"
],
"Title": "Small JavaScript function that mimics flag handling of the command line"
} | 267749 |
<p><strong><a href="https://www.codewars.com/kata/5765870e190b1472ec0022a2/train/javascript" rel="nofollow noreferrer">Task</a></strong></p>
<blockquote>
<p>You are at position [0, 0] in maze NxN and you can only move in one of the four cardinal directions (i.e. North, East, South, West). Return true if you can reach p... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T17:11:18.997",
"Id": "527998",
"Score": "0",
"body": "`if(userPosition...) { return true } else { ...}` The \"hard return\" makes \"else\" unnecessary. Just let code fall through. That final `return false` - instead: `return result`... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T11:01:02.767",
"Id": "267753",
"Score": "1",
"Tags": [
"javascript",
"performance",
"programming-challenge",
"recursion",
"depth-first-search"
],
"Title": "Codewars: Path ... | 267753 |
<p>We are using Dapper as our ORM and have chosen the repository pattern for organizing our operations. This has worked very well for us but I'd like to confirm that this configuration is capable of sharing and disposing of SQL connections properly.</p>
<p><strong>Startup.cs</strong></p>
<pre><code>services.AddScoped(_... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T05:41:17.543",
"Id": "528024",
"Score": "0",
"body": "I would recommand moving the `Startup` code into an extension or you can put it under a namespace, and use Reflection to get all instances and register them, try to automate thin... | [
{
"body": "<p><strong>Extra boiler plating</strong></p>\n<p>To start with unless there is missing code from <code>DeploymentManagerDbConnection.cs</code> or <code>DbConnection.cs</code> they aren't doing anything interesting or cleaver with the underlying <code>IDbConnction</code> you're wrapping. If anything I... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T13:13:15.657",
"Id": "267755",
"Score": "0",
"Tags": [
"c#",
"dependency-injection",
"asp.net-core"
],
"Title": "Using the repository pattern with Dapper and a single accessor obj... | 267755 |
<p>This function (in a React web application) code takes a random sample of items to test in each test function, for end-to-end testing:</p>
<pre><code>if (randomSample) {
for (const test of selectedTestFunctions) {
let total = getSampleSize(testFunctions.filter(tf => tf.testID === test)[0].itemTypeFilter);
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T16:01:45.673",
"Id": "527991",
"Score": "1",
"body": "Hi. Welcome to Code Review! If there is a warning, then the code does not do what you want (run without warnings in this case). You should make an MCVE and post on Stack Overf... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T13:18:52.277",
"Id": "267756",
"Score": "0",
"Tags": [
"javascript",
"random",
"react.js"
],
"Title": "Random sample items for testing"
} | 267756 |
<h2>Introduction</h2>
<hr />
<p>I've started to learn C programming a bit and wanted to create a simple 2D console game. Let me first introduce you to the game level/map structure:</p>
<pre><code>(1) ################# (2) #################
# # # #
# v S ^#... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T01:27:01.617",
"Id": "528013",
"Score": "0",
"body": "Minor: `strcpy(dst, src); return dst;` rewritable as `return strcpy(dst, src);`."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T14:52:41.077",
... | [
{
"body": "<h1>Answers to your questions</h1>\n<blockquote>\n<p>How can I deal with cleaning up resources in a more concise way? As of now, I'm trying to emulate exception handling by letting errors bubble up to <code>main</code> and doing general cleanup there. I thought about passing around a structure (alloc... | {
"AcceptedAnswerId": "267771",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T14:06:44.917",
"Id": "267757",
"Score": "7",
"Tags": [
"c",
"game",
"error-handling",
"memory-management"
],
"Title": "2D Maze Game with Monsters"
} | 267757 |
<p>Please can you <strong>suggest</strong> a better / <strong>Optimized</strong> logic or code for the question. It has been asked that when you find a zero value in a matrix, make that element the sum of its upper, lower ,left, right value and make the upper, lower ,left, right elements zero. I assume to the matrix pr... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T12:35:21.533",
"Id": "528057",
"Score": "0",
"body": "Can you use libraries other than the standard lib?"
}
] | [
{
"body": "<p><em><strong>Fitting Abstraction</strong></em></p>\n<p>Use spaces please. Let the IDE reformat your code.</p>\n<p>The neighbors' offsets can be elements from {(1, 0), (-1, 0), (0, 1), (0, -1)}.</p>\n<p>For instance:</p>\n<pre><code>private static final int[] UP = {-1, 0};\nprivate static final int[... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T16:25:44.050",
"Id": "267761",
"Score": "4",
"Tags": [
"java",
"matrix"
],
"Title": "Make surrounding elements zero in a matrix, when you find a zero value"
} | 267761 |
<p>I made this small program which takes some inputs (emails) and after looking if they exist it looks for the respective id and delete it. It works (I use it with crontab) but seems redundant. I had several problems with split and decode function, mainly because decode gives me lists of strings spaced by a tab. I w... | [] | [
{
"body": "<p>The <code>listy</code> comprehension could be refactored into a generator:</p>\n<pre class=\"lang-py prettyprint-override\"><code>def search_emails(imap, senders):\n for sender in senders:\n typ, data = imap.search(None, f'FROM {sender}')\n msg_nums = data[0].decode().split()\n ... | {
"AcceptedAnswerId": "267764",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-07T18:29:38.350",
"Id": "267762",
"Score": "1",
"Tags": [
"python"
],
"Title": "Cron email-deleter"
} | 267762 |
<p>I am working on a machine learning problem with object detection. For now, I am trying to find GPS coordinates that are close to other GPS coordinates. If they are close, I want to make note of it by index. So in my example below, with test data, these two areas are not actually close to one another, so their 'close... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T03:21:57.587",
"Id": "528019",
"Score": "0",
"body": "It sounds like this code does not work as expected. Is it a working solution? If not, this might be a bit better for Stack Overflow rather than Code Review"
},
{
"Content... | [
{
"body": "<p>First some general comments</p>\n<p>In the dataset, the key <code>lnglat</code> is confusing, because the data is clearly latitude and then longitude. That is just asking for a bug.</p>\n<p><code>lng</code>, <code>lon</code>, and <code>long</code> are all used as abbreviations for longitude in the... | {
"AcceptedAnswerId": "267840",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T02:27:56.827",
"Id": "267777",
"Score": "3",
"Tags": [
"python",
"performance",
"python-3.x"
],
"Title": "Finding similar values within a list of lists in Python"
} | 267777 |
<h3>description</h3>
<ul>
<li>I'm using influxDB, I need use Java to generate a query command.</li>
<li>The <code>TestingTag</code> struct maybe missing 0-3 fields.</li>
</ul>
<h3>code:</h3>
<pre><code> public List<FluxTable> getAggregatedValueWithTag(String type, String fieldName, String func, TestingTag tag)... | [] | [
{
"body": "<p>Please don't post random slapped-together lines of code that couldn't possibly compile to CodeReview. We strongly prefer code that compiles, even if all the dependencies aren't available to us. This method will never compile.</p>\n<p>In canonical Java, there is whitespace after a <code>,</code></p... | {
"AcceptedAnswerId": "267780",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T03:36:46.430",
"Id": "267779",
"Score": "-1",
"Tags": [
"java",
"strings",
"formatting"
],
"Title": "Better way to format a query string in Java"
} | 267779 |
<p>Everything works perfectly fine. However, I just want to know if there's a way for these codes to be shorter and non-repetitive and how?</p>
<p>I have these increment counters to update the stocks after submitting them.</p>
<p>The <code>selectedItem</code>:</p>
<pre><code><SelectItem
value={selectedItem}
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T07:22:28.957",
"Id": "528031",
"Score": "0",
"body": "The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to **simply sta... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T07:19:41.710",
"Id": "267781",
"Score": "0",
"Tags": [
"javascript",
"react.js",
"firebase"
],
"Title": "Single incrementCounter for 2 form submissions"
} | 267781 |
<p>Please critique my implementation of Quicksort in python 3.8:</p>
<pre><code>import random
from typing import List
def quicksort(A: List[int], left: int, right: int):
"""
Sort the array in-place in the range [left, right(
"""
if left >= right:
return
pi... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-09T06:21:48.217",
"Id": "528130",
"Score": "0",
"body": "(Please do *not* change in your code (after the first CR answer): when using round *and* square brackets for the notation of intervals, they are in standard orientation. I've see... | [
{
"body": "<p>One possible solution to handle duplicates without a big performance degrade is to randomly shuffle the input list before doing the sort. A specific algorithm to do so is a Fisher Yates Shuffle.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "20... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T09:07:41.443",
"Id": "267782",
"Score": "0",
"Tags": [
"python",
"python-3.x",
"algorithm",
"quick-sort"
],
"Title": "Python Quicksort Implementation with duplicates"
} | 267782 |
<p>I have written this small program in Python to calculate decimal places of <span class="math-container">\$\pi\$</span>. I tried to code it as readably as possible, but since this is a bit calculation heavy, it is reasonable to think about performance optimizations.</p>
<p>The program calculates the first root of the... | [] | [
{
"body": "<p>Thanks @Aemyl for your post. From a quick check of your code, these initial issues jump out at me:</p>\n<ul>\n<li>Using <code>__name__</code> entry point as a runner for <code>main()</code> function</li>\n<li>Global statements (<code>c = getcontext()</code>) outside of <code>__main__</code></li>\n... | {
"AcceptedAnswerId": "267790",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T09:45:56.810",
"Id": "267783",
"Score": "6",
"Tags": [
"python",
"mathematics"
],
"Title": "Calculating decimal places of pi in Python"
} | 267783 |
<p>This is a script that can convert any numerical value to any arbitrary radix representation and back, well, technically it can convert a number to any base, but because the output is a string representation with each a character as a digit, and possible digits are 10 Arabic numerals plus 26 basic Latin (lowercase) l... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-09T00:17:02.740",
"Id": "528114",
"Score": "0",
"body": "You realize that `from_base` can be entirely replaced with a call to `int()`, right?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-09T04:38:07.440"... | [
{
"body": "<p>If your goal is to have good code, most of this shouldn't exist and you should make better use of built-ins, but it seems like that isn't your goal.</p>\n<p>If your goal is to demonstrate that you know how to write functions equivalent to the built-ins, you haven't quite hit your mark, because the... | {
"AcceptedAnswerId": "267872",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T11:26:52.157",
"Id": "267787",
"Score": "1",
"Tags": [
"python",
"python-3.x",
"reinventing-the-wheel",
"converting"
],
"Title": "Python 3 arbitrary base converter and bas... | 267787 |
<p>There is a string "abcdebfkj", we need to transform this string to the below array:</p>
<p>expected o/p: </p>
<pre><code>["a", "a.b", "a.b.c", "a.b.c.d", "a.b.c.d.e", "a.b.c.d.e.b", "a.b.c.d.e.b.f", "a.b.c.d.e.b.f.k", "a.... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T17:52:46.353",
"Id": "528078",
"Score": "0",
"body": "Can't be \\$O(n)\\$. The result itself is \\$O(n^2)\\$, and you cannot build it faster."
}
] | [
{
"body": "<p>I am not into JavaScript anymore, but:</p>\n<pre><code>function splitString(str) {\n const result = [];\n var o = "";\n for (let ch of str) {\n result.push(o + ch);\n o += ch + '.';\n }\n return result;\n}\n\nfunction splitString(str) {\n const result = [];\n var o = "&... | {
"AcceptedAnswerId": "267800",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T11:33:01.543",
"Id": "267788",
"Score": "0",
"Tags": [
"javascript",
"performance"
],
"Title": "Build list of prefixes, including the whole string"
} | 267788 |
<p>I am attempting to make a simple Portal wrapper that does the following.</p>
<ol>
<li>Can render multiple portals on the same view</li>
<li>Can render multiple portals by targeting parent ids. This cannot be done by passing a ref into the component since the container may live anywhere.</li>
<li>Can render multiple ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-09T06:24:21.580",
"Id": "528132",
"Score": "0",
"body": "The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to **simply sta... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T14:03:58.690",
"Id": "267792",
"Score": "0",
"Tags": [
"javascript",
"react.js",
"typescript"
],
"Title": "How can I call React useRef conditionally in a Portal wrapper?"
} | 267792 |
<p>How should I structure this code to create a maze, solve it with breath-first-search (BFS) and to provide basic navigation movements by 1 step within maze with number of moves required to navigate? Use move along the path, Up, Left, Right, Down.</p>
<p>Below is some code that I mangled together on how to think / app... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T16:48:27.247",
"Id": "528073",
"Score": "0",
"body": "Class Agent is showed twice (did you mean to subclass"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T19:42:30.797",
"Id": "528091",
"Scor... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T15:06:16.403",
"Id": "267794",
"Score": "1",
"Tags": [
"python",
"algorithm",
"breadth-first-search"
],
"Title": "How to create a maze solve search with BFS provide navigation mov... | 267794 |
<p>I am going through a course and after learning the theory I decided to implement the DS on my own. I write a few test cases and all operations seem to be working fine but once I tried to double check with the course's solution, it is not clear if I am missing anything since my logic is not line by line the same :(</... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T17:22:16.197",
"Id": "267796",
"Score": "0",
"Tags": [
"java",
"algorithm",
"queue",
"circular-list"
],
"Title": "Circular Resizing Array in Queue Impl"
} | 267796 |
<p>I would love some criticism on the design and get feedback on how easy the python library <a href="https://github.com/AxelGard/cira" rel="nofollow noreferrer">cira</a> is to use.</p>
<p>Cira is a Façade library for simpler interaction with alpaca-trade-API from <a href="https://alpaca.markets/" rel="nofollow norefer... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T20:07:31.450",
"Id": "528092",
"Score": "0",
"body": "Okej, thanks! Will edit the post with the code."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-12T17:39:58.537",
"Id": "528291",
"Score": "1... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T18:26:25.590",
"Id": "267799",
"Score": "1",
"Tags": [
"python",
"python-3.x"
],
"Title": "Building a simple index fund using Cira"
} | 267799 |
<p>I just finished my Tic-tac-toe AI, and would be very grateful for opinions and comments on that project. I would like to add it to my 'entry level Python developer portfolio'.</p>
<p>README:</p>
<p>Simple AI that plays tic-tac-toe with itself. At the beginning it choses moves to play randomly, every possible move ha... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T22:12:44.667",
"Id": "528110",
"Score": "4",
"body": "Looking at your GitHub link it doesn't look like you have too much more code in this project, I would consider adding that to your question too so you can get a more rounded revi... | [
{
"body": "<p>Thanks Jacek for your post. Let's make a quick summary of the most obvious issues and we'll go over them:</p>\n<ul>\n<li>number of files</li>\n<li>the functions in certain files belong in other files due to their naming</li>\n<li>clear dependencies for functions in other files</li>\n<li>redundant ... | {
"AcceptedAnswerId": "268066",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T20:51:55.203",
"Id": "267807",
"Score": "3",
"Tags": [
"python",
"tic-tac-toe"
],
"Title": "Python tic-tac-toe AI"
} | 267807 |
<p>In the book they recommend to utilize an Array, but I think that it's easier to use an ArrayList instead, is there any problem with that? Is this code well designed?</p>
<pre><code>package com.company;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.Random;
public class Random... | [] | [
{
"body": "<p>You should document the reason why <code>Random r</code> is package private. At the moment the reason is not clear, but if you fix the "perpetual reinstantiation" by initializing the <code>r</code> variable in the constructor, then you can take advantage of the package private visibility... | {
"AcceptedAnswerId": "267816",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-08T21:26:30.417",
"Id": "267809",
"Score": "5",
"Tags": [
"java",
"performance",
"random",
"queue"
],
"Title": "Randomized Queue with ArrayList from Princeton's Algorithm Boo... | 267809 |
<p>I'm always down to learn better ways of doing thing and I wanted to see if I can get an input from the community to see if there is a way that I can improve this function:</p>
<pre class="lang-php prettyprint-override"><code>function pardot_dashboard_query()
{
$args = [
's' => '<!-- wp:acf/... | [] | [
{
"body": "<p>I generally don't advocate for printing any content from within a function, but I'll not dwell on this because it is a somewhat common practice for WordPressers.</p>\n<ul>\n<li>Name your function to clearly express what it does. Please greater importance on clarity than brevity.</li>\n<li>declare ... | {
"AcceptedAnswerId": "267823",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-09T02:53:21.457",
"Id": "267813",
"Score": "1",
"Tags": [
"php",
"html"
],
"Title": "Output results of a search for usage of a pardot-form"
} | 267813 |
<p>I'm implementing row-level-locking on a MS SQL Server. The function I created below works, but even with a very small data set, it takes a significant amount of time to return the results.</p>
<p>If I were to code this in VBA for example, I would call the username() function only once and store the result. Can this ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-09T07:36:16.973",
"Id": "528137",
"Score": "1",
"body": "Are tbl_Users.UnitID and tbl_Activity.ActivityID primary keys? Are tbl_Activity.UnitID, tbl_Users.Active and tbl_Users.RoleID indexed? Also, you check compliance.tbl_Users.Active... | [
{
"body": "<p>Based on Pavlov's comment I added indexs to my tables and altered the fuction as follows:</p>\n<pre><code>ALTER Function [compliance].[fn_AllowActivity] (@ActivityID sysname)\nreturns table\nwith schemabinding\nas\nreturn select 1 as [fn_AllowActivity_result]\nfrom \ncompliance.tbl_Users left join... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-09T07:25:33.077",
"Id": "267817",
"Score": "0",
"Tags": [
"performance",
"sql",
"sql-server"
],
"Title": "Table-Value Function with row-level-locking"
} | 267817 |
<p>I have an array <code>requestArr</code> in which there are objects with two values, also I have an array with objects <code>itemsArr</code> keys which is 'id' and the value of the array with numbers.</p>
<p>Task like this:
To map array of <code>itemsArr</code> and to compare key of object in it with value of an id i... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-09T07:34:30.803",
"Id": "267818",
"Score": "0",
"Tags": [
"javascript",
"array"
],
"Title": "Create a new array of an array of numbers and an array of objects whose key is used for searc... | 267818 |
<p>I have written some code to determine an interpolation matrix over a grid of points. I originally wrote the code in matlab, where under the specified parameters it took just over 2 minutes. The equivalent code in Python however takes 40minutes!</p>
<p>I was expecting Python to be slower, but not be such an amount! A... | [] | [
{
"body": "<p>In both Matlab and Numpy, your indexed loops are not the right way to express vectorized operations. You should adopt a strong bias against loops and individual element indexing, learn how broadcasting works, and pass around <code>ndarray</code>s instead of lists.</p>\n<p>Based on the above, a pot... | {
"AcceptedAnswerId": "267844",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-09T12:07:12.563",
"Id": "267824",
"Score": "2",
"Tags": [
"python",
"python-3.x",
"numpy"
],
"Title": "Calculating a function over a large array"
} | 267824 |
<p>There is a function that draws triangles on the canvas area in each lines:</p>
<pre><code>function DivotTemplate(divot, canvas) {
if (divot === void 0) { divot = defaultConfig; }
var config = __assign(__assign({}, defaultConfig), divot);
var ctx = canvas.getContext('2d');
if (!ctx)
throw Erro... | [] | [
{
"body": "<h2>2D canvas performance</h2>\n<p>You are running on a VERY slow system. Make sure you are not running any extension when measuring performance.</p>\n<h3>Avoid GPU state changes</h3>\n<p>The biggest performance penalty when using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CanvasR... | {
"AcceptedAnswerId": "267835",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-09T16:04:29.737",
"Id": "267830",
"Score": "2",
"Tags": [
"javascript",
"performance",
"canvas"
],
"Title": "Draw triangles on the HTML canvas optimization"
} | 267830 |
<p>I recently crafted <a href="https://puzzling.stackexchange.com/questions/111576/a-pretty-binary-grid">a binary word search puzzle</a> using HTML, CSS and JavaScript to dynamically build grids within a grid:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div cla... | [] | [
{
"body": "<p>Answering to your first question your code is certainly legible, I would modify your main structure (I'm copying just the first two rows for brevity):</p>\n<pre><code>var characters = ['H','U','O','M','S','F','I','R','E','I',\n 'P','O','B','P','O','S','P','K','K','A',\n];\n</code></pre>\n<p>You... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-09T17:46:13.033",
"Id": "267833",
"Score": "4",
"Tags": [
"javascript",
"performance",
"html",
"css"
],
"Title": "Creating a binary word search "
} | 267833 |
<p>I wanted to get some feedback on a fluent unit testing framework I’ve written. I call the project Fluent VBA. You can find a link to the project on GitHub <a href="https://github.com/b-gonzalez/Fluent-VBA" rel="nofollow noreferrer">here</a></p>
<p><strong>Motivation</strong></p>
<p>This project was inspired when I r... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-09T22:20:04.033",
"Id": "528169",
"Score": "1",
"body": "You need lots lots lots more examples demonstrating how your code works and a detailed help file explaining what each of your classes does/ how it should be used."
},
{
"... | [
{
"body": "<p>Really great stuff!</p>\n<p><strong>PredeclaredIds</strong></p>\n<p>It might be useful to consider declaring many of your classes with their <code>VB_PredeclaredId</code> attribute set to <code>True</code>. Doing so makes each class essentially 'static' (a default instance will always exist). Th... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-09T19:21:59.147",
"Id": "267836",
"Score": "3",
"Tags": [
"vba"
],
"Title": "A fluent unit testing framework in VBA"
} | 267836 |
<p>I have a little project, <a href="https://github.com/UltiRequiem/chuy" rel="nofollow noreferrer">chuy</a>, which is basically a copy of <a href="https://en.wikipedia.org/wiki/Make_(software)" rel="nofollow noreferrer">Make</a>.</p>
<p>By request of users I have added support for <code>toml</code> configuration, sinc... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-10T00:47:22.743",
"Id": "528175",
"Score": "2",
"body": "It's preferable to use `pathlib` to find files. Read through [the pathlib documentation](https://pymotw.com/3/pathlib/) to understand some of the options. e.g. `p = pathlib.Path(... | [
{
"body": "<ul>\n<li>Don't <code>raise BaseException</code></li>\n<li>Typo: <code>posible</code> -> <code>possible</code></li>\n<li>Don't type-hint a <code>list</code>; instead use <code>List[str]</code> in the case of your <code>posible_config_files</code></li>\n<li>Consider making a reusable solution that ... | {
"AcceptedAnswerId": "267878",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-10T00:03:36.683",
"Id": "267841",
"Score": "2",
"Tags": [
"python",
"python-3.x",
"array",
"file",
"file-system"
],
"Title": "Send an array of files and return the first ... | 267841 |
<p>Need help to optimize the following code for lower time complexity:</p>
<pre><code>arrayMultiply(ipnArray: number[]): number[] {
let outArray = [];
for (let i=0; i<ipnArray.length; i++){
let currentNum = ipnArray[i];
let newArr = ipnArray.filter(nub => nub !== currentNum);
let tempValue;
fo... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-10T17:55:56.387",
"Id": "528212",
"Score": "0",
"body": "I'm sorry, but your script does not return `[12, 6, 6, 4]` for `[1, 2, 2, 3]`."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-27T15:03:44.397",
... | [
{
"body": "<p>I haven't written JavaScript in years, so won't attempt a coded response.</p>\n<p>If you ran your code and showed us the output, there wouldn't be typos, and it would show that you've actually tested your code.</p>\n<p>Your solution unnecessarily creates temporary arrays, when it could simply omit... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-10T04:27:18.930",
"Id": "267846",
"Score": "1",
"Tags": [
"javascript",
"performance",
"array",
"typescript"
],
"Title": "Replace array values with product of all other values"
} | 267846 |
<p>In my learning course, I've implemented a message queue to which data gets pushed by some thread and later gets processed by some other thread. My implementation isn't that efficient as it involves creating minimum three copies of the same data which is not acceptable. So is there any way to avoid these unnecessary ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-10T10:14:22.753",
"Id": "528187",
"Score": "0",
"body": "This doesn't really seem to do much? (Well, it crashes due to popping from the wrong list in `relay_thread`). Otherwise this seems like a question about how to do something (avoi... | [
{
"body": "<h1>Create a <code>class</code> that implements the thread-safe queue</h1>\n<p>Your program has two queues, and already you see a lot of code duplication. It would be great to create a class that implements everything necessary for a thread-safe queue. For example:</p>\n<pre><code>template <typena... | {
"AcceptedAnswerId": "267859",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-10T04:56:01.837",
"Id": "267847",
"Score": "5",
"Tags": [
"c++",
"queue"
],
"Title": "Thread-safe message queue"
} | 267847 |
<p>Challenge: find the top three most frequently used words in a string. Only imports from the <code>base</code> package are allowed (source: <a href="https://www.codewars.com/kata/51e056fe544cf36c410000fb" rel="nofollow noreferrer">codewars</a>)</p>
<p>I'm looking for feedback on (1) readability, and (2) performance<b... | [] | [
{
"body": "<p>I'd write</p>\n<pre><code>increment = (<|> (Just 1)) . fmap (+1)\n</code></pre>\n<p>You can probably also write</p>\n<pre><code>reverseBySecond = flip $ comparing snd\n</code></pre>\n<p>if you don't mind getting <code>EQ</code> for equal pairs.</p>\n",
"comments": [
{
"Cont... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-10T05:38:39.237",
"Id": "267848",
"Score": "1",
"Tags": [
"strings",
"haskell",
"functional-programming",
"reinventing-the-wheel"
],
"Title": "Word frequency finder"
} | 267848 |
<p>I've started to write my first APL project, so I would like to have general feedbacks on coding style, file organization, error handling and defensive programming, performance improvements, etc.</p>
<p>The PNM format is handled by the following two functions:</p>
<pre><code> ∇img←readpnm file;data;x;y;type;⎕IO
... | [] | [
{
"body": "<h1>Coding style</h1>\n<h2>Comment your code</h2>\n<p>My father brought be up with the principle that you should be able to reconstruct your code from your comments. Maybe that level of commenting isn't necessary, especially if you use well-chosen names, but at least comment your API functions with w... | {
"AcceptedAnswerId": "267934",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-10T10:52:30.473",
"Id": "267857",
"Score": "5",
"Tags": [
"image",
"apl"
],
"Title": "Image processing using Dyalog APL"
} | 267857 |
<p>As the title suggests, I'm writing an x64 Code Emitter. Right now I've only encoded 1 instruction (The add instruction). I want to know if this API can be improved at all.</p>
<p>This is how you I use it.</p>
<pre class="lang-c prettyprint-override"><code>int main() {
// The Operand type contains the type of the... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-10T12:59:51.677",
"Id": "528193",
"Score": "4",
"body": "IMO the API is still too small to give meaningful feedback about, especially because it doesn't include any interesting cases yet (eg memory operands and labels). Maybe someone e... | [
{
"body": "<pre><code>// forward declaration for emitAdd\n#include "Instruction.h"\n</code></pre>\n<p>There's no declaration here. Do you mean it's in <code>Instruction.h</code>? I think you don't need this comment. When you include a header with the same name as the source file, everyone reading your... | {
"AcceptedAnswerId": "267869",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-10T12:21:19.323",
"Id": "267860",
"Score": "2",
"Tags": [
"c",
"assembly",
"native-code"
],
"Title": "Writing an x64 Code Emitter to eventually make a full fledged Assembler like... | 267860 |
<p>I'm trying to learn C++ with a background in python. This is my first program besides general practice. I wanted to remake the war game. I'm looking to get feedback on the C++ equivalent of its pythonicness. Some mistakes I believe I've made are possibly misusing the std functions, unnecessary type transformations, ... | [] | [
{
"body": "<h1>Representing decks of cards</h1>\n<p>The way you store decks of cards and shuffle them is really very strange.\nThere's the unnecessary conversion (even for Python) from numbers to strings and back.\nUsing <code>std::set</code> for a deck is wrong, because it doesn't preserve the order of the car... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-10T13:39:01.507",
"Id": "267862",
"Score": "4",
"Tags": [
"c++",
"beginner",
"playing-cards"
],
"Title": "War card game with random play"
} | 267862 |
<p>This is the code I've written that'll take a word as input and write all its anagrams to a file. The java compiler forces me to use try-catch statements every time I wish to do something with the file. I want to know if there's any way to make my code shorter and more readable in general. As you can see, inside the ... | [] | [
{
"body": "<p><em>(I'm a little nervous about answering since you mention this is for an exam, but then again we're here to help you learn and it's up to you and your examiners to see that you do the right thing with any help you get.)</em></p>\n<p>Since you asked about the exceptions, the answer is that if you... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-10T16:28:32.133",
"Id": "267866",
"Score": "2",
"Tags": [
"java"
],
"Title": "Generate anagrams and write them to a file"
} | 267866 |
<pre><code>function transformXCoordinate(x, xOrigin, y, yOrigin, theta) {
return xOrigin + (x - xOrigin) * Math.cos(theta) - (y - yOrigin) * Math.sin(theta);
}
function transformYCoordinate(x, xOrigin, y, yOrigin, theta) {
return yOrigin - (x - xOrigin) * Math.sin(theta) + (y - yOrigin) * Math.cos(theta);
}
funct... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-10T21:31:37.410",
"Id": "528219",
"Score": "0",
"body": "The second bit of code you translated from Troubadour's answer assumes the rotation is around the bottom-left corner. Hence `y_min = A_y;` for a rotation in 0-90 degrees. The oth... | [
{
"body": "<h2>Avoid numeric inaccuracies</h2>\n<p>You can use the vector along the x axis calculated as <code>ct</code>, <code>st</code> to deduce the quadrant rather than use <code>Math.PI / 2</code> or the approximation <code>1.5708</code>\n<code>ct >= 0</code> for quads 1 & 4 and <code>st >= 0</co... | {
"AcceptedAnswerId": "267876",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-10T20:46:11.857",
"Id": "267873",
"Score": "-1",
"Tags": [
"javascript",
"performance",
"algorithm"
],
"Title": "Finding the minimum bounding box of a rotated rectangle"
} | 267873 |
<p>There are some image quality assessment methods for "no-reference" image quality analysis. Here, I am attempting to calculate the <a href="https://www.mathworks.com/help/images/ref/niqe.html" rel="nofollow noreferrer">NIQE score</a> and <a href="https://www.mathworks.com/help/images/ref/piqe.html" rel="nof... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-10T23:49:05.133",
"Id": "267877",
"Score": "0",
"Tags": [
"performance",
"excel",
"file",
"image",
"matlab"
],
"Title": "NIQE score and PIQE score calculation for batch of im... | 267877 |
<p>I have the following code which works great to do what it is meant to do. It scrapes the bodies of all e-mails in the inbox at an e-mail address using IMAP and retrieves the unique code sent inside the body and stores it in a database with the amount paid. I'm hoping to make it so when a user purchases something t... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-12T11:23:17.450",
"Id": "528271",
"Score": "0",
"body": "I have no idea what you are actually using this for, but to scrape financial details from within an e-mail box, which you do not own, seems a recipe for disaster. It sounds like ... | [
{
"body": "<h3>Only read new messages</h3>\n<p>From a <a href=\"https://codereview.stackexchange.com/questions/267879/scrape-e-mails-using-imap-from-cron?noredirect=1#comment528320_267879\">comment</a>:</p>\n<blockquote>\n<p>It circulates through all the e-mails in the inbox so yes, it reads all of them multipl... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-11T02:54:32.107",
"Id": "267879",
"Score": "4",
"Tags": [
"php",
"email"
],
"Title": "Scrape E-Mails using IMAP from cron"
} | 267879 |
<p>I'm new to programming and was tasked with programming a generic circular FIFO queue, without using anything but an underlying array and self-programmed methods. I still don't know how to approach bigger projects like this yet. I managed to program something that technically works, but I need someone brutal to reall... | [] | [
{
"body": "<p><strong>Advice 1</strong></p>\n<p>In Java Collection Framework (the data structure framework residing in <code>java.util.*</code>), the item type is denoted by <code>E</code>, and not <code>T</code>. I suggest you do this:</p>\n<pre><code>public class FloatingQueue<E> {\n ... E here and t... | {
"AcceptedAnswerId": "267883",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-11T04:13:16.133",
"Id": "267880",
"Score": "4",
"Tags": [
"java",
"array",
"homework",
"generics",
"queue"
],
"Title": "FIFO array/queue"
} | 267880 |
<p>I've been tasked with creating some way to encrypt arbitrary text for a .NET Core app, with the following requirements:</p>
<ul>
<li>Messages will be between 10 bytes and 1 kB.</li>
<li>Boss doesn't want me to use AES-GCM (which I know would be the sensible option as it's already included in .NET Core and I've alrea... | [] | [
{
"body": "<h2>Cryptography</h2>\n<p>Yes, CBC followed by HMAC is fine (also known as encrypt-then-MAC), and you include the IV into the calculations, which is great. You indeed do not have to include the salt and iteration count into the HMAC calculation as they already influence the key being used. You may ne... | {
"AcceptedAnswerId": "267923",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-11T04:35:38.517",
"Id": "267881",
"Score": "1",
"Tags": [
"c#",
"encryption"
],
"Title": "Manual authenticated encryption on .NET Core"
} | 267881 |
<p>I am a newbie in Ruby. I want to learn Ruby and I want to learn clear code in Ruby. I coded a number guessing game but my code is smelling bad. How I can do better code?</p>
<pre><code>class NumberGuess
attr_accessor :num_of_guess, :random_num, :name
def initialize(random_num, num_of_guess, name)
@name = na... | [] | [
{
"body": "<p>I'm not a Ruby programmer, but there are a couple of general improvements I can think of for this code:</p>\n<ul>\n<li><strong>Better initialization</strong>: There is no need to pass the random number and <code>num_of_guess</code> to the class.\nGenerating a random number is part of the core def... | {
"AcceptedAnswerId": "267893",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-11T05:15:33.187",
"Id": "267882",
"Score": "2",
"Tags": [
"beginner",
"game",
"ruby",
"number-guessing-game"
],
"Title": "Number guessing game in Ruby"
} | 267882 |
<pre><code>print("Welcome to the Sieve of Eratosthenes, where you can generate prime numbers from 1 to n : ")
n = int(input("Enter your n : "))
y = [y for y in range(1,n) if y*y < n]
primes = [p for p in range(2,n+1)]
length = len(primes)
print(primes)
for p in range(2,len(y)+2):
fo... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-11T09:24:26.363",
"Id": "528235",
"Score": "0",
"body": "i've updated the code,could you recheck it again"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-11T10:31:22.063",
"Id": "528237",
"Score": "... | [
{
"body": "<h2>Stylistic improvements</h2>\n<ul>\n<li>You create a list <code>y</code>, and only use it to have an upper bound for the first loop. The bound should be the square root of <code>n</code>, you can compute that directly.\nSo <code>for p in range(2, math.ceil(n**0.5) + 1)</code> instead of <code>for ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-11T08:47:28.460",
"Id": "267887",
"Score": "0",
"Tags": [
"python",
"primes"
],
"Title": "My prime sieve using Python"
} | 267887 |
<p>My code is working perfectly fine, except for one-thing. The performance is not up-to the mark. What I am trying to achieve is I have an image with a few circles (each circle has a border with different color than circle fill color). When the user touches any circle, I want to change the border color of the selecte... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-11T15:12:59.447",
"Id": "528246",
"Score": "0",
"body": "This function is taking 3-4 seconds to run? Did you profile your code? Or are you assuming that this is the slow bit? I don’t know Swift, so can’t do a review, but I’m sure you c... | [
{
"body": "<p>There are two issues.</p>\n<ol>\n<li><p>The process of converting to and from <code>UIColor</code> objects is very expensive.</p>\n</li>\n<li><p>The process of calling <a href=\"https://developer.apple.com/documentation/swift/array/2945493-contains\" rel=\"nofollow noreferrer\"><code>contains</cod... | {
"AcceptedAnswerId": "267899",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-11T12:40:20.327",
"Id": "267889",
"Score": "1",
"Tags": [
"performance",
"image",
"swift",
"ios",
"color"
],
"Title": "Changing the color of some pixels in an image in Sw... | 267889 |
<p>I just started learning java and wrote this variable length array as my first program. I wanted people's opinion on how "java" this code is. For example coding conventions, idioms that I could have used or any improvements that could be made.</p>
<p><strong>MyClass.java</strong>:</p>
<pre><code>package myp... | [] | [
{
"body": "<p><strong>Advice 1</strong></p>\n<pre><code>public MyArray() {\n array = new int[size];\n}\n</code></pre>\n<p>Above, <code>size</code> is 0, so you are allocating a zero-length array. Useless. Consider this:</p>\n<pre><code>private static final int INITIAL_CAPACITY = 10; // Or some other reasonab... | {
"AcceptedAnswerId": "267891",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-11T13:06:50.177",
"Id": "267890",
"Score": "2",
"Tags": [
"java",
"beginner"
],
"Title": "Variable length array"
} | 267890 |
<p>I want to enable bitmask-like behavior (ie. overloaded <code>operator|</code>, <code>operator&</code> and <code>operator^</code>) for some <code>enum class</code>es. This is what I came up with:</p>
<pre class="lang-cpp prettyprint-override"><code>#pragma once
#include <type_traits>
/// \brief Marks an en... | [] | [
{
"body": "<h1>Simplify <code>is_bitmask</code></h1>\n<p>Since you are using C++20 anyway, you can avoid making <code>is_bitmask</code> a <code>struct</code>, and make it a <code>constexpr</code> template variable instead. This simplifies the first part of the code a lot:</p>\n<pre><code>#define ENABLE_BITMASK(... | {
"AcceptedAnswerId": "267906",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-11T21:36:29.087",
"Id": "267902",
"Score": "6",
"Tags": [
"c++",
"enum",
"c++20",
"constant-expression"
],
"Title": "Enabling bitset-like behavior for enum classes (C++20)"
} | 267902 |
<p>This is one more implementation of <a href="https://en.wikipedia.org/wiki/Binary_search_tree" rel="nofollow noreferrer">Binary Search Tree</a> in C++. There are many such implementations, however they are typically long and complex, and also many of them rely on pointers to parent nodes for deletion (which isn't ne... | [] | [
{
"body": "<h1>Move <code>struct Node</code> inside <code>struct BST</code></h1>\n<p>A <code>Node</code> is just an implementation detail of a <code>BST</code>. Also, consider the scenario where you need multiple data types, like linked lists, hash maps and so on, you can't name everything <code>Node</code>. Mo... | {
"AcceptedAnswerId": "267912",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-12T03:47:29.260",
"Id": "267907",
"Score": "3",
"Tags": [
"c++",
"binary-search-tree"
],
"Title": "Binary Search Tree in C++ without parent pointers"
} | 267907 |
<p>In my coding interview for a company, I got the question to write a Minesweeper game. I did not manage to finish the game in 1 hour at that time, so now I have written it again after the interview. Could you please help me to check if my code follows good practices for a game-program ? I appreciate any ideas.</p>
<p... | [] | [
{
"body": "<p>Generally the code shows a consistent style, so in that regard I think it looks good. I like the way the status is explicitly kept using the enum; it makes everything that more easy to follow.</p>\n<hr />\n<pre><code>def __init__(self, w, h, k):\n</code></pre>\n<p>I could guess the <code>w</code> ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-12T04:23:14.330",
"Id": "267908",
"Score": "14",
"Tags": [
"python",
"minesweeper"
],
"Title": "A simple Minesweeper in Python"
} | 267908 |
<p>I have an array wrapper class that I'd like to get reviewed.</p>
<p>There are two differences with other common questions on this site. First, my class needs to be "nullable", where a "null array" has a different meaning than an array of length zero.</p>
<p>Second, I'm trying to test whether smal... | [] | [
{
"body": "<h1>Missing <code>#include <memory></code></h1>\n<p>Since you use <a href=\"https://en.cppreference.com/w/cpp/memory/allocator\" rel=\"nofollow noreferrer\"><code>std::allocator</code></a>, you have to <code>#include <memory></code>, otherwise your code might fail to compile.</p>\n<h1>Avo... | {
"AcceptedAnswerId": "267913",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-12T08:41:35.487",
"Id": "267910",
"Score": "4",
"Tags": [
"c++",
"array",
"c++14"
],
"Title": "Nullable array wrapper class with small size optimization"
} | 267910 |
<p>In this post, I will present and compare two distinct algorithms for sieve of Eratosthenes:</p>
<p><strong><code>com.github.coderodde.math.prime.PrimeFinder</code></strong></p>
<pre><code>package com.github.coderodde.math.prime;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
/**
* Thi... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-12T12:19:35.933",
"Id": "528272",
"Score": "0",
"body": "(While the title is spot-on, I don't think you *wish to know which of the solutions you presented is best (and why)*.)"
},
{
"ContentLicense": "CC BY-SA 4.0",
"Creati... | [
{
"body": "<p>Just a few stabs:</p>\n<ul>\n<li><p>Why an <code>abstract class</code>? You could even have static method members in <code>interface</code>s.</p>\n</li>\n<li><p><code>/* Finds all the primes no larger than {@code limit} and returns them in a * sorted list.</code> I read <code>BitSet findPrimesUpTo... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-12T09:14:20.150",
"Id": "267911",
"Score": "5",
"Tags": [
"java",
"algorithm",
"comparative-review",
"sieve-of-eratosthenes"
],
"Title": "Comparing 2 distinct sieve of Eratosthen... | 267911 |
<p>I am working on a practice problem found here: <a href="https://www.hackinscience.org/exercises/sequence-mining" rel="nofollow noreferrer">https://www.hackinscience.org/exercises/sequence-mining</a></p>
<blockquote>
<p>Overview</p>
<p>Sequence mining is useful for analyzing list of events when order matters. It's us... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-12T15:13:13.113",
"Id": "528276",
"Score": "0",
"body": "Just a general remark: for me the code is just too dense to understand easily. My mind just starts to complain when trying to read stuff like `[pos_dict[seq_index].append(seq[sub... | [
{
"body": "<p>Any time you see nested <code>for</code> loops like this, you can visually clean them up (or at least separate them) with generators:</p>\n<pre class=\"lang-py prettyprint-override\"><code>def create_substrings(data, max_int):\n # This function cleans up the seq mining function\n # by just c... | {
"AcceptedAnswerId": "267936",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-12T12:02:18.503",
"Id": "267914",
"Score": "4",
"Tags": [
"python",
"programming-challenge",
"time-limit-exceeded"
],
"Title": "HackInScience exercise: Sequence Mining"
} | 267914 |
<p>This is my first time using StackExchange. I did not have any idea what this website for, but I guess is a place to review the code? So, I'm just going to give it a shot.</p>
<pre><code>#include <iostream>
std::string board[3][3];
void making_board();
void play_the_game();
void display_board();
void choose_... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-12T13:49:41.317",
"Id": "528274",
"Score": "0",
"body": "Hi. Welcome to Code Review! Your post is rather chatty. We can already see that you are a first time user. It shows in your profile and your reputation score. We would prefe... | [
{
"body": "<p>No time for a full review, but here are some general remarks:</p>\n<ul>\n<li><code>making_board</code>: try and use verbs, as methods are things that perform actions, i.e. <code>make_board</code> or <code>setup_board</code> (you seem to do this right for the other methods, so maybe this is just th... | {
"AcceptedAnswerId": "268003",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-12T12:16:01.643",
"Id": "267916",
"Score": "2",
"Tags": [
"c++",
"beginner",
"tic-tac-toe"
],
"Title": "My tic tac toe minimax implementation"
} | 267916 |
<p>I have been coding in Python for a number of years now. I've always felt that Matplotlib code takes up a lot more lines of code than it should. I could be wrong.</p>
<p>I have the following function that plots a simple scatter plot graph with two additional solid lines. Is there any way for me to reduce the number o... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-12T17:32:28.477",
"Id": "528290",
"Score": "1",
"body": "It might be a good idea to include a little more code so people can run an analysis in their IDE. They should be able to reproduce what you're seeing."
},
{
"ContentLicen... | [
{
"body": "<blockquote>\n<p>Is there any way for me to reduce the number of lines to achieve exactly the same outcome?</p>\n</blockquote>\n<p>should, in isolation, not be your overriding concern, and your code is about as minimally chunky as matplotlib will allow. Your current push - rather than to shed a line ... | {
"AcceptedAnswerId": "268005",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-12T12:41:42.690",
"Id": "267917",
"Score": "1",
"Tags": [
"python",
"matplotlib"
],
"Title": "Plot a simple scatter plot graph with two additional solid lines"
} | 267917 |
<p>I've implemented a Game of Life in Clojure and would like to understand what I can do better, especially in terms of idiomatic Clojure (without losing readability/maintainability) of the current version.</p>
<p>This is my first "serious" Clojure program (beyond hello world).</p>
<p>Things that I'm specific... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-12T13:52:17.863",
"Id": "267922",
"Score": "3",
"Tags": [
"clojure",
"game-of-life"
],
"Title": "Game of Life in Clojure"
} | 267922 |
<p>I'm new to writing benchmarks and would like some advice whether I am doing this correctly.</p>
<p>I currently have two classes: <code>Person.java</code> and <code>PersonFinaliser.java</code> which each have a single field <code>age</code>. The only difference is that <code>PersonFinaliser.java</code> has a <code>fi... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-15T19:04:12.713",
"Id": "528547",
"Score": "0",
"body": "According to https://github.com/openjdk/jmh/blob/99e9c19c80a0133c28f6532ef2b5776d5b8bd023/jmh-core/src/main/java/org/openjdk/jmh/annotations/Mode.java#L65 `Mode.SingleShotTime` ... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-12T15:22:54.460",
"Id": "267924",
"Score": "2",
"Tags": [
"java",
"performance",
"benchmarking"
],
"Title": "Measuring Performance of Class Instantiation with JMH"
} | 267924 |
<p>I just have the free account at leetcode. I've been practicing some coding there in preparation for interviews. But I can't see the solution logic behind the <code>IntegerToRoman</code> conversion function. I solved both the leetcode Roman Numbers problems (Arabic -> roman, and roman -> Arabic). I made a solut... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-13T13:58:05.187",
"Id": "528353",
"Score": "0",
"body": "`std::map` is slow unless your benchmark shows it to be faster than say `std::vector`. Only ever use it where it performs better, or when it makes code simpler but the performanc... | [
{
"body": "<pre><code>if (s.size() == 1)\n{\n return oneSizeRomans(s[0]);\n}\n</code></pre>\n<p>There is nothing special with a size of 1. Yes, you can return early of course, but <em>all the other values</em> will have to go through this spurious <code>if</code> statement as well.</p>\n<p>If well programmed... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-12T15:28:01.290",
"Id": "267925",
"Score": "2",
"Tags": [
"c++",
"performance",
"roman-numerals"
],
"Title": "Improving speed and simplify code of \"leetcode\" Roman Numbers converte... | 267925 |
<p>Originally written in C (which was abysmal, you may check <a href="https://pastebin.com/QP8D3rFt" rel="nofollow noreferrer">here</a> if you want), I rewrote my simple credit card validation program using Python</p>
<pre><code>def main():
# Prompts user for card number
nums = int(input("Number: "))
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-14T14:58:02.097",
"Id": "528446",
"Score": "0",
"body": "Suggested reading: https://codereview.stackexchange.com/questions/256078/how-can-i-shorten-this-program-using-luhns-algorithm-to-check-credit-card-numbe"
},
{
"ContentLic... | [
{
"body": "<h1>Getting the First 2 Digits of a Number</h1>\n<p>A solution for this in constant space and time is already documented in <a href=\"https://stackoverflow.com/a/48716024/7867968\">this answer</a>:</p>\n<pre class=\"lang-py prettyprint-override\"><code>from math import log10\n\n# go from this\nnum = ... | {
"AcceptedAnswerId": "267940",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-12T20:57:41.153",
"Id": "267932",
"Score": "2",
"Tags": [
"python",
"algorithm",
"validation",
"finance",
"checksum"
],
"Title": "Simple credit card validation with Luhn'... | 267932 |
<p>I wrote this code in c#. It is a question from LeetCode, number 49. Given an array of strings, group the anagrams.</p>
<p>The examples it gives are:</p>
<blockquote>
<p>["eat","tea","tan","ate","nat","bat"]</p>
</blockquote>
<p>then return:</p>
<blockquote>... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-13T06:20:49.280",
"Id": "528330",
"Score": "0",
"body": "Array.Sort(new string(temp)); -> Impossible to convert from \"string\" to \"System.Array\"."
}
] | [
{
"body": "<p>Here is my 4 lines long alternative:</p>\n<pre><code>var anagrams = from word in words\n let pair = new { Original = word, AlphabeticallyOrdered = string.Concat(word.OrderBy(@char => @char)) }\n group pair by pair.AlphabeticallyOrdered into anagram\n select anagram.Select(@group => ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-12T23:36:01.223",
"Id": "267935",
"Score": "2",
"Tags": [
"c#",
"strings",
"array"
],
"Title": "Grouping anagrams together from a string array"
} | 267935 |
<p>I have just recently picked up coding and am trying to improve my coding. I've written this bit of code to create a little adventure world. I haven't completed the code, everything runs how I want it too but I'm aware this code isn't efficient. I would like some advice and some help on how I would make my code bette... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-13T13:32:14.020",
"Id": "528350",
"Score": "1",
"body": "I receive errors when testing your code. It appears that the paste is missing the import statements? Can you fix? Thanks."
},
{
"ContentLicense": "CC BY-SA 4.0",
"Cre... | [
{
"body": "<p>This is a fun start to a game.</p>\n<p>Decrease your reliance on globals, passing around variables in function parameters instead. Encapsulating the character stats in a class will make things easier.</p>\n<p>You need to work on your spelling and grammar - for example, <code>you're power is the to... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-12T23:51:45.247",
"Id": "267937",
"Score": "4",
"Tags": [
"python",
"performance",
"beginner",
"game",
"role-playing-game"
],
"Title": "Create a little adventure world"
} | 267937 |
<blockquote>
<p>Given a file or directory, create an iterator that returns the non-empty words from the file or from all files <em>recursively</em> in the directory. Only process ".txt" files. Words are sequence of characters separated by whitespace.</p>
</blockquote>
<pre><code>class WordIterable:
def __... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-13T05:38:24.923",
"Id": "528328",
"Score": "0",
"body": "The question is vague and the code makes some assumptions that aren't in the question. For example, what is a \"word\" and a \"non-empty word\"? Just letters? What about numbers ... | [
{
"body": "<p>The code seems overly complicated and complex for a relatively simple task.</p>\n<pre><code>from pathlib import Path\n\ndef words(file_or_path):\n path = Path(file_or_path)\n \n if path.is_dir():\n paths = path.rglob('*.txt')\n else:\n paths = (path, )\n \n for ... | {
"AcceptedAnswerId": "267946",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-13T03:35:41.043",
"Id": "267941",
"Score": "4",
"Tags": [
"python",
"io",
"iterator"
],
"Title": "Iterate through non-empty words from text files"
} | 267941 |
<p>So I did my own take (I wrote my own algorithm) for generating prime numbers from <code>1 to 1000</code>.</p>
<pre><code>lst = [y for y in range(1000)]
for i in range(0,len(lst)): #i = 1 and i is traversal
print("iterate - " + str(i))
for j in range(i,0,-1): #divisor range
print(j)
... | [] | [
{
"body": "<h1>Remove print statements</h1>\n<p>Printing to the console takes a significant amount of time, and you are printing for every iteration and every element in the list. Run it once with the statements, and once without. It's a substantial time save.</p>\n<h1>Removing elements</h1>\n<p>For every itera... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-13T05:04:20.983",
"Id": "267944",
"Score": "4",
"Tags": [
"python",
"algorithm",
"primes"
],
"Title": "My prime number generation program in Python"
} | 267944 |
<p>I'm using Python's <code>Enum</code> to define the physical units in which a value is expressed.</p>
<p>Eventually, I want to add them as an attribute to my <code>pandas.Series</code> and <code>pandas.DataFrame</code> instances, so that this information does not need to be stored in the variable name or in comments ... | [] | [
{
"body": "<p>A small suggestion is to move the <code>relations</code> variable from the function calls to the class and make it static as well. As it will be creating the same variable every time you try to call the <code>__mult__</code> or <code>__truediv__</code> this might be overhead.</p>\n",
"comments... | {
"AcceptedAnswerId": "267954",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-13T06:53:54.230",
"Id": "267948",
"Score": "12",
"Tags": [
"python",
"reinventing-the-wheel",
"enum"
],
"Title": "Using Python enums to define physical units"
} | 267948 |
<p>I'm doing the following exercise from PPP - Bjarne Stroustrup, Chapter 19, ex.10.</p>
<blockquote>
<p>Implement a simple <code>unique_ptr</code> supporting only a constructor, destructor,<code>-></code>, <code>*</code> and <code>release()</code>. In particular, don't try to implement an assignment or a copy const... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-13T13:08:50.397",
"Id": "528348",
"Score": "0",
"body": "You need to deal with copy / move constructors and assignments - their implementation and declarations are missing. Also default one ought to set `ptr` to `nullptr`."
},
{
... | [
{
"body": "<p>First of all, you don't need to write <code>inline</code> when a function is defined inside the class. You might notice that you've used it in some but not all of them; it doesn't add anything to the meaning.</p>\n<blockquote>\n<p>In particular, don't try to implement an assignment [operator] or ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-13T11:56:33.757",
"Id": "267957",
"Score": "0",
"Tags": [
"c++",
"reinventing-the-wheel",
"c++14",
"pointers"
],
"Title": "Implementing a unique_ptr - PPP Stroustrup exercise"
} | 267957 |
<p>Dumbserver, or the simplest workable HTTP server. It is supposed to operate in the 'traditional' way, that is, mapping paths in requests to the directory structure.</p>
<p>Why did I write it: I needed a simple development server for a website I'm trying to make. Instead of using Express or something like that for th... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-13T13:46:29.587",
"Id": "267962",
"Score": "2",
"Tags": [
"javascript",
"node.js",
"http",
"server"
],
"Title": "Node.js Dumbserver"
} | 267962 |
<p>I'm a new DS student, and I get the basic concept of Standardisation, whilst I was learning we used StandardScaler in some algorithms, and not in others on the same dataset, and I'm still confused as where and to use it.</p>
<p>I have other categorical features selected for the classifiers. Could you please review ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-16T13:16:59.290",
"Id": "528589",
"Score": "0",
"body": "I would recommend asking this over at Cross Validated. Code Review is more for feedback on the implementation of your analytics pipeline itself (meaning the Python code itself). ... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-13T14:44:26.417",
"Id": "267968",
"Score": "0",
"Tags": [
"python",
"algorithm",
"machine-learning"
],
"Title": "To scale or not to scale in regression and classification algorithms"... | 267968 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.