body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<blockquote>
<p>Given a binary tree, return a list of each level.</p>
</blockquote>
<p>I'm looking for a general review and a mention on best-practices, optimization, and verification of my complexities.</p>
<p>Time complexity: \$O(n)\$</p>
<p>Space complexity: \$O(2^{height})\$ </p>
<pre><code>public class Print... | [] | [
{
"body": "<p>I think that this code is overly complex for the task on hand. Since you pass in a list that is already tree-like, there is no real reason to convert it into a real tree data structure and then back again. By eliminating the intermediate step, you can reduce overhead and increase speed tremendousl... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T06:25:12.070",
"Id": "57275",
"Score": "2",
"Tags": [
"java",
"algorithm",
"tree"
],
"Title": "Get the levels of a binary tree"
} | 57275 |
<p>The idea is to show how many times a user (by <code>EmployeeID</code>) is in the <code>TblTableList</code> and then update the <code>TblTableStatusCount</code></p>
<p>I have been learning Fetch this week so wanted to ensure I have gone down the right path and this is a small database, can/should I use this for any ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T10:02:30.063",
"Id": "102325",
"Score": "1",
"body": "Can you explain why you need to store the count vs. querying the count when you need it? It would also help if we knew what flavor of SQL you're using."
}
] | [
{
"body": "<p><strong>Nitpicks</strong></p>\n\n<ul>\n<li>The keyword capitalization is inconsistent. <code>Alter PROCEDURE</code> should be <code>ALTER PROCEDURE</code>. Likewise with <code>case WHEN ... then 1 else 0 end as cntX</code>. Keywords should be capitalized to distinguish them from variables and fiel... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T09:08:17.997",
"Id": "57284",
"Score": "7",
"Tags": [
"sql",
"sql-server",
"t-sql",
"cursor"
],
"Title": "SQL Stored Procedure Get Distinct and Update"
} | 57284 |
<p>I have the following query. I know there's an easier way to do this without the sub queries, or at least optimizing how they're used. I've read about cross joins and using <code>HAVING</code> but cannot figure out how to make this better as I know it's pretty bad.</p>
<p>Basically what I'm trying to do is get the t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T10:00:36.930",
"Id": "102323",
"Score": "0",
"body": "Why not just use `WHERE c.id = 9`? Do you need to make sure it exists in the products table?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T10:46... | [
{
"body": "<p>There are some things that you don't need here</p>\n\n<pre><code>SELECT u.id, \n u.avatar, \n u.storeName,\n (SELECT COUNT(o.id) FROM orders o WHERE o.storeId = u.id) AS orders\nFROM users u\nWHERE (SELECT c.id\n FROM categories c, products p\n WHERE c.id = p.category... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T09:49:55.933",
"Id": "57285",
"Score": "7",
"Tags": [
"optimization",
"performance",
"sql",
"mysql"
],
"Title": "Getting the top 10 stores within a category"
} | 57285 |
<p>Say I have the following code. What are your thoughts on questions 1-4 below?</p>
<ol>
<li><p>I think it's way too long when I have to list out most of the fields. Is there any better way of doing this?</p></li>
<li><p>I build up the DB column name so it can be used later in my select and insert statement.</p></li>... | [] | [
{
"body": "<blockquote>\n <p><strong>I think it's way too long when I have to list out most of the fields. Is there any better way of doing this?</strong></p>\n</blockquote>\n\n<p>Extract the creation of the parameters in a method passing in the <code>Patient</code> object and the <code>SqlParameterCollection... | {
"AcceptedAnswerId": "57359",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T10:04:44.240",
"Id": "57286",
"Score": "2",
"Tags": [
"asp.net",
"vb.net"
],
"Title": "Long list of SQL parameters and audits"
} | 57286 |
<p>I'm new to JavaScript, and in Java I probably would do this as a singleton. I need something that I can call from anywhere and instantiate only once.</p>
<p>This is what I have done, but I need some advice to write it in the right way in this new prototype based and functional JavaScript.</p>
<pre><code>var winsto... | [] | [
{
"body": "<p>Interesting question,</p>\n\n<p>You have a ton of repeating code, so don't hesitate to write more helper functions so that this:</p>\n\n<pre><code>genericLogger = new (winston.Logger)({\n transports: [\n new (winston.transports.Console)(),\n new (winston.transports.File)({ filename: '... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T10:50:12.970",
"Id": "57289",
"Score": "1",
"Tags": [
"javascript",
"beginner",
"node.js",
"logging"
],
"Title": "Logger module with JavaScript"
} | 57289 |
<p>I have a 2D list like this:</p>
<pre><code>>>> a = [[8,2,3,4,1,2,1,1,3,1,0,1],
... [1,2,3,4,1,1,5,1,3,1,1,1],
... [9,2,3,4,2,1,1,1,3,1,0,1],
... [1,2,3,4,1,1,1,5,3,1,1,1],
... [1,2,3,4,1,1,6,1,3,0,1,1]]
</code></pre>
<p>I want to convert it to: </p>
<pre><code> result = {0: {0: [10], ... | [] | [
{
"body": "<p>Your code has two nested loops for each array row, which means that you are having to scan every row multiple times to get your result. You can almost get what you want, but with a linear algorithm, doing the following:</p>\n\n<pre><code>d = {}\nfor idx, val in enumerate(c):\n d.setdefault(val,... | {
"AcceptedAnswerId": "57302",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T12:34:09.817",
"Id": "57297",
"Score": "1",
"Tags": [
"python",
"optimization",
"python-2.x",
"hash-map"
],
"Title": "Convert 2D list to dict of list of index"
} | 57297 |
<p>I made a Rock, Paper, Scissors game and would like the code to be reviewed.</p>
<p><strong><code>Main</code> class:</strong></p>
<pre><code>public class Main {
public static void main(String args[]){
Game game = new Game();
game.gameLoop();
}
}
</code></pre>
<p><strong><code>Game</cod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T14:51:36.120",
"Id": "102375",
"Score": "2",
"body": "One little comment, the class `Random` comes with the method `nextInt()` so you could do `Random.nextInt(4)` instead of multiplying a floating point. Please someone correct me if... | [
{
"body": "<p>I will not cover the style convention, but do know that there is work to do !</p>\n<h2>Empty if</h2>\n<p>You should never use empty if. This would to someone thinking that the <code>if</code> is not necessary, remove it and bang your program doesn't work anymore.</p>\n<blockquote>\n<pre><code> ... | {
"AcceptedAnswerId": "57303",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T13:44:13.710",
"Id": "57301",
"Score": "10",
"Tags": [
"java",
"game",
"rock-paper-scissors"
],
"Title": "Rock, Paper, Scissors Game in Java"
} | 57301 |
<p>I ran into this <a href="https://stackoverflow.com/questions/24804905/generate-all-possible-words-typed-on-a-phone-keypad-recursively-in-javascript">question</a> on Stack Overflow. It looked like a really cool thing to try myself, being that I haven't done any recursion for ages (read at least 2 years).</p>
<pre><c... | [] | [
{
"body": "<p>Overall, I'd say recursion is a good way to go. Good use of an IIFE to keep things tidy as well. I do however have some concerns.</p>\n\n<h3>Input checking</h3>\n\n<p>Firstly, if I pass an empty array, I get a stack overflow, since you only check for a length of 1 - not for a length < 1. I am t... | {
"AcceptedAnswerId": "57317",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T14:57:19.640",
"Id": "57305",
"Score": "4",
"Tags": [
"javascript",
"recursion"
],
"Title": "Generating all keypad possibilities"
} | 57305 |
<p>I've been tasked with updating our current error logging system to prevent the logging of similar errors (from a single client program) that were probably caused by the same event. The code here is what I have added in order to accomplish this. Are there any obvious issues I am missing or is there a simpler way to a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T16:15:31.580",
"Id": "102384",
"Score": "0",
"body": "After more testing I found that i'm not recording 4 most recent errors I need to adjust the Dequeue() operation to be `if( PreviousErrors.Count > 3) PreviousErrors.De... | [
{
"body": "<pre><code>ErrorObject newError = new ErrorObject(…);\n</code></pre>\n\n<p>This is one of the cases where most people will probably agree that you can use <code>var</code> here. Doing that doesn't lose any information (you can still see at a glance that <code>newError</code> is an <code>ErrorObject</... | {
"AcceptedAnswerId": "57327",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T15:13:30.357",
"Id": "57307",
"Score": "4",
"Tags": [
"c#",
"multithreading",
"error-handling"
],
"Title": "Simple way to prevent duplicate logging of errors"
} | 57307 |
<p>I just programmed a quiz and the code is given below. Is there a better way to program to do what I have done? Also I tried to do transition effect while the question is changing, but it isn't working.</p>
<pre><code><!DOCTYPE html>
<html>
<head>
<title>Quiz</title>
<link r... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T16:03:16.400",
"Id": "102381",
"Score": "2",
"body": "Be aware that we cannot help you with the non-working transition effect. Such questions belong on Stack Overflow."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDa... | [
{
"body": "<h2>Overview</h2>\n\n<p><strong>Overall, this code looks moderately well written, albeit with questionable formatting.</strong> I'm going to suggest some formatting methods that aren't necessarily best practice, but will improve the look and readability of your code. I'll also be making a suggestion ... | {
"AcceptedAnswerId": "57544",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T15:46:49.040",
"Id": "57310",
"Score": "7",
"Tags": [
"javascript",
"html",
"css"
],
"Title": "Is there a better way to design this quiz?"
} | 57310 |
<p>I've written the following code ages ago (10+ years) which is part of a simple chat server. I'm going to refactor it a bit in Java and then for fun I'm going to convert it to Scala and use Akka actors instead of threading.</p>
<p>Do you see any thread issues that can arise from the method of synchronization?</p>
<... | [] | [
{
"body": "<p>Yes there is a thread safety issue. While the <code>getIterator()</code> is synchronized, the <code>Iterator</code> it returns is not. <code>LinkedHashMap</code> supports removal through the <code>values()</code> view, and hence the <code>Iterator</code> can be used to modify the <code>Map</code> ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T16:27:22.670",
"Id": "57313",
"Score": "4",
"Tags": [
"java",
"thread-safety",
"hash-map"
],
"Title": "Synchronized LinkedHashed map"
} | 57313 |
<p>This works, but do I have to make a new array, <code>result</code>, or is there a way to just insert the field I need into each <code>$key</code> of the received parameter <code>$data</code>?</p>
<p>Won't this way take up more memory needlessly?</p>
<pre><code>function add_tax($data){
$result = [];
... | [] | [
{
"body": "<p>You could try something along these lines:</p>\n\n<pre><code>function add_tax($data){\n foreach($data as $product => $details) {\n $data[$product]['tax'] = 0;\n }\n return $data;\n}\n</code></pre>\n\n<p>EDIT 1:</p>\n\n<p>After a bit more researching on <a href=\"... | {
"AcceptedAnswerId": "57326",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T16:28:23.437",
"Id": "57314",
"Score": "4",
"Tags": [
"php",
"array"
],
"Title": "Returning nested array with added key=>value"
} | 57314 |
<p>I have a Python 2.7.6 script parsing large files (~60MB to ~2GB) containing lines of the following format:</p>
<blockquote>
<p>componentA componentB < floating point value ></p>
</blockquote>
<p>My goal is to sum the floating point values for duplicate pairs of components and reflected pairs, reducing each pa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T17:53:43.257",
"Id": "102401",
"Score": "0",
"body": "If I understand correctly, you do not really need any additional data structures. While reading the list swap component names when necessary, then just sort the list."
},
{
... | [
{
"body": "<p>As requested:</p>\n\n<p>Sort the list according to the component names. To achieve a correct order, either swap component names when necessary, or supply the custom comparator (which will account for <code>(componentA, componentB)</code> being the same thing as <code>(componentB, componentA)</code... | {
"AcceptedAnswerId": "57329",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T17:14:50.507",
"Id": "57321",
"Score": "0",
"Tags": [
"python",
"optimization",
"algorithm",
"python-2.x"
],
"Title": "Using Comprehensions to Handle a Large Dataset in Pyt... | 57321 |
<p>I am using this code to write more than 170,000 rows to an Excel document. All in all, the file generation process takes about 3 minutes total. (I've already shaved off about ten minutes by shaving off overhead in the form of Apache POI and an unnecessary ArrayList) I'd like to shave off some more time, but I'm curr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T17:51:17.113",
"Id": "102399",
"Score": "0",
"body": "Can we see the code of `FileUtils.writeStringToFile()`? From the looks of it, that will need to open the file again and again. Without profiling though, it's just a guess whether... | [
{
"body": "<blockquote>\n <p>I'd like to shave off some more time, but I'm currently out of ideas.</p>\n</blockquote>\n\n<p>Run the code in a profiler, to find out where the bottleneck is. At a minimum, force the jvm to dump the thread stacks every 5 seconds or so, and find out where it is (because it is prob... | {
"AcceptedAnswerId": "57334",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T17:25:25.427",
"Id": "57325",
"Score": "3",
"Tags": [
"java",
"performance",
"excel"
],
"Title": "Improving performance in generating an Excel file"
} | 57325 |
<p>This is my revised code of Stopwatch:</p>
<pre><code>package com.zm0617;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.event.*;
public class MultiThreadedStopwatchController implements StopwatchController,
StopwatchState {
private volatile static b... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T04:08:39.767",
"Id": "102700",
"Score": "0",
"body": "What are you looking for here? Does it work correctly? You want advice about how to make it more efficient or reduce the number of lines of code?"
}
] | [
{
"body": "<p>Going from <a href=\"https://codereview.stackexchange.com/q/57252/40788\">your previous question on the topic</a>, I'm tempted to point you back to the accepted answer but, as you <a href=\"https://codereview.stackexchange.com/questions/57252/inefficient-stopwatch?rq=1#comment102287_57264\">pointe... | {
"AcceptedAnswerId": "59579",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T18:56:29.313",
"Id": "57330",
"Score": "4",
"Tags": [
"java",
"multithreading",
"datetime",
"swing",
"timer"
],
"Title": "Inefficient Stopwatch - revised"
} | 57330 |
<p>This is my revised code of the <code>Calculator</code>:</p>
<pre><code>import java.math.*;
import java.util.*;
public class Calculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Welcome to the Calculator!");
do {
Syst... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T19:14:53.357",
"Id": "102428",
"Score": "2",
"body": "Why do you have combined functions (ie multiplyOrDivide) rather than having one function for multiplication and one for division? Yes, it's DRY, but its not clean."
},
{
... | [
{
"body": "<p>From <a href=\"https://codereview.stackexchange.com/q/57134/40788\">your previous question</a>:</p>\n<blockquote>\n<p>I have a simple calculator program that needs some reviewing. Is this as efficient as it can get, or is there a better way?</p>\n</blockquote>\n<p>I'll try tackling both processing... | {
"AcceptedAnswerId": "58379",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T19:01:43.987",
"Id": "57331",
"Score": "4",
"Tags": [
"java",
"console",
"math-expression-eval",
"calculator"
],
"Title": "Simple Calculator - revised"
} | 57331 |
<p><a href="https://codereview.stackexchange.com/users/35211/garrett-openshaw">Garrett Openshaw</a> had an okay answer to <a href="https://codereview.stackexchange.com/q/39551/18427">Codingbat maxMirror challenge</a></p>
<p>But there were a couple of issues with the code he gave, so I decided to review it and make it ... | [] | [
{
"body": "<p>This is looking very good.</p>\n\n<p>First thing I would do is split out a method, <code>GetMaxMirror</code>, and rename <code>maxLength</code> to <code>maxMirror</code>. Then I would put braces around the <code>break</code>, maybe invert the condition <code>if (sequence[frontIndex] == sequence[i]... | {
"AcceptedAnswerId": "57344",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T19:53:03.193",
"Id": "57333",
"Score": "8",
"Tags": [
"c#",
"algorithm",
"rags-to-riches"
],
"Title": "Response to an answer: Solution to maxMirror problem"
} | 57333 |
<p>I'm trying to hover over over the img then use Greensock Tweenmax on hover to control the speed and opacity of the text within the span. The opacity will change on mouseover and mouseout.</p>
<p>The problem is that I'm having to repeat the same exact same effect on several div's and it's becoming repetitive. Each... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T22:04:58.443",
"Id": "102452",
"Score": "1",
"body": "Welcome to Code Review! To make life easier for reviewers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of ... | [
{
"body": "<p>The recommended way is to use <a href=\"http://learn.jquery.com/events/event-delegation/\" rel=\"nofollow\"><code>event delegation</code></a>:</p>\n\n<pre><code>$('.test, .testx, .testxy, .testxyz')\n .on('mouseover', 'img', function (e) {\n TweenLite.to($(e.delegateTarget).find('span'), 1.5, ... | {
"AcceptedAnswerId": "57373",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T22:04:00.410",
"Id": "57339",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Simplifying similar functions using a hover state with different div content"
} | 57339 |
<p>This algorithm seeks to find all of the possible permutations of a word:</p>
<pre><code>-(void)permute:(NSMutableArray*)word position:(int)p length:(int)l{
if(p==l){
[self.allPermutations addObject:[word componentsJoinedByString:@""]];
}
else {
for(int i = p;i<l;i++){
NSString* t;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T22:01:40.557",
"Id": "102673",
"Score": "0",
"body": "Is this an array of strings containing only single characters? Or is this intended to permute an array of anything?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creation... | [
{
"body": "<p>Before I comment on performance, I want to comment on style and naming and such.</p>\n\n<p>First and foremost, let's not use single letters for variables. They're meaningless. It's hard to follow what's happening in your code when it's just a handful of letters. Longer variable names has ZERO i... | {
"AcceptedAnswerId": "57347",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T22:06:42.887",
"Id": "57340",
"Score": "4",
"Tags": [
"optimization",
"algorithm",
"recursion",
"objective-c",
"combinatorics"
],
"Title": "Seeking improved Objective-C... | 57340 |
<p>The Codility's TapeEquilibrium problem asks:</p>
<blockquote>
<p>Given an array \$A\$ with length \$N\$, indexed starting from 0, find an equilibrium index \$P\$, such that</p>
<p>$$\left| \sum_{i=0}^{P-1} a_i - \sum_{i=P}^{N-1} a_i \right|$$</p>
<p>is minimized. Assume that \$2 \le N \le 100000\$ and ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T23:18:38.877",
"Id": "102462",
"Score": "4",
"body": "What does 83% mean? Does your code fail for some inputs? Or just that it's too slow?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T00:58:26.417"... | [
{
"body": "<p>I coded up my own solution, and mine was pretty close to yours, but mine received 100%. </p>\n\n<p>Here are the problems: </p>\n\n<pre><code>List<int> list = A.Cast<int>().ToList();\n</code></pre>\n\n<p>Both the <code>Cast</code> and the <code>ToList</code> are redundant here. Arrays i... | {
"AcceptedAnswerId": "57345",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T22:28:25.713",
"Id": "57341",
"Score": "7",
"Tags": [
"c#",
"programming-challenge"
],
"Title": "TapeEquilibrium implementation does not satisfy all requirements"
} | 57341 |
<p>This is a much simplified version of the real code focusing just on the handling of Futures from <a href="https://pypi.python.org/pypi/requests-futures" rel="noreferrer">Requests Futures</a>.</p>
<p>I have a few questions:</p>
<ol>
<li>I had to implement my own version of <code>as_completed</code> because the data... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-03-02T20:43:08.547",
"Id": "226702",
"Score": "0",
"body": "Sean, do you not find the requests-futures a bit slow? For example [I can't get an improvement over mulitprocessing.Pool()](http://stackoverflow.com/questions/35747235/python-req... | [
{
"body": "<p>Nice code, clearly written.</p>\n\n<p>I understand the rate limiting requirement.\nHaving the <code>drain()</code> call within the loop doesn't seem like the caller's responsibility, better to let the BG callback handle it, or defer until <code>finish()</code> as written, which does make sense. Ea... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T22:40:00.810",
"Id": "57342",
"Score": "8",
"Tags": [
"python",
"asynchronous",
"http",
"signal-handling"
],
"Title": "Questions regarding the use of Requests Futures for acce... | 57342 |
<p>This code is intended to be used with an image manipulation library that I'm working on, and the goal is to take the raw byte[] data from an image, and transform it into a 2D array where each position on the array has a value corresponding to the pixel coordinates of the image. </p>
<p>Comments concerning how to do... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T02:37:12.040",
"Id": "102481",
"Score": "0",
"body": "So, the image is a greyscale 8-bit bitmap? (Otherwise, one byte per pixel wouldn't make sense.)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T02... | [
{
"body": "<p>You should consider whether <code>byte[][]</code> is really the best type to represent a bitmap in F#.</p>\n\n<p>On one hand, arrays are inherently mutable and don't work well with pattern matching, so you might want to consider using <code>list<list<byte>></code>, especially if perfor... | {
"AcceptedAnswerId": "57476",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T23:31:12.920",
"Id": "57343",
"Score": "3",
"Tags": [
"array",
"image",
"f#"
],
"Title": "Transforming a byte array into an array of byte arrays with F#"
} | 57343 |
<p>I'm new in LINQ and Lambda expression. I'm not sure is there a way to shorten the result on this <code>o.z.cust.cust.cust.bintAccountNo</code>. As you can see below, the more table needed to join the longer the resultselector <code>cust.cust.cust</code>. Is there better way to shorten this Lambda expression's resu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T01:54:17.347",
"Id": "102472",
"Score": "0",
"body": "Where's `Tbl1` & friends coming from? Is there not a `DataContext`? Is this [tag:linq-to-sql] or linq-to-entities /[tag:entity-framework]? It would really help if you posted your... | [
{
"body": "<h3>Naming</h3>\n<p>Your entities / POCO classes have badly named members (assuming the entity names themselves aren't <em>really</em> named the way you've posted them), that break the C# naming conventions for public members - they should be <code>PascalCase</code>, ...and what's with the Hungarian ... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T01:44:57.400",
"Id": "57349",
"Score": "2",
"Tags": [
"c#",
"entity-framework",
"sql-server",
"lambda"
],
"Title": "Is there better way to shorten this Lambda expression's res... | 57349 |
<p>This question is attributed to <a href="http://www.geeksforgeeks.org/sum-of-two-linked-lists/" rel="nofollow">GeeksForGeeks</a>:</p>
<blockquote>
<p>Given two numbers represented by two linked lists, write a function
that returns sum list. The sum list is linked list representation of
addition of two input nu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T07:02:10.693",
"Id": "102505",
"Score": "0",
"body": "This looks way too overengineered to me. The way I have it in mind is that you can get it done with a traditional linkedlist with the addition of a method `int getNumberRepresent... | [
{
"body": "<p>This is failing on the 'do not use any additional space' test. You are creating new objects (non-node) which have the value and the carry options.</p>\n\n<p>In effect, the only new memory you can allocate off the stack, are a single node for each digit in the sum, which will be the same, or one la... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T02:06:48.733",
"Id": "57350",
"Score": "3",
"Tags": [
"java",
"algorithm",
"linked-list"
],
"Title": "Add two numbers represented by a linked list"
} | 57350 |
<p>I have written an adapter class that allows iteration over the rows of a <code>Mat</code> object from OpenCV. For those interested, here is the <a href="http://docs.opencv.org/modules/core/doc/basic_structures.html#mat">Mat documentation</a>, but the salient points are as follows:</p>
<ul>
<li><code>Mat</code> is a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T02:45:07.387",
"Id": "102485",
"Score": "1",
"body": "I'm not into C++, but I like how you've named the operator parameters `that` and go `this` vs `that`."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-10... | [
{
"body": "<p>Disclaimer: I am not a CV expert.</p>\n\n<p>Overall, LGTM.</p>\n\n<ul>\n<li><p>Relational operators (<code>==, !=, <, ></code> etc) should not be members but friends. If such operators do not treat their operands symmetrically, expect problems with implicit conversion.</p></li>\n<li><p>It is... | {
"AcceptedAnswerId": "58343",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T02:39:37.433",
"Id": "57351",
"Score": "12",
"Tags": [
"c++",
"iterator",
"opencv"
],
"Title": "Custom iterator implementation returning OpenCV Mat"
} | 57351 |
<p>The problem is the following:</p>
<p>We have a number of months to buy a number of supplies. The sooner we finish buying them, the better, but we don't know how much we can buy per month and would like to calculate all possible scenarios.</p>
<p>Suppose months = 5 and supplies = 9, and (72000) means 7 in the first... | [] | [
{
"body": "<p>What you're looking for is <em>all (ordered) <a href=\"http://en.wikipedia.org/wiki/Partition_(number_theory)\" rel=\"nofollow\">integer partitions</a> (of <code>supplies</code>) up to a maximum length (<code>months</code>)</em>.</p>\n\n<p>Here is a solution in C#, as I'm not that comfortable with... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T03:09:32.260",
"Id": "57352",
"Score": "5",
"Tags": [
"javascript",
"algorithm",
"combinatorics"
],
"Title": "Possible combinations following a rule"
} | 57352 |
<p>Given a binary tree, return the next right node. This question is attributed to <a href="http://www.geeksforgeeks.org/find-next-right-node-of-a-given-key/" rel="nofollow">GeeksForGeeks</a>. </p>
<p>For example, consider the following Binary Tree. Output for 2 is 6, output for 4 is 5. Output for 10, 6 and 5 is NULL.... | [] | [
{
"body": "<p>Just reviewing the <code>findRight()</code> method since many of the Node and other constructs have been reviewed in other questions of yours, and there's not much changed since then...</p>\n\n<blockquote>\n<pre><code>public static Integer findRight (BinaryTree tree, int val) {\n final TreeNode... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T03:24:11.907",
"Id": "57354",
"Score": "0",
"Tags": [
"java",
"algorithm",
"tree"
],
"Title": "Return the next right node"
} | 57354 |
<p>I have recently answered one question on <a href="https://stackoverflow.com/questions/24806865/how-to-make-two-or-more-combinations-of-specific-letter">Stack Overflow</a>.</p>
<p>Problem statement:</p>
<blockquote>
<p>Input sequence:</p>
<pre><code>PEACCEL
</code></pre>
<p>User mutation input file:</p>
<p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T09:34:26.043",
"Id": "102513",
"Score": "0",
"body": "Is the change of case intended? E.g: `C4W_E6G` creates\n`PEAwCgL` instead of `PEAWCGL`."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T09:38:07.3... | [
{
"body": "<p>There are several things that I would change in your code:</p>\n\n<h2>Use functions</h2>\n\n<p>This is a good example of spaghetti code where everything is meshed together.\nYou should provide functions to load the mutation list, one to execute one mutation and one that executes a list of mutation... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T06:36:42.280",
"Id": "57361",
"Score": "2",
"Tags": [
"python",
"optimization"
],
"Title": "Mutations and Combinations"
} | 57361 |
<p>I am new to Java's Swing and built a test client that connects to a server. I was wondering if my use of a <code>Controller</code> class as a link between the classes <code>ClientWindow</code> and <code>WebsocketService</code> made sense and would be thankful for comments. (I can take it, so the more my code is crit... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T10:49:33.253",
"Id": "102529",
"Score": "0",
"body": "I haven't looked at this in too much detail, but that random hard coded \"19\" looks pretty smelly. I can see later it's a userId, but whose?"
},
{
"ContentLicense": "CC ... | [
{
"body": "<ol>\n<li><p>I'm not too familiar with GUIs nor MVC, but I guess your model contains at least a string (which is displayed in the <code>responseArea</code>). You might put that into a separate model class. </p>\n\n<p>Another thing is a websocket service which I try to hide behind the model and separa... | {
"AcceptedAnswerId": "57714",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T07:16:03.843",
"Id": "57363",
"Score": "10",
"Tags": [
"java",
"beginner",
"mvc",
"swing"
],
"Title": "Swing UI for a test Websocket client"
} | 57363 |
<p>I am attempting <a href="http://codeforces.com/contest/448/problem/C" rel="nofollow">this problem</a> at Codeforces. I'm stuck as it gives a time limit exceeded error for large inputs though the logic I followed is similar to that of the editorial.</p>
<p>I'd be grateful for any pointers that can be useful in impro... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T15:22:04.117",
"Id": "102589",
"Score": "2",
"body": "I would highly suggest you use more descriptive variable names than single letters as it vastly improves readability."
}
] | [
{
"body": "<p>Your logic seems badly organised. Let's try to improve this first :</p>\n\n<ul>\n<li><p>Making things better organised</p>\n\n<p>At the moment, when you get the input, you use them to define <code>a</code> and <code>n</code> such that, for example, <code>a = [[2, 2, 1, 2, 1]]</code> and <code>n = ... | {
"AcceptedAnswerId": "57560",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T09:39:33.470",
"Id": "57365",
"Score": "2",
"Tags": [
"python",
"optimization",
"programming-challenge",
"python-2.x"
],
"Title": "Painting Fences - optimize for faster per... | 57365 |
<p>In the code below, I have a dictionary of attributes and values. I am checking to see if the value if an attribute is True, and if so adding the attribute to a list for later processing (it becomes part of a SQL group by).</p>
<p>This code works fine, but I was wondering how it could be more "Pythonic". Note that t... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2018-08-17T07:59:35.287",
"Id": "388884",
"Score": "2",
"body": "This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about [what your code does](//coderev... | [
{
"body": "<p>I would do</p>\n\n<pre><code>supply_kpi = self.browse(cr, uid, ids, context=None)[0]\ngroup_by = [col_map[key] for key in col_map if getattr(supply_kpi, key)]\n</code></pre>\n\n<ul>\n<li>Iterating with list comprehension is much more efficient.</li>\n<li>You don't build iteritems list of tuples.</... | {
"AcceptedAnswerId": "57369",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T09:47:33.510",
"Id": "57368",
"Score": "6",
"Tags": [
"python",
"hash-map"
],
"Title": "Dictionary of attributes and values"
} | 57368 |
<p>One of the tenets of <a href="http://docs.castleproject.org/Default.aspx?Page=MainPage&NS=Windsor&AspxAutoDetectCookieSupport=1" rel="nofollow">Windsor</a> IoC (probably applies to all <a href="https://en.wikipedia.org/wiki/Inversion_of_control" rel="nofollow">IoC</a> containers too) is to "release what you ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T15:13:33.260",
"Id": "102586",
"Score": "0",
"body": "Is it easy to give a short example of releasing objects correctly with and without using this extension?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014... | [
{
"body": "<p>Style-wise everything looks good. The only note I'd make is that in C#, generally the convention is to start brackets on a new line rather than in-line, although obviously this is ultimately up to personal or team preference. XML comments on public members may be a good idea too, as it's not trivi... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T10:57:49.653",
"Id": "57378",
"Score": "5",
"Tags": [
"c#",
"extension-methods"
],
"Title": "Helper extension to release Windsor component; not sure if it's over-kill"
} | 57378 |
<p>I have created a class that gets data from an ODBC connection. The code works but it is really slow - I'm talking up to 1.20ish minutes to run. I know my code is inefficient but I'm really not sure why it's so slow. Tips or advice on speeding it up would be much appreciated.</p>
<pre><code><?php
class machine {... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T11:22:52.110",
"Id": "102533",
"Score": "1",
"body": "Please note that by convention, classes should start with an uppercase letter and variables and methods with a lowercase one. This helps keeping apart what is what."
}
] | [
{
"body": "<h1>Recycling is the solution</h1>\n<p>For every Machine, you are performing 3 queries and opening/closing 3 connections.</p>\n<p>So for 10 machines, you are performing 30 queries (no problemo) but opening a connection 30 times (w t f?) and closing it again.</p>\n<p>There is your problem. Instead of ... | {
"AcceptedAnswerId": "57384",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T11:16:42.410",
"Id": "57381",
"Score": "5",
"Tags": [
"php",
"optimization",
"sql"
],
"Title": "Speeding up class that uses an ODBC connection"
} | 57381 |
<p>Inspired a bit by <a href="https://codereview.stackexchange.com/questions/26648/ascii-table-in-brainfuck">a previous Brainfuck question</a> and the recent <a href="/questions/tagged/fizzbuzz" class="post-tag" title="show questions tagged 'fizzbuzz'" rel="tag">fizzbuzz</a> invasion, I decided to make FizzBuzz... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T06:03:34.120",
"Id": "102708",
"Score": "35",
"body": "Oh god, something serious was made in BF?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T10:34:22.590",
"Id": "102716",
"Score": "10",
... | [
{
"body": "<ul>\n<li><p>You should \"initialize 100\" after the \"Tape meanings\". I consider it to be part of the actual code and the explanation to be a kind of \"header\" explaining the code. </p></li>\n<li><p>I agree that commenting \"what\" becomes more important in bf, but you should still explain \"why\"... | {
"AcceptedAnswerId": "104022",
"CommentCount": "11",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T11:22:57.423",
"Id": "57382",
"Score": "101",
"Tags": [
"fizzbuzz",
"brainfuck"
],
"Title": "FizzBuzz in Brainfuck"
} | 57382 |
<p>I have the following piece of code and I would like to see what different approaches would be to solve that in a more elegant way. </p>
<p>The thing is that I don't know whether is better to have the null checks or the try/catch block there or maybe the code below should not happen in the first place. Maybe one ca... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T11:40:00.200",
"Id": "102534",
"Score": "3",
"body": "An avoided exception is always better then a handled exception."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T11:46:07.837",
"Id": "102537",... | [
{
"body": "<p>Let's count the number of times you're writing <code>get</code>.</p>\n\n<pre><code>if (people.getImages() != null && people.getImages().size() > 0 && people.getImages().get(0).getUrl() != null) {\n Url thumbUrl = people.getImages().get(0).getUrl().getThumb();\n // do somet... | {
"AcceptedAnswerId": "57385",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T11:36:34.253",
"Id": "57383",
"Score": "1",
"Tags": [
"java",
"android",
"null"
],
"Title": "Null checking in nested getter calls"
} | 57383 |
<p>What do you think is wrong with this code, and how can it be improved? What corner case have I overlooked, if any?</p>
<p><strong>Note:</strong> I do not want to use any STL features here, but I'm okay with anything else from C++11.</p>
<pre><code>class min_heap{
int pvt,P;
int arr[10000];
public:
mi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T12:56:35.270",
"Id": "102551",
"Score": "0",
"body": "This contains no C++11 code, yet it is tagged as that. Does that mean you're willing to accept such recommendations?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creatio... | [
{
"body": "<p>You've mentioned that you don't want to utilize the STL, so I'll honor that. Just be aware that neglecting to use it may lessen the quality of your code, especially if you start to experience bugs.</p>\n\n<p>I'll mainly address best-practices as I'm not so familiar with the algorithm myself.</p>\... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T12:35:20.087",
"Id": "57387",
"Score": "13",
"Tags": [
"c++",
"c++11",
"heap"
],
"Title": "Implementation of binary min-heap data structure"
} | 57387 |
<p>I recently suggested <a href="https://stackoverflow.com/questions/22751000/split-large-text-filearound-50gb-into-multiple-files-using-python">this method</a> for emulating the Unix utility split in Python.</p>
<p>Is there a more elegant way of doing it?</p>
<p>Assume that the file chunks are too large to be held i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T15:16:32.620",
"Id": "102587",
"Score": "0",
"body": "the use of contextlib makes things a bit complexe to me. You could keep the same code and simply close fd_out before opening a new file. This would make the code a lot clearer."
... | [
{
"body": "<p>Unfortunately, as far as I know, there is no chunks methods in the standard library.\nBut this makes things rather neat.</p>\n\n<pre><code>from itertools import chain, islice\n\ndef chunks(iterable, n):\n \"chunks(ABCDE,2) => AB CD E\"\n iterable = iter(iterable)\n while True:\n yie... | {
"AcceptedAnswerId": "57400",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-07-18T14:01:04.030",
"Id": "57395",
"Score": "11",
"Tags": [
"python",
"performance",
"python-3.x",
"file",
"unix"
],
"Title": "Split large file into smaller files"
} | 57395 |
<p>I'm having a dip into F# and am attempting not to write it like it's C#.</p>
<p>One area that bothers me is using members of <code>System.String</code>. These often need to be chained together, but the only way to do so that I've seen so far is pretty much the same as C#.</p>
<p>For example, I've written a functio... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T14:09:14.663",
"Id": "102575",
"Score": "0",
"body": "I posted my latest iteration of this method. There have been a few, but all had the horrible String functions line."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationD... | [
{
"body": "<p>F# does have <a href=\"http://msdn.microsoft.com/en-us/library/ee353758.aspx\">a <code>String</code> module</a>, but it's almost empty. If you want to make string manipulations look more idiomatic, you'll have write functions that wrap <code>System.String</code> methods yourself (quick search didn... | {
"AcceptedAnswerId": "57575",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T14:08:32.650",
"Id": "57397",
"Score": "5",
"Tags": [
"strings",
"regex",
"f#",
"url"
],
"Title": "Generating the pretty bit at the end of a URL"
} | 57397 |
<p>I have been Googling for a few days and am trying to find the best practices when it comes to using the Repository pattern. But what I found that there are no standards and everyone claims that their approach is the best approach. However, I have come up with this design based on what I have read online.</p>
<p>I... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T20:24:55.473",
"Id": "102657",
"Score": "1",
"body": "Please note, SE sites are not *forums*. Please avoid in-post discussions; feel free to use [chat] instead! :)"
}
] | [
{
"body": "<h2>The Interface</h2>\n\n<ul>\n<li><p>The idea of a generic repository interface is that it should be applicable to all entity types. So <code>GetUsers</code> shouldn't be there, because it's only relevant for a particular type of entity. If you want members specific to an entity type, you should ha... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T16:32:37.453",
"Id": "57401",
"Score": "5",
"Tags": [
"c#",
"design-patterns",
"repository"
],
"Title": "Repository pattern best practices using EF 6"
} | 57401 |
<p>Is there a better way to time the functions and print the result and function name dynamically?</p>
<pre><code>package project_euler
object Timers extends App{
def time[R](f: => R): Unit = {
val t0 = System.nanoTime()
val r = f
val t1 = System.nanoTime()
val t = (t1-t0)/1000
... | [] | [
{
"body": "<p>So, I pasted your code into my IDE and ran it in the debugger, and there isn't really any way to do exactly what you want to do. The function object doesn't appear to have any knowledge of anything other than how to call it.</p>\n\n<p>Your best bet seems to be to modify the timing function to some... | {
"AcceptedAnswerId": "57416",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T18:08:14.960",
"Id": "57405",
"Score": "4",
"Tags": [
"performance",
"functional-programming",
"scala",
"programming-challenge",
"higher-order-functions"
],
"Title": "T... | 57405 |
<p>Right now, I have base abstract <code>GenericDAO</code> class to execute CRUD operations with different kind of objects. I have Customer and Employee POJO classes which are used in specific <code>DAO</code> classes that extends <code>GenericDAO</code> class. </p>
<p><strong>Questions:</strong></p>
<ul>
<li>How cor... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T21:55:03.920",
"Id": "102672",
"Score": "0",
"body": "I don't quite understand what it is that you need, and how that compares to the code you have at the moment. Does your code produce the expected result? What exactly do you think... | [
{
"body": "<p>One generic (pun unintended) suggestion: Use braces <code>{ }</code> for your <code>if</code> statements to ensure you do not accidentally introduce bugs, because it makes the presentation clearer.</p>\n\n<p><strong>Minor points:</strong></p>\n\n<ol>\n<li>You can compare <code>enums</code> by <cod... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T18:25:00.090",
"Id": "57407",
"Score": "5",
"Tags": [
"java",
"database"
],
"Title": "Base generic DAO to work with different POJO classes"
} | 57407 |
<p>I'm looking for some input here. I have a class that contains a value which is updated every few seconds by a method within that class. Right now, access to this value across multiple threads is done via synchronization, which I would like to eliminate. Would this make sense?</p>
<pre><code>class DataSegment {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T22:27:52.770",
"Id": "102674",
"Score": "0",
"body": "Where is the `theInstance` declared?"
}
] | [
{
"body": "<p>Your code is not synchronized at all at the moment. There are two major mistakes:</p>\n\n<ol>\n<li><p>You are only synchronizing in the thread(s) which are <em>writing</em> the value, but are never synchronizing on the threads <em>reading</em> the value. You must always synchronized on all threa... | {
"AcceptedAnswerId": "57418",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T18:29:42.333",
"Id": "57408",
"Score": "5",
"Tags": [
"java",
"multithreading",
"synchronization"
],
"Title": "Accessing a String value from multiple threads without synchroniz... | 57408 |
<p>The program asks the user to input 10 integers, and then prints the largest odd number that was entered. If no odd number was entered, it prints a message to that effect.</p>
<pre><code>q = int(raw_input("Please enter an integer:"))
r = int(raw_input("Please enter another integer:"))
s = int(raw_input("Please enter... | [] | [
{
"body": "<p><strong>Use loops!</strong></p>\n\n<pre><code>odd_nums = []\nfor i in xrange(10):\n value = int(raw_input('Enter an integer: '))\n if value % 2 != 0:\n odd_nums.append(value)\n\nif len(odd_nums) != 0:\n print max(odd_nums)\nelse:\n print \"No odd values\"\n</code></pre>\n\n<hr>\... | {
"AcceptedAnswerId": "57412",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T18:53:08.997",
"Id": "57410",
"Score": "6",
"Tags": [
"python",
"beginner",
"functional-programming"
],
"Title": "Printing inputted, largest, odd integer"
} | 57410 |
<p>I was skimming through <a href="http://arxiv.org/pdf/1406.5569.pdf" rel="nofollow">this paper</a> out of boredom. On pages 5 and 6, the paper shows a simple encryption/decryption scheme that Citadel uses to obfuscate data. The algorithm basically XORs the next character with the previous character. The code is rough... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T00:10:34.057",
"Id": "102690",
"Score": "1",
"body": "Looks like `std::transform` with a simple callable (a struct with a single data member like your `value` and an `operator()`) would do the job."
}
] | [
{
"body": "<p>The way you handle the first element as a special case is cumbersome: you're basically unrolling the first iteration of the loop. You could just initialize <code>value = 0</code> so that the first XOR just copies the input to the output.</p>\n\n<pre><code>template <class InputIterator, class O... | {
"AcceptedAnswerId": "57503",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T22:08:18.527",
"Id": "57420",
"Score": "10",
"Tags": [
"c++",
"cryptography"
],
"Title": "Citadel's VisualEncrypt and VisualDecrypt"
} | 57420 |
<p>This is a tiny learning program that lead to an interesting question: how can I best/most elegantly handle user entered numbers? This method works, fails cleanly, and reads well. It doesn't apply to types other than build in ones (as far as I know), but for floats and integers it's a nice feature. But it doesn't sca... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T23:21:32.643",
"Id": "102679",
"Score": "1",
"body": "What do you mean by \"doesn't scale well\"?"
}
] | [
{
"body": "<p>I question your use of exceptions to catch the invalid input. Exceptions are supposed to be used for exceptional situations. Validating user input is part of the normal functionality of the program, not an exceptional situation. It's on the lazy side to use exceptions here; you're basically treati... | {
"AcceptedAnswerId": "57450",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T22:58:42.700",
"Id": "57423",
"Score": "8",
"Tags": [
"c++",
"c++11",
"exception-handling",
"validation",
"io"
],
"Title": "Validation/error handling of user input valu... | 57423 |
<p>I wrote a small component (still in the works but working) which takes a large SQL script file, splits it into different "blocks" based on GO statements, and executes them one by one.</p>
<p>The only major flaw I know of is not being able to detect when a <code>GO</code> statement is inside of a comment block, for ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T04:00:36.823",
"Id": "102832",
"Score": "0",
"body": "Component TZSQLProcessor from the [ZeosLib](http://zeoslib.sourceforge.net/index.php) open source, mature (~9 years of development), reasonably light weight, multi platform (mult... | [
{
"body": "<p>I am unfortunately not able to test your code, but I am able to read your code. Very well. Your code is overall very well written and you seem to adhere to most of the Delphi coding conventions that I know of. (Yes, non-Delphi users, using <code>F</code> for field name, <code>T</code> for a type, ... | {
"AcceptedAnswerId": "60806",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T23:25:34.220",
"Id": "57424",
"Score": "24",
"Tags": [
"sql",
"sql-server",
"delphi",
"adodb"
],
"Title": "Executing large SQL script file with GO statements using ADO"
} | 57424 |
<h2>Practicing Prototypal Code</h2>
<p>I'm focusing on practicing a very prototypal structure with my code (non library oriented) to begin learning to reuse large portions of my application infrastructures where applicable in future projects. With this in mind, I don't have experience with prototypal programming befor... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T14:15:56.090",
"Id": "102728",
"Score": "1",
"body": "I think that code review must be light on JavaScript reviewers. I posted some code a while back that got 8 up-votes and no review. 12 hours after posting this, not so much as a c... | [
{
"body": "<h3>The Basics</h3>\n\n<p>As you said, I think as each handler grows in size and the base handler adds more common features, the prototypes will pay off in spades.</p>\n\n<p>Honestly, the biggest readability issue for me is the require-and-instantiate style you're using. Is this common? I haven't see... | {
"AcceptedAnswerId": "57547",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T01:18:39.560",
"Id": "57429",
"Score": "8",
"Tags": [
"javascript",
"object-oriented",
"node.js",
"socket.io"
],
"Title": "Proper prototypal programming with Node.JS"
} | 57429 |
<p><a href="http://ninject.org/" rel="nofollow">Ninject</a> is a lightweight dependency injection framework for .NET applications. It helps you split your application into a collection of loosely-coupled, highly-cohesive pieces, and then glue them back together in a flexible manner. By using Ninject to support your sof... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T02:54:04.037",
"Id": "57434",
"Score": "0",
"Tags": null,
"Title": null
} | 57434 |
Ninject is a dependency injection framework for .NET applications. Use this tag for questions containing code that involves Ninject. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T02:54:04.037",
"Id": "57435",
"Score": "0",
"Tags": null,
"Title": null
} | 57435 |
<p>I am trying to parse HTML using "jsoup". This is my first time working with "jsoup" and I read some tutorials on it as well.</p>
<p>If you see my table, it has three <code><tr></code> as of now (I have shortened it down to have three table rows just for understanding purpose, but in general it will be more). ... | [] | [
{
"body": "<p>If you don't need implementation specific features, declare variables using interface types. That is, instead of:</p>\n\n<blockquote>\n<pre><code>ArrayList<String> downServers = new ArrayList<>();\n</code></pre>\n</blockquote>\n\n<p>Use the <code>List</code> interface:</p>\n\n<pre><cod... | {
"AcceptedAnswerId": "57442",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T03:50:25.800",
"Id": "57436",
"Score": "7",
"Tags": [
"java",
"performance",
"html",
"parsing"
],
"Title": "Parsing an HTML table using jsoup"
} | 57436 |
<p>I've been trying to figure out the best way to create a inventory system in Python. I like the way this one works but what I was wondering was if there was a better way to write it.</p>
<pre><code>inv = ['Sword','Armor']
item_values = {'Sword':['Sword',5,1,15,2],
'Armor':['Armor',0,10,25,5]}
print('N... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T09:28:42.393",
"Id": "102711",
"Score": "2",
"body": "What exactly do you like about the way that one works?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T10:16:30.013",
"Id": "102714",
"Sco... | [
{
"body": "<p>The items and the inventory can be modelled intuitively with classes:</p>\n\n<ul>\n<li>You can define an <code>Item</code> class that has attributes like <code>name</code>, <code>weight</code>, <code>attack</code></li>\n<li>You can define an <code>Inventory</code> class that has a collection of it... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T04:58:56.087",
"Id": "57438",
"Score": "7",
"Tags": [
"python",
"beginner"
],
"Title": "Game inventory system"
} | 57438 |
<p>I have written a very simple web service with MVC and WebApi. Now I'm working on the client code which will be a WPF application (and soon Windows 8 Store/Phone app). What I have done works, but I'm not sure I'm doing it the "right" way. The purpose of the service is to check if there are any new software updates to... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T23:20:12.113",
"Id": "102813",
"Score": "0",
"body": "Have you considered using something like WCF, where a method invocation is translated into a network request automatically?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"C... | [
{
"body": "<hr>\n\n<p>Simplified, examplified, trimmed code is frowned upon on this site; I'm surprised this question hasn't received any close votes yet.</p>\n\n<p>I don't see anything blatantly done wrong here - I like . On the other hand if the client code you've shown is cohesively written in a specialized ... | {
"AcceptedAnswerId": "57620",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T06:57:29.943",
"Id": "57443",
"Score": "5",
"Tags": [
"c#",
"wpf",
"asp.net-web-api",
"windows-phone",
"json.net"
],
"Title": "Checking for new software updates to the ... | 57443 |
<p>I have this one controller that serves up all the webpages and any dynamic content. Is this the most efficient way of doing this? Can it be improved?</p>
<pre><code>package uk.co.morleys;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.RequestDispatcher;
import ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T17:56:08.047",
"Id": "102764",
"Score": "1",
"body": "I'm not familiar with web server development in Java, but on the first look, I'd suggest using a framework that handles routing for you."
}
] | [
{
"body": "<p>First, a few points on case statements. The last three cases all do the same thing. To reduce duplication, you can <a href=\"http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html\">allow cases to fall through</a>:</p>\n\n<pre><code>case \"\":\ncase \" \":\ndefault:\n rd = getServ... | {
"AcceptedAnswerId": "57506",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T09:36:07.777",
"Id": "57445",
"Score": "4",
"Tags": [
"java",
"mvc",
"http"
],
"Title": "Making this site navigation less verbose"
} | 57445 |
<p>I have written a C++ program to convert an infix expression to postfix expression using recursion. I would like to know if it can be improved if possible. Can we improve it by not using a stack? I am using a <code>vector<char></code> as a stack here.</p>
<pre><code>#include <iostream>
#include <vecto... | [] | [
{
"body": "<h2>Don't use global variables</h2>\n\n<p>All your function parameters are global variables that introduce hard to track side effects. </p>\n\n<p>If you want to use the function in multiple threads in parallel it will fail.</p>\n\n<p>Just pass parameters and the code becomes much more readable as wel... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T09:43:58.083",
"Id": "57447",
"Score": "7",
"Tags": [
"c++",
"recursion",
"converting",
"math-expression-eval"
],
"Title": "Infix to postfix conversion"
} | 57447 |
<p>The following method will add two strings of any length as binary numbers assuming the characters <code>1</code> and <code>0</code>. I made this for fun in my spare time. Improvements are not critical but I would like to hear them. I would also like to know if there is a more efficient algorithm to simulate a <a hr... | [] | [
{
"body": "<blockquote>\n <p>strings of any length as binary numbers</p>\n</blockquote>\n\n<p>Why are they <code>string</code>s? Something like <code>bool[]</code> would fit much better and it would also make your code simpler.</p>\n\n<hr>\n\n<pre><code>string a, string b\n</code></pre>\n\n<p>Those are not ver... | {
"AcceptedAnswerId": "57498",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T12:40:29.677",
"Id": "57452",
"Score": "3",
"Tags": [
"c#",
"strings",
".net"
],
"Title": "Binary addition with strings"
} | 57452 |
<p>I'd like this code to be improved.</p>
<pre><code>package com.array.demo;
import java.util.Arrays;
public class ArraysDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
// array initialization
int[] arr = { 5, 10, 12, 22, 4 };
int size = arr.length;
int i,po... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T16:01:41.777",
"Id": "102742",
"Score": "0",
"body": "Your previous program used separate methods, but not this one. Is there a reason for that?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T16:16:... | [
{
"body": "<h3>The easy stuff first...</h3>\n\n<p>You should format your code nicer. It makes it easier to read for everyone who uses the same standard formatting style. Use your IDE's reformatting function (Control + Shift + f in Eclipse, Alt + Control + l in IntelliJ) to reformat before posting on forums.</p>... | {
"AcceptedAnswerId": "57462",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T15:51:45.643",
"Id": "57457",
"Score": "8",
"Tags": [
"java",
"beginner",
"array"
],
"Title": "Program to insert, search for and delete an element from an array"
} | 57457 |
<p>I want to load JS files asynchronously to speed up page loading, but also need to execute JS code only once the scripts finish loading (so I need a way to implement callbacks).</p>
<p>I based this off of some example code on the Google Pagespeed website:</p>
<pre><code>// Add script elements as a children of the b... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T17:09:19.817",
"Id": "102748",
"Score": "2",
"body": "https://www.igvita.com/2014/05/20/script-injected-async-scripts-considered-harmful/ perhaps you consider using _async_"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creati... | [
{
"body": "<p>First of all, I would split you problem into 3 parts:</p>\n\n<ol>\n<li>Loading a js-file asynchronously, and calling a callback-function</li>\n<li>Loading several js-files an once asynchronously</li>\n<li>Using an onload-Handler, which triggers everything</li>\n</ol>\n\n<p>These are 3 independent ... | {
"AcceptedAnswerId": "57509",
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T16:34:15.830",
"Id": "57458",
"Score": "7",
"Tags": [
"javascript",
"asynchronous"
],
"Title": "Is this a good approach to loading JavaScript files asynchronously?"
} | 57458 |
<p>I'm looking for input on the code itself and formatting/style. This script parses the output of <code>df -h</code> on a Linux server and emails the user if the usage percentage is above the threshold (90% in this case). </p>
<pre><code>#!/usr/bin/perl
use warnings;
use strict;
use Mail::Sendmail;
my $svr = `host... | [] | [
{
"body": "<p>There is a bug here:</p>\n\n<blockquote>\n<pre><code>foreach (@output) {\n if (($_ =~ m/(\\d+)% (.*)/) && ( $1 > $threshold )) {\n chomp($svr); $msg = \"$svr: $2 volume is $1 percent full\\n\" }\n }\n</code></pre>\n</blockquote>\n\n<p>If there are more than one partitions fu... | {
"AcceptedAnswerId": "57465",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T16:39:07.673",
"Id": "57459",
"Score": "3",
"Tags": [
"perl",
"linux",
"email"
],
"Title": "Perl script to check disk usage"
} | 57459 |
<p>I've just completed coding my template engine. I'm willing to have a review on how to increase the quality, efficiency, elegance and performance of the code, perhaps by shortening the code, etc. I'm also open for suggestions on other ways of doing this. It would be really appreciated if you point out every tiny bit ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T17:47:07.137",
"Id": "102756",
"Score": "0",
"body": "OK, let's start with, the `Model` class is completely broken. PHP has no implicit `$this`, so none of the code there gets or sets anything on the object."
},
{
"ContentL... | [
{
"body": "<h3>MVC</h3>\n\n<p>The <code>handlePageLoad</code> method in <code>View</code> is doing a bit too much: </p>\n\n<ul>\n<li>It does checking if a page exists or not</li>\n<li>It knows too much about how the site works, the paths, the 404 page</li>\n</ul>\n\n<p>I think it would be better if the <code>Vi... | {
"AcceptedAnswerId": "57471",
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T16:49:52.277",
"Id": "57461",
"Score": "5",
"Tags": [
"php",
"mvc"
],
"Title": "Template engine"
} | 57461 |
<p>I have written this program to count the number of words in a string. I have checked my program for the worst-case scenario. If any of you can find any cases for which this program doesn't work, please let me know so that I can work and improve it.</p>
<p>And just to be clear, we don't want symbols like, "," , "!" ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T17:22:10.937",
"Id": "102749",
"Score": "0",
"body": "Was there a problem copying this from your IDE? There are many inconsistencies in indentation here."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-... | [
{
"body": "<p>I personally would use the built-in way of reading words.</p>\n\n<pre><code>std::stringstream wordStream(\"A list of words\");\n\nstd::string word;\nint count = 0;\nwhile(wordStream >> word)\n{\n ++count; // We read one space separated words\n} // from t... | {
"AcceptedAnswerId": "57484",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T17:09:39.753",
"Id": "57463",
"Score": "7",
"Tags": [
"c++",
"beginner",
"strings"
],
"Title": "Counting the number of words in a string"
} | 57463 |
<p>I have a MySQL query which runs very slowly. I've rewritten it many times but no improvements yet.</p>
<p>My current query for advanced search takes about 60 secs to complete. Any suggestions for improving this?</p>
<ul>
<li>Database: MySQL</li>
<li>Webserver: Apache - PHP (PDO)</li>
</ul>
<p>Current code structu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T17:39:17.973",
"Id": "102753",
"Score": "1",
"body": "For 5 million records...using `LIKE`...? 60 seconds doesn't sound all that outrageous."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T17:41:54.2... | [
{
"body": "<p>Rather than address performance, I'd first like to raise some skepticism about the correctness of the query.</p>\n\n<p>I don't think that <code>PhysicalInfo A LEFT JOIN BibliographicInfo</code> is appropriate. What that <code>LEFT JOIN</code> means is that it's OK to include a <code>PhysicalInfo<... | {
"AcceptedAnswerId": null,
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T17:21:21.080",
"Id": "57464",
"Score": "5",
"Tags": [
"performance",
"sql",
"mysql",
"join"
],
"Title": "Library database search with multiple JOINs is too slow"
} | 57464 |
<p>I am attempting to design an application that tracks currency and recent transactions in a safe. I am using entity-framework code-first in a wpf desktop application.</p>
<p>The first goal is to be able to track whats currently in the safe. For example - 87 Ones, 55 Twos, 76 fives, etc..</p>
<p>The second goal is ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T19:23:48.020",
"Id": "102783",
"Score": "0",
"body": "I don't think that this code is sufficiently complete to be reviewable."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T20:06:13.910",
"Id": "... | [
{
"body": "<blockquote>\n<p><em>One concern I have is tracking non-US currency. Not a requirement currently, but maybe in the future.</em></p>\n</blockquote>\n<p>You're right to be concerned about the flexibility of your approach: what would <code>Twos</code> return in a currency that doesn't have toonies?</p>\... | {
"AcceptedAnswerId": "57473",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T18:32:39.353",
"Id": "57469",
"Score": "3",
"Tags": [
"c#",
"entity-framework"
],
"Title": "Data model for tracking currency in a safe"
} | 57469 |
<p>I have a process with a number of stages that need to be completed in sequence. Each stage is largely parallelisable, involving looping over a large data structure and processing each item independently, and collating the results into the data structure used by the next stage.</p>
<p>My approach is like the followi... | [] | [
{
"body": "<p>I don't know anything about Go. I read your post out of curiosity and I think I can give you some pointers nonetheless.</p>\n\n<ol>\n<li><p>It seems you removed too many things to create your simplified post. Your code does not make sense as it is. For example, <code>wg.Add(1)</code> is never c... | {
"AcceptedAnswerId": "57535",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T19:01:43.417",
"Id": "57472",
"Score": "8",
"Tags": [
"concurrency",
"go"
],
"Title": "Is this a good way of managing parallel go routines when I care about ordering of results?"
} | 57472 |
<p>I have 3 simple predicates and 3 simple actions to be taken based on those predicates. In my actual application they are not based on integer arithmetic, and in fact are <strong>rather expensive to compute</strong> (in comparison to the actions taken), but their dependency chain is the same.</p>
<pre><code>#include... | [] | [
{
"body": "<p>It seems to me that the primary role of the programmer is to write clear and correct code and that it's largely the job of the compiler to turn that into efficient machine code. With that said, it seems to me that the first <code>fun()</code> version is both clear and effective in that it avoids ... | {
"AcceptedAnswerId": "57505",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T20:45:12.917",
"Id": "57477",
"Score": "5",
"Tags": [
"c++",
"optimization",
"c++11"
],
"Title": "Simplifying logic of overlapping predicates"
} | 57477 |
<p>Original question:</p>
<p><a href="https://codereview.stackexchange.com/questions/57461/is-this-the-proper-way-of-using-the-mvc-concept">Template engine</a></p>
<p>I updated my files as instructed, and now I require a review. Please point out the most minute things out to me for me to have better code. Once again... | [] | [
{
"body": "<p>I'll skip MVC for now, as I see a whole review for formatting and the such. Perhaps someone else could break down the pattern for you. Right now, let's focus on each individual class. </p>\n\n<p><strong>Model</strong></p>\n\n<ul>\n<li><p><code>public</code>!? What's your logic behind that!? Are we... | {
"AcceptedAnswerId": "57745",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T22:21:13.050",
"Id": "57481",
"Score": "6",
"Tags": [
"php",
"mvc"
],
"Title": "Proper way of using the MVC concept - update"
} | 57481 |
<p>This is my first public web-application. I'm a beginner to JavaScript and this is my first time using jQuery. It's not complete, but I'd love some feedback on the programming and the functionality. As I said, I'm just learning and I'm not sensitive, so feel free to be thorough with your criticism/feedback.</p>
<p>Y... | [] | [
{
"body": "<p>First of all: be consistent.</p>\n\n<pre><code>$(\"#blob\").popover();\n$('#company_name').popover();\n</code></pre>\n\n<p>Mixed usage of single or double quotes is allowed in JS, but is sloppy.\nUse either one or the other, but be consistent.</p>\n\n<pre><code>$(\"#copy_button\").on('click', func... | {
"AcceptedAnswerId": "57486",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-19T23:38:53.167",
"Id": "57483",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"html",
"twitter-bootstrap"
],
"Title": "Cover letter generator: guides writing a template and... | 57483 |
<p>Originally, this isn't how I would have done this at all. I was told by someone I know who is a programmer that I needed to include several functions: one for removing and adding users, one for searching for users information etc.</p>
<p>I would have made it so you can pass a username into the constructor and then ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T00:52:48.400",
"Id": "102815",
"Score": "0",
"body": "I'm having trouble analyzing this wordy post. Are you just asking for a review of this code?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T00:5... | [
{
"body": "<p>No, this design is not object-oriented, nor would I recommend you follow your friend's advice. I also would not recommend your original design either. Neither one adheres very well to object-oriented design principles, namely the <a href=\"http://en.wikipedia.org/wiki/SOLID_(object-oriented_design... | {
"AcceptedAnswerId": "57501",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T00:49:24.250",
"Id": "57487",
"Score": "6",
"Tags": [
"php",
"object-oriented",
"authorization"
],
"Title": "Attempting to utilize OOP with a user-management class"
} | 57487 |
<p>If it is possible, I'd like to be able to mash all of my arrays into one array, but still have the same functionality within my function (pick quote, pick creator, set padding).</p>
<p><a href="http://pastebin.com/uDPbujK0" rel="nofollow">Pastebin</a></p>
<pre><code>var quotes = [
/*48px*/"The true sign of int... | [] | [
{
"body": "<p>It seems to me like <code>quotes</code>, <code>creators</code> and <code>margins</code> all belong to the same object; your intuition is correct, merging them into one is the right thing to do.</p>\n\n<p>I don't do much web development, so I'm not going to post example code, but I would have the q... | {
"AcceptedAnswerId": "57491",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T01:17:10.887",
"Id": "57488",
"Score": "4",
"Tags": [
"javascript",
"optimization",
"jquery"
],
"Title": "Optimizing display of various famous quotes"
} | 57488 |
<p>I have recently gotten back into development and I am wondering if the script I have just created is clearly documented and easily understandable throughout each step. Is it easy to understand?</p>
<pre><code>class Encryption {
public function Encrypt ($String){
/*
* Create an Encrypted String... | [] | [
{
"body": "<p>In my opinion, <strong>no</strong> your class is not <em>clearly</em> documented and <em>easily</em> understandable.</p>\n\n<p>Here are the main reasons I find this code... dirty:</p>\n\n<ul>\n<li>The naming is misleading.</li>\n<li>The naming is unusual.</li>\n<li>There are too many comments.</li... | {
"AcceptedAnswerId": "57500",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T01:44:11.093",
"Id": "57489",
"Score": "5",
"Tags": [
"php",
"security",
"cryptography"
],
"Title": "Clarity of encryption class"
} | 57489 |
<p>I've been learning how to code for the past three years. I have made some really good progress I think, and right now I'm trying myself on creating an MVC framework.</p>
<p>I found <a href="http://www.broculos.net/2008/03/how-to-make-simple-html-template-engine.html#.U8sZd_ldV8F" rel="nofollow noreferrer">this awes... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T07:53:29.267",
"Id": "102855",
"Score": "0",
"body": "Okay now this is weird: I just added `microtime()` to the beginning and the end of the script, and display the difference just before exiting the script: `0.568397` half a second... | [
{
"body": "<p>Okay I think I fixed it with very little decrease in flexibility. Basically I did four things:</p>\n\n<ul>\n<li>instead of putting each row in one form, put the entire table in a form. This required changing the field names, but no biggie. </li>\n<li>consolidating template files (for example inste... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T01:54:40.127",
"Id": "57490",
"Score": "2",
"Tags": [
"php",
"performance",
"mvc",
"template",
"url-routing"
],
"Title": "Redirecting to a file"
} | 57490 |
<p>I have some code to interface with a wire protocol that requires data to be inserted into a stream at regular byte intervals. Every 8KB (or at some other definable interval), a small chunk will be inserted. To make this easy, I decided to create a transform stream that would take a flowing stream and write fixed c... | [] | [
{
"body": "<p><strong>First of all, your code looks great.</strong> It brought me to study the internal workings of Node's stream API.</p>\n\n<p>The piece that you're concerned with, and rightfully so, is:</p>\n\n<pre><code>buffer = Buffer.concat([buffer, chunk]);\n</code></pre>\n\n<p>That's <em>the</em> way to... | {
"AcceptedAnswerId": "58877",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T02:05:18.303",
"Id": "57492",
"Score": "4",
"Tags": [
"javascript",
"node.js"
],
"Title": "ChunkerTransformStream, a transform stream to take arbitrary chunk sizes and make them co... | 57492 |
<p>I am using Python3 to extract some information from a dictionary that contains 10k of CIDRs, but the running time is pretty long.</p>
<p>Here is my purpose: I have a dictionary of CIDRs (10000) and a list of IPs (5000), then I want to go through each IP in the list and check if it belongs to one CIDR in the diction... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T04:48:34.563",
"Id": "102839",
"Score": "1",
"body": "you break if you find the first CIDR for an IP. Is this because your CIDR definitions have no IP adress in common? They are pairwise mutually exclusive? If this is the case you c... | [
{
"body": "<p>First of all, welcome to Code Review! This is a great first question. There are some things to learn about how to post a question in order to get the best response, so I'll cover these first and then cover the performance problems that you're seeing.</p>\n\n<h1>Readability</h1>\n\n<p>You will get ... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T02:55:16.540",
"Id": "57493",
"Score": "10",
"Tags": [
"python",
"performance",
"python-3.x",
"ip-address"
],
"Title": "Efficiently matching IP addresses with a list of CIDRs"... | 57493 |
<p>I am trying to write a class similar to <code>std::set</code>, and I was wondering if I handled the perfect forwarding right in implementing the <code>emplace</code> member function below. Basically, I forwarded calls to my class to a member <code>set</code>. But I wasn't sure whether I used <code>std::forward</code... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2019-03-26T12:28:41.310",
"Id": "418394",
"Score": "0",
"body": "`Also, is there an easy way to tell when something is not forwarded as desired, and values are copied instead?` sure, try passing a struct with deleted copy-constructor, defaulte... | [
{
"body": "<p>You are using <code>std::forward</code> correctly. However, there are several other things worth noting about your code:</p>\n\n<ul>\n<li>why do you need a private counter instead of re-using <code>m_s.size()</code> that will automatically update itself after each <code>emplace_back()</code>?</li>... | {
"AcceptedAnswerId": "57561",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T03:03:06.847",
"Id": "57494",
"Score": "11",
"Tags": [
"c++",
"c++11"
],
"Title": "Perfect-forwarding while implementing emplace"
} | 57494 |
<p>I'm still learning Ruby and I made the following function to convert <code>"N"</code> or <code>"SE"</code> into <code>"NORTH"</code> or <code>"SOUTH EAST"</code> respectively. The function works and the tests all pass, but the code seems to be overly complicated. Any suggestions on how to clean it up and make it m... | [] | [
{
"body": "<p>All the round brackets are unnecessary here:</p>\n\n<pre><code>if (not match[1].empty?) and (not match[2].empty?)\n CARDINAL_DB[match[1]] + \" \" + CARDINAL_DB[match[2]]\nelsif (not match[1].empty?)\n CARDINAL_DB[match[1]]\nelsif (not match[2].empty?)\n CARDINAL_DB[match[2]]\n</code></pre>\n\n<... | {
"AcceptedAnswerId": "57512",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T03:22:05.333",
"Id": "57495",
"Score": "5",
"Tags": [
"beginner",
"ruby",
"converting"
],
"Title": "Convert cardinal abbreviations into full cardinal direction"
} | 57495 |
<p>I am writing this program to try and get some practice at C++ and correct and proper styling.</p>
<p>This code is meant to take user input from a pip and then run it through the program. The user enters a pattern and that pattern is turned into regex which is compared against the input, such that it could look lik... | [] | [
{
"body": "<p>The big thing that jumps out from reading your code is the lack of <code>const</code>. Just about every reference parameter that is passed should be passed by <code>const &</code>. This is very valuable - it means the compiler can enforce that only methods that will not change the object state... | {
"AcceptedAnswerId": "57529",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T04:29:33.183",
"Id": "57497",
"Score": "6",
"Tags": [
"c++",
"strings",
"parsing",
"regex",
"validation"
],
"Title": "Pattern tokenization program"
} | 57497 |
<p>I'm trying to apply sound today, and the goal in mind was a simple violin tuner. The <code>actionListener</code> seems repetitive/ How might I optimize it (what I tried just broke everything)? I also noticed the sounds bleed into each other. I don't mind that so much for the different keys (though I'm thinking of ... | [] | [
{
"body": "<p>You can clean up the repetition by moving the <code>ActionListener</code>'s code into a custom class, like this:</p>\n\n<pre><code>static class KeyButtonListener implements ActionListener {\n private final JButton button;\n private final String filename;\n\n KeyButtonListener(JButton butt... | {
"AcceptedAnswerId": "57516",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T05:42:11.433",
"Id": "57502",
"Score": "19",
"Tags": [
"java",
"beginner",
"event-handling",
"audio"
],
"Title": "Using sounds in Java"
} | 57502 |
<p>The code below downloads file in multiple chunks if split is set to some number, however there is a limit to maximum possible splits defined below by <code>maxSplits</code> if split is 0 or 1 then no extra thread overhead is laid on to split into further thread coming out of <code>ThreadedFetch</code>.</p>
<p>Pleas... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T09:03:48.753",
"Id": "102864",
"Score": "0",
"body": "Obligatory suggestion to read and consider following [the Python style guide, PEP-0008](http://legacy.python.org/dev/peps/pep-0008/)."
},
{
"ContentLicense": "CC BY-SA 3.... | [
{
"body": "<p>The join seems right to me.</p>\n\n<p>Tip 1:\nInstead of storing the file in memory using dataDict, you can directly write to file using </p>\n\n<pre><code>f = open('workfile', 'r+')\nf.seek(5) # Go to the 6th byte in the file\nf.write('0123456789abcdef')\n</code></pre>\n\n<p>Tip 2:\nOn _grabA... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T08:39:39.783",
"Id": "57510",
"Score": "2",
"Tags": [
"python",
"performance",
"multithreading",
"http",
"network-file-transfer"
],
"Title": "Command line multipart file d... | 57510 |
<p>First of, <a href="https://codereview.stackexchange.com/questions/55870/generate-the-norwegian-equivalent-to-social-security-numbers"><strong>here</strong></a> is my previous post.</p>
<p>That should explain a fair bit. The reason I'm posting one more time, is I have changed a lot. Using more classes, let them do a... | [] | [
{
"body": "<p>Here are some suggestions which may help you improve your code.</p>\n\n<h2>Don't abuse <code>using namespace std</code></h2>\n\n<p>Putting <code>using namespace std</code> within your program is generally <a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-b... | {
"AcceptedAnswerId": "57520",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T08:39:56.993",
"Id": "57511",
"Score": "2",
"Tags": [
"c++",
"classes",
"datetime",
"validation",
"inheritance"
],
"Title": "Generate the Norwegian equivalent to social... | 57511 |
<p>What do you think about this directive? For each <code>input</code>, it traverses the DOM towards the root and if it finds an element with the class <code>readonly</code>, it makes the input <code>readonly</code>.</p>
<p>An <code>ng-readonly</code> directive on the <code>input</code> itself get honored: The input be... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T19:59:15.280",
"Id": "102926",
"Score": "1",
"body": "I haven't worked with angular, so I can't read this syntax, but +1 for a simple, well explained review request."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate"... | [
{
"body": "<p>Generally speaking, you should avoid looking outside the current directive for anything that would affect your internal state (bar events). The preferred method of communication is scopes. Here is how I would recommend you do this.</p>\n\n<pre><code><div ng-controller=\"MyCtrl\">\n <di... | {
"AcceptedAnswerId": "57870",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T11:34:04.207",
"Id": "57515",
"Score": "12",
"Tags": [
"javascript",
"performance",
"angular.js"
],
"Title": "A directive allowing to make a whole DOM subtree readonly"
} | 57515 |
<p>I wrote an Ajax function, which should be used in a framework to interact with a webserver.</p>
<p>The (self-written) Java-Webserver can be used to fetch files and folder-contents, create files and folders, and delete them.</p>
<pre><code>/**
* Performs an Ajax-Request
* @param {string} method HTTP... | [] | [
{
"body": "<p>Support for JSONP and CORS is a must for any modern web framework.</p>\n\n<p>APIwise, I think you'd want to reduce the arguments to your method to a single object, similar to how jQuery does it. It gives an opportunity to give defaults, and simplifies it from the API perspective. As it stands, it... | {
"AcceptedAnswerId": "57532",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T12:17:09.863",
"Id": "57518",
"Score": "4",
"Tags": [
"javascript",
"optimization",
"ajax",
"http"
],
"Title": "Ajax for RESTful web service"
} | 57518 |
<p>I wanted to work on <code>HttpSessions</code> and JSP.</p>
<p>This is the view I have:</p>
<pre><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<div>
<c:out value="All available products:"/>
<br/>
<br/>... | [] | [
{
"body": "<h3>Interfaces vs implementations</h3>\n\n<p>Always use interfaces in declarations, not implementations. Instead of:</p>\n\n<blockquote>\n<pre><code> private static HashMap<Integer,String> products = new HashMap<Integer, String>();\n</code></pre>\n</blockquote>\n\n<p>Do like this:</p>\n\n... | {
"AcceptedAnswerId": "57526",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T16:23:56.593",
"Id": "57524",
"Score": "4",
"Tags": [
"java",
"http",
"jsp"
],
"Title": "Simple Java web app code"
} | 57524 |
<pre><code>/((([\w -]+)|("[\w -]+"))( *, *)?)+/
</code></pre>
<p><a href="http://refiddle.com/18ql" rel="nofollow">http://refiddle.com/18ql</a></p>
<p>I'm trying to use a <strong>PHP regex</strong> to sanitize a user input for a <strong>list of fonts</strong>. The above one seems to work nicely, but also feels a bit ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T20:08:09.247",
"Id": "102927",
"Score": "1",
"body": "Is it really necessary to filter out SQL injection attempts via regex? If the user is intentionally trying to break the system, they deserve to end up with invalid CSS."
},
... | [
{
"body": "<p>I'll tell you, I definitely had trouble reproducing your expression. The Refiddle you linked to was using JavaScript's regex engine, not <a href=\"http://php.net/manual/en/pcre.pattern.php\">PHP's PCRE</a>.</p>\n\n<p>Now, what you're doing is something that is complicated. Just so everyone knows, ... | {
"AcceptedAnswerId": "57570",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T18:07:01.767",
"Id": "57528",
"Score": "6",
"Tags": [
"php",
"css",
"regex",
"validation",
"sql-injection"
],
"Title": "Regex to validate font names"
} | 57528 |
<p>The scenario is about processing 'Message' objects. Producer creates them and Consumer does the consumption. </p>
<pre><code>class Message{...}
class MessageBatch{
public MessageBatch(Collection<Message> messages){...}
public List<Message> getMessages(){...};
//more utility methods like ... | [] | [
{
"body": "<p>Since you say that your whole system is based on message passing you should take a serious look at akka. You get a rock solid message passing system, and you can even spread it on multiple machines in the future.</p>\n\n<p>I have not checked in detail, but you have some very serious concurrency ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T20:30:08.963",
"Id": "57533",
"Score": "6",
"Tags": [
"java",
"multithreading",
"concurrency"
],
"Title": "Queue that connects multiple producers and multiple consumers"
} | 57533 |
<p>Honestly, I can't help but feel that this is done merely to confuse newcomers. Most of the errors on Stack Overflow by complete Android newbies mostly stem from that they have a static inner class Fragment that they don't understand how it works, why it's there, and try to use Activities even though they don't fully... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T22:57:49.760",
"Id": "102942",
"Score": "1",
"body": "Nice interesting question ! I hope it will receive a good amount of interest!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-04-29T22:10:15.370",
"... | [
{
"body": "<p>I totally agree that it is better to have a Fragment in it's own class rather than as a static inner class. I don't think I've seen any cases where it's been a static inner class, but perhaps I'm just lucky (or have a bad memory).</p>\n\n<p>Overall your code is very clean. And I really mean <em>ve... | {
"AcceptedAnswerId": "57918",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-20T22:54:34.367",
"Id": "57543",
"Score": "12",
"Tags": [
"java",
"android",
"xml",
"static"
],
"Title": "Why does the new ADT create a static inner class Fragment by default?... | 57543 |
<p>We record software builds from our build machine into a database and for practice purposes I'm building a little web dashboard for it.</p>
<p>The API is REST (WebApi) and provides access to query for Products, Branches, Profiles and specific Builds.</p>
<p>The controller queries all products (each product contains... | [] | [
{
"body": "<ol>\n<li><p>You can use this <code>unexplodeWord</code> function:</p>\n\n<pre><code> var explodedWords = [{\"0\":\"h\",\"1\":\"e\",\"2\":\"l\",\"3\":\"l\",\"4\":\"o\"}, \n {\"0\":\"w\",\"1\":\"o\",\"2\":\"r\",\"3\":\"l\",\"4\":\"d\"}]\n\n var words = explodedWords.map(unexpl... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T00:46:29.633",
"Id": "57548",
"Score": "12",
"Tags": [
"javascript",
"angular.js",
"promise",
"rest"
],
"Title": "Simple AngularJS controller for REST API"
} | 57548 |
<p>I made a little text-based game where you move a rover and it gives you the current coordinates. You can essentially move around a 1000x1000 grid, and get output into <code>stdout</code> on what your coordinates are. I'm simply wondering if I could improve anything.</p>
<pre><code># Rover moving program
from random... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T11:16:48.347",
"Id": "102998",
"Score": "1",
"body": "\"I made a little text-based game where you move a rover and it gives you the current coordinates.\" I doubt that; this is a standard test question called 'the Mars rover'. It is... | [
{
"body": "<h2>Validation</h2>\n\n<p>Your validation is weird, and probably not what you intended.</p>\n\n<ul>\n<li><code>move_rover(-1, -1)</code> appears to succeed, even though it's not within your 1000 × 1000 grid.</li>\n<li><code>move_rover(-1, 1001)</code> is a no-op. <code>move_rover(1001, 500)</code> i... | {
"AcceptedAnswerId": "57553",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T01:54:47.147",
"Id": "57550",
"Score": "6",
"Tags": [
"python",
"game",
"python-2.x",
"coordinate-system"
],
"Title": "Moving a rover and receiving current coordinates"
} | 57550 |
<p>I have just written my first git hook script. It is very simple that simply finds any URLs in the commit message and uses the Google URL shortener to rewrite the URL nicely.</p>
<p>it is located <a href="https://github.com/JamesWatling/commit-msg">here</a>.</p>
<p>I feel it could be improved immensely (as it is m... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T06:45:53.540",
"Id": "102978",
"Score": "7",
"body": "Why is that useful? A full URL usually has information in it. A shortened URL has no meaning (but is short). Its only useful in situations where you have limited space (like twit... | [
{
"body": "<p>First of all, the <code>`cmd`</code> form of running commands and capturing their output is deprecated. Use the recommended, modern way everywhere: <code>$(cmd)</code></p>\n\n<h3>Safety</h3>\n\n<p>Be careful with spaces in filenames. These commands will break:</p>\n\n<blockquote>\n<pre><code>messa... | {
"AcceptedAnswerId": "57557",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T05:09:21.117",
"Id": "57555",
"Score": "6",
"Tags": [
"bash",
"url",
"git"
],
"Title": "Git commit-msg URL shortener"
} | 57555 |
<p>I stumbled upon <a href="https://codereview.stackexchange.com/questions/33542/ugly-numbers-problem">an unaswered question</a>, which looked like a good fit for a functional programming language.</p>
<p>Here is the problem statement from <a href="https://www.codeeval.com/browse/42/" rel="nofollow noreferrer">codeeva... | [] | [
{
"body": "<p>What is the purpose of the <code>Expression</code> type? Why doesn't <code>expressions</code> just return all the possible results?</p>\n\n<p>This might be useful in other situations (like printing all the possibilities), but I don't see a reason for it here. Basically, it's an unnecessary level o... | {
"AcceptedAnswerId": "57568",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T06:46:33.620",
"Id": "57556",
"Score": "11",
"Tags": [
"programming-challenge",
"f#",
"rags-to-riches"
],
"Title": "Ugly Numbers: A Rags-to-Riches Story"
} | 57556 |
<p>I have a JavaScript function that is getting data out of a JSON file and then doing some formatting to it. The code works but I feel like it just an awful way of doing it. All criticism and help appreciated.</p>
<pre><code>function MCScrap(ZWA, ZWB, ZWC, ZWD, Number) {
$(document).ready(
function() {
... | [] | [
{
"body": "<p>I'd suggestion cleaning it up like this:</p>\n\n<pre><code>function MCScrap(ZWA, ZWB, ZWC, ZWD, Number) {\n $(document).ready(function () {\n setInterval(function () {\n $.getJSON(\"mccount.json\", function (machines) {\n var zwa, zwb, zwc, zwd, TScount, YScount... | {
"AcceptedAnswerId": "57564",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T10:21:04.130",
"Id": "57563",
"Score": "2",
"Tags": [
"javascript",
"optimization"
],
"Title": "Acquiring and formatting data from a JSON file"
} | 57563 |
<p>I am trying to write a version of <code>Task.WhenAll</code> for .NET 3.5 using the "Task Parallel Library for .NET 3.5". This is what I came up with. Is there a better way of doing this?</p>
<pre><code> public static Task WhenAll(IEnumerable<Task> tasks)
{
var tcs = new TaskCompletionSource<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T11:48:23.557",
"Id": "103002",
"Score": "2",
"body": "Not really sure but shouldn't the SetException code be outside the foreach loop?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T13:08:18.227",
... | [
{
"body": "<p>I like how you've written this code. Just a couple of nitpicks:</p>\n<h3>Consistency with <code>var</code></h3>\n<blockquote>\n<pre><code> var remainingTasks = tasks.ToList();\n int count = remainingTasks.Count();\n var exceptions = new List<Exception>();\n</code></pre>\n</blockquot... | {
"AcceptedAnswerId": "57583",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T11:20:04.410",
"Id": "57566",
"Score": "12",
"Tags": [
"c#",
"task-parallel-library"
],
"Title": "WhenAll for .NET 3.5"
} | 57566 |
<p>I have a small game I'm working on with a set of interfaces:</p>
<p><strong><code>IHavePosition</code>:</strong></p>
<pre><code>public interface IHavePosition<T>
{
T Position { get; set; }
}
</code></pre>
<p><strong><code>ICanMove</code>:</strong></p>
<pre><code>public interface ICanMove<T> : IHa... | [] | [
{
"body": "<blockquote>\n <p>The problem, however, is that this means when creating my classes, I need to ferry around this TPos generic construct to places where it doesn't make sense to define it. I'm left creating new <code>Player<Vector3></code> or <code>Player<Int2></code> instances all over t... | {
"AcceptedAnswerId": "57572",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T12:23:34.037",
"Id": "57569",
"Score": "14",
"Tags": [
"c#",
"generics",
"inheritance",
"interface"
],
"Title": "Reusability vs simplicity in a small game with a set of int... | 57569 |
<p>I have a userform that displays a goal time for workers to shoot for when completing a task. It also has a stopwatch on it that is controlled by a start, stop, and reset button on the userform. If the stopwatch time reaches the goal time and goes over, then there is a box called "extra time" that starts counting up.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T13:31:53.383",
"Id": "103015",
"Score": "0",
"body": "Just to be clear, is this code is written in a .bas code module, or it's a sheet's code-behind?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T13... | [
{
"body": "<p>Just formatting first:</p>\n\n<p>Your code is missing indentation and has some extra newlines in it. </p>\n\n<p>Your <code>Do Until</code> loop should be double indented because it is inside of a sub.\nYou should also get rid of the extraneous commented code. If you got it working, get rid of the ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T13:14:56.917",
"Id": "57573",
"Score": "10",
"Tags": [
"performance",
"vba",
"excel",
"timer"
],
"Title": "How can I make this userform timer faster?"
} | 57573 |
<p>I need to optimize the following function:</p>
<p>$$ \max_{a',\ m'}\ f(a, m, e, m', a') $$</p>
<p>I have approximated \$f\$ with a grid \$F\$, which has a shape \$(nA, nM, nE, nM, nA)\$. Now, I want to interpolate over the last two dimensions (the ones I need to maximize over), and then maximize. </p>
<p>The fol... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T14:35:58.253",
"Id": "103023",
"Score": "0",
"body": "Could you give us enough code (and sample data) that we can actually run it?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T14:53:54.063",
"I... | [
{
"body": "<p>It's not useful to have <code>class Parameters</code> just store constants...simply place those constants at the top of the code, after the import statements. </p>\n\n<p>Place all of your import statements at the beginning of the code. They can be accessed by any functions or methods below them.<... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T14:21:54.107",
"Id": "57577",
"Score": "10",
"Tags": [
"python",
"performance",
"numpy"
],
"Title": "Interpolate then maximize"
} | 57577 |
<p>I just developed a URL shortener.</p>
<p>index.php:</p>
<pre><code><?
$sql_host = "...";
$sql_db = "...";
$sql_user = "...";
$sql_pass = "...";
$conn_error = "Could not connect to database";
$con = mysqli_connect($sql_host, $sql_user, $sql_pass, $sql_db) or die($conn_error);
$hash... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T15:17:24.737",
"Id": "103034",
"Score": "1",
"body": "url rewrite might work with.htaccess"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T16:46:23.697",
"Id": "103058",
"Score": "0",
"bod... | [
{
"body": "<p>Ok, so the main problem with your code is that it is vulnerable to <code>SQL injection</code> you can fix that by using prepared statements - <a href=\"http://php.net/manual/en/mysqli.quickstart.prepared-statements.php\">http://php.net/manual/en/mysqli.quickstart.prepared-statements.php</a></p>\n... | {
"AcceptedAnswerId": "57589",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T14:56:01.813",
"Id": "57580",
"Score": "15",
"Tags": [
"php",
"html",
"sql",
"mysql",
"url"
],
"Title": "PHP URL Shortener"
} | 57580 |
<p>I use the <em>loop-every-single-list-item</em> approach to filter out unique elements in a given list, which tends to be very inefficient way as a list grow in size, or as function call frequency increases. Lately I was working on event handling patch and needed fast method for filtering out unique function handlers... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T17:59:32.940",
"Id": "103069",
"Score": "0",
"body": "I think there is a better way, yes, but I don't have the time at this moment. I'll be able to get to this this evening if you haven't gotten a good answer yet"
},
{
"Cont... | [
{
"body": "<p>There are some formatting issues here, but <strong>I'm going to focus on performance in my review</strong>, and others <a href=\"https://codereview.meta.stackexchange.com/q/2106/44716\">may come after me to touch on best practices with comments and formatting.</a></p>\n\n<p>Try to avoid running th... | {
"AcceptedAnswerId": "57634",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T15:02:05.887",
"Id": "57581",
"Score": "10",
"Tags": [
"javascript",
"optimization",
"array"
],
"Title": "How can I quickly find unique list items?"
} | 57581 |
<p>Below is a function (part of a procedurally written Wordpress plugin) which iterates through a multi dimensional array of regions, adding them to a custom hierarchical taxonomy. In the spirit of <em>globals are generally bad practice</em> I'd like to see how one could achieve the same ends without one.</p>
<p>The f... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-23T13:09:14.280",
"Id": "103497",
"Score": "0",
"body": "@Jamal I own this code (I commissioned it), and I'm trying to refactor it to avoid the use of a global. While I did not write it, I do maintain it. The code is not sudo code, nor... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T16:07:38.393",
"Id": "57587",
"Score": "1",
"Tags": [
"php",
"wordpress"
],
"Title": "Foreach with the aim of removing the need for a $global"
} | 57587 |
<p>I was reading about similar problems to the one I am having, and my guess is that I am having a 'memory leak'. I'm not sure exactly what that means, or how to correct it. Could you take a look at my code and help me optimize? <code>LastRow</code> in this bit is a little over 70000.</p>
<pre><code>start = Timer
Fo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T17:45:32.793",
"Id": "103067",
"Score": "2",
"body": "The `vlookup` is slowing down because Excel will recalculate the entire sheet each time the formula is entered into a new cell. Setting the calculation to xlManual prior to filli... | [
{
"body": "<p>I wish you would have posted more of your code here. I suspect that the code you posted should be broken out into it's own subroutine and we could have made sure you're using appropriate variable declarations. That being said, I'm only going to address your vlookup method, as you only need one or ... | {
"AcceptedAnswerId": "57610",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T17:03:41.600",
"Id": "57592",
"Score": "7",
"Tags": [
"memory-management",
"vba",
"excel"
],
"Title": "Possible memory leak in a for loop macro"
} | 57592 |
<p>I've built a simple command line flashcard game for learning Korean. I'm a beginner programmer, so I just wanted to make sure I'm following best practices, especially pertaining to OOP principles.</p>
<p>Any feedback would be greatly appreciated. </p>
<p>Here's GitHub <a href="https://github.com/Jberczel/korean_f... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T17:54:13.970",
"Id": "103068",
"Score": "3",
"body": "+1 for technology and learning! Another theoretical +1 for reminding me of dictionary reverse (I am building a French linguistics software) :)"
}
] | [
{
"body": "<p>The program's data structures aren't necessarily complicated enough for OOP - you'll almost never need to create multiple instances of any of the potential objects. So don't worry about it too much. </p>\n\n<p>The only big problem I can see is that you always calculate both the Korean-English and ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T17:31:23.643",
"Id": "57593",
"Score": "7",
"Tags": [
"beginner",
"object-oriented",
"ruby",
"game"
],
"Title": "Command line flashcard game"
} | 57593 |
<p>I am relatively new to TDD and am trying to adopt better names for my tests. </p>
<p>I wrote the following tests abruptly and have since refactored them to the best of my ability, but despite my best efforts, the test names are still (mostly) abysmal.</p>
<p>I am here today to ask that you review my test names. </... | [] | [
{
"body": "<p>Let me start out by saying that your test names are actually decent. You have already come to the conclusion that a good test name is one that can convey what is being tested without requiring someone to actually read the test.</p>\n\n<p>As with many things, there are three important pieces of inf... | {
"AcceptedAnswerId": "57683",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T18:20:09.820",
"Id": "57597",
"Score": "17",
"Tags": [
"c#",
"unit-testing",
"asp.net-mvc"
],
"Title": "Naming for unit tests for controller to edit posts"
} | 57597 |
<p>The University Library where I work is in the process of redesigned our home page. One of the features we wish to include is a widget to display the current hours. Unfortunately for a variety of reasons this must be done using client side scripting instead of a PHP script which pulls from Google Calendar. After m... | [] | [
{
"body": "<p>I'm not an expert in JavaScript, but there is some things I can say about your code.</p>\n<h2>Naming</h2>\n<blockquote>\n<p>Unfortunately for a variety of reasons this must be done using client\nside scripting instead of a PHP script which pulls from Google\nCalendar</p>\n</blockquote>\n<p>Even if... | {
"AcceptedAnswerId": "57623",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-21T18:24:34.943",
"Id": "57599",
"Score": "3",
"Tags": [
"javascript",
"datetime"
],
"Title": "Date Comparison Script"
} | 57599 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.