I would really like that post to be stickied so everyone who comes into code review to see how good we are at our purpose that we write stellar code like that ;)
My professor gave us this source code as a template for a project and there are errors when BinarySearchTee is called. I'm not entirely sure as to why this is?
import java.util.Scanner;
import java.io.*;
public class useBinarySearchTree {
public static vo...
My professor gave us this source code as a template for a project and there are errors when BinarySearchTee is called. I'm not entirely sure as to why this is?
import java.util.Scanner;
import java.io.*;
public class useBinarySearchTree {
public static vo...
In my world, I have a form of magic that can be used by a practitioner to connect with a subject's mind at touch range, and effectively give an experienced, powerful practitioner total control over that person's mind and body.
Such a practitioner could easily kill an individual, or - given a min...
Aim: Dynamic SQL based on user input
Use: User search boxes to get a result
Query: Does the below leave the code exposed to SQL Injection attacks?
--Declare Variable to hold the Dynamic SQL
DECLARE @vSQL varchar(max);
DECLARE @sSomeValue varchar(max);
DECLARE @sFirstName varchar(max);
--Your...
I created an addon for WoW, and for its new version I need to convert the database format, so I need a function to do it automatically This is the current format: MyAddonDB = { ["profiles"] = { ["Mage"] = { ["Bars"] = { { { ["castbyme"] = true, …
I have a couchdb view with the following view/reduce function. After working over 2 hours on it, I have a result I am happy with, but I believe there is a lot of room for improvment.
Basically I would like the code a bit more slim :)
Maybe one of you has an idea, i am out.
reduce: function (ke...
for (i = 1; i <= x; i++)
for (j = 1; j <= z; j++)
{
c[i][j] = 0;
for (k = 1; k <= y; k++)
c[i][j] += a[i][k] * b[k][j];
}
I have the above code for multiplying two matrices but it is very hard to comprehend how all the three loops are working.For me its like imaginin...
open(d1,"<f1.txt") or die "cant open file";
while(<d1>)
{
$l=$_;
if($l=~/^\d+.*\.$/)
{
print $l;
}
}
close(d1);
I am new to perl.
Can anyone explain what does $l=~/^\d+.*\.$/ do. Why is it used.
I have been slowly evolving some code for Git and VSS interop based on a quest I started a while ago
And the code is now working, some parts have been updated without test (such as the init) and I am not 100% sure everything is doing what it should/is the best way and some parts seem really roun...
Input
The input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are two numbers m and n (1 <= m <= n <= 1000000000, n-m<=100000) separated by a space.
Output
For every test case print all prime numbers p such that m <= p <= n, one number per l...
This is my current code:
def search(word,source):
places = []
for x in range(0,len(source)):
if source[x] == word[0]:
if source[x:x+len(word)] == word:
places.append(x)
return places
How would I optimize this without using regular expressions?
I use this node.js script to migrate MongoDB collection to a schema to another, it does work if the collection is <20k documents, but slow down to a crawl and sometime throw a FATAL ERROR: JS Allocation failed - process out of memory.
Is it because of a memory leak? Or the intensive call to proc...
A practice interview question.
Question: How would you design a stack which, in addition to push and pop, also has a function getMin which returns the minimum element? Push, pop and min should all operate in O(1) time.
class stackWithMin
{
private:
std::vector<int> stack;
std::vector<int>...
After a couple of small programs in Python we are now asked to do some basic stuff in Java. I don't really know where to start to improve this and whether it's even necessary.
This is an exercise, so the resulting message for when the denominator is zero should not be taken too seriously.
impo...
My colleagues and I sometimes write not readable and not maintainable CSS, because we are working in damn "move fast” mode. So, I made some CSS folder structure, which I think help us to:
keep stylesheets maintainable;
keep code transparent, sane, and
readable;
-keep stylesheets scalable.
I...
This is what I think is the most important, and a simple explanation.
This code will create the function once for each object:
this.Display = function () {
alert("Id=" + this.Id);
}
Using prototypes, the function is instead created only once and applied to all objects of that kind. Wastes...
don't even remember having written that answer, was such a long time ago.
would be interesting to hear what JS experts here think of it
A while back I had to do a project for school in Python, creating a game or something interesting. I decided to make a memory game. The code isn't really nice and neither are the variable names. It's not supposed to look good, and all that matters is the functionality. I had done a lot of movemen...
I need to generate a T-SQL script for loading data into this table:
create table dwd.FiscalCalendars (
_Id int not null identity(1,1)
,_DateInserted datetime not null
,_DateUpdated datetime null
,CalendarDate date not null
,CalendarDayOfWeek int not null
,CalendarDayOfMo...
To me it's screaming like... I'm pretty sure that we can never get into insert unwanted situation here, but to be extra extra sure, I'll put an extra Assert on it
There's a discussion going on over at comp.lang.c++.moderated about whether or not assertions, which in C++ only exist in debug builds by default, should be kept in production code or not.
Obviously, each project is unique, so my question here is not so much whether assertions should be kept, bu...
This being code review, please voice any and all problems you see in the code whether they directly relate to the question Title or not.
The basic jist of the software is that it stylizes the shell prompt (in the example, just Zsh, but could be configured to style Bash, Sh, Fish, etc.). Future...
then, it's good to add the assert to codify that assumption, to document it for future maintainers who might change the code and not know this important assumption
@JeroenVannevel are we talking C# or Java? Assuming C#. I'm not quite sure about C#, but I know that very often in Java, the assert keyword has no real effect.
This is code of sieve of eratosthenes.....can i make it more efficient? or is there any way to do that?
#include <stdio.h>
#include <string.h>
#include <math.h>
void setvalue(int array_copy[], int i, int n)
{
int j,p;
for(j = i*i ; j <= n ; j +=(i*2) )
{
array_copy[j...
This is not a code review. It's good to share your solution, including the bugfix, but in my opinion that doesn't make it a better answer than mine. I disagree with your decision to unaccept my answer in favor of this one. — janos7 hours ago
He unaccepted it? At this point, I feel that others might as well flag such answers for CW conversion. I don't recall a single user CWing their own such answer.
While adapting a Joomla!2.5 backend-only component to Joomla!3.3, I've ran into the issue of the toolbar in the data edition page not working at all. Only two buttons were declared: Save and Cancel; neither do anything. Upon first glance, the problem is neither on the view.html.php file, nor tmpl...
@janos Huh, weird. That was one of the first things I changed. I moved the statements in the try block and got an error and assumed I can't declare them there. I think I forgot the last print statement which referenced them outside the try-catch-block.
Please review the implementation of Djkistra, Kruskal, Prim algorithms. Points on which I have doubt:
My Graph doesn't have any ID for nodes. Nodes are accessed based on their data. Is there any general approach in that? Should nodes be referenced by an ID as that will also make these algo som...
I learn BASH scripting occasionally from time to time, now I am working on a simple bash script that serves to maintain dove-cot user database. The general purpose of the script is able to list, add or delete user entries in the specified file. Please add some comments about the code - common mis...
I've written a method that takes an object whose keys are arrays and converts it to an array of objects.
I feel like the code is fairly complex, after waiting a week or so and revisiting it, I don't think anyone would be able to really understand what is going on, especially if they aren't used ...
I am collecting tweets using a Python script and I want to store them in a database.
I want to find out the lowest tweet id and for each tweet, I want to change the id field to an _id field.
Is there any way I could optimize this piece of code?
search_result = #list of tweets
min_id = float(...
Meme: calling-the-punisher
Originator: @Vogel & @Janos
Cultural Heigh: The 2nd Monitor
Background: On Nov 24 2014, the following remark was made in the chat room:
Janos: am I right here? ->
This is not a code review. It's good to share your solution, including the bugfix, but in ...
I am having trouble deciding on which answer to accept on my question: Convert Object Keys according to Table/Map object. konijn's answer is great and helped me get to my final solution. But my answer code is slimmer and combines the convert/revert into a single understandable function. For future onlookers, what do you think would be best?
@200_success Thanks, I think your statements make it very clear that konjin's is better for future onlookers as it shows how to improve the code in question directly.
I converted the answer into a comment. Had the author done a better job of posing the question, so as to avoid the X-Y problem, it might have been appropriate to post such an answer.
I am trying to follow the template provided here to create a doubly linked list in java. This homework is based on this lecture. Can someone please review my implementation?
No change to this part of the code
/* DListNode.java */
/**
* A DListNode is a node in a DList (doubly-linked list)....
I've always given the standard bullsh** answer to the usual interview question: Why do you want to work for us?
To work at your company is an exciting opportunity for me to exercise the immense knowledge I've gained so far, and to progress further in my career.
Would it reflect badly upon me ...
I've looked at the examples on the github page, but this has me scratching my head as to why it's not working. Grunt file:
uncss: {
dist: {
files: [
{src: ['build/html/index.html'], dest: 'public/css/site.tidy.min.css'},
],
options...
This website has a useful list of the various iDevice models. And the "identifier" column is helpful for any iOS developers, as this is the string you can fetch in your application to determine what kind of device your program is running on.
However, for reasons, I am interested in determining ...
Based on this question on math.SE regarding probabilities in variations on the Monty Hall problem, I cobbled up a simulator in Ruby to give myself an introduction to the language.
Since this is my first Ruby program, I'm especially looking for feedback regarding Ruby style, but I would love any ...
@nhgrif I am trying to set up an admin page for a website, and I am having a hell of a time trying to get my approve/disapprove functionality to work with Radio Buttons.....
So, what I'm trying to do is make it so that the user has to keep entering things in until they follow the specifications listed, which is it has to be a number between 1 and 5. But that happens is they cn keep trying and trying, but when they finally get it right, and the number is stored into a...