I would like to get some code review for my recursive implementation of python flatten array method.
Write a piece of functioning code that will flatten an array of
arbitrarily nested arrays of integers into a flat array of integers.
e.g. [[1,2,[3]],4] -> [1,2,3,4].
I'm particularly...
Any suggestions are highly appreciated. I am a beginner in Python.
upper_bound = 50
def remove_non_primes(list_of_ints, prime_to_check_against):
only_primes = list()
for i in range(len(list_of_ints)):
if list_of_ints[i] % prime_to_check_against != 0:
only_primes.appe...
I've ran short of podcasts to listen to. Can anyone suggest a tech/security/IT podcast that they enjoy? Prefer recurring podcasts rather than series, but open to either.
PS: Already listen to @SmashinSecurity & @cyberwirestudio both of which I highly recommend!
I'm voting to close this question as off-topic because it is about optimizing working code and therefore is more suitable for Code Review — Ken White39 secs ago
After a lot of testing I've reached this solution to fit text into an editable container with automatic height. I started with a textarea and javascript but it got extremely slow on hundreds of textareas so I switched to div with contenteditable, css and some js.
My main issue was that firefox i...
how can i speed up the function regexEngine as on my machine it takes 7 to 10 seconds (depending on the format string) to do 2545 iterations wich is bad (it takes around 2 seconds without the function) (full code minimal example), as im trying to find an alternative to using a bit mask since thos...
how do i get commit to work AFTER the initial commit using libgit2 as i have checked out and tried all of the other posts related to implimenting git commit using libgit2 (on stackoverflow) but all of them seem to fail with either SIGSEGV On the commit or give "error: Could not create the initial...
We had a really messy method that created a memory leak and used to process an XML file with 300 entries and around 5 GB of memory. I have rewritten the function and I'm currently only unsure about the reading of the XmlNode to the NodeList.
while (!dsNav.EOF)
{
XmlNode schlussrechnung = dsN...
I'm writing a small mobile app, foremost for myself and a few other people, but it won't probably get a huge userbase(but one never knows).
I do want a clean architecture though, so here is my code for review
I have a Recyclerview containing a line for every ingredient entered into the system. T...
That’s question to choose LinQ or SP will not answer for your performance. It depends on your skillsets about LinQ or SP, we good at SP the performance is good, same we are good at LinQ. With many right way to do the performance is similar. I prefer LinQ with EF core in the web application for code structure and good to have a code review with everything in code. For SP for big data stuffs. — ocrenaka57 secs ago
This is in context of a springboot application. I considered using Spring @Retryable too but found that it didn't work with function with return types. Is this approach considered good?
public String getResource(String id, int retries,String url) throws InterruptedException{
if (retries=...
I'm retrieving the operating system platform with .NET Core with system.runtime.interopservicesI have created the code below and was wondering if there was a way that I could use a switch statement rather than the if statement for determining which platform is in use.
/// <summary>
/// Operating...
I am doing one socket programming in java. If server socket is down for a while then start again after that the server can get auto connection with the client which connect with previously.If possible can any one help me how to handle the Exception?
@202_accepted Did you partly shutdown SESE? Whenever I select a site, I get a runtime error. For example: CR
> Server Error in '/' Application. Runtime Error Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace LinkedListQuestions
{
[TestClass]
public class ReverseLinkedList
{
[TestMethod]
public void ReservseLinkedListTest()
{
Node<int> head = new Node<int>();
Node<int> two = new Node
I'm trying to make a like and dislike system. everything works very well, a user can't like a post twice and they just can like or dislike a post, not both. my problem is in jquery part. I want to change the button values when a user clicks on them but right now when the user click on like button...
Regardless, your question doesn't really have a clear problem statement - if the code is already working, if you want somewhat opinion-based answers on how it might be formulated better, it would be more suited to codereview than here — CertainPerformance11 secs ago
@MathiasEttinger Doesn't invalidate either answer. as papagaga say's that filter_helper method is too complicated either way and bipll is mostly concerned about namespaces.
@Mast You were able to rule out invalidation and still rolled back?
Since filter was named but not really reviewed, it's a bit iffy.
Current policy as I understand it, is to rollback even when in doubt. The standard comment doesn't even mention invalidation as an issue. It mentions it's against Q&A style.
> 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 you should keep the most updated version in your question. Please see what you may and may not do after receiving answers.
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 you should keep the most updated version in your question. Please see *[what you may and may not do after receiving answers](//codereview.meta.stackexchange.com/a/1765)*.
This is intended as a ready copy & paste version for including in the Auto-Comments script.
The Auto Comments script also has support for a "remote" feature where you can use this URL: http://www.zomis.net/codereview/auto-comments
###[Q] Broken Code
I'm afraid this question does not match what ...
I'm aware of the FPCs. Still, OP didn't incorporate any feedback from the answers, they just found out that they can skip the template specialization for <true, …> since the <false, …> is enough. That should have been a self-answer, though, not an edit.
The method below is returning a string of random characters using RNGCryptoServiceProvider. The return string result is built by picking characters from the string chars by applying % chars.length
on the values from GetBytes(). As I understand, this will favour some characters over others, depe...
Thank you, I was more looking for such an answer actually, not a code review. Since the day I asked, I suceeded creating my entries in my DB by limitating the in flight requests at a time. It works perfectly. Thank you for explanation and the links — Benjamin D.39 secs ago
I implemented a password field based on the peewee framework to handle passwords of accounts in web applications for Python 3.4.
My goals were
Secure hashing, no plain password leakage.
Easy password verification.
And this is what I came up with:
peeweeplus.passwd:
"""Argon2-based password...
please review my code. It works as it should but I think about making it more pretty or optimal.
This method should take in some IEnumerable of Rules, current number of adults and array of ints, where each int is age of child. We want to check each rule if we can identify child as some type of En...
@MathiasEttinger The second is a follow-up, yes. If a follow-up is placed before the initial question gets a review, there's no point in reviewing the first version. It's actually quite harmful if the initial version attracts another review instead of the reviewer being redirected to the 2nd question to begin with. So the first question gets closed as dupe.
This question was asked a couple of weeks ago, and has not been answered in that time. It has languised: https://codereview.stackexchange.com/questions/79233/edmonds-karp-algorithm-for-maximum-flow-in-java
In the interim, the question asker has updated their code substantially, and posted the re...
I wanted to create slider when it slide center slide width must have incresed and the two slide next to it stay on normal slide.
I have tried one using slick slider.
Here is the code pen link that I have tried.
But this is not smooth and slide next to center slide not showing properly.
If any...
A minesweeper library in C#. Can be included in any GUI stack.
It is an update to Minesweeper library for any GUI. I have done many updates with regards to the answer.
Three sections: Game, Board and Tile.
Then a unit test class: GameTest
Game
public enum GameState
{
NotStarted,
Start...
the specific question as I cannot find elsewhere:
How to split the text by keywords (list of keywords e.g. 'from:','to:' etc.) to copy the text from beginning of one keyword to the beginning of another keyword.
Language Python.
Many thanks!
I'm very new to python and programming in general. For a school assignment, I made this Memory Game and would love to receive feedback from you guys.
import tkinter as tk # imports tkinter as tk
from tkinter import font as tkfont # imports font as tkfont
import random # imports random
import...
I'm trying to find the smallest integer greater than 0 that is not in a given list. For some reason, this code outputs 1, because java thinks 1 and "smallest" are different values. Can somebody please explain to me why so?
public static void main(String[] args) {
int [] A= {1,2,3};
int smallest...
I'm currently learning python / network programming altogether and coded this simple python reverse shell; I would like to hear any remarks from you regarding code structure, any common beginner mistake, actually pretty much anything that feels wrong with my code.
The code is pretty straightforw...
While exploring the moderator page /admin/analytics for the first time I see Google is the only search engine listed, and among the three referrers is duckduckgo.com at 15% of our traffic. Shouldn't it be listed as a search engine instead?
Given an array of integers, find the longest consecutive sequence, where a sequence is defined as being either (strictly) ascending, (strictly) descending, or all-equal.
836926 then has the longest sequence 369, which happens to be ascending. 241455556 has the longest sequence 5555, which happen...
If the script works fine, and you want to know what you should improve with it, you should post it on Code Review. But please post the source as text there. 50 lines is not that huge even on SO and will be rather small on CR... Anyway, this is off topic here. — Serge Ballesta10 secs ago
@MathiasEttinger The problem you have when passing a str is the same as using the following. Rather than fixing it for a certain type, I'd recommend fixing it for all input.
a = []
a[:] = [[a], [], 2]
flatten(a)
RecursionError
The Fortran program 'MAIN' below calls 3 subroutines. 1) It opens a file if it is not present, (overwrites if it is already present). 2) writes something on the file using the file identifier integer and 3) closes the file.
program MAIN
2001 FORMAT (A,I10)
INTEGER FILEIDS(10)
CHA...
Yay, good idea… Just borked my system by calling list(itertools.repeat(2)) '-_-
@Peilonrayz Yes because strings are special in the sense that iterating over them gives str back, not char. Handling inherently recursive structures, on the other hand, is harder and has not a natural way of solving it.
It's not that hard a fix if you opt for the second method:
def flatten(iterable, parents=()):
try:
iterator = iter(iterable)
except TypeError:
yield iterable
else:
for element in iterator:
if element not in parents:
yield from flatten(element, parents + (element,))
Anyway, even though you raise valid points, I often feel that strings being iterables is an unwanted features as I want each string to be treated as a single token and not a container. For instance:
I have a user-editable dictionary of content used to fill in a string.Template and I wanted to allow the user to fill the same template with several values at once.
Using only values, itertools.product would be enough for my needs but I needed dictionaries to fill in a template. I also wanted us...
I'm currently developing a simple 2D game engine and I was just wondering, what are some things that I can do to improve my service locator class, at the moment it's very basic.
For example, should I be checking for null objects, if so, what exceptions should I throw?
Here's the code, thatnks i...
I posted first this question here, but they suggested to put on this forum. I have many shell commands that need to be executed in my python script. I know that I shouldn't use shell=true as mentioned here and that I can use the std outputs and inputs in case when I have pipes in the command as m...
@DietrichEpp Code review does not accept neither code that is not working, nor code that is simplified for the purpose of demonstrating a specific behaviour. This question has a clear problem (code hangs) that can be addressed on SO. — Mathias Ettinger26 secs ago
I'm attempting to code a turn based RPG battle simulator (text based) in java.
I'm doing this as an exercise/project to learn OOP design. I've coded something similar in C, but just porting that code over to java would, of course,
be rather silly. I'm going to be taking this extremely slow, focu...
If anything, this question should be moved to Code Review. It's not asking for debugging and isn't overly broad. It could do with some example data, but that's cause for a comment to the author, not anonymous downvoting and close-voting. — AkselA7 secs ago
i'm new to javascript and still learning. The below code works fine is just that i want to add a delete button on each new row produce. and when it's pressed it will delete the data and update the "totaldonation" value.
I got stuck here and need some help. Thanks
HTML
<div class="item active">
<...
If you have a working solution but want some improvements (performance, code style, architecture etc), then it's better to ask a question on Code Review. — dymanoid21 secs ago
Recently we got the question Finding the longest word in a String. (10k required)
This question looked like it was off-topic, because of the following results:
>>> findLongestWordLength("What is the space?");
6
>>> findLongestWordLength('What is')
2
If 'word' means any segment that isn't a sp...
Recently we got the question Finding the longest word in a String. (10k required)
This question looked like it was off-topic, because of the following results:
>>> findLongestWordLength("What is the space?");
6
>>> findLongestWordLength('What is')
2
If 'word' means any segment that isn't a sp...
How do i get the button to delete the specific data of the row and update the value of totaldonation. Really need some guidance. Thanks
HTML
<div class="item active">
<img src="item/dapur.png" class="img-responsive" style="height:120px;">
<input class="input-display itemname" type="text" id="it...
Two players are made to play a game
They can choose a unit of either of rifle,knife,bomb and fill an army.
The space is limited to 10.
So player 1 and player 2 can choose any combination of units which is stored in two respective lists.
Lets say Player 1 list contains [rifle,bomb,knife,rifle]...
I have around 300 log files in a directory and each log file contains around 3300000 lines. I need to read through each file line by line and count how many hostnames that appear on each line.I wrote basic code for that task. but it takes more than 1 hour to run and takes lots of memory as well. ...
Below is my code, so I have a abstract class where in I have used AddAsync function so its method definition is dynamic & parameter is dynamic too however since any one calling this method may have different definition & parameter input so I had to create a empty class called DomainEntityDto, I d...
I have around 300 log files in a directory and each log file contains around 3300000 lines. I need to read through each file line by line and count how many hostnames that appear on each line.I wrote basic code for that task. but it takes more than 1 hour to run and takes lots of memory as well. ...
so i have written this script (pastebin . com/NJgLW8xb) in python 2.7 and i was wondering where i could improve it or efficient. this is my first script so idk much. the script takes a text file from a folder removes blank spaces with list comprehension and then breaks it into smaller 20 elements...
Hi Paul, I don't post enough in CR to recommend migration, but usually StackOverflow is for bugs or problems in code. Check out CodeReview if your code is working and you just want feeback — en_Knight38 secs ago
I created a BFS algorithm in order to solve an 8-puzzle, and while it works, it is awfully slow compared to my DFS implementation. My main point of concern is the puzzleExists() function, which determines whether the created puzzle already exists in the list and should therefore be dropped. Curre...
Good day,
I am automating a report for my department which currently requires going to a website, putting in your user name/password, then navigating to the proper page and copy the data from there.
What I need help with is creating a VBA to open a pop up box asking for the username and passwo...
The only idea here is that if it's between double quotes it can contain anything it wants. I'm only concerned about making it safe within the context of a csv file itself. That is, I don't care if they write </textarea><script>window.location.href='http://regressionbuddy.com';</script> in one of ...
I believe this qualifies as "stub code" and not "concrete code usage" - from the close reasons: Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." — Thomas Ward21 secs ago
@Malachi you're a mod you can read it. Stub code, asking if that specific function has proper anti-injection methodology to it
but no concrete context of usage, etc.
the other reason would be "Unclear what you're asking", but since OP or mod now deleted it, I can't see it if I close the other tab it's in
would also fall into the "best practices" category without any other code to show the context of the code being used, what it was being told to process, what actual injections they're protecting against, etc.
that's my interp. anyways. Two others came by asking for more details because it was unclear, but I can't see what else happened. (I'm not a CR mod.)
it looked like it escaped double quotes, and looked like real code, and looked like it performed the function completely and might actually be part of a code base
@Malachi then the next step I do is take the question to Meta of the scope of "with sufficient context for reviewers to understand how that code is used" in the close reason, and that its scope needs more clearly defined to include what is or isn't included in it.
from my perspective it was just that one singular function without details or other contextual uses of the code
but since I'm just a user on CR, my opinion remains just my opinion without any other weight behind it :P
Parsing ECMAScript requires knowing what Unicode characters are allowed in identifiers. I mostly used Unicode character classes for validating IdentifierStarts and IdentifierParts.
E.g., using the online UnicodeSet utility, I get something like [\$A-Z_a-z\u00AA\u00B5\u00BA\u00C0-\u00D6[large lis...
This function formats the text in each cell of a CSV. The goal of the function is to make sure that the sequence of characters in text will never break the cell's partition. The correct output of this function looks like this:
"foo"
"123"
"drop table 'chocolate'; -- this is fine, i don't care"
...
correct, I just know there is a meta post already so I want to make sure that I am in line with the community on this as well....maybe your answer is already on Meta somewhere
maybe it is, maybe it isn't. 'Tis why I like Meta, if it's already explained elsewhere then the answer can easily be found, and if it isn't then it gets attention and answers to better clarify things :)
... this being said, at least I'm not one of the users who goes off on a rant and gets mad at the mods/community just because I don't understand a mod's interpretation of something or such :P
(and even as a mod over on Ask ubuntu, I regularly find myself about to do something but then notice the community consensus goes against that and "WHoopsies, I shouldn't do that..." is my ultimate response, yay for meta!)
My idea of Code Review is posting (near) production code in pieces that can be run on their own given the correct input. and the purpose is clear as well.
well that is rather simplified, but gives a general idea
I was looking for http_build_queryphp similar method in javascript but did not find but create my own and here I am a bit confused to decide the right approach.
so here is the problem.
I have an object of params and need to create query string to append with URL with help of encodeURIComponent....
I'm trying to learn how to program with JAVA which is more or less my first programming language (had some basic Pascal and C,C++ in school and collage) but still a Beginner from a capital B.
Right now I'm working on a mini game, which is similar to the break out game but it's going to have my ...
The question Does this method guarantee that cells in a CSV will be correctly partitioned? is a duplicate of this one (10k+ and mods only) which asks whether a singular function properly 'escapes' bits of text from a CSV when handed to the function.
My personal opinion is that it does not meet t...
I am using a toolbar button to present a modal view controller (in which I let the user export data as a PDF file). The main section of my app is a UITableViewController subclass embedded in a UINavigationController.
Here is a schematic of my layout.
The modal itself is embedded in a UINaviga...
Hi. I was solving this problem for implementing linkedList class and ListNode class, and Insert method, Remove Method for Linked List.
and I was wondering if I can get any code review and feedback. You can find this problem below.
class ListNode:
def __init__(self, value=None):
se...
I have two checkboxes chkProjectTechs and chkTeamLeader
if (!chkProjectTechs.Checked || !chkTeamLeader.Checked)
{
//code there
}
For me, this if says, "only execute this code if chkProjectTechs is not checked or chkTeamLeader is not checked. So when I...
I had 15 minutes to code the following question:
Given a file name return the char which appears maximal number of times.
please do not take into account the unit test.
Please look at the final foreach loop, I could have also used a for loop, I have doubts what is the best way to implement find...
I was solving this problem for implementing linkedList class and ListNode class, and Insert method, Remove Method for Linked List.
and I was wondering if I can get any code review and feedback. You can find this problem below.
class ListNode:
def __init__(self, value=None):
self.va...
I was asked to complete the task described below:
Event Emitters are objects that serve as the core building block in event-driven architectures. They simplify the process of handling asynchronous
events and enable clean and decoupled code.
Create an Event Emitter module in JavaScript ...
@SamOnela I don't think PHP would compile that... I think that was a copy paste thing maybe. the post engine will allow for certain HTML tags and will render them as HTML.
position: sticky; elements are sticky within the bounding box of their direct parent containers. I wanted to make a stickily-positioned button that sticks to the bottom of the viewport, not its parent. So here's what I did:
#container { position: relative; top: -99999px; }
#offset { height: 9999...
@DimaVizelka, I removed the HTML Tag because it is not needed for formatting on our site, but the space does not appear to be a result of formatting so it needs to stay in your post because it was mentioned in this answer/review. — Malachi ♦22 secs ago
This is a follow-up to Searching online English dictionaries.
Here is my code:
import webbrowser
import random
available_dicts = [
('Merriam-Webster Dictionary', 'https://www.merriam-webster.com/dictionary/', '%20'),
('Oxford Dictionary', 'https://en.oxforddictionaries.com/definition/'...
I'm using an API that allows to retrieve a list of data. That API uses public and private keys to identify requests.
For clarity of code, I would like to store these two values in a file and to access them as global values.
QUESTION:
In which file should I store these values?
Here is code to dynamically choose between three country options (United States, Canada, Other). After the user selects a country it will show the related select option or an empty input (when "Other" country is chosen). Then I pass the previous value into an input called spr(state/province/regio...
I need to create a C++ program that creates an array, fills the array with a series of random numbers, prints the elements of the array to cout, identifies the largest element in the array and prints the value and address of this element to cout. My code will also print the address of the array.
...
I have a scenario where I do filters depending on checkboxes checked. Now I have only 2 checkbox and I need to cover all escenarios into if else conditionals like:
if (!chkProjectTechs.Checked && !chkTeamLeader.Checked)
{
foreach (DataRowView list in lstTech.Selecte...
Stack Overflow is for fixing broken code and suggesting algorithmic approaches to problems, here implemented in Ruby. SO's sister-site, CodeReview is specifically for suggesting improvements to working code. I suggest you delete your question and post it at Code Review. You'll no doubt get more helpful answers at that site. — Cary Swoveland52 secs ago
This looks like a potentially better fit for Code Review than for Stack Overflow. We can help with identifiable problems, but if you're just looking for general critiques of your code that's better done elsewhere. — David22 secs ago
I'm new in stored procedures world and in one of my projects I'm trying to implement stored procedure for the search process. I'm not sure if everything I created is correct. Also I'm wondering if this code has any leaks or vulnerability on SQL Injection. Here is example of my stored procedure:
...
This is probably the last time I will post this data structure that I have been working on. I have added in an iterator and const_iterator class (although I do not use them probably where I should be). I also did not follow another persons advice to add emplace, emplace_front, and emplace_back si...