Well, I tried but feel like more could be said about the code itself... the approach though gives me shivers, if I was a DBA I would definitely not want this executing against a production server, especially from a potentially unsecured connection...
@Phrancis In this case with the callback function, it is showing that the function body is not going to be using that parameter to the reader; sometimes not all parameters are needed.
I'm new to C++. I'm trying to solve a problem which goes something like this:
Q: create varies string vectors, and using iterator to change those strings to uppercase.
Below is the code I came up with. However, the IDE always output error and I have no idea where I made mistake. It would be gr...
Often used if you want to split into asynchronous operations, and get different responses back depending on some strange criteria. Or you want something done after something else is done...
Another good use of callbacks are for event subscription, where you call your subscription function with a callback function to be used whenever the event is triggered.
Note that, if the poster is asking for code to be reviewed, offering alternative solutions is acceptable if paired with a review of the code. Also, reinventing the wheel is a perfectly valid way to learn a programming language. Telling someone attempting to do that to "use this builtin" -- which it's entirely possible that the poster knew about anyway -- is not helpful. — QPaysTaxes41 secs ago
In addition to what QPaysTaxes said, this is identical to a point already made by Joe Wallis and 200_success. Reiterating what others have already said (in a worse fashion) is not a good thing to do. — Quill6 secs ago
I'm from PPCG so I was making an esolang and I decided to write it in Python. Eventually it went from an esolang to an OEIS (Online Encyclopedia of Integer Sequences) lookup tool. I'm very new to Python.
Essentially this program takes an OEIS sequence number (e.g. 55 for sequence A000055) and t...
import*:
Please avoid importing all modules at all costs. Import each module you use separately
Regex ಠ_ಠ
Regex is evil, the worst. seriously. stop it. right now. kill python.exe right now and change it.
You use beautifulsoup, a dom parsing library, literally a few lines later, but you choo...
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:15:05) [MSC v.1600 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import braces
File "<stdin>", line 1
SyntaxError: not a chance
>>>
I have been working on a simplistic weather application that utilizes the openweathermap.com API. I have an ajax call to make an HTTP request to get a JSON object that contains the data which is returned in the success callback from the HTTP request. I use JQuery to display the response object's ...
I have a list of Comment objects comments. Each Comment has several properties, one of which is the date the comment was posted. I've sorted this list by date and there is at least 1 comment per date in a range.
I would like to loop over comments and for every date, create a new list of comments...
I have a lot of experience in Python and Haskell but am new to C++, so I'm wondering if my code is idiomatic. For one of the first assignments in my class, I wrote a linked list class (the "cities" are nodes in the linked list, the teacher wanted to make things interesting, I guess). Here's the h...
@ivan_pozdeev thanks for the suggestion. I've posted a question in code review (does that mean I should take this one down?). And yes, comment_arrays is an array of arrays. day_comments contains all the comments on a given day, and comment_arrays is an array of all the day_comments — PDN1 min ago
private string name;
public new string Name // Notice the use of the new modifier
{
get
{
return name;
}
set
{
name = value;
}
}
I keep seeing private / public properties that differ in case where the lowercase is the private property and the TitleCase is the public one. I used to prefix private with `m` for that distinction. Is the case difference a common practice in c#?
@ivan_pozdeev I see. I will ask a moderator to move it next time. In the meantime I'll delete it on Code Review since that one hasn't had any activity yet. Thanks! — PDN15 secs ago
I'm taking in a string of input from the command line, and when prefixed by 0o or 8# interpreting it as an octal string. I'd like to convert it to a byte array more directly, but I'm not sure how to perform the bit carrying in LINQ.
Here's how I'm doing it for Hexadecimal:
public static byte[] ...
This module is going to be part of a larger ElixirChess library for validating chess positions and moves, but I started with the core of it which is parsing a position from FEN notation into a more consumable format and back again. I'm basing this somewhat on Chess.js, so I decided to convert the...
I'm willing to listen to any advice you have for improving it.
from collections import defaultdict
import nltk
import numpy as np
seq, freq, sample = [t for ts in [[None] + nltk.casual_tokenize(line) + [None] for line in open("file.txt").readlines()] for t in ts], defaultdict(lambda: defaultdi...
Here is my code for converting a sorted array to a binary search tree. Please review and let me know the improvements or some better way of solving this.
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode...
Here is my code.
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public List<List<Integer>> levelOrder(TreeNode root) {
List<List<Integer>
I just finished writing a program which working with a database. Throughout the process when working with people to get past some of the hurdles I faced I was ridiculed for my SQL statements. I have never fully understand what to do to protect myself and I know there is a lot of information out t...
The Rubberduck 2.0 Code Inspections UI was recently redesigned (again!), this time featuring a GroupingGrid control (thanks @BrunoCosta!), and what appears to be a dynamic grouping:
Resources
The UserControl's resources include two CollectionViewSource definitions, which determine the sorting...
I am trying to create an application where I need to know where to put the logic. Here is the code
HomeController.java
@Controller
public class HomeController {
private EmployeeService employeeService;
@Autowired(required=true)
@Qualifier(value="employeeService")
public void s...
Hey guys, haven't ever been here before, but I've been bouncing around IRC's on FreeNode and was wondering if anyone here could shed some insight as to the best way to get Code Review on a javascript library I've developed/developing.
I don't really have specifics where I would just "ask/post a question", it's more just like a general library code review.
While looking at a recent question, I realized that there is no CSV parser in the standard Java library. I decided to write one that complies with RFC 4180. Highlights of the standard include:
Whitespace is significant.
Strings may be double-quoted. Inside a double-quoted string, newlines ar...
@ChrisHennighan You could try this site, Code Review, but we require the code to be present in the question. If you have a large library it may not fit in one question. If your code is split-up into modules, you could post each module separately and link between your questions.
@Mast that's where I'm iffy though, it's not really that I have any issues or anything, I just want someone to see if they can peer review and give some advice or something lol. Does that fall into this context still?
It's my first time creating a N-tier application. It's a WPF Application. I Also use repository design pattern and unit of work beside using EntityFramework in my Data Access Layer.
Here is my structure:
And Here is some of my classes:
Unit of Work Interface:
public interface IUnitOfWork : I...
I have a project I am working on, and I would like some, or all of it
reviewed, how can I ask for this review on Code Review in a way that
produces the best possible value?
This is not about a question being on-topic, or off topic. Rather, this is about making on-topic questions great qu...
@ChrisHennighan If there's anything else we can help you with, just ask. I prefer helping people post quality questions over closing off-topic ones because users didn't understand the scope of the site.
@Mast Definitely, that's another reason why I wanted to come here and see what people thought before I even composed something that may not be useful for anyone including myself lol. Thanks again.
t is number of tests; each test contains two lines: n and sequence
n is number of integers
sequence is a sequence of integers from 1..n (e.g. '4 1 2 3' if n is 4)
Rotate sequence until you maximize the number of integers that match their position in the string. (e.g. '4 1 2 3' s...
Were you an active user in the past that no longer contribute to Stack Overflow?
Hi, my name is Justin. Currently, we're seeking participants from Stack Overflow to participate in a question survey. The survey is composed of 10 questions and there is an incentive for participating in the resear...
@Downgoat string.format has many more formatting options and allows you to do more with it than % formatting. string.format also coerces types to strings, so it often doesn't need stuff to be explicitly converted to strings. — SuperBiasedMan57 secs ago
I'd like to know if I can improve the performance of my recent bot / and maybe some design patterns. So far, it's warning a user if it's using some bad words ( which are parsed from bad_words.txt) and it's entertaining the users by posting jokes from jokes.txt.
from selenium import webdriver
imp...
Suppose I have a controller in which whenever I want to perform any action, I need to check if the user is logged in or is the session exist. Here is the sample.
@Controller
public class MultiActionController {
@RequestMapping("/listUsers")
public ModelAndView listUsers() {
}
...
I recently completed this code challenge so just looking for some feedback on my code. The task is to read polygon coordinates from a file and calculate the perimeter, I was provided with a script containing bugs and asked to fix and improve the code.
Example input
data.csv
x,y
-16,-18
-18,-10...
Here is my code without using additional data structure. Assuming all the characters are alphabets and character checks are case-insensitive.
public static boolean isRepeated(String s) {
if (s == null) {
return true;
}
int length = s.length();
for (int i = 0; i < length; ...
I have CSV file which has structure like this (separated by tabulators):
VariableName DateAdded ValueNumeric
VariableName DateAdded ValueNumeric
VariableName DateAdded ValueNumeric
...
and I am changing it to form where there are all variables with same date in same line:
DateA...
I codded a python framework to automatically inject arbitrary codes inside of Android apps (insert backdoors inside of legit Android apps). The injection is done on the assembly level (smali).
I codded two payloads so far:
a logger to get in real time the code execution flow (with the return ...
I made this function for to get rid of writing numerical option values in a HTML-select manually.
From what I have seen so far it works as expected. But hints and suggestions are welcome anyway.
// Trying it out.
var selects = document.querySelectorAll('.drop-down');
selects = Array.prototy...
I want to pass a column2 to a function and update column3 with output of function. I have made func function to calculae the output. When i run the program
it only takes last value as input and outputs all columns with same value.What am i doing wrong?
cmd.ExecuteNonQuery();
...
Scenario description:
This is a customer information data entry form. First name and Last name are required. In addition phone number, e-mail and birth date are used to check the database for existing customers with the same information.
Either of these fields (phone, e-mail or birth date) can ...
This is a review from a different perspective, and as such it's legit. There's also plenty of precedent. Thanks for bringing to our attention, but I think this is fine. Feel free to raise on Meta — janos ♦8 mins ago
I have accomplished what I need to do, but the code is very messy and I know there is a better way to do this.
I am pulling some 'products' from a database based on a term ('product type'). I am checking if the 'product' is a 'featured product', then checking if the 'product' is 'text based' or ...
This question came up in regards to my comment on this post.
If somebody has two different approaches for reviewing a piece of code, should they combine them into one answer, or have separate answers?
could I get a could review on the function below please, also can anyone tell me how could I make this function process the api response in a more efficient and faster way.
products_list its the api response in the form of list of dictionaries which returns all products for one supermarket only ...
I'm glad that you got it to work. Perhaps you could post it on Code Review to get more feedback. I think that one improvement would be to get rid of exceptions in favor of options. Returning NONE replaces raising an exception and pattern matching against NONE replaces handle. I read that in O'CAML at least using options is much quicker than raising exceptions since it doesn't involve unwinding the call stack. See this question: stackoverflow.com/q/7952625/4996248 — John Coleman5 secs ago
@CaptainObvious The best way to iterate 35000 dictionaries is make a spelling mistake on the internet in a complex word and watch as at least one person rushes to correct your spelling
This is the implementation of BFS and DFS i have tried to follow from CLRS.Please suggest what can be improved in this code.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Graph {
VertexL...
I have several hundred rasters "A" (numbered from 001_A.tif to 100_A.tif).
I have several hundred rasters "B" (numbered from 001_B.tif to 100_B.tif).
I want to multiply them like this:
001_A * 001_B = 001_result
002_A * 002_B = 002_result
003_A * 003_B = 003_result
.
.
.
I have a loop in R, ...
I have a small R script (below) to generate a nonlinear correlation coefficient and I want a direct conversion to Matlab format. I could convert the functions like cbind or rnorm of R to matlab but can't gather all pieces together, so if anybody could help ? Many thanks in advance.
rdc <- funct...
Why does the below given program prints -128
#include<studio.h>
main()
{
char i=0;
for(;i>=0;i++);
printf("%d",i);
}
Also can I assign int value to char without type-casting it. And if I used a print statement in for loop it prints till 127 which is correct but this program current prints -128...
That's not the JavaFX API documentation: it is found at docs.oracle.com/javase/8/javafx/api/index.html What you are looking at there (I think) is a repository for code review for forks of JavaFX (i.e. code for consideration in future releases). — James_D8 secs ago
I'm voting to close this question as off-topic because it is about code review and belongs on codereview.stackexchange.com — Daij-Djan11 secs ago
I'm new to programming, I've learnt most of the basics in school and was wondering if I could practise over my holiday, I've installed Python 3.5.1 and have began programming all sorts of things to improve my capabilities, recently I've been thinking about programming a text-based adventure game ...
Task:
My implementation:
public class Main {
public static void main(String[] args) {
String fileName = "Brackets.txt";
Path filein = Paths.get(fileName);
ParentStack s = new ParentStack();
if (!Files.exists(filein) ||
!Files.isReadable(f...
Here is my approach.
1. Checking there is no cycle.(Using BFS)
2. All nodes are connected. (visited)
public static boolean isTree(int[][] adjMat) {
int numVertex = adjMat.length;
State[] isVisited = new State[numVertex];
for (int i = 0; i < numVertex; i++) {
isVisited[i] = St...
I have this java.util.Set implementation that is based on AVL-trees, which implies that the set is sorted. However, it provides two additional operations:
get(int i)returns the ith smallest element in the set, and
indexOf(Object o) returns the rank of the object o (the rank of the smallest elem...
I wanted to know if using a pattern like the one used for the second class is a good idea or not.
Is the usage clear enough ?
class gedcom_relationships_row : Manageable{
public:
long long int chd;
long long int mth;
long long int fth;
};
class gedcom_relationships : std::vector<ge...
I'm going to convert a code from Octave to FORTRAN. every thing looks ordinary but I get different results. I tried (about 2 complete days) different matrix solver and again different answers.
I know here is not for code debugging, but I don't know where make the difference.
Do you have any ide...
Here is my approach. Do DFS and check in stack whether the new node is already in the Stack or not.
public static boolean isCyclicDFS(int[][] adjMat) {
int len = adjMat.length;
boolean[] isVisited = new boolean[len];
for(int i =0; i<len; i++) {
isVisited[i] = ...
Forum.
I have two DataTables:
dt: is populated from a csv file with over 1.7 million rows
dataStructure.Tables["AccountData"]: is populated from a database query also roughly a million rows
I use the following code to iterate through and compare the data from each set of rows. The code takes...
@Jaywalker the correct term for "pedanticism" is pedantry. (Normally I wouldn't point this out, but in this case I couldn't resist the irony.) — Nathaniel2 hours ago
I explain the nonlinear correlation coefficients in this paper and provided the code in this post. The nonlinear nonparametric regression is an extension of this work and its description can be found in the linked paper. In short, the subset means are the regression points and we can achieve a ...
The purpose of this rewrite code is to change the URL to include www on the URI request and pass everything else to it. I'm finding that the URL parameters are not being passed on.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{H...
In the following question, I'm unsure regarding how much typos and/or omissions one should accept before closing as broken code (or similar). The edit a few hours ago changed variable naming, clearly indicating rewrite before posting. In addition there are omissions related to instantiating the panda data frames.
I have code that backup files to remote servers.
There are 2 pandas data frames:
storedfiles: that points to the files already stored in previous runs
filelist: a list of candidates to be stored in one of the depots (comes from a config file).
Filelist structure has the following columns:
...
Yes, one typo, but that is indicative of not copy-pasting the question, and rather rewriting before asking the question. And such rewriting could be OK, but raises the question on how "correct" is the code in the question?
I may just be to pedantic, but in cases like this I find it hard to decide whether to VTC or not as the code is not runnable as is, and clearly is not the code the actual OP is using in their "production" environment.
I'm calling an expensive function that dynamical changes as the end user types in a textbox.
To reduce the amount of calls to the function I've used setTimeout to delay calling the function,
and if the function is called again whilst waiting to run, it'll also remove the last function request via...
I wrote this script for adding information to a compressed file and compressing the output:
#!/bin/env python3
import argparse
from Bio.bgzf import BgzfWriter
import gzip
import sys
def main():
args = parse_args()
# with BgzfWriter(args.out, 'wb') as fd_out:
with gzip.open(args.ou...
I have written some code and would like to put it into functions to make it more efficient however am struggling any help is very much appreciated also I have been told to use parameters and not globals your help is very much appreciated:
sorted_list = []
for i in range(len(headers_list)...
Just got this comment in my project management course on one of my written assignments:
> You were the only one to highlight the "lack of familiarity" and I'm glad you did. That may seem like a small thing, but it plays such a large role in a group of people forming a team or just remaining a group of strangers.
It seems interesting that no one else got that.
It was even discussed in the article we were supposed to be commenting on.
I just want to output something like this in the terminal :
Executing in 10s..
I've tried coding it in this way :
#include<stdlib.h>
#include<stdio.h>
#include<unistd.h>
void printTimer(int delay){
while(delay--){
printf("Executing in %ds...\r",delay);
fflush(stdout);
...
I wanted to put the title "How the false Gods of Stackoverflow are created".
This started with me asking a question, simple in nature, but that you see being used wrongly so many times, that even at an intermediate level you start to wonder what is the correct answer.
Bang ... comes [duplicate...
Thanks for taking the time to do the tutorial. Stackoverflow is more a Q&A site, so I'd suggest making a blog post for your tutorial. And, if you'd like your code reviewed you can visit SO's sister site: CodeReview. Again, thanks for your efforts. :-) — markE12 secs ago
Background
This is a follow-up of this CR: Compile-time plugin system. The code exposed below can also be browsed on this gist, which shows the differences between both questions (original is version 1, this one is version 3).
This is a simple factory which is able to serve the requested specif...
I'm looking to improve the runtime and efficiency of my VBA code that performs multiple Replace operations on an Excel Spreadsheet. I started out with the following (please forgive me for this horrendous mess):
Private Sub symbolCheck()
Range("A2").Select
'Selects only to the end of all the data...
I am currently implementing pyramids in Lucas Kanade algorithm for optical flow. To be able to build pyramids, I need to pad the images (mirror edge matrix elements) for the required amount of rows/cols determined by parameter half_window.
I have written the code below which works but I am new ...
Background information for those of you who don't know what 4chan tripcodes are:
A tripcode is the hashed result of a password that allows one's identity to be recognized without storing any data about users. Entering a particular password will let one "sign" one's posts with the tripcode g...
My code works and I am looking for smarter ideas to be more efficient?
For string similarity, it is defined as longest common prefix length,
for example, "abc" and "abd" is 2, and "aaa" and "aaab" is 3.
The problem is calculate the similarity of string S and all its suffixes,
including itself a...
I read through other questions here and improved the code and added a new feature. The old question can be found at: Email a notification when detecting changes on a website
The improvments that are done until now:
using a difflib.SequenceMatcher
added a logger
using format for strings
excepti...
@SimonForsberg just read this post here on the airport arstechnica.co.uk/security/2016/02/… pretty interesting and crazy. Not sure if you've read it before though.
http://www.commitstrip.com/en/2016/02/16/better-than-a-guy-who-codes-a-gal-who-codes/ CommitStrip Better than a guy who codes, a gal who codes! CommitStrip 1455646911
Welcome to SO. Please check the help pages about asking the questions: stackoverflow.com/help. As for now, your question is completely unclear. You did not ask anything. Please note that this is not a code reviewing site. You have to ask a meaningful question. — nolexa15 secs ago