body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>Recently I'm interested in the Tower of Hanoi problem. The simplest solution is probably the recursive one but I'm trying to challenge myself by solving it iteratively. After observing the pattern of Tower of Hanoi position sequence I came up with this:</p>
<p><div class="snippet" data-lang="js" data-hide="false" da... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T04:24:24.010",
"Id": "268892",
"Score": "0",
"Tags": [
"javascript",
"programming-challenge"
],
"Title": "Iterative solution for Tower of Hanoi challenge"
} | 268892 |
<p>I've a list of strings and a list of regular expressions. I need to categorize each string to get what type of string it is based on regex.</p>
<p>This is my code:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-cod... | [] | [
{
"body": "<p>What I think is wrong in your code :</p>\n<ul>\n<li>Instead of assigning one variable name per Regex, put them all in an Array, or an Object. An Object makes sense here, because you want to associate regexes to letters.</li>\n<li><code>if() else if () else if()</code> is cumbersome to read and mai... | {
"AcceptedAnswerId": "268894",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T06:30:18.143",
"Id": "268893",
"Score": "0",
"Tags": [
"javascript",
"regex"
],
"Title": "Test strings with a lot of regular expressions"
} | 268893 |
<p>I'm trying to sort a <code>Sector</code> array and a <code>Province</code> array based on the language.</p>
<p><code>sector.ts</code>:</p>
<pre><code>export interface Sector {
id: string;
Label_FR: string;
Label_NL: string;
}
</code></pre>
<p><code>province.ts</code>:</p>
<pre><code>export interface Pro... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-13T09:29:38.283",
"Id": "530472",
"Score": "2",
"body": "Have you considered [`localeCompare`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare) for `sortFunc` implementation?"
}
] | [
{
"body": "<p>The constructor should mostly just be used for injection:</p>\n<pre class=\"lang-js prettyprint-override\"><code>currentLang: string // Declare members above constructor\n\nconstructor(\n private readonly _translateService: TranslateService,\n private statisticsManager: StatisticsManager\n) ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T07:25:37.810",
"Id": "268895",
"Score": "1",
"Tags": [
"typescript",
"angular-2+"
],
"Title": "Sort an object array with two variable based on the language"
} | 268895 |
<pre><code> r←n optimal img;bmp;bin;rgb
;i;p;v;b;euclid;most
;m;⎕IO
⍝ compute optimal palette
⍝ it is recomended using
⍝ a shrinked image
⎕IO←0
r←⍬
⍝ 12996=114*2=(⌊0.45×255)*2, 0.45 is the threshold constant from the paper.
euclid←{∧/12996≤+⌿×⍨r(-⍤1 0⍤¯1)⍥((3⍴256)∘⊤)⍵}
most←(((⊢⍳⌈/)⊢/)⌷⊣/){⍺(+/⍵)}⌸
⍝ 16*3 bi... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T07:58:05.147",
"Id": "268896",
"Score": "4",
"Tags": [
"image",
"apl"
],
"Title": "Compute the optimized palette for RGB image"
} | 268896 |
<p>This is a finished project where 2 players each roll 2 dice. If the sum of the number that a player has rolled is even, then 10 is added to their score; if the sum of their 2 rolls isn't even then 5 is subtracted from the player's score. If the player's first role = the second roll, then another roll is done and add... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-13T21:36:30.937",
"Id": "530528",
"Score": "0",
"body": "Is the list of valid users public information? If not, you have a security issue."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T07:46:40.530",
... | [
{
"body": "<p>This… … … is a mouthfull. The sheer amount of comments make the code very hard to read as it gets buried under tons upon tons of other information. Most of them being just there to state the obvious of what the line of code is doing. This is not what comments are about. Comments, if any, should st... | {
"AcceptedAnswerId": "268909",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T08:59:43.357",
"Id": "268897",
"Score": "9",
"Tags": [
"python",
"python-3.x",
"dice"
],
"Title": "Two player dice roll game"
} | 268897 |
<p><strong>Intro:</strong> I started working three month ago and i have never used JavaScript before, i don't know what is the best practice in JS and i feel like my code can be improved a lot, so i'm here searching for tips and tricks or other infos who can make my code better.</p>
<p><strong>Task:</strong> Take in in... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T13:42:37.970",
"Id": "530408",
"Score": "0",
"body": "Welcome to the site!! I’m not sure what version of JavaScript you used but I’m getting some errors when running it in Chrome and Node.js [TIO](https://bit.ly/3DyMRVT)"
},
{
... | [
{
"body": "<p>I think you are overcomplicating things with all the inline lambda functions.</p>\n<p>A Simple way to compare two times is to use the following formula:</p>\n<pre><code>time = hour * 60 + minute.\n</code></pre>\n<p>Based on this you can use the following function to create a time representation fr... | {
"AcceptedAnswerId": "268913",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T10:29:45.920",
"Id": "268899",
"Score": "1",
"Tags": [
"javascript",
"datetime"
],
"Title": "Find when the shop will next open or close"
} | 268899 |
<p>To learn some rust I decided to write a simple calculator. This calculator can take a string in the form of <code>1+2*3/4-5</code>, and calculate the result. It does so while keeping the order of operations in mind (*/ before +-).</p>
<p>I came up with the following:</p>
<pre><code>/// Token containing either a numb... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T13:11:08.027",
"Id": "268907",
"Score": "2",
"Tags": [
"rust"
],
"Title": "Rust calculator"
} | 268907 |
<p>I have to sort the array based on rating in a specific pattern.</p>
<p>3 star = 5, 4star = 3 , 5 star =7</p>
<p>[3 star hotel, 4 star hotel, 5 star hotel]</p>
<p>Note: Replace 3 star hotel with 4 star hotel if 4 star are not there.</p>
<p>expected pattern:
345
345
345
335
555</p>
<p>basically i want to sort some h... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T20:45:12.533",
"Id": "530444",
"Score": "0",
"body": "What exactly do you want to improve? Performance, shorten the code?"
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T13:33:02.000",
"Id": "268908",
"Score": "0",
"Tags": [
"javascript",
"algorithm",
"array"
],
"Title": "Order array based on rating in a specific pattern"
} | 268908 |
<p><code>wordList</code> is an array of non-empty strings ("words"). The following code I have written with the purpose of obtaining a Map, containing the unique words and their respective count:</p>
<pre><code>for (let p = 0; p < wordList.length; p++) {
const word = wordList[p];
if (wordMap.has(word)... | [] | [
{
"body": "<h2>General review points</h2>\n<ul>\n<li><p>Rather than use a <code>for(;;)</code> loop use a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of\" rel=\"nofollow noreferrer\" title=\"MDN JavaScript statement reference. for...of\">for...of</a> loop as yo... | {
"AcceptedAnswerId": "268934",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T16:43:12.443",
"Id": "268917",
"Score": "2",
"Tags": [
"javascript",
"strings",
"hash-map"
],
"Title": "word frequency distribution"
} | 268917 |
<p>Looking for any suggestions - alternative design, improvements to readability, improvements to the comments, etc.</p>
<hr />
<p>I implemented this letter dictionary to see if it would faster than a regular dictionary in a Trie implementation. Keys into this dictionary must be lowercase letters. <code>LetterDict</cod... | [] | [
{
"body": "<h1>Counting bits</h1>\n<pre class=\"lang-py prettyprint-override\"><code> K = self.K\n i = 0\n while (K := K & (K - 1)) & target:\n i += 1\n</code></pre>\n<p>This loop is counting the number of <code>1</code>-bits below the <code>target</code> bit.</p>\n<p>The... | {
"AcceptedAnswerId": "268924",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T17:50:09.057",
"Id": "268919",
"Score": "3",
"Tags": [
"python",
"hash-map",
"bitwise",
"trie"
],
"Title": "LetterDict, a dictionary whose keys must be lowercase letters [... | 268919 |
<p>I have a string of Hebrew text which also contains":", "-", & "|".
Attempting to replace "-", "|", and ":" with a space.
How can I do this efficiently?</p>
<pre><code>string my_string = "עַל־פְּנֵי:על־פני|על־פני";
string[] replace_chars = new ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T19:54:01.007",
"Id": "530437",
"Score": "0",
"body": "Is there any alternative to have this done ?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T20:46:19.520",
"Id": "530445",
"Score": "0",
... | [
{
"body": "<p>you can always use <code>Replace</code> extension, it's fast, durable, and under your hands. So, your work would be something like :</p>\n<pre><code>const char space = '\\u0020'; // for readability purpose.\n\nvar result = my_string.Replace(':', space).Replace('-', space).Replace('|', space);\n</c... | {
"AcceptedAnswerId": "268970",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T18:00:11.527",
"Id": "268920",
"Score": "2",
"Tags": [
"c#",
"performance",
"strings"
],
"Title": "replace substrings from within Hebrew text"
} | 268920 |
<p>I have the following entity, I am getting it in response of REST API.</p>
<pre><code>class Account {
private String ownerId;
private List<String> coOwners;
}
</code></pre>
<p>REST API accepts UUID and returns linked Account.</p>
<p>Now my task here is to call this REST API for multiple bank accounts ow... | [] | [
{
"body": "<p>You could clean it up by splitting into multiple steps. It feels wrong to make a class for ownerId and coOwners... Don't you know the ownerId at the time of making the request? (How do you know that accounts belong to the same owner?)</p>\n<pre><code>public List<String> fetchDistinctCoOwners... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T18:44:35.213",
"Id": "268925",
"Score": "0",
"Tags": [
"java",
"object-oriented",
"design-patterns"
],
"Title": "What is the elegant way to merge collection of entities with a dup... | 268925 |
<p>This is my first game ever. I' learning C++ now and I decided to make a game. I saw a snake game that works with the draw-input-logic system and I really liked it. I tried to make a tic tac toe game.</p>
<p>Please rate it and show me how can I improve it, or give me any other simple game ideas.</p>
<p>input: x y;</... | [] | [
{
"body": "<p>I'll start with the good.</p>\n<ol>\n<li>You did not have <code>using namespace std;</code>.</li>\n<li>You are passing <code>std::vector<std::vector<int>> game</code> by a reference, nice!</li>\n</ol>\n<p>Now for the bad, and unfortuanatly there is quite a bit.</p>\n<p>This looks like ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T19:52:17.883",
"Id": "268928",
"Score": "2",
"Tags": [
"c++",
"beginner",
"game",
"tic-tac-toe"
],
"Title": "tic-tac-toe game with a vector"
} | 268928 |
<p>I did a lot of research trying to find a React Native component which could reference its own dimensions in order to scale different elements in its style, but could not find any solid examples. I created a hook which boils a component's dimension down to its simplest, easiest to use components and this is what I co... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T21:45:50.303",
"Id": "268931",
"Score": "1",
"Tags": [
"beginner",
"typescript",
"jsx",
"react-native"
],
"Title": "Typescript React-Native Component Dimension Hook"
} | 268931 |
<p>Find shape of n-dim array that'd be formed from nested list of lists with variable lengths if we were to pad the lists to same length at each nest level. E.g.</p>
<pre><code>ls = [[1],
[2, 3],
[4, 5, 6]]
# (3, 3) because
ls_padded = [[1, 0, 0],
[2, 3, 0],
[4, 5, 6]]
</code></pre... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-13T01:22:33.863",
"Id": "530455",
"Score": "0",
"body": "Is there a reason you're seemingly rewriting [basic NumPy functionality](https://numpy.org/devdocs/reference/generated/numpy.shape.html) here? Why not use NumPy to manage your ar... | [
{
"body": "<p>Get the length of the longest row, then pad each row with a sufficient number of zeros.</p>\n<pre><code>from itertools import islice, repeat, chain\n\n\ndef pad(x):\n zeros = repeat(0)\n n = maximum(map(len, x))\n return [list(islice(chain(row, zeros), n)) for row in x]\n</code></pre>\n<p... | {
"AcceptedAnswerId": "269021",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-12T23:35:09.490",
"Id": "268932",
"Score": "1",
"Tags": [
"python",
"array",
"iteration",
"nested"
],
"Title": "Variable length nested list of lists pad shape"
} | 268932 |
<p>As part of a larger project, I've written the following code for interacting with <a href="https://git-annex.branchable.com/git-annex-addurl/" rel="nofollow noreferrer">git-annex's <code>addurl</code> command</a> in batch mode. <code>addurl</code> takes a series of URLs and output filepaths on stdin, and it outputs... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-11-01T05:19:58.413",
"Id": "531905",
"Score": "0",
"body": "For anyone who finds this post later: I ended up rewriting this code using [trio](https://trio.readthedocs.io/en/stable/), and I expanded it a bit into a package: https://github.... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-13T01:35:19.987",
"Id": "268933",
"Score": "2",
"Tags": [
"python",
"python-3.x",
"asynchronous",
"asyncio"
],
"Title": "Asynchronous line-based communication with an external pr... | 268933 |
<p>I started out to learn more about C to learn more about low level programming and hardware and I can improve.</p>
<p>It generates a random number between 1 and 4 then stores it into two variables.</p>
<p>It takes in to x,y board values ranging to 1,4 in the board then if the two inputs equal the random values it giv... | [] | [
{
"body": "<h3>Naming conventions</h3>\n<p>There doesn't seem to be one definite naming convention for C, but there's still something to be said here.</p>\n<ul>\n<li>I haven't seen functions in <code>SCREAMING_SNAKE_CASE</code>, they are usually written in something like <code>snake_case</code> or <code>camelCa... | {
"AcceptedAnswerId": "268941",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-13T04:00:01.000",
"Id": "268935",
"Score": "6",
"Tags": [
"beginner",
"c",
"game",
"battleship"
],
"Title": "Console battleship game made in C"
} | 268935 |
<p>So I've created this Header to include in all my PHP files, and think everything works as it should for now. But since it's the first time I'm creating one, I wanted to have it reviewed just to learn from you guys.</p>
<p><code>LocalStorage</code> doesn't work on stackoverflow, so to try this the example code have t... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-13T06:57:27.033",
"Id": "268939",
"Score": "0",
"Tags": [
"javascript",
"html",
"css"
],
"Title": "Creation of a header file"
} | 268939 |
<p>I am coding a Splay Tree class in C++. I am looking for code review.</p>
<p>Currently, my Splay Tree class has search and rotate function.</p>
<p>I feel that I'm doing things overcomplicated.</p>
<pre><code>#include <iostream>
#include <string>
#include <fstream>
#include <regex>
using names... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T02:01:00.107",
"Id": "530531",
"Score": "0",
"body": "`key = root->key; // Modifies the outer-scoped variable` does it?!"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T07:43:43.460",
"Id": "53054... | [
{
"body": "<p><a href=\"https://stackoverflow.com/questions/1452721\">Don’t</a> write <code>using namespace std;</code>.</p>\n<p>You can, however, in a CPP file (not H file) or inside a function put individual <code>using std::string;</code> etc. (See <a href=\"https://github.com/isocpp/CppCoreGuidelines/blob/... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-13T07:30:29.013",
"Id": "268940",
"Score": "2",
"Tags": [
"c++",
"algorithm"
],
"Title": "C++ Splay Tree implementation"
} | 268940 |
<p>Not sure if I have gone over board with this or if I have even approached it correctly.</p>
<p>Basic I wanted to created classes which fulfilled the following:</p>
<ul>
<li>Single class that can be used to create a connection to either a known Redis or Mysql DB</li>
<li>Decoupled classes for DI (Eventually)</li>
<li... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-13T14:44:51.643",
"Id": "268951",
"Score": "0",
"Tags": [
"design-patterns",
"php7"
],
"Title": "PHP Class(es) for setting up DB adaptor"
} | 268951 |
<p><strong>I have attempted [and made one] function to convert string to integer and catch errors in pure c</strong></p>
<p><em><strong>Working method</strong></em></p>
<p>The whole working method is present in code itself</p>
<p><em>The header file</em></p>
<p><em>The str2num.h here:-</em></p>
<pre class="lang-c prett... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T17:02:36.627",
"Id": "530599",
"Score": "0",
"body": "Hmmm, \"Convert string to integer and catch errors\" and test code uses [`gets()`](https://stackoverflow.com/q/1694036/2410359)???"
},
{
"ContentLicense": "CC BY-SA 4.0",... | [
{
"body": "<p>There are a few things about your code that can be improved.</p>\n<h2>Style</h2>\n<p>You obviously <em>have</em> a style, which is to the good. But it's one I have some problems with:</p>\n<ol>\n<li><p>Spaces. I don't know why you are so chary with your horizontal space, but I suggest you amend yo... | {
"AcceptedAnswerId": "268978",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-13T14:50:49.333",
"Id": "268952",
"Score": "2",
"Tags": [
"c",
"strings",
"converting",
"integer"
],
"Title": "Convert string to integer and catch errors"
} | 268952 |
<p>Due to recent need I wrote a simple <code>main</code> function that has the goal to convert the C-style strings and arrays into a more STL-style. Then because I also had a need for it, I created a variation that converts all the involved <code>std::string</code>s into <code>std::wstring</code>s.</p>
<p>So essentiall... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T10:18:25.620",
"Id": "530558",
"Score": "0",
"body": "No I'm compiling this with C++17, but the code itself works up until C++11, that's why I tagged it that way."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "... | [
{
"body": "<p>This is not as portable as we'd like it to be. Instead of assuming that the arguments are supplied as UTF-8 bytes, we ought to use the local character encoding, as used by <code>std::locale{""}</code>.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"Cont... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-13T16:51:04.830",
"Id": "268958",
"Score": "3",
"Tags": [
"c++",
"strings",
"c++17",
"converting"
],
"Title": "Convert program arguments to std::wstring"
} | 268958 |
<p>I'm building a contact manager with Flask for a community group, and I'm working on the function to export contacts as a spreadsheet. I want to export either all contacts, only those who have been assigned to a ticket seller, only those assigned to a <strong>specific</strong> ticket seller, or those assigned to <str... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-13T17:08:22.143",
"Id": "268959",
"Score": "0",
"Tags": [
"python",
"flask"
],
"Title": "Rendering Radio Buttons Individually in WTForms/Jinja2"
} | 268959 |
<p>I have the following code snippet:</p>
<pre><code>for index, row in df.iterrows():
if row['MSI Status'] == 'MSS':
print(row['Patient ID'])
for dirpath, dirnames, filenames in os.walk(path):
for dirname in dirnames:
joined_path = os.path.join(path, dirname)
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-13T19:03:40.760",
"Id": "530507",
"Score": "1",
"body": "What does the file structure look like?"
}
] | [
{
"body": "<ul>\n<li><p>You should make a function to contain the <code>os.walk(path)</code>. As both walks are almost identical, the difference is the destination directory.</p>\n</li>\n<li><p>You're not walking correctly. If I have the file structure:</p>\n<pre><code>──.\n └─test\n └─test_nested\n └─... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-13T17:55:19.713",
"Id": "268961",
"Score": "0",
"Tags": [
"python",
"file-system",
"pandas"
],
"Title": "Combining iterrows of pandas with os.walk given I have a lot of directories"
... | 268961 |
<p>This question applies to any language with flatMap -- e.g. functional languages -- but I'll use an example in JavaScript.</p>
<hr />
<p>I'm working my way through <a href="http://reactivex.io/learnrx/" rel="nofollow noreferrer">Functional Programming in JavaScript</a>, which is a set of exercise for learning rxjs. H... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T06:54:40.507",
"Id": "530540",
"Score": "1",
"body": "Welcome to Code Review! Please [edit] your question so that the title describes the *purpose* of the code, rather than its *mechanism*. We really need to understand the motivati... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-13T23:59:33.383",
"Id": "268967",
"Score": "0",
"Tags": [
"javascript",
"functional-programming",
"comparative-review",
"rxjs"
],
"Title": "Multiple flatMap style: Nested or sequ... | 268967 |
<p>I have this view in SwiftUI; it works as expected, and for the most part, works great. My only concern with it is that it feels extremely clunky. Reading through the view itself is very difficult. Does anyone have recommendations for cleaning this thing up?</p>
<p>Effectively, the sign in and register pages both hav... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T00:27:12.050",
"Id": "268968",
"Score": "0",
"Tags": [
"gui",
"swiftui"
],
"Title": "SwiftUI Reusable Login & Register View"
} | 268968 |
<p>Have this code do what I want: If there is argument pass to constructor, initialize; otherwise, set it to default value?</p>
<pre><code>class Node
{
public:
Node(string id, bool isNum, int level, string data, bool duplicate, Node *next)
: id(id), isNum(isNum), level(level), data(data), duplicate(duplic... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T07:27:36.627",
"Id": "530546",
"Score": "0",
"body": "It's usually a good idea to write the initialisers in the same order as the members, to avoid reader confusion when there's a dependency - remember that initialisers execute in t... | [
{
"body": "<p>Don't use default arguments, but provide various overloaded constructors like this</p>\n<pre><code>#include <string>\n\nclass Node\n{\npublic:\n // pass string by const reference, this avoids unecessary copying of the string\n // pass all other arguments as const, initializer is not su... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T06:33:42.993",
"Id": "268972",
"Score": "-1",
"Tags": [
"c++"
],
"Title": "Refactoring class member initialization C++"
} | 268972 |
<p>Here are implementations of both non-const and const view of submatrices,
which is a subclass of my toy C++ matrix project: (<a href="https://codereview.stackexchange.com/questions/260197/c20-n-dimensional-minimal-matrix-class">C++20 : N-dimensional minimal Matrix class</a>)</p>
<p>MatrixView.h</p>
<pre><code>templa... | [] | [
{
"body": "<h1>Unnecessary use of <code>using</code></h1>\n<p>You are publicly inheriting from <code>MatrixBase<...></code>, so there is usually no need to use <code>using Base::...</code> to explicitly bring member functions and operator overloads into the derived class. The only reason to do this is if ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T07:22:39.540",
"Id": "268975",
"Score": "3",
"Tags": [
"c++",
"c++20"
],
"Title": "View of submatrix, in const and non-const form, preserving const-correctness"
} | 268975 |
<p>Following is bubble sorting code.</p>
<p>I tried bubble sort after reading theory. Please let me know if my solution is correct and if so anyway I can make it more efficient?</p>
<pre><code> static int[] BubbleSort(int[] arr)
{
int count = arr.Length;
while (count > 0)
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T15:22:32.527",
"Id": "530585",
"Score": "6",
"body": "*\"let me know if my solution is correct\"* - it is up to you to determine if it is correct or not, preferably with automated unit tests. If it is not correct, it does not belong... | [
{
"body": "<p>Let me show you how you can setup an environment where you can safely experiment with optimisation probes. I'll use <a href=\"https://benchmarkdotnet.org/\" rel=\"nofollow noreferrer\">BenchmarkDotNet</a> for this purpose, which might seem an overkill for this simple use case. But it demonstrates ... | {
"AcceptedAnswerId": "269018",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T14:21:06.820",
"Id": "268983",
"Score": "2",
"Tags": [
"c#"
],
"Title": "Is my approach to bubble sort correct?"
} | 268983 |
<p>I'm learning Dynamic Programming and trying to solve this Target Sum array problem. I've to find an array of integers that sums to a given target sum using the integers of given input array. I've used memoization technique but still getting TLE. Can somebody help what I might be doing wrong. This is my code:</p>
<pr... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T15:20:23.840",
"Id": "530584",
"Score": "0",
"body": "\"_Can somebody help what I might be doing wrong._\" Code Review is for reviewing working code, looking for: security holes, hidden bugs, clarity, maintainability, inefficiencie... | [
{
"body": "<p>In your memoization you cannot distinguish between target sums that have not been evaluated, and ones that you have evaluated but have no solution. This results in re-running these unsuccessful possibilities.</p>\n<p>You should add some way to tell these two cases apart: Either use an empty vector... | {
"AcceptedAnswerId": "268987",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T14:48:16.463",
"Id": "268985",
"Score": "1",
"Tags": [
"c++",
"time-limit-exceeded",
"dynamic-programming"
],
"Title": "Target Sum array using Dynamic Programming"
} | 268985 |
<p><strong>What do I need help with?</strong></p>
<p>I'm doing the challenge below, in which I need to increase code performance. It's currently at 63% and I need to increase it to at least 71% however I can't optimize more than the current one.<br />
How can it be optimized?</p>
<blockquote>
<p><strong>Introduction</s... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T16:35:30.243",
"Id": "530596",
"Score": "1",
"body": "This fails but should succeed: `my_analyzer = DrugAnalyzer(); my_new_analyzer = my_analyzer + ['G03-01', 789.01, 129.00, 0.00008]`"
},
{
"ContentLicense": "CC BY-SA 4.0",... | [
{
"body": "<ul>\n<li><p><code>__init__</code> has a mutable default argument. The default argument is <em>not</em> reset between calls to a function, so multiple analyzers that start out empty will have <em>the same</em> list, which could be a problem if one of them changes:</p>\n<pre class=\"lang-py prettyprin... | {
"AcceptedAnswerId": "268994",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T16:00:04.010",
"Id": "268988",
"Score": "2",
"Tags": [
"python",
"performance",
"python-3.x",
"programming-challenge"
],
"Title": "Drug Analyzer challenge"
} | 268988 |
<p>I have used below method for throttling which is a Higher Order Function (HOF), but find some difficulties to choose which one is better way to write it. Below are both methods.</p>
<ol>
<li>return of the <code>setTimeout()</code> assigned in a variable</li>
</ol>
<pre><code>const throttle = (fn, delay) => {
le... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T16:33:59.827",
"Id": "268989",
"Score": "1",
"Tags": [
"javascript",
"functional-programming",
"comparative-review",
"meta-programming"
],
"Title": "Higher-order function to d... | 268989 |
<p>I have very recently learned some Python and found out about web scraping.</p>
<p>This is my first bash at writing some code to get a playlist from a site I had previously been copying and pasting. I would love it if someone could have a look at the code and review it for me. Any advice, tips, suggestions welcome.</... | [] | [
{
"body": "<p>I don't think the CSV format is benefiting you all that much here. You haven't written header names, and it seems you only have one column - and maybe only one row? Either you should have multiple columns with headers, or give up on CSV and just call it a text file.</p>\n<p>Otherwise:</p>\n<ul>\n<... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T16:38:00.860",
"Id": "268990",
"Score": "2",
"Tags": [
"python",
"web-scraping",
"beautifulsoup"
],
"Title": "Web scraping playlist from website and writing to CSV"
} | 268990 |
<p>I need to classify URLs from a DataFrame and modify it by exact match and contains conditions:</p>
<pre><code>class PageClassifier:
def __init__(self, contains_pat, match_pat):
"""
:param match_pat: A dict with exact match patterns in values as lists
:type match_pat: dict
... | [] | [
{
"body": "<p>The first thing I notice here that will tank performance the most is:</p>\n<pre><code>new_pd = pd.concat([new_pd, classify.worker(chunk)])\n</code></pre>\n<p>cs95 outlines this issue very well in <a href=\"https://stackoverflow.com/a/56746204/15497888\">their answer here</a>. The general advice is... | {
"AcceptedAnswerId": "269005",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T19:00:27.540",
"Id": "268992",
"Score": "1",
"Tags": [
"python",
"python-3.x",
"csv",
"pandas"
],
"Title": "How to speed up the search by patterns matching and modifying a... | 268992 |
<p>Realize the Radio and Channel classes that represent radio and a radio station. The radio class offers an argumentless constructor and the following methods:</p>
<ul>
<li>addChannel: stores and returns a new station, characterized by name, frequency. Attempting to store a station that has the same frequency as an al... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-15T10:14:11.703",
"Id": "530638",
"Score": "0",
"body": "@dariosicily `comp` is a static final field after the constructor. Unusual, but working."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-15T10:18:51... | [
{
"body": "<p><strong>Advice 1: missing package</strong></p>\n<p>I suggest you put your classes into a package. Consider something like:</p>\n<pre><code>package com.github.giuseppe.radio;\n\nimports...\n\ncode...\n</code></pre>\n<p><strong>Advice 2</strong></p>\n<pre><code>import java.util.*;\n</code></pre>\n<p... | {
"AcceptedAnswerId": "269016",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T21:26:58.673",
"Id": "268999",
"Score": "2",
"Tags": [
"java",
"array",
"iterator",
"lambda",
"set"
],
"Title": "Radio with channels"
} | 268999 |
<p>Given the following data struct:</p>
<pre><code>typdef struct lista {
int num1, num2;
struct lista* sig;
} nodoNum ;
</code></pre>
<p>and a declared <code>nodoNum</code> pointer variable, the following function will take said variable and create nodes, link them and stop when the user inputs "0" as... | [] | [
{
"body": "<p>There is a small typo in this line:</p>\n\n<pre class=\"lang-cpp prettyprint-override\"><code>typdef struct lista {\n</code></pre>\n<p>It should be</p>\n<pre class=\"lang-cpp prettyprint-override\"><code>typedef struct lista {\n</code></pre>\n<p>I ran <code>sig</code> through Google translate and ... | {
"AcceptedAnswerId": "269014",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-14T22:56:26.350",
"Id": "269000",
"Score": "3",
"Tags": [
"beginner",
"c",
"linked-list"
],
"Title": "Function to create single linked-list"
} | 269000 |
<p>here it is my simple cash register app. It lacks some functionality ( <code>class Payments</code> should have more options like daily statements etc, <code>class TillSettings</code> needs more settings as well) but it does the job. Simple Cash Register and Stock Manager allows to add items to stock and then sell it ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-15T09:08:11.433",
"Id": "530632",
"Score": "0",
"body": "I can't run the code because `list[Any]` in line 458 causes error, is it because it's written in old python?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "... | [
{
"body": "<h2>Violation of <a href=\"https://pep8.org/\" rel=\"nofollow noreferrer\">PEP8</a></h2>\n<p>According to <a href=\"https://pep8.org/\" rel=\"nofollow noreferrer\">PEP8</a>,</p>\n<ul>\n<li>Imports should be on seperate lines.</li>\n<li>Surround top-level function and class definitions with two blank ... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-15T00:32:49.957",
"Id": "269002",
"Score": "4",
"Tags": [
"python",
"beginner",
"tkinter"
],
"Title": "Simple Cash Register -Python"
} | 269002 |
<h1>Simple Disjoint Set Implementation</h1>
<p>I had not implemented a <code>DisjointSet</code> before and the following is my attempt at implementing a very simple <code>DisjointSet</code> for learning purposes.</p>
<p>When <code>union</code>-ing sets, the goal was to implement union-by-size.</p>
<h1>Approach</h1>
<p>... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-15T11:15:56.360",
"Id": "530647",
"Score": "0",
"body": "You might be interested in the following post: https://codereview.stackexchange.com/questions/267718/comparing-8-different-disjoint-set-data-structure-variants-in-java"
},
{
... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-15T06:48:41.093",
"Id": "269007",
"Score": "0",
"Tags": [
"java",
"union-find"
],
"Title": "Implementation for Simple Disjoint Set"
} | 269007 |
<p>Got this problem in a coding interview -
Get the max value of a stack in O(1).
The stack contains numbers only.
Please review my solution.</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-... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-17T11:09:08.397",
"Id": "530763",
"Score": "0",
"body": "The code does not work. If you `push` `[2, 1, 5]` the max is 5. However if you `pop` the 5 the max remains 5 (should be 2)., If you then push a 4 the max is still 5 (should be 4)... | [
{
"body": "<p>This solution looks incorrect and doesn't cover the case when the max value is popped.</p>\n<p>For example,</p>\n<pre class=\"lang-javascript prettyprint-override\"><code>const stack = new Stack();\nstack.data = [];\nstack.insert(1);\nstack.pop();\nconsole.log(stack.maxVal); // even though stack i... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-15T13:23:38.687",
"Id": "269013",
"Score": "3",
"Tags": [
"javascript",
"interview-questions",
"ecmascript-6",
"stack"
],
"Title": "Check for max value in stack"
} | 269013 |
<p><strong>Problem definition : Array partition problem</strong></p>
<p>Given an array of positive integers, divide it into three disjoint subsets having equal sum. These disjoint sets cover the complete array.</p>
<p><strong>Example</strong>
Input: [7, 6, 1, 7] Output: [[7], [6, 1], [7]]</p>
<p>Input: [7, 6, 2, 7] Out... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-15T21:18:11.210",
"Id": "530679",
"Score": "0",
"body": "Your problem description has output of list values. Your solution outputs list indices. Why?"
}
] | [
{
"body": "<h1>PEP 8</h1>\n<p>The <a href=\"https://pep8.org/\" rel=\"nofollow noreferrer\">Style Guide for Python Code</a> has a several conventions all Python programmers should follow. You deviate from the guidelines in a few minor areas.</p>\n<ul>\n<li>Binary operators should be surrounded by a space. You... | {
"AcceptedAnswerId": "269022",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-15T20:00:48.957",
"Id": "269020",
"Score": "2",
"Tags": [
"python",
"python-3.x",
"algorithm",
"array",
"dynamic-programming"
],
"Title": "Divide array into three disjoin... | 269020 |
<p>The goal is to have a function that can sort a series of all object types that implement the comparable interface. I'm not trying to improve the performance of the sort. I'm only trying to optimize my use of generics.</p>
<p>I currently use <code>T extends whatever</code> and <code>T[]</code>, however I was also con... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T22:31:19.300",
"Id": "530989",
"Score": "0",
"body": "Er, there is a space too many after `main(` and before the closing `)` - not consistent ;)"
}
] | [
{
"body": "<p>Welcome to Code Review, the use of <code><T extends Comparable<T>></code> and <code>T[]</code> looks fine to me and personally I would not change it. The only one thing I am not agree is about the indexes you use to order one array like below :</p>\n<pre><code>Quicksort.sort(stringList... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-15T22:19:01.907",
"Id": "269024",
"Score": "3",
"Tags": [
"java",
"sorting",
"generics",
"quick-sort"
],
"Title": "Quicksort using generics in java"
} | 269024 |
<p>The program is supposed to be set as the default browser in Windows and allows me to select which browser profile I want to use when I open a link from another program. I have quite some experience in PHP, Java, C, C++, Pascal, but this is my first venture into Rust. Before I continue adding features I'd like to kno... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-16T05:35:12.120",
"Id": "269026",
"Score": "1",
"Tags": [
"beginner",
"rust"
],
"Title": "Interactive browser launcher in Rust using Native Windows GUI"
} | 269026 |
<p>Recently, I was studying flask and my friend sent me a bit.ly link. Then the idea of a bit.ly clone struck my mind.</p>
<p>This project uses</p>
<ul>
<li>Python - 3.10.0</li>
<li>flask - version 2.0.2</li>
<li>Bootstrap CSS. (I am very bad at CSS)</li>
<li>sqlite3</li>
</ul>
<p>I would appreciate you thoughts and im... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-16T07:53:01.470",
"Id": "269030",
"Score": "1",
"Tags": [
"python",
"sqlite",
"flask"
],
"Title": "bit.ly Clone in Python powered by Flask"
} | 269030 |
<blockquote>
<p><strong>Input</strong><br />
The first line of input contains a string s: the word misspelled
by your partner. Assume that your partner did not add or remove any
letters; they only replaced letters with incorrect ones. The next line
contains a single positive integer n indicating the number of possible
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-16T13:59:56.697",
"Id": "530713",
"Score": "0",
"body": "Related: [Calculate Levenshtein distance between two strings in Python](https://codereview.stackexchange.com/questions/217065/)."
},
{
"ContentLicense": "CC BY-SA 4.0",
... | [
{
"body": "<h1>Code Review</h1>\n<p>Your code doesn't pass all of the test cases, so by some definitions, it is not ready for a code review. However, it is close enough to working and has several code-habits that should be corrected, that I'll give you a Code Review anyway.</p>\n<h2>Variable names</h2>\n<p>Bot... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-16T10:00:30.540",
"Id": "269031",
"Score": "2",
"Tags": [
"python",
"beginner",
"python-3.x",
"programming-challenge"
],
"Title": "Find the closest match to a string"
} | 269031 |
<p>I've created a simple Snakes and Ladders game. The goal is improving my knowledge about OOP.There are some basic rules.</p>
<ol>
<li>I need to be able to move my token.</li>
<li>The token starts in the square 1.</li>
<li>If the token is on square 1 and is moved by 3 then the token is on square 4.</li>
<li>A player c... | [] | [
{
"body": "<ul>\n<li><p>When an array is created, it is nulled automatically. <code>Array.Clear(board, 0, board.Length);</code> is obsolete.</p>\n</li>\n<li><p>Rolling the dice: You are waiting a few milliseconds before creating the <code>Random</code> object to get different seeds. Better: Create it as a stati... | {
"AcceptedAnswerId": "269039",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-16T12:46:00.130",
"Id": "269035",
"Score": "3",
"Tags": [
"c#",
"object-oriented"
],
"Title": "Snakes and Ladders OOP"
} | 269035 |
<p>I have created a simple server that host html that has css. Please make sure if ur testing then change the paths relative to ur system in listhell.c in respond_main(..) function.</p>
<p>The html file has to be named as html9.html and css has to be named as style9.css should be path to ../project directory/css direct... | [] | [
{
"body": "<p>In this part:</p>\n\n<pre class=\"lang-cpp prettyprint-override\"><code>struct connection *con_obj=malloc(sizeof(struct connection));\nif(con_obj!=NULL)\n</code></pre>\n<p>You have checked if malloc succeeded, but then you print a warning and continue on. Consider using <code>assert</code> to test... | {
"AcceptedAnswerId": "269064",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-16T14:43:56.247",
"Id": "269036",
"Score": "1",
"Tags": [
"c",
"linux",
"http",
"socket",
"server"
],
"Title": "Simple server to host simple website page with css"
} | 269036 |
<p>I have a solution to the following question which seems straightforward enough. However, I feel as if I am missing something.</p>
<p>The question: Objective: You have given a character ‘A’ which is already printed. You are allowed to perform only 2 operations –</p>
<p>Copy All – This operation will copy all the prin... | [] | [
{
"body": "<ul>\n<li><p>The approach is correct. It may be optimized a bit.</p>\n<ul>\n<li><p>Use the fact that <span class=\"math-container\">\\$N(p^n) = n(p - 1)\\$</span>. Do not collect identical primes in the list, but just count them.</p>\n</li>\n<li><p>Calling <code>max(factors)</code> is a waste of time... | {
"AcceptedAnswerId": "269045",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-16T15:18:45.767",
"Id": "269038",
"Score": "4",
"Tags": [
"python",
"strings"
],
"Title": "String Manipulation: Given two operations on a character 'A', Copy and Paste, find the mini... | 269038 |
<p>Find all subarrays from a given array in the least possible time complexity.</p>
<p><strong>Requirement:</strong><br />
calculate the square of (sum of even-indexed elements) - (the sum of odd-indexed elements) of al the subarrays.</p>
<p><strong>Explanation of above code:</strong><br />
I am iterating the array, an... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-16T21:06:57.903",
"Id": "530727",
"Score": "0",
"body": "Welcome to Stack Review, I understand how you find the subarrays of one array like the title of your question, but I don't understand the part about sum of even and odd elements.... | [
{
"body": "<h3>Naming</h3>\n<p>Using consistent variable naming with full words usually is considered a good habit. Well, in a small part of the code like this using <code>evnSum</code> instead of <code>evenSum</code> can be justified by length of <code>oddSum</code>; but <code>subarr2</code>, <code>set_size</c... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-16T19:35:34.160",
"Id": "269044",
"Score": "0",
"Tags": [
"java",
"performance",
"algorithm",
"array"
],
"Title": "Calculate square of (sum of even-indexed) - (sum of odd-indexed... | 269044 |
<p>this is my first real website I created after learning about web development.
It's amazing to me that anyone would spare their free time to code review strangers' code. So thank you in advance. I'd like a general feedback and especially on the caching I implemented. The full Code (with ejs templates and media etc) i... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-17T09:52:46.650",
"Id": "530754",
"Score": "0",
"body": "Welcome to Code Review@SE. Time allowing, (re?)visit [How to get the best value out of Code Review](https://codereview.meta.stackexchange.com/q/2436)"
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-16T21:17:43.823",
"Id": "269047",
"Score": "2",
"Tags": [
"html",
"css",
"node.js",
"express.js",
"markdown"
],
"Title": "Simple Markdown Blog"
} | 269047 |
<p>I've seen <a href="https://codereview.stackexchange.com/questions/257344/using-asyncio-and-aiohttp-in-classes">Using asyncio and aiohttp in classes</a> but could not really figure out how to apply this to my own code.</p>
<p>The main idea of this code is to inherit from this RESTClient class whenever I build a new A... | [] | [
{
"body": "<blockquote>\n<p>While creating this bit of code, I ran into a few problems with the asyncio loop that, to be honest, I know very little about.</p>\n</blockquote>\n<p>You are using <code>asyncio</code> very inappropriately.\nYou need to pick one either <code>RestClient</code> is synchronous or asynch... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-16T22:23:54.183",
"Id": "269049",
"Score": "0",
"Tags": [
"python",
"api",
"rest",
"asyncio"
],
"Title": "Python RESTClient Class with asyncio and aiohttp"
} | 269049 |
<p>This is a follow-up question for <a href="https://codereview.stackexchange.com/q/268829/231235">Calculate distances between two multi-dimensional arrays in Matlab</a>. Given a set S<sub>X</sub></p>
<p><span class="math-container">$$
S_{X} = \{ { X_{1}, X_{2}, X_{3}, \dots, X_{n} } \}
$$</span></p>
<p>where n is the ... | [] | [
{
"body": "<p>My only comment here is that</p>\n<pre class=\"lang-matlab prettyprint-override\"><code>AIED = AverageIntraEuclideanDistancesPar(Collection)\nVIED = VarIntraEuclideanDistancesPar(Collection)\n</code></pre>\n<p>computes the average twice, since <code>VarIntraEuclideanDistancesPar</code> also calls ... | {
"AcceptedAnswerId": "269067",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-17T00:00:47.377",
"Id": "269052",
"Score": "1",
"Tags": [
"array",
"multithreading",
"matlab"
],
"Title": "Mean and variance of element-wise distances in a set of multi-dimension... | 269052 |
<p>I wrote the following Bash scripts to make pull-mode backups with <a href="https://restic.net/" rel="nofollow noreferrer">restic</a>, a backup solution written in Golang, similar to Borg Backup. The main use case for this script is pulling backups into a central backup server that you trust, especially if you don't ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-17T01:36:07.353",
"Id": "269055",
"Score": "3",
"Tags": [
"bash",
"security",
"encryption"
],
"Title": "Bash script for pull-mode backups via restic's rest-server"
} | 269055 |
<p>I am making a UI library for the fun of it, and decided to use move semantics instead of pointers with new/delete.</p>
<p>Everything is working, but I am not satisfied.</p>
<p>Given this code:</p>
<pre><code>void ControlGroup::AddControl(Control&& control) noexcept
{
if(control.tabstop)
control.t... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T23:59:52.097",
"Id": "530996",
"Score": "0",
"body": "Also added Window.hpp / Window.cpp in the post."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T04:56:47.860",
"Id": "530999",
"Score": "0... | [
{
"body": "<h2>WndProc setup</h2>\n<p>It's been a while since I've done Windows API stuff, so my memory's kinda fuzzy, but I think there's an issue with how the window procedure is set up in the <code>Window</code> class:</p>\n<p><code>CreateWindowEx</code> only returns after various calls have already been mad... | {
"AcceptedAnswerId": "269177",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-17T05:11:24.403",
"Id": "269056",
"Score": "1",
"Tags": [
"c++",
"c++11",
"winapi"
],
"Title": "Win32 UI with tabs and buttons"
} | 269056 |
<p>I find myself frequently needing to create a new directory and changing to it enough to want to combine the two commands, so I figured it was a good opportunity to practice scripting with bash.</p>
<p>The command I use to create and change to a directory is <code>mkdir -p directory_name && cd directory_name<... | [] | [
{
"body": "<h1>Good</h1>\n<ul>\n<li>consistent indentation</li>\n<li>good error checking</li>\n<li>nice comments</li>\n<li>great quoting of variable substitutions</li>\n<li>yay for putting it all in a function</li>\n<li>good use of <code>case</code> statement for processing options. (Typically this would be in... | {
"AcceptedAnswerId": "269071",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-17T07:27:08.860",
"Id": "269057",
"Score": "2",
"Tags": [
"bash"
],
"Title": "Bash function to create a directory and change to it in a single command"
} | 269057 |
<p>I want to create ENUM which maps different statuses:</p>
<pre><code>public enum BusinessCustomersStatus {
A("active"),
O("onboarding"),
NV("not_verified"),
private String status;
BusinessCustomersStatus(String status)
{
this.status = status;
... | [] | [
{
"body": "<p>About the for in your <code>getStatusByText</code> method :</p>\n<pre><code>BusinessCustomersStatus response = null;\nfor (BusinessCustomersStatus status : values()) {\n if (status.getStatus().equalsIgnoreCase(statusText)) {\n response = status;\n break;\n }\n}\nif(response == nu... | {
"AcceptedAnswerId": "269061",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-17T08:08:05.247",
"Id": "269058",
"Score": "8",
"Tags": [
"java"
],
"Title": "Throw exception if value is not found"
} | 269058 |
<p>I recently came across the <code>OneOf<T0,...,Tn></code> package from <a href="https://github.com/mcintyre321/OneOf" rel="nofollow noreferrer">mcintyre321</a> via a video by <a href="https://www.youtube.com/watch?v=r7QUivYMS3Q" rel="nofollow noreferrer">Nick Chapsas</a>, which presents the idea of holding exce... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T09:44:01.977",
"Id": "530819",
"Score": "4",
"body": "If StackTrace matters for you, then I would suggest to take a look at the [`ExceptionDispatchInfo`](https://codereview.stackexchange.com/questions/256732/rethrowing-unhandled-exc... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "9",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-17T09:30:11.927",
"Id": "269060",
"Score": "1",
"Tags": [
"c#",
"error-handling",
"exception"
],
"Title": "Class to wrap result or exception, similar to the OneOf approach"
} | 269060 |
<p>Created a new typedef and functions supporting it, making it user-friendly [specifically programmer-friendly].</p>
<h4>What does the code do?</h4>
<ul>
<li>It makes users [programmers] easy to deal with strings as most functions are there.</li>
<li>Additionally, we can append, obtain substrings, replace string very ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-11-04T07:13:19.297",
"Id": "532230",
"Score": "0",
"body": "This code has been updated with bugfixes and suggestions! thanks all for reviewing this code. [updated code](https://codereview.stackexchange.com/questions/269720/user-friendly-s... | [
{
"body": "<h1>Don't reimplement <code>bool</code></h1>\n<p>Just <code>#include <stdbool.h></code>. The problem with reimplementing it is that it will now conflict with the definitions from <code><stdbool.h></code>, so someone using both <code><stdbool.h></code> and your string library will ha... | {
"AcceptedAnswerId": "269066",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-17T09:55:31.777",
"Id": "269062",
"Score": "2",
"Tags": [
"c",
"strings"
],
"Title": "User-friendly string struct and utility functions"
} | 269062 |
<p>So I implemented a program that takes an input file, two command strings and an output file to mimick the behaviour of running :</p>
<p><code><input cmd1 -option | cmd2 -option > output</code></p>
<p>that's called like this :</p>
<p><code>./pipe input "cmd1 -opt" "cmd2 -opt" output</code><... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T07:54:03.383",
"Id": "530815",
"Score": "0",
"body": "What's `\"pipex.h\"`? It seems to be essential for this program, but I don't know what I need to install to compile this."
},
{
"ContentLicense": "CC BY-SA 4.0",
"Cr... | [
{
"body": "<h1>Error handling</h1>\n<p>The way you handle error is quite unusual. Why use <code>write()</code> instead of <code>fprintf(stderr, ...)</code>? Why have some error messages stored in a variable like <code>g_empty_string</code>, but other errors messages are passes as literals, like <code>"pipe... | {
"AcceptedAnswerId": "269065",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-17T10:15:29.883",
"Id": "269063",
"Score": "4",
"Tags": [
"c",
"linux"
],
"Title": "Implementing a pipe-like program without wait?"
} | 269063 |
<p>I'm trying to learn OOP with PHP (I know it's hard because It's not an OOP language). I'm rewriting my procedural code to OOP.<br>Please provide any feedback on my code, naming and file/folder structure.</p>
<p>Structure:<br></p>
<pre><code>\classes
Procurement.php
ProcurementDetails.php
\services
DatabaseServ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-17T22:30:58.477",
"Id": "530789",
"Score": "4",
"body": "If you down vote a question please leave a comment explaining why you down voted the question. I don't see anything here that suggests there should be a down vote."
},
{
... | [
{
"body": "<p>Firstly, PHP is 100% an 'OOP' language. It provides you with all the necessary functionality to conform to all of the <a href=\"https://en.wikipedia.org/wiki/Object-oriented_programming\" rel=\"nofollow noreferrer\">OOP principles</a>.</p>\n<p>Secondly, you should definitely familiarise yourself w... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-17T15:56:00.563",
"Id": "269072",
"Score": "4",
"Tags": [
"php",
"object-oriented"
],
"Title": "PHP object oriented programming"
} | 269072 |
<p>I am supposed to write code for an assignment. The goal is to make 2 threads (which are objects of a class that implements runnable) take turns printing the alphabet. One of them prints upper case while the other one prints lower case. (they print only a single letter each turn, not the whole alphabet, just for clar... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T16:47:02.093",
"Id": "530951",
"Score": "0",
"body": "Just a suggestion. Please try to follow the java standard naming conventions when using java to solve a problem. Use camel case when naming any variable. Dont use underscores."
... | [
{
"body": "<p>Welcome to code review! :)</p>\n<p>Here are a few tips to improve your code:</p>\n<ul>\n<li><p>Empty lines have a meaning. Do not just spam emtpy lines every where, as that makes the code harder to read. By removing most of the empty lines, I have reduced you code's number of lines to almost have.... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-17T16:07:21.540",
"Id": "269073",
"Score": "4",
"Tags": [
"java",
"multithreading",
"concurrency"
],
"Title": "2 Threads taking turns printing the alphabet"
} | 269073 |
<p>I play a lot of old-school western CRPGs, and most of them (if not all) require the player to generate an avatar at the start of a new game, including naming the character (with names that will never be pronounced).</p>
<p>I want my character to have the most unique and beautiful name, with as few namesakes as possi... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T04:45:25.157",
"Id": "530797",
"Score": "0",
"body": "I've just chosen the path of least resistance and use a single character for the names, like 'I', 'Z' etc. :)"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": ... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-17T16:28:10.667",
"Id": "269074",
"Score": "3",
"Tags": [
"python",
"python-3.x",
"parsing",
"statistics",
"markov-chain"
],
"Title": "Python program that analyzes a corpus f... | 269074 |
<p>I have solved <a href="https://www.codechef.com/problems/REDALERT" rel="nofollow noreferrer">this problem from the CodeChef platform</a> using the Python prorgamming language</p>
<p>Here is the code:</p>
<pre><code>test_cases = int(input())
for _ in range(test_cases):
n, d, h = [int(x) for x in input().split()]
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-17T22:15:24.667",
"Id": "530787",
"Score": "3",
"body": "Please make the question self contained. E.g include the information from the link =)"
}
] | [
{
"body": "<p>I like your code =) What it does is clear, and your variable names and spacing is correct. There is not much of an algorithm to speak of here, so instead I will focus on structure.</p>\n<p>It is always a good idea to separate inputs from actions. This can be done using a if_main guard, and clear f... | {
"AcceptedAnswerId": "269080",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-17T20:11:20.537",
"Id": "269078",
"Score": "2",
"Tags": [
"python",
"programming-challenge"
],
"Title": "CodeChef - Red Alert"
} | 269078 |
<p>How can I shorten my code for this? There are 6 variable sets of numbers, someone picks a number between 1-63, if their number is in a set, you add the first number of the list to the magic number variable. If it is not, you don't add anything, and move to the next set. I have used multiple while loops, but want a m... | [] | [
{
"body": "<p>Welcome to Code Review! Congratulations on having a working game/project :)</p>\n<p>I have a few pointers to help you minimizing the code length, and probably make it easily extensible. Some of these might be considered personal quirks; so YMMV.</p>\n<h2>The deck</h2>\n<p>You're asking the user if... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T02:27:32.520",
"Id": "269081",
"Score": "7",
"Tags": [
"python"
],
"Title": "Magic number game in Python"
} | 269081 |
<p>I implemented a console version of a news ticker and I will be glad for a code review. It takes a text from the user and displays it for a given period. How may I get it better?</p>
<pre class="lang-cpp prettyprint-override"><code>#include <algorithm>
#include <iostream>
#include <cstdlib>
#include... | [] | [
{
"body": "<p>Generally good. A couple of weaknesses:</p>\n<ul>\n<li>We probably want to exit if <code>std::getline()</code> returns a failed stream. We might want to do the same for an empty input. Personally, I'd probably prefer to accept the message as command arguments, rather than reading standard input... | {
"AcceptedAnswerId": "269086",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T04:33:56.023",
"Id": "269083",
"Score": "2",
"Tags": [
"c++",
"console",
"stl"
],
"Title": "Implementing a News Ticker"
} | 269083 |
<p>While on SO someone posted this question and I gave it a quick try. My solution passed all the testcases.</p>
<p>Link to the problem: <a href="https://codeforces.com/contest/798/problem/A" rel="nofollow noreferrer">Problem: (A) Mike and palindrome</a></p>
<p><strong>Question:</strong></p>
<blockquote>
<p>Mike has a ... | [] | [
{
"body": "<p>Formatting: Don't be so stingy with the indentation, give your code some room to breathe!</p>\n<p>Validating input: You should check if <code>std::cin</code> was successful.</p>\n<p>It is always good if you can split out complexities into functions. Your <code>main</code> function does it all, rea... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T09:04:51.623",
"Id": "269090",
"Score": "0",
"Tags": [
"c++",
"programming-challenge"
],
"Title": "Codeforces - problem: (A) Mike and palindrome"
} | 269090 |
<p>I was trying to implement my own version of <code>matplotlib</code>'s <code>hist</code> function and I came up with this:</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
import numba as nb
from numba import prange
import time
N = 10_000_000
normal = np.random.standard_normal(N)
@nb.jit(parallel=... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T17:59:08.793",
"Id": "530853",
"Score": "1",
"body": "Can you show screenshots of your histogram?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T18:47:35.493",
"Id": "530855",
"Score": "0",
... | [
{
"body": "<p>You are slicing your original dataset 1000 times, making 2000 comparisons with borders for each of the values in it.\nIt is much faster to calculate the proper bin for each value using simple math:</p>\n<pre><code>bin = (value - min_data) / dx\nD[bin][1] += 1\n</code></pre>\n<p>And you can use ori... | {
"AcceptedAnswerId": "269100",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T10:10:34.533",
"Id": "269093",
"Score": "2",
"Tags": [
"python",
"python-3.x",
"numpy",
"matplotlib",
"numba"
],
"Title": "Implementing histogram in python"
} | 269093 |
<p>I want to be able to create a hierarchy of classes and efficiently lookup them by common class attribute value. So far I've come up with this solution:</p>
<pre><code>class IndexedAttr:
def __init__(self):
self.cls = None
self.name = None
def find_cls(self, value):
cls_by_value = sel... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T12:52:24.880",
"Id": "530830",
"Score": "3",
"body": "Please explain what the code is used for, that will help us write better reviews."
}
] | [
{
"body": "<p>It looks like you are trying to implement a "dynamic new": create an object of a class using a string to choose the class object to create. For example:</p>\n<pre class=\"lang-py prettyprint-override\"><code>auths = { 'basic': BasicAuth, 'ntlm': NtlmAuth }\ncls = auths['ntlm']\ncls('pas... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T12:19:31.767",
"Id": "269096",
"Score": "0",
"Tags": [
"python",
"python-3.x"
],
"Title": "Indexing base class attribute overrides: cls -> value"
} | 269096 |
<p>I've gone through the docs in a fair bit of detail and understand that a setState function can be passed a function if the previous state is needed.</p>
<p>Here I am trying to, based on the state of a variable, set the state of another variable. This seems logically correct to me, but just feel weird. Looking for so... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T14:10:40.353",
"Id": "530833",
"Score": "0",
"body": "Did you test it? Does it produce the expected result?"
}
] | [
{
"body": "<p>Use effect requires a second parameter, the list of dependencies for the effect.</p>\n<p>This effect declares that you want to re-compute the items state when command is updated.</p>\n<pre><code>useEffect(() => {\n const items = syncFunc(allowedTags, command);\n setItems(items);\n... | {
"AcceptedAnswerId": "269103",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T12:51:01.060",
"Id": "269098",
"Score": "0",
"Tags": [
"react.js"
],
"Title": "Setting a state variable in an effect based on comparing the value of another state variable"
} | 269098 |
<p>This week I dived into the issue of speeding up my program by either threading or multiprocessing. I did not understand well the difference between the two, but that became quite clear when I got the results.
Below program is processing 12 text data files that has a Pandas DataFrame as output.</p>
<p>It compares the... | [] | [
{
"body": "<p>Overall this looks like throwaway code meant to give you a quick answer. It's not worth trying to improve since you will never re-use or maintain it.</p>\n<p>If you did want to improve it, the issue I'd tackle is that the code is too long and repetitive.</p>\n<h2>Reduce Repetition</h2>\n<ul>\n<li>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T14:06:54.760",
"Id": "269099",
"Score": "0",
"Tags": [
"python",
"multithreading",
"multiprocessing"
],
"Title": "Showcase difference multiprocessing and threading in Python"
} | 269099 |
<p>Please verify jump searching algorithm that I have written and let me know if any bugs are present.
I have tested it from my end, but still would like to get it verified for any missing corner scenarios.</p>
<pre><code>class JumpSearch
{
public static void main(String[] args)
{
int[] input = new int[] { ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T17:07:58.967",
"Id": "530848",
"Score": "1",
"body": "Welcome back to Stack Review, please confirm if your code is referring to [Jump_search](https://en.wikipedia.org/wiki/Jump_search) and include yours tests."
}
] | [
{
"body": "<p>The sheer amount of breaks, and boolean controls, is an immediate red flag. It is a natural consequence of a decision to stuff everything into a single loop. Try to decompose the problem into a smaller chunks instead.</p>\n<p>First, the <code>for</code> loop implements an important algorithm, on i... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T14:25:51.997",
"Id": "269101",
"Score": "2",
"Tags": [
"java",
"algorithm",
"search"
],
"Title": "Please verify Jump searching algorithm"
} | 269101 |
<p>I am trying to implement a <em><strong>Left shift/ Right Shift on arrays</strong></em>.</p>
<p>I was able to accomplish this using double loops.
Can the efficiency be improved?</p>
<p>This is the working code for LeftShift/RightShift which is using 2 nested loops.</p>
<pre><code>#include <iostream>
#include &l... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T19:18:32.027",
"Id": "530859",
"Score": "5",
"body": "This looks like a use-case for `std::rotate`: https://en.cppreference.com/w/cpp/algorithm/rotate"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T2... | [
{
"body": "<p>You can use <code>memmove()</code> function to move overlapping areas of memory and <code>memset()</code> to clear the moved items.</p>\n<p>LeftShift can be implemented like:</p>\n<pre class=\"lang-c prettyprint-override\"><code>#include <string.h>\n\nvoid LeftShift(struct Array *arr, int n)... | {
"AcceptedAnswerId": "269108",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T18:34:51.460",
"Id": "269105",
"Score": "6",
"Tags": [
"c++",
"c",
"array",
"iterator",
"pointers"
],
"Title": "Left Shift/ Right Shift an array in C"
} | 269105 |
<p>For reasons, I want to implement a predicated version of <code>std::for_each</code>. I know that, in C++20, this is made somewhat redundant or less useful, as we can use <code>std::ranges:views::filter</code>; and that a more robust implementation than the one I present below might use conditional iterators (like Bo... | [] | [
{
"body": "<h1>Answers to your questions</h1>\n<blockquote>\n<p>Which version is preferable? The latter has less dependencies, but the former has no raw loops...</p>\n</blockquote>\n<p>If having less dependencies matters, then go for the raw loops. If not, then I don't think it matters much; the lambda in the f... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T21:11:06.020",
"Id": "269112",
"Score": "3",
"Tags": [
"c++",
"template",
"generics",
"stl"
],
"Title": "A predicated version of std::for_each"
} | 269112 |
<p>I had to implement a function for getting the Levenshtein distance of two strings for a problem. It linked to the <a href="https://en.wikipedia.org/wiki/Levenshtein_distance" rel="nofollow noreferrer">Wikipedia Article</a> for Levenshtein distance and mentioned I can use the <a href="https://en.wikipedia.org/wiki/Le... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T12:48:42.947",
"Id": "530920",
"Score": "2",
"body": "You don't actually need such a big array (`d`) because you're only ever accessing two consecutive rows at a time. Hence a `2 x m` array is sufficient, while accessing the two row... | [
{
"body": "<h2>Documentation</h2>\n<p>Add a docstring for <code>levenshtein_distance</code> which explains what Levenshtein distance is. Explain the algorithm (or give a link to some existing explanation) if easy. I count about 5 sections in the algorithm--put a comment above each to explain what it's doing. No... | {
"AcceptedAnswerId": "269118",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-18T23:13:44.007",
"Id": "269117",
"Score": "7",
"Tags": [
"python-3.x"
],
"Title": "Levenshtein distance using dynamic programming in Python 3"
} | 269117 |
<p>I want to create an <em>In Memory Cache</em> in .Net. The primary usage for this cache would be to store addresses... I want to keep around 1000 addresses in memory and once the cache is full, remove the <em>Least Recently Used</em> address from the cache.</p>
<p>Microsoft provide 2 versions of <code>MemoryCache</co... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T06:53:38.970",
"Id": "530888",
"Score": "0",
"body": "is it possible to use timestamp key instead of `string` ? I'm thinking if you were using a timestamp key, then you can just compare the last usage time and the timestamp (which i... | [
{
"body": "<h3>The Least Recently Used cache replacement policy</h3>\n<blockquote>\n<p>I want to keep around 1000 addresses in memory and once the cache is full, remove the Least Recently Used address from the cache.</p>\n</blockquote>\n<p>Based on your description of what you're trying to do, this is called a ... | {
"AcceptedAnswerId": "269157",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T00:57:18.350",
"Id": "269120",
"Score": "2",
"Tags": [
"c#",
"cache"
],
"Title": "Implementing a Most Recently Used Cache"
} | 269120 |
<p>There are six Binary Tree DFS traversals (preorder, inorder, postorder, and their reverse counterparts). Their implementations can be very similar <sup>1</sup>, so I factored out the core logic into a class <code>Traverser</code> (found in the first code block below). As an example, say you want the "inorder&qu... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T03:47:37.030",
"Id": "269121",
"Score": "0",
"Tags": [
"iterator",
"breadth-first-search",
"depth-first-search",
"generator",
"binary-tree"
],
"Title": "Binary Tree DFS an... | 269121 |
<p>I have put together a small node application with <strong>Express.js</strong> and <strong><a href="https://jsonplaceholder.typicode.com" rel="nofollow noreferrer">jsonplaceholder</a></strong>.</p>
<p>On the homepage, it displays posts by all users. You can also filter posts by one user (author).</p>
<p>In <code>app.... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T21:49:47.113",
"Id": "530980",
"Score": "0",
"body": "Could you please [edit] to include the contents of `routes/users.js`? and is `helpers` actually used by the code in `indexController`? If so, what for?"
},
{
"ContentLice... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T05:04:14.653",
"Id": "269122",
"Score": "1",
"Tags": [
"javascript",
"express.js"
],
"Title": "Express.js and jsonplaceholder application"
} | 269122 |
<p>I'd like to have a review on my C-style array wrapper. I based this on std::array implementation. I hope you can leave some feedback!</p>
<h2>array.ixx</h2>
<pre><code>module;
#include <cstddef>
#include <stdexcept>
#include <utility>
#include <type_traits>
#include <compare>
export m... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T15:16:57.357",
"Id": "530933",
"Score": "0",
"body": "It's nice to see _someone_ using modules!"
}
] | [
{
"body": "<pre><code>template<class T, std::size_t N>\nconstexpr const T& stl::array<T, N>::back() const\n{\n return *(_items + N);\n}\n</code></pre>\n<p><strong>bug:</strong> Shouldn't this be accessing element <code>(N - 1)</code>?</p>\n<p>(Same issue with the non-const version).</p>\n<hr ... | {
"AcceptedAnswerId": "269128",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T10:34:48.593",
"Id": "269126",
"Score": "5",
"Tags": [
"c++",
"array",
"c++20"
],
"Title": "C++20 std::array implementation"
} | 269126 |
<p>I have 3 different lists which I get in 3 separate API calls.</p>
<ol>
<li><code>persons</code> 2. <code>cars</code> 3. <code>categories</code></li>
</ol>
<p>What I need to do is:</p>
<ol>
<li>Get <code>persons</code> -> then pull cars ids from the <code>persons</code> list</li>
<li>Gel <code>cars</code> based on... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T19:45:43.850",
"Id": "530964",
"Score": "1",
"body": "Please do not edit the question, especially the code, after an answer has been posted. Changing the question may cause answer invalidation. Everyone needs to be able to see what ... | [
{
"body": "<h1>Inconsistent Requirements</h1>\n<p>You state the following</p>\n<blockquote>\n<p>What I need to do is:\nGet persons -> then pull cars ids from the persons list\nGel cars based on the cares ids I got on #1 -> then pull categories ids from the cars list\nGet categories based on categories ids... | {
"AcceptedAnswerId": "269147",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T10:42:40.667",
"Id": "269127",
"Score": "0",
"Tags": [
"javascript"
],
"Title": "Get data from a chain of lists"
} | 269127 |
<p>I'm learning C++, and would like some guidance. I'm pretty sure I'm doing something wrong.</p>
<p>This algorithm runs in O(n) time and uses O(n) external space. Could I make a more efficient algorithm for doing this, time and memory-wise? Also, could I multi-thread this?</p>
<p>Here is my code. Ignore my coding styl... | [] | [
{
"body": "<pre><code>std::ostream&operator<<(std::ostream&ost,const std::vector<int>&input){\n</code></pre>\n<p>It's not just style.</p>\n<p>Peopledontwritelikethisbecauseitsreally reallyhardtoreadthisiswhatyourcodelookslikedontdoit.</p>\n<p>...</p>\n<p>Please use a reasonable amount of... | {
"AcceptedAnswerId": "269145",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T15:28:04.240",
"Id": "269138",
"Score": "0",
"Tags": [
"c++",
"object-oriented",
"complexity",
"bitwise",
"vectors"
],
"Title": "Separating odd numbers and even number... | 269138 |
<p>At heart, this program is just the basic <a href="https://en.wikipedia.org/wiki/Fizz_buzz" rel="nofollow noreferrer">"FizzBuzz" program</a>. However, the program was pushed further, by making it a client-server via Unix Socket:</p>
<ol>
<li>Server run, and listening on a socket.</li>
<li>Client run with an... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T15:34:23.120",
"Id": "269139",
"Score": "2",
"Tags": [
"json",
"go",
"socket",
"fizzbuzz",
"ipc"
],
"Title": "FizzBuzz JSON via Unix socket (Go)"
} | 269139 |
<p>I got inspired by a recent question to do some benchmarking on the different methods to copy data and this is what I have come up with:</p>
<pre class="lang-cpp prettyprint-override"><code>#include <iostream>
#include <iomanip>
#include <chrono>
#include <vector>
#include <cstring>
cl... | [] | [
{
"body": "<h2>avoid manual memory management</h2>\n<pre><code>int* src = new int[length];\nfor (int i = 0; i < length; i++)\n src[i] = i;\nint* dst = new int[length];\n</code></pre>\n<p>We could use two <code>std::vector<int></code>s for this and avoid the manual memory management. Pointers to the ... | {
"AcceptedAnswerId": "269152",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T15:42:24.917",
"Id": "269140",
"Score": "7",
"Tags": [
"c++",
"performance"
],
"Title": "Benchmarking data copying"
} | 269140 |
<p>I'm writing a function which iterate through a list of objects and should return:
true if all the items have the attributes (cp and type).
false if all the items haven't the attributes (cp and type).
throw an error if one of the attribute is missed in the object.</p>
<pre><code>const checkList = (list) => {
i... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T17:43:33.743",
"Id": "530954",
"Score": "0",
"body": "What is poiDict? I can't see it declared in your code."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T19:10:08.763",
"Id": "530958",
"Sco... | [
{
"body": "<p>As @JaeBradley says, the out-of-memory error doesn't seem to have anything to do with the function you want to to have reviewed, so I'll just do a regular review, but I've added some words about this at the end.</p>\n<h1>Code style</h1>\n<p>Personally I'm not a big fan of using the lambda notation... | {
"AcceptedAnswerId": "269181",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T16:01:25.227",
"Id": "269143",
"Score": "2",
"Tags": [
"javascript",
"performance",
"node.js",
"memory-optimization"
],
"Title": "iterating a big list of objects throws a ... | 269143 |
<p>I want to learn about performance impact of different calculations and influences/optimizations like compiler flags, use of SSE, AVX etc.</p>
<p>I'm going to code some small subroutines which will take place in almost every arithmetic operation in a special program, thus good code, portability and performance do! ma... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T17:29:48.797",
"Id": "530953",
"Score": "0",
"body": "I don't see any mutexes or `std::atomic` types in your code, so I wouldn't call the things you want to measure \"atomic\", just \"small bits of code\"."
},
{
"ContentLice... | [
{
"body": "<p><a href=\"https://stackoverflow.com/questions/1452721\">Don’t</a> write <code>using namespace std;</code>.</p>\n<p>You can, however, in a CPP file (not H file) or inside a function put individual <code>using std::string;</code> etc. (See <a href=\"https://github.com/isocpp/CppCoreGuidelines/blob/... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T17:20:38.293",
"Id": "269148",
"Score": "1",
"Tags": [
"c++",
"performance"
],
"Title": "Little program to measure costly operations"
} | 269148 |
<p>This is for leetcode problem: <a href="https://leetcode.com/problems/majority-element" rel="nofollow noreferrer">https://leetcode.com/problems/majority-element</a></p>
<p>There is something wrong with the way I create solutions, and not sure how to stop doing it. Basically the problem is I always create a count vari... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T19:36:08.813",
"Id": "530961",
"Score": "4",
"body": "Thank you for providing the link, however, links can break. Please include the text of the programming challenge in the question."
},
{
"ContentLicense": "CC BY-SA 4.0",
... | [
{
"body": "<h2>Your code, simplified:</h2>\n<p>Here's an alternative that uses fewer variables. It involves tuple comparisons in <code>max(num_cnt_max, num_cnt)</code>:</p>\n<pre><code>CNT, NUM = 0, 1\nclass Solution:\n def majorityElement(self, nums):\n unique_nums = set(nums)\n num_cnt_max = ... | {
"AcceptedAnswerId": "269159",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T19:33:33.160",
"Id": "269156",
"Score": "-2",
"Tags": [
"python",
"programming-challenge"
],
"Title": "leetcode 169 optimzations reducing complexity"
} | 269156 |
<p>I'm trying to write a program whose input is an array of integers, and its size. This code has to delete each element which is smaller than the element to the left. We want to find number of times that we can process the array this way, until we can no longer delete any more elements.</p>
<p>The contents of the arra... | [] | [
{
"body": "<p>Cannot tell about how to make your solution run faster, but I have some suggestions for the cosmetic issues in your code:</p>\n<p><strong><code>size_t</code> for counting stuff</strong></p>\n<p>Instead of using <code>int</code> values for counting, it is more customary to use <code>size_t</code> i... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T19:43:15.260",
"Id": "269158",
"Score": "1",
"Tags": [
"c++",
"performance",
"algorithm",
"array"
],
"Title": "Count how many iterations of deletion until array is ordered"
} | 269158 |
<p>I was working on <a href="https://leetcode.com/problems/first-unique-character-in-a-string/" rel="nofollow noreferrer">First Unique Character in a String</a></p>
<h2>Question</h2>
<p>Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1.</p>
<p>Example 1... | [] | [
{
"body": "<p>When I execute your solution, I get a result that says that the submission is faster than ~5% of submissions and uses less memory than ~5% of submissions.</p>\n<p>The following solution ran faster than ~94% of submissions and used less memory than ~92% of submissions.</p>\n<pre class=\"lang-javasc... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T20:27:40.607",
"Id": "269161",
"Score": "2",
"Tags": [
"javascript",
"performance",
"algorithm",
"programming-challenge",
"time-limit-exceeded"
],
"Title": "Leetcode First... | 269161 |
<p>would love a review for this hook.</p>
<p>The context:</p>
<ul>
<li>I have a "date slider", which has "today", and previous days</li>
<li>It's possible that a user leaves the app, and when he re-opens it from foreground, it's the next day</li>
<li>In a scenario like this, I'd like to reset the st... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T21:20:42.577",
"Id": "269164",
"Score": "0",
"Tags": [
"react.js",
"react-native"
],
"Title": "React Native useForegroundResettingState hook"
} | 269164 |
<p>This is my implementation of the Pig Latin recommended exercise in The Rust Programming Language book. Any pointers on making this code more idiomatic or run more optimal?</p>
<pre class="lang-rust prettyprint-override"><code>fn pig_latin() {
let s = String::from("Some abobus string 32 text привет абоба 123... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-11-07T16:42:23.600",
"Id": "532573",
"Score": "2",
"body": "Please do not update the code in your question to incorporate feedback from answers, doing so goes against the Question + Answer style of Code Review. This is not a forum where y... | [
{
"body": "<pre><code>let consonant = Vec::from([\n 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r',\n 's', 't', 'v', 'w', 'x', 'y', 'z', 'б', 'в', 'г', 'д', 'ж', 'з', 'й',\n 'к', 'л', 'м', 'н', 'п', 'р', 'с', 'т', 'ф', 'х', 'ц', 'ч', 'ш', 'щ'\n]);\n</code></pre>\n<p>An alternative... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T21:29:12.813",
"Id": "269165",
"Score": "2",
"Tags": [
"strings",
"rust",
"pig-latin"
],
"Title": "The Rust Programming Language Pig Latin"
} | 269165 |
<p>I consistently have code where I need to pull individual chunks of substrings out of a larger string; while I won't get into details, it's easy to replicate in a proof of concept:</p>
<pre><code>var data = "alja5nerjvnalskjnbaeviunreklvnaslidhfvbaelkjnrfvliasndve";
var open = data.Substring(0, 4);
var inpu... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T06:18:01.187",
"Id": "531004",
"Score": "1",
"body": "IMHO this `data.Substring(..., ref data)` looks really weird. I do understand the intent but passing the same parameter twice seems odd. Are you interested about alternative solu... | [
{
"body": "<p>Overloading a built-in string method with an extension method is not a good idea IMO, especially something as well known as <code>Substring</code>.</p>\n<p>I'd also avoid mutating arguments, it's a recipe for confusing code. You do have the <code>ref</code> clue here but it's a practice best avoid... | {
"AcceptedAnswerId": "269183",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-19T22:57:22.493",
"Id": "269170",
"Score": "2",
"Tags": [
"c#",
"strings",
"extension-methods"
],
"Title": "Substring extension method with a method of removal"
} | 269170 |
<p>For a particular problem, I need to have a list that:</p>
<ol>
<li>supports <code>O(1)</code> prepend, and</li>
<li>that I can call <a href="https://docs.python.org/3.9/library/bisect.html?highlight=bisect#bisect.bisect_left" rel="nofollow noreferrer"><code>bisect.bisect_left</code></a> on, which means the list must... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T07:40:08.483",
"Id": "531011",
"Score": "2",
"body": "What python version do you use? From the bisect docs : \"Changed in version 3.10: Added the key parameter.\""
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "... | [
{
"body": "<blockquote>\n<p>Should just use a <code>deque</code>?</p>\n</blockquote>\n<p>No. Unless you're ok with <code>bisect_left</code> taking O(n log n) instead of O(log n).</p>\n<p>Your class doesn't support negative indexes, like lists normally do. Not saying you should add that (up to you, doesn't sound... | {
"AcceptedAnswerId": "269179",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T00:01:01.093",
"Id": "269171",
"Score": "0",
"Tags": [
"python",
"binary-search"
],
"Title": "Python list subclass with O(1) prepend / How to get bisect to work with reverse sorte... | 269171 |
<p>This is a follow-up on my first question, <a href="https://codereview.stackexchange.com/questions/269148/little-program-to-measure-costly-operations">Little program to measure costly operations</a>, thanks for all answers and comments, esp. @JDługosz. I made a second attempt adapting a teaching program I found on th... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T06:58:06.647",
"Id": "531008",
"Score": "1",
"body": "Asking how to port this to C is a separate topic which would probably better be left out from this particular question, and arguably not asked on this site."
}
] | [
{
"body": "<p>You are including several C headers that have C comments on the lines, and then several C++ headers. Don't use C headers. Sometimes, don't use the C library stuff in C++ (e.g. <code>printf</code>; you are also using <code>cout</code>! and this is a small piece of code! Is it just pasted up from... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T06:28:51.743",
"Id": "269173",
"Score": "0",
"Tags": [
"c++",
"performance"
],
"Title": "Little program to measure the 'cost' of CPU-operations"
} | 269173 |
<blockquote>
<p>As firestore don't support in operation for more than 10 items. So I decided to write a code to handle multiple (OR) query and merge them afterwards.</p>
</blockquote>
<p>Suppose I want to show posts of the user you follow (that can be more than 10) . <a href="https://stackoverflow.com/questions/6949450... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T06:33:07.607",
"Id": "269174",
"Score": "0",
"Tags": [
"android",
"kotlin",
"firebase"
],
"Title": "Firestore Paging implementation for multiple OR query Android"
} | 269174 |
<p>the last couple of weeks i have been working on my own WordPress plugin. I am trying to do a class based codebase.</p>
<p>My plugin works correctly, but i don't really know if this is the correct way to develop. I would like to learn the best practices.</p>
<p>To demonstrate, here is my base plugin file:</p>
<pre><c... | [] | [
{
"body": "<p><strong>1. The constructor is not a good place for actions & filters.</strong></p>\n<p>See <a href=\"https://wordpress.stackexchange.com/questions/164121/testing-hooks-callback/164138#164138\">this very detailed answer from WP.SE</a> or <a href=\"https://tommcfarlin.com/wordpress-plugin-constr... | {
"AcceptedAnswerId": "269500",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T08:06:43.790",
"Id": "269175",
"Score": "1",
"Tags": [
"php",
"wordpress"
],
"Title": "Instantiating classes in WordPress plugin"
} | 269175 |
<p>I have been working on an online <strong><a href="https://github.com/Ajax30/Bravecms/" rel="nofollow noreferrer">newspaper/blogging application</a></strong> with <em>CodeIgniter 3.1.8</em> and Twitter Bootstrap 4.</p>
<p>The latest feature added is <em>lazy loading</em> of posts.</p>
<p>From the <strong>Static_model... | [] | [
{
"body": "<h3>I will briefly mention a few things I see in you're snippets.</h3>\n<ol>\n<li>\n<blockquote>\n<p>Is the code DRY enough?</p>\n</blockquote>\n</li>\n</ol>\n<p>Given this line of code:</p>\n<pre class=\"lang-php prettyprint-override\"><code>pageUrl = $(location).attr('href'),\n pageBaseUrl =... | {
"AcceptedAnswerId": "269409",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T10:04:58.777",
"Id": "269178",
"Score": "3",
"Tags": [
"php",
"jquery",
"ecmascript-6",
"ajax",
"codeigniter"
],
"Title": "PHP blogging application with AJAX loading"
... | 269178 |
<p><strong>Problem description</strong></p>
<p>As the title indicates, I want to be able to write to and read from a binary file safely, in the sense that I want to have full control of everything that might go wrong. Since I am somewhat unfamiliar with all the flags of the <code>ofstream</code> class and not sure how ... | [] | [
{
"body": "<h2><code>using namespace std;</code></h2>\n<p>Don't do <code>using namespace std;</code>. It can <a href=\"https://stackoverflow.com/a/1453605/673679\">lead to name collisions and other issues</a>.</p>\n<p>Typing out the full names (e.g. <code>std::cout</code>) avoids such issues, and is also cleare... | {
"AcceptedAnswerId": "270254",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T12:32:53.967",
"Id": "269182",
"Score": "7",
"Tags": [
"file",
"error-handling",
"c++17"
],
"Title": "Robust program to write an array of certain data type to a binary file an... | 269182 |
<p>This is a Python program that finds all possible ways a positive integer <code>num</code> can be expressed a sum of a number of integers between 1 and <code>lim</code> (including both ends).</p>
<p>There is no limit on the number of integers, duplicates are allowed, same elements in different order is considered dif... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T15:35:36.710",
"Id": "531060",
"Score": "0",
"body": "So just want to confirm. The nested dictionaries represent a tree, where each root-to-leaf path has a path sum equal to the target, namely `num`? For completeness, the root can b... | [
{
"body": "<p>In terms of code structure, here are my suggestions:</p>\n<ol>\n<li><p>Move <code>d = dict()</code> to after the argument checks, so that you only create the dictionary if the inputs are valid.</p>\n</li>\n<li><p>The <code>if</code>/<code>else</code> statements inside the <code>for</code> loop can... | {
"AcceptedAnswerId": "269218",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T13:17:26.833",
"Id": "269185",
"Score": "3",
"Tags": [
"python",
"python-3.x",
"mathematics"
],
"Title": "Python program to find all possible ways an integer num can be expres... | 269185 |
<p>I need to implement in Python the formula in the image. The set B is a set of real numbers <span class="math-container">\$-1 \le t \le 1\$</span>. Also, <span class="math-container">\$\mathbb{F}_2\$</span> is a set with the elements 0 and 1. <span class="math-container">\$y_i\$</span> is the <span class="math-contai... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T14:25:33.990",
"Id": "531038",
"Score": "0",
"body": "A quick note: using `if __name__ == '__main__'` is great but you should consider putting all the chunk of code in a `main` function and then just call it under the if. (`if __nam... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T13:39:19.563",
"Id": "269187",
"Score": "3",
"Tags": [
"python",
"performance",
"numpy"
],
"Title": "Implementation of a crypto formula in Python"
} | 269187 |
<p>I used recursion to generate fractal and got the desired result but I think my code can be better</p>
<p>I started using MATLAB a few days ago and since than trying and learning new things.<br>
Now this code generates the fractal exactly as I wanted but I feel like it can a little bit neater.<br>
Any suggestions are... | [] | [
{
"body": "<p>Though MATLAB allows to expand the size of a matrix by assigning to elements outside its bounds, it is always best to <a href=\"https://www.mathworks.com/help/matlab/matlab_prog/preallocating-arrays.html\" rel=\"nofollow noreferrer\">preallocate</a> the array to its final size.</p>\n<p>The <code>f... | {
"AcceptedAnswerId": "269336",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T13:42:02.337",
"Id": "269188",
"Score": "2",
"Tags": [
"performance",
"recursion",
"matlab",
"fractals"
],
"Title": "Recursion to generate fractal"
} | 269188 |
<p>So I've decided to practice I will turn all my scripts etc into GUI apps. So my 36 loc guess the number game turned into 136 loc. It's not the best looking, but it does work and on hard it's actually hard to beat computer sometimes. What are your thoughts guys? After finishing it I am not sure if my approach was rig... | [] | [
{
"body": "<ul>\n<li>You're not using <code>math</code>, so delete that import</li>\n<li><code>is_number</code> has nothing to do with the class, so move it to global scope. Also, this can be simplified with <code>str.isnumeric</code> if the function did what it's named to do. However, it <em>doesn't</em> do wh... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T14:18:16.580",
"Id": "269193",
"Score": "1",
"Tags": [
"python",
"beginner",
"game",
"tkinter",
"number-guessing-game"
],
"Title": "Guess The Number Game with GUI"
} | 269193 |
<p>I was struggling to make the RadioButtons widget look presentable. Either the circles were not round, or the frame had a totally wrong shape, or both (see pictures below, and also <a href="https://stackoverflow.com/questions/66510212/how-to-place-widgets-axes-with-equal-aspect-and-requested-size">this question on SO... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T14:44:48.717",
"Id": "531048",
"Score": "1",
"body": "Are you constrained to using Matplotlib for a UI? This doesn't seem very practical. I would stick to using Matplotlib for plots and something else (tkinter, etc.) for UI. Are the... | [
{
"body": "<ul>\n<li>Use four-space indentation instead of two</li>\n<li>Try not to rely on <code>gcf</code>. Pass around figures explicitly.</li>\n<li>Unpack the return of <code>get_size_inches</code> to a width and a height rather than using indexing.</li>\n<li>Replace your ternary with a call to <code>min</c... | {
"AcceptedAnswerId": "269205",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T14:32:17.783",
"Id": "269197",
"Score": "2",
"Tags": [
"python",
"matplotlib",
"widget"
],
"Title": "RadioButtons with round circles"
} | 269197 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.