body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<blockquote> <p>HTTP Strict Transport Security (HSTS) is an opt-in security enhancement that is specified by a web application through the use of a special response header. Once a supported browser receives this header that browser will prevent any communications from being sent over HTTP to the specified domain and ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-02T15:59:05.290", "Id": "85678", "Score": "0", "body": "In production you'll use durations of at least a month. The only reason for small values is that you can recover more quickly when you discover that part of you website doesn't wo...
[ { "body": "<p>I would suggest setting the message on ArgumentException to your parameter name</p>\n\n<p>e.g.</p>\n\n<pre><code>throw new ArgumentException(\"'duration' must be greater than 0\");\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-...
{ "AcceptedAnswerId": "48482", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T10:16:46.337", "Id": "48314", "Score": "6", "Tags": [ "c#", "security", "asp.net-mvc" ], "Title": "Implementing HTTP Strict-Transport-Security via MVC action filter" }
48314
<p>Recently I have given an interview to a widely well-known technology firm. The first interview was general and it went well but they rejected based on some technical things. They did not mention it so I expect may be due to my Coding Exercise that I submitted is not well designed.</p> <p>It would be great if someon...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T14:32:31.920", "Id": "84822", "Score": "0", "body": "I don't have time for a full review and might do it later, but just a first thing I noticed: Object should not have `ArrayList` as a type, but only use the interface `List`. Simil...
[ { "body": "<h1>General</h1>\n<ul>\n<li>Your formatting isn't very clean. You have random spaces, empty lines and indentations everywhere.</li>\n<li><a href=\"https://stackoverflow.com/questions/147468/why-should-the-interface-for-a-java-class-be-prefered\">Use interfaces instead of concrete types where possibl...
{ "AcceptedAnswerId": "48338", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T11:58:06.937", "Id": "48320", "Score": "8", "Tags": [ "java", "interview-questions" ], "Title": "Calculate final test score from a list of test results" }
48320
<p>Below is the code for the problem at <a href="http://www.codechef.com/problems/ROTSTRNG/" rel="nofollow">Codechef</a>. I have made use of the <code>String</code> method <code>.equals</code> in my solution which is working fine for all the test inputs. However, I am getting a Time Limit Exceeded when I submit to the ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T14:58:34.113", "Id": "84832", "Score": "4", "body": "The first step to clean code is proper formatting and avoiding pointless empty lines. Please fix your code, it will make it easier to read and review." } ]
[ { "body": "<p>I would use an entirely different strategy to determine the number of times needed to rotate the string: addition.</p>\n\n<p>Since rotating a string by <code>a</code> and then <code>b</code> yields the same result as rotating it <code>a+b</code>, we do not need to keep track of the string at all, ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T12:22:33.097", "Id": "48323", "Score": "4", "Tags": [ "java", "strings", "programming-challenge", "time-limit-exceeded" ], "Title": "\"Rotating the string\" optimization" }
48323
<p>I'm writing a driver in C for a WiFi module attached to a PIC18 microcontroller. I want to implement some functions that I'm familiar with in computer application level programming like Window's API <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms740121%28v=vs.85%29.aspx">recv</a> function for Win...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T13:39:43.593", "Id": "84806", "Score": "0", "body": "Could you give further details about `ReceiveByte()`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T13:49:45.883", "Id": "84808", "Score"...
[ { "body": "<p>The only thing I see wrong with the algorithm is that if you don't have any data coming in from the WiFi module, you could potentially sit and wait for 200ms (the value of <code>RECEIVE_TIMEOUT</code>) before returning to the caller to say \"no data\". Is there other work that your main program co...
{ "AcceptedAnswerId": "48376", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T12:34:43.957", "Id": "48325", "Score": "7", "Tags": [ "c", "networking", "embedded" ], "Title": "Writing an interface for networking in an embedded system" }
48325
<p>Aim is to provide total head movement in different disk scheduling algorithms namely FCFS, SSTF, LOOK, C-LOOK, SCAN, C-SCAN.</p> <pre><code>#include &lt;iostream&gt; #include &lt;cstdlib&gt; #include &lt;conio.h&gt; #include &lt;math.h&gt; using namespace std; int compare (const void * a, const void * b) { if (...
[]
[ { "body": "<p>You are using C++, but overall, your code looks like C. There are numerous ways to improve your code readability by replacing C standard features by C++ ones. I will give some examples.</p>\n\n<h1><code>using namespace std;</code></h1>\n\n<p>Wirting <code>using namespace std;</code> is generally <...
{ "AcceptedAnswerId": "48334", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T12:34:44.123", "Id": "48326", "Score": "8", "Tags": [ "c++" ], "Title": "Disk Scheduling Algorithm" }
48326
<p>After coding my divisor code which I did as a practice for my GCSE stuff which I have to take soon, I have decided to ask the community if there are any bugs or ways I can improve my code. </p> <pre><code>import time, math from array import * def programme(): num = input("Enter your Number: ") try: ...
[]
[ { "body": "<p>I'm new, so can't comment, otherwise, would have commented. This isn't a bug, but you don't necessarily need the brackets in python for ifs and things like that:\nInstead of:</p>\n\n<pre><code>if (intnum % i) == 0:\n</code></pre>\n\n<p>you could just do:</p>\n\n<pre><code>if intnum % i == 0:\n</co...
{ "AcceptedAnswerId": "48347", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T13:46:32.910", "Id": "48328", "Score": "7", "Tags": [ "python", "mathematics", "python-3.x" ], "Title": "Are there any bugs or ways to make my divisor code better?" }
48328
<p><a href="http://learnyouahaskell.com/modules#loading-modules" rel="nofollow noreferrer">Learn You a Haskell</a> shows the <code>intersperse</code> function:</p> <pre><code>ghci&gt; intersperse '.' "MONKEY" "M.O.N.K.E.Y" ghci&gt; intersperse 0 [1,2,3,4,5,6] [1,0,2,0,3,0,4,0,5,0,6] </code></pre> <p>Note that ...
[]
[ { "body": "<blockquote>\n <p>Could the fold approach have worked? If so, how?</p>\n</blockquote>\n\n<pre><code>intersperse' i = foldr (\\x ys -&gt; x : if null ys then [] else i : ys) []\n</code></pre>\n\n<p>In the fold, we cannot access the rest of the input, only the rest of the output. However, if and only ...
{ "AcceptedAnswerId": "48349", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T14:13:15.657", "Id": "48333", "Score": "5", "Tags": [ "haskell", "reinventing-the-wheel" ], "Title": "Writing Data.List's intersperse" }
48333
<p>This is a teaching sample intended to illustrate use of mutability and list consing in F#. The structure is intended to be a thread-safe stack structure, which multiple threads can push to/pop from concurrently. Concerns:</p> <ul> <li>Will this actually be thread safe?</li> <li>Are the locks necessary?</li> <li>I...
[]
[ { "body": "<blockquote>\n <p>Will this actually be thread safe?</p>\n</blockquote>\n\n<p>Yes, I think it will. All access to the <code>_stack</code> field is protected by a lock, so I do not see why this wouldn't be thread safe.</p>\n\n<p>A nice coincidence of using immutable lists is that you can also nicely...
{ "AcceptedAnswerId": "48340", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T14:24:43.213", "Id": "48335", "Score": "2", "Tags": [ "f#" ], "Title": "A concurrency-safe stack structure" }
48335
<p><strong>&lt;edit:</strong> There's a major problem in the code. It is basically the one in the comment regarding backpressure. I'll rework the code within a a few days...</p> <p>It's time for a quick code review, good points, examples, handholding if anyone has time to spare for commenting and, yes, even nitpicking...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-01T20:00:50.637", "Id": "85519", "Score": "0", "body": "I'll update this shortly. It turns out this became quite a largish issue to handle haphazardly. See a closely related question at https://stackoverflow.com/questions/23404185/how-...
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T15:05:56.670", "Id": "48342", "Score": "2", "Tags": [ "f#", "system.reactive" ], "Title": "Polling, parsing, validating and handling data cleanly and efficiently" }
48342
<p>This is a follow-up of <a href="https://codereview.stackexchange.com/q/47975/39083">'any' class implementation</a>. After posting <a href="https://codereview.stackexchange.com/a/48250/39083">my answer</a>, I kept working on the code towards parameterizing with respect to memory management as I had promised. I ended ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T11:10:58.133", "Id": "84930", "Score": "0", "body": "After `some t{std::move(*this)};`, isn't it UB to access anything in the class?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T22:30:28.487", ...
[ { "body": "<p>The very idea of the storage inside <code>some</code> made me think about the problems it brings in <code>swap()</code> and <code>assign()</code>. I was first thinking about adding the <code>swap()</code> <strong><em>as another virtual method</em></strong>, possibly even the assignment. That could...
{ "AcceptedAnswerId": null, "CommentCount": "11", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T15:26:25.883", "Id": "48344", "Score": "31", "Tags": [ "c++", "c++11", "memory-management", "reinventing-the-wheel", "variant-type" ], "Title": "Yet another 'any' class i...
48344
A data type or a class designed to emulate a data type that holds a single value of a type that is either from an explicitly (compile-time) specified list, or arbitrary. The actual type of the stored value is only known at runtime.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T15:32:31.760", "Id": "48346", "Score": "0", "Tags": null, "Title": null }
48346
<p>I am writing the Cloud function for <a href="https://parse.com/docs/cloud_code_guide" rel="nofollow">Parse</a> whose purpose is to update my database with a provided array of data objects. The main problem are the nested promises, which doesn't look right. Any help to refactor this code or any other critiques?</p>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T18:44:12.853", "Id": "84855", "Score": "0", "body": "This may just be me not knowing Parse's system, but the flow seems a little shaky: It looks like it'll call `response.success` right away, because it doesn't wait for all the save...
[ { "body": "<p>I'd start with refactoring the promises functions and remove any code repetition, something like this:</p>\n\n<pre><code>...\n\nfunction success(object){\n // success \n}\nfunction error(error){\n return response.error(error);\n}\n...\n\nquery.find().then(function(ar...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T17:10:23.457", "Id": "48357", "Score": "2", "Tags": [ "javascript", "database", "node.js", "asynchronous", "promise" ], "Title": "Cleaning up nested promises in Cloud func...
48357
<p>I'm writing a Perl program to take a set of clauses and a conclusion literal and produce a resolution-refutation proof (if possible) using a breadth-first set of support (SOS) search algorithm.</p> <p>The actual searching part of the program runs extremely slow, because I have many nested loops. I imagine it may al...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T16:31:58.727", "Id": "84851", "Score": "0", "body": "would using multiple threads help at all?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T16:54:25.080", "Id": "84852", "Score": "0", "...
[ { "body": "<p>You seem to have taken away little from my efforts to help you write good Perl code. In particular you <em>must</em> add</p>\n\n<pre><code>use warnings\n</code></pre>\n\n<p>to the top of <em>every</em> Perl program, which in this case would have resulted in line after line of errors like</p>\n\n<p...
{ "AcceptedAnswerId": "48362", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T16:28:06.253", "Id": "48358", "Score": "3", "Tags": [ "perl", "optimization", "io" ], "Title": "Optimizing system calls and nested loops" }
48358
<p>I want to create a container that has an <code>AutoList</code> object list. I wonder if my container is correct.</p> <pre><code>class Auto{ string model; int co2; public: Auto (); Auto(string m, int c); ~Auto(){}; string GetModel(){return model;} void SetModel(string s){model = s;} i...
[]
[ { "body": "<ul>\n<li><p>The absence of <code>std::</code> in front of <code>string</code> can imply that you're using <code>using namespace std</code>. If so, this should be removed as it can break code (mainly with name-clashing) that includes this file. Read <a href=\"https://stackoverflow.com/questions/145...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T19:24:19.340", "Id": "48363", "Score": "2", "Tags": [ "c++", "beginner", "container" ], "Title": "Containers and lists" }
48363
<p>I have made 2 scripts in Ruby. The first program creates an .rtf file with cards (file with colored table with persons) from a list of people in text file. The second program does the same, but in an HTML file. In the first, I can use the gem library, but I'm not allowed to do so in the second.</p> <p>My teacher ...
[]
[ { "body": "<p>Your code is basically a long a list of discrete steps, rather than an attempt at modelling the data and the task.</p>\n\n<p>The steps for both output formats are</p>\n\n<ol>\n<li>Read</li>\n<li>Parse</li>\n<li>Write</li>\n</ol>\n\n<p>I think your teacher would want you to realize that the first 2...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T20:00:43.437", "Id": "48366", "Score": "2", "Tags": [ "ruby", "classes" ], "Title": "Creating an .rtf file with cards from a list of people" }
48366
<p>A recruiter gave me a homework problem as a part of the recruiting process and after receiving my submission he told me that he decided not to proceed with me. When I asked for the reason, he told me that I should ask for advice online from more experienced Python programmers. He said that "the issues were algorithm...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T00:27:10.697", "Id": "84903", "Score": "2", "body": "There are some good algorithms discussed in [this question](http://stackoverflow.com/questions/2954626/algorithm-to-find-the-smallest-snippet-from-searching-a-document)" } ]
[ { "body": "<p>Some quick (as in \"I'm procrastinating\") tips:</p>\n\n<ul>\n<li><p>Use standard naming. ReplaceTheseFormsOfVariableNames with these_forms_of_variable_names, at least in accordance to <a href=\"http://legacy.python.org/dev/peps/pep-0008/\">PEP 8</a>.</p></li>\n<li><p>State in global variables is ...
{ "AcceptedAnswerId": "48381", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T23:41:55.183", "Id": "48374", "Score": "17", "Tags": [ "python", "strings", "interview-questions", "python-2.x", "clustering" ], "Title": "Given a page of content, dete...
48374
<p>Given a set T of characters and a string S, find the minimum window in S which will contain all the characters in T in complexity O(n).</p> <p>eg, S = “ADOBECODEBANC” T = “ABC”</p> <p>Minimum window size is 4 - “BANC”.</p> <pre><code>public final class MinSubstringWindow { private MinSubstringWindow() {} ...
[]
[ { "body": "<p>The first big issue that crosses my mind: Naming. In particular, commenting variables is <em>always</em> a sign that you did a poor job on giving them good names:</p>\n\n<pre><code>int j = 0; // the trailing position of the sliding window\nint i = 0; // the leading position of the sliding window.\...
{ "AcceptedAnswerId": "48412", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T23:54:08.983", "Id": "48375", "Score": "6", "Tags": [ "java", "algorithm" ], "Title": "Find minimum window size which includes the subset of characters" }
48375
<p>I'm writing some code which needs to take a generic <code>java.util.List</code> from another source and adapt to the available functions; eg. does it support <code>add()</code>, <code>set()</code>, etc.</p> <p>I'm currently just calling the functions on the list and creating a set of available operations, but I'm w...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T04:58:58.020", "Id": "84913", "Score": "2", "body": "Sorry, I'm having trouble understanding what you are trying to accomplish. Could you provide a few example `List`s and what the expected behaviour should be?" }, { "Conten...
[ { "body": "<p><b>After edit original question: </b><br/></p>\n\n<p>I understand what you are trying to do, and very nice if you can do that.\nThat's why I'm trying to think together with you for an solution.<br/>\nThe only thing is that I seems not capable enough to reach to an solution.<br/>\nThat's why I'm st...
{ "AcceptedAnswerId": "48399", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T04:35:07.477", "Id": "48382", "Score": "6", "Tags": [ "java", "collections" ], "Title": "Detecting available List operations" }
48382
<p><a href="http://jsfiddle.net/rdesai/8qmyg/15/">Here is the link to the jsFiddle</a> and below is the code:</p> <p>JS:</p> <pre><code>$(function() { var hours = minutes = seconds = milliseconds = 0; var prev_hours = prev_minutes = prev_seconds = prev_milliseconds = undefined; var timeUpdate; // St...
[]
[ { "body": "<p><a href=\"http://jsfiddle.net/8qmyg/17/\">Chess clock anyone?</a> :D</p>\n\n<p>HTML:</p>\n\n<pre><code>&lt;!-- \nNever assume just one. Prepare for more than one always. \nWith that, we use classes\n--&gt;\n\n&lt;div class=\"stopwatch\" data-autostart=\"false\"&gt;\n &lt;div class=\"time\"&gt;\...
{ "AcceptedAnswerId": "48390", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T04:59:58.350", "Id": "48383", "Score": "8", "Tags": [ "javascript", "jquery", "datetime", "jquery-ui" ], "Title": "jQuery stopwatch" }
48383
<p>The class routes URLs based on the <code>domain.com/class/method/param/..</code> format. It also checks the request type (GET or POST) and calls the method name GET or POST from the identified class.</p> <pre><code>class Router { private $_routes, $_path, $_method, $_found; ...
[]
[ { "body": "<p>Let's look at your questions individually:</p>\n\n<p><strong><em>Am I utilizing dependency injection correctly?</em></strong><br>\nYes <em>and</em> no. You are, essentially, injecting the routes. That's fine. But you extract them from a <code>$config</code> object. If you are working out some MVC ...
{ "AcceptedAnswerId": "48468", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T13:15:04.923", "Id": "48396", "Score": "3", "Tags": [ "php", "object-oriented", "mvc", "url-routing" ], "Title": "Router for MVC framework" }
48396
<pre><code>from random import random def to_color(obj=None): """Determine a color (string 000000-ffffff) from the hash of any object If no argument is passed, a random color is returned. Args: obj: any hashable object; string, tuple, ... Returns: a color string in range '000000' to '...
[]
[ { "body": "<p>From <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP 8</a>:</p>\n\n<blockquote>\n <p>Comparisons to singletons like None should always be done with is or\n is not, never the equality operators.</p>\n \n <p>Also, <strong>beware of writing if x when you really mean i...
{ "AcceptedAnswerId": "48413", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T14:23:09.090", "Id": "48402", "Score": "2", "Tags": [ "python" ], "Title": "Color string from object (random if empty, deterministic else)" }
48402
<p>Answer is the Parent table and AnswerDetail is the child. Below works, but I'm wondering if there is a better way to do this using EF?</p> <p><strong>My Method Signature is this:</strong></p> <pre><code> [HttpPost] public ActionResult Evaluator(EvaluationVM evaluation, string command) </code></pre> <p><st...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T16:15:12.443", "Id": "84967", "Score": "0", "body": "Are all code blocks in the same method? If so, it would be nice if you could add the method's signature; if not, splitting the code block into distinct methods would make it easie...
[ { "body": "<h3>Separation of Concerns</h3>\n<p>I like that you're using EF's built-in unit-of-work implementation. However <code>db</code> (your <code>DbContext</code> class) looks like it's declared at instance level in your controller - make sure it's disposed properly at the end of the request (you could inj...
{ "AcceptedAnswerId": "48414", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T14:58:37.973", "Id": "48406", "Score": "2", "Tags": [ "c#", "entity-framework" ], "Title": "Parent/child relationships: adding/updating details to an answer" }
48406
<p>I've written the following query for SQL server:</p> <pre><code>SELECT YEAR(Meeting_Date) year, MONTH(Meeting_Date) month, COUNT(project) meetings FROM meetings WHERE Meeting_Date BETWEEN CAST(DATEPART(year,DATEADD(m,-6,GETDATE())) as varchar(4)) + '-' + CAST(DATEPART(month,DATEADD(m,-6,GETDATE())) as varchar(2)) +...
[]
[ { "body": "<p>This is one of those things.... date manipulation in SQL.</p>\n\n<p>For performance reasons, it is a pain to cast to <code>NVarchar</code>, etc. For readability reasons, everything is a pain.....</p>\n\n<p>What I have found works best for me, is the following function:</p>\n\n<pre><code>DateAdd(d,...
{ "AcceptedAnswerId": "48408", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T15:05:37.630", "Id": "48407", "Score": "7", "Tags": [ "sql", "sql-server", "datetime", "t-sql" ], "Title": "Count and group rows for six months prior" }
48407
<p>This is part of one of my projects called <a href="https://github.com/fge/largetext" rel="nofollow">largetext</a>, which actually stemmed from a question on Stack Overflow. The goal is to provide access to a very large text file as a <a href="http://docs.oracle.com/javase/8/docs/api/java/lang/CharSequence.html" rel=...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T16:25:15.240", "Id": "86380", "Score": "0", "body": "It's not standard Java you're using non-standard annotations ( @ThreadSafe etc)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T16:36:49.110", ...
[ { "body": "<p>I'll freely admit that my following suggestions are hunches. I hope they make some difference, but they may be negligible.</p>\n\n<ul>\n<li><p><strong>Override <code>ThreadLocal.initialValue()</code></strong>. This will eliminate calls to <code>Optional.fromNullable</code>: you will always have ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T15:44:58.590", "Id": "48411", "Score": "13", "Tags": [ "java", "multithreading", "thread-safety", "concurrency" ], "Title": "Thread-safe large text buffer" }
48411
<p>So I wrote this code a while ago as a way of seeing how many times it could compute a simple sum in a second (one tick). I was wondering if this gives me valid results or is in fact giving me bogus ones.</p> <pre><code>from datetime import datetime from datetime import timedelta start_time = datetime.now() def m...
[]
[ { "body": "<p>No, your benchmark is completely bogus. Let's look at the main loop:</p>\n\n<pre><code>while millis() - start &lt; 1000:\n x = 4+5\n #counting up\n count = count + 1\n</code></pre>\n\n<p>The addition <code>4+5</code> can be constant-folded when the code is compiled. If you are lucky, the ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T17:11:04.697", "Id": "48415", "Score": "5", "Tags": [ "python", "python-3.x", "timer" ], "Title": "Does this code actually give a valid representation of how quick a system is?" }
48415
<p>I was wondering which <code>time.time()</code> of <code>from datetime import timedelta</code> was the quickest and best way to find how long a programme had been running for example.</p> <pre><code>import time start = time.time() #do stuff print(start - time.time()) </code></pre> <p>or (although longer)</p> <pr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T20:23:36.073", "Id": "85011", "Score": "0", "body": "What is your goal here — just to benchmark the Python interpreter on your machine?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T14:59:37.543", ...
[ { "body": "<p>In Python 3.3 and later you can use one of</p>\n\n<blockquote>\n <p><a href=\"https://docs.python.org/3/library/time.html#time.perf_counter\"><code>time.perf_counter()</code></a><br>\n Return the value (in fractional seconds) of a\n performance counter, i.e. a clock with the highest available\n...
{ "AcceptedAnswerId": "48785", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T17:18:21.153", "Id": "48416", "Score": "9", "Tags": [ "python", "python-3.x", "timer" ], "Title": "Measuring Execution Times" }
48416
<p>After coding this, I was wondering if there are any ways in which I can improve upon it. It generates a random string of characters and symbols the same length as what is entered by the user. It uses a separate list for each char list but I am sure it is using a very long-winded method!</p> <pre><code>import random...
[]
[ { "body": "<p>Python already defines a number of strings of possible characters. See <code>string.ascii_lowercase</code> and <code>string.digits</code> <a href=\"https://docs.python.org/2/library/string.html\">Source</a></p>\n\n<hr>\n\n<p>I would use <code>True</code> and <code>False</code> instead of <code>\"...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T17:24:32.967", "Id": "48417", "Score": "3", "Tags": [ "python", "optimization", "python-3.x", "random" ], "Title": "Generating a random string of characters and symbols" }
48417
<p>I wrote a fizz buzz variation method in Python which prints "fizz", "bang", and "buzz" for 3, 7, and 11 respectively.</p> <pre><code>def FizzBang(): string = '' for n in range(1,101): msg = "" if not n % 3: msg += "Fizz" if not n % 7: msg += "Bang" if ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T21:54:36.760", "Id": "85021", "Score": "1", "body": "You could write it in a native language." } ]
[ { "body": "<p>I don't think the modulo operator is as expensive as you think it is, and even if it would be there's no way you can avoid it.</p>\n\n<p>However, instead of doing string concatenation you can write to <code>sys.stdout</code> directly. This however, requires a temporary variable to know if any prev...
{ "AcceptedAnswerId": "48432", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T17:55:57.097", "Id": "48419", "Score": "11", "Tags": [ "python", "performance", "python-2.x", "fizzbuzz" ], "Title": "\"FIZZ BANG BUZZ!\" 3,7,11 efficiency" }
48419
<p>I'm new to design patterns and specifically the Service Layer implementation. I need some clarification on where to use Service Layer calls. </p> <p>Below is an example of what I'm dealing with. I have data from 2 different repositories so I'm not quite certain when/where I'm supposed to call up any additional in...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T17:34:48.927", "Id": "86572", "Score": "3", "body": "I can review the \"Business Model/Logic\" part, but everything under it makes no sense, ..why not just post your real code?" } ]
[ { "body": "<blockquote>\n <p><em>Business Model/Logic</em></p>\n</blockquote>\n\n<p>These are two distinct things: your <em>model</em> and your <em>logic</em> should be implemented in separate classes - the <em>business model</em> defines a <code>Car</code> class, and the <em>business logic</em> consumes it. ...
{ "AcceptedAnswerId": "49245", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T18:02:28.747", "Id": "48420", "Score": "4", "Tags": [ "c#", "design-patterns" ], "Title": "Is the following service layer correctly implemented with multiple repositories?" }
48420
<p>I have few years of experience with web and I recently started learning C++ and I feel a bit lost, so I would like to ask to for some tips how to improve my code overall. This text summarizer should get the sentences with the highest weight (most important ones). </p> <p>Header file:</p> <pre><code>#include &lt;io...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T23:40:26.517", "Id": "85038", "Score": "1", "body": "You should include `<iterator>` and not pass a temporary `istringstream` to an `istream_iterator`. The latter works due to a language extension of MSVC. If you use the MSVC++ comp...
[ { "body": "<ul>\n<li><p>Since any file including a header file is exposed to all its code, it's best to include as few things in a header as possible. All of those libraries but <code>&lt;string&gt;</code> and <code>&lt;set&gt;</code> are not used in the header. They should instead be moved to the .cpp file, ...
{ "AcceptedAnswerId": "48484", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T18:10:19.897", "Id": "48424", "Score": "12", "Tags": [ "c++", "optimization", "performance", "c++11" ], "Title": "Text \"analyzer\" in C++" }
48424
<p>I am trying to use the following form to enter new info into a database. </p> <p><img src="https://i.stack.imgur.com/zkQfE.png" alt="enter image description here"></p> <p>I am trying to use the entity framework.</p> <p>I have the following classes of Interest: </p> <pre><code>public class InventoryContext : DbCo...
[]
[ { "body": "<p>I'm about to watch Vikings so here are a few quick pointers:</p>\n\n<h1>Naming</h1>\n\n<p>Your code contains variables named <code>me</code>, <code>pe</code>, <code>ce</code>, etc. This tells me nothing about what that variable does. </p>\n\n<p>I'm not experienced with <code>Expressions</code> but...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T20:30:57.440", "Id": "48435", "Score": "4", "Tags": [ "c#", "linq", "entity-framework" ], "Title": "EntityFramework-based filtering" }
48435
<p>I was thinking in a way to improve the following query if possible:</p> <pre><code>SELECT CONCAT(DATE_FORMAT(start_date, '%Y'), ',', (MONTH(start_date) -1), ',', DATE_FORMAT(start_date, '%d')) as start_date FROM PROJECTS </code></pre> <p>I need <code>start_date</code> in this format: <code>dd/mm-1/yyyy</co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T01:04:02.733", "Id": "85050", "Score": "2", "body": "Could you post your application code as well? I think that using SQL to work around the 0-1 mismatch is a bad idea." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
[ { "body": "<p>If there is no workaround then, bad practice as it may be, what you have is functional. I <a href=\"https://stackoverflow.com/questions/8931106/mysql-my-months-are-current-stored-0-11\">found this post on SO</a> that may allow you to convert the column's <code>date</code> data type to the 0-11 for...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T20:55:26.853", "Id": "48436", "Score": "4", "Tags": [ "sql", "datetime", "mysqli" ], "Title": "Selecting one MySQL date with month reduced by one" }
48436
<p>I want to implement the following function:</p> <pre><code>// Return true if and only if 's' is numeric including // leading positive/negative sign, decimal point. bool isnumeric( const char * s ); </code></pre> <p>It is somewhat similar to <code>strtol()</code> but I don't need to return the number.</p> <p>My ap...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T21:18:59.323", "Id": "85018", "Score": "1", "body": "Looks like you're using your `int`s mainly as `bool`s, might want to consider to use `bool`s there for that." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2...
[ { "body": "<p>State variables are bad. Keep the state explicit, along the lines of:</p>\n\n<pre><code>if (*p == '+' || *p == '-') p++;\nif (!isdigit(*p)) return False;\nwhile (isdigit(*p)) p++;\nif (*p == 0) return True;\nif (*p != '.') return False;\np++;\nwhile (isdigit(*p)) p++;\nreturn *p == 0;\n</code></pr...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T21:03:37.170", "Id": "48438", "Score": "7", "Tags": [ "c", "parsing", "unit-testing", "validation", "fixed-point" ], "Title": "Test if string is numeric" }
48438
<p>I have written the same code in Python (NumPy) and in Matlab, and I tried to use the same structure for both language and follow the same procedure. Now my problem is that when I run my code in Python it's very very slow but it runs fast in Matlab.</p> <p>How can I improve my Python code? I want to work on the Pyt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T22:00:02.820", "Id": "85024", "Score": "3", "body": "Your title should state what your code is for, not that it is slow! What is it's *purpose*?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T23:03:2...
[ { "body": "<p>You use very short variable names, so its hard to follow what your code is doing.</p>\n\n<p>For speed in numpy, you need to use vector operations. So instead of writing</p>\n\n<pre><code>for ii in range(step):\n out[ii] = ii * x + b\n</code></pre>\n\n<p>You should write:</p>\n\n<pre><code>out =...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T21:26:07.493", "Id": "48440", "Score": "1", "Tags": [ "python", "performance", "matrix", "numpy", "matlab" ], "Title": "Creation of MxM matrix: Python version much slower ...
48440
<p>I am trying to implement lock by which I don't want to have reads from happening whenever I am doing a write.</p> <p>Here is my <code>ClientData</code> class in which I am using <code>CountDownLatch</code>:</p> <pre><code>public class ClientData { private static final AtomicReference&lt;Map&lt;String, Map&lt;...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T22:39:15.697", "Id": "85027", "Score": "0", "body": "Is this a Bean or something (i.e. why do you need three setters... can't you `setMappings(primary, secondary, tertiary)`) ?" }, { "ContentLicense": "CC BY-SA 3.0", "Cr...
[ { "body": "<p>AtomicReferences are a great construct when you have just one item that needs to be kept in a sane state ina multithreaded environment. Your code is trying to juggle three, and ensure they all have a sane state at the right times, and, for that, you need something bigger than the AtomicReference....
{ "AcceptedAnswerId": "48450", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T22:20:38.303", "Id": "48442", "Score": "6", "Tags": [ "java", "performance", "multithreading", "rest", "atomic" ], "Title": "Lock for preventing concurrent access in cl...
48442
<p>I had a task to create a responsive HTML5/CSS3 page based on PSD layout. I got rejected and when asked for details I got these comments:</p> <ul> <li>semantically incorrect HTML</li> <li>incorrect use of ID selectors in CSS</li> <li>incorrect general way of solving given CSS problems</li> </ul> <p>The link is <a h...
[]
[ { "body": "<p>Several things that would cause me to reject this:</p>\n\n<ul>\n<li><p><strong>Nearly every element on the page is a <code>&lt;div&gt;</code>.</strong></p>\n\n<p><code>&lt;div&gt;</code> is semantically void. It says nothing about the structure of the document, other than that \"there's a block h...
{ "AcceptedAnswerId": "48455", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T20:04:51.803", "Id": "48444", "Score": "6", "Tags": [ "html", "css", "html5" ], "Title": "Why is my page semantically incorrect HTML and incorrect use of CSS?" }
48444
<p>So I am working through a few different game ideas as I learn programming, and I could definitely use some feedback on my latest project. This is a simple SimCity clone. So far I have created a City made up of City Tiles objects, and a number of Person objects as well. The Persons are passed from the City Tiles to...
[]
[ { "body": "<p><em>Note:</em> I don't have time right out a complete answer, so you'll have to check back this afternoon, but I'll get one started.</p>\n\n<hr>\n\n<p>First, the most glaring problem I see is your use of the <code>self.</code> accessors in the init methods. It seems to be a common problem here (I...
{ "AcceptedAnswerId": "48476", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T23:14:09.520", "Id": "48445", "Score": "5", "Tags": [ "game", "objective-c", "queue", "stack", "simulation" ], "Title": "Managing People in a SimCity Clone" }
48445
<p>This is a follow-up to <a href="https://codereview.stackexchange.com/q/47098/37034">this question</a>, which resulted in major confusion on my side regarding forwarding of arguments. <strong>Advice regarding that should probably be given in <a href="https://stackoverflow.com/q/23323547/692359">my question on SO</a>....
[]
[ { "body": "<p>I will try not to give awful advice like I did last time. Here are a few remarks:</p>\n\n<ul>\n<li><p>First of all, let's come back to <a href=\"http://en.cppreference.com/w/cpp/utility/forward\" rel=\"nofollow noreferrer\"><code>std::forward</code></a>. You should follow the link and read again a...
{ "AcceptedAnswerId": "49194", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T23:25:36.680", "Id": "48447", "Score": "8", "Tags": [ "c++", "c++11", "delegates" ], "Title": "Delegate and Observer pattern implementation for an embedded system - copy and as...
48447
<p>I'm implementing <code>transpose</code> in Haskell.</p> <pre><code>-- transpose [[1,2,3],[4,5,6],[7,8,9]] -- [[1,4,7],[2,5,8],[3,6,9]] </code></pre> <p>Please give it a look. Note that I'm trying not to use any built-in functions (excluding <code>map</code> and <code>++</code>):</p> <pre><code>transpose' :: [[a...
[]
[ { "body": "<p>I see a few problems, mostly similar to my <a href=\"https://codereview.stackexchange.com/a/48104/9357\">remarks in a previous answer</a>:</p>\n\n<ol>\n<li><p>Your definition of <code>head'</code> is unconventional. Its definition should be</p>\n\n<pre><code>head' :: [a] -&gt; a\nhead (x:_) = x\n...
{ "AcceptedAnswerId": "48463", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T02:39:52.127", "Id": "48451", "Score": "8", "Tags": [ "haskell", "matrix", "reinventing-the-wheel" ], "Title": "Implementing Transpose" }
48451
<p>Below is working code of a semi complete program. Its purpose is to take an input string of any type and modify it based on rules defined for each type. So in this example I pass it a string in CSV format and modify some of the fields. </p> <p>My questions are</p> <ol> <li><p>Can the use of interfaces be improv...
[]
[ { "body": "<p>The first word that comes to my mind, is <em>over-engineering</em>. This looks like a lot of trouble just to get to work with a CSV string, you turn a 10-liner into a party, happiness ensues and neighbors come too, and their friends also, and before you know it you've got 100 lines of code written...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T03:12:59.817", "Id": "48452", "Score": "5", "Tags": [ "c#", "strings", ".net", "csv" ], "Title": "String modification application" }
48452
<p>I've been trying several styles of validation code for a form. I was wondering if this is good or needs some improvement or just trash it and use jQuery validator code?</p> <pre><code>$("#registration-form").on("submit", function(e) { e.preventDefault(); var error_field = ""; $(this).find(".input-fie...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T05:30:51.730", "Id": "96196", "Score": "0", "body": "Why you don't use [this jQuery Validation plugin](http://jqueryvalidation.org/)!. It offers plenty of customization options." } ]
[ { "body": "<blockquote>\n <p>I was wondering if this is good</p>\n</blockquote>\n\n<p>Well, are you just looking to prevent the normal user from messing up during registration? I think it would be fine for that.</p>\n\n<p>I'll see if I can point out flaws in your validation...</p>\n\n<ol>\n<li>First, you check...
{ "AcceptedAnswerId": "58580", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T03:26:27.907", "Id": "48453", "Score": "4", "Tags": [ "javascript", "jquery", "validation", "form" ], "Title": "Form Validation Evaluation" }
48453
<p>This is a follow-up to: <a href="https://codereview.stackexchange.com/questions/48442/lock-for-preventing-concurrent-access-in-client-data">Lock for preventing concurrent access in client data</a></p> <p>I am trying to implement lock by which I want to avoid reads from happening whenever I am doing a write on my th...
[]
[ { "body": "<h1>A simpler approach</h1>\n<p>As far as I can tell from your problem definition, you're overthinking it:</p>\n<ul>\n<li><p><code>ConcurrentMap</code> is overkill because you won't be writing concurrently. As long as you pass a memory barrier of some sort, your other threads will read correctly.</p...
{ "AcceptedAnswerId": "49677", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T04:40:36.530", "Id": "48457", "Score": "4", "Tags": [ "java", "performance", "multithreading", "locking" ], "Title": "Lock for preventing concurrent access in client data -...
48457
<p>I am learning data structures, and have written an algorithm for insertion sort after learning from some sources. But I am confused which implementation is more correct or appropriate. <br><br><strong>Code #1</strong> This implementation takes an element and sorts itself with all the elements to its left, one by one...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T07:49:14.653", "Id": "85086", "Score": "0", "body": "Found a review comment myself. I am modifying original array so there is no need to return the same array, it is already modifying the source. Proper way can be to clone the array...
[ { "body": "<h1>Bubble or Insert?</h1>\n\n<p>#1 and #2 are both implementations of insertion sort (*). The way you insert the element is not so important: whether you copy one by one, use <code>arraycopy</code>, or bubble it down is up to implementation. I'd imagine <code>arraycopy</code> to be the best for la...
{ "AcceptedAnswerId": "48490", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T07:43:48.763", "Id": "48461", "Score": "1", "Tags": [ "java", "algorithm", "insertion-sort" ], "Title": "Appropriate insertion sorting algorithm" }
48461
<p>Building on the older building block, <a href="https://codereview.stackexchange.com/questions/47273/trading-card-games-hand-class-and-tests">Trading Card Game&#39;s Hand class and tests</a>, I decided it was time to implement a <code>HandView</code>, which can be implemented by a GUI for example. The view need only ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T11:45:38.000", "Id": "85099", "Score": "1", "body": "\"I haven't bothered with the unit tests for these classes yet as they are still all very experimental.\" If you do not write tests first; tests, instead of verifying some preexis...
[ { "body": "<p>I will provide some comments here regarding your code, and at the end I will provide \"My version\" (with some of my comments taken into consideration).</p>\n\n<hr>\n\n<blockquote>\n <p>Composition over inheritance</p>\n</blockquote>\n\n<p>Although I understand that you mean that you want to use ...
{ "AcceptedAnswerId": "48472", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T09:12:05.217", "Id": "48466", "Score": "10", "Tags": [ "java", "game", "community-challenge" ], "Title": "Trading Card Game's Hand and HandView implementation using composition...
48466
<h2>Initial problem</h2> <p>For a project I found myself in the need to search for elements in a container that are the closest neighbours to another precise element I have. In my case it was points in any dimension, but it can apply to various other things that we are not used to compute "distance" for.</p> <p>So I ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T18:15:57.160", "Id": "85159", "Score": "0", "body": "I am afraid you are overcomplicating things. With a proper comparator, `std::partial_sort` does exactly what you need. And I don't think it is a great burden for the caller to mak...
[ { "body": "<p>From a design point of view, when the standard library algorithms have to return a <code>[begin, end)</code> range of values, they don't return a container but take an additional <a href=\"http://en.cppreference.com/w/cpp/concept/OutputIterator\" rel=\"nofollow\"><code>OutputIterator</code></a> it...
{ "AcceptedAnswerId": "48619", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T10:16:10.400", "Id": "48470", "Score": "8", "Tags": [ "c++", "c++11", "template", "clustering" ], "Title": "Std lib-like C++ function to find nearest elements in a containe...
48470
<p>I tried to write <a href="https://github.com/tomilov/variant" rel="nofollow noreferrer">my own</a> <code>variant</code> class, that is fully move-semantics enabled. WRT to implemented visitors, they don't require any policy and like to be derived from <code>boost::static_visitor</code> or to contain <code>typedef</c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T13:27:48.127", "Id": "85105", "Score": "0", "body": "It seems, that bloating of the symbol tables may be signinfically decreased using `decltype(auto)` as return type in **C++14**." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<h1>The things you did right</h1>\n\n<p>Almost all of your code:</p>\n\n<ul>\n<li>Correct use of rvalue references, move semantics and perfect forwarding.</li>\n<li>You provided namespace-level functions that help with ADL (even though namespace-level <code>get</code> will probably not be found by AD...
{ "AcceptedAnswerId": "51807", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T10:59:38.433", "Id": "48471", "Score": "18", "Tags": [ "c++", "c++11", "error-handling", "variant-type" ], "Title": "Variant class with full move support" }
48471
<p>I need comments on the below code:</p> <pre><code>Thread.new {EM.run do IpamAgent::Amqp.run end} module IpamAgent class Amqp class &lt;&lt; self def run begin $connection = AMQP.connect(RMQ_CONFIGURATIONS) $connection.on_tcp_connection_loss do |co...
[]
[ { "body": "<p><strong>Don't use global variables</strong><br>\nUsing <code>$connection</code> as a holder for your AMQP connection is a bad idea. <code>connection</code> being such a generic name, it might be used somewhere else for something completely different, and you may end up breaking your code with some...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T11:36:01.460", "Id": "48473", "Score": "1", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Implementation on AMQP in Ruby" }
48473
<p>I want to inform the Receivers about new contracts we have this week. After I sent the Emails, the Information about sent contracts are stored in MS SQL Database.</p> <p>To avoid that someone become the same Email about contract more than one time I perform this steps:</p> <ol> <li>I have the Collection with new c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T14:26:32.117", "Id": "85115", "Score": "1", "body": "You're doing `N` queries to the database, where `N = newThisWeekContracts.Count`. Would probably be *better* [citation needed] to do just one query with two `IN` clauses. On the o...
[ { "body": "<p>Several points:</p>\n\n<ul>\n<li>Write your code against <em>abstractions</em>. <code>Collection</code> is a specific <em>implementation</em>.\n<ul>\n<li>You don't need <code>newThisWeekContracts</code> to be specifically a <code>Collection</code>. I'd take in any <code>IEnumerable&lt;Contract&gt;...
{ "AcceptedAnswerId": "48494", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T12:14:37.347", "Id": "48477", "Score": "2", "Tags": [ "c#", "linq", "entity-framework" ], "Title": "Compare Collection with the information in DB using EF and LINQ" }
48477
<p>I need to generate a minimum and maximum value for a range of speeds (slow, medium, fast), the user can specify any combination of the 3 values, and receive a range that encompasses all.</p> <p>Given any combination of <code>"slow"</code>, <code>"medium"</code>, <code>"fast"</code>, <code>getRange()</code> will ret...
[]
[ { "body": "<p>I do believe this could be done easier. You could use the <code>||</code> shortcut to set <code>min</code> and <code>max</code> if you could not find a speed range, and you could extract the numbers into a data structure and go from there.</p>\n\n<p>Something like this:</p>\n\n<pre><code>function ...
{ "AcceptedAnswerId": "48480", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T12:37:23.437", "Id": "48479", "Score": "3", "Tags": [ "javascript", "node.js", "interval" ], "Title": "Generate [min, max] range from strings" }
48479
<p>What do you think of this piece of code ? This is an implementation of quick sort in C, but I'm not sure about the quality and correctness.</p> <pre><code>#include &lt;stdio.h&gt; void swap(int tab[], int a, int b) { int temp = tab[a]; tab[a] = tab[b]; tab[b] = temp; } void quickSort(int tab[], int begin, i...
[]
[ { "body": "<p>The code is not a bad implementation of Quicksort but it has a flaw, inherent to the Quicksort algorithm, that you can easily fix. I tested the code with this main:</p>\n\n<pre><code>const int testsize = 100000;\n\nint main(void)\n{\n int tab[testsize];\n int i;\n\n for(i = 1; i &lt; tes...
{ "AcceptedAnswerId": "48485", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T13:29:06.307", "Id": "48481", "Score": "4", "Tags": [ "c", "reinventing-the-wheel", "quick-sort" ], "Title": "Correctness of quick sort in C" }
48481
<p>I am very new to Ruby and building my first game. To be honest I did it this way because I was lazy to type so much. My friend told me that the correct way was to do this with case statement i.e. for scissor we have three cases, for rock we have three cases and similarly for paper.</p> <pre class="lang-ruby prettyp...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T15:39:50.960", "Id": "85129", "Score": "0", "body": "can you fix the indenting?" } ]
[ { "body": "<p>You can initialize the score's var this way : <code>w = l = t = j = 0</code>.</p>\n\n<p>Choices could be initilize with the literal string array : <code>choice = %w( rock paper scissor )</code>.</p>\n\n<p>Don't use the <code>and</code> reserved key word to inline code, you can use the <code>;</cod...
{ "AcceptedAnswerId": "48618", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T14:00:08.623", "Id": "48483", "Score": "2", "Tags": [ "beginner", "ruby", "game", "rock-paper-scissors" ], "Title": "Rock, Paper, Scissors game" }
48483
<p>I wrote this code where I trap <code>InterruptedException</code>'s in a blocking queue and try again to consume from the same queue thinking of spurious wakeups. I don't know if in this case I should be thinking of spurious wakeups since I am not calling <code>wait()</code> directly.</p> <p>Basically, the worry tha...
[]
[ { "body": "<p>When you write, that message <strong>cannot</strong> be <code>null</code>, why are you asserting for it then?\nThat code is IMO noise. I'd rather remove it. Other than that, the comment on it is even more noisy. Your assert says exactly what your comment says. Why keep it?</p>\n\n<p>Same should go...
{ "AcceptedAnswerId": "48498", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T14:46:57.437", "Id": "48488", "Score": "4", "Tags": [ "java", "multithreading", "synchronization" ], "Title": "Spurious wakeups in Java's BlockingQueue.take()" }
48488
<p>I'm new to HTML coding and have created a basic webpage structure for a basic website with 5 pages.</p> <p>Can anyone suggest any improvements that could help with the structure, layout and design for the pages?</p> <p>Code for one of the pages is below (all the same except for the names):</p> <pre><code>&lt;!DOC...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T23:59:40.537", "Id": "85243", "Score": "1", "body": "Use [Lorem Ipsum](http://www.lipsum.com/) instead of lots and lots of text. ;)" } ]
[ { "body": "<pre><code> &lt;div id=\"Header\"&gt;\n</code></pre>\n\n<p>HTML 5 introduces the <a href=\"http://www.w3.org/TR/html5/sections.html#the-header-element\" rel=\"nofollow\"><code>&lt;header&gt;</code></a> element.</p>\n\n<pre><code> &lt;h1 align=\"center\"&gt;\n</code></pre>\n\n<p>Don't us...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T15:02:28.150", "Id": "48489", "Score": "7", "Tags": [ "beginner", "html" ], "Title": "Basic webpage structure" }
48489
<p>I have the need to search a directory containing 1000+ files on remote servers where I only have access to SQL Server Management Studio and Explorer. I have written the below SQL statement which does what I need, only incredibly slowly. I fear using this many temp tables and the cursor is the main issue. Any ideas o...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T18:19:26.827", "Id": "85160", "Score": "0", "body": "I've fixed the formatting, which was due to your mixture of spaces and tabs." } ]
[ { "body": "<p>SSIS jobs are the most appropriate for this usecase</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T16:22:59.623", "Id": "85135", "Score": "0", "body": "I forgot to mention that i need to keep this query based....
{ "AcceptedAnswerId": "49503", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T16:03:30.910", "Id": "48496", "Score": "1", "Tags": [ "performance", "sql", "sql-server", "search", "file" ], "Title": "Text file searching using SQL" }
48496
<p>I want to find the corresponding hash in an array from a string that contains a criterion defined in a hash of the array.</p> <p>I do something like that :</p> <pre><code>types = [ {key: 'type_1', criteria: ['type_1a', 'type_1b']}, {key: 'type_2', criteria: ['type_2a', 'type_2b']}, ... ] def find_type(str) t...
[]
[ { "body": "<p>The orthodox (and functional) approach in Ruby is:</p>\n\n<pre><code>def find_type(types, str)\n types.detect do |type|\n type[:criteria].any? do |criterion|\n str =~ /#{criterion}/i # or Regexp.new(criterion, \"i\")\n end\n end\nend\n</code></pre>\n", "comments": [ { ...
{ "AcceptedAnswerId": "48507", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T16:05:26.187", "Id": "48497", "Score": "1", "Tags": [ "ruby", "search" ], "Title": "Search a value across 2 array" }
48497
<p>I'm changing the inner implementation of a project. In order to do so, I've created an interface that will be implemented in 2 different ways.</p> <p>One of this ways is by class <code>A</code>, which is a wrapper for an outside class (class "<code>B</code>") from a .dll file (a product of other team).</p> <p>Cla...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T17:26:46.157", "Id": "85146", "Score": "0", "body": "How are you going to access your SomeClass object from outside of class A?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T17:32:11.037", "Id":...
[ { "body": "<p>If you need to wrap <code>SomeClass</code>, make your wrapper an <em>abstraction</em>:</p>\n\n<pre><code>public interface ISomeClassWrapper\n{\n // expose the methods and properties you want to wrap\n}\n</code></pre>\n\n<p>Then everywhere it's needed in the code, replace static method calls lik...
{ "AcceptedAnswerId": null, "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T17:13:17.380", "Id": "48502", "Score": "0", "Tags": [ "c#", "singleton" ], "Title": "Singleton-like pattern for a project" }
48502
<p>Following code is supposed generate a new ID (PID) for a new client based on the client name's first letter and the existing IDs in the range which are stored in a database. </p> <p>For ex lets say if the new client's name is "Abc" and if last ID in the database starting from letter A, is A200. Then the new ID sho...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T00:43:06.277", "Id": "85252", "Score": "1", "body": "Create a table `create table charid { id char, count long }`. Search for `pointName[0]` as `id` in the table, increment `count` and write it back while locking the row. If `pointN...
[ { "body": "<p>First, I would expect from a function named GeneratePID to return the generated ID and not to set it. (Nobody likes side-effects)</p>\n\n<pre><code>private string GeneratePIDforNewPoint(string pointName)\n{\n if(pointName == null)\n return \"error\"; \n\n var storedPIDs = _ds....
{ "AcceptedAnswerId": "48515", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T17:56:44.720", "Id": "48505", "Score": "3", "Tags": [ "c#", "optimization", ".net" ], "Title": "Algorithm generating a unique ID based on client name" }
48505
<p>Not sure if this is the right board for this topic but since it will affect my SEO i guess it's not that wrong to ask about this in here.</p> <p>I just took on a website that lists some stores around your location. You can enter some conditions and it will return a list of nearby stores.</p> <p>I noticed that the ...
[]
[ { "body": "<p><a href=\"http://www.whatwg.org/specs/web-apps/current-work/multipage/sections.html#the-article-element\" rel=\"nofollow\">Spec</a>:</p>\n\n<blockquote>\n <p>The article element represents a complete, or self-contained, composition in a document, page, application, or site and that is, in princip...
{ "AcceptedAnswerId": "48516", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T19:45:04.607", "Id": "48506", "Score": "3", "Tags": [ "html", "html5" ], "Title": "Should I return an object wrapped by an article tag?" }
48506
<p>This question continues on my previous implementations of the <code>Hand</code> class of a Trading Card Game, earlier questions can be found here:</p> <ul> <li>Earlier model: <a href="https://codereview.stackexchange.com/questions/47273/trading-card-games-hand-class-and-tests">Trading Card Game&#39;s Hand class and...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T15:27:58.583", "Id": "85309", "Score": "1", "body": "Where's the assertion in `testRemoveViewCallback`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T15:34:30.983", "Id": "85311", "Score": "...
[ { "body": "<pre><code>public interface Viewable&lt;T extends Viewable&lt;T, V&gt;, V extends View&lt;T&gt;&gt; {\n public void addViewCallback(final V view);\n\n public void removeViewCallback(final V view);\n}\n</code></pre>\n\n<p>Drop the <code>public</code> keywords from the methods. Methods in interfa...
{ "AcceptedAnswerId": "48617", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T18:25:00.583", "Id": "48509", "Score": "11", "Tags": [ "java", "game", "community-challenge" ], "Title": "Trading Card Game's Hand and HandView implementation and unit tests" }
48509
<p>Is there a more elegant and Pythonic way to handle counters in this solution to an exercise from the NLTK book? The exercise asks to print out the context (one word forward and one word back) for every verb of a particular type (tagged VN).</p> <pre><code>import nltk wsj = nltk.corpus.treebank.tagged_words(simplif...
[]
[ { "body": "<p>You could use <code>enumerate</code> to get the index. It makes the code both simpler and more efficient, as the linear search of <code>index</code> is avoided. I would also suggest unpacking <code>t</code> to <code>(word, tag)</code> to improve readability.</p>\n\n<pre><code>for ndx, (word, tag) ...
{ "AcceptedAnswerId": "48512", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T18:32:50.037", "Id": "48510", "Score": "2", "Tags": [ "python" ], "Title": "A more Pythonic way to iterate over a list with duplicate items" }
48510
<p>In my method I have something like this:</p> <pre><code>returnValue = null; if (!string.IsNullOrEmpty(pa.Phone)) { if (pa.Length != 10 &amp;&amp; member == Schema.Phone.Name) { returnValue = new stuff; } } if (!string.IsNullOrEmpty(pa.OtherPhone)) { if (pa.OtherPhone.Length != 10 &amp;&amp...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T19:28:44.357", "Id": "85183", "Score": "0", "body": "Is the first nested if supposed to be `Pa.Phone.Length` rather than `Pa.Length`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T19:50:54.293", ...
[ { "body": "<p>If <code>member</code> is <code>string</code>.</p>\n\n<pre><code>Func&lt;string, string, bool&gt; f = (p, m) =&gt; !string.IsNullOrEmpty(p) &amp;&amp; p.Length != 10 &amp;&amp; member == m;\nif (f(pa.Phone, Schema.Phone.Name) ||\n f(pa.OtherPhone, Schema.OtherPhone.Name) ||\n f(pa.Fax, Schem...
{ "AcceptedAnswerId": "48514", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T19:17:39.997", "Id": "48513", "Score": "-2", "Tags": [ "c#", "null" ], "Title": "Refactoring the logic of a return value" }
48513
<p>I've been working to create a game in Python similar to <a href="http://www.ndemiccreations.com/en/22-plague-inc">Plague Inc.</a> and instead of just writing one big clump of code and then getting it reviewed, I wanted to do it stage-by-stage and make it a little easier. Also, reviews might possibly help me later on...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T20:56:43.897", "Id": "96299", "Score": "0", "body": "I suggest you put static game information in a text file and import the information at runtime." } ]
[ { "body": "<p>Store the population as a number. If you want to include comas when the numbers are presented to the user, the UI code can add those in. When people start dying, trying to decrement a number stored in a string, that contains comas, is going to be a pain.</p>\n\n<hr>\n\n<p>I would use a <a href=\"h...
{ "AcceptedAnswerId": "48529", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T20:26:42.010", "Id": "48517", "Score": "8", "Tags": [ "python", "game", "python-2.x" ], "Title": "Plague Inc. in Python - Extremely Early Stage" }
48517
<p>I've implemented DFS and BFS implementations. I want to check if the code is readable, contains any issues, and can be improved.</p> <p><strong>GraphImplementation</strong></p> <pre><code>package graphs; import java.util.*; import graphs.State; public class GraphImplementation { public void dfs(Node root) ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T21:03:45.130", "Id": "85204", "Score": "0", "body": "Is this code for learning/assignment purpose or for working software/app ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T21:05:42.683", "Id":...
[ { "body": "<p>I'd use lists instead of a arrays and public counter. \neg.:</p>\n\n<pre><code>public class Graph\n{\n private List&lt;Node&gt; vertices = new LinkedList&lt;Node&gt;(); \n\n public void addNode(Node n)\n { \n if(vertices.length &gt;= 10){\n System.out.println(\"grap...
{ "AcceptedAnswerId": "48530", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T20:44:52.173", "Id": "48518", "Score": "24", "Tags": [ "java", "graph", "breadth-first-search", "depth-first-search" ], "Title": "Depth First Search & Breadth First Search ...
48518
<p>The <a href="http://www.spoj.com/problems/GSS1/" rel="nofollow">problem is presented here</a> as follows:</p> <blockquote> <p>You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ). A query is defined as follows: Query(x,y) = Max { a[i]+a[i+1]+...+a[j] ; x ≤ i ≤ j ≤ y }. Given \...
[]
[ { "body": "<p>I can't suggest any optimization. The complexity of the algorithm is N*logN in both setup and execution time. The task however has a (sub)linear solution.</p>\n\n<p>Since this is a competitive problem, I am sure it is unethical to show the code; I am not even sure it is ethical to describe an algo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T21:22:08.900", "Id": "48525", "Score": "2", "Tags": [ "java", "performance", "algorithm", "programming-challenge", "time-limit-exceeded" ], "Title": "GSS1 SPOJ problem Tim...
48525
<p>I am trying to implement lock by which I want to avoid reads from happening whenever I am doing a write on my three maps.</p> <p>Requirements:</p> <ul> <li>Reads block until all three maps have been set for the first time.</li> <li>Now second time, If I am updating the maps, I can still return all the three old ma...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T22:00:13.093", "Id": "85224", "Score": "0", "body": "I had assumed in [your previous question](http://codereview.stackexchange.com/questions/48442/how-to-prevent-reads-before-initialization-is-complete/48450#48450) that the maps cou...
[ { "body": "<p>Going through some smaller items in your code. Your <code>Mappings</code> class is public, which is fine, but it should also be final. There is no reason for people to extend your class. The constructor should be private, and all the Map fields should be private as well, but you should have getter...
{ "AcceptedAnswerId": "52482", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T21:39:53.143", "Id": "48526", "Score": "5", "Tags": [ "java", "optimization", "performance", "multithreading", "locking" ], "Title": "Using CountDownLatch for blocking ...
48526
<p>I have the below MySQL query that does exactly what I need, but I am sure there are better queries that do the same thing.</p> <p>If you see something very ugly or bad and have any suggestions, I will be very glad to hear them.</p> <pre><code>SELECT c.`ID_COURIER`, c.`NAME`, c.`NICKNAME`, c.`AREA_CODE`, c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T21:57:34.130", "Id": "85223", "Score": "1", "body": "If you would like help with an SQL performance issue, please post the output of `EXPLAIN SELECT`." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T2...
[ { "body": "<p>Top to bottom, here we go.</p>\n\n<ul>\n<li><p><code>COUNT(DISTINCT <code>ID_ORDER</code>)</code> </p>\n\n<p>This <code>DISTINCT</code> aggregation seems superfluous, if <code>ID_ORDER</code> is a true identity column then there should not be duplicates. This will improve performance.</p></li>\n<l...
{ "AcceptedAnswerId": "51255", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T21:51:08.110", "Id": "48528", "Score": "2", "Tags": [ "performance", "sql", "mysql" ], "Title": "Delivery geolocations query" }
48528
<p>This code works fine, but I believe it has optimization problems. Please review this.</p> <p>Also, please keep in mind that it stops after each iteration of the loop <code>foreach($mascow_sub_area as $subway)</code>.</p> <pre><code> &lt;META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"&gt; &lt;...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T11:39:42.817", "Id": "85291", "Score": "0", "body": "You have up to five levels of nesting in foreach loop. Its Big O can't be good. http://stackoverflow.com/questions/21372927/big-o-and-nested-loops" }, { "ContentLicense": ...
[ { "body": "<p>I want to focus principally on this section of your code:</p>\n\n<pre><code>$mascow_sub_area = array(//'Aviamotornaya','Avtozavodskaya','Akademicheskaya','Aleksandrovskiy_Sad',\n'Alekseevskaya',\n'Alma-Atinskaya','Altufevo','Annino','Arbatskaya','Aeroport','Babushkinskaya','Bagrationovskaya','Barr...
{ "AcceptedAnswerId": "62467", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T23:10:24.283", "Id": "48531", "Score": "8", "Tags": [ "php", "mysqli", "curl", "geospatial", "web-scraping" ], "Title": "Optimize web-scraping of Moscow grocery website...
48531
<p>I'm working on a framework that will be used to create simple 2D grid based games. It is using an Entity-Component-System pattern with corresponding manager classes used to control the lifespan of objects and construct them polymorphically based on an ID.</p> <p>In addition to general improvements to my code, I'm a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-30T04:08:12.813", "Id": "104968", "Score": "1", "body": "This is surprisingly very pointer heavy for no apparent reason." } ]
[ { "body": "<p>There is nothing to redesign. This is (rudely speaking) a lot of scaffolding, with no concrete usage to validate whether this is a good design.</p>\n\n<p>I suggest that you first try to implement a real <code>System</code> (like the video <code>System</code> for instance), which will unequivocally...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T02:43:56.617", "Id": "48536", "Score": "12", "Tags": [ "c++", "design-patterns", "game", "c++11", "entity-component-system" ], "Title": "An ECS model for game development"...
48536
<p>Problem:</p> <blockquote> <p>\$n!\$ means \$n × (n − 1) × ... × 3 × 2 × 1\$</p> <p>For example, \$10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800\$, and the sum of the digits in the number \$10!\$ is \$3 + 6 + 2 + 8 + 8 + 0 + 0 = 27\$.</p> <p>Find the sum of the digits in the number \$100!\$.</p> </blockquote>...
[]
[ { "body": "<p>Your first question: you could make range return a list of bigints, and reduce over it</p>\n\n<pre><code>(reduce * (range (bigint 1) 101))\n</code></pre>\n\n<p>your second question: :</p>\n\n<ol>\n<li>you dont have to explicitly use <code>seq</code>, clojure will automatically treat your string as...
{ "AcceptedAnswerId": "48546", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T03:46:09.237", "Id": "48537", "Score": "1", "Tags": [ "clojure", "programming-challenge" ], "Title": "Project Euler #20 solution in Clojure" }
48537
<p>I have a class called <code>Piece</code>, and many many subclasses of <code>Piece</code>. I want to add an instance of every single subclass of <code>Piece</code> (under the <code>pieces</code> package) to my <code>JTree</code>. Currently, I have this class with a huge function (well, 57 lines, but still) that incre...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T20:20:30.663", "Id": "85348", "Score": "0", "body": "What exactly _is_ a `Piece`? Perhaps you mean `LogicComponent`? The fact that you have so many subclasses is a sign that maybe inheritance is not the best approach. There might be...
[ { "body": "<p>My solution to keeping track of <code>Piece</code> instances would be a enum <code>PieceRepository</code>.</p>\n\n<pre><code>import java.util.ArrayList;\nimport java.util.List;\n\n\npublic enum PieceRepository {\n\n INSATNCE;\n\n private List&lt;Piece&gt; pieces;\n\n private PieceReposito...
{ "AcceptedAnswerId": "48560", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T04:45:54.050", "Id": "48541", "Score": "6", "Tags": [ "java", "tree", "inheritance", "reflection" ], "Title": "Initializing JTree" }
48541
<p>From the <a href="http://www.crummy.com/software/BeautifulSoup/bs4/doc/" rel="nofollow noreferrer">Beautiful Soup documentation</a>:</p> <blockquote> <p>Beautiful Soup is a Python library for pulling data out of HTML and XML files. It works with your favorite parser to provide idiomatic ways of navigating, search...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T07:55:49.803", "Id": "48547", "Score": "0", "Tags": null, "Title": null }
48547
Beautiful Soup is a Python library for pulling data out of HTML and XML files.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T07:55:49.803", "Id": "48548", "Score": "0", "Tags": null, "Title": null }
48548
<p>I recently began learning Clojure. In order to get better acquainted with it, I've been tackling Project Euler challenges.</p> <p>Problem 14 is not really a difficult one. It asks for the number that results in the longest Collatz sequence.</p> <blockquote> <p>The following iterative sequence is defined for the ...
[]
[ { "body": "<p><strong>CAVEAT I am not a clojure programmer.</strong> (But hopefully you will agree with what I suggest ;))</p>\n\n<p>Put all your code in functions such that all top level forms are <code>def</code>s. Similarly put your tests in <code>deftest</code> forms and run them with <a href=\"http://cloju...
{ "AcceptedAnswerId": "48583", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T08:05:04.317", "Id": "48549", "Score": "4", "Tags": [ "clojure", "programming-challenge" ], "Title": "Project Euler Problem 14 in Clojure" }
48549
<p>I need to split a list into equal sublists, e. g <code>[1..9]</code> split into groups of 3 will be <code>[[1, 2, 3], [4, 5, 6], [7, 8, 9]]</code>. I have accomplished this task in the following way:</p> <pre><code>splitInGroupsOf n = takeWhile ((n ==) . length) . map fst . drop ...
[]
[ { "body": "<p>There are <a href=\"http://hackage.haskell.org/package/split-0.2.2/docs/Data-List-Split.html#v%3achunksOf\"><code>Data.List.Split.chunksOf</code></a> and <a href=\"http://hackage.haskell.org/package/list-grouping-0.1.1/docs/Data-List-Grouping.html#v%3asplitEvery\"><code>Data.List.Grouping.splitEve...
{ "AcceptedAnswerId": "48564", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T08:39:21.077", "Id": "48552", "Score": "8", "Tags": [ "haskell" ], "Title": "Split list into groups of n in Haskell" }
48552
<p>"Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.</p> <p>For ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-01T09:21:13.343", "Id": "91369", "Score": "0", "body": "`doseq` is *not* preferable to `loop` ... `recur`. It requires mutated state to do anything, as it returns `nil`. Where both apply, use the latter. Was what you read, perhaps, tha...
[ { "body": "<p>Yes. I think you still miss a very useful part of clojure - using its various collection types to model your solution. In your problem, you could use the fact that a string is a seq and a map acts as a function to calculate the cost of a word:</p>\n\n<pre><code>;; this map will act as a function f...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T21:54:57.430", "Id": "48553", "Score": "3", "Tags": [ "clojure", "programming-challenge" ], "Title": "More succinct / ideal solution to Project Euler #22" }
48553
<p>I'm back with a Python solution for <a href="http://projecteuler.net/problem=35" rel="nofollow">Project Euler 35</a>. Any help would be appreciated; I generate the numbers by observing that all circular primes can only have digits 1, 3, 7, and 9. Then I use the Cartesian product built into itertools. I also have a <...
[]
[ { "body": "<ul>\n<li>Returning an error message instead of data is not a good approach to handling errors. Try and see what happens if you tweak your code to pass an invalid argument to <code>find_circular_primes_under</code>. Do you see your error message? No, the program raises an exception trying to format t...
{ "AcceptedAnswerId": "48584", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T09:58:11.983", "Id": "48557", "Score": "2", "Tags": [ "python", "optimization", "programming-challenge" ], "Title": "Project Euler 35 in Python" }
48557
<p><a href="http://projecteuler.net/problem=36" rel="nofollow">This one</a> was quick and simple. Any optimizations?</p> <pre><code>from timeit import default_timer as timer def sum_double_base_palindromes_under(limit): def is_palindrome(n): if str(n) == str(n)[::-1]: return True retur...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T13:26:35.130", "Id": "85296", "Score": "0", "body": "I don't mean to be an ass, but it is Project Euler's policy that you should not publish solutions to their problems online, see [here](http://projecteuler.net/about). A policy you...
[ { "body": "<p>Some quick comments:</p>\n\n<ul>\n<li><p>I don’t know why you’re defining <code>is_palindrome()</code> within your <code>sum_double_base_palindromes_under()</code> function.</p>\n\n<p>Since <code>is_palindrome()</code> is a fairly simple function, and you only call the sum function once, the perfo...
{ "AcceptedAnswerId": "48623", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T10:14:23.923", "Id": "48558", "Score": "1", "Tags": [ "python", "optimization", "programming-challenge", "palindrome" ], "Title": "Optimizing Project Euler 36 - double-base...
48558
<p>My project here works upon output that comes out of a Tesseract OCR scan using hOCR format, then I read it with JDOM 2.0 and finally save it one of my own objects, which <em>at a later point</em> needs to be serializable. I have spotted one major codesmell, which is a for-loop of 5 levels deep.</p> <p>An example hO...
[]
[ { "body": "<p>Looking at just the JDOM portion, there are a couple of tricks you can play.</p>\n\n<p>Unfortunately, XML and streams will always be an uncomfortable mix...</p>\n\n<p>The following factors in JDOM make better performance possible:</p>\n\n<ul>\n<li>DRY\n<ul>\n<li>XPathExpressions are threadsafe. Re...
{ "AcceptedAnswerId": "48566", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T11:52:35.487", "Id": "48563", "Score": "10", "Tags": [ "java", "xml" ], "Title": "Saving an XML file created by Tesseract OCR as a traversable object" }
48563
<p>I was looking at other people code and I realized that mine is not so neat after all.</p> <p>In this version, I included a base case for the merge part (when there is only 2 elements to merge, just sort it normally). I do not know this is a good idea or not, never seen it in other people' codes.</p> <p>This is the...
[]
[ { "body": "<p>Since you're asking for a <a href=\"/questions/tagged/readability\" class=\"post-tag\" title=\"show questions tagged &#39;readability&#39;\" rel=\"tag\">readability</a> review, here's my input:</p>\n\n<ul>\n<li><strong>Way too many comments</strong>. Comments should say <em>why</em>, not <em>what<...
{ "AcceptedAnswerId": "48581", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T13:19:21.207", "Id": "48573", "Score": "2", "Tags": [ "c#", "sorting", "mergesort" ], "Title": "Merge Sort optimization" }
48573
<p>I created a client side search module. Could anyone please provide review pointers on it?</p> <pre><code>var search = function(){ "use strict"; var _instanceMap = {}; var maxLimit = 50; //TODO: add a perf test to determine the scale. /** * @constructor * @private */ function _IndexCreator(_searchConfig){ th...
[]
[ { "body": "<p>Not a full code review, and my comments might be off base if you based your naming on the API you are using. The naming confuses me. I cannot read this code and know what it does without really focusing, that's not how code should read.</p>\n\n<p>For <code>_IndexCreator</code>:</p>\n\n<ul>\n<li><c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T14:09:19.913", "Id": "48575", "Score": "3", "Tags": [ "javascript", "api", "prototypal-class-design" ], "Title": "Lunr backed client side search module" }
48575
<p>I use the following code to find the lowest denominator Rational that is within a certain delta from a <code>double</code>.</p> <p>The rationale is that the I am pulling float numbers from a database and in many cases summing them. All of the numbers are calculated using simple maths such as +, -, * and /. No trans...
[]
[ { "body": "<h2>Naming</h2>\n\n<p>You definitely need to improve your variable names. Here are some suggested changes with the reasoning</p>\n\n<ul>\n<li><code>dbl</code> -> <code>value</code> (does not change much but repeating the type of a variable as its name does not add value (no pun intended))</li>\n<li><...
{ "AcceptedAnswerId": "48596", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T14:17:42.527", "Id": "48577", "Score": "8", "Tags": [ "java", "performance", "mathematics", "floating-point", "rational-numbers" ], "Title": "Finding the nearest Ration...
48577
<p>In mathematics, the mediant of two fractions</p> <p>$$ \frac {a}{c} \text{ and } \frac {b} {d} $$ is $$ \frac {a + b} {c + d}. $$</p> <p>that is to say, the numerator and denominator of the mediant are the sums of the numerators and denominators of the given fractions, respectively.</p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T14:19:23.690", "Id": "48578", "Score": "0", "Tags": null, "Title": null }
48578
the numerator and denominator of the mediant are the sums of the numerators and denominators of the given fractions, respectively.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T14:19:23.690", "Id": "48579", "Score": "0", "Tags": null, "Title": null }
48579
<p>I needed to have a Lisp function that could produce a string of a certain length, created by repeated concatenations of a another string given as argument (so for example by giving 10 and "abc" I could obtain "abcabcabca"). I came up with a perverse idea of using a circular list of characters in combination with the...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-01-05T06:31:44.787", "Id": "137717", "Score": "0", "body": "Alexandria (a very popular library) has a function for creating circular lists: http://common-lisp.net/project/alexandria/draft/alexandria.html#Sequences ." } ]
[ { "body": "<p>Not a bad approach. </p>\n\n<p>I can see one arguable bug, and have a few style notes on your code though. Lets start with the bug:</p>\n\n<pre><code>CL-USER&gt; (defparameter a \"test\")\nA\nCL-USER&gt; (pad-with-string 6 a :from-end t)\n\"tsetts\"\nCL-USER&gt; a\n\"tset\"\nCL-USER&gt; \n</code><...
{ "AcceptedAnswerId": "48601", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T14:27:42.693", "Id": "48580", "Score": "4", "Tags": [ "strings", "lisp", "common-lisp" ], "Title": "Creating a repetitive string in Common Lisp" }
48580
<p>I've built a simple class <code>RequestHandler</code> that does exactly what I want without any extras I won't be utilizing. When needed I will expand. I'm passing this object to my Router class, to route URls to the correct controller. I will also take any suggestions!</p> <p><strong>How is the readability?</stron...
[]
[ { "body": "<p>Just a quick observation I have made here, and this is by no means a full review, but you have some dead code here:</p>\n\n<pre><code>if ($parts) {\n $this-&gt;controller = ucfirst(array_shift($parts)) . 'Controller';\n $this-&gt;action = array_shift($parts);\n $this-&gt;params = ...
{ "AcceptedAnswerId": "48590", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T15:45:05.760", "Id": "48586", "Score": "1", "Tags": [ "php", "object-oriented" ], "Title": "RequestHandler: Is my code clean?" }
48586
<p>I’ve recently coded a way of checking a <a href="http://en.wikipedia.org/wiki/International_Standard_Book_Number#ISBN-10_check_digits" rel="nofollow">10-digit ISBN</a>.</p> <p>I was wondering if the code works to check the numbers, and if there are any flaws in my code.</p> <pre><code>def isbn(number): try: ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-08T16:33:51.653", "Id": "86560", "Score": "0", "body": "I am sure that you wrote this for the learning experience, at least in part – so but if ISBN parsing is a specific thing on your to-do list, the uninventively-named PyISBN module ...
[ { "body": "<p>Right now, the code doesn't work. Your code only validates ISBNs that use Arabic numerals, but some ISBNs can end in an &quot;X&quot;. Quoting from the <a href=\"http://www.isbn.org/faqs_general_questions#isbn_faq5\" rel=\"nofollow noreferrer\">ISBN FAQs</a>:</p>\n<blockquote>\n<p><strong>Why do s...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T15:50:12.920", "Id": "48588", "Score": "3", "Tags": [ "python", "python-3.x", "validation" ], "Title": "ISBN Number Check" }
48588
<p>Is there an effective way, maybe with regex, to change the following text pattern?</p> <p>I have a string like <code>abc_def_ghi_jkl</code>. I want to replace it to <code>AbcDefGhiJkl</code>. I currently use the following code to change it. Is there a more effective way than this?</p> <pre><code>implode('',array_...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-08-09T08:55:47.323", "Id": "258262", "Score": "3", "body": "What you describe is usually called PascalCase." } ]
[ { "body": "<p>You could use <code>preg_replace_callback()</code>, which replaces matches with the result of a function:</p>\n\n<pre><code>$str = \"abc_def_ghi_jkl\";\n$str = preg_replace_callback(\"/(?:^|_)([a-z])/\", function($matches) {\n// Start or underscore ^ ^ lowercase character\n return...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T16:38:38.703", "Id": "48593", "Score": "16", "Tags": [ "php", "regex" ], "Title": "Converting snake_case to PascalCase" }
48593
<p>Following my answer to <a href="https://codereview.stackexchange.com/questions/44936/unique-type-id-in-c/45079#45079">Unique type ID in C++</a>, I have worked towards a "safer" version that I am posting here.</p> <p>This is a lightweight type that can store a unique (also across compilation units) ID per type for u...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T08:46:04.793", "Id": "89925", "Score": "0", "body": "the type id trick won't work across shared libraries." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-29T09:00:16.880", "Id": "89927", "Score"...
[ { "body": "<p>The first thing I notice when looking at this code is the lack of documentation.</p>\n\n<p>I would provide some more operators. Specifically I would go for <code>operator&lt;</code> so <code>type_id_t</code> is usable as key for <code>std::map</code> and you should think about specializing <code>s...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T17:24:25.737", "Id": "48594", "Score": "20", "Tags": [ "c++", "c++11", "rtti" ], "Title": "Unique type ID, no RTTI" }
48594
<p>I always been curious on how to build great application with proper routing to my controllers, but after seeing some sources of applications like Xenforo, Joomla, it seems completely different, and mostly I can't understand them.</p> <p>From my understanding the user sends a request to the web-server, the controll...
[]
[ { "body": "<p>Kid Diamond has asked for the opinions of other on the subject of routing and whats the best practice to code and he has shown his code.\n<a href=\"https://codereview.stackexchange.com/questions/48396/router-for-mvc-framework-is-it-oo-and-good-to-go\">Here is the link</a></p>\n\n<p>Now I believe t...
{ "AcceptedAnswerId": "48605", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T17:44:33.550", "Id": "48597", "Score": "3", "Tags": [ "php", "object-oriented", "mvc", "url-routing" ], "Title": "Routing the CMS way" }
48597
<p>I have written this Perl program to prove a conjecture given a set of clauses. I've actually posted some code from it on here in another question. </p> <p>This time its all done and I've made it as fast as I need to make it. </p> <p>Now, I want to calculate the Big O notation of the program. It's something I want ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T19:21:14.703", "Id": "85339", "Score": "1", "body": "To help us understand what this code does, could you provide some sample inputs and outputs?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T20:05:...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T18:02:50.587", "Id": "48602", "Score": "2", "Tags": [ "perl", "complexity" ], "Title": "Proving a conjecture given a set of clauses - calculating complexity" }
48602
<p>I created a DAO class which is base class for all other DAO classes. </p> <p>I use Spring Framework 4 and Hibernate 4.</p> <p><strong>Question:</strong> Is there anything that could be done better? </p> <pre><code>public class GenericDaoImpl&lt;E, I extends Serializable&gt; implements GenericDao&lt;E, I&gt; { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-03T18:17:43.130", "Id": "85804", "Score": "0", "body": "I would shorten `getCurrentSession` to `getSession` which is clear enough." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T18:50:09.053", "Id":...
[ { "body": "<p>To be able to create a parameter-less constructor add the following code into your constructor. It will use reflection to set <code>entityClass</code>. This way you don't even need to worry about passing in a class type, you can extend out your generic DAO and its type will be set by parameterisat...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T18:12:20.633", "Id": "48603", "Score": "5", "Tags": [ "java", "hibernate", "spring" ], "Title": "Create better Base DAO class" }
48603
<p>Some programming languages provide a built-in (primitive) rational data type to represent rational numbers and to do arithmetic on them (e.g. the ratio type of Common Lisp and analogous types provided by most languages for algebraic computation, such as Mathematica and Maple).</p> <p>Many languages that do not have...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T19:13:05.257", "Id": "48606", "Score": "0", "Tags": null, "Title": null }
48606
In mathematics, a rational number is any number that can be expressed as the quotient or fraction p/q of two integers, with the denominator q not equal to zero.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T19:13:05.257", "Id": "48607", "Score": "0", "Tags": null, "Title": null }
48607
<p>I am making a Swing application for light local database management and I have the button <code>Run XAMPP</code>.</p> <p>When that button is pressed this code is executed:</p> <pre><code>private void jRunXAMPPButtonActionPerformed(java.awt.event.ActionEvent evt) ...
[]
[ { "body": "<ul>\n<li>Give your method a <em>proper</em> name. These auto-generated names are pure terror!</li>\n<li>You can import <code>ActionEvent</code> directly, no need to reference it with the entire package name.</li>\n<li>Your formatting is unusual at best, I'd call it bad. I know this is, for some reas...
{ "AcceptedAnswerId": "48611", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T19:14:29.950", "Id": "48608", "Score": "4", "Tags": [ "java", "swing", "file", "error-handling" ], "Title": "Executing a file through a swing button" }
48608
<p>Quoted from the manpage:</p> <blockquote> <p>tcsh is an enhanced but completely compatible version of the Berkeley UNIX C shell csh It is a command language interpreter usable both as an interactive login shell and a shell script command processor. It includes a command-line editor, programmable word comple...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T19:18:26.223", "Id": "48609", "Score": "0", "Tags": null, "Title": null }
48609
tcsh is an enhanced but completely compatible version of the Berkeley UNIX C shell, csh.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T19:18:26.223", "Id": "48610", "Score": "0", "Tags": null, "Title": null }
48610
<p>Once you define the <code>&lt;</code> operator, you can have an estimation of how the rest of relational operators behave. I'm trying to implement a way to do that for my classes. </p> <p>What I want is to <strong>define only the <code>&lt;</code> and the rest of the operators to be defaulted implicitly</strong>. W...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T22:11:34.997", "Id": "85363", "Score": "2", "body": "I unfortunately don't have much to say, but if you're wanting to see a well-established, fully fleshed out version of your concept, you could take a look at Boost.Operators: http:...
[ { "body": "<p>The problem I see is that it requires that the class be derived from <code>relational</code>, which is not a very durable design. Instead, why not use the fact that <strike>\"substitution failure is not an error\" (which has the regrettable but commonly used abbreviation SFINAE).</strike> the use...
{ "AcceptedAnswerId": "48692", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T21:18:16.993", "Id": "48622", "Score": "6", "Tags": [ "c++" ], "Title": "Implementing C++ relational operators generator" }
48622
<p><strong>Question:</strong> Is there anything you could do in order to improve the test? </p> <p>I am using Spring Framework 4, Hibernate 4, JUnit 4. All DAO unit tests inherit from TestDaoSetup class:</p> <pre><code>@ContextConfiguration(locations={ "classpath:/config/test/spring.xml", "classpath:/...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-02T12:57:56.110", "Id": "85634", "Score": "1", "body": "This is an integration test though, not a unit test. A unit test should depend on the implementation being correct only. Whereas these cases test whether the spring wire-up is cor...
[ { "body": "<pre><code>public void create_Created(){\n</code></pre>\n\n<p>This violates Java coding standards. In Java, the convention is camelCase, not snake_case. On top of that, the name <em>create_Created</em> is utterly meaningless. What is that supposed to mean? Give your tests names describing what they t...
{ "AcceptedAnswerId": "48628", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T22:16:51.170", "Id": "48624", "Score": "9", "Tags": [ "java", "unit-testing", "junit" ], "Title": "Create better Unit test" }
48624
<p>I'm working on a Unix machine where I can't use more than vanilla Perl, and I'm using Perl5.8. This script exits with a 1 if the current directory size is smaller than 1 GB (the character after <code>-d</code> is a literal "tab" character).</p> <pre><code>my $du = `du --si | tail -1 | cut -d" " -f1`; chomp $du; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T23:29:48.527", "Id": "85368", "Score": "0", "body": "Why `tail -1`? Doesn't that just choose one of the subdirectories arbitrarily?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-01T00:30:59.773", "...
[ { "body": "<p>It is unusual on Code Review, to recommend a different approach, but this process can be simplified a whole bunch..... and avoid perl entirely.....</p>\n\n<pre><code>du -s -B 1 | grep -P -q '^\\d{10,}+\\s.*'\n</code></pre>\n\n<p>It breaks down as follows:</p>\n\n<pre><code>du -s -B 1\n</code></pre...
{ "AcceptedAnswerId": "48636", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-30T22:48:12.560", "Id": "48626", "Score": "4", "Tags": [ "perl", "file-system", "unix" ], "Title": "Clean way to get size of directory" }
48626
<p>Currently I'm making a website that has a to-do list that will probably become quite long to write in html. So I decided to make a shorter version for me to write that I find more comfortable to read.</p> <p>What I am currently doing is using ajax to read the text file from the server. Once the file has been stored...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-01T01:50:55.443", "Id": "85376", "Score": "0", "body": "Why would you do it like this? Use the DOM, check out `innerHTML`." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-01T03:34:10.577", "Id": "85384"...
[ { "body": "<p>What do you mean with the variable name <code>wanted</code>? I don't understand what it has anything to do with what you are doing, so it's a badly chosen name.</p>\n\n<pre><code>if( wanted[i] === \"\\n\" )\n continue;\n</code></pre>\n\n<p>This won't do anything. Since you split by <code>\"\\n\...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-01T00:42:02.730", "Id": "48631", "Score": "2", "Tags": [ "javascript", "html", "formatting" ], "Title": "A better way to read text files into html?" }
48631