body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I know I could've used a <code>&lt;meter&gt;</code> element, but I wanted to try implementing from scratch. The positions are a bit hacky, and I tried to make it responsive but ended up using <code>px</code> anyway. I would like some advice on when and how to use sizing units, if possible. Thanks!</p> <p>P.S. Please...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-10T11:10:52.280", "Id": "256965", "Score": "0", "Tags": [ "javascript", "beginner", "html", "css", "animation" ], "Title": "CSS animated button and custom meter made of divs"...
256965
<p>Any idea how to shorten and improve the program? it's going to take a list included of 22 people and split them into two teams and return the names and teams</p> <pre><code>import random # list of teams teams = ['A', 'B'] # list of players which is inculded of 22 people players = ['a', 'b', 'c', 'd', 'e', ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-10T13:37:51.840", "Id": "507469", "Score": "0", "body": "`Human` doesn't seem to be the best name and the class also seems unneccessary - why does `Player` inherit from it instead of just taking the list itself?" }, { "ContentL...
[ { "body": "<p>Honestly, your code is pretty compact already. There are really only 2 areas that I think can be shortened.</p>\n<ol>\n<li>The <code>get_team</code> method of <code>Player</code>.</li>\n</ol>\n<pre><code> def get_team(self):\n random.shuffle(self.name)\n return {'A':self.name[0::2...
{ "AcceptedAnswerId": "256994", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-10T11:16:38.067", "Id": "256966", "Score": "4", "Tags": [ "python", "classes" ], "Title": "random team distributer" }
256966
<p>I have made a random password generator using a class called <code>password</code> and a method called <code>generate</code>.</p> <p>My program works as it should. It generates a random password determined by the users preferences for length, upper or lowercase, numbers and special characters.</p> <p>I was just wond...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-10T12:01:49.287", "Id": "507454", "Score": "0", "body": "You can store various thinks in a dict, then access them on a the key. I've not pythoned for a long time, so I'm not confident enough to write a whole answer." }, { "Cont...
[ { "body": "<p>You can use the ternary operation to reduce the vertical space, i.e. <code>x = a if condition else b</code>. This sets <code>x</code> to <code>a</code> if <code>condition</code> is true and to <code>b</code> otherwise.</p>\n<p>You can also use a dictionary to map a string to some object, like</p>\...
{ "AcceptedAnswerId": "256969", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-10T11:43:11.870", "Id": "256967", "Score": "2", "Tags": [ "python" ], "Title": "Is there anyway to use less if statements in my function?" }
256967
<p>I want to calculate the <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.ttest_ind.html" rel="nofollow noreferrer">scipy.stats.ttest_ind()</a> for numeric columns in a pandas DataFrame with the binary target variable.</p> <pre><code>import pandas as pd from scipy import stats </code></pre> <...
[]
[ { "body": "<p>There may be a bug in your code. Look at these two lines:</p>\n<pre class=\"lang-py prettyprint-override\"><code> group1 = df.where(df[target] == 0).dropna()[column]\n group2 = df.where(df[target] == 1).dropna()[column]\n</code></pre>\n<p>What is happening here? First, the <code>wher...
{ "AcceptedAnswerId": "257115", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-10T11:52:35.720", "Id": "256968", "Score": "1", "Tags": [ "python", "pandas", "statistics" ], "Title": "T-test Independence for a Pandas DataFrame" }
256968
<p>I have 3 checkbox's with 8 different combinations and outcomes.</p> <ul> <li>Selecting no checkboxes shows no divs.</li> <li>Selecting one checkbox shows the colored div.<br /> For example; clicking the red checkbox.</li> <li>Selecting two checkboxes shows the color1+color2 div. But doesn't show either of the single...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-10T13:34:50.273", "Id": "507468", "Score": "0", "body": "This question is lacking any explanation of what the code should _do_. \"3 checkbox's with 8 different combinations and outcomes\" doesn't explain what value this has to the use...
[ { "body": "<p>A few notes on your code:</p>\n<ul>\n<li>If you don't need supporting of very old or non-standard browsers, and given that your project does not relies heavily on jQuery, vanilla JavaScript can do the same work, without jQuery's overhead.</li>\n<li>On each checkbox click, all coloured divs are que...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-10T12:14:58.113", "Id": "256970", "Score": "0", "Tags": [ "javascript", "jquery" ], "Title": "Selecting multiple checkboxes to show similar but different boxes" }
256970
<p>I have built a housekeeping script and I would like to improve it. I have a JSON file with the details such as directory path, number of days after which the directory or file should be zipped, deletion period for the zip as well as if it's files or directories that we are zipping.</p> <p>Config JSON file:</p> <pre>...
[]
[ { "body": "<pre><code>class housekeeping(object):\n \n __metaclass__ = abc.ABCMeta\n</code></pre>\n<p>looks nicer as</p>\n<pre><code>class housekeeping(metaclass = abc.ABCMeta):\n</code></pre>\n<p>This isn't Java, you don't need getter methods for your properties - just access them directly. On a related ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-10T14:15:14.830", "Id": "256971", "Score": "4", "Tags": [ "python", "design-patterns", "json" ], "Title": "Housekeeping script improvements" }
256971
<p>I have written a short function as part of my program that strips the quotation marks (&quot;) from a list of lists. An example of the input data is:</p> <pre class="lang-py prettyprint-override"><code>[['&quot;foo&quot;', '&quot;Spam&quot;', '123', '&quot;Angry Badger&quot;'], ['&quot;dead&quot;', '&quot;Parrot&qu...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-10T15:49:46.800", "Id": "507476", "Score": "0", "body": "Since you've got to traverse a 2D array in Python, your code will be minimum 2 lines just for the traversal." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "...
[ { "body": "<blockquote>\n<p>I just always seem to mess up comprehensions when they have the <code>=</code> sign in them like this.</p>\n</blockquote>\n<p>I found the best way to think about comprehensions is instead think of comprehensions as <code>.append</code>s.</p>\n<p>Lets change your inner loop to use <co...
{ "AcceptedAnswerId": "256974", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-10T15:26:47.250", "Id": "256972", "Score": "3", "Tags": [ "python" ], "Title": "Stripping Quotations from a List of Lists" }
256972
<p>I'm using a script that converts a CSV file into GeoJSON in order to display it on a map. <a href="http://digitalwaterfall.space/ypsilandlords/searchable-map-template-csv/" rel="nofollow noreferrer">You can see it for yourself here.</a> The CSV has about four thousand rows. It's quite slow. I'm wondering what is slo...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-10T17:37:00.740", "Id": "507489", "Score": "0", "body": "Are you certain that that the performance problem is in this function specifically, and not some other part of the process? Or are you just guessing?" }, { "ContentLicens...
[ { "body": "<p>The slowest part is probably the <code>parseFloat</code>s, but I can't think of a faster way.</p>\n<p>One thing that stands out to me is the use of <code>map</code>, but at the same time you are modifying the items, so in the end you have two arrays with the same content. You probably can save som...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-10T16:55:28.660", "Id": "256976", "Score": "2", "Tags": [ "javascript", "performance", "leaflet" ], "Title": "Speed up javascript code to convert csv to geojson" }
256976
<p>I have a plan to make something to solve this stuff:</p> <p>You have 7 chips that are on the run. each has some cargo loaded. And also there's <code>where</code> record on each.Latter could be either <code>track</code> means running(or gone offroad) or <code>tobeauty</code> means it reaches its finish. Where <cod...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-10T18:26:33.653", "Id": "256981", "Score": "2", "Tags": [ "pascal" ], "Title": "max() without arithmetics or so" }
256981
<p>Let's say I want to write a super simple Python program to ask a user for their personal information and list it back out in a &quot;pretty&quot; format.</p> <pre><code>def get_info(): first = input(&quot;enter your first name: &quot;) while not first.isalpha(): first = input(&quot;enter your first n...
[]
[ { "body": "<p>You could abstract the character checking into a function, and do one print statement:</p>\n<pre><code>def get_info():\n def valid_check(alpha, message):\n &quot;&quot;&quot;\n Assumes:\n alpha is a boolean discerning whether to check for alpha or numeric\n m...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-10T19:00:21.917", "Id": "256986", "Score": "1", "Tags": [ "python" ], "Title": "DRY input-checking in python" }
256986
<p>For more information on Blazor, see the <a href="https://docs.microsoft.com/en-us/aspnet/core/blazor/?view=aspnetcore-5.0" rel="nofollow noreferrer">Introduction/Overview in Microsoft's documentation</a>.</p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-10T19:58:02.723", "Id": "256989", "Score": "0", "Tags": null, "Title": null }
256989
Blazor is a free and open-source web framework being developed by Microsoft. It supports incremental updates to a virtual DOM, enables UI code to be written in C# with JS interoperability, can run from either server or client, and sends data over a constant SignalR connection instead of http request/response cycles.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-10T19:58:02.723", "Id": "256990", "Score": "0", "Tags": null, "Title": null }
256990
<p>This is a student project of mine. I got 4/5 points but I suspect there's a lot of weird stuff in there. I never had a chance to hear my teacher's feedback about it and it bothers me so I figured somebody could take a glance at it and provide some feedback.</p> <h3>Quick documentation</h3> <blockquote> <p>First we r...
[]
[ { "body": "<p>I'm not going to look at the code for what is does, but I can give you some feedback on how it looks / is styled, and where you might improve.</p>\n<h2>Exception handling</h2>\n<p>Your current exception handling consist of print errors with a stack trace. There is no explicit error handling or com...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-10T21:16:23.113", "Id": "256995", "Score": "1", "Tags": [ "java", "thread-safety", "socket", "udp" ], "Title": "Java UDP port knocking authentication. Many clients at the same ti...
256995
<p>I just started learning Python and this is the first code I wrote. It's a Random Walk generator. I think I got it to work pretty well but I'm also sure there are more effective and less clunky ways to do this. Could you give me some tips on what to change to make the code shorter/more optimized and just objectively ...
[]
[ { "body": "<p>Here's one suggestion; other readers will probably offer more.\nSeveral times, you need to get an integer from the user. You\ncould create a function to handle such details. The code\nbelow shows what the function might look light and how you\nwould use it.</p>\n<pre><code>def int_from_user(prompt...
{ "AcceptedAnswerId": "257001", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-10T23:19:39.957", "Id": "256998", "Score": "2", "Tags": [ "python", "random" ], "Title": "Random walk generator - looking for optimizations (Python)" }
256998
<p>I have started a hobby project and would like to integrate better and more thorough testing practices. Since I am not too used to it, I'd love to have some feedback on the sample code below. In particular, I'd be interested in the best practices surrounding setting up data necessary to feed a particular testing func...
[]
[ { "body": "<p>Definitely not the most important issue, but at least for my brain, this is a\ncase where some short convenience variables -- with contextual help and a\nnarrow scope -- can really help code readability scannability. Just\nhas a nicer vibe too.</p>\n<pre><code>def get_journal_entry(*tups):\n re...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T00:24:26.063", "Id": "256999", "Score": "2", "Tags": [ "python", "unit-testing" ], "Title": "Python unit testing" }
256999
<p>I am working on an e-commerce website.</p> <p>I want to track 2 events in Google Analytics (I would need to send these events to Analytics):</p> <ol> <li>when a buyers contacts a sellers (an email will be sent through the website)</li> <li>when a job seeker applies for a job (job seeker would be redirected to the em...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T00:34:59.457", "Id": "257000", "Score": "0", "Tags": [ "c#", "javascript", "asp.net-mvc" ], "Title": "Clean way for sending Google Analytics events" }
257000
<p>This is a follow-up question for <a href="https://codereview.stackexchange.com/q/255182/231235">A Paragraph Merger with Removing Overlapped Duplicated Lines in C#</a>. I am trying to implement a tester for testing the implemented paragraph merger for removing overlapped duplicated lines. The operations of this teste...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T03:42:56.107", "Id": "257004", "Score": "0", "Tags": [ "c#", "object-oriented", "strings", "array", "random" ], "Title": "A Tester of Paragraph Merger for Removing Overlap...
257004
<p>I'm programming a multithreaded application (server-client UNIX socket) implemented for the server-side. I have two thread <code>check_cmd_thr</code> and <code>server_thr</code>.</p> <p>I use <code>check_cmd_thr</code> to check data input from keyboard, if the input is <code>start</code> then the server is allowed t...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T12:29:09.060", "Id": "507589", "Score": "0", "body": "The current question title, which states your concerns about the code, is too general to be useful here. Please [edit] to the site standard, which is for the title to simply stat...
[ { "body": "<p>First of all, get rid of your secret macro language so that other programmers who don't know your what your secret names mean can read the code. This means replace the mysterious, unreadable <code>SERVER_LOCK</code> with the super-readable <code>pthread_mutex_lock(&amp;mtx)</code> and so on.</p>\n...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T03:46:52.747", "Id": "257005", "Score": "2", "Tags": [ "c", "multithreading" ], "Title": "Multi-threaded application performance in C" }
257005
<p>Trying to generate fractals image with given <a href="https://en.wikipedia.org/wiki/Iterated_function_system" rel="nofollow noreferrer">IFS equations</a>. I have two classes:</p> <ul> <li><code>Shape</code> - Gives co-ordinate to form a shape.</li> <li><code>Ifs</code> - Takes the given <a href="https://en.wikipedia...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T06:58:38.427", "Id": "257010", "Score": "3", "Tags": [ "python", "numpy" ], "Title": "Generating basic Fractals" }
257010
<p>I made my own custom OpenGL shader loader for C++. Please tell me is I'm doing anything incorrectly or anything to improve on. I've tested this and it works perfectly fine.</p> <p>main.cc</p> <pre><code>std::vector&lt;ShaderInfo&gt; shader_info { {GL_VERTEX_SHADER, &quot;shader.vert&quot;}, {GL_FRAGMENT_SHAD...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T17:57:08.993", "Id": "507621", "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": "<ul>\n<li><p><code>for (auto info : shader_info)</code> -&gt; <code>for (auto const&amp; info : shader_info)</code> to avoid a string copy.</p>\n</li>\n<li><p>Reading the source file into a string should probably be a separate function.</p>\n</li>\n<li><p>We should throw an error if the file fails to...
{ "AcceptedAnswerId": "257015", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T07:52:01.640", "Id": "257012", "Score": "1", "Tags": [ "c++", "opengl", "glsl" ], "Title": "OpenGL Shader Loader in C++" }
257012
<p>So I created a wrapper class to authenticate user via POST HTTP request.</p> <pre class="lang-php prettyprint-override"><code> class Nucleolus { public const AUTHEN_USER_URL = &quot;localhost:8000/authen/user&quot;; protected $ch; public function __construct(string $token) ...
[]
[ { "body": "<p>Let me be frank: this code is just a Frankenstein sewn from different unrelated parts. Basically here are two main problems:</p>\n<ul>\n<li>sending HTTP requests is a distinct task and should be performed by another wrapper</li>\n<li>splitting the main functionality between two methods just makes ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T09:28:39.253", "Id": "257014", "Score": "0", "Tags": [ "php", "authentication", "curl" ], "Title": "A wrapper for user authentication using cURL in PHP" }
257014
<p>The following code creates a simple tree structure and then walks through the tree looking for node with the value 9 that appears after we have seen a node with the value 1 and a node with the value 4 (order of the 1 and 4 don't matter).</p> <pre><code>type N = Value of int | Children of N list type S = {oneFound:b...
[]
[ { "body": "<p>At first step I've removed hardcoded into function input data, so it's become testable.</p>\n<pre><code> ...\n walkImpl (Children [Value 1; Value 2 ; Children [Value 9; Children [Value 4; Value 5]; Value 9]])\n \nwalk ()\n</code></pre>\n<pre><code>\nlet walk n =\n ...\n walkImpl n\n\n...
{ "AcceptedAnswerId": "257050", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T11:03:29.073", "Id": "257017", "Score": "1", "Tags": [ "recursion", "f#" ], "Title": "Maintaining state while walking a tree structure" }
257017
<p>Use-case in a nutshell: Interpolate fixed-sized data (a lookup table) that provides output values for combinations of a (fixed) number of inputs. The appropriate scaling is done externally, each axis starts at 0 and increments by 1. The output is a floating point value regardless of the table data type, the idea bei...
[]
[ { "body": "<p>First, the input type is rather strange <code>const Td(&amp;data)[N]</code> - normally one would want a <code>std::span</code> or equivalent and I don't think that fixing values of all dimensions as a template parameter is helpful. Number of dimensions indeed should be a template as otherwise impl...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T11:09:08.913", "Id": "257018", "Score": "2", "Tags": [ "c++", "template-meta-programming", "embedded", "interpolation" ], "Title": "C++ generic, multi-dimensional linear inter...
257018
<p><strong>Summary</strong></p> <p>I have finished creating a secure login functionality. I have used 1 resource to help me with the security. The security section was copy and pasted but implemented into a class to suit it in my own way, but all the logic and properties, commands etc.. is all my work. <a href="https:/...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T12:24:44.753", "Id": "507587", "Score": "1", "body": "If *Most of it was just copy and paste* then what should be reviewed?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T14:55:59.940", "Id": "50...
[ { "body": "<h3>Storing password in <code>string</code> is totally insecure.</h3>\n<p>Because <code>string</code> is immutable object and can be kept in memory for undefined period of time. This makes easy to get clean password through not complicated reverse engineering operation.</p>\n<p>By the way</p>\n<block...
{ "AcceptedAnswerId": "257033", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T12:02:48.887", "Id": "257022", "Score": "0", "Tags": [ "c#", "mysql" ], "Title": "First-name, Last-name and Password logging in functionality using C#" }
257022
<p>I have an array of object and I want to group/order some inner properties in a map according to a key. I did this code but I would like to know if there was a way to optimize the code ?</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <...
[]
[ { "body": "<p>The code looks okay as is, but I would destructure the return value of the function rather than calling twice and also remove the brackets from the conditionals since they’re both one-liners</p>\n<pre><code>const myMap = new Map();\nmyArray.forEach(item =&gt; {\n const {key, value} = item.getValu...
{ "AcceptedAnswerId": "257093", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T13:43:06.273", "Id": "257024", "Score": "1", "Tags": [ "javascript", "typescript" ], "Title": "Group inner properties from an array of objects to a map" }
257024
<p>In an attempt to create a function that returns <code>x</code> with the <code>n</code> bits that begin at position <code>p</code> inverted, leaving the others unchanged - following the exercise in K&amp;R - I've come up with the following piece of code.</p> <p>Still, I find it unclear where to start counting, i.e. t...
[]
[ { "body": "<p>When you find it &quot;<em>unclear where to start counting</em>&quot; you have encountered one of the greatest problems in software development: extracting useful specifications from your stakeholders! In these situations, when we can't just ask, then we need to choose an interpretation that seem...
{ "AcceptedAnswerId": "257037", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T15:04:10.367", "Id": "257025", "Score": "3", "Tags": [ "c", "bitwise" ], "Title": "Invert n bits beginning at position p of an unsigned integer" }
257025
<p>I implemented <a href="https://github.com/tugrul512bit/VirtualMultiArray" rel="nofollow noreferrer">virtual array</a> using OpenCL and graphics cards as backing store, with caching some of data on RAM using a LRU algorithm and accessing data through some simple setters/getters. Accession of an array element goes thr...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T20:12:43.367", "Id": "507642", "Score": "0", "body": "I am not familiar with `omp` so not sure how it parallelizes it loops. But the`std::random_device` is very expensive to create. Could you not do this outside the loop (in an arra...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T15:32:12.547", "Id": "257027", "Score": "0", "Tags": [ "c++", "cache", "benchmarking", "portability", "opencl" ], "Title": "Performance discrepancy between Windows and Ubu...
257027
<p>I've been toying with Haskell again and implementing a simple text replacement program that replaces all consonants <em>c</em> in a text by <em>c</em>o<em>c</em>, i.e., inserting an 'o' in between:</p> <pre><code>&gt; robber_simple &quot;abcdef&quot; &quot;abobcocdodefof&quot; </code></pre> <p>This is rather simple ...
[]
[ { "body": "<p>I probably would reach directly for Parsec or another parsing library writing this from scratch, but I think even with a more direct recursive solution you've drastically overcomplicated this!</p>\n<p>Separate your problem into constituent pieces which you find easier to handle on their own terms....
{ "AcceptedAnswerId": "257089", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T15:43:22.260", "Id": "257028", "Score": "3", "Tags": [ "strings", "parsing", "haskell" ], "Title": "Text replacement with Räubersprache (\"Røversprog\")" }
257028
<p>I have a function that I've been trying to make faster that computes <span class="math-container">\$XA + B\$</span>, where <span class="math-container">\$A \in \mathbb{R}^{n \times n}\$</span> is a tridiagonal matrix, and <span class="math-container">\$X, B \in \mathbb{R}^{m \times n}\$</span>. In the code, the lowe...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T18:10:43.327", "Id": "507623", "Score": "0", "body": "Can you show the attempted AVX code as well?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T18:44:02.100", "Id": "507627", "Score": "0", ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "10", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T17:54:15.387", "Id": "257036", "Score": "1", "Tags": [ "performance", "c", "vectorization" ], "Title": "Faster Tridiagonal Matrix Multiplication" }
257036
<p>The problem is basically this: Return the permutation of the set of the first <em>n</em> natural numbers which satisfies the following property:</p> <p>|pos(i) - i| = k<br /> ∀ i ∈ (1,n)<br /> where pos(i) is the <em>i</em>th number in the permutation</p> <p>If no such permutation exists, return -1.</p> <p>Note: the...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T18:33:43.093", "Id": "507626", "Score": "0", "body": "There are 2 \"if\" that are doing same thing. Why don't you use only 1 \"if\"? if len<=2 then add once." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-...
[ { "body": "<p>Many programming puzzles of this sort can be solved without brute-force\ncomputations if you can figure out the pattern. Rather than trying to implement\na solution to the puzzle, it's often helpful to write some temporary code just\nto explore. The small script below does that. For each list size...
{ "AcceptedAnswerId": "257045", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T18:22:16.170", "Id": "257039", "Score": "-2", "Tags": [ "python", "algorithm", "time-limit-exceeded" ], "Title": "Hackerrank: Absolute Permutation - How do I make this code mo...
257039
<p>I am a beginner in C# and trying to learn how to program with OOP in mind. I am 100% that the code is not OOP-friendly at all, but the game is running and working, so if anyone could look throw the code and give me feedback on how to improve it, that would be helpful.</p> <p>The game is a simple snake game with thre...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-12T07:49:47.110", "Id": "507668", "Score": "3", "body": "Are you sure that you understand the OOP principles? 700+ lines of `Form1` class says you don't." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-17T0...
[ { "body": "<p>OP has stated that (s)he is interested mainly about the <code>UpdateScreen</code>.<br />\nSo, in this review I try to focus only on that part of the application.</p>\n<p>First, let me show you the end result and then let me iterate through the changes one-by-one:</p>\n<pre class=\"lang-cs prettypr...
{ "AcceptedAnswerId": "257311", "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-11T19:42:07.280", "Id": "257042", "Score": "3", "Tags": [ "c#", "object-oriented", "snake-game" ], "Title": "Simple Snake Game With OOP in Mind" }
257042
<p>The original Javascript slider is on W3 schools. I modified it to work as a slider for my homepage. The goal is to call it into <code>index.js</code> (which works) and use it at the top of the page (which works) and if I want to swap out an image, I could load <code>slideshow.js</code>, add a new static image or rem...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-12T20:20:08.830", "Id": "507713", "Score": "0", "body": "Welcome to Code Review! Your post looks good, I wonder though if you couldn't include a link to a fully working version to check out, since it's impossible to actually run it lik...
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-12T02:29:21.193", "Id": "257047", "Score": "1", "Tags": [ "javascript", "beginner", "react.js" ], "Title": "W3 automatic slideshow converted to React (gatsbyjs)" }
257047
<p>I am trying to stay ahead of my Year 12 Software class. Starting to work with records and arrays. I have answered the question, but the solution feels very clunky. I am hoping someone has suggestions/links for completing this task in a more efficient way.</p> <p>The task: read in lines from a text file and into a st...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-25T07:08:32.027", "Id": "513006", "Score": "0", "body": "Please do not update the code in your question after receiving answers, doing so goes against the Question + Answer style of Code Review. This is not a forum where you should kee...
[ { "body": "<p>Opinion: there is no benefit to building an array like this. I agree it is a clunky use of arrays which I think is unnecessary (and old-school). For instance you don't even need to know in advance how many records, nor do you need to dimension the array to a predetermined size. There are more flex...
{ "AcceptedAnswerId": "257082", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-12T07:17:18.347", "Id": "257051", "Score": "2", "Tags": [ "vb.net" ], "Title": "Reading from a text file into a structure and posting to list boxes" }
257051
<p>I am attempting to implement a converter which can convert two dimensional array (such as <code>string[,]</code>) into <a href="https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#Tables" rel="nofollow noreferrer">markdown table</a>.</p> <p><strong>The experimental implementation</strong></p> <p>The exp...
[]
[ { "body": "<p>Here are my observations:</p>\n<h3><code>Align</code></h3>\n<ul>\n<li>I think <code>Alignment</code> would be a better name. (<em>Align</em> is a verb where <em>Alignment</em> is a noun)</li>\n<li>Most of the time the <code>Default</code>, <code>Unknown</code> or <code>Invalid</code> is the first ...
{ "AcceptedAnswerId": "257058", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-12T07:34:45.560", "Id": "257052", "Score": "2", "Tags": [ "c#", "strings", "array", "formatting", "generics" ], "Title": "Two Dimensional Array to Markdown Table Converte...
257052
<p>I tried my hand at a contact-us PHP script. I came up with the following. First the markup, then a little client-side validation and then the email script. I just need to know if this is usable code. <p>I actually got to the point where I can make some cash developing websites. I just need to know if this is valid<...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-12T09:17:47.453", "Id": "507671", "Score": "0", "body": "If somebody could help me format that code to look more pretty I would appreciate it." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-12T09:22:42.870...
[ { "body": "<p>The script is extremely basic but it seems to me that it is also not secure. I have seen similar code that vulnerable to header injection, so it was possible for spammers to add a BCC header, and instead spam other people through your server (and your IP address will get blacklisted as a result).<...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-12T09:16:47.517", "Id": "257059", "Score": "0", "Tags": [ "php", "html5", "email" ], "Title": "Reviews on a contact-us form" }
257059
<p>I have a code that scrapes list of URL and appends dataframe as below:</p> <pre><code>from selenium import webdriver import pandas as pd from tabulate import tabulate import os os.chdir(r&quot;C:\Users\harsh\Google Drive\sportsintel.shop\Files&quot;) cwd = os.getcwd() print(cwd) browser = webdriver.Chrome() browse...
[]
[ { "body": "<p>Seems like there's one major point of redundancy, in that you're performing the same logic on the two different pages you're scraping (requesting site, parsing results, storing in dataframe).</p>\n<p>You could eliminate the redundancy with a function that takes in the site URL and performs the log...
{ "AcceptedAnswerId": "257108", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-12T12:19:34.207", "Id": "257064", "Score": "3", "Tags": [ "python", "functional-programming" ], "Title": "Scraping Premier League results" }
257064
<p>I wrote a math vector implementation using expression templates to add a little boost to &quot;chain operations&quot; like:</p> <pre class="lang-cpp prettyprint-override"><code>tnt::vector res = -v * 2 + d / 2 - 4 * c; // v, d, c are some vectors. </code></pre> <p>by avoiding the creation of the temporaries. The imp...
[]
[ { "body": "<p>It looks like very good code in general, good use of C++20 features, <code>constexpr</code> all the things. There is one issue I see with this code though:</p>\n<h1>Is it worth avoiding temporary <code>tnt::vector</code>s?</h1>\n<p>Are you sure that avoiding temporary <code>tnt::vector</code>s is ...
{ "AcceptedAnswerId": "257081", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-12T14:03:00.813", "Id": "257067", "Score": "6", "Tags": [ "c++", "mathematics", "c++20" ], "Title": "C++20 generic math vector implementation" }
257067
<p>This is a website Question on Hackrrank called Hash Tables: Ransom Note:</p> <p>Given the words in the magazine and the words in the ransom note, print &quot;Yes&quot; if we can replicate the ransom note exactly using whole words from the magazine; otherwise, print &quot;No&quot;.</p> <p>Here is an example input:</p...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-12T19:44:58.757", "Id": "507707", "Score": "0", "body": "Please link to the problem." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-13T10:29:26.180", "Id": "507733", "Score": "0", "body": "Chec...
[ { "body": "<p>Instead of:</p>\n<pre><code>for i in magazine:\n if i in list(UniqueWordDictMag.keys()):\n UniqueWordDictMag[i] += 1\n\n for i in note:\n if i in list(UniqueWordDictNote.keys()):\n UniqueWordDictNote[i] += 1\n</code></pre>\n<p>Avoid creating a list and just i...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-12T14:26:09.130", "Id": "257068", "Score": "0", "Tags": [ "python", "python-3.x", "programming-challenge", "time-limit-exceeded" ], "Title": "Determine whether a magazine contain...
257068
<p>I am currently learning C++, so I made this basic password wallet for Ubuntu.</p> <p>Its source code is in the <code>/opt</code> directory and it has a symlink so i can launch it from any directory using <code>pw</code> in the terminal.</p> <p><strong>Here is what it does:</strong><br /> It asks for a password (pas...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-12T15:28:31.663", "Id": "507699", "Score": "3", "body": "This looks very similar to your earlier, closed question. The right thing to do is to edit that question, which will automatically nominate it for re-opening - you don't need to...
[ { "body": "<p>There's quite a few beginner problems here:</p>\n<blockquote>\n<pre><code>using namespace std;\n</code></pre>\n</blockquote>\n<p>This is a really bad idea. It means we no longer have any control over the names in the global namespace as the Standard Library evolves. If this is a habit you have, ...
{ "AcceptedAnswerId": "257071", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-12T14:44:30.407", "Id": "257069", "Score": "4", "Tags": [ "c++", "security", "linux", "openssl" ], "Title": "Securing my password wallet" }
257069
<p>I had to populate the fields of a <code>Service</code> object using a <code>Set</code> (HashSet) with any configuration parameters -&gt; <code>ConfigurationMap</code> (Class with 2 attributes: key and value). The problem is that the attribute <code>quantity</code> of <code>Service</code> object can be set from two d...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-12T19:57:11.410", "Id": "507708", "Score": "0", "body": "Tough one, hard to gain anything from introducing functions. I thought about introducing a `Set<String, Function>` or similar which maps from parameter names to setters on the se...
[ { "body": "<blockquote>\n<p>I think it's pretty messy and inefficient</p>\n</blockquote>\n<p>Let's say that it is getting messy, especially if the number of parameters (and hidden rules) keeps growing.</p>\n<p>About being inefficient, I am not sure. Even if the input is very large, the method <code>populateServ...
{ "AcceptedAnswerId": "257092", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-12T15:09:07.540", "Id": "257070", "Score": "3", "Tags": [ "java", "collections", "set" ], "Title": "Take element of a Set collection depending on the value of another element" }
257070
<p>I finished my first real C project and it was Conways Game of Life. The code is working fine and the game runs. Since this was my first project though I don't know any of the real code conventions for writing C. I wanted to implement some tests so I had to split up the functionality from the main file into a new one...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-12T17:33:29.493", "Id": "257075", "Score": "4", "Tags": [ "c", "unit-testing", "sdl" ], "Title": "Testing and coding conventions for testing C with SDL" }
257075
<p><strong>dlfcn.h</strong> is a library of C functions to work with dynamic dependencies (shared objects). I've been experimenting with wrapping them in a C++ API, mostly as practice in making a C++ wrapper.</p> <p>This is an excerpt of my process of wrapping the <code>Dl_serinfo</code> parts of <a href="https://man7....
[]
[ { "body": "<pre><code>class dl_error : public std::runtime_error {\npublic:\n using std::runtime_error::runtime_error;\n};\n</code></pre>\n<p>Given the purpose of this class, it seems logical to have it get the most recent error automatically. Especially since there is a gotcha involved, where <code>dlerror(...
{ "AcceptedAnswerId": "257408", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-12T22:47:02.073", "Id": "257083", "Score": "0", "Tags": [ "c++" ], "Title": "dlinfo(... SERPATH ...) C++ wrapper" }
257083
<p>I have a C# application which needs to encrypt string and save the key as a hash. The key is saved as a hash to check the right key has been input before trying to decrypt the message.</p> <p>First, I have these method to generate the hash string - hopefully &quot;off the shelf&quot; and ready to go</p> <pre><code> ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-13T11:12:12.620", "Id": "507734", "Score": "1", "body": "If you add a date into the pass-phrase - how does the other end know what it is ??" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-13T11:15:49.147", ...
[ { "body": "<blockquote>\n<p>My concern is that the passphrase is 4 sets of &quot;diceware&quot; words (like here: <a href=\"https://diceware.dmuth.org/\" rel=\"nofollow noreferrer\">https://diceware.dmuth.org/</a>) and therefore could be brute forced.</p>\n</blockquote>\n<p>The diceware password is about 51 bit...
{ "AcceptedAnswerId": "259314", "CommentCount": "9", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-13T10:38:30.680", "Id": "257095", "Score": "1", "Tags": [ "c#", "cryptography", "encryption" ], "Title": "Encrypted text - C# SHA256, implementation" }
257095
<p>My code doesn't actually do that per se, but rather it find every possible edge that can be added without creating a cycle. The return value of the function <code>FindNodesToConnect</code> is a map, where the key is a node and the value is a list of all the nodes we can direct an edge to from the key without introdu...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-13T12:09:09.690", "Id": "257096", "Score": "0", "Tags": [ "javascript", "graph", "genetic-algorithm" ], "Title": "Add an edge to a directed acyclic graph such that it stay acyclic" }
257096
<p>I have written a class that acts like a stopwatch using C++11's <code>std::chrono</code> library. I wrote this because I find it difficult to benchmark my cpp code properly, this class just combines chrono's functionality and gives it a nice interface</p> <p>I have two classes, <code>stopwatch.h</code> and <code>lap...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-13T20:18:08.977", "Id": "507772", "Score": "0", "body": "Calling `LapWatch::reset` does not reset the `clock_state` in the base class to `idle`. Is this intended?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "202...
[ { "body": "<h1>Use <code>clock</code>'s native resolution everywhere</h1>\n<p>If you cast time points and durations to something with a different resolution than that of <code>clock</code>, you risk losing precision. So for all internal state of your classes, I would definitely store everything as <code>clock::...
{ "AcceptedAnswerId": "257109", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-13T13:44:43.680", "Id": "257099", "Score": "4", "Tags": [ "c++", "datetime" ], "Title": "Stop Watch class in C++ using chrono" }
257099
<p>I've implemented a simple vector-like structure. I would appreciate all criticism relevant to code. I have also published code under github. Here is the link to source code + unit test for most functions: <a href="https://github.com/Nethius/mystd" rel="nofollow noreferrer">https://github.com/Nethius/mystd</a></p> <p...
[]
[ { "body": "<p>Hi and welcome to CodeReview,</p>\n<p>There is a lot to unravel here, mostly concerning readability and robust code.</p>\n<ol>\n<li><p><code>typedef</code> is a relict from C that has been completely superseded by <code>using</code> declarations, so your aliases should read:</p>\n<pre><code> using...
{ "AcceptedAnswerId": "257157", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-13T14:18:17.523", "Id": "257100", "Score": "7", "Tags": [ "c++", "reinventing-the-wheel", "c++17", "template", "vectors" ], "Title": "re-implementation of std::vector" }
257100
<p>I have written some Go code that produces the output I would like, but I am unsure if the code itself &quot;smells&quot; good. I would like to know if it contains any anti-patterns, exemplifies bad practices, or lacks the proper idioms one would expect to see in a program written in Golang. Details of the program fo...
[]
[ { "body": "<h2>String Constants</h2>\n<p>An alternative way for representing your constants if you don't need their string representations would be to use the <a href=\"https://golang.org/ref/spec#Iota\" rel=\"nofollow noreferrer\">iota</a> identifier built into golang to assign auto-incrementing enumerations l...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-13T17:21:27.283", "Id": "257104", "Score": "4", "Tags": [ "beginner", "go", "lexical-analysis" ], "Title": "Idiomatic Go Lexer" }
257104
<p>Looking for more simple one liner for environment variable check with default value in csharp, any help is appreciated.</p> <pre><code>public static string GetEnvironmentVariable1(string envName, string defaultValue) { var env = Environment.GetEnvironmentVariable(envName); return string.IsNullOrEmpty(env) ? de...
[]
[ { "body": "<p>Use <code>??</code>. <a href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-coalescing-operator\" rel=\"nofollow noreferrer\">Null-coalescing operator</a>.</p>\n<p>Null check only</p>\n<pre class=\"lang-cs prettyprint-override\"><code>public static string GetEnv...
{ "AcceptedAnswerId": "257121", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-13T17:36:19.600", "Id": "257105", "Score": "0", "Tags": [ "c#" ], "Title": "Environment variable check with default value in csharp" }
257105
<p><strong>I am computing shortest paths of graphs using Python Networkx and Matplotlib.</strong> I'm focused on animating the <a href="https://en.wikipedia.org/wiki/Route_inspection_problem" rel="nofollow noreferrer">route inspection problem</a> path in particular here. My goal is to <strong>smoothly render such anima...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-13T22:25:45.820", "Id": "507778", "Score": "0", "body": "Recently I also needed to make some animations in matplotlib and ended up simply saving the frames of choice to later merge them with 3rd party software. I found that extremely e...
[]
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-13T18:22:22.893", "Id": "257107", "Score": "2", "Tags": [ "python", "performance", "graph", "animation", "matplotlib" ], "Title": "Slow render of a graph path using python ma...
257107
<p>I've written a program that finds the difference between data and gives output. Here's the code:</p> <pre class="lang-py prettyprint-override"><code>import json import numpy as np print(&quot;This is a basic machine learning thing.&quot;) baseData = {&quot;collecting&quot;:True,&quot;x&quot;:[],&quot;y&quot;:[]} whi...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-13T22:16:33.157", "Id": "507776", "Score": "0", "body": "Do you have a particular question or concern with your code?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-13T22:43:24.350", "Id": "507780", ...
[ { "body": "<p>Maybe you should check validity of the input and ask again if input is wrong?</p>\n<pre><code>while baseData[&quot;collecting&quot;]:\n baseData[&quot;x&quot;].append(float(input(&quot;X:&quot;)))\n</code></pre>\n<p>This is always True, so just discard this part:</p>\n<pre><code>if len(baseData[&...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-13T20:37:41.530", "Id": "257111", "Score": "0", "Tags": [ "python", "python-3.x", "machine-learning" ], "Title": "Machine Learning Program" }
257111
<p>First of all, I am here to explore unsafe features of Rust, if you are the kind of guy who likes &quot;safe&quot; Rust and will start nagging about using safe features of Rust I will still happily read your comment and learn about the safe alternatives.</p> <p>That said, I am looking to enhance my knowledge about <s...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-17T14:51:47.590", "Id": "508216", "Score": "2", "body": "Welcome to Code Review! Could you please update the title to accurately reflect what the code does, since lots of people are presumably playing with unsafe code it currently does...
[ { "body": "<h1>Ok, let's talk about <code>unsafe</code></h1>\n<p>Your use of <code>unsafe</code> is very unidiomatic, not because you're using it at all, but because you're not using it <em>correctly</em>; that is, to create a boundary between safe and unsafe code.</p>\n<h2>First, some definitions</h2>\n<p><str...
{ "AcceptedAnswerId": "257274", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-13T20:42:42.853", "Id": "257112", "Score": "3", "Tags": [ "rust" ], "Title": "Playing with unsafe code: Sending files over UDP" }
257112
<p>I am learning Rust and decided to create a simple program to calculate n-th Fibonacci number. It uses a vector for memoization. The program works, but what would you suggest to improve here? Maybe store <code>memo</code> inside <code>fib</code> function as a static variable?</p> <p>I tried to use <code>u32</code> ev...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T08:53:03.927", "Id": "507826", "Score": "0", "body": "Related Q&A [Recursive Fibonacci in Rust with memoization](https://codereview.stackexchange.com/q/204555)" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "202...
[ { "body": "<p>Looks good in general. Your main loop for parsing the input is generally idiomatic, except I would remove that pesky <code>.unwrap()</code> and explicitly report the error: <code>.flush().expect(&quot;Yikes! Failed to flush stdout!&quot;)</code></p>\n<p>The <code>fib</code> logic is a bit convolut...
{ "AcceptedAnswerId": "257120", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-13T21:27:37.327", "Id": "257113", "Score": "9", "Tags": [ "rust", "fibonacci-sequence" ], "Title": "n-th Fibonacci number with memoization" }
257113
<p>I'm iterating through a list to generate calendars, the issue is each generator function has the same <code>this.addToCalendar()</code> function. I'd like to know how I could condense this into only being called once, rather than in each function.</p> <p>The main generators I'd like to look at are the ones within <c...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-17T10:58:59.350", "Id": "508194", "Score": "1", "body": "There is not enough information in your question to answer. Required is... How the calendars relate? How does instantiating a calendar effect the state and thus behavior of `addT...
[ { "body": "<blockquote>\n<p>I'd like to know how I could condense this into only being called once, rather than in each function.</p>\n</blockquote>\n<p>One option would be to make a method that accepted the calendar or type and called the associated method</p>\n<pre><code>methods:\n generateCalendar(type) {...
{ "AcceptedAnswerId": "257357", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T00:59:42.973", "Id": "257127", "Score": "2", "Tags": [ "javascript", "ecmascript-6", "iteration", "generator", "vue.js" ], "Title": "Iterating through a list to genera...
257127
<pre><code> Table &quot;matrices&quot; Column | Type | Modifiers --------+--------+----------- matrix | text[] | not null </code></pre> <blockquote> <p>rows count 2,values are in this format given below</p> </blockquote> <pre><code> matrix ------------------- {{1,2,3},{4,5,6}} {{a,b,c},{d,e,f}} </code></pre> ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T07:59:41.073", "Id": "507820", "Score": "0", "body": "Welcome to Code Review! Unfortunately your post is off-topic because (1) there is no code for us to review, and (2) the title of your question is of the form \"how do I do X?\" w...
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T05:24:54.313", "Id": "257134", "Score": "0", "Tags": [ "database", "postgresql", "lua-table" ], "Title": "how to Transpose two-dimensional arrays values from rows into columns in ...
257134
<p>I seek a fast implementation of <code>(x / y).imag</code>, where <code>x, y</code> are complex 2D arrays (PyTorch tensors already on GPU). My approach is to move computation to a CUDA kernel via <code>cupy</code>, interfacing C and Python. Requirements:</p> <ul> <li>Faster than <code>(x / y).imag</code></li> <li>Usi...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T10:49:17.287", "Id": "507833", "Score": "0", "body": "Your 'Full code' link refers to a log-in page. Please include all relevant code in the question itself." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T06:50:46.423", "Id": "257137", "Score": "1", "Tags": [ "python", "c", "cuda", "pytorch" ], "Title": "Complex division for imaginary part" }
257137
<p><strong>Exercise:</strong> Write a prime number-test isPrime(num: Int), which for integer m &gt;= 2 checks, if the integer is a prime number or not.</p> <p><strong>My solution:</strong></p> <pre><code>fun main(args: Array&lt;String&gt;) { var isPrime: Boolean = false for (i in 2..101) { isPrime = is...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T12:44:32.073", "Id": "507843", "Score": "0", "body": "You might also be interested in looking at another Kotlin prime generator question: https://codereview.stackexchange.com/q/253690/31562" }, { "ContentLicense": "CC BY-SA ...
[ { "body": "<p>Two easy improvements</p>\n<p>Check up to the square root of n rather than n/2. So for 101 you only need to check n up to 10 not 50. If your number isn't prime then 1 of it's factors must be less than it equal to its square root.</p>\n<p>Don't check multiples of 2, so do a single test to see if t...
{ "AcceptedAnswerId": "257143", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T12:05:02.733", "Id": "257141", "Score": "2", "Tags": [ "primes", "integer", "kotlin" ], "Title": "Write a Kotlin-function isPrimeNumber" }
257141
<p>I attempted to make a smart/dynamic array implementation in C which is supposed to be a hybrid between a C++ vector/stack/queue.</p> <p>This is what i came up with:</p> <p>Header (smart_array.h):</p> <pre><code>#pragma once #include &lt;stddef.h&gt; typedef struct smart_array smart_array_t; void smart_array_alloc...
[]
[ { "body": "<h2>File Structure</h2>\n<p>The code is well organised into testing, implementation, and headers. Including <code>stddef.h</code> is appropriate in your header since you use <code>size_t</code>.</p>\n<h2>Consistency</h2>\n<p>Consider making sure the pointers are valid, for example, with <code>assert<...
{ "AcceptedAnswerId": "257170", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T14:04:10.043", "Id": "257145", "Score": "3", "Tags": [ "c", "array", "memory-management" ], "Title": "Smart/Dynamic array in C" }
257145
<p>On this script I look up properties in an array of objects. There is an original array of strings <code>list</code> to get the objects that match the <code>name</code> property, then I look up their respective line managers, <code>reports</code> recursively but only up to the <code>rank</code> 2, finally I merge the...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T17:05:07.307", "Id": "507945", "Score": "0", "body": "*I get duplicates when two people have the same manager*. Sounds like a job for StackOverflow, not CodeReview which is intended for reviewing (not debugging) working code." },...
[ { "body": "<p>From a medium review;</p>\n<ul>\n<li>This code belongs in a well named function</li>\n<li>I always forget about destructuring in a <code>filter</code>, very nice</li>\n<li>Mapping to an object automatically removes dupes, something I (ab)use in my counter</li>\n<li><code>const findManager = (manag...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T15:30:27.443", "Id": "257148", "Score": "1", "Tags": [ "javascript", "object-oriented", "array", "ecmascript-6" ], "Title": "Recursively find data in array of objects" }
257148
<p>I wrote this Rust code to parse my financials from a YAML file and my main concern is the large <code>match</code> branches (although general code review is welcome; still a Rust beginner):</p> <pre><code>extern crate yaml_rust; use yaml_rust::{Yaml, YamlLoader}; fn main() -&gt; Result&lt;(), std::io::Error&gt; { ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T16:54:19.147", "Id": "507857", "Score": "2", "body": "Can you please also add the output of your program to your post?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T16:57:33.727", "Id": "507858"...
[ { "body": "<h1>Structure your data</h1>\n<p>The reason you need nested <code>match</code>es is that even after parsing the YAML document into a <code>Yaml</code> object, it's still essentially unstructured data. Not every YAML object will have the right shape, so you have to validate it piece by piece as you tr...
{ "AcceptedAnswerId": "257460", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T16:47:53.147", "Id": "257150", "Score": "1", "Tags": [ "beginner", "rust", "yaml" ], "Title": "Parsing financials from a YAML file. Is this normal/idiomatic in Rust?" }
257150
<p>This works for me, but is this the right way to create this timer?</p> <p>I might be naive about this but I think this is close to perfect in pure JS.</p> <p>What would be the drawbacks of using this Timer compared to creating it in a different way?</p> <ul> <li>Click start and the timer starts to countdown.</li> <l...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T13:22:59.847", "Id": "507921", "Score": "0", "body": "Consider the naming `restart` vs `reset`. To me, `reset` means put it back to zero and `restart` means put it back to zero and start the timer again. Could just be me though." ...
[ { "body": "<p>From a short review;</p>\n<ul>\n<li>You use <code>9</code> twice, this should be assigned to a nicely named global constant</li>\n<li>You hard code both <code>9</code> and <code>00:10</code>, this is not flexible. I would expect to be able to change <code>9</code> to <code>99</code> and to have th...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T16:48:43.887", "Id": "257151", "Score": "2", "Tags": [ "javascript", "timer" ], "Title": "A Countdown Timer with reset functionality in pure Javascript" }
257151
<p>Can you guys review my GraphQL search pagination function? I'm afraid there could be some performance issues, or something. Especially at the aggregation section and this <code>const result: any = await this.BooksModel.findOne(</code> section.</p> <p>I'm using MongoDB as the database and string ISO Date as cursor.</...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T17:39:25.323", "Id": "257153", "Score": "1", "Tags": [ "javascript", "pagination", "cursor", "graphql" ], "Title": "Cursor-based search result pagination" }
257153
<p>For some reason, I am trying to implement a various type tuple flatten tool with the following requirements:</p> <ul> <li><p>The nested <code>Tuple</code> object <code>Tuple&lt;Tuple&lt;...&gt;&gt;</code> can be unwrapped into <code>Tuple&lt;...&gt;</code>.</p> </li> <li><p>There are various types in the nested <cod...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T18:41:41.370", "Id": "507865", "Score": "3", "body": "As for me there's no sense to wrap single `Tuple` with `Tuple`. Anyway if that happened, it's the reason to investigate why, instead of making the workaround." }, { "Cont...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T18:09:24.380", "Id": "257155", "Score": "0", "Tags": [ "c#", "generics" ], "Title": "Various type Tuple flatten tool implementation" }
257155
<p>This is my solution to a <a href="//stackoverflow.com/q/66628354/14737198">&quot;vacancy test&quot; task</a>.</p> <p>I'm not sure at all if I have correctly implemented the task, but here is my solution.</p> <p>Goals of code:</p> <ol> <li>Parse rows of table from a URL and extract some data (make a list of jsons fro...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T13:56:40.543", "Id": "507926", "Score": "0", "body": "Unfortunately this question is _off-topic_ because this site is for reviewing **working** code. Please [take the tour](https://codereview.stackexchange.com/tour) and read up at o...
[]
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T19:47:42.830", "Id": "257159", "Score": "0", "Tags": [ "python", "parsing", "web-scraping", "asynchronous" ], "Title": "Asynchronous web scraping" }
257159
<p>I am able to make the clock layout and get the time but I don't understand how to continuously update the time.<br /> I made the layout using Java labels and I have to change their texts continuously</p> <pre><code>calendar=Calendar.getInstance(); frame =new JFrame(); panel= new JPanel(); hour=calendar.get(Calen...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T21:10:08.863", "Id": "507884", "Score": "0", "body": "Calendar is not advised to be used any more - try [LocalTime](https://docs.oracle.com/javase/8/docs/api/java/time/LocalTime.html)." }, { "ContentLicense": "CC BY-SA 4.0",...
[]
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T19:55:15.627", "Id": "257163", "Score": "1", "Tags": [ "java" ], "Title": "digital clock in java using calendar class" }
257163
<p><a href="https://leetcode.com/problems/delete-and-earn/" rel="nofollow noreferrer">https://leetcode.com/problems/delete-and-earn/</a></p> <blockquote> <p>Given an array nums of integers, you can perform operations on the array.</p> <p>In each operation, you pick any nums[i] and delete it to earn nums[i] points. Afte...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-18T12:16:11.530", "Id": "508301", "Score": "0", "body": "Are you concerned about speed or memory consumption? Have you performed any profiling with different datasets?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate":...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T21:56:13.010", "Id": "257166", "Score": "0", "Tags": [ "c#", "performance", "programming-challenge", "dynamic-programming" ], "Title": "LeetCode: Delete and Earn C#" }
257166
<p>I have written a fairly simple bot that provides information or additional choice based on the user's query. It runs well and does the job, however, I was wondering how can I optimize my code and use the telebot better?</p> <p>Currently the main action happens in the query handler and something tells me that I am mi...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-29T12:06:21.237", "Id": "513462", "Score": "3", "body": "\"Below is the code, simplified for demonstration purposes\" Next time, please don't simplify the code. We can handle big pieces of code, but we'd be wasting your and our time by...
[ { "body": "<p>From my point of view you can use a visitor pattern for this with a simple dictionary, specially for your operations, here is a small example:</p>\n<p>Insead of this</p>\n<pre><code>@bot.callback_query_handler(func=lambda call: True)\ndef tempo(call):\n\n # here a handle the queries launched bo...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T23:02:52.477", "Id": "257167", "Score": "2", "Tags": [ "python", "performance", "python-3.x", "telegram" ], "Title": "How to optimize my telegram bot written in Python?" }
257167
<p>Recently, I've explored using rust as a scripting language for unity. My current method involves creating a DLL from rust, and loading it into my game at runtime. It requires that the user use a library I've made which has specific datatypes that I use to link unity and rust together, and must also be compiled as a ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-14T23:59:40.237", "Id": "257169", "Score": "2", "Tags": [ "game", "rust", "library", "unity3d", "dynamic-loading" ], "Title": "How should I go about implementing rust into th...
257169
<p>I'm working on converting my basic cryptocurrency miner from C# to C++ for performance reasons (I've been told that C++ is faster in many aspects). However, that aside, the focus of this post is to get some feedback for a very basic port of <code>ReadLine</code>, <code>Write</code> and <code>WriteLine</code> as I un...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T01:54:17.707", "Id": "507894", "Score": "0", "body": "Why are you creating a class for that? What's wrong with using `cin` and `cout` directly everywhere?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-...
[ { "body": "<p>Don't use:</p>\n<pre><code>using namespace std;\n</code></pre>\n<p>In the header file it is really bad and can break code. But even in the source file is considered bad practice.</p>\n<p>see: <a href=\"https://stackoverflow.com/q/1452721/14065\">Why is “using namespace std;” considered bad practic...
{ "AcceptedAnswerId": "257174", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T01:03:10.637", "Id": "257172", "Score": "0", "Tags": [ "c#", "c++", "console" ], "Title": "C# to C++: Basic Console Replication" }
257172
<p>I've just picked coding back up for the first time in a long time, so I understand if your eyes bleed looking at this code. It all works, but I'd be grateful for any tips (how to improve the python code, how to use Spacy's semantic similarity vector feature better, how to make it work faster, etc).</p> <p>The main p...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T05:43:55.880", "Id": "507899", "Score": "1", "body": "Is the indentation correct? Or should the `while` loop be indented further (in the body of the `for item in link_list_1` loop?" }, { "ContentLicense": "CC BY-SA 4.0", ...
[ { "body": "<h3>First a few observations, then we'll try to improve things.</h3>\n<ul>\n<li>&quot;Frog&quot; in the first list comprehension should be <code>closest_match</code> (which is initialized to 'frog').</li>\n<li>The two list comprehensions are identical, which suggests the code could be rearranged to e...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T01:19:33.870", "Id": "257173", "Score": "1", "Tags": [ "python", "natural-language-processing", "wikipedia" ], "Title": "Finding a path from one wikipedia page to another using se...
257173
<p>I'm currently trying to speeding up my python code. The code should calculate all the possible routes in a maze that is generated from a black and white image. The maze should be solved starting from the 0,j pixel of the image to every point in the bottom of the image(Better explained in the image attached).<a href=...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T12:03:58.310", "Id": "507914", "Score": "0", "body": "Could you please provide an example matrix (interpreted picture) and your validated output for that matrix?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2...
[]
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T11:55:17.250", "Id": "257178", "Score": "3", "Tags": [ "python", "performance" ], "Title": "Solve maze with python, speed issue" }
257178
<p>I am going to make this code below into the second release of my library, but I want to make sure I haven't missed anything. If there are improvements that can be made, I'd like to implement them.</p> <p>This code is also <a href="https://github.com/lunAr-creator/pw-gen" rel="nofollow noreferrer">on GitHub</a>.</p> ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T17:01:26.097", "Id": "507943", "Score": "0", "body": "You're getting your dictionary from _the web_? That's one of the first places I would attack this, through DNS spoofing or flat-out interception. Don't you have a standard syst...
[ { "body": "<h2>1. Add even more typing</h2>\n<p>It's good that you use some basic type annotations but you should use them everywhere, not just on a few select parameters. Have a look at the <code>typing</code> module, especially if you want to support Python versions before 3.9. For example, your function sign...
{ "AcceptedAnswerId": "257195", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T14:58:14.907", "Id": "257185", "Score": "4", "Tags": [ "python", "random" ], "Title": "Library for generating passwords" }
257185
<p>I write an app server that uses TCP socket on Linux. When there is no traffic (no data is sent by client, no client <code>connect()</code> or <code>close()</code>), the process sleeps on <code>epoll_wait()</code> while waiting for events hit the socket file descriptors.</p> <h3>What is a good thing to do while the p...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T17:57:26.290", "Id": "507952", "Score": "1", "body": "At least 2 functions are missing from the code, `likely()` and `unlikely()`. In addition the function `exec_epoll_wait()` contains `TODO` in the comments. In the Code Review Comm...
[ { "body": "<h1>Keeping the cache hot</h1>\n<blockquote>\n<p>So my initiative is to make the sleep time short and force the process to read from memory again and again until the events come.</p>\n<p>Reason for doing this is that to keep critical (for performance) data hot in the cache.</p>\n</blockquote>\n<p>If ...
{ "AcceptedAnswerId": "257205", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T15:08:56.560", "Id": "257188", "Score": "1", "Tags": [ "performance", "c", "linux", "socket" ], "Title": "Utilizing idle socket server to do meaningful thing (timeout afte...
257188
<p>Hi guys how you doing??</p> <p>I just finished creating an <code>rsync</code> helper program that reads its configuration file using a program that I also created and it deletes some cache directories that I included in the config file plus a few commands for cleaning the system, then it creates a directory on my ha...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T15:40:10.937", "Id": "508055", "Score": "0", "body": "This is not by any stretch of the imagination functional programming." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T15:43:54.383", "Id": "50...
[ { "body": "<h2>Language</h2>\n<blockquote>\n<p>I know that it may sound strange choice for a wrapper program to be written in C</p>\n</blockquote>\n<p>Yeah, about that. For practice, fine; but overall C isn't the right tool for this job. A more abstract scripting language such as Python will buy you shorter cod...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T15:49:20.777", "Id": "257190", "Score": "4", "Tags": [ "c", "linux" ], "Title": "rsync helper in C program" }
257190
<p>In order to keep the fragmentation ratio of indices low, you should re-organize the indices from time to time on MSSQL. Microsoft describes in the link below how you can check the fragmentation of indices on tables in MSSQL and then how you can re-organize (re-build) the indices to reduce the fragmentation percentag...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-23T10:03:21.123", "Id": "512843", "Score": "1", "body": "Fortunately someone has already done the work for you on this. Check out https://ola.hallengren.com/sql-server-index-and-statistics-maintenance.html" } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T16:40:35.497", "Id": "257192", "Score": "0", "Tags": [ "sql-server", "t-sql" ], "Title": "Re-organizing indices in case of fragmentation is T-SQL" }
257192
<p>Here is a <a href="https://www.oracle.com/java/technologies/javase/codeconventions-statements.html" rel="nofollow noreferrer">reference</a> to how switch statements should be formatted (I've never seen this used at the two companies I've worked at):</p> <p><a href="https://i.stack.imgur.com/aekqJ.png" rel="nofollow ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T17:40:16.903", "Id": "507951", "Score": "2", "body": "This post isn't really suited for Code Review (because you're not asking us to review code). It would be better off on Stackoverflow, but would probably get closed there too as i...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T17:01:46.423", "Id": "257193", "Score": "1", "Tags": [ "java", "formatting" ], "Title": "Does Oracle have a mistake in their documentation regarding switch case formatting?" }
257193
<p>I implemented lazy_map - <a href="https://github.com/tinytrashbin/lazy_map" rel="nofollow noreferrer">https://github.com/tinytrashbin/lazy_map</a>.</p> <p><strong>Can someone help with reviews ?</strong></p> <p>lazy_map is an implementation of unordered_map that has O(1) cost of copying irrespective of the current s...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T08:44:20.083", "Id": "507993", "Score": "0", "body": "It's not clear in the question, but does this satisfy the same complexity constrains as `std::unordered_set` for the other operations? In particular, are `insert()` and `erase()...
[ { "body": "<blockquote>\n<pre><code>// The documentation (ts/lazy_map.md) MUST be read twice\n// before using this utility.\n</code></pre>\n</blockquote>\n<p>Scary warning! I wonder whether that will be obeyed? It might be an idea to specifically mention pitfalls where we differ from standard unordered map.</...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T18:01:50.187", "Id": "257196", "Score": "4", "Tags": [ "c++", "hash-map", "c++14", "lazy" ], "Title": "lazy_map implementation in C++ | Similar to unordered_map but O(1) copya...
257196
<p>This is a follow up of <a href="https://codereview.stackexchange.com/questions/256579/skyscraper-solver-for-nxn-size">Skyscraper Solver for NxN Size</a></p> <p>I followed the advice in the last question and changed my approach from generating Permutations to use <a href="https://en.wikipedia.org/wiki/Backtracking" r...
[]
[ { "body": "<h1>Use more efficient containers</h1>\n<p>There are several areas where your code can be improved by changing the containers you are using to hold the data:</p>\n<h2>Don't use nested <code>std::vector</code>s for 2D arrays</h2>\n<p>Instead of <code>std::vector&lt;std::vector&lt;Something&gt;&gt;</co...
{ "AcceptedAnswerId": "257203", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T18:04:18.503", "Id": "257197", "Score": "1", "Tags": [ "c++", "performance", "c++17" ], "Title": "Skyscraper Solver for NxN Size Version 2 (Using Backtracking)" }
257197
<p>I converted an old Wordpress Plugin of mine from jQuery to plain JavaScript using a cheat sheet. I was very surprised that it seems to work right out of the box on my first try.</p> <pre><code>(function ($) { $(document).ready(function ($) { $('.comment-list &gt; li .comment-reply').each(function () { ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T23:32:54.840", "Id": "507975", "Score": "0", "body": "Welcome to Code Review! Your post looks good, hope you get some good answers!" } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T20:31:46.693", "Id": "257199", "Score": "2", "Tags": [ "javascript", "jquery", "wordpress" ], "Title": "Copy the reply button to each comment thread in WordPress. Converted from j...
257199
<p>I have a requirement to fetch data for different types of Users (Customers, Publishers etc) for three different timelines (retro, current, and past), all have different URLs. There is a scheduler which will run at the different interval (for example 2 minute for retro data, 5 minutes for current data and 10 minutes ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T23:30:10.047", "Id": "507973", "Score": "0", "body": "Welcome to Code Review! Looks like you already got some answers, great, hope you enjoy your stay!" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T...
[ { "body": "<p>It seems not a good idea to hard code the different constants. I would inject them through the constructor (I am using properties instead of <code>Get</code>-methods):</p>\n<pre class=\"lang-cs prettyprint-override\"><code>public sealed class Publisher : interfaces\n{\n public void Publisher (s...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T21:22:20.200", "Id": "257200", "Score": "5", "Tags": [ "c#", "inheritance", "interface" ], "Title": "Best approach for the Design Pattern for multiple schedulers using interface a...
257200
<p>I created a tic-tac-toe using java and I would like to know if there are any practices that I can improve and make the code cleaner and more performative</p> <pre><code>import java.util.Scanner; public class Main { public static boolean test(String[] values){ //Check diagonals if((values[0].equal...
[]
[ { "body": "<p>I hate this sort of hard-coded testing - there is usually a better approach to represent our data.</p>\n<p>A few thoughts come to mind.</p>\n<ol>\n<li>You don't stop players playing into an already occupied cell.</li>\n<li>Why not use a 2-d array (actually an array of arrays)? Then you can more na...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-15T23:39:06.880", "Id": "257207", "Score": "3", "Tags": [ "java", "tic-tac-toe" ], "Title": "How can I better test whether the player won in my tic-tac-toe?" }
257207
<p>A while ago, I got this question as a part of an interview test which asked to write a function to find the biggest number in a vector and write all the unit tests required to show that the <em>code works under any circumstance</em> using any language or pseudo-code.</p> <p>To the best of my knowledge, one would nee...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-17T12:12:30.283", "Id": "508197", "Score": "3", "body": "If you're applying for a job in software development and you have no experience, it's probably a good idea to read up on some basic standards for professional software developmen...
[ { "body": "<p>A function that returns the largest value in a vector would certainly have to check if the vector is actually non-empty. You aren't handling that case and are just assuming &quot;the first&quot; element is the biggest...if there is no &quot;first&quot; element, your program will crash in Debug bui...
{ "AcceptedAnswerId": "257220", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T00:01:34.953", "Id": "257208", "Score": "9", "Tags": [ "c++", "beginner", "unit-testing", "interview-questions" ], "Title": "Unit test for a maximum-finding function" }
257208
<p>(using GNU sed)</p> <p>I want to grab some output from xrandr and leave out everything but the resolution and offset.</p> <p>Input:</p> <pre><code>eDP1 connected 1366x768+0+0 (normal left inverted right x axis y axis) 290mm x 160mm 1366x768 60.02*+ 1280x720 59.74 ... 640x360 59.84 59...
[]
[ { "body": "<p>Cleaner is very much in the eye of the beholder.</p>\n<p>Your regex is fine - although for the digits part - I would use <code>\\d+</code> because you expect at least 1 digit. And <code>\\&lt;</code> only works in GNU sed (not on OSX for instance).</p>\n<p>Alternative you can look at it different...
{ "AcceptedAnswerId": "257228", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T02:42:48.060", "Id": "257212", "Score": "0", "Tags": [ "regex", "sed" ], "Title": "Grabbing resolution and offset from xrandr" }
257212
<p>Just out of curiosity, I have this code lying around a personal project in which I will generate lots of dummy customer data.</p> <p>Here's the code:</p> <pre><code>faker = Faker() # Faker.seed(random.randint(0, sys.maxsize)) async def get_random_customer_login(count: int, user: CustomerLogin_PydanticIn) -&gt; lis...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T09:18:34.673", "Id": "507994", "Score": "0", "body": "There is not much room for performance improvement, no, since all you are doing is a series of \"if X is not set, assign this value to it\"." }, { "ContentLicense": "CC B...
[ { "body": "<p>Since most of your checks are simply checking that a value hasn't already been provided, you can use the <code>or</code> operator to remove most of the if statements. e.g.</p>\n<pre class=\"lang-py prettyprint-override\"><code>&gt;&gt;&gt; print(None or &quot;I've used the 'or' operator&quot;)\nI'...
{ "AcceptedAnswerId": "259785", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T03:39:46.423", "Id": "257213", "Score": "3", "Tags": [ "python", "performance" ], "Title": "Generate dummy customer data" }
257213
<h3>Objective:</h3> <ul> <li>Create a function called <code>wordsAndSpaces</code> that splits a string on groups of spaces, preserving each group of space characters as a single token.<br> Example: <code>wordsAndSpaces &quot;extra spaces&quot;</code> gives <code>[&quot;extra&quot;, &quot; &quot;, &quot;spaces&q...
[]
[ { "body": "<p>The big thing that jumped out to me was how you seem to be treating Haskell lists like Java... Arrays? (I haven’t used Java since... 2006?) If you’re repeatedly fiddling with the elements at the end of lists, you’re probably doing something wrong. I’m not sure what the complexity of this all is, b...
{ "AcceptedAnswerId": "257287", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T04:22:15.060", "Id": "257214", "Score": "1", "Tags": [ "beginner", "strings", "haskell", "recursion", "reinventing-the-wheel" ], "Title": "String tokenizer" }
257214
<p>I want to write an extension method for getting Sunday Date based on weekOffset and current date. For example if weekOffset value is 1 that means next week sunday date and if weekOffset is 2 that means next to next week's Sunday date.</p> <p>I have come up with below code</p> <pre><code>private static List&lt;string...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T07:26:33.420", "Id": "507990", "Score": "1", "body": "You should perhaps be clear about your definition of \"better\"" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T12:21:50.000", "Id": "508031",...
[ { "body": "<p>I think your code could be more succinctly and usefully (ie don't return string) written as:</p>\n<pre><code> private static DateTimeOffset[] GetWeekRange(this DateTimeOffset d, int weekOffset = 0)\n {\n var weekStartDate = new DateTimeOffset(d.Date, d.Offset).AddDays(weekOffset * 7 -...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T07:07:10.053", "Id": "257215", "Score": "0", "Tags": [ "c#", "performance", "datetime", "extension-methods", "asp.net-core" ], "Title": "Extension method to get the Sunday...
257215
<p>I'm trying to implement execvp () using execv (). I don't know if the code is the best implementation.</p> <p>my code:</p> <pre><code>#include &lt;string.h&gt; #include &lt;unistd.h&gt; #include &lt;stdlib.h&gt; #include &lt;errno.h&gt; #include &lt;stdio.h&gt; extern char **environ; int my_execvp(char *file, cha...
[]
[ { "body": "<p>The implementation is non-conformant.</p>\n<ol>\n<li>No handling of undefined <code>PATH</code>. Quoting <code>man execp</code>:</li>\n</ol>\n<blockquote>\n<p>search path is the path specified in the environment by\n``PATH'' variable. If this variable is not specified, the <strong>default path\ni...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T09:26:07.677", "Id": "257222", "Score": "1", "Tags": [ "beginner", "c", "reinventing-the-wheel", "file" ], "Title": "A better implementation of the `execvp` call: the code imp...
257222
<p>A Java service that connects to MongoDB in production, but opened connection count is too much. It affects on MongoDb performance, so I have come up with a solution that provides only one <code>MongoClient</code> instance so which will reduce the connections.</p> <p>Here is my code, is it a good way to provide a sin...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T15:53:24.560", "Id": "508062", "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": "<p>I am not expert in singleton but does the connectionString really change over the life of the application? Usually (I might be wrong) this string is declared with the <code>final</code> keyword.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "20...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T10:50:23.440", "Id": "257226", "Score": "1", "Tags": [ "java", "singleton" ], "Title": "Singleton MongoClient instance provider" }
257226
<p>I have done some programming tasks as a part of my candidacy for a web development apprenticeship. Unfortunately, my application was rejected as the hiring manager &quot;didn't like my codes.&quot; I called up their office but no one was able to provide sufficient feedback for me.</p> <p>If any of you could tell me ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T11:24:53.917", "Id": "508017", "Score": "2", "body": "We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review. Please [**follow the tour**](https://CodeReview.StackExchan...
[ { "body": "<p>You don't use counter, isFizz() or isBuzz(), testFizzBuzz() calls to a fizzBuzz method which doesn't appear to exist. (Passing a boolean argument which seems illogical).</p>\n<p>Your code is formatted well, but the points above mean that a reviewer would doubt your competence.</p>\n<p>Have you sho...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T10:52:00.743", "Id": "257227", "Score": "2", "Tags": [ "java", "fizzbuzz" ], "Title": "Fizzbuzz questions - job interview rejected" }
257227
<p>In R, the function <strong>dpois</strong> (the poison distribution) can be used as <code>dpois(x,theta)</code> with both <code>x</code> and <code>theta</code> being vectors. However, in Rcpp, it can't be used like that. Can anyone suggest some function to replace the loop in the following <strong>dtpoi0</strong> fun...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-04-07T08:28:58.607", "Id": "511116", "Score": "0", "body": "There is no need to do that, as the act of compiling can sometimes \"vectorize\" for you, so it is seldomly advantageous to have vectorised variants of functions in C++." } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T12:29:51.087", "Id": "257237", "Score": "0", "Tags": [ "r", "rcpp" ], "Title": "Is there a way for Rcpp's dpois function where I can send a vector `theta` as param?" }
257237
<h2>Context</h2> <p>In an Angular application, I have three <code>&lt;select&gt;</code> boxes that are fed from the database with a relatively small data set. These boxes are part of a filter <code>Component</code> that is displayed next to a server-side data table. The component outputs the filter asynchronously to th...
[]
[ { "body": "<p>It is in theory not necessary to unsubscribe all subscriptions. For example if you call the backend with the Angular HttpClient then you will get an observable, that will automaticly complete after it emits the first result. As soon as it is completed, the observable is gone and does not strain yo...
{ "AcceptedAnswerId": "257332", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T13:59:20.490", "Id": "257243", "Score": "0", "Tags": [ "typescript", "angular-2+", "rxjs" ], "Title": "Handling a spinner for multiple REST calls" }
257243
<blockquote> <p>Write a recursive version of the function <strong>reverse(s)</strong>, which reverses the string <strong>s</strong> in place.</p> </blockquote> <p>I'm studying K&amp;R and wrote a code for the question.</p> <pre><code>void reverse(char s[], int n) // The seconde argument should be always 1. { ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-18T17:01:35.367", "Id": "508345", "Score": "1", "body": "\"second argument n says reverse() is currently called at n-th times\" is unclear with the comment \"The seconde argument should be always 1\"." } ]
[ { "body": "<p>To be honest, this is a bad way to solve the problem - recursion with <code>strlen()</code> is not a good idea. There was a recent discovery that Rockstar Games had their loading screens in GTA5 extended by several minutes due to their JSON parser calling <code>strlen()</code> on a string repeated...
{ "AcceptedAnswerId": "257263", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T15:17:19.907", "Id": "257247", "Score": "0", "Tags": [ "c", "strings", "recursion" ], "Title": "A recursive function to reverse string" }
257247
<p><strong>Note: This is my first post for a code review, so any feedback on what other info would be helpful to post (if any) would be much appreciated!</strong></p> <p>React component: Social.js</p> <p>The component has an input of 4 properties:</p> <ul> <li>dark: Boolean - if dark is supplied, the component renders ...
[]
[ { "body": "<ul>\n<li><p>consider using The strict equality operator (===) over the abstract equality operator (==) , see <a href=\"https://stackoverflow.com/questions/359494/which-equals-operator-vs-should-be-used-in-javascript-comparisons\">== VS ===</a></p>\n</li>\n<li><p>avoid nested <code>if</code> blocks u...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T15:22:54.210", "Id": "257248", "Score": "1", "Tags": [ "react.js", "jsx" ], "Title": "Dynamic social media component w/ dark mode" }
257248
<p>I am trying to understand the best way to write this. This is part of my organization work so can't disclose it fully here like why such requirement. So Apologies for that.</p> <p>I have <strong>ListA</strong> and <strong>ListB</strong>.</p> <pre><code>val ListA: List[((String, String), Int)] = List( ((&quot;A&quo...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-17T10:11:23.147", "Id": "508184", "Score": "0", "body": "Welcome to CR! Could you explain the reasoning behind the exact way this filtering is supposed to work? I have a hard time seeing why an iterative solution is necessary at all. ...
[ { "body": "<p>Apart from my comment, I'd suggest using <code>Set</code> for, well sets, since operations will likely be quicker, but more importantly, they're more correct wrt. what operations can be done on them.</p>\n<pre><code>val setB: Set[(String, String)] = ListB.toSet\n\nval filtered: List[((String, Stri...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T15:27:24.520", "Id": "257249", "Score": "0", "Tags": [ "scala" ], "Title": "filtering element of one List from another in Scala with different tuple structure" }
257249
<p>I previously posted this question in Stack Overflow, but I was told to post it here as my code is already working and I'm just trying to optimize it. Background: I'm developing a Game Boy emulator, and because most of it is done, I'm currently trying to optimize everything as much as I can.</p> <p>There's this opera...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T22:03:53.543", "Id": "508113", "Score": "0", "body": "Welcome to the Code Review Community. The name code review is important, to optimize code we need to see the actual code. This question is off-topic on `Code Review` as well as `...
[ { "body": "<p>At the risk of this question being closed as off topic, I find this problem interesting and will hazard an answer.</p>\n<p>I believe that the best answer here is simply a lookup table. You only have 16 bits of input domain, so you could make a LUT with 2^16 entries, each entry giving the 8 colours...
{ "AcceptedAnswerId": "257276", "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T15:32:04.867", "Id": "257250", "Score": "-1", "Tags": [ "c++", "performance" ], "Title": "Optimizing a bit manipulation formula" }
257250
<p>I am attempting to implement a converter which can convert two dimensional array (using Boost.MultiArray library) into <a href="https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#Tables" rel="nofollow noreferrer">markdown table</a>.</p> <p><strong>The experimental implementation</strong></p> <pre><code...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T15:46:11.983", "Id": "257253", "Score": "0", "Tags": [ "c++", "strings", "array", "boost", "c++20" ], "Title": "Boost.MultiArray Based Two Dimensional Array to Markdown Ta...
257253
<p>I have a piece of bash code that works fine.</p> <pre><code>for thing in &quot;$things&quot;; do output=$(my_program &quot;$thing&quot; 2&gt;&amp;1) if [[ $? -eq 0 ]]; then echo &quot;$(echo &quot;$output&quot; | tail -1)&quot; else echo &quot;$(echo &quot;$output&quot; | tail -1)&quot; ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-20T13:21:33.427", "Id": "508509", "Score": "0", "body": "Welcome to Code Review! I changed the title so that it describes what the code does per [site goals](/questions/how-to-ask): \"*State what your code does in your title, not your ...
[ { "body": "<p>Don't quote <code>$things</code>:</p>\n<pre><code>for i in &quot;1 2 3 4&quot;; do\n echo &quot;i=$i&quot;\ndone\ni=1 2 3 4\n# Better is\nfor i in 1 2 3 4; do\n echo &quot;i=$i&quot;\ndone\ni=1\ni=2\ni=3\ni=4\n</code></pre>\n<p>When <code>my_program</code> is written well, errors are written t...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T16:05:20.487", "Id": "257255", "Score": "0", "Tags": [ "bash" ], "Title": "Tail program output to stdout or stderr" }
257255
<p>I'm new to C++ and decided to implement a simple program that checks if a string is a pangram (i.e. the string contains all the English alphabet letters). It's my first program in C++ and I have some background with interpreted programming languages like Python and R.</p> <p>I want to know what are the common beginn...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T16:59:51.907", "Id": "508072", "Score": "17", "body": "For a beginner, it's amazing I'm not seeing the most-most common mistakes of: No STL; C as C++; `using namespace std;`; You even have an appropriate use of `std::vector<bool>`!"...
[ { "body": "<ul>\n<li><p>The sequence</p>\n<pre><code> if (condition) {\n return false;\n }\n return true;\n</code></pre>\n<p>is a long way to say</p>\n<pre><code> return !condition;\n</code></pre>\n</li>\n<li><p><code>std::all_of</code> seems more natural than <code>std::any_of</code>, which implies do...
{ "AcceptedAnswerId": "257259", "CommentCount": "10", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T16:21:06.263", "Id": "257256", "Score": "18", "Tags": [ "c++", "strings" ], "Title": "A C++ program to check if a string is a pangram" }
257256
<p>I just got started coding in Java and I just made my first project. I was wondering if someone would review my code and show me the things I can improve in it. I am eager to learn and would appreciate any advice.</p> <p>Here is the code:</p> <pre><code>package snake.app; import java.awt.*; import java.awt.event.*; ...
[]
[ { "body": "<p>This is very readable. I noticed you had a XKCD random number generator there...</p>\n<pre><code>int i = 1;\n</code></pre>\n<p>I'm aware that the time signal is not related to keypress timings (e.g. you might make a direction change but not actually move for up to 75ms). In principle I guess you c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T17:43:52.400", "Id": "257260", "Score": "5", "Tags": [ "java", "beginner", "snake-game" ], "Title": "Java GUI Snake game" }
257260
<p>I wrote some functions to compress and decompress a list of ints using <a href="https://en.wikipedia.org/wiki/Elias_gamma_coding" rel="nofollow noreferrer">Elias gamma encoding</a>:</p> <pre class="lang-py prettyprint-override"><code>def _reverseBits(number: int) -&gt; int: rev = 0 while number: rev ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T20:17:27.827", "Id": "508089", "Score": "0", "body": "Why are you creating numbers instead of (bit)strings?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T20:23:05.787", "Id": "508090", "Scor...
[ { "body": "<p>Rather strange to encode as a number instead of a (bit)string. And the way you do it takes quadratic time in the size of your list (because both the <code>+</code> and the <code>&lt;&lt;</code> in <code>bitstream += encoded_number &lt;&lt; bitstream_length</code> are linear). You could do it in li...
{ "AcceptedAnswerId": "257268", "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T20:08:01.987", "Id": "257264", "Score": "2", "Tags": [ "python" ], "Title": "speed up Elias gamma compression" }
257264
<p>I'm trying to solve the N-Puzzle problem using IDA* algorithm with a Manhattan heuristic. I already implemented the algorithm from the pseudocode in this Wikipedia page (<a href="https://en.wikipedia.org/wiki/Iterative_deepening_A*" rel="nofollow noreferrer">link</a>).</p> <p>Here's my code so far :</p> <pre class="...
[]
[ { "body": "<p>The code does not compile as it is:</p>\n<ul>\n<li>The <code>solve</code> function's signature contains unnecessary code\n<pre><code>def solve(initial_state):path = solve(initial_state)\n</code></pre>\n</li>\n<li>A NumPy array cannot be initialized like <code>np.array([8 7 3],[4 1 2],[0 5 6])</cod...
{ "AcceptedAnswerId": "257288", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-16T20:46:58.797", "Id": "257267", "Score": "2", "Tags": [ "python", "algorithm", "pathfinding", "a-star", "sliding-tile-puzzle" ], "Title": "How can I speed up my IDA* al...
257267