body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
The NSMutableString class declares the programmatic interface to an object that manages a mutable string — that is, a string whose contents can be edited — that conceptually represents an array of Unicode characters. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T00:33:38.890",
"Id": "56300",
"Score": "0",
"Tags": null,
"Title": null
} | 56300 |
<blockquote>
<p>Find all nodes of trees, without siblings.</p>
</blockquote>
<p>This question is attributed to <a href="http://www.geeksforgeeks.org/print-nodes-dont-sibling-binary-tree/" rel="nofollow">GeeksForGeeks</a>.</p>
<p>I'm looking for code reviews, optimizations and best practices.</p>
<pre><code> publi... | [] | [
{
"body": "<h2>Tests</h2>\n<p>I will say it again and again and again! Tests are <strong>important</strong>!! Don't throw 2 tests that are, sorry to say it, really bad. You should use them like powerful tools that will help you create better code. If you don't put effort on them, then don't bother to make them.... | {
"AcceptedAnswerId": "56312",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T01:18:19.313",
"Id": "56305",
"Score": "3",
"Tags": [
"java",
"tree"
],
"Title": "Find all nodes in tree, without a sibling"
} | 56305 |
<p>This is my first code in C# ever. It compiles and works as intended (not complete), but I want to see what I'm doing right and wrong as a first-timer.</p>
<pre><code>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T05:25:38.347",
"Id": "99094",
"Score": "0",
"body": "Don't cast an enum to `int` like you're doing in `IsLinux`, you're defeating the purpose of the [PlatformID](http://msdn.microsoft.com/en-us/library/3a8hyw88(v=vs.110).aspx) enume... | [
{
"body": "<p><strong>Overall Impression</strong> <br />\nApplications should be split into layers. <br />\nI know it's a simple, throwaway, demo application but these are a perfect opportunity to start working on splitting an application into a Model, View and X. (A Matter Of Personal Preference <em>(AMOPP)</e... | {
"AcceptedAnswerId": "56316",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T04:21:22.773",
"Id": "56311",
"Score": "5",
"Tags": [
"c#",
"beginner",
"parsing",
"xml"
],
"Title": "Short XML parser"
} | 56311 |
<p>I want to write a program to work out how many semi-magic squares there are. </p>
<p>Here is the definition of <a href="http://mathworld.wolfram.com/SemimagicSquare.html" rel="nofollow">semi-magic squares</a></p>
<blockquote>
<p>If we define \$H_n(t)\$ is the number of semi magic squares which satisfy:</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T14:35:45.727",
"Id": "99179",
"Score": "0",
"body": "Hi! Sorry - are you not missing the big constraint: 3. A semi-Magic Square must contain all numbers from 1..n*n exactly once? Otherwise you don't even need a program..."
},
{
... | [
{
"body": "<p>There could be smarter ways to write your code in such a way that it would scale better (for instance, if you were to consider squares of side 4 or 5, you'd have 16 or 25 nested loops and local variables to handle).</p>\n\n<p>First thing first, let's try to see what can easily be improved in your ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T08:47:48.310",
"Id": "56319",
"Score": "10",
"Tags": [
"c++",
"performance",
"matrix",
"backtracking"
],
"Title": "How many semi magic squares are there?"
} | 56319 |
<p>I'm comparing two variables which I'd like to be printed to the console like so:</p>
<pre><code>==Full Ex Vat==
true
</code></pre>
<p>Currently the code to do this is:</p>
<pre><code>print '==Full Ex Vat=='
print case when
@aTotalExVat = @sTotalExVat
then 'true' else 'false' end
</code></pre>
<p>which I feel isn... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T12:12:54.327",
"Id": "99147",
"Score": "0",
"body": "Seems fine to me. Not sure what bugs you with this. I'd write the second `print` statement on a single line though."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDa... | [
{
"body": "<p>SQL uses three valued logic.</p>\n\n<p>When one of the operands is null the expression evaluates to <code>UNKNOWN</code> not false. Your current code does not take account of this and can be altered as below to do so.</p>\n\n<pre><code>PRINT CASE\n WHEN @aTotalExVat = @sTotalExVat THEN 'tru... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T08:50:22.587",
"Id": "56320",
"Score": "4",
"Tags": [
"sql",
"sql-server"
],
"Title": "Printing simple SQL comparsion"
} | 56320 |
<p>I'm having a hard time figuring out if the code I wrote is purely combinatorial or sequential logic. I'm designing a simple 16-bit microprocessor (will be implemented on a Spartan 6) and I'm new to Verilog, HDL and FPGAs. The code for the microprocessor is complete, but I'm having second thoughts about the best prac... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T11:37:04.690",
"Id": "99141",
"Score": "0",
"body": "Just FWIW, the Xilinx tools will tell you how fast a particular design can run on their hardware. At least in my experience, their estimates are usually *pretty* accurate."
},
... | [
{
"body": "<blockquote>\n <p>non-blocking one, which is better for sequential circuits.</p>\n</blockquote>\n\n<p>It is not better per-se but it is the correct way to simulate a flip-flop. </p>\n\n<p>Combinatorial</p>\n\n<pre><code>always @* begin\n a = b;\n</code></pre>\n\n<p>Sequential (flip-flop)</p>\n\n<pr... | {
"AcceptedAnswerId": "56328",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T09:44:36.127",
"Id": "56322",
"Score": "7",
"Tags": [
"verilog"
],
"Title": "Verilog coding practices for synthesis"
} | 56322 |
<p>I'm trying to create code that reads a text file (containing (<code>double</code>) numbers between 0 and 1) and filling up a 3D array/matrix (calling it matrix from now on) with those values. After that is done I need to figure out the current max-value inside this matrix and then look at the values around it (in ev... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T10:21:11.297",
"Id": "99127",
"Score": "0",
"body": "Welcome to Code Review! It's an interesting question you have here, I feel that it would be helpful if you could provide some sample input/output data that can be used to test you... | [
{
"body": "<p><strong>Cast-Aways</strong></p>\n\n<p>Make your constants double at compile time.</p>\n\n<p><code>BubbleFrame[b, a, c] = 0D;</code>, <code>0.12D</code>, <code>BubbleFrame[b + 1, a - 1, c - 1] = 0D</code> etc. Well, <code>0.12</code> is already a <code>double</code>, but what the heck.</p>\n\n<p>... | {
"AcceptedAnswerId": "56397",
"CommentCount": "17",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T09:48:33.147",
"Id": "56323",
"Score": "4",
"Tags": [
"c#",
"performance",
"matrix",
"search"
],
"Title": "Search algorithm for specific values in a 3D array/matrix being ... | 56323 |
<p>I am practicing object oriented design and have taken Tic Tac Toe as an example. I have written first all the requirements and then started writing code. I would like to get it reviewed so that I can improve my skill further. Please provide suggestions.</p>
<p>I have placed code at this <a href="https://github.com/... | [] | [
{
"body": "<p>Overall this looks pretty good. Just a couple of things come to mind:</p>\n\n<p><strong>Square.js</strong></p>\n\n<ol>\n<li>The <code>setSymbol</code> method should throw errors instead of returning strings, especially since I don't see any place where those strings are handled in a manor allowing... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T10:42:38.103",
"Id": "56325",
"Score": "10",
"Tags": [
"javascript",
"object-oriented",
"design-patterns",
"tic-tac-toe"
],
"Title": "OO design for Tic Tac Toe program"
} | 56325 |
<p>I've just begun creating my first user class. First, I need some clarifications.</p>
<p>Am I using <code>try</code> and <code>catch</code> correctly?</p>
<p>To clarify, the way I would be instantiating this object is like so:</p>
<pre><code>try{
$loggedInUser = new LoggedIn/User($email,$password,$useragent);
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T16:59:15.620",
"Id": "99206",
"Score": "0",
"body": "5 hours, not a single comment or answer. must be dead over here."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T13:33:26.883",
"Id": "99386",
... | [
{
"body": "<p>Here on Code Review, it's common to not receive some sort of feedback for a few hours. We all try our best to be on and answering!</p>\n\n<hr>\n\n<p>I'm having a hard time deciding what you mean in your question. It's hard to understand... As of now, your class seems to be indescribably complex fo... | {
"AcceptedAnswerId": "56371",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T11:12:53.160",
"Id": "56327",
"Score": "4",
"Tags": [
"php",
"object-oriented",
"design-patterns",
"classes"
],
"Title": "First attempt at making a user class"
} | 56327 |
<p>Given a base path and a list with extensions the task is to list all files:</p>
<p>Two of my solutions are:</p>
<pre><code>from glob import glob
from os import path
EXTENSIONS = ['*.zip', '*.jar', '*.pdf']
DOC_PATH = '/path/to/files'
# Solution1:
files = []
for ext in EXTENSIONS:
files.extend(glob(p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T12:20:02.510",
"Id": "99149",
"Score": "2",
"body": "Not quite sure how idiomatic/efficient it is : `sum((glob(path.join(DOC_PATH, ext)) for ext in EXTENSIONS), [])` ."
}
] | [
{
"body": "<p>If you only need to iterate over them (once) and not an actual list, you could use <code>itertools.chain</code> and <code>glob.iglob</code>:</p>\n\n<pre><code>files = chain(*(iglob(path.join(DOC_PATH, ext)) for ext in EXTENSIONS))\n</code></pre>\n\n<p>If you do need an actual list, you can further... | {
"AcceptedAnswerId": "56334",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T12:08:45.517",
"Id": "56332",
"Score": "4",
"Tags": [
"python"
],
"Title": "Pythonic way for double iteration (list all files with extensions)"
} | 56332 |
<p>I wrote my first animation in Java FX and would like a code review. </p>
<p>I created <code>StackPane</code> with <code>Rectangle</code>. <code>Rectangle</code> starts to move inside <code>StackPane</code> to right-bottom direction and changes direction after hitting the <code>StackPane</code> bound. </p>
<p>P... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T14:25:45.087",
"Id": "99171",
"Score": "0",
"body": "Welcome to Code Review! Have you tested your code? Code Review is about making working things cleaner, but a simple test fails to get your code working properly. `Exception in thr... | [
{
"body": "<p>No, this is not the correct way to do it. I would recommend that you read <a href=\"http://docs.oracle.com/javafx/2/animations/jfxpub-animations.htm\" rel=\"nofollow noreferrer\">JavaFX Transitions</a> documentation.</p>\n\n<p>I personally could not get your code to work properly (Using Java 8, bu... | {
"AcceptedAnswerId": "56358",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T14:08:32.613",
"Id": "56340",
"Score": "5",
"Tags": [
"java",
"animation",
"javafx"
],
"Title": "Bouncing square in a box"
} | 56340 |
<p>I have to write the following method:</p>
<p>I have sorted array of integers and in this array every integer repeats twice, except two elements. I have to find these two elements.</p>
<ul>
<li>Input: 1, 1, 2, 3, 3, 4, 4, 5</li>
<li>Output: 2, 5</li>
</ul>
<p>This is my solution:</p>
<pre><code>private static in... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T14:26:06.840",
"Id": "99172",
"Score": "0",
"body": "Are there any restrictions to the code?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T14:33:43.670",
"Id": "99177",
"Score": "0",
"bo... | [
{
"body": "<p>For each number in the list, either</p>\n\n<ul>\n<LI>there is no next (at end of src list) - add to result list</li>\n<li>the next is different - add to the result list, increment result count (if all answers found, return)</li>\n<li>the next is the same; skip next, (add 2 to src pointer)</li>\n</... | {
"AcceptedAnswerId": "56346",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T14:16:17.643",
"Id": "56341",
"Score": "10",
"Tags": [
"java",
"array",
"interview-questions"
],
"Title": "Find two unique integers in sorted array"
} | 56341 |
<p>This server require fast decoding of packets from clients, as I am expecting 5000 concurrent clients that is sending packets possibly every second. This is a game server (5000 players walking send packets each n every step).</p>
<p>I want to see if my implementation is fast enough or there are still room for improv... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T15:32:32.700",
"Id": "99193",
"Score": "0",
"body": "Can you say more about this algorithm? How did you choose it? Why did you not use a standard algorithm like AES?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate"... | [
{
"body": "<p>It is hard to review something when you can't test whether your reviewed code actually works, so with that disclaimer lets see what we can do with your code.</p>\n\n<p>Regarding style issues, your variable names are not good, and doesn't convey any useful informations. But leave that as it is...</... | {
"AcceptedAnswerId": "113323",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T14:29:20.423",
"Id": "56343",
"Score": "10",
"Tags": [
"python",
"optimization",
"python-2.x",
"networking",
"twisted"
],
"Title": "Decoding custom packets with Python... | 56343 |
<p>The problem:</p>
<ul>
<li>A <code>Node</code> is located in a specific coordinate (x, y, z). </li>
<li>A <code>Node</code> can be one of these types: <code>None</code>, <code>Hinge</code>, <code>Roll</code>, <code>Fixed</code>. (it is called Boundary Condition)
Different boundary condition type determine a <code>N... | [] | [
{
"body": "<p>It all looks good to me, though you can simplify your NodeBase <code>getForce()</code> and <code>getDisplacement()</code> methods if you use <a href=\"http://www.php.net/manual/en/language.variables.variable.php\" rel=\"nofollow\">variable properties</a>, like so:</p>\n\n<pre><code>public function... | {
"AcceptedAnswerId": "56615",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T15:19:55.893",
"Id": "56352",
"Score": "5",
"Tags": [
"php",
"object-oriented"
],
"Title": "Nodes and Boundary Conditions in Finite Element Method"
} | 56352 |
<p>This library registers a new user.</p>
<p>Questions:</p>
<ol>
<li><p>Where should the DB class instantiation happen for user class? I tried instantiation in the constructor but that property doesn't seem to be available to the rest of the user class. As a work-around, I'm creating a new instance with every functi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T11:35:24.440",
"Id": "99357",
"Score": "1",
"body": "Just a few tips: `global` + `class` = bad code. Likewise for `$_POST` in a class: if a method needs data, or an instance of a class, then that method should take arguments. When w... | [
{
"body": "<p>I'm sorry I don't really know the answer to number 1, 2, 3. I'm a beginner too, but I think I know a better solution for number 4. As far as I know, global variables are bad. So you should create a new class for storing config data, like this:</p>\n\n<pre><code>class DatabaseConfig\n{\n private... | {
"AcceptedAnswerId": "56364",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T15:48:57.937",
"Id": "56357",
"Score": "6",
"Tags": [
"php",
"object-oriented",
"mysql"
],
"Title": "DB abstraction, private methods in OOP PHP library"
} | 56357 |
<p>I'm trying to figure out the cleanest way to implement a fluent interface with <code>unique_ptr</code> and other "modern" C++ language constructs. Here's my first attempt:</p>
<pre><code>#include <iostream>
#include <memory>
#include <vector>
// Backported from C++14
namespace std
{
template&... | [] | [
{
"body": "<p>Please don't do this:</p>\n\n<pre><code>using namespace std;\n</code></pre>\n\n<p>See: <a href=\"https://stackoverflow.com/q/1452721/14065\">Why is “using namespace std;” considered bad practice?</a></p>\n\n<p>I would change a couple of things:</p>\n\n<h3>In WidgetBuilder</h3>\n\n<p>I don't like t... | {
"AcceptedAnswerId": "56374",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T16:10:23.917",
"Id": "56360",
"Score": "7",
"Tags": [
"c++",
"design-patterns",
"c++11",
"smart-pointers"
],
"Title": "Builder/named argument/fluent interface pattern with ... | 56360 |
<p>I implemented a generic <code>Deque<T></code> data structure.</p>
<p>Please, review this implementation.</p>
<p><strong>Deque.java:</strong></p>
<pre><code>import java.util.Iterator;
import java.util.NoSuchElementException;
class Deque<T> implements Iterable<T> {
private class Node<T> {... | [] | [
{
"body": "<p>This class looks reasonably complete, and fully usable. There are some issues I see that may affect the experience though, and also some suggestions about a better way to do it...</p>\n<h2>Issues:</h2>\n<ul>\n<li><p>Why do you reject <code>null</code> values? Your implementation works well even if... | {
"AcceptedAnswerId": "56365",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T16:47:10.370",
"Id": "56361",
"Score": "11",
"Tags": [
"java",
"generics",
"queue"
],
"Title": "Generic deque implementation"
} | 56361 |
<p>I have been writing an event class for my game engine and I came across to the following problem:</p>
<p><em>Is casting a base class object to a derived class object given a type flag a good programming design?</em></p>
<p>Let me give you the following simple example. I have this <code>enum</code> holding the cat... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T17:50:41.573",
"Id": "99213",
"Score": "0",
"body": "I think a pattern like this is common when posting events. Some thoughts: 1) Perhaps SetType and SetEventType could be private. It looks like it is only called from the base cla... | [
{
"body": "<p>You may consider looking into the <code>dynamic_cast</code> keyword. which allows polymorphic classes to be down-casted based on their type. </p>\n\n<p>For example:</p>\n\n<pre><code>class Base {\npublic:\n virtual ~Base() { }\n};\n\nclass Derived : public Base {\n\n};\n\nint main() {\n Base... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T17:11:51.723",
"Id": "56363",
"Score": "10",
"Tags": [
"c++",
"object-oriented",
"design-patterns"
],
"Title": "Casting base to derived class according to a type flag"
} | 56363 |
<p>I'm implementing the K-nearest neighbours classification algorithm in C# for a training and testing set of about 20,000 samples and 25 dimensions. </p>
<p>There are only two classes, represented by <code>'0'</code> and <code>'1'</code> in my implementation. For now, I have the following simple implementation:</p>
... | [] | [
{
"body": "<pre><code>var distances = new double[trainNumber][]; \nfor (var i = 0; i < trainNumber; i++)\n{\n distances[i] = new double[2]; // Will store both distance and index in here\n}\n</code></pre>\n\n<p>This is a code smell. You shouldn't use a jagged double array to store an array of distances and ... | {
"AcceptedAnswerId": "56372",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T17:50:31.213",
"Id": "56367",
"Score": "7",
"Tags": [
"c#",
"performance",
"machine-learning"
],
"Title": "K-nearest neighbours in C# for large number of dimensions"
} | 56367 |
<p>I've a feeling I'm overdoing my <code>Auth</code> class, and that it could be done in a simpler and more understandable way.</p>
<p>Could you give me advice on this, please?</p>
<p>This is for my learning process and I just want to learn. This is why I am 'reinventing the wheel'.</p>
<pre><code>class Auth
{
... | [] | [
{
"body": "<p>The code is understandable, but it can be simplified.</p>\n\n<p>Instead of:</p>\n\n<blockquote>\n<pre><code>public function unset_session()\n{\n if (isset($this->session))\n {\n $this->session = null;\n }\n}\n</code></pre>\n</blockquote>\n\n<p>You can simply:</p>\n\n<pre><co... | {
"AcceptedAnswerId": "56383",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T18:26:17.453",
"Id": "56373",
"Score": "12",
"Tags": [
"php",
"object-oriented",
"authentication",
"session"
],
"Title": "Sessions and Authentication"
} | 56373 |
<p>From <a href="http://en.wikipedia.org/wiki/Cursor_%28databases%29" rel="nofollow">Wikipedia</a>:</p>
<blockquote>
<p>In computer science and technology, a database cursor is a control structure that enables traversal over the records in a database. Cursors facilitate subsequent processing in conjunction with the ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T19:54:20.767",
"Id": "56377",
"Score": "0",
"Tags": null,
"Title": null
} | 56377 |
A cursor is a control structure for traversing records in a database. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T19:54:20.767",
"Id": "56378",
"Score": "0",
"Tags": null,
"Title": null
} | 56378 |
<p>I'm a beginner in JavaScript and I am sure that there is a better way to do it (basic one minute timer from 01:00 to 00:00 running from pageload):</p>
<p><a href="http://jsfiddle.net/L7u26/">JSFiddle</a></p>
<pre><code>window.onload=function(){
(function(){
setInterval(function(){
cro();
document.ge... | [] | [
{
"body": "<p>There's another Stack Overflow <a href=\"https://stackoverflow.com/questions/6312993/javascript-seconds-to-time-with-format-hhmmss\">question</a> with a useful function:</p>\n\n<pre><code>String.prototype.toHHMMSS = function () {\n var sec_num = parseInt(this, 10); // don't forget the second pa... | {
"AcceptedAnswerId": "56386",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-07T20:34:05.817",
"Id": "56381",
"Score": "11",
"Tags": [
"javascript",
"beginner",
"timer"
],
"Title": "Basic timer from one minute to 0"
} | 56381 |
<p>The following code list all files in a folder and allows the user to download one of them. It is working but I think it could be done better.</p>
<p>Is there a way to reduce the number of forms to only one and to improve the way I retrieve the name of the file to download?</p>
<p>My second concern is about the sec... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T05:06:53.290",
"Id": "99305",
"Score": "0",
"body": "Your `getFile` function is *incredibly* insecure. The number one rule is to never trust the user. I could POST `getFile=/var/etc/passwd` or `getFile=../my/secret/file` or somethin... | [
{
"body": "<p>Let's post a dry review first, before jumping in to the conceptual stuff:</p>\n\n<ul>\n<li>You are allowing your end-users download any file on the server. All I need to do is to change the path to <code>/etc/passwd</code> on any form and submit, and I get your server's password file! And if I don... | {
"AcceptedAnswerId": "56417",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T01:19:19.423",
"Id": "56391",
"Score": "5",
"Tags": [
"php",
"form",
"file-system"
],
"Title": "List files and download"
} | 56391 |
<p>How can I rewrite this in a simpler way?</p>
<pre><code>$imageContainer = $($(this).parent().children()[0]).children()
currentIdx = 0
for e, idx in $imageContainer
if e.className.indexOf('active')
currentIdx = idx
break
</code></pre>
| [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T03:52:28.843",
"Id": "99298",
"Score": "1",
"body": "Could you describe what this code does?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T04:00:37.137",
"Id": "99299",
"Score": "1",
"bo... | [
{
"body": "<p>It looks like you're looking for the index of the first child of <code>$imageContainer</code> with the <code>active</code> class. (Incidentally, your code will also trigger on stuff like <code>inactive</code>, which might be a false positive. Be careful about your classes!)</p>\n\n<p>Native select... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T03:48:26.503",
"Id": "56399",
"Score": "1",
"Tags": [
"jquery",
"coffeescript"
],
"Title": "Navigating around ul li and looking for the active state on the current slide"
} | 56399 |
<p>I used the idle command to wait for incoming messages in my Gmail mailbox. The protocol I am using is IMAP.</p>
<p>My concern is as follows:</p>
<p>While the below code works, Gmail has a tendency to try to interrupt the connection. Therefore, I found some solutions online including sending a periodic NOOP command... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T05:55:06.603",
"Id": "99310",
"Score": "0",
"body": "What's `com.sum.mail.iap`? Have you verified that this program works?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T06:06:51.097",
"Id": "993... | [
{
"body": "<h1>Threads:</h1>\n\n<p>Threads are <strong><em>hard.</em></strong> It's difficult to do it right and very very easy to mess up. One of the things you shouldn't do are so called <em>Busy Waits</em>.<br>\nThese busy waits is calls to <code>Thread.sleep()</code> with values other than \\$0\\$ or \\$1\\... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T05:25:34.940",
"Id": "56403",
"Score": "7",
"Tags": [
"java",
"networking",
"email"
],
"Title": "Wait for messages in IMAP Gmail mailbox"
} | 56403 |
<p>I have a list of datacenters, which are <code>dc1</code>, <code>dc2</code> and <code>dc3</code>. And each datacenter has six ids as of now (can be 11 in each datacenter as well or uneven number for each datacenter).</p>
<blockquote>
<pre><code>dc1 - h1, h2, h3, h4, h5, h6
dc2 - h1, h2, h3, h4, h5, h6
dc3 - h1, h2, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T22:23:12.310",
"Id": "99513",
"Score": "0",
"body": "A few othe data cases that may throw off a few people: dc1, dc2, dc3 with each having hosts h1, h2"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T... | [
{
"body": "<p>Your code is so complicated that I did not understand it (I did not try that long). I decided to write my own solution since I thought it would take less time than understanding your code. My method takes about 15 lines. Also, I used good OO decomposition and wrapped this generation of configur... | {
"AcceptedAnswerId": "56473",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T05:52:44.487",
"Id": "56406",
"Score": "5",
"Tags": [
"java",
"optimization",
"algorithm"
],
"Title": "How to generate valid number of combinations basis on the rules?"
} | 56406 |
<p><strong>My Problem</strong></p>
<p>I have a library containing business logic which is being used from 3 different projects:</p>
<ul>
<li>Website</li>
<li>Local WPF Application</li>
<li>WCF Service</li>
</ul>
<p>The library uses Entity Framework and a connection string which is read out of config on first use and... | [] | [
{
"body": "<p>The general approach seems reasonable to me, thought I believe it means you have to very careful around anything that can switch threads, like TPL or <code>async</code>-<code>await</code>.</p>\n\n<hr>\n\n<pre><code>public static ContextIdentity LocalIdentity;\n</code></pre>\n\n<p>Why is this <code... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T06:17:11.747",
"Id": "56410",
"Score": "1",
"Tags": [
"c#",
"design-patterns",
"multithreading",
"entity-framework",
"wcf"
],
"Title": "Concept for saving context informat... | 56410 |
<p>The code below is sort of complicated to explain...
It writes a "sphere" of data to a 3D array from the given 3D-Position outwards in a spherical shape based on the given radius and value to write.</p>
<p>A graphical representation of this would be:</p>
<p><img src="https://i.imgur.com/LpgfQAU.png" alt=""></p>
<p... | [] | [
{
"body": "<p>I find it suspicious that your \"Dimension 0\" is completely empty. I'd at least expect to see a small \"+\" of <code>5</code>'s there. Whatever shows up in this last dimension should also show up (assuming spherical symmetry), on the top, the bottom and the sides of the sphere. This will round-ou... | {
"AcceptedAnswerId": "56460",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T07:27:42.187",
"Id": "56413",
"Score": "4",
"Tags": [
"c++",
"array"
],
"Title": "Implementing write sphere of values to 3D array"
} | 56413 |
<p>I have the following function that creates an array of JSON objects with properties from an array of arrays, where the first 'row' in the array contains the keys.</p>
<p>It works, but could it be improved?</p>
<pre><code>var myArray = [
["a","b","c","d"], // will become keys
[1,2,3,4],
["foo","bar","b... | [] | [
{
"body": "<p>You can use Slice and Transpose, but your code is not that bad - just add some syntactic sugar by refactoring the code and:</p>\n\n<pre><code>function Map(arr, i) {\n var obj = {};\n for (var j = 0; j < arr[0].length; j++) {\n obj[ arr[0][j] ] = arr[i][j];\n };\n return obj;\... | {
"AcceptedAnswerId": "56436",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T11:22:16.117",
"Id": "56425",
"Score": "3",
"Tags": [
"javascript"
],
"Title": "Create an array of objects from array of arrays"
} | 56425 |
<blockquote>
<p>If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.</p>
<p>Find the sum of all the multiples of 3 or 5 below N.</p>
</blockquote>
<pre><code> #include <stdio.h>
int main(){
int i=0,j,k,l,sum=0;
scanf("%d&... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T11:52:59.847",
"Id": "99362",
"Score": "5",
"body": "The formatting makes it nearly unreadable. Code that doesn't look good also typically doesn't run well."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-... | [
{
"body": "<p>Generally, try to think about the problem before brute-forcing it. </p>\n\n<p>Is there an easy way to sum all the multiples of 3 below \\$N\\$? Of course there is. \nFirst we note that the largest multiple of 3 is \\$3 * \\lfloor\\frac{N}{3}\\rfloor\\$ and the sum of all the multiples is then \\$3... | {
"AcceptedAnswerId": "56510",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T11:28:02.863",
"Id": "56426",
"Score": "1",
"Tags": [
"c",
"programming-challenge",
"time-limit-exceeded"
],
"Title": "Sum the Multiples of 3 and 5"
} | 56426 |
<p>In my Android app I have number of methods that should be executed in a background thread. </p>
<p>One of the methods looks like this</p>
<pre><code>public static void processItem(final Context context, final String itemId)
{
if (Looper.myLooper() == Looper.getMainLooper())
{
Thread task = new Thre... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T13:09:10.557",
"Id": "99378",
"Score": "0",
"body": "You could use something like the `GuiUtils` class from this question : http://codereview.stackexchange.com/questions/52197/console-component-in-javafx (it's for javafx but the sam... | [
{
"body": "<p>You can pass a Runnable to the <code>processItem</code> function which the only thing that does it to be sure that the Looper is the same as the main looper and if yes start a thread with the callback you passed to it.</p>\n\n<pre><code>processItem(Runnable callback);\n</code></pre>\n\n<p>will be:... | {
"AcceptedAnswerId": "56444",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T11:31:40.547",
"Id": "56428",
"Score": "15",
"Tags": [
"java",
"android"
],
"Title": "Run different methods in background threads without duplication"
} | 56428 |
<p>I have a multithreaded application for web scraping from an automobile website. While performing web scraping, there are many links that gives the same result, so I have to check for data redundancy. </p>
<p>I have maintained a <code>BlockingCollection<String></code> that adds vehicle VIN number in it and pe... | [] | [
{
"body": "<p>What do you ultimately intend to do with this data?</p>\n\n<p>It may not be ideal to keep it all in memory. You may want to use an actual database, which will index and cache the data in an efficient way. Since you're doing things with tasks, the extra overhead of going to the database and back wo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T12:00:55.043",
"Id": "56432",
"Score": "4",
"Tags": [
"c#",
"multithreading",
"memory-management"
],
"Title": "Maintaining a car collection list in a multithreaded application"
} | 56432 |
<p>I am creating a vector class which can be manipulated on the GPU and I am using C++AMP for the GPU accelerated code. </p>
<p>I am wondering the most efficient way of assigning elements of a different type to a <code>concurrency::array</code> in C++AMP. There are two ways that I can think of (but there may be more):... | [] | [
{
"body": "<p>As with almost any performance related question, the correct answer is probably to do some profiling to get solid answers.</p>\n\n<p>That said, it strikes me as unlikely that attempting to do the copy in parallel will usually make much difference. In a typical case, copying to the accelerator take... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T12:24:10.187",
"Id": "56434",
"Score": "2",
"Tags": [
"c++",
"c++11",
"concurrency",
"amp"
],
"Title": "Assigning an array of different (but convertible) type to concurrency::... | 56434 |
<p>Ignoring my shocking use of the <code>mysql_*</code> extension (and any associated issues), could you take a look at my script that uploads an image, adds it to a database, creates a thumbnail of the image 578px in width, and adds that to the database too?</p>
<pre><code><?php
require_once("validate.php");
whil... | [] | [
{
"body": "<p>It's considered better to omit the closing <code>?></code> of the PHP file.</p>\n\n<p>If you're wondering why, there are a few rare situations in which you can accidentally have whitespace trailing the closing tag and issues will result. Since PHP doesn't require the closing tag anyway, it's sa... | {
"AcceptedAnswerId": "56603",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T14:02:26.140",
"Id": "56445",
"Score": "1",
"Tags": [
"php",
"memory-management",
"image"
],
"Title": "Image upload and thumbnail creation script using PHP GD"
} | 56445 |
<p>This is my solution to the <a href="http://www.codechef.com/JULY14/problems/FROGV" rel="nofollow">FROGV problem on Codechef</a>:</p>
<pre><code>N,K,P = map(int,raw_input().split(' ')) # N: No of Inputs, K: highest possible jump, P: no of test cases
L = map(int,raw_input().split(' ')) # Takes in the N space separate... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T18:19:17.920",
"Id": "99465",
"Score": "0",
"body": "Have you measured the performance of your code? What test case did you use?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T18:21:40.140",
"Id"... | [
{
"body": "<p>You said that only checked your code against the example on Codechef. But the example only has 5 frogs and 3 pairs! Running this tiny example won't tell you how your code will perform on the worst case, where there might be 100,000 frogs and 100,000 pairs.</p>\n\n<p>So the first step is to make a ... | {
"AcceptedAnswerId": "56645",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T14:30:19.970",
"Id": "56451",
"Score": "3",
"Tags": [
"python",
"optimization",
"programming-challenge"
],
"Title": "Speeding up Codechef FROGV"
} | 56451 |
<p>I have a small script that takes a list of objects from an SQL table and groups them if the date-time on the object has less than 60 second difference with the last object. </p>
<p>It does this by converting the date-time to epoch and then subtracting the epoch of the previous object from the epoch of the current o... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T14:43:44.383",
"Id": "99404",
"Score": "1",
"body": "Welcome to Code Review! This is a good question, thank you for taking the time to form it so that we can help show you the proper coding styles and techniques. We all look forward... | [
{
"body": "<p><code>list1</code> is a bad variable name. What is it actually storing? I know that it is a list, but I don't know what it is being used for.</p>\n\n<p>It looks like this code is a snippet from a bigger block of code, but at least in this context, <code>list1</code> is never being read. You should... | {
"AcceptedAnswerId": "56465",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T14:35:48.233",
"Id": "56452",
"Score": "7",
"Tags": [
"python",
"datetime"
],
"Title": "Have I coded this small object grouping script Pythonically?"
} | 56452 |
<p>Is there a better way (I'm pretty sure there is) to create a stored procedure to do dynamic paging, filtering and sorting than the following code?</p>
<p>I'm actually generating this sproc from a database using a T4 template.</p>
<pre><code>CREATE PROCEDURE [uspProductWithPagingSortingFiltering]
(
-- Optional Filt... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T16:48:05.297",
"Id": "99443",
"Score": "0",
"body": "What is the primary key on `SalesLT.Product`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T16:51:09.983",
"Id": "99447",
"Score": "0",
... | [
{
"body": "<p>These are really the only local variables that you need</p>\n\n<pre><code>SET @lSortCol = LTRIM(RTRIM(@SortColumn))\n\nSET @lFirstRec = ( @lPageNbr - 1 ) * @lPageSize\nSET @lLastRec = ( @lPageNbr * @lPageSize + 1 )\nSET @lTotalRows = @lFirstRec - @lLastRec + 1\n</code></pre>\n\n<p>and you don't re... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T14:40:14.067",
"Id": "56453",
"Score": "8",
"Tags": [
"sql",
"sql-server",
"stored-procedure"
],
"Title": "Dynamically filtering, sorting, and paging using a stored procedure"
} | 56453 |
<p>I got sick and tired of writing certain functions over and over again, so I made a module that has those functions whenever I need them. I don't use it for code I plan on sharing, so I don't need to worry about portability. I do code in Python 2 and Python 3, so I used a bit of hackery to make it compatible with bot... | [] | [
{
"body": "<p>What you're looking for in your <code>cache</code> decorator is <a href=\"https://docs.python.org/2/library/functools.html#functools.wraps\" rel=\"nofollow\">functools.wraps</a>.</p>\n\n<p>Otherwise, very handy!</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"C... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T15:32:31.667",
"Id": "56458",
"Score": "2",
"Tags": [
"python",
"modules",
"primes"
],
"Title": "Custom module of common functions"
} | 56458 |
<p>Recently I have discovered one thing, which makes me feel frustrated. The Perl is lack of syntax sugar for strings, to do the same things, those are applicable to lists. The implementation I posted <a href="https://codereview.stackexchange.com/questions/56339/longest-common-substring-solution">here</a> would require... | [] | [
{
"body": "<ol>\n<li><p>No docstrings! What do your functions do and how do I call them?</p></li>\n<li><p>Your <code>lcss</code> function has a name that suggests it might return the <em>longest</em> common subsequence. But in fact it returns <em>all</em> common subsequences of length 3 or more (except for ones... | {
"AcceptedAnswerId": "56506",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T16:14:47.270",
"Id": "56464",
"Score": "7",
"Tags": [
"python",
"algorithm",
"strings"
],
"Title": "Longest Common Substring solution for a string and a list"
} | 56464 |
<p>I am working on an HTML5/jQuery todo list app and <a href="http://jsfiddle.net/rdesai/csTS7/19/" rel="nofollow">here</a> is my code so far.</p>
<p>As you might notice, there are some functions called at the beginning of the JS code. These functions work perfectly right now. Is it OK if I declare these functions in... | [] | [
{
"body": "<p>Not only would that be okay, but I'd actually recommend it. Defining the checkLocalStorageBrowserSupport, checkLocalStorageExistingData, addItem and tweakMinorUIStuff methods in the global scope is a bad idea in js. It's too easy for another js library to overwrite your methods in global scope, an... | {
"AcceptedAnswerId": "56469",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T16:35:14.800",
"Id": "56467",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"to-do-list"
],
"Title": "Should I declare all of the outer functions inside the object literal?"
... | 56467 |
<p>After posting <a href="https://codereview.stackexchange.com/questions/55735/job-queue-for-strategy-game">my previous question</a> about this Job Queue, I decided I wasn't actually very happy with it. I am embarrassed to admit that upon further testing it did not function properly in all situations. I received some... | [] | [
{
"body": "<p>A few things about this method bother me:</p>\n\n<pre><code>-(BOOL) chooseAnActiveJob {\n if (_jobQueue.count > 0 && _activeJob == nil) {\n _activeJob = [_jobQueue firstObject];\n [_jobQueue removeObjectAtIndex:0];\n return YES;\n } else {\n return NO;\... | {
"AcceptedAnswerId": "56516",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T17:48:47.503",
"Id": "56477",
"Score": "5",
"Tags": [
"object-oriented",
"game",
"objective-c",
"queue"
],
"Title": "Revised Job Queue for Strategy Game"
} | 56477 |
<p>Given two linkedlist, merge them. Looking for code review, optimizations and best practices.
The code is influenced by feedback <a href="https://codereview.stackexchange.com/questions/56287/given-a-two-dimensional-linked-list-create-a-flattened-sorted-list">here</a>.
Changes incorporated were:</p>
<ol>
<li>Linkedli... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T18:22:32.423",
"Id": "99468",
"Score": "0",
"body": "Please state more explicitly *what* you have changed. About the \"influenced by feedback here\", I see a number of things which you have *not* changed."
},
{
"ContentLicen... | [
{
"body": "<p>Wow! You've obviously put a lot of work into this! </p>\n\n<h1>Advice / Optimizations</h1>\n\n<ol>\n<li>Unless it's an explicit requirement of the assignment, there's no reason you can't use <code>java.util.LinkedList</code>.</li>\n<li>I think it's cleaner to have the <code>mergeLinkedLists</cod... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T18:04:07.293",
"Id": "56479",
"Score": "8",
"Tags": [
"java",
"linked-list",
"hashcode"
],
"Title": "Merge two linked list"
} | 56479 |
<p>Is there a faster way to get all primes between 0 - n?</p>
<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
namespace myPrime
{
public class simplePrimer
{
public List<BigInteger> primeList;
public void findVersio... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T19:38:34.077",
"Id": "99479",
"Score": "5",
"body": "You're going to want to find a non naïve prime algorithm. Check out this answer on Stackoverflow that will help you http://stackoverflow.com/questions/3220907/efficient-algorithm-... | [
{
"body": "<p>Leaving aside the algorithm there are a number of points about the code</p>\n\n<p><strong>Naming</strong><br/>\nPascal casing is standard for C# - <code>SimplePrimer</code> and <code>FindVersion</code> as opposed to <code>simplePrimer</code> and <code>findVersion</code>.<br/>\n<code>FindVersion</c... | {
"AcceptedAnswerId": "56496",
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T18:27:20.640",
"Id": "56480",
"Score": "4",
"Tags": [
"c#",
"primes"
],
"Title": "Getting all primes between 0 - n"
} | 56480 |
<p>I have seen various tweaks for quicksort and to establish their usefulness, I designed a program that randomly generates arrays and times how long quicksort takes to sort them. Right now I'm focusing on how the pivot is chosen. I'm comparing choosing the first element as the pivot versus choosing the median of first... | [] | [
{
"body": "<h2>Sorting the Three</h2>\n\n<p>You only need at most three swaps to sort the three elements:</p>\n\n<ul>\n<li>at most two swaps to place the smallest element into the first slot since it must be compared to the other two, and</li>\n<li>at most one swap to order the remaining two elements.</li>\n</u... | {
"AcceptedAnswerId": "56490",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T18:37:12.167",
"Id": "56481",
"Score": "10",
"Tags": [
"java",
"performance",
"sorting",
"quick-sort"
],
"Title": "Comparing pivot choosing methods in quicksort"
} | 56481 |
<p>I am aware of the fact that a sorted unidirectional list has only very few use cases, but nevertheless, this python code feels fairly long for Python code. How can I improve it?</p>
<pre><code>class List:
def __init__(self, list):
self.first = list
def __repr__(self):
element = self.first
... | [] | [
{
"body": "<p>For starters, you should read <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow noreferrer\"><strong>PEP 8, the Python style guide</strong></a>. A few things that jump out from your code:</p>\n\n<ul>\n<li>Variable names should be <code>lowercase_with_underscores</code>, not <c... | {
"AcceptedAnswerId": "56541",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T19:02:53.983",
"Id": "56482",
"Score": "7",
"Tags": [
"python",
"classes",
"python-3.x"
],
"Title": "Sorted unidirectional list with add, delete and find"
} | 56482 |
<p>I'm using multiple jQuery filter functions to affect the background color of select objects based on the selected option and it works, but it seems bulky/redundant. Does anyone know how these filter statements could be simplified/combined? I have a JSFiddle <a href="http://jsfiddle.net/Kn1ghtman/RDEeA/" rel="nofollo... | [] | [
{
"body": "<p>Because there's no context to your code, and it's difficult to understand what the purpose is, I couldn't do much besides refactor the code. I was hoping I would be able to suggest alternate methods to get the job done, but I didn't feel I had enough info.</p>\n<h2>JavaScript</h2>\n<p>I was able t... | {
"AcceptedAnswerId": "56491",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T19:14:21.383",
"Id": "56484",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"css"
],
"Title": "Conditional Branching Using Filter"
} | 56484 |
<p>I've written a decorator for easily creating <a href="http://en.wikipedia.org/wiki/Multiple_dispatch" rel="nofollow noreferrer">multiple dispatch</a> functions:</p>
<pre><code>from functools import wraps
def multi_dispatch(for_function):
"""
Returns a multiple dispatch version of the function.
The ret... | [] | [
{
"body": "<ol>\n<li><p>You have a docstring and some doctests, which is great! The docstring needs some work, though, as described below.</p></li>\n<li><p>The docstring needs to mention that the returned function has an <code>add</code> method, and explain what this method does.</p></li>\n<li><p>The docstring ... | {
"AcceptedAnswerId": "56543",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T19:18:35.257",
"Id": "56485",
"Score": "12",
"Tags": [
"python",
"python-3.x"
],
"Title": "Multiple dispatch decorator in Python"
} | 56485 |
<p>I'm much more fluent in JS, but I needed to sort a lot of dates, ages, genders, etc. from a tab-delimited text file so I wrote this. Could I get some tips on how to make this more efficient and more Pythonic? The more Python I write the more I like it, but I <em>definitely</em> need some help.</p>
<p>One thing I no... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T09:10:59.520",
"Id": "99612",
"Score": "1",
"body": "Are you sure your code works as shown? For example, you are calling `getCities()` which returns a list, without assigning it anywhere. In `sortLists` you seem to do `str(getCities... | [
{
"body": "<p>Things I would have done (some minor) -</p>\n\n<ul>\n<li><p>I would order the imports alphabetically. (not a huge deal)</p></li>\n<li><p>You have a lot of \"with open\" statements in your code. I would have put this in a function. (again minor) i.e.</p>\n\n<pre><code># Formatting your strings like... | {
"AcceptedAnswerId": "56568",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T19:27:53.217",
"Id": "56486",
"Score": "5",
"Tags": [
"python",
"performance",
"memory-management",
"csv"
],
"Title": "CSV demographics analyzer seems to waste memory/move ... | 56486 |
<p>I'm working on a proxy service that will run on top of a Java application in order to manipulate some headers. I've just completed the first step and that is intercepting the request message and storing them.</p>
<p>This code features only the storage part, and not the edit and send part.</p>
<p>Some information a... | [] | [
{
"body": "<h1>socketToMessages()</h1>\n\n<p>There are a number of things in here to report:</p>\n\n<ol>\n<li><p>there is no need for the labelled loop <code>listeningLoop</code>. Th places you use the label, you have <code>break listeningLoop;</code>, and those can simply be replaced with <code>return</code>.<... | {
"AcceptedAnswerId": "56502",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T19:56:31.790",
"Id": "56487",
"Score": "10",
"Tags": [
"java",
"http"
],
"Title": "HTTP request reader"
} | 56487 |
<p>I have a class that I use to represent a distance called <code>Dimension</code>.</p>
<p>Here is its four constructors:</p>
<pre><code> /// <summary>
/// Accepts any valid architectural string value for input.
/// </summary>
public Dimension(string passedArchitecturalString)
{
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T22:35:19.480",
"Id": "99517",
"Score": "0",
"body": "Your question is pretty much ok but next time please try to include more code about what you are really trying to achieve. In this question you wanted to compare two Dimensions an... | [
{
"body": "<p>The concept/pattern that you are trying to apply to <code>DimensionGenerator</code> is actually a factory.\nYou can approach this problem in two major ways, the factory which is what you were trying to do and by subclassing.</p>\n\n<p>To make the factory pattern correct your dimension class must n... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T20:51:44.520",
"Id": "56497",
"Score": "4",
"Tags": [
"c#",
"static",
"factory-method"
],
"Title": "Code for simplifying the creation of Dimension Objects"
} | 56497 |
<p>I have been unable to find any other way to update a user config file than the following method. </p>
<pre><code>public class SettingServices : ISettingServices
{
public UserSetting GetUserSetting()
{
XmlSerializer reader = new XmlSerializer(typeof(UserSetting));
StreamReader file = new Stre... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T05:45:43.090",
"Id": "99582",
"Score": "0",
"body": "What are you trying to achieve? Why do you want to update the file?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T13:50:39.393",
"Id": "99646... | [
{
"body": "<blockquote>\n <p>Preferably I'd like to just be able to update that node in the XML file without having to rewrite the whole file every time a change is made.</p>\n</blockquote>\n\n<p>In general, that's simply not possible, because XML is a text-based format.</p>\n\n<p>Imagine you have the followin... | {
"AcceptedAnswerId": "57201",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T21:08:01.603",
"Id": "56498",
"Score": "2",
"Tags": [
"c#",
"xml",
"winforms",
"serialization"
],
"Title": "Updating XML config files"
} | 56498 |
<p>I would like a complete threshing of this code so that I can see what I did wrong and what I am using incorrectly.</p>
<p>I made this super simple, trying to learn a little bit about <code>List<T></code> while I was doing this. I have never actually tried to do this before, so I thought it would be a good le... | [] | [
{
"body": "<p>One note: You create extra work and time for the program by including all of the even numbers in the initial List creation.</p>\n\n<p>You can do something similar to this to eliminate the even numbers:</p>\n\n<pre><code>var upperLimit = 9999;\nList<Int64> primes = new List<Int64>(); ... | {
"AcceptedAnswerId": "56505",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T21:11:57.660",
"Id": "56500",
"Score": "6",
"Tags": [
"c#",
"algorithm",
"primes",
"sieve-of-eratosthenes"
],
"Title": "Threshing: Sieve of Eratosthenes"
} | 56500 |
<p>I tried writing alternative functions to Java's <code>BigInteger.add(BigInteger.ONE)</code>, <code>BigInteger.add(BigInteger)</code>, and <code>BigInteger.subtract(BigInteger)</code>:</p>
<pre><code> public static BigInteger increment(BigInteger x)
{
int i=0;
while(x.testBit(i))
x=x.clearBit(i++);
x=x.set... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T23:34:33.977",
"Id": "99533",
"Score": "2",
"body": "Or perhps it is because your add algorithm is naive and you shouldn't re-event the wheel, especially if it is a strong, tested refined and well thought one"
},
{
"ContentL... | [
{
"body": "<p>Your question comes in multiple parts: General code review, adding algorithms, and then performance relative to standard <code>BigInteger</code></p>\n\n<h2>General Review</h2>\n\n<p>Let's focus on this method, it shows essentially all the general issues I see:</p>\n\n<blockquote>\n<pre><code> publ... | {
"AcceptedAnswerId": null,
"CommentCount": "12",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T23:21:49.943",
"Id": "56512",
"Score": "6",
"Tags": [
"java",
"optimization",
"algorithm",
"bitwise",
"integer"
],
"Title": "Why are these functions slower than BigIntege... | 56512 |
<p>My goal is to create a memory-efficient (immutable) collection of strings. The imagined use-case is checking for valid words in a Scrabble-like game.</p>
<p><a href="http://commons.wikimedia.org/wiki/File:Trie-vs-minimal-acyclic-fa.svg" rel="nofollow noreferrer">Wikimedia Commons</a> has a pretty good summary of th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T23:52:13.680",
"Id": "99542",
"Score": "1",
"body": "I find a `Collection` suffix is a bit misleading. Client code may rightfully be expecting `ICollection` members. Also I'd throw an `ArgumentNullException` instead of an `ArgumentE... | [
{
"body": "<blockquote>\n<h2>StringCollection</h2>\n</blockquote>\n<h3>Naming</h3>\n<p><code>StringCollection</code> is, as I pointed out in the comments, a misleading name that suggests your type is implementing <code>ICollection<T></code>. A better name is pretty hard to find though, since <code>Enumera... | {
"AcceptedAnswerId": "57306",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T23:32:52.813",
"Id": "56514",
"Score": "12",
"Tags": [
"c#",
"strings"
],
"Title": "Memory-efficient string collection"
} | 56514 |
<p>An implementation of the singleton pattern in PHP using a trait (added in 5.4). Is there anything missing, any ways to create a second copy of the class?</p>
<pre><code>trait Singleton {
static function instance() {
static $instance;
if ( is_null( $instance ) ) {
$instance = new stat... | [] | [
{
"body": "<h2>Contract Enforcement</h2>\n\n<p>There are a few ways to violate the singleton contract, but none need to be guarded against. </p>\n\n<ol>\n<li>Create a subclass with a public constructor. This obviously is pilot error. </li>\n<li>Use reflection to either make the constructor accessible (5.3.2) or... | {
"AcceptedAnswerId": "56523",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T01:36:04.400",
"Id": "56520",
"Score": "2",
"Tags": [
"php",
"php5",
"singleton",
"trait"
],
"Title": "PHP Trait Singleton"
} | 56520 |
<p>Given a list of objects, return an iterator for such a list. Looking for code-review, optimizations and best practices. Verifying complexity to be O(n) where n is sum of all objects, including elements of collections if contained. previously solved <a href="https://codereview.stackexchange.com/questions/32827/flatte... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T02:19:36.243",
"Id": "99568",
"Score": "2",
"body": "I so want this to be named `Flatterator`!"
}
] | [
{
"body": "<p>I'm going to hit the high notes on my phone and swing back later with details unless someone beats me to it. </p>\n\n<h2>Allow <code>null</code></h2>\n\n<p>Add a separate boolean field to track when <code>next</code> holds the actual next element rather than using <code>null</code> as a signal tha... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T01:48:15.480",
"Id": "56521",
"Score": "5",
"Tags": [
"java",
"reinventing-the-wheel",
"iterator"
],
"Title": "Iterator for a list of objects"
} | 56521 |
<p>I'm working on wrapping the <a href="http://www.last.fm/api/show/album.search" rel="nofollow">last.fm web API</a>. I'm trying to use Interfaces to be able to easily make calls via functions which return an interface (as opposed to an object which would need to be free'd). I believe I have the fundamentals down, but ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T02:53:59.630",
"Id": "99570",
"Score": "0",
"body": "PS - is there some standard terminology behind this method of using interfaces?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-11-20T23:18:29.250",
... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T02:08:42.533",
"Id": "56522",
"Score": "1",
"Tags": [
"api",
"interface",
"delphi"
],
"Title": "Is this interface structure/setup correct?"
} | 56522 |
<p>It's known that if you naively sum up a collection of arbitrary floating-point numbers using any floating-point standard (e.g. <code>float</code>s or <code>double</code>s with the C standard), the end result may differ, sometimes significantly, from the actual sum. This is due to the loss of precision involved in ap... | [] | [
{
"body": "<p>Two small notes:</p>\n\n<ol>\n<li>You should use constructor chaining for maintenance reason.</li>\n<li><p>You should integrate a null check inside your overloaded constructor</p>\n\n<pre><code>public StableSummer(StableSummer m):this()\n{\n if (m != null)\n {\n partials.AddRange(m.pa... | {
"AcceptedAnswerId": "56540",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T03:30:52.277",
"Id": "56526",
"Score": "8",
"Tags": [
"c#",
"floating-point"
],
"Title": "Numerically stable sum of `double`s"
} | 56526 |
<p>I started to refactor my app to MVC today. I wasted a lot of time because of simple mistakes.</p>
<p>One was I kept trying to access the getter method inside of my custom getter method, which just causes and endless loop of gets.</p>
<p>Even when I figured it out, I repeated this mistake several times. I think it'... | [] | [
{
"body": "<pre><code>if (_phoneNumbers) {\n [_phoneNumbers removeAllObjects];\n}\n\nif (!_phoneNumbers) {\n //Create _phoneNumbers array\n _phoneNumbers = [[NSMutableArray alloc]init];\n}\n</code></pre>\n\n<p>Instead of this, we can replace all these lines with simply:</p>\n\n<pre><code>_phoneNumbers ... | {
"AcceptedAnswerId": "56604",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T03:37:26.543",
"Id": "56527",
"Score": "2",
"Tags": [
"mvc",
"objective-c",
"ios"
],
"Title": "Very small start to MVC refactor in iOS app"
} | 56527 |
<p>This is a Graphical Timer control I made for C# Winforms, which taught me quite a bit (it is my first Custom Control). The code below is a fully working application with the Graphical Timer, some buttons to control it, and a listbox showing the sweeping angle of the pie (for debugging purposes). Being my first contr... | [] | [
{
"body": "<p>Some comments:</p>\n\n<p>I would recommend making sure that the base constructor is called:</p>\n\n<pre><code>public GraphicalTimer()\n : base()\n{\n ...\n}\n</code></pre>\n\n<p>I would recommend doing the following in your <code>OnTimeout</code> method:</p>\n\n<pre><code>protected virtual v... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T03:53:54.190",
"Id": "56528",
"Score": "3",
"Tags": [
"c#",
"winforms",
"timer"
],
"Title": "Winforms Graphical Timer Control"
} | 56528 |
<p>Okay - so basically I have a login form that has a couple of 'states' it needs to display (connecting, input credentials, authenticating, invalid credentials, etc...etc...) - in the past I've literally tossed my views into my DI container and bound a ContentControl to a property on my ViewModel that holds a referenc... | [] | [
{
"body": "<p>Yes it could be made a bit more simple. If you would use three views for your state it might make sense to template these views and bind the templates according to the state MyViewModel publishes.</p>\n\n<p>The State would no longer only indicate the a simple state (value) but would become a type ... | {
"AcceptedAnswerId": "56544",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T04:14:21.930",
"Id": "56529",
"Score": "2",
"Tags": [
"c#",
"wpf",
"mvvm",
"xaml"
],
"Title": "ViewStateManager for more than just Controls?"
} | 56529 |
<p>During the hiring process, a company gave me this test:</p>
<blockquote>
<p>Q) Consider Share prices for a N number of companies given for each month since year 1990 in a CSV file. Format of the file is as below with first line as header.</p>
<pre class="lang-none prettyprint-override"><code>Year,Month,Company... | [] | [
{
"body": "<h2>Meeting the specifications</h2>\n\n<p>The specifications said to accept a CSV file, so your test data should be comma-delimited, not space-delimited. In practice, it's not a big deal, but if you're answering an interview question, don't deviate from the instructions unless you can justify it wit... | {
"AcceptedAnswerId": "56536",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T05:47:20.063",
"Id": "56531",
"Score": "12",
"Tags": [
"python",
"interview-questions",
"csv"
],
"Title": "Find the peak stock price for each company from CSV data"
} | 56531 |
<p>Inspired by another question, I decided to implement <a href="http://en.wikipedia.org/wiki/Kahan_summation_algorithm" rel="nofollow">Kahan summation</a> in C++ (though that question implemented a different summation algorithm).</p>
<p>Since I was writing C++, I decided to make the code generic. Although it's a litt... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T09:27:29.467",
"Id": "99613",
"Score": "0",
"body": "Your implementation looks sound, but there is no guarantee it is portable. If you are only targeting one compiler, there may be command-line switches available to ensure the optim... | [
{
"body": "<p>I've taken the liberty of freely using C++11 in my answer because about half of the improvements I propose require it. </p>\n\n<h2>An instrumentation class</h2>\n\n<p>I decided to do a little instrumentation to see how this template would do with an artificial type so I created my own <code>Goofy... | {
"AcceptedAnswerId": "56592",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T05:51:37.953",
"Id": "56532",
"Score": "12",
"Tags": [
"c++",
"floating-point"
],
"Title": "Kahan summation"
} | 56532 |
<p>We start with an empty queue. For the push operation we simply insert the value to be pushed into the queue.</p>
<p>The pop operation needs some manipulation. When we need to pop from the stack (simulated with a queue), first we get the number of elements in the queue, say n, and remove (n-1) elements from the queu... | [] | [
{
"body": "<p>Seems awfully convoluted to me. Is there a particular reason you're implementing your stack as a queue? A stack can be as simple as this:</p>\n\n<pre><code>typedef struct _stack_t\n{\n int * top; /* Top Of Stack (TOS) pointer */\n size_t used; /* number of items on stack ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T08:44:51.210",
"Id": "56538",
"Score": "5",
"Tags": [
"optimization",
"performance",
"c",
"queue",
"stack"
],
"Title": "Stack implementation using only one queue in C"
} | 56538 |
<pre><code>#include<stdio.h>
int main(){
int numberGiven,num=2,i=0,stack[100] = {0},top=-1;
// get the number from user
printf("Enter the number : ");
scanf("%d",&numberGiven);
while(numberGiven >= num){
// check for prime-ness of number
for(i=num/2;i>1;i--){
... | [] | [
{
"body": "<p>There are several functions that I would have factored out to make the code more clear:</p>\n\n<pre><code>bool isFactorOf(int possibleFactor, int number) {\n return number % possibleFactor == 0;\n}\n\nbool isPrime(int number) {\n int i;\n int max = ceil(sqrt(num));\n for(i = 2; i <=... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T10:42:38.727",
"Id": "56542",
"Score": "5",
"Tags": [
"optimization",
"performance",
"c",
"primes"
],
"Title": "Prime factor in reverse order"
} | 56542 |
<p>This is a part of my <a href="https://codereview.stackexchange.com/questions/54737/analyzing-minesweeper-probabilities">Minesweeper analyzer code</a> that didn't fit into the last question.</p>
<p>This code uses <code>FieldGroup</code> which <code>extends ArrayList</code> because I am using some more data than just... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T14:01:29.663",
"Id": "99651",
"Score": "0",
"body": "How large are typical and extreme input FieldGroup sets? 10 members, 5 members? thousands of members?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-... | [
{
"body": "<p>Just a few quick minor notes:</p>\n\n<ol>\n<li><p>This comment:</p>\n\n<blockquote>\n<pre><code>// Check if ALL fields are in common\nif (onlyA.isEmpty() && onlyB.isEmpty()) {\n</code></pre>\n</blockquote>\n\n<p>could be replaced with an explanatory local variable:</p>\n\n<pre><code>boolea... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-07-09T11:29:31.523",
"Id": "56545",
"Score": "11",
"Tags": [
"java",
"collections"
],
"Title": "Splitting two lists into OnlyA, Both, and OnlyB"
} | 56545 |
<p>I have made a method which returns a list of all songs on my device. Now I want to get a list of albums out of these songs.</p>
<p>What I basically do is go through every song I have in my list, check if its album is already in the list and if not I create a new album. </p>
<p>This method will take some time since... | [] | [
{
"body": "<p>What you need is a <code>Map</code>. A map is a collection of key --> value combinations. There can not be two equal keys pointing to different values.</p>\n\n<p>There are a few ways to organize this map. The simplest is to make <code>Map<String, Album> albumNames;</code>, but that would mak... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T11:46:48.837",
"Id": "56548",
"Score": "10",
"Tags": [
"java",
"android"
],
"Title": "Create albums out of songs"
} | 56548 |
<p>For a data warehousing project I ran into the following:</p>
<p>Custom fields that users can create, modify and delete, that should be loaded into the data warehouse as they are when the ETL happens.</p>
<p>On the profiling part of the area in the database that holds this data I discovered that theses fields are n... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T12:21:54.720",
"Id": "99624",
"Score": "0",
"body": "I think you're right to question the use of cursors. Thank you for including the table definitions. Great first question! Welcome to CR! Feel free to drop by [chat and meet the re... | [
{
"body": "<p>I noticed that you have a Select nested inside of a select twice, which looks kind of ugly...</p>\n\n<blockquote>\n<pre><code> DECLARE @maxcols AS NVARCHAR(MAX) = STUFF((\n SELECT DISTINCT ',MAX(' + QUOTENAME(v.field_name) + ') AS ' + QUOTENAME(v.field_name)\n FROM (\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T12:12:03.070",
"Id": "56551",
"Score": "11",
"Tags": [
"sql",
"sql-server",
"dynamic-programming"
],
"Title": "Loading Data Warehouse with Dynamic SQL"
} | 56551 |
<p>This is a script which takes an Amazon URL as input, takes out ASIN/ISBN from the URL, and uses <a href="http://github.com/yoavaviram/python-amazon-simple-product-api">Amazon Python API</a> to fetch details. </p>
<p>For this task, I looked at many Amazon URLs and observed the following things:</p>
<ol>
<li>ASIN/IS... | [] | [
{
"body": "<p>This should be a short review mainly because your code looks pretty nice. </p>\n\n<p>I don't have any experience with the Amazon API, but from what I can tell you are using it as I would expect it to be used.</p>\n\n<p>The only points that I want to speak on and can nit-pick are:</p>\n\n<ol>\n<li>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T12:15:31.890",
"Id": "56554",
"Score": "10",
"Tags": [
"python",
"parsing"
],
"Title": "Python script which fetches Amazon product details using its API"
} | 56554 |
<p><a href="http://jsfiddle.net/spadez/kx4w7/" rel="nofollow">This is my code</a></p>
<pre><code><ul id="filter">
<li><a href="#" class="dropdown">Any status &#9662;</a>
<form>
<ul class="opt">
<li>
<input clas... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T20:12:40.823",
"Id": "99630",
"Score": "3",
"body": "I don't see any problems. Most menus, including famous twitter-bootstrap one, use lists, since the markup is quite clean. Yes, you do have to clean up lists and remove bullets and... | [
{
"body": "<p>Since you are using it as a controller, you should use <code>datalist</code>, and since those anchors go nowhere, you should use another element.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T19:2... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T19:49:07.303",
"Id": "56556",
"Score": "2",
"Tags": [
"html",
"css"
],
"Title": "More correct way to avoid using a list for dropdown"
} | 56556 |
<p>As a beginner in Ruby, I am trying to optimize this script that is a client side pre-commit hook for git.</p>
<p>Was hoping I could get a review to ensure I am following all ruby idioms, and to ensure I have the most elegant solution.</p>
<pre><code>#!/usr/bin/env ruby
#
# Pre-commit hook created to help ensure dn... | [] | [
{
"body": "<p>Some notes:</p>\n\n<ul>\n<li><p><code>zone_files.keys.each</code> and then <code>zone_files[key]</code>. You should iterate the pair: <code>zone_files.each do |key, zone|</code></p></li>\n<li><p><code>current_branch = %x{git branch}.match(/\\* (.+?)\\n/m)</code>. Isn't this inmutable? then better ... | {
"AcceptedAnswerId": "56584",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T13:01:41.663",
"Id": "56557",
"Score": "11",
"Tags": [
"beginner",
"ruby",
"git"
],
"Title": "Git pre-commit hook to check that changes to certain files only happen on the mast... | 56557 |
<p>As you will see, I am not very familiar with Python and NumPy but want to learn it.</p>
<p>The following code is a very basic Sudoku solver which works fine for simple examples. Although it runs, I still have the feeling it is not very Pythonic. </p>
<pre><code>from numpy import *
import sys
def set(col,row,wert)... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T18:17:04.143",
"Id": "99724",
"Score": "1",
"body": "Why don't you check out [Peter Norvig's famous Sudoku Solver](http://norvig.com/sudoku.html) written in Python for inspiration? The implementation is very Pythonic and is interes... | [
{
"body": "<p>I noticed a few suspicious problems with your coding style. There's plenty to talk about even without analyzing the sudoku solver portion of your program.</p>\n\n<p>Your functions are actually more like procedures that act on <strong>global variables</strong>. For example, your <code>read()</cod... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T13:08:35.860",
"Id": "56558",
"Score": "5",
"Tags": [
"python",
"python-3.x",
"numpy",
"sudoku"
],
"Title": "Hints to make Sudoku solver more Pythonic"
} | 56558 |
<p>To calculate torque I need to look up a value from a table which I've hardcoded based on three conditions: grade, size, and thread. Then I need to multiply it by coefficients associated with the selected lubricants.</p>
<p>I've written the code to be a web-app, but it will also just run as an html file sitting on a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T16:46:52.873",
"Id": "99693",
"Score": "0",
"body": "I'm a little surprised that I can select multiple types of grease at once. I wouldn't expect to be able to do that as a user."
},
{
"ContentLicense": "CC BY-SA 3.0",
"... | [
{
"body": "<p>A few things caught my eye here.</p>\n\n<p>Firstly, since you need to store all the data in the files (which, I agree, is the best way to go about this, given the constraints) why not store <em>all</em> the data there? By which I mean build the lubricant list and grades in JS too. Or flip it aroun... | {
"AcceptedAnswerId": "56598",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T16:41:24.490",
"Id": "56573",
"Score": "10",
"Tags": [
"javascript",
"beginner",
"html"
],
"Title": "Calculate torque of a bolt based on grade, size, and lubricant"
} | 56573 |
<p>Given an iterator of iterators, return all of the elements from the iterators in order. Looking for code review, optimizations, and best practices. Verifying complexity to be \$O(n)\$, where \$n\$ is the total number of elements from all iterators.</p>
<pre><code>public class IteratorOfIterator implements Iterator&... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T17:50:44.723",
"Id": "99704",
"Score": "3",
"body": "[`Iterators.concat` from Guava](http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/Iterators.html#concat%28java.util.Iterator...%29)"
}
] | [
{
"body": "<p>I don't see any reason to limit this to <code>Integer</code>s. The solution can be trivially genericized.</p>\n\n<p><code>IteratorOfIterator</code> is a clumsy name. By analogy with Python's <a href=\"https://docs.python.org/2/library/itertools.html#itertools.chain\"><code>itertools.chain()</cod... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T17:25:13.230",
"Id": "56575",
"Score": "7",
"Tags": [
"java",
"algorithm",
"iterator"
],
"Title": "Iterator of iterator"
} | 56575 |
<p>I am learning PySide and am trying to implement widgets within a main window. My goal right now is very simple: I want to place a <code>QLabel</code>, with independently defined event handling, inside a main window that has its own event handling: </p>
<pre><code># -*- coding: utf-8 -*-
from PySide import QtGui, Qt... | [] | [
{
"body": "<p>While there is no hard and fast rule, it seems to make code more readable and modular (i.e., Pythonic) to have a separate class for something that is effectively a new Qt widget. This is especially true if there is any chance that new widget might be something you want to break out and use in anot... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T18:31:33.417",
"Id": "56582",
"Score": "4",
"Tags": [
"python",
"gui",
"pyqt",
"pyside"
],
"Title": "Implementing widgets within a main window"
} | 56582 |
<p>I am trying to refactor these three methods into one:</p>
<pre><code> public StatusReturn UpdateProperty(int id, int onlineReportId)
{
//Yes I realize I should not be using ref variables but the queryPermissions is an external dll.
var webQueryInputProperty = new WebQueryInputProperty();
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T19:09:28.977",
"Id": "99725",
"Score": "3",
"body": "Please do not recreate the [refactoring] tag. We have had it removed because Code Review questions already involve refactoring."
}
] | [
{
"body": "<blockquote>\n<p><em>I am trying to refactor these three methods into one</em></p>\n</blockquote>\n<p>That would be, uh, <em>de-factoring</em>. I don't know of any <em>merge methods</em> refactoring - when people refactor code, they tend to <em>extract</em> functionality so as to have <strong>more me... | {
"AcceptedAnswerId": "56620",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T18:37:39.753",
"Id": "56583",
"Score": "8",
"Tags": [
"c#"
],
"Title": "Refactoring three property methods"
} | 56583 |
<p>I am solving <a href="http://www.spoj.com/problems/ROCK/" rel="nofollow">ROCK</a> problem on SPOJ. I have used bottom up dynamic programming approach for this problem. Time complexity for this is \$O(n^3)\$.</p>
<pre><code>#include<stdio.h>
#include<string.h>
#include<math.h>
#define MAX 210
#defi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T19:45:39.067",
"Id": "99735",
"Score": "1",
"body": "The constraints scream \\$O(n^3)\\$, so I would look into potential constant optimizations."
}
] | [
{
"body": "<p>The way you call <code>sellable</code> may amount to a 4-th degree complexity. The very smart compiler may notice that it is a pure function, and optimize it out of the inner loop, but I wouldn't rely on it. So, one obvious optimization is to rephrase it as</p>\n\n<pre><code>if (sellable(a, i, j))... | {
"AcceptedAnswerId": "56616",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T19:00:03.917",
"Id": "56587",
"Score": "4",
"Tags": [
"optimization",
"algorithm",
"c",
"programming-challenge"
],
"Title": "SPOJ is giving TLE for this solution of ROCK"
} | 56587 |
<p>I am working on a class library in C# to convert <code>WKT</code> to <code>GeoJson</code>. I am getting shapes in WKT out of MSSQL. A lot of the shapes that come out of SQL have a lot of points. I am concerned that even though what I have is working on the much smaller shapes I am using for testing, that it will ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T03:46:02.307",
"Id": "99774",
"Score": "2",
"body": "`\"catastroiphic [sic] failure\"` isn't a very meaningful/informative message to display when a `coordinatesArray`'s length is different than 2. Perhaps `\"Coordinates are expecte... | [
{
"body": "<p>The <code>ConvertGeometryType</code> function could be rewritten a little bit. Instead of breaking from the switch and returning <code>value</code>, you could directly return and use a default case to make sure you get an empty string if none of the cases matched. </p>\n\n<pre><code>switch (Geomet... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T19:28:18.750",
"Id": "56591",
"Score": "11",
"Tags": [
"c#",
"performance",
"regex",
"converting"
],
"Title": "Convert WKT representations of geometries into GeoJson"
} | 56591 |
<p>I took a little bit from all the answers to my previous question <a href="https://codereview.stackexchange.com/questions/56500/threshing-sieve-of-eratosthenes">Threshing: Sieve of Eratosthenes</a>.</p>
<hr>
<p>This may be bordering on code-golfing, but I think that I have a pretty good piece of code here.</p>
<p>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T23:02:47.317",
"Id": "99756",
"Score": "0",
"body": "Have you considered using `uint` instead of `long` and setting the upper limit to something dumb like `uint.MaxValue`? The `for` loops would also need to be `uint`s. You should al... | [
{
"body": "<p><code>List<T></code> is probably not the fastest data structure. A linked list would actually be perfect here. Each item keeps track of the prime after it.</p>\n\n<pre><code>Node head = new Node(1);\nNode current = head.next = new Node(2);\ncurrent = current.next = new Node(3);\n</code></pre... | {
"AcceptedAnswerId": "56625",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T20:19:04.813",
"Id": "56597",
"Score": "11",
"Tags": [
"c#",
"algorithm",
"primes",
"sieve-of-eratosthenes"
],
"Title": "Threshed and Malachi'd: Sieve of Eratosthenes"
} | 56597 |
<p>I'm brand new to programming (in general) and C++ (in particular). I'm learning the basics of classes and objects.</p>
<p>I'm trying to do the following: </p>
<ol>
<li><p>Create a class called <code>X</code>. It has 4 member functions, with 0 arguments, 1 argument, 2 arguments and 3 arguments, respectively.</p>... | [] | [
{
"body": "<p>First of all, you should avoid \"getters\" and \"setters\" whenever possible. This is because they can be bad for encapsulation as they reveal the internal members. This would be an ideal example if you were merely trying to understand getters and setters, but it's still not the best approach to... | {
"AcceptedAnswerId": "56600",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T20:54:47.690",
"Id": "56599",
"Score": "7",
"Tags": [
"c++",
"beginner",
"classes"
],
"Title": "Creating C++ classes and objects"
} | 56599 |
<p>If we have a set of <code>class</code>es or <code>struct</code>s such as:</p>
<pre><code>struct Point
{
float x;
float y;
};
struct Square
{
Point topLeft;
float width;
};
struct Circle
{
float radius;
Point middle;
};
</code></pre>
<p>If we need to add some functionality to to these, doe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T23:16:37.077",
"Id": "99757",
"Score": "2",
"body": "If you want your code to read like English, try [tag:Objective-C]. ;) I'm not sure how well accepted this would be in the C++ community, but we definitely strive for verbose cod... | [
{
"body": "<p>It reads like a mandate, and not necessarily a sentence which makes this point trivial.</p>\n\n<p>Notice how all are English:</p>\n\n<blockquote>\n <p>Run this code!</p>\n \n <p>The code ran</p>\n \n <p>The code is running</p>\n</blockquote>\n\n<p>This design doesn't let you define movement i... | {
"AcceptedAnswerId": "56623",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-09T23:11:36.150",
"Id": "56606",
"Score": "15",
"Tags": [
"c++",
"object-oriented",
"c++11"
],
"Title": "Classes for sentence-like readability"
} | 56606 |
<p>I have links like <code><a href="http://www.example.org" target="_system">foo</a></code> that are supposed to open in Safari (from phonegap), so globally I did this:</p>
<pre><code>$(document).on("a[target=_system]", function(e) {
e.preventDefault();
window.open($(this).attr("href"), '_system');
});... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-06-11T23:03:37.447",
"Id": "169804",
"Score": "1",
"body": "Well, do you have a good use for adding a global listener? If so, I see nothing wrong with it."
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T08:28:22.280",
"Id": "56630",
"Score": "1",
"Tags": [
"javascript",
"ember.js"
],
"Title": "Overriding global click behavior"
} | 56630 |
<p>I'm currently trying to make the code of an app I'm developing a bit more efficient and easier to read. Basically what this does is after the user taps with two fingers (gesture) it retrieves a previously saved array from <code>NSUserDefaults</code> of player names, and fills in the 6 text boxes (tagged 6-11) on a t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T13:00:04.990",
"Id": "100820",
"Score": "0",
"body": "@Jamal: I'm not sure your modified title is an improvement in this case. The original title made it clear that the OP was worried about the `if` structure of the code. That poin... | [
{
"body": "<p>We can do better still.</p>\n\n<p>First of all, we're talking about a <code>UITableViewCell</code> to which you've added custom views--or at least modified existing views (hence the tags) as well as adding a gesture recognizer.</p>\n\n<p>What makes most sense is to instead subclass <code>UITableVi... | {
"AcceptedAnswerId": "56639",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T08:50:55.367",
"Id": "56632",
"Score": "5",
"Tags": [
"objective-c"
],
"Title": "Filling text boxes with player names received from an array"
} | 56632 |
<p>I have this function which parses Beautiful Soup elements:</p>
<pre><code>def get_info():
holder = []
problem_dict = {}
selection_container = []
for moselect in base_page.find_all('div', attrs={'class': 'Moselect'}):
if moselect.find('div', attrs={'id': 'noSize'}):
holder.append(... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T11:52:03.110",
"Id": "100803",
"Score": "0",
"body": "Could you provide some more information about what this function is supposed to do? Possibly give a some example input and what you expect to be output?"
},
{
"ContentLic... | [
{
"body": "<p>There are a couple things in this method that can be refactored to remove a lot of duplicate code:</p>\n\n<ol>\n<li><p>Firstly, you have this if statement:</p>\n\n<pre><code>if held_item.find_all('option')[1:]:\n ...\nelse:\n ...\n</code></pre>\n\n<p>What this is really checking for is if th... | {
"AcceptedAnswerId": "56648",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T09:08:25.103",
"Id": "56634",
"Score": "2",
"Tags": [
"python",
"performance",
"parsing",
"beautifulsoup"
],
"Title": "Optimizing Beautiful Soup elements"
} | 56634 |
<p>Background: I have 4 GB of text data dispersed in 250,000 html files. I want to interlink the files with <code><a></code> for the reader to click on. I have a 12 MB file of regex patterns to identify the <code><a></code> sites.</p>
<p>Situation: I have developed a working proof of concept, three files:<... | [] | [
{
"body": "<p>If it does run in 24 hours then that might well be the best way to do it. The only way I could think of speeding it up would be to build some kind of index (using xsl:key) of the words that appear in the links, and then pre-filtering each text node to see whether any of its words are present in th... | {
"AcceptedAnswerId": "56682",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T09:44:35.513",
"Id": "56635",
"Score": "4",
"Tags": [
"html",
"parsing",
"xslt"
],
"Title": "XSLT 2.0: Crawl HTML and add links"
} | 56635 |
<p>I'm currently learning how to use <a href="https://spark.apache.org">Apache Spark</a>. In order to do so, I implemented a simple wordcount (not really original, I know). There already exists an example on the documentation providing the needed code. However, I tried to go one step further and to produce the result a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T12:07:52.023",
"Id": "100808",
"Score": "0",
"body": "Are you using Java 6, 7, 8 or something else? I see explicit type parameter names, regular code and lambdas, what is exactly going on?"
},
{
"ContentLicense": "CC BY-SA 3... | [
{
"body": "<p>I'll review this code with keeping in mind that you want to leave Apache Spark intact, as you intend to use it in the future for purposes it is intended to do.<br>\nI strongly believe that your current code can be written in pure Java 8, though that is not the point of the question.</p>\n\n<h3>Use... | {
"AcceptedAnswerId": "56642",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T12:04:46.510",
"Id": "56641",
"Score": "11",
"Tags": [
"java",
"performance",
"java-8",
"apache-spark"
],
"Title": "Producing a sorted wordcount with Spark"
} | 56641 |
<p>I have a list of lists which represents the options I can chose from.</p>
<p>I have a sequence of indices which represent which option lists I want to take elements from, and in which order.</p>
<p>E.g. if I have</p>
<pre><code>choices = [
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ]
]
sequence = [ 2, 0, 1,... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T14:08:15.927",
"Id": "100840",
"Score": "0",
"body": "Per [the style guide](http://legacy.python.org/dev/peps/pep-0008/#pet-peeves), consider removing the extraneous whitespace inside brackets."
},
{
"ContentLicense": "CC BY... | [
{
"body": "<p>I find neither of your solutions very pythonic. </p>\n\n<p>Using sum to concatenate lists seems like a hack.</p>\n\n<p>Using reduce looks better but still has the problem of making the selection too verbose to read it fast.</p>\n\n<p>The last one is far too much. Understanding what it does takes w... | {
"AcceptedAnswerId": "56654",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T14:02:32.443",
"Id": "56650",
"Score": "15",
"Tags": [
"python",
"performance"
],
"Title": "Most pythonic way to combine elements of arbitrary lists into a single list"
} | 56650 |
<p>I have been given three values: <code>@lLength</code>, <code>@lWidth</code>, <code>@lHeight</code>. I need to take these <code>DECIMAL(4,2)</code> values and set the values of <code>@lMax</code>, <code>@lMid</code>, <code>@lMin</code> with the values I've been given in order of value. So whichever value of <code>Len... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T14:37:44.277",
"Id": "100854",
"Score": "0",
"body": "what happens if all the values are the same?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T14:43:16.470",
"Id": "100856",
"Score": "1",
... | [
{
"body": "<p>I don't know how you are using this information, but I think that you could create a very small table variable or temp table with like one column and then sort and select the information in order. </p>\n\n<pre><code>DECLARE @Table1 TABLE\n(\n Dimension VARCHAR(10),\n Size DECIMAL(4,2)\n)\n... | {
"AcceptedAnswerId": "58106",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T14:05:25.093",
"Id": "56651",
"Score": "7",
"Tags": [
"sql",
"sorting",
"sql-server",
"t-sql"
],
"Title": "Sorting three Decimal values"
} | 56651 |
<p>I have this method that performs certain functions based on the state that the algorithm is currently at:</p>
<pre><code>static infoStruct_t info;
void first_part_of_algorithm(void){
info.state = FIRST_STATE;
//set other information here as well
while(info.state < FINAL_STATE){
switch(info.s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T14:28:31.300",
"Id": "100848",
"Score": "0",
"body": "This looks like code that has not yet been written, we don't review theoretical questions here on Code Review."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate":... | [
{
"body": "<p>Since it's a single-threaded algorithm, I think you could simplify things a bit to avoid all the state-checking. Unless you're reading the state from another thread, you don't really need to keep track of it at all. You could simply make <code>perform_check_needed_for_algorithm</code> return a <co... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T14:07:01.033",
"Id": "56652",
"Score": "5",
"Tags": [
"c",
"singleton",
"state"
],
"Title": "Static variable representing program state accessed with multiple functions"
} | 56652 |
<p>I have two classes that do that same thing with different types. I was thinking of using generics (but I am open to all options). <code>QueryPermissions</code> and the <code>WebQueryObjects</code> come from an external dll that I cannot edit.</p>
<pre><code> public class OnlineReportOutputService : AService, IOnlin... | [] | [
{
"body": "<p><strong>A First Incremental Refactoring Suggestion</strong></p>\n\n<ul>\n<li>The goal is to have working code without \"major multiple organ replacement surgery\" done all at once.</li>\n<li>Have a type parameter for each variant type.</li>\n<li>Keep all of your existing methods for now. Put all o... | {
"AcceptedAnswerId": "56666",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T14:53:49.920",
"Id": "56656",
"Score": "2",
"Tags": [
"c#",
"generics"
],
"Title": "Converting web-querying classes to a single generic class"
} | 56656 |
<p>I have created a tool that lets me calculate the profitability of doing certain actions in an MMORPG game which I play, it's more edging towards a quick-and-dirty solution than towards a neat solution because it's simply a tool and does not need excessive robustness, however I do think there is room for improvements... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T16:45:44.093",
"Id": "100887",
"Score": "5",
"body": "Thanks for including a \"domain knowledge\" section to your post. I wish everyone would do this."
}
] | [
{
"body": "<p>You're looping through every possible permutation of three boolean values. This could be achieved by looping on booleans:</p>\n\n<pre><code>final boolean[] BOOLEANS = new boolean[] { false, true };\nfor (final boolean upgrade5ShinyCrystals : BOOLEANS)\n for (final boolean upgrade6ShinyCrystals ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T15:35:23.800",
"Id": "56661",
"Score": "15",
"Tags": [
"java",
"game"
],
"Title": "Tool to calculate profitability of certain items in a game"
} | 56661 |
<p>So I have a URI with a DNS alias, and I need to dynamically replace the alias with the actual machine. I started out with this:</p>
<pre><code>var builder = new UriBuilder("http://server-alias/path/to/resource");
builder.Host = Dns.GetHostEntry(builder.Host).HostName;
return builder.Uri; // http://server1.mydomain.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T17:45:38.800",
"Id": "100899",
"Score": "0",
"body": "I'm curious, what's the motivation for this?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T17:50:39.837",
"Id": "100901",
"Score": "0",
... | [
{
"body": "<blockquote>\n<p>However, what I need is the URI with just the machine name, <code>http://server1/path/to/resource</code>. Of course I can use this, but string manipulation seems seems a bit kludgey:</p>\n<pre><code>builder.Host = Dns.GetHostEntry(builder.Host).HostName.Split(new[] { '.' }, 2)[0]; \... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T17:36:52.783",
"Id": "56673",
"Score": "4",
"Tags": [
"c#",
".net",
"url"
],
"Title": "Resolve (domainless) machine name from DNS alias"
} | 56673 |
<p>I'm new to JavaScript, and I've built a lightbox for an image gallery. There's a button to open the gallery, plus forwards, backwards, and close buttons, and keyboard controls. Currently, everything works exactly the way I intended, but I know that it can be more DRY, and would love some feedback on that.</p>
<p>He... | [] | [
{
"body": "<p>I'll be reviewing your first chunk of code.</p>\n\n<p><strong><code>fillGalleryContainers</code></strong></p>\n\n<ul>\n<li><p>In the future, you'll probably<sup>†</sup> be able to just write:</p>\n\n<pre><code>$(\".gallery\").css(\"background-image\", \"url(attr(data-image-source url))\");\... | {
"AcceptedAnswerId": "58456",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T17:37:39.323",
"Id": "56674",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Homemade Lightbox and Image Gallery"
} | 56674 |
<h2>Overview:</h2>
<p>I have a need to manage a Google Calendar from a spreadsheet, so I developed a Calendar Manager program with Google Apps Script. I found some inspiration <a href="https://stackoverflow.com/questions/22206851/increasing-speed-of-script-using-cache">over on Stack Overflow</a>, but my requirements a... | [] | [
{
"body": "<h3>UI.gs</h3>\n\n<p>I left some debugging/development code that should be removed. In particular, this </p>\n\n<pre><code>var debugLabel = app.createLabel().setId('DebugLabel').setVisible(false);\n</code></pre>\n\n<p>and this</p>\n\n<pre><code>//UiApp.createApplication().createVerticalPanel().setCel... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T18:14:04.867",
"Id": "56677",
"Score": "10",
"Tags": [
"javascript",
"datetime",
"google-apps-script",
"rags-to-riches",
"google-sheets"
],
"Title": "Managing Google Calen... | 56677 |
<p>I am querying all orders from a WordPress database that uses the WooCommerce Bookings plugin. I want to display upcoming bookings, and there is a potential to have every hour within 2015 to be booked; which means that I might query over 8700 orders.</p>
<p>I'm new to PHP and did most of this following code myself. ... | [] | [
{
"body": "<p>The biggest performance issue is probably here:</p>\n\n<blockquote>\n<pre><code>foreach( $order_items as $order_item ) {\n $item_meta = $wpdb->get_results(\"\n SELECT *\n FROM {$wpdb->prefix}woocommerce_order_itemmeta\n WHERE order_item_id = \" . $order_item->... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T18:17:19.263",
"Id": "56678",
"Score": "6",
"Tags": [
"php",
"beginner",
"mysql",
"wordpress"
],
"Title": "Check efficiency of PHP code that will query over 8500 orders"
} | 56678 |
<p>I have a view controller on my app, where the user is shown a table view. The table view displays their address book contacts and allows the user to select any friends that they would like to invite to the app.</p>
<p>I have 2 model classes: <code>HALAddressBook</code> represents the address book, and <code>HALCont... | [] | [
{
"body": "<blockquote>\n <p><strong>Is it ok that I am setting the properties of the HALContact instance in my view controller?</strong></p>\n</blockquote>\n\n<p>In general, yes. In specific, however, I <em>really</em> don't like the way <code>mainPhoneNumber</code> works. I also don't like that <code>phone... | {
"AcceptedAnswerId": "56700",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T19:06:24.223",
"Id": "56680",
"Score": "5",
"Tags": [
"mvc",
"objective-c",
"ios"
],
"Title": "Adding friends to address book app"
} | 56680 |
<p>I have two different folders. </p>
<p>In one folder, I have files that will be exported to a remote site via FTP.</p>
<p>In a second folder, I have .dat files that will be processed by a ftp client program that I have. Each .dat file contains basic information that my ftp program needs to process a request.</p>
... | [] | [
{
"body": "<p>Pretty hard to pick on this, looks pretty nice already!</p>\n\n<p>You have this duplicated pattern though:</p>\n\n<blockquote>\n<pre><code>if (-not(Test-Path $filepath)){\n New-Item -ItemType file -Path $filepath -Value $i\n}\n# ...\nif (-not(Test-Path $queue_filepath)){\n New-Item -ItemType... | {
"AcceptedAnswerId": "56685",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T19:08:18.550",
"Id": "56681",
"Score": "4",
"Tags": [
"beginner",
"powershell"
],
"Title": "Create Dummy Files for Testing"
} | 56681 |
<p>I made a simple AngularJS text function. The purpose is to provide an array of content to display. A 'slider' will be made with next and previous buttons that hide on the last and first slide, respectively. I can't help but feel it isn't very efficient. Any thoughts?</p>
<p>Here is a <a href="http://jsfiddle.net/jo... | [] | [
{
"body": "<p>Instead of setting the active property to an element in the array, set it to the index of the element.</p>\n\n<p>The reason for this being that almost all your operations are on the index and not the element itself. You only use that once: when you display the element. You can then eliminate your ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T19:45:30.177",
"Id": "56684",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"angular.js"
],
"Title": "Simple text toggling"
} | 56684 |
<p>First off, this is not my code. I'm curious what everyone thinks about changing the type of an object inside of a method then modifying the properties of the cast type. I wanted to use composition to build up a patient, but this is the recommend path. I'm probably wrong which is why I wanted 3rd party feedback. O... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T20:25:00.137",
"Id": "100938",
"Score": "0",
"body": "In C# you can't change the type of an object (an object only exist at runtime) you can test the type (and cast) as you do but you are not chaning the type"
}
] | [
{
"body": "<p>It stead of having a static method the basically does what polymorphism could do for you use polymorphism.</p>\n\n<pre><code>public class Person\n{\n public string FirstName { get; private set; }\n public string LastName { get; private set; }\n\n public virtual void InitializeFromDictiona... | {
"AcceptedAnswerId": "56689",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-10T20:20:10.560",
"Id": "56687",
"Score": "5",
"Tags": [
"c#",
"casting",
"polymorphism"
],
"Title": "Changing the type of an object inside a method?"
} | 56687 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.