body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<pre><code>Public Function MyProjectFuncion(firstObject As Object, myEnumeration As Enumeration, theString As String, someCollection As List(of Object), anotherObject As Object) _ ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-11T20:22:00.837", "Id": "82211", "Score": "0", "body": "Thanks @SimonAndréForsberg but unfortunately this is a code that someone is actually using in our real project, I just don't wanna use the real name values. I'm posting this code ...
[ { "body": "<p>You're throwing <code>System.Exception</code> - that's bad, you'll want to throw a <em>meaningful</em> exception. See <a href=\"https://codereview.stackexchange.com/a/44490/23788\">this answer</a> for more details.</p>\n\n<p>The main problem with this code, is that you're using exceptions to <em>c...
{ "AcceptedAnswerId": "46960", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-11T20:09:13.387", "Id": "46957", "Score": "5", "Tags": [ "vb.net", "validation", "exception" ], "Title": "Is there a better way to optimize these conditionals?" }
46957
<p>I'm still new in Java so I always try to find new ways and improve my skills.</p> <p>I found <code>enum</code> in Java to be very powerful (maybe excessively?) and while I was reading Effective Java book I've had some great ideas and I thought about using it to improve the flexibility of a standard console applicat...
[]
[ { "body": "<p>Just a few random comments:</p>\n\n<ol>\n<li><p>For this:</p>\n\n<blockquote>\n <p>A description of the action is passed to the constructor; \n the value (the number to write to execute the action) is calculated\n using ordinal() + 1 it could be read as a bad practice but I may be wrong, am I?<...
{ "AcceptedAnswerId": "47065", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-11T20:19:51.480", "Id": "46959", "Score": "4", "Tags": [ "java", "console", "enum" ], "Title": "\"Agenda\" test application for Enum" }
46959
<p>I'm trying to work with exception handling by displaying "No Such File" when the file doesn't exist. I need to use a <code>try</code> statement.</p> <pre><code>import sys try: f = open("h:\\nosuchdirectory\\nosuchfile.txt","w") # do not modify this line f.write("This is the grape file") # do not modify thi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-11T21:41:24.283", "Id": "82239", "Score": "0", "body": "From the answer given by @RuslanOsipov, it appears that your code actually does not work. You should only post working code on Code Review, otherwise, your question will be deemed...
[ { "body": "<p>You will not get <code>IOError</code> when opening a file for writing. Writing a non-existent file will just create a new one. Here's a solution:</p>\n\n<pre><code>import os\n\npath = \"h:\\\\nosuchdirectory\\\\nosuchfile.txt\"\nif os.path.isfile(path):\n print(\"No such file!\")\n return\nf...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-11T20:43:59.727", "Id": "46961", "Score": "2", "Tags": [ "python", "file", "exception", "error-handling" ], "Title": "Python and Exception Handling IOError" }
46961
<p>Please be brutal, and treat this as if I was at an interview at a top 5 tech firm.</p> <blockquote> <p><strong>Question:</strong> Write a function to find the longest common prefix string amongst an array of strings.</p> </blockquote> <p>Time it took: 17 minutes</p> <p>Worst case complexity analysis: n possib...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-11T21:19:34.427", "Id": "82230", "Score": "3", "body": "http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html#getCommonPrefix%28java.lang.String...%29, http://commons.apache.org/proper/commons-...
[ { "body": "<p>Pure functions should generally be declared <code>static</code>.</p>\n\n<p>You shouldn't need to take substrings in a loop — that's inefficient. Think of scanning a two-dimensional ragged array of characters. Check that all of the first characters match, then that all of the second characters ma...
{ "AcceptedAnswerId": "46967", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-11T20:55:31.187", "Id": "46965", "Score": "15", "Tags": [ "java", "algorithm", "interview-questions" ], "Title": "Longest Common Prefix in an array of Strings" }
46965
<p>This is my first time using knockout. I'm reading/writing a JSON file with a fair bit of nested data. I had no problem creating the ViewModel to just write to the file, but now that I'm reading the data into my model also, I've had to write a few if/else statements to handle the different cases. Not sure if this is ...
[]
[ { "body": "<p>Overall, it looks really good and serves as a pretty great model of what Knockout models <em>should</em> look like, but, internally there are some strange things here like arrays that you are using <code>[0]</code> only on (this could be the result of poor data format via your backend web services...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-11T21:33:20.773", "Id": "46968", "Score": "2", "Tags": [ "javascript", "jquery", "knockout.js" ], "Title": "Is this a correct knockout ViewModel setup?" }
46968
<p>I have had this keylogger code for a while now (a few years*), and I figured I would put it up for review. Here is what I would like reviewed (in order):</p> <ol> <li><p><strong>Portability</strong> - right now, this program can only work on Windows systems. In what ways can I make this more portable? (I feel like...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-01-01T17:24:50.910", "Id": "137184", "Score": "0", "body": "what is the use of this GetAsyncKeyState(VK_SHIFT)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-01-01T19:07:59.103", "Id": "137196", "Score":...
[ { "body": "<ul>\n<li><p>You have some global variables in <strong>main.c</strong>:</p>\n\n<blockquote>\n<pre><code>bool invisible = true;\nchar fileName[MAX_PATH];\n</code></pre>\n</blockquote>\n\n<p>They should be placed in the closest <em>local</em> scope possible and passed to functions as needed.</p></li>\n...
{ "AcceptedAnswerId": "46984", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T00:21:26.510", "Id": "46980", "Score": "26", "Tags": [ "c", "windows", "logging", "portability" ], "Title": "Windows keylogger in C" }
46980
<p>So about a year and a half ago, me and my friend started on a game called <em>Zombie Smack Down</em>. It's a text based game written in Ruby. But we were both really new to Ruby when most of it was written. I realize lots of this code is probably really bad, but I'm kinda stuck in my ways. </p> <p>I'd love to know ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T02:32:23.747", "Id": "82275", "Score": "0", "body": "To trap the CTRL-C interrupt signal, you need to `rescue Interrupt`. See [this SO question](http://stackoverflow.com/questions/2089421/capturing-ctrl-c-in-ruby) for more info." ...
[ { "body": "<p>I would like to start by saying that I've never worked with ruby 1.8.7, so I apologize in advance if some of my observations are not relevant for that version...</p>\n\n<p><strong>Require relative</strong><br>\nYou use <code>$rpath</code> where you <em>assume</em> that your app is installed somewh...
{ "AcceptedAnswerId": "46990", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T01:40:17.447", "Id": "46983", "Score": "6", "Tags": [ "beginner", "ruby", "game", "meta-programming" ], "Title": "Zombie Smack Down game" }
46983
<p>I'm a beginner to .NET and could you guide me to right direction. My problem is based on the following code. Here I have 4 variations of same method and all 4 variations are working fine.</p> <ol> <li><p>What is the recommended or standard way of doing this? </p></li> <li><p>If none of these methods are okay, kindl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T03:33:02.550", "Id": "82283", "Score": "0", "body": "you should separate these into 4 separate questions I think. and then see what answers you get from each of them, then you could better decide which one you like the best." }, ...
[ { "body": "<p>with all of the methods you should add another <code>using</code> statement for your Readers as well. </p>\n\n<p>right now you aren't closing your reader, I am not sure that the reader is closed inside the using block of the connection, but I would imagine it should be, logically you can't have t...
{ "AcceptedAnswerId": "46987", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T03:29:01.397", "Id": "46985", "Score": "19", "Tags": [ "c#", "beginner", ".net", "winforms" ], "Title": "Displaying data from a database onto a form" }
46985
<p>Protocol buffers are a flexible, efficient, automated mechanism for serializing structured data – think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T08:46:13.107", "Id": "46991", "Score": "0", "Tags": null, "Title": null }
46991
Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. Google uses Protocol Buffers for almost all of its internal RPC protocols and file formats.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T08:46:13.107", "Id": "46992", "Score": "0", "Tags": null, "Title": null }
46992
<p>The crawler is in need of a mechanism that will dispatch threads based on network latency and system load. How does one keep track of network latency in Python without using system tools like ping?</p> <pre><code>import sys import re import urllib2 import urlparse import requests import socket import threading impo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T15:55:45.520", "Id": "82317", "Score": "0", "body": "The idea is to hit n domains and after n domains\nhave been hit stop crawling and check each domain\nin the set of crawled domains for rss feeds" }, { "ContentLicense": "C...
[ { "body": "<p>I see a flurry of downloading activity, but I don't see that you do anything with the pages that you download except parse some URLs for more downloading. There's no rate limiting or any attempt to check <a href=\"http://www.robotstxt.org\"><code>robots.txt</code></a>, making your web crawler a p...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T09:16:39.127", "Id": "46993", "Score": "5", "Tags": [ "python", "multithreading", "http", "web-scraping" ], "Title": "A simple little Python web crawler" }
46993
<p>I need help optimizing my code to run faster (it works but I get Time Limit Exceeded) for <a href="http://www.codechef.com/APRIL14/problems/CNPIIM" rel="nofollow">this problem</a>.</p> <p>(Don't pay attention to <code>readInt()</code> function, its only used for fast input)</p> <pre><code>#ifdef _MSC_VER #define _...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T09:50:34.227", "Id": "82297", "Score": "1", "body": "Could you please translate the names of the functions `Luwia`, `Luwistvis` and `Kentistvis` to english?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-0...
[ { "body": "<p>A good part of this review will not be about optimization but about style. The speed of your program should not be worse after you apply the changes though. First of all, you should order your headers by alphabetic order: this will allow you to check whether a header is inluded or not without havi...
{ "AcceptedAnswerId": "47011", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T09:41:30.377", "Id": "46994", "Score": "5", "Tags": [ "c++", "optimization", "algorithm", "programming-challenge" ], "Title": "Counting matrices" }
46994
<p>I made a function for recursively reading a directory and it just seems kind of long and complicated. If you could take a look and tell me what's good or bad about it, that would be great.</p> <p>Reading the directory synchronously is not an option.</p> <pre><code>var dutils = require('./dutils'); module.exports =...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T14:37:22.253", "Id": "82308", "Score": "0", "body": "You should read about control flow libraries, for example [async](https://github.com/caolan/async) or promises, for example [q](https://github.com/kriskowal/q)." }, { "Con...
[ { "body": "<p>My comments are inline starting with the <code>//*</code>. I also very much encourage you to look at async libraries <a href=\"https://www.npmjs.org/search?q=q\" rel=\"nofollow\">such as Q</a>.</p>\n\n<pre><code>var dutils = require('./dutils');\n\n//* Why export an object with a single function? ...
{ "AcceptedAnswerId": "47014", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T11:36:30.670", "Id": "46998", "Score": "3", "Tags": [ "javascript", "recursion", "node.js" ], "Title": "Recursively reading a directory in node.js" }
46998
<p>Please feel free to comment on the accuracy/validity of the following wrapper source for processing signals using the new POSIX sigaction API. If you feel I'm doing anything wrong or potentially dangerous, chime in.</p> <p><em>Note:</em> <code>syserr</code> is a custom function not shown to exit gracefully.</p> <h...
[]
[ { "body": "<pre><code>static struct sigaction *\nhandle_signal(int sig,\n int flags,\n void (*handler)())\n{\n</code></pre>\n<p>Two things here:</p>\n<ul>\n<li><p>The signal handler function should have the signature <code>void handler(int signum);</code> <a href=\"http://linux.die.net...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T11:42:21.987", "Id": "46999", "Score": "11", "Tags": [ "c", "linux", "wrapper" ], "Title": "Set of wrapper functions for POSIX signal APIs on Linux" }
46999
<p>I'm writing the data structures for my program (a toy compiler), and I'm trying to understand what's the best way to define the AST:</p> <p>Current code</p> <pre><code>data RExpr = RExpr Location InnerRExpr data InnerRExpr = RLExpr LExpr | RConstant Constant | RMathExpr MathExpr | FCall Id [RExpr] </code></pre> <...
[]
[ { "body": "<p>I tend towards the former, and then use a lens or traversal to extract the location.</p>\n\n<pre><code>import Control.Lens\n\nclass HasLocation t where\n loc :: Lens' t Location\n\ninstance HasLocation RExpr where\n loc f (RLExpr l e) = f l &lt;&amp;&gt; \\l' -&gt; RLExpr l' e\n loc f (RCons...
{ "AcceptedAnswerId": "47001", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T13:18:44.030", "Id": "47000", "Score": "1", "Tags": [ "haskell" ], "Title": "What's more idiomatic in Haskell?" }
47000
<p>I have a trivial function that rotates 2d vectors, and a method in a class representing a polygon that rotates every point in the polygon around an origin. The code is fairly optimized as it is, but I was wondering if there is any faster way of doing it, since the function is called a HUGE amount of times and I need...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T14:51:56.907", "Id": "82310", "Score": "0", "body": "You might want to try OpenCL/CUDA. They are PyOpenCL and PyCUDA. The neat thing about using the GPU for computing is that it is extremely parallel." }, { "ContentLicense":...
[ { "body": "<p>You will likely be rotating many vectors by the same angle. Therefore, it would be wasteful to compute \\$\\cos \\theta\\$ and \\$\\sin \\theta\\$ repeatedly.</p>\n\n<p>The typical way to think of linear transformations is as matrix multiplication:</p>\n\n<p>$$\n\\left[ \\begin{array}{c} x' \\\\ ...
{ "AcceptedAnswerId": "47008", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T14:36:52.660", "Id": "47003", "Score": "5", "Tags": [ "python", "optimization", "matrix", "computational-geometry" ], "Title": "Optimize vector rotation" }
47003
<p>I need a function (I named it <code>applyToEveryPair</code>) that works on lists, e.g. <code>[x0,x1,x2,x3,...]</code>, and uses a function <code>f:: (a,a) -&gt; [(a,a)]</code>. For every (distinct) pair <code>(xi,xj)</code>, <code>i/=j</code> of the list I want all lists where <code>xi</code> is replaced by <code>yi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T07:01:45.623", "Id": "82549", "Score": "0", "body": "can you please provide example of `f :: (a,a) -> [(a,a)]`? how it can swap lines?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T09:14:14.690", ...
[ { "body": "<p>I don't think there is a much nicer way to do this. However, on the performance side, you should definitely use a data structure with constant time random access, such as <code>Vector</code>. That would save you from writing the <code>setList</code> function.</p>\n", "comments": [], "meta_...
{ "AcceptedAnswerId": "47457", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T15:34:44.947", "Id": "47005", "Score": "4", "Tags": [ "haskell" ], "Title": "replacing every pair in a list" }
47005
<p>I solved a problem which you can read about <a href="http://www.spoj.com/problems/EIGHT/" rel="nofollow">here</a>, but it gives me "time limit exceeded" even though it runs in 4 seconds. I really don't understand why.</p> <p>I don't think my code can be any simpler, basically it has as many functions as there are s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T16:33:31.083", "Id": "82319", "Score": "0", "body": "Say your word to find is three characters long. Then you would not need to search to the right if you are less than three characters from the right edge of the array because you c...
[ { "body": "<p>First you can change those non-required letters to a specific character like '.'.</p>\n\n<p>Turning the 2D array into a string or array of byte. For example:</p>\n\n<pre><code>1234\n5678\n90ab\ncdef\n=&gt;\nstring1: 1234\nstring2: 5678\nstring3: 90ab\nstring4: cdef\n</code></pre>\n\n<p>Remove '.' ...
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T16:08:45.290", "Id": "47007", "Score": "7", "Tags": [ "performance", "programming-challenge", "pascal" ], "Title": "Eight Directions Crossword" }
47007
<p>I am learning string algorithms and wrote this C example based on a Java example I found online. Any feedback relating to style, code clarity, whether it is generic enough to be re-used, interface, etc, etc would be very much appreciated.</p> <pre><code>/* Demonstration of least significant digit (LSD) radix sort...
[]
[ { "body": "<ul>\n<li><p>This macro name is misleading:</p>\n\n<pre><code>#define ALPHABET 36\n</code></pre>\n\n<p>The alphabet consists of 26 letters, not 36. <em>But</em> in a CS context, this can be implied (in this case, it appears to include A-Z and 0-9).</p>\n\n<p><em>However</em>, this macro is storing t...
{ "AcceptedAnswerId": "47013", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T17:25:47.890", "Id": "47009", "Score": "15", "Tags": [ "algorithm", "c", "strings", "sorting", "radix-sort" ], "Title": "Least significant digit (LSD) radix sort of str...
47009
<p>For the first time, I tried to use threads by myself in order to implement a parallel <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes" rel="noreferrer">sieve of Eratosthenes</a>. The trick is that each time a prime is found, a thread is spawned to eliminate all the multiples of this prime number from the...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T20:03:39.330", "Id": "82333", "Score": "4", "body": "Have you timed this? It would surprise me if a parallel sieve is faster because of the memory contention. The speed up you receive from cached memory over real memory seem more li...
[ { "body": "<p>As you are correctly assuming there are multiple threading related issues with your code, but lets tease you and start with the usual suspects.</p>\n\n<h1>Naming</h1>\n\n<p>The name <code>apply_prime</code> is misleading and inexpressive.\nNeither does the function really require a prime nor does ...
{ "AcceptedAnswerId": "47017", "CommentCount": "15", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T19:33:35.083", "Id": "47016", "Score": "42", "Tags": [ "c++", "multithreading", "c++11", "primes", "sieve-of-eratosthenes" ], "Title": "Parallel sieve of Eratosthenes"...
47016
<p>Motivation: I have a large number of large read-only dicts with large string keys mapped to tuples of two floats. They are taking up a large amount of heap space.</p> <p>Proposed solution: a 3xn NumPy array, with the first column being the hash value of the key, and sorted by that column. Only contains and <code>ge...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T12:27:32.970", "Id": "82404", "Score": "0", "body": "I am a little confused as to why you do not just use a `dict` here. Can you prove that your solution is more memory efficient. The lookups will certainly be slower." }, { ...
[ { "body": "<p>I think this looks pretty efficient. Let me add a few more minor, detailed comments (more than 1 year after the question was asked; I hope they are still useful):</p>\n\n<ol>\n<li><p>After you convert to a NumPy array, the keys are longer guaranteed to be unique (if someone re-uses your code in a...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T20:35:07.310", "Id": "47022", "Score": "5", "Tags": [ "python", "numpy", "hash-map" ], "Title": "NumPy array as quasi-hash table" }
47022
<p>I have made a basic calculator using methods. This is my first attempt at using methods and would like to see if I can improve on this as there is a lot of repeated code.</p> <pre><code>import java.util.Scanner; public class Calculator { public static void main(String[] args) { Scanner kb = new Sca...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T23:50:26.000", "Id": "82363", "Score": "1", "body": "If you are wondering why you post hasn't received many votes, it's because you posted your answer late in the day; no one has any ammo left. ;)" }, { "ContentLicense": "CC...
[ { "body": "<p>Nice job! I hope you find the comments below useful as you progress.</p>\n\n<ol>\n<li><strong>Variable names:</strong> Try to have variable names which describe what the variable actually <em>represents</em> or <em>holds</em>. For example, I have no idea why you named your <code>Scanner</code> \...
{ "AcceptedAnswerId": "47036", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T22:38:44.220", "Id": "47026", "Score": "16", "Tags": [ "java", "beginner", "calculator" ], "Title": "Very basic calculator using methods" }
47026
<p>Below is a naive algorithm to find nearest neighbours for a point in some n-dimensional space. </p> <pre><code>import numpy as np import scipy.sparse as ss # brute force method to get k nearest neighbours to point p def knn_naive(k, p, X): stacked_p = ss.vstack([p for n in range(X.get_shape()[0])]) D = X -...
[]
[ { "body": "<p>I wasn't aware that scipy's sparse matrices did not support broadcasting. What a shame that you can't simply do <code>D = X - p</code>! Your construction of <code>stacked_p</code> can be sped up quite a bit, but you need to access the internals of the CSR matrix directly. If you aren't aware of th...
{ "AcceptedAnswerId": "47040", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T22:40:16.520", "Id": "47027", "Score": "6", "Tags": [ "python", "performance", "matrix", "numpy", "clustering" ], "Title": "Calculating Euclidean norm for each vector i...
47027
<p>Would you please review and give me some feedback? I've been learning Java and I want to avoid bad practices.</p> <p>Is it good to make a helper class to define the methods my main program is using?</p> <p>Is this approach ok for bigger projects?</p> <p>If the game looks fine, what would be the next simple game c...
[]
[ { "body": "<p>Not a bad start at Java! :) Below are some comments that I hope can help you improve.</p>\n\n<h1>Some big things:</h1>\n\n<ol>\n<li><strong>Comments:</strong> I think you make the very uncommon mistake of having <em>too many</em> comments rather than not enough. I'm actually loathe to even menti...
{ "AcceptedAnswerId": "47034", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T22:52:16.063", "Id": "47028", "Score": "10", "Tags": [ "java", "game", "number-guessing-game" ], "Title": "\"Guess a number\" game in Java" }
47028
<p>Given two rectangles, return the intersecting rectangles. This class is thread-safe. It takes rectangles in two different representations, and returns the intersecting rectangle in the respective representations.</p> <p>Looking for code review, optimization and best practices.</p> <pre><code>final class RectangleW...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T22:06:28.210", "Id": "82503", "Score": "0", "body": "I'm not sure if you are required to keep the two representations, but I would stick with just one. It gets unnecessarily complicated otherwise. Of course, you could have a const...
[ { "body": "<p>Instead of putting unit tests in the <code>main</code> method, create proper JUnit tests.</p>\n\n<hr>\n\n<p>At least one of your unit tests is incorrect:</p>\n\n<pre><code>assertEquals(new RectangleWithPoints(15, 25, 25, 5), \n fecthIntersectingRectangle(new RectangleWithPoints(10, 35, 25...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T23:21:38.530", "Id": "47029", "Score": "5", "Tags": [ "java", "algorithm" ], "Title": "Find intersecting rectangle" }
47029
<p>I would like to revise the fundamentals of Java threads on before-Java 5, so that I can understand improvements in Java 5 and beyond.</p> <p>I started off with a custom collection and need help on:</p> <ol> <li>Things I am doing wrong / grossly overlooking</li> <li>How to make it better</li> <li>Suggest alternate ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T00:26:46.923", "Id": "82368", "Score": "0", "body": "I found one issue , RemoveCollClass thread will go on a indefinite wait if AddCollClass thread stops before RemoveCollClass thread. Solution : Thread should wait on certain timepe...
[ { "body": "<p>Regardless of which version of Java you are using, there are a few things you have 'wrong' when it comes to best-practice threading in Java.</p>\n\n<h1>The Big Picture</h1>\n\n<ul>\n<li>avoid volatile unless you have no choice (especially pre-Java5 - In Java5 and later the volatile keyword introdu...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-12T23:51:58.097", "Id": "47030", "Score": "4", "Tags": [ "java", "multithreading", "thread-safety" ], "Title": "Pre-Java 5 threads" }
47030
<p>I googled around for secure random number generation and random string generation, combining them with some user data.</p> <p>Is this good or am I totally off-base? I don't know much about cryptography but I do not see many alternatives, other than some bad code that gets copied around a lot with <code>mt_rand</co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T01:06:38.717", "Id": "82377", "Score": "1", "body": "To me, it looks like it's doing too much. I'd just generate 16 random bytes, convert them to hex, and be done with it." }, { "ContentLicense": "CC BY-SA 3.0", "Creatio...
[ { "body": "<p>If CSRF stands for Cross Site Request Forgery, then it's hard to imagine why I should help. </p>\n\n<p>In any case, simply doing a cryptographic Whirlpool hash of a user-supplied string with a random seed value should be sufficiently random for most every purpose. The rest is just obfuscation an...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T00:55:05.703", "Id": "47031", "Score": "4", "Tags": [ "php", "random", "hashcode" ], "Title": "Generating random and secure CSRF tokens" }
47031
<p>The code displays a video that will play a video and then display some text on the screen at specific locations on the video screen.</p> <p>The code works but I would like to see if I could change somethings to make it better and how I would do that. You should be able to just copy the code into a web browser and i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T03:11:39.357", "Id": "82386", "Score": "0", "body": "Based largely on the O'Reilly book [_HTML5 Canvas_, Chapter 6](http://chimera.labs.oreilly.com/books/1234000001654/ch06.html). Video samples at http://orm-other.s3.amazonaws.com/h...
[ { "body": "<p>Interesting code,</p>\n\n<p>you are skirting the rules of 'code you wrote', but I still think review of this code is valuable. In essence this code is fine, there are some style changes you might want to consider.</p>\n\n<ul>\n<li>I am guessing part of your goal is to have a \"one page has it all\...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T02:07:21.887", "Id": "47039", "Score": "6", "Tags": [ "javascript", "canvas", "video" ], "Title": "Display text on video screen" }
47039
<p>This scrapes results from thefreedictionary.com:</p> <pre><code>#!/usr/bin/python from bs4 import BeautifulSoup as bs import re from requests import get def remove_non_ascii(text): return re.sub(r'[^\x00-\x7F]+', '', text) def get_soup(url): raw = remove_non_ascii(get(url).content) soup = bs(raw) ...
[]
[ { "body": "<ol>\n<li>According to <a href=\"http://legacy.python.org/dev/peps/pep-0008/#imports\" rel=\"nofollow\">PEP8</a>, <code>import re</code> should come first</li>\n<li>In free dictionary there is only one div having the class <code>ds-single</code>. You can simplify your code to search for this div</li>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T05:26:14.043", "Id": "47045", "Score": "2", "Tags": [ "python", "python-2.x", "web-scraping" ], "Title": "Scraping thefreedictionary.com" }
47045
<p>I just started getting into the Less CSS framework and I am wondering if I'm doing it right and how the code can be improved if possible.</p> <p><strong>global.less</strong></p> <pre><code>//variables @themeRed: #cc1111; @themeColor: @themeRed; @marginBottom: 10px; @contentRadius: 5px; //mixins .border-radius(@ar...
[]
[ { "body": "<p>Looks just fine, I think. Only some really minor things come to mind</p>\n\n<ol>\n<li><p>For <code>font-family</code>, it's good to always end with a generic font face style; in this case it'd be <code>sans-serif</code>. Arial is of course as \"web-safe\" as it gets, but still.</p></li>\n<li><p>Wh...
{ "AcceptedAnswerId": "47060", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T08:21:08.847", "Id": "47047", "Score": "4", "Tags": [ "css", "less-css" ], "Title": "Can my Less CSS code be improved?" }
47047
<p><a href="http://projecteuler.net/problem=27" rel="nofollow">Project Euler problem 27</a></p> <p>I decided to try simple brute force, and it worked surprisingly quickly. How can this be optimized?</p> <pre><code>"""Considering quadratics of the form: n^2 + an + b, where |a| &lt; 1000 and |b| &lt; 1000 Find the pro...
[]
[ { "body": "<p>This is mostly quite good, but has some issues.</p>\n\n<ul>\n<li><p>The required answer to the Project Euler problem is not the values of \\$a\\$ and \\$b\\$, but their product. You could output that value rather than requiring another computation.</p></li>\n<li><p>Your prime test could be speeded...
{ "AcceptedAnswerId": "47057", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T11:29:34.947", "Id": "47055", "Score": "4", "Tags": [ "python", "primes", "programming-challenge" ], "Title": "Project Euler 27 - Quadratic Primes" }
47055
<p><a href="http://projecteuler.net/problem=28" rel="nofollow">Project Euler problem 28</a></p> <blockquote> <p>Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:</p> <p>$$\begin{array}{rrrrr} \color{red}{21} &amp;22 &amp;23 &amp;24 &amp;\color{red}...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T20:23:23.943", "Id": "82460", "Score": "4", "body": "Metric Marvin says, \"1s = 1000ms.\" :)" } ]
[ { "body": "<p>Accumulating all the numbers in a list is unnecessary, and with large numbers you might reach the memory limit. This is equivalent and more efficient:</p>\n\n<pre><code>count = 1\nlastnum = 1\ntotal = lastnum\nwhile count &lt; (2 * n - 1):\n increment = count * 0.5 + 1.5\n for p in range(4):...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T12:04:08.293", "Id": "47056", "Score": "6", "Tags": [ "python", "programming-challenge" ], "Title": "Project Euler 28 - Number Spiral Diagonals" }
47056
<p>I'm trying to find the best - read: readable, maintainable, robust, threadsafe, usable - solution for a State Machine in python. For this I've been looking at the State Design Pattern. However I want a pythonic and lean solution (saying not implementing functions in subclasses that are not needed).</p> <p>Long stor...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T16:33:55.903", "Id": "82428", "Score": "0", "body": "Interesting question ! Out of curiosity, my understanding is that nothing happens when the transition is not possible. Is it something we want ?" }, { "ContentLicense": "C...
[ { "body": "<p>Not a proper code review as per se but I was wondering if things couldn't be done in a more straight-forward way like this :</p>\n\n<pre><code>#!/usr/bin/python\n\nclass Machine(object):\n def __init__(self, state, transitions):\n self.transitions = transitions\n self.state = stat...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T13:05:49.447", "Id": "47058", "Score": "4", "Tags": [ "python", "design-patterns", "state-machine" ], "Title": "State Design Pattern in Python" }
47058
<h3>Background</h3> <p>I have a base (only 2 classes inherit from it, and only from it) abstract (meaning I don't want it to be used directly) class that implements some common functionality.</p> <p>Some of it depends on certain methods being defined, methods whose implementation differs per the exact sub-class; so I...
[]
[ { "body": "<blockquote>\n <p><strong>Source:</strong> Question answered while <a href=\"http://chat.stackexchange.com/transcript/message/14923903#14923903\">rubber-ducking in the chat-room</a>, LOL ;)</p>\n</blockquote>\n\n<p>When the <code>Matrix</code> methods try to look for the non-existent methods; they'l...
{ "AcceptedAnswerId": "47063", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T13:39:38.820", "Id": "47059", "Score": "9", "Tags": [ "python", "classes", "inheritance", "abstract-factory" ], "Title": "Raising error if method not overridden by sub-clas...
47059
<p>I'm not going to explain the purpose of the code provided below. If you do not understand it, i know that i have to improve it (naming, structure etc.).</p> <p>I would like to know how to improve this code in terms of readability and complexity.</p> <p><strong>Data structure:</strong></p> <pre><code>&lt;?xml vers...
[]
[ { "body": "<p>Instead of reloading the XML file every time you call <code>AddAuthor</code>, it would be more efficient to load the file once. If you are concerned about other threads or processes writing to the file, then you might want to lock it.</p>\n\n<p>The <code>authorExists</code> local variable is point...
{ "AcceptedAnswerId": "47070", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T15:21:43.137", "Id": "47066", "Score": "8", "Tags": [ "c#", "xml" ], "Title": "Check if XmlNode with certain attribute exists and create XmlNode if not" }
47066
<p>This question is a revision of <a href="https://codereview.stackexchange.com/q/47016/15094">Parallel sieve of Eratosthenes</a>. The goal is to implement a <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes" rel="nofollow noreferrer">sieve of Eratosthenes</a> with parallel strikes out from the boolean array....
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T20:13:33.207", "Id": "82459", "Score": "0", "body": "Note: The constructor you mention is the fill constructor. `vector(size_type n, const value_type& val = value_type())`. The second argument (if not supplied) is defaulted; but it ...
[ { "body": "<p>Expanding on comments:</p>\n\n<p>I would reverse the splitting.\nI would split the writable memory across the threads so each thread wrote to a unique section of memory (it would be good if this were divided by page size as it may help performance). We will call the section of memory that a thread...
{ "AcceptedAnswerId": "47094", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T15:22:32.190", "Id": "47067", "Score": "12", "Tags": [ "c++", "multithreading", "c++11", "primes", "sieve-of-eratosthenes" ], "Title": "Parallel sieve of Eratosthenes, ...
47067
<p>I'm a beginner to Model-View-Presenter pattern and I'm finding a way to use it in a sample application</p> <p>In my C# winforms application has a <code>Employee Class</code> and it has properties like <code>EmployeeID</code>,<code>Name</code>, <code>Address</code>, <code>Designation</code> etc. Also it has behavior...
[]
[ { "body": "<blockquote>\n<p>I think your question would be better if you fleshed it up with your actual working code, there's a lot of &quot;placeholder&quot; code in your post, which makes it border the line of off-topicness.</p>\n<p>You may be able to find more information and high-level design guidance about...
{ "AcceptedAnswerId": "47119", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T15:42:44.133", "Id": "47068", "Score": "5", "Tags": [ "c#", ".net", "ado.net", "mvp" ], "Title": "Using model view presenter (MVP) in C# code" }
47068
<p>This started out with my <a href="https://stackoverflow.com/a/23040622/2644390">answer</a> to <a href="https://stackoverflow.com/q/23038622/2644390">Radix Sort on an Array of Strings?</a>. Since I intend to write a generic radix sort for my own purposes anyway, I continued a little bit, and here is a version tested ...
[]
[ { "body": "<h1>Style</h1>\n\n<p>You should reorder your headers in alphabetic order. It will help when you will have to check whether a header is already included or not:</p>\n\n<pre><code>#include &lt;algorithm&gt;\n#include &lt;array&gt;\n#include &lt;iostream&gt;\n#include &lt;numeric&gt;\n#include &lt;strin...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T15:49:27.257", "Id": "47069", "Score": "12", "Tags": [ "c++", "algorithm", "sorting", "generics", "floating-point" ], "Title": "Generic radix sort" }
47069
<p>I've brute forced solve <a href="http://projecteuler.net/problem=14" rel="nofollow">Project Euler 14</a>. This is my first attempt at trying to solve it, by caching already solved answers, and skipping them as I run it, I am finding the program take's almost twice as long as the simple brute force method of checking...
[]
[ { "body": "<p>Try adding the following:</p>\n\n<pre><code>#include &lt;limits&gt;\n#include &lt;sstream&gt;\n#include &lt;stdexcept&gt;\n\nint main() {\n constexpr unsigned max_odd = (std::numeric_limits&lt;unsigned&gt;::max() - 1) / 3;\n\n …\n for … {\n if … {\n …\n for … ...
{ "AcceptedAnswerId": "47092", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T16:33:35.827", "Id": "47071", "Score": "4", "Tags": [ "c++", "c++11", "programming-challenge" ], "Title": "Project Euler 14: Longest Collatz Sequence" }
47071
<p>I'm very much on the beginner end of the PHP scale but I have read plenty of the entry level books and completed the online training at teamtreehouse.com so I know the basics.</p> <p>I'm at a point where I've built a tax calculator in PHP (UK income tax) and it works and is accurate but I have no clue if the code f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T09:36:18.383", "Id": "82569", "Score": "1", "body": "Just a quick comment, before I take the time for a more thorough review [Coding standards are very important](http://www.php-fig.org). Try to adhere to them as much as you can. In...
[ { "body": "<p>I'm not too familiar with PHP, so just a few generic notes:</p>\n\n<ol>\n<li><p>For this:</p>\n\n<blockquote>\n<pre><code>/*\n * Sets the default values we need when the class is instantiated.\n * @param array $persona User submitted inputs\n * @param array $income_tax_rates R...
{ "AcceptedAnswerId": "47681", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-04-13T17:01:31.477", "Id": "47073", "Score": "5", "Tags": [ "php", "beginner", "object-oriented", "finance" ], "Title": "UK tax calculator" }
47073
<p>I retrieved Bloomberg data using the Excel API. In the typical fashion, the first row contains tickers in every fourth column, and the second row has the labels Date, PX_LAST, [Empty Column], Date, PX_LAST, etc. The following rows have dates and last price.</p> <blockquote> <pre class="lang-none prettyprint-ov...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-08-22T11:08:25.843", "Id": "110269", "Score": "0", "body": "[Reposted from Stack Overflow](http://stackoverflow.com/questions/23043812/parse-bloomberg-excel-csv-with-pandas-dataframe-new-user)" } ]
[ { "body": "<p>You can probably do most of what you want in native Pandas.\nIt has <a href=\"http://pandas.pydata.org/pandas-docs/stable/io.html#excel-files\" rel=\"nofollow\">functions</a> for excel file IO that will probably take care of much of the date-munging.</p>\n\n<p>If you want to carry on with the inte...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T17:58:27.540", "Id": "47077", "Score": "1", "Tags": [ "python", "beginner", "numpy", "csv", "pandas" ], "Title": "Parse Bloomberg Excel/CSV with Pandas DataFrame" }
47077
<p>Web scraping is the use of a program to simulate human interaction with a web server. A common goal is to extract specific information from a web server, especially from web pages whose contents are intended for human consumption rather than machine interpretation. It is usually considered to be a fragile techniqu...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T18:38:26.690", "Id": "47080", "Score": "0", "Tags": null, "Title": null }
47080
Web scraping is the use of a program to simulate human interaction with a web server or to extract specific information from a web page.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T18:38:26.690", "Id": "47081", "Score": "0", "Tags": null, "Title": null }
47081
<p>I'm doing some high energy physics modelling in C++. I have written code that implements class that score interactions of particles with detector material. </p> <p>Here is a base class: </p> <pre><code>class XYZScorer: public virtual AbstractScorer{ public: XYZScorer(double material_rad_len=-1): Abst...
[]
[ { "body": "<p>I need a bit to look into a cleaner decorator pattern, but three technicalities immediately jump out at me.</p>\n\n<hr>\n\n<p>Accepting a user defined value as const implies that your methods should probably be taking const-references. <code>void f(const T)</code> will make a copy of the value pas...
{ "AcceptedAnswerId": "47097", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T19:32:33.927", "Id": "47083", "Score": "14", "Tags": [ "c++", "c++11", "template", "template-meta-programming" ], "Title": "Compile time decorator pattern in C++ with templ...
47083
<p>Now that I've got this working, any improvements that I can make to better my code review would be helpful.</p> <pre><code>import random import math import console console.set_font('Arial-BoldMT',15) print'Welcome to the guessing game!\nA number will be randomly chosen from 0 to 1000.\nThe player will make a gues...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T23:15:14.890", "Id": "82516", "Score": "1", "body": "I would recommend diving into the world of functions. It will help you better organise your sections, and be easier to debug http://codereview.stackexchange.com/questions/46482/ba...
[ { "body": "<ol>\n<li><p><code>player_score&gt;=computer_score</code> makes the computer win even when they score the same. A comparison should be <code>&gt;</code> instead of <code>&gt;=</code> (same for the next clause).</p></li>\n<li><p>The game, as coded, may terminate early (before reaching 5 rounds). For m...
{ "AcceptedAnswerId": "47295", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T20:11:59.600", "Id": "47086", "Score": "6", "Tags": [ "python", "beginner", "game", "python-2.x", "number-guessing-game" ], "Title": "Guessing Game in Python" }
47086
<p>This is solution to the assembly line problem. <a href="http://www.geeksforgeeks.org/dynamic-programming-set-34-assembly-line-scheduling/" rel="noreferrer">Here</a> is complete description, which is too big and verbose to re-describe. I apologize for the inconvenience of the hyperlink.</p> <p>Note: I do understand...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T20:46:54.607", "Id": "82468", "Score": "0", "body": "I think you misunderstood the problem statement given that you assign two transition times for each station. There's only one transition time per station per line: the time it wou...
[ { "body": "<p>The code implementing the core algorithm is very cumbersome. This is partly due to shoehorning the line entry/exit times into the first/last stations as evidenced by some internal stations in your tests having unusable exit times. But the code duplication doesn't help either.</p>\n\n<blockquote>\n...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T20:16:06.223", "Id": "47088", "Score": "8", "Tags": [ "java", "algorithm", "dynamic-programming" ], "Title": "Assembly line scheduling" }
47088
<p>Is it recommended to combine two similar methods into one?</p> <pre><code>public void initialize_board(){ for(int y = 0; y &lt; board.length; y++){ for(int x = 0; x &lt; board.length; x++){ if(x == 0) board[x][y] = (char)y; else board[x][y] = '~'; ...
[]
[ { "body": "<p>By the Single Responsibility Principle, they should remain separate methods. Furthermore, <code>initialize_board()</code> should probably be a constructor for a <code>Board</code> class, and <code>display_board()</code> should be its <code>toString()</code>.</p>\n", "comments": [ { ...
{ "AcceptedAnswerId": "47093", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T20:45:17.597", "Id": "47090", "Score": "11", "Tags": [ "java" ], "Title": "Similar methods using loops" }
47090
<p>I'm writing a set of simple widgets for a microcontroller application. I'd like to use the observer pattern to pass around events: when a button is clicked, when a timeout occurs - there are many uses which I'm currently implementing with very ugly glue code, with similar code occuring again and again.</p> <p>The w...
[]
[ { "body": "<p>Some tidbits about using C++11 features efficiently:</p>\n\n<ul>\n<li><p>I find that the old <code>typedef</code> is rather hard to read for function pointers. You could refactor this line:</p>\n\n<pre><code>typedef ReturnType (T::*ObjMemFn)(args...);\n</code></pre>\n\n<p>into this one using a C++...
{ "AcceptedAnswerId": "47106", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T21:42:30.050", "Id": "47098", "Score": "6", "Tags": [ "c++", "c++11", "delegates" ], "Title": "Delegate and Observer pattern implementation for an embedded system" }
47098
<p>I have started learning programming in ObjC from <em>"Objective-C Programming: The Big Nerd Ranch Guide"</em></p> <p>In a task to exercise the learned stuff I've had to write a program what compares the the names in the file /usr/share/dict/words if there are same proper names (capitalized) and normal words (uncapi...
[]
[ { "body": "<p>The first most glaring problem I see is <code>sleep(2)</code>. We really don't want to be doing this, particularly with Objective-C programs. The main reason I add emphasis on Objective-C is because virtually every program written in Objective-C is either an OSX or iOS app with a GUI. And in th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-09T14:20:17.283", "Id": "47100", "Score": "4", "Tags": [ "objective-c" ], "Title": "Compare words in one file" }
47100
<p>I have the class below to manage my specific implementation of a membership system using entity framework 6.1</p> <p>Is the use of static access correct in this case? as far as I understood that EF context is not thread-safe so I'm instantiating one with every call through the <code>using</code> statement. My secon...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T02:52:49.947", "Id": "82538", "Score": "0", "body": "If you're using .NET 4.5, then there are new ASync methods for all of your query methods, which will allow you to multi-thread calls to the database." } ]
[ { "body": "<p>umm yes, you could do it that way.</p>\n\n<blockquote>\n <p>as far as I understood that EF context is not thread-safe so I'm\n instantiating one with every call through the using statement</p>\n</blockquote>\n\n<p>Where did you read this? I'm not denying it it's just that I have not read this b...
{ "AcceptedAnswerId": "47109", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T22:20:47.110", "Id": "47104", "Score": "4", "Tags": [ "c#", "asp.net", "entity-framework", "asp.net-mvc-3", "authentication" ], "Title": "Using static management class ...
47104
<p>I want to interpolate temperature in correlation with height. I have temperature data from stations with coordinates and height in this format:</p> <pre><code>Lat Lon Temp Height 46.2956 16.3978 10.71196 120 45.9776 16.0159 11.78539 150 45.8521 15.9598 11.18838 133 etc. </code></pre> <p>After readi...
[]
[ { "body": "<p>The problems start with this code being fairly unreadable. A few simple rules can help:</p>\n\n<ul>\n<li><p>Every comma is followed by a space: <code>xi, yi</code> instead of <code>xi,yi</code>.</p></li>\n<li><p>Every binary operator like <code>+</code> is surrounded by a space on each side: </p>\...
{ "AcceptedAnswerId": "47148", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T23:24:12.900", "Id": "47110", "Score": "13", "Tags": [ "python", "performance", "mathematics", "numpy", "geospatial" ], "Title": "Temperature Interpolation" }
47110
<p>A project I was working on required the usage of the Separating Axis Theorem to detect collisions between two convex polygons in real time. So I implemented a basic class (<code>ConvexFrame</code> in the code) to keep track of the information about the polygon that is necessary for the SAT algorithm. I implemented i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T15:07:10.467", "Id": "82600", "Score": "2", "body": "Rather than look for ways to optimise, I would recommend profiling your code, for example with [cProfile](https://docs.python.org/3.4/library/profile.html#module-cProfile), to see...
[ { "body": "<h3>1. Vectors</h3>\n\n<p>Much of this code is awkward and long-winded because points and vectors are represented by plain Python tuples. A simple operation like subtracting two points requires disassembling the points into their elements, subtracting the elements, and then reassembling the result. I...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-13T23:43:30.823", "Id": "47111", "Score": "7", "Tags": [ "python", "performance", "python-3.x", "computational-geometry", "collision" ], "Title": "Implementation of SAT (Sepa...
47111
<p>This finds the equilibrium. For <code>sum/mult</code> an equilibrium is defined as the <code>index i</code> at which sum/mult of all elements at <code>index &lt; i</code> is same as sum/mult of all elements of at <code>index &gt; j</code> respectively. Edge cases are documented clearly in JavaDocs.</p> <p>Note: I d...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T08:50:39.177", "Id": "82564", "Score": "0", "body": "just for understanding, should the `leftSum += a[i];` operation not instead happen before the comparison?" } ]
[ { "body": "<p>I've had a look at your code, and come up with the following suggestions.</p>\n\n<p>Firstly, rename your variables to something meaningful:</p>\n\n<pre><code>public static double getMultEquilibrium(int[] a\n</code></pre>\n\n<p>change this too:</p>\n\n<pre><code>public static double getMultEquilibr...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T00:51:41.610", "Id": "47114", "Score": "5", "Tags": [ "java", "algorithm" ], "Title": "Find the sum and multiply equilibrium" }
47114
<p>MVP is a user interface architectural pattern engineered to facilitate automated unit testing and improve the separation of concerns in presentation logic:</p> <ul> <li>The model is an interface defining the data to be displayed or otherwise acted upon in the user interface.</li> <li>The view is a passive interface...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T02:00:30.600", "Id": "47117", "Score": "0", "Tags": null, "Title": null }
47117
Model View Presenter is a Derivative of MVC, used for creating user interfaces.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T02:00:30.600", "Id": "47118", "Score": "0", "Tags": null, "Title": null }
47118
<p>I would like to give it a try and ask about my codes on here from now on to see if there are improvement for'em</p> <p>this code is supposed to combine two sql tables into one.</p> <pre><code>SELECT * FROM (SELECT * FROM posts WHERE id &lt; $lastpost AND position = submitter order by id DESC LIMIT 5) t1 JOIN (SELE...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T07:44:59.230", "Id": "82560", "Score": "0", "body": "Why the sub-query, and why write a union-like query without the `UNION` keyword" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T09:11:18.820", ...
[ { "body": "<p>Assuming that each post has exactly one submitter, this is a more natural formulation of the query.</p>\n\n<pre><code>SELECT posts.*\n , users.username\n , users.firstname\n , users.lastname\n , users.avatar\n FROM posts\n JOIN users\n ON posts.submitter = user...
{ "AcceptedAnswerId": "47135", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T04:56:09.273", "Id": "47121", "Score": "7", "Tags": [ "mysql", "sql", "join" ], "Title": "A faster way to combine two SQL table" }
47121
<p>A <strong>very</strong> simple Thread pool:</p> <p>Any work added to the pool will be executed. The destructor will wait for all work to be finished before letting the threads stop. We then join all threads before letting the destructor exit.</p> <pre><code>#include &lt;thread&gt; #include &lt;mutex&gt; #include &...
[]
[ { "body": "<p>On startup a lot of the code is there to deal with making sure that threads don't start work until the SimpleWorkQueue object is correctly initialized.</p>\n<p>This work is not related to the work queue and should be factored out into its own class.</p>\n<p>The concept of a barrier was mentioned i...
{ "AcceptedAnswerId": "48247", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T05:51:14.123", "Id": "47122", "Score": "15", "Tags": [ "c++", "multithreading" ], "Title": "A simple Thread Pool" }
47122
<p>This code animates my main game sprite by increasing the animation frame. First I check if the character is moving, then I increase the animation counter until it reaches the desired speed, and then if so, I increase the animation frame.</p> <p>How can I make it more elegant and optimised in terms of speed?</p> <p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T07:08:34.743", "Id": "82551", "Score": "0", "body": "quick question, why do you need to reset the anispeed when increasing the animationframe by one? I don't understand why you do this... Your posted code also misses the closing bra...
[ { "body": "<p>Two small comments:</p>\n\n<p><strong>Naming:</strong><br>\nThe convention for variable names in Java is <code>camelCase</code>. Your <code>animationframe</code> should instead be <code>animationFrame</code> when going by that rule. Similar for your <code>animaxspeed</code>. You don't have to save...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T06:51:29.680", "Id": "47124", "Score": "5", "Tags": [ "java", "animation" ], "Title": "Game sprite animation" }
47124
<p>Return any three descending numbers that appear sequentially in the input such that A[i] > A[j] > A[k] and i &lt; j &lt; k. Since problem description contains 'any', I could not unit test using JUnit.</p> <p>I'm looking for request code review, optimizations and best practices. </p> <pre><code>final class Descendi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T08:13:53.190", "Id": "82563", "Score": "1", "body": "sequentially meaning that `k = j-1, j = i-1`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T13:00:36.503", "Id": "82581", "Score": "1", ...
[ { "body": "<blockquote>\n <p>Return any three descending numbers that appear sequentially in the input such that A[i] > A[j] > A[k] and i &lt; j &lt; k. \n Since problem description contains 'any', I could not unit test using junits.</p>\n</blockquote>\n\n<p>I think you could create inputs for tests where </p...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T07:18:15.843", "Id": "47126", "Score": "3", "Tags": [ "java", "algorithm", "array" ], "Title": "Given an integer array of size n, find any three numbers" }
47126
<p>It has been a while since I've implemented a QuickSort and I wanted to write it down like I remembered.</p> <pre><code>int MyPartition(List&lt;int&gt; list, int left, int right) { int pivot = list[left]; while(true) { while(list[left] &lt; pivot) left++; while(list[right] &...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-12-08T23:07:09.507", "Id": "131764", "Score": "0", "body": "why do you check if pivotIDX > 1" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-04-10T10:51:42.420", "Id": "233784", "Score": "0", "body": ...
[ { "body": "<p>With QuickSort, the complexity always comes down to two things:</p>\n\n<ul>\n<li>how you deal with equal numbers (duplicates)</li>\n<li>which index you use to return from the partition (left or right)</li>\n</ul>\n\n<p>You need to decide up-front whether the pivot value is going to be in the left ...
{ "AcceptedAnswerId": "47142", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T07:41:41.270", "Id": "47128", "Score": "20", "Tags": [ "c#", "algorithm", "sorting", "quick-sort" ], "Title": "QuickSort C# Implementation" }
47128
<p>I'm trying to implement String-Pool. I'm maintaining a <code>HashMap&lt;String,String&gt;</code> to store the keys.</p> <pre><code>public class TestStringCaching { static Map &lt; String, String &gt; cache = new HashMap &lt; String, String &gt; (); public static void main(String[] args) { int iter =...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T13:17:23.060", "Id": "82585", "Score": "3", "body": "What happens if you have `generateString2(){ return \"abc\";}` ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T13:23:02.047", "Id": "82586", ...
[ { "body": "<h2>generateString</h2>\n\n<ul>\n<li>It creates <code>8000000</code> <code>String</code> instances on the heap and stores their references in the array. </li>\n<li>Every array slot refers to a different <code>String</code> instance.</li>\n<li>It uses more memory and GC might use a lot of CPU time.</l...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T13:05:11.627", "Id": "47141", "Score": "15", "Tags": [ "java", "strings", "cache", "reinventing-the-wheel" ], "Title": "Why does caching of string objects perform faster?" }
47141
<p>I have been looking through Code Review on the subject of Unit of Work and Repository patterns and realised that my implementation appears to provide very similar functionality but in reverse class order/hierarchy. (Couldn't think of a better way to describe it sorry)</p> <p><a href="https://codereview.stackexchang...
[]
[ { "body": "<p>I get what you mean by \"reversed\":</p>\n\n<p><img src=\"https://i.stack.imgur.com/sdjXl.png\" alt=\"unit-of-work depends on repository\"></p>\n\n<p>As opposed to:</p>\n\n<p><img src=\"https://i.stack.imgur.com/qBS8o.png\" alt=\"repository depends on unit-of-work\"></p>\n\n<p>Makes sense, at leas...
{ "AcceptedAnswerId": "47180", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-04-14T14:01:12.637", "Id": "47144", "Score": "8", "Tags": [ "c#", "entity-framework", "asp.net-mvc", "repository" ], "Title": "MVC 5 & EF 6 - Repository & Unit of Work Pattern" }
47144
<p>I have three JavaScript objects. The first one serves merely as a prototype. The other two are implementation of a specific type.</p> <pre><code>var MainPrototype = {}; var SpecificType = $.extend(Object.create(MainPrototype)); var OtherSpecificType = $.extend(Object.create(MainPrototype)); </code></pre> <p>I am ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T14:39:00.050", "Id": "82597", "Score": "2", "body": "What is the goal of this code?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T15:23:08.610", "Id": "82601", "Score": "1", "body": "Any...
[ { "body": "<p>Why wouldn't you create a method with a unique name accross all subclasses? In this way you don't have to generically build a function name, which can be a pain to maintain code / refactor</p>\n\n<p>For instance :</p>\n\n<pre><code>var MainPrototype = {\n bind: function() {\n //generic s...
{ "AcceptedAnswerId": "47149", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T14:16:12.333", "Id": "47145", "Score": "4", "Tags": [ "javascript", "optimization", "jquery", "object-oriented" ], "Title": "Should I differentiate object types by calling ...
47145
<p>I'm learning how to use Python with the Raspberry Pi. I successfully followed the tutorial for how to have a Python script run on the Pi to check for new email and turn on an LED if any new messages are in an inbox. I wanted to give myself a challenge by adding a feature to blink a secondary LED to indicate the numb...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T18:18:39.130", "Id": "82805", "Score": "1", "body": "I would replace `Thread.__init__(self)` with the `super(Repeat, self).__init__()` as it is a better way of calling base functions." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>That looks about right. Your thread doesn't do very much, though, so you might want to consider something like so (untested):</p>\n\n<pre><code>def blink(abort, delay, count):\n while not abort.isSet():\n for x in range(0, count):\n print \"blink\", x + 1\n GPIO.out...
{ "AcceptedAnswerId": "47359", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T14:46:27.027", "Id": "47147", "Score": "5", "Tags": [ "python", "multithreading", "python-2.x", "raspberry-pi" ], "Title": "Raspberry Pi LED for new emails" }
47147
<p>I would like a review for this code which is used apparently successfully in my current project. More info are available in <a href="https://gist.github.com/Klaim/10599137">this gist</a> but I'm pasting here the main info:</p> <blockquote> <p>The project use C++11/14 as provided by VS2013 (no CTP) and Boost. I ...
[]
[ { "body": "<p>I don't see any real problem, only tidbits and things that could potentially be done differently:</p>\n\n<ul>\n<li>Your header guard name is actually <a href=\"http://en.cppreference.com/w/cpp/language/identifiers\" rel=\"nofollow\">reserved to the implementation</a> since it uses a double undersc...
{ "AcceptedAnswerId": "47492", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T15:45:54.920", "Id": "47152", "Score": "9", "Tags": [ "c++", "c++11" ], "Title": "AnySetValue - a set of with multiple types of values" }
47152
<p>My original code is <a href="https://codereview.stackexchange.com/questions/41531/installing-mods-with-python">here</a>. I made some changes to it based on your suggestions, but then I lost my flash drive and had to redo it. I have a suspicion that my second version was better than this one, so could you all help me...
[]
[ { "body": "<p>I'll leave an in-depth analysis to the true Python experts, but here are just some quick notes:</p>\n\n<p><strong>Variable and function names</strong>: As far as I'm aware, variable and function names should have words/elements separated by underscores (e.g., <code>check_dirs</code>, <code>is_file...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T16:00:45.243", "Id": "47153", "Score": "4", "Tags": [ "python", "python-3.x", "file-system" ], "Title": "Installing Mods With Python (v 2.0)" }
47153
<p>I just started coding a simulation-like application. It's about our solar system. Right now, I'm working on rotating the moon. I have this <code>constructor</code></p> <pre><code>function Mass(elm) { if (typeof elm == "string") { this.elm = document.getElementById(elm); } else { this.elm = e...
[]
[ { "body": "<p>For one, you don't want to pass a string to <code>setInterval()</code>; better to use a function. You can bind that function to the object's context, so it'll call the right thing.</p>\n\n<p>For another, aim for less ambiguous names. <code>rotation</code> should probably be <code>updateRotation</c...
{ "AcceptedAnswerId": "47159", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T16:13:11.893", "Id": "47155", "Score": "3", "Tags": [ "javascript", "css", "simulation", "animation" ], "Title": "Single Rotate Method" }
47155
<p>I have implemented Tic-Tac-Toe so that human can play with the computer, where the computer should never lose. I did a simple analysis before implementing, and I found out that there are certain cells you want to occupy (I named it BEST_CELLS).</p> <p>Here is the link to the implementation: <a href="https://github...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T21:25:01.050", "Id": "83445", "Score": "1", "body": "http://xkcd.com/832/" } ]
[ { "body": "<p>There's a lot of code there, so I'll just pick out a some things.</p>\n\n<p>From a bird's eye view, it looks like there's just too much code. That's my initial gut feeling without looking at any of it in-depth. It just seems like you're working too hard.</p>\n\n<p>Also:</p>\n\n<ol>\n<li>Comment yo...
{ "AcceptedAnswerId": "47581", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T16:28:49.490", "Id": "47158", "Score": "1", "Tags": [ "algorithm", "object-oriented", "ruby", "design-patterns" ], "Title": "Tic-Tac-Toe implementation where computer shoul...
47158
<p>This is my attempt at Conway's Game of Life. It works, and it's the most complicated program I've made to date. I'm sure it's pretty poorly done. Any ideas on how I can improve on it?</p> <pre><code>#include &lt;iostream&gt; #include &lt;cstdlib&gt; const int gridsize = 75; //Making this a global constant to avo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T05:23:21.600", "Id": "82871", "Score": "7", "body": "I don't know if anyone has seen this before, but if you Google Conway's Game of Life, it actually has a live one running on the results page." } ]
[ { "body": "<p>One major thing: <em>do not pass C-arrays to functions as they will decay to a pointer</em>.</p>\n\n<p>In C++, you should just use storage containers (from the standard library or Boost) instead of C-arrays, which are more proper for passing storage data to functions (they will not decay to a poin...
{ "AcceptedAnswerId": "47179", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T18:35:14.217", "Id": "47167", "Score": "42", "Tags": [ "c++", "game-of-life" ], "Title": "Conway's Game of Life in C++" }
47167
<p>I would like this to happen every time I run a program from the command line. Is my approach Pythonic? I'm interested to know whether there is any problem with readability or correctness. Any general advice on better ways of doing things or potential problems are also welcome.</p> <p>Although the <code>main</code> ...
[]
[ { "body": "<p>Make it a habit to run <code>pyflakes</code> and the <code>pep8</code> tools on Python projects. <code>pep8</code> finds some style violations in this code:</p>\n\n<ul>\n<li>There should be two blank lines before global method declarations (<code>main</code> and <code>_doctests_pass</code> in your...
{ "AcceptedAnswerId": "47177", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T18:49:11.893", "Id": "47170", "Score": "10", "Tags": [ "python", "unit-testing", "assertions" ], "Title": "Automatically run doctest every time program is run" }
47170
<p>Please be brutal, and judge my code as if it was written at a top 3 tech company, straight out of college. (The method signature, and input parameter is given by the problem, so don't worry about that)</p> <p>Worst case complexity: \$ O \left( n^2 \right) \$</p> <p>Space complexity: \$ O \left( n \right) \$</p> <...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T22:11:11.720", "Id": "82663", "Score": "0", "body": "MathJax usage will always earn a +1 from me! :)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T13:40:12.430", "Id": "82752", "Score": "0",...
[ { "body": "<h1>Complexity</h1>\n\n<p>Your answer is \\$O(n^3)\\$ and not \\$O(n^2)\\$. You have three levels of nested loops... two inside the <code>longestPalindrome()</code> method and another inside the <code>isPalindrome()</code>.</p>\n\n<p>Can this problem be solved with less complexity? I believe it is po...
{ "AcceptedAnswerId": "47183", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T21:47:25.157", "Id": "47181", "Score": "17", "Tags": [ "java", "algorithm", "interview-questions", "palindrome" ], "Title": "Longest palindrome in a string" }
47181
<p>From <a href="http://en.wikipedia.org/wiki/Insertion_sort">Wikipedia</a>:</p> <blockquote> <p>Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data, finds the location it belongs within t...
[]
[ { "body": "<ul>\n<li><p>More whitespace here:</p>\n\n<blockquote>\n<pre><code>for(int j=i-1; j&gt;-1; j--)\n</code></pre>\n</blockquote>\n\n<p>could help improve readability, especially when glancing at it:</p>\n\n<pre><code>for (int j = i - 1; j &gt; -1; j--)\n</code></pre></li>\n<li><p>This line:</p>\n\n<bloc...
{ "AcceptedAnswerId": "47189", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T22:53:12.303", "Id": "47184", "Score": "17", "Tags": [ "c++", "sorting", "insertion-sort" ], "Title": "Insertion Sorting in C++" }
47184
<p>Currently I'm using a binary search algorithm to search an index of a tree that represents an XML file.</p> <p>Can I use heuristics to improve the search? What can I do to improve this search function?</p> <p>Here is my search function, in PHP, so far:</p> <pre><code>public function search($key) { // split th...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T22:59:12.790", "Id": "47185", "Score": "1", "Tags": [ "php", "search", "binary-search" ], "Title": "Binary search with heurisitcs or something else" }
47185
<p>How can I improve the <code>string RecvData()</code> function?</p> <pre><code>std::string Socket::RecvData() { std::string strBuffer; do{ char buffer; int recvInt = recv(s_, &amp;buffer, 1, 0); if (recvInt == INVALID_SOCKET) { return ""; } if (recv...
[]
[ { "body": "<ol>\n<li><p>Change the name. The function returns when it sees a newline, so the correct name is <code>RecvLine</code> or something similar.</p></li>\n<li><p><code>recv</code> returns -1 on any error. The way your code is structured, it would bail out without testing the <code>errno</code>.</p></li>...
{ "AcceptedAnswerId": "47198", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T23:49:26.840", "Id": "47187", "Score": "6", "Tags": [ "c++", "socket" ], "Title": "Optimize RecvData wrapper" }
47187
<p>This is the current Makefile that I use with my C projects. Here is what I would like to be reviewed:</p> <ol> <li><p><strong>Reusability</strong> - is this Makefile easy to use for multiple separate projects with minimal modification?</p></li> <li><p><strong>Organization</strong> - is this Makefile organized in a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T08:36:53.243", "Id": "82717", "Score": "0", "body": "Question is why would you use and (more importantly) create by hand Makefiles? For any project that exceeds few files (and spans over more than one directory) Makefiles become ver...
[ { "body": "<p>Dependencies: right now your makefile will let changes in <code>.h</code> to remain unnoticed.</p>\n\n<pre><code>DEPS := $(SOURCES:.c=.d)\n\n.c.d:\n $(CC) -o $&lt; -MM $(CFLAGS)\n\n-include $(DEPS)\n</code></pre>\n\n<p>PS: it is highly recommended to remove <code>-c</code> from CFLAGS and menti...
{ "AcceptedAnswerId": "47197", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T00:00:02.220", "Id": "47188", "Score": "17", "Tags": [ "c", "makefile" ], "Title": "C Makefile boilerplate" }
47188
<p>I have a few objectives (which are working fine, but I want tips in case I can improve it).</p> <p>Let me try to make this as clear as possible, as this is a <em>much</em> larger project:</p> <p>There are <strong>three</strong> move categories:</p> <ul> <li><code>Hammer</code> (10 damage)</li> <li><code>Scythe</c...
[]
[ { "body": "<p>Ahh, the origins of a simulator. I have always wanted to create one of those. Anyways...</p>\n\n<p>I suggest you model this all in the JS. If you follow MVC, then all data (or most of it) live in the Model, the data storage. The View would be the HTML, and all event handlers like clicks, change, h...
{ "AcceptedAnswerId": "47194", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T02:01:14.510", "Id": "47192", "Score": "3", "Tags": [ "javascript", "jquery", "html", "dom" ], "Title": "HTML/Attrs Tester Environment" }
47192
<p>I'm planning to transition from years of forced procedural programming to OOP. I decided I'd start off small with a little gumball machine object to get my bearings. Everything seems to run ok, but I feel strange having all these globals in my class. </p> <p>Code in action <a href="http://artfuladvection.com/proj...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T02:50:19.223", "Id": "82868", "Score": "0", "body": "Yes, I know this is pretty terrible OOP code. I wanted to know just how terrible. Thanks for all the feedback! Especially guy who emailed me about this :)" } ]
[ { "body": "<p>First of all, all your gumballs counters have no good reason to be global. As they are part of the state of the gumball machine, why don't you make the counters instance variables?</p>\n\n<p>Also, there might be a much more concise way to handle this counters : instead of having multiple variables...
{ "AcceptedAnswerId": "47244", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T03:39:04.713", "Id": "47199", "Score": "5", "Tags": [ "php", "object-oriented" ], "Title": "Avoiding globals in gumball machine class" }
47199
<p>I've hodgepodged together an attempt to extract all phone numbers from all CSVs in a directory, regardless of where they are and what format they're in. I want all phone numbers to be printed to a compilation CSV with no repeat elements in the format <code>8885551234</code> with NO leading ones. E.g., <code>1 (510...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T05:49:21.780", "Id": "82707", "Score": "0", "body": "You say that you intend to strip out the country code, but I don't see that happening in the code." } ]
[ { "body": "<p>Simple comments here :</p>\n\n<ul>\n<li><p>You don't need both <code>seen</code> and <code>output</code>: the set will be enough to store the unique numbers and print them later on.</p></li>\n<li><p>You should keep your reading logic and your writing logic independent by performing the former and ...
{ "AcceptedAnswerId": "47204", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T05:10:10.327", "Id": "47201", "Score": "2", "Tags": [ "python", "strings", "regex", "python-2.x", "csv" ], "Title": "Speeding up and fixing phone numbers from CSVs with...
47201
<p>This is how I read the keyboard in my game:</p> <pre><code> @Override public void keyPressed(KeyEvent key) { keypressed=true; if (key.getKeyCode() == KeyEvent.VK_UP) { keyup=true; } if (key.getKeyCode() == KeyEvent.VK_DOWN) { keydown=true; } if (key.getKeyCode() == ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T07:42:51.857", "Id": "82716", "Score": "3", "body": "So you've succeeded in setting some variables based on the keys pressed. Then what do you do with all those variables?" } ]
[ { "body": "<p>Yes there is. As <code>KeyEvent</code> is an enumeration type, you can instead use a <code>switch</code>-statement:</p>\n\n<pre><code>char key;\nboolean isSpecialKey = false;\nSpecialKey specialKeyValue;\nswitch(key.getKeyCode()){\n case KeyEvent.VK_UP:\n key = '';\n isSpecialkey = ...
{ "AcceptedAnswerId": "47209", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T07:39:17.683", "Id": "47208", "Score": "2", "Tags": [ "java", "game", "event-handling" ], "Title": "Reading keyboard input" }
47208
<p>(continuation from <a href="https://codereview.stackexchange.com/questions/47201/speeding-up-and-fixing-phone-numbers-from-csvs-with-regex">Speeding up and fixing phone numbers from CSVs with Regex</a>)</p> <p>I'm pulling all of the phone numbers from all CSVs in two different directories, outputting them in a sing...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T17:12:30.053", "Id": "82794", "Score": "0", "body": "Some of the operations on built-in sets might make your code simpler (and possibly faster): https://docs.python.org/2/library/stdtypes.html#set" } ]
[ { "body": "<p>Here's my 5 cents as non-python guy</p>\n<h3>Naming:</h3>\n<p>As soon as you begin numbering variable names, there should be alarm bells ringing... multiple <strong>loud</strong> alarm bells.</p>\n<p>rename your <code>out</code>, <code>out2</code>, and the corresponding writers. Instead use descri...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T08:01:18.923", "Id": "47210", "Score": "5", "Tags": [ "python", "python-2.x", "csv" ], "Title": "Comparing phone numbers across CSVs Python" }
47210
<p>I have an array of objects that I must sort based on two criteria. I've come up with a solution but I'd like to know if there is a better way to do it.</p> <p>Assume a list of devices:</p> <pre><code>[ {"battery_level": 0.45, "network_status": "ok"}, {"battery_level": 0.45, "network_status": "ok"}, {"b...
[]
[ { "body": "<p>There is a better way, use a single sort function where you check on both values. If network status is different, sort on that, otherwise sort on battery power:</p>\n\n<pre><code>var devices = JSON.parse(document.getElementById('devices').innerHTML);\n\nfunction sortDevicesByStatusAndPower(a, b) {...
{ "AcceptedAnswerId": "47219", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T10:39:10.443", "Id": "47218", "Score": "4", "Tags": [ "javascript", "array", "sorting" ], "Title": "Multicriteria sort array" }
47218
<p>I have a working restaurant menu system - as the user selects a menu it slides into view. The build is responsive, and I've used the 'Debounced Resize() jQuery Plugin'. However, in implementing the responsive code, I feel my code has become clunky, and it needs refactoring.</p> <p>The hope here is that I'll receive...
[]
[ { "body": "<p>Some of your code is redundant. These two lines are mutually exclusive. Especially since you add \"active\" to the first menu item, which is the only one which would satisfy !active.</p>\n\n<pre><code> if (!active) {\n .removeClass('active') // remove the active class from any that ha...
{ "AcceptedAnswerId": "47226", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T11:01:22.343", "Id": "47220", "Score": "5", "Tags": [ "javascript", "performance", "beginner", "jquery", "html" ], "Title": "Responsive jQuery restaurant menu system" }
47220
<p>This is my first time writing a game in C++/SDL and I decided to post the code here so you can tell me what I am doing wrong.</p> <p><strong>main.cpp</strong></p> <pre><code>#include &lt;SDL.h&gt; #include "Game.h" int screenWidth = 640; int screenHeight = 480; const char* title = "Pong Clone"; Game game; int m...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T19:54:40.660", "Id": "82820", "Score": "0", "body": "I should note that the last two questions are off-topic as we don't assist in adding additional functionality. For such questions, consult Stack Overflow." } ]
[ { "body": "<p>This is just a quick partial review. I can't comment on the SDL parts because I know very little about SDL.</p>\n\n<p><em>main.cpp</em></p>\n\n<p>Avoid global mutable state. All of the variables shown below could be made local.</p>\n\n<pre><code>int screenWidth = 640;\nint screenHeight = 480;\ncon...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T11:08:56.173", "Id": "47221", "Score": "6", "Tags": [ "c++", "game", "sdl" ], "Title": "SDL/C++ Pong clone" }
47221
<p>I have been researching and experimenting with HTML5 and CSS3. I was aiming to create a very simple but efficient tiled gallery / grids. So some sort of grid system that I can layout anything inside.</p> <p>Below is what I have created, what are your opinions? I also have a question, why the distributing of the ima...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T18:18:08.663", "Id": "82803", "Score": "0", "body": "Have you looked at bootstrap? http://getbootstrap.com/" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T12:54:54.213", "Id": "83154", "Score...
[ { "body": "<p>Very impressive! I forgot that this tech existed. Anyways, <a href=\"http://jsbin.com/yugujaji/1/\" rel=\"nofollow\">off to review</a>:</p>\n\n<h1>Prefixes and Indentations</h1>\n\n<p><code>column-count</code> will be bound to prefixes for quite a while, since <a href=\"http://caniuse.com/multicol...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T11:22:46.820", "Id": "47222", "Score": "6", "Tags": [ "performance", "html", "css", "html5" ], "Title": "Simple grid system made out of CSS columns" }
47222
<p>I have made a gallery function, this function handles three different types of gallery, one with horizontal nav, other vertical and last one vertical with no nav.</p> <pre><code>function vid() { var vid = $(".videoBg"), btn = $(".wVid"), wrap = $(".home"); $(wrap).css({ "margin-top":...
[]
[ { "body": "<h1><code>var</code> per variable</h1>\n\n<p>It's personal preference, but it's a practical preference. If you had something like this in the middle of the code:</p>\n\n<pre><code>var vid = $(\".videoBg\"),\nbtn = $(\".wVid\"),\nwrap = $(\".home\");\n</code></pre>\n\n<p>You would readily think \"Oh, ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T11:25:46.343", "Id": "47223", "Score": "6", "Tags": [ "javascript", "optimization", "jquery" ], "Title": "Three layout Gallery" }
47223
<p>Objective:</p> <p>I want to import an Excel file, and read the rows of certain columns. For this, I use <code>ExcelDataReader</code>. I've implemented a low-level class called <code>ExcelData</code> which uses the <code>ExcelDataReader</code> and does things like figuring out if it is an ".xls" of ".xslx" file (or ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T12:43:58.537", "Id": "82740", "Score": "3", "body": "This code does not work with all Excel-files... Keep in mind there are also some other EXCEL-File endings. `\".xlsm\"` and `\".xlsb\"`, as well as the template types..." }, { ...
[ { "body": "<p>Simplify your catch-chain</p>\n\n<pre><code>static void Main(string[] args)\n{\n try\n {\n ReadInData readInData = new ReadInData(@\"C:\\SC.xlsx\", \"sc_2014\");\n IEnumerable&lt;Recipient&gt; recipients = readInData.GetData();\n }\n catch (Exception ex)\n {\n i...
{ "AcceptedAnswerId": "47246", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T12:14:59.560", "Id": "47227", "Score": "14", "Tags": [ "c#", "exception-handling", "io", "excel" ], "Title": "Reading data from Excel sheet with ExcelDataReader" }
47227
<p>I have a security manager I'm writing for a Java program, and within the checkRead method, I wish to only allow reads to files within a given directory.</p> <p>The basis of it is that it will get a canonical file for the input (which is actually a string as per the method contract). It will then begin taking the fi...
[]
[ { "body": "<h1>Nit-Picks</h1>\n\n<p>This exception-handling code should include the IOException as part of the SecurityException re-throw:</p>\n\n<pre><code>try {\n tested = new File(file).getCanonicalFile();\n} catch (IOException e1) {\n // set the cause of the SecurityException so that users can potenti...
{ "AcceptedAnswerId": "47236", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T13:04:37.250", "Id": "47233", "Score": "8", "Tags": [ "java", "security", "file" ], "Title": "Checking if file is within a directory for security" }
47233
<p>I'm trying to manage several means of payment in my Rails 3.2 application.</p> <p>Let's say I have 2 means : Credit Cards &amp; Bank Transfers (BIC), working with 2 different payment providers. Those means both contain a reference string that will be sent to the payment provider to trigger new payments later. Each ...
[]
[ { "body": "<p>First: \"Means\" is uncountable in English; it's always plural. So the model should be called <code>PaymentMeans</code>, and associations should be <code>has_many :payment_means</code> and <code>has_one :payment_means</code>. You can set that up in Rails' inflections config (or just call it \"paym...
{ "AcceptedAnswerId": "47245", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T13:13:19.813", "Id": "47234", "Score": "0", "Tags": [ "ruby", "ruby-on-rails", "classes" ], "Title": "Managing several payment means in my Rails 3.2 app" }
47234
<p>My code looks like this:</p> <pre><code>public void checkIfCanDelete() throws BusinessException { boolean canDelete = canDelete(); if (canDelete) { checkIfLocked(); if(!editable) { throw new BusinessException(BusinessError.MSG_YOU_ARE_NOT_AUTHORIZED_TO_REMOVE_DOCUMENTS); ...
[]
[ { "body": "<p>right here:</p>\n\n<pre><code>boolean canDelete = canDelete();\n\nif (canDelete) {\n\n checkIfLocked();\n\n if(!editable) {\n throw new BusinessException(BusinessError.MSG_YOU_ARE_NOT_AUTHORIZED_TO_REMOVE_DOCUMENTS);\n }\n\n return;\n}\n</code></pre>\n\n<p>you can remove the Boo...
{ "AcceptedAnswerId": "47258", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T13:45:59.167", "Id": "47239", "Score": "10", "Tags": [ "java", "optimization" ], "Title": "Checking to see whether a document can be deleted" }
47239
<p>This is a follow-up: <a href="https://codereview.stackexchange.com/q/43318/37981">Python Hangman Program</a></p> <p>I'm working on adding a few features to my hangman game, and I just implemented two-player gameplay, in the form of one player chooses the word to be guessed while the other player guesses said word.<...
[]
[ { "body": "<p>One thing I would definitely change is the return type on functions like <code>increment_count</code>.\nYou don't want to leave a situation where the returns aren't logical... ie) in most cases, all possible return values of a function should return a consistent amount of variables, and have consi...
{ "AcceptedAnswerId": "47256", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T13:46:14.393", "Id": "47240", "Score": "8", "Tags": [ "python", "game", "python-2.x", "hangman" ], "Title": "2-player in a Python hangman game" }
47240
<p>I have implemented the Falling rocks game in C#. The instructions are simple: Don't get hit by rocks. The game is running quite well, however there are some bugs that occur and furthermore, I would like to receive advice whether I could make the code less complicated if possible.</p> <pre><code>using System; using ...
[]
[ { "body": "<p>A few things that should help. </p>\n\n<p>Instead of using a keyword <code>Object</code> for your custom object using a more descriptive name like <code>GameObject</code> makes it more obvious what the object's purpose is.</p>\n\n<p>Since there is a difference between the rocks and the dwarf but ...
{ "AcceptedAnswerId": "47302", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T13:50:14.703", "Id": "47243", "Score": "3", "Tags": [ "c#", "game", "console" ], "Title": "Falling Rocks Game" }
47243
<p>I think I've done a decent job keeping this query simple and understandable, but I'd like to know if you have some more advice.</p> <p>My relevant entities are defined like this:</p> <pre><code>public class Task { [ForeignKey("Employee")] public string EmployeeId { get; set; } public Employee Employee ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T15:04:30.637", "Id": "82778", "Score": "0", "body": "You could probably make the `&&`s into more `Where`s. Otherwise, I doubt you can change it much." } ]
[ { "body": "<ol>\n<li>Remove the additional <code>()</code>s in the <code>statusFilter</code> and <code>employeeFilter</code> lines as they are unnecessary.</li>\n<li>Indent the <code>statusFilter</code> and <code>employeeFilter</code> lines so that they are symmetrical with the <code>search</code> lines.</li>\n...
{ "AcceptedAnswerId": "47253", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T14:40:06.203", "Id": "47250", "Score": "3", "Tags": [ "c#", "linq", "entity-framework" ], "Title": "Retrieve Tasks by Employee" }
47250
<p>Here is some VB code that is part of a major system of apps that I have been asked to maintain, one of the more fun things that I get to do is rewrite some code here and there, I have done a little bit of that here, I finally have it functioning properly and would like to see if I am still on an upward stride in m...
[]
[ { "body": "<p>when I posted this I thought that I caught everything that I could think of, but looking at it again I noticed that I could use at least 2 more <code>Using</code> statements here:</p>\n\n<pre><code> Dim objCommand As New SqlCommand(SQLstr, cnn)\n\n Try\n ReadLetterText(ErrorLog)\n ...
{ "AcceptedAnswerId": "47265", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T15:58:30.170", "Id": "47257", "Score": "6", "Tags": [ "vb.net", "email" ], "Title": "Notify user of upcoming expiration of subscription" }
47257
<p>My PowerShell scripting skills are pretty poor, but I've managed to hobble together got this script:</p> <pre><code>function Create-Process() { param([string] $fileName, [string] $arguments) $pinfo = New-Object System.Diagnostics.ProcessStartInfo $pinfo.RedirectStandardError = $true $pinfo.Redirect...
[]
[ { "body": "<p>Here's what I've been able to come up with so far. It could probably be improved further.</p>\n\n<pre><code>function Pack {\n param(\n [Parameter(Mandatory=$true)]\n [string] $nuspec,\n\n [string] $OutputDirectory,\n\n [string] $BasePath,\n\n [ValidateSet(\"no...
{ "AcceptedAnswerId": "47299", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T16:59:33.920", "Id": "47261", "Score": "6", "Tags": [ "strings", "powershell" ], "Title": "Convert list of parameters to a string that can be invoked" }
47261
<p>I have a CRM system that has Notes, Payments, DairyEvents and anything else that needs to be bolt on over time.</p> <p>I created an <code>ITimeline</code> interface that has a datetime and message method and implemented them on those models.</p> <p>This is the simplest form of code I have started with:</p> <pre><...
[]
[ { "body": "<p>The error should be caught where it occurs, namely in the controller. If possible try to implement something like this</p>\n\n<pre><code>TimelineEventCollection personTimelineEvents; // Change to the appropriate collection type.\nif (Controllers.FollowUp.TryGetAll(personID, out personTimelineEvent...
{ "AcceptedAnswerId": "47271", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T18:10:17.610", "Id": "47267", "Score": "3", "Tags": [ "c#", "interface" ], "Title": "Interface for a CRM system" }
47267
<p>This is my attempt at Project 18/67 of Project Euler. You can see the problem information, and obtain the needed txt file from <a href="http://projecteuler.net/index.php?section=problems&amp;id=67" rel="nofollow">here</a>.</p> <p>I had some help with the split function, and help on how to use an vector to do this. ...
[]
[ { "body": "<p>Generally speaking, I find that your code is clear. I just have a few remarks:</p>\n\n<ul>\n<li><p>You should order your headers in alhabetical order. It will help you to quickly check whether some header is already included or not in you plan to add some:</p>\n\n<pre><code>#include &lt;fstream&gt...
{ "AcceptedAnswerId": "47274", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T18:35:36.553", "Id": "47272", "Score": "6", "Tags": [ "c++", "c++11", "programming-challenge" ], "Title": "Project Euler 18/67: Maximum Sum from Top to Bottom of the Triangle" ...
47272
<p>As part of a Trading Card Game, I have created a <code>Hand</code> that will need to hold all cards that a player currently has in his hand. The code is built using Java 8.</p> <p>The structure is the following:</p> <ul> <li>Class for exception throwing.</li> <li>The Card interface.</li> <li>The Hand class.</li> <...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T20:03:42.960", "Id": "82823", "Score": "4", "body": "I agree with the response below but those are just \"minor\" tweaks. Overall, I have to say I love the code. Also the defensive programming, nice approach." }, { "ContentL...
[ { "body": "<ol>\n<li><p>If NetBeans requires this:</p>\n\n<blockquote>\n<pre><code>{\n assertEquals(true, true);\n}\n</code></pre>\n</blockquote>\n\n<p>I would put a comment about that or move it into a method like <code>workaroundForNetBeansNotToRemoveStaticImports</code>.</p></li>\n<li><p>Instead of this:<...
{ "AcceptedAnswerId": "47279", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T18:47:08.900", "Id": "47273", "Score": "15", "Tags": [ "java", "game", "unit-testing", "community-challenge" ], "Title": "Trading Card Game's Hand class and tests" }
47273
<p>I wrote a little Perl script to <a href="http://en.wikipedia.org/wiki/Caesar_cipher" rel="noreferrer">Caesar shift</a> strings. Usage:</p> <pre><code>$ # usage: caesar &lt;string&gt; [shifts,...] $ caesar abcde # The default shift is 13. nopqr $ caesar abcde 1 bcdef $ caesar abcde 1,13 # Multiple shifts are supp...
[]
[ { "body": "<p>This is good Perl code. You've followed good practices such as <code>use strict</code> and declaring variables using <code>my</code>. It's also quite readable.</p>\n\n<p>However, it feels a bit like C, trudging along with a lot of iteration and low-level operations. Also, I would suggest defini...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T18:57:08.693", "Id": "47276", "Score": "5", "Tags": [ "perl", "caesar-cipher" ], "Title": "Little script to Caesar shift strings" }
47276
<p>I have the following code, written in Python:</p> <pre><code>if id: fields = r.table(cls._tablename) .get(id) .run(cls.connection()) else: try: fields = list(r.table(cls._tablename) .filter(**kwargs) .limit(1) ...
[]
[ { "body": "<p>Not really much you can do about the aesthetics of Python's indent style. Perhaps you can do as such:</p>\n\n<pre><code>if id:\n fields = r.table(cls._tablename).get(id).run(cls.connection())\nelse:\n try:\n fields = list(r.table(cls._tablename).filter(**kwargs).limit(1).run(cls.conne...
{ "AcceptedAnswerId": "47318", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T19:36:06.523", "Id": "47280", "Score": "9", "Tags": [ "python", "optimization" ], "Title": "Simplifying many-indents-code" }
47280
<p>I'm working on a directory that lists employee information. Each employee can belong to multiple departments and each employee can have multiple job titles. I have 5 MySQL tables that I am pulling information out of, including: </p> <ul> <li><code>employee</code></li> <li><code>employee_has_department</code></li>...
[]
[ { "body": "<p>The answer is that there is a definite performance gain in having it all in a single join. Just the reduction in back and forth should greatly decrease the latency, and the database engine should be way more effective.</p>\n\n<p>For a more general view on that topic :</p>\n\n<ul>\n<li><p>Will the ...
{ "AcceptedAnswerId": "47296", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-15T21:45:51.287", "Id": "47292", "Score": "0", "Tags": [ "php", "performance", "mysql", "mysqli" ], "Title": "Directory that lists employee information" }
47292