body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p><strong>Which unit testing approach and WHY do you prefer?</strong></p> <p>Inheritance-driven-testing</p> <pre><code>public class GivenSynchronizedDataLink : TestBase { internal SynchronizedDataLink Subject { get; private set; } protected Mock&lt;IDataLink&gt; DataLinkFake { get; private set; } protec...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T14:05:45.850", "Id": "78090", "Score": "0", "body": "Your question is asking for an opinion. Could you rephrase it to be less opinionated (is this a real word ) ? You could chose one of those approach and see the review of it. You c...
[ { "body": "<p>I'd favor the second one, it seems that the first one abusing inheritance (uses it for only code reuse) and I think it's harder to read because you have to go back and forth to the parent class.</p>\n\n<ul>\n<li><em>Effective Java, 2nd Edition</em>, <em>Item 16: Favor composition over inheritance<...
{ "AcceptedAnswerId": "44879", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T13:35:13.797", "Id": "44861", "Score": "2", "Tags": [ "c#", ".net", "unit-testing" ], "Title": "Unit testing - test class inheritance vs single test class" }
44861
<p>Is there a way to write this better or more Clojure way? Especially the last part with <code>with-open</code> and the <code>let</code>. Should I put the <code>-&gt;</code> form into a separate function? Is this function to overloaded (to much stuff) or is this still ok?</p> <pre><code> (defn scrape-book-cover [url ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T16:12:57.260", "Id": "78150", "Score": "2", "body": "You have many forms with single element you can ignore parens around them `java.net.URL. html/html-resource .... first :attrs :src` instead of `(java.net.URL.) (html/html-resourc...
[ { "body": "<p>@abuzittingillifirca made a good point in that you can leave the parentheses off of the <code>-&gt;</code> forms that are just a single element. </p>\n\n<p><code>html/html-resource</code> is actually quite flexible; it can take a variety of different kinds of arguments, including strings, URLs, in...
{ "AcceptedAnswerId": "44898", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T13:47:16.210", "Id": "44862", "Score": "11", "Tags": [ "clojure", "web-scraping" ], "Title": "Is this the Clojure way to web-scrape a book cover image?" }
44862
<p>I have the following two methods of completing the same task, however I'd like to know <strong><em>which is the preferred method and WHY?</em></strong> Or if there are any suggestions to complete the task in an even better, cleaner way.</p> <p><em><strong>The task</em></strong></p> <p>Find part 1 of <code>$string<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T14:05:12.077", "Id": "78089", "Score": "0", "body": "is the string always guaranteed to be delimited by /" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T14:08:33.493", "Id": "78094", "Score":...
[ { "body": "<pre><code>$string = '1/2/3/4';\n\n$change = str_replace('/',',',$string);\n\n$result = $connection-&gt;query(\"SELECT id, filename FROM pages WHERE id IN($change) ORDER BY FIELD(id,$change)\");\n\n$new_string = \"\";\nwhile($row = $result-&gt;fetch_assoc()) {\n $new_string .= $row['filename'].\"...
{ "AcceptedAnswerId": "44866", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T13:51:56.160", "Id": "44863", "Score": "2", "Tags": [ "php", "sql", "array" ], "Title": "Two script completing the same task, which is the best way?" }
44863
<p>I have a multidimensional array as a result from a webservice called from PHP. I cannot edit the webservice, but the result is as</p> <pre><code>array (size=5) 'id' =&gt; int 0 'name' =&gt; array (size=7) 'it' =&gt; string 'Tutti' (length=5) 'ca' =&gt; string 'Tots' (length=4) 'es' =&gt; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T14:03:05.650", "Id": "78086", "Score": "0", "body": "Is this complete code ? It's seems to be missing some part ? Does it work on it's own ? Are you here for a review or something else ?" }, { "ContentLicense": "CC BY-SA 3.0...
[ { "body": "<p>You can choose a (key => value) pair recursively with this function:</p>\n\n<pre><code>function array_value_recursive($key, array $arr){\n $val = array();\n array_walk_recursive($arr, function($v, $k) use($key, &amp;$val){\n if($k == $key) array_push($val, $v);\n });\n return co...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T13:52:08.773", "Id": "44864", "Score": "5", "Tags": [ "php", "recursion" ], "Title": "recursive function : filtering large multidimensional array by key element to HTML list" }
44864
<p>I wrote a <code>cstring</code> parser. It has to work with a relatively wide amount of arguments (usually 3 or 4, but maybe in future with a different amount), which are separated by an <code>,</code> or <code>;</code>. My wish is to make at least Function 1 less static and save some code. However, I don't really wa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T19:19:19.667", "Id": "78353", "Score": "0", "body": "Should really open this up to C developers. Nothing C++ about it." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T04:39:38.650", "Id": "78468",...
[ { "body": "<h1>Two-dimesional array</h1>\n\n<p>Your first function can be aggressively reduced by replacing <code>cI</code> and friends by a 2D array:</p>\n\n<pre><code>float *Receiver::parse_pid_substr(char* buffer) {\n static float pids[8];\n memset(pids, 0, 8*sizeof(float) );\n\n char rgcPIDS[8][32];\n s...
{ "AcceptedAnswerId": "44870", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T14:46:01.103", "Id": "44867", "Score": "11", "Tags": [ "c", "strings", "parsing", "floating-point", "embedded" ], "Title": "Parsing comma-separated floats and semicolon...
44867
<p>In <a href="https://codereview.stackexchange.com/questions/44821/print-out-table-with-start-end-temperatures-and-step-size/44829#comment78006_44829">this comment</a> the OP wrote,</p> <blockquote> <p>I am a newbie so i would like to know how would i parse the negetive numbers/arguments ?</p> </blockquote> <p>In ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T15:05:04.657", "Id": "78116", "Score": "1", "body": "What does using a 'modern compiler' have to do with implementing the out-of-range value part of the spec?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014...
[ { "body": "<p>After reading the specification of the input ...</p>\n\n<ul>\n<li>Optional sign</li>\n<li>One or more digits</li>\n<li>Optional decimal with one or more digits</li>\n<li>Optional exponent with\n<ul>\n<li>Optional sign</li>\n<li>one or more digits</li>\n</ul></li>\n</ul>\n\n<p>... instead of a sing...
{ "AcceptedAnswerId": "44874", "CommentCount": "12", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T14:53:59.027", "Id": "44869", "Score": "5", "Tags": [ "c++", "c", "unit-testing", "reinventing-the-wheel", "floating-point" ], "Title": "Implement strtod parsing" }
44869
Questions under this tag regroup common code issues that are often encountered in code that is posted for review. Use this tag for Community Wiki questions that aim at providing general-purpose, one-size-fits-all answers to these common issues, so that reviewers can link to them when reviewing real code.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T16:57:31.647", "Id": "44883", "Score": "0", "Tags": null, "Title": null }
44883
<p>I use SonarQube to help me try and become a better programmer to program along with 'best-practice' standards.</p> <p>There are business rules when a user is submitting data they enter in a datagridview that I encompass in a <code>Try Catch</code> block. I think the comments in the code describe fairly well what sh...
[]
[ { "body": "<p>All of your <code>Exit Try</code> statements follow an error condition. So why not throw an exception with the message and display it in the <code>Catch</code> block instead? That's the purpose of the <code>Try..Catch</code>. </p>\n\n<p>Also, to get rid of the <code>Exit For</code>, just reverse t...
{ "AcceptedAnswerId": "44890", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T18:00:22.533", "Id": "44887", "Score": "3", "Tags": [ "vb.net", "exception-handling" ], "Title": "How to reformat this code so I don't use 'Exit Try' and 'Exit For'?" }
44887
<p>Can anyone recommend improvements to the compress() method? </p> <pre><code>public class ArrayList&lt;E&gt; { private Object[] array; public static final int DEFAULT_SIZE = 20; private int size = 0; public ArrayList(){ this(DEFAULT_SIZE); } public ArrayList(int size){ array = new Object[size]; } public...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T18:17:17.700", "Id": "78169", "Score": "6", "body": "Can you explain more about what you are actually doing? Are you, knowingly that `ArrayList` exists, making your own implementation for fun? Why does it not implement the `List<E>`...
[ { "body": "<h2>General</h2>\n\n<p>There are a few things in here....</p>\n\n<ul>\n<li><p>You allow users to add a null value in the <code>add()</code> method, but you will then 'compress' it later if you remove something.</p></li>\n<li><p>you have an off-by-one error on the <code>get()</code> (but not <code>rem...
{ "AcceptedAnswerId": "44892", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T18:11:55.120", "Id": "44889", "Score": "7", "Tags": [ "java", "generics" ], "Title": "Generic ArrayList" }
44889
<p>I'm new to jQuery and trying to learn how to refactor my bloated code to make it nicer and better maintainable.</p> <p>I have a tabbed navigation which I'm using jQuery to hide and show pages depending on the selector that is clicked.</p> <pre><code> $('#search_distributors').on 'click', (e) =&gt; e.preventDe...
[]
[ { "body": "<p>It's hard to give an exact answer without knowing your HTML structure, but if we assume that:</p>\n\n<ol>\n<li>Your tab headers (apparently li-elements with classes like <code>.search_locations</code> and ids like <code>#search_distributors</code>) have some common class, such as <code>.tabheader<...
{ "AcceptedAnswerId": "44904", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T18:42:20.057", "Id": "44893", "Score": "10", "Tags": [ "javascript", "jquery", "beginner", "coffeescript" ], "Title": "Tabbed navigation to hide and show pages" }
44893
<p>I've written a small library of objects for parsing of Valve Map Files (VMF). These files are always generated and exported from either the Hammer World Editor, or a Source engine built in map making program like the PTI in Portal 2. So I can trust them to always look roughly like the following, except of course tha...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T23:19:15.543", "Id": "78224", "Score": "0", "body": "Isn't there a format specification for the language? Just to make sure that you covered every possible edge case correctly." }, { "ContentLicense": "CC BY-SA 3.0", "Cr...
[ { "body": "<p>Instead of writing your own parser by hand, I think you should use a <a href=\"https://en.wikipedia.org/wiki/Parser_generator\">parser generator</a>. If you've never used anything like that before, it requires some learning, but it's not actually that hard and the grammar is actually pretty unders...
{ "AcceptedAnswerId": "44924", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T19:12:58.230", "Id": "44895", "Score": "11", "Tags": [ "c#", ".net", "parsing" ], "Title": "Parsing Valve Map Files (VMF) into a tree like structure" }
44895
<p>I wrote a lockless queue for sending small objects from a single thread to a random worker thread.</p> <p>Assumptions:</p> <ul> <li>x86/x86_64 compiled with GCC</li> <li>one thread may Write(), multiple threads may Read()</li> <li>notifying a thread that data is available is done elsewhere</li> <li>T is copy assig...
[]
[ { "body": "<p>This line seems really strange to me:</p>\n\n<pre><code>static_assert(N!=0x80000000,\"N is too large.\");\n</code></pre>\n\n<p>Technically, it is rather odd to just compare for equality with one big number where there could be numbers even bigger. Didn't you mean:</p>\n\n<pre><code>static_assert(N...
{ "AcceptedAnswerId": "44971", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T19:14:04.613", "Id": "44896", "Score": "8", "Tags": [ "c++", "multithreading", "c++11", "queue", "lock-free" ], "Title": "Lockless Queue Multiple-Reader Singler-Writer ...
44896
<p>I have a large import task that runs as a cronjob and I want to split that task in smaller subtasks. Each subtask should be handled by an own class.</p> <p>At the cronjob entry point I prepare the import-file and want to pass it to sub-functions e.g. </p> <pre><code>$category = new categoryImport($param1, $param2)...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T20:01:19.450", "Id": "78189", "Score": "0", "body": "If you want local storage in a static implementation then use static variables. Created by `public static $var = array();` and accessed with the scope resolution operator internal...
[]
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T19:17:59.643", "Id": "44897", "Score": "1", "Tags": [ "php", "php5", "dependency-injection", "subroutine" ], "Title": "Split large import task into smaller subtasks" }
44897
<p>This is code I need to maintain. I'm trying to make this as an example for code gone bad, for C programmers going to C++.</p> <p>Please provide any comment you can. The original code is about 40 pages long, so I just gave this "small example".</p> <pre><code>void Algo::compute( Image* pInImg, Image* pImg, Image*...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T20:06:14.093", "Id": "78190", "Score": "1", "body": "Get yourself familiarized with OOPS Design Patterns, if you haven't already." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-23T20:31:37.550", "Id...
[ { "body": "<p>Given that a good rule of thumb is to keep functions small enough to fit on a page, I want the kind of screen these coders have...<br><br>\nSeriously, function calls are cheap on modern hardware, and compilers can do the inlining for you today. I'd bet the code can gain some performance simply by ...
{ "AcceptedAnswerId": "44943", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T19:53:55.920", "Id": "44900", "Score": "6", "Tags": [ "c++", "algorithm", "c++11", "image" ], "Title": "Image processing algorithm" }
44900
<p>I would like review on the following dynamic memory allocation process and suggestions on whether there are any memory leaks. Following code is not real code in use, but I'm trying to understand concepts of memory allocations and de-allocation in different ways.</p> <pre><code>class ObjMapData { private: //Header I...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T22:04:42.993", "Id": "78410", "Score": "0", "body": "Your code is broken (undefined behavior abounds). See my answer below. You should never use C style casts in your code." } ]
[ { "body": "<p>Short Answer: Yes</p>\n\n<p>Longer Answer:\nAs far as I see, your code works without any memory leaks.\nA program which helps you detect memleaks would be valgrind.</p>\n\n<p>With this code you have to be very careful. I recommend checking the pointer before assigning it in <code>SetMapData(int* p...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T20:06:44.010", "Id": "44901", "Score": "7", "Tags": [ "c++", "memory-management", "pointers" ], "Title": "Pass pointer data across multiple functions" }
44901
<p>I have a controller with just a few actions, not the whole 7 RESTful actions situation. Here's what I have so far for routing:</p> <pre><code>Snip::Application.routes.draw do get "appointment_reminder_responses/confirmation_thanks", to: "appointment_reminder_responses#confirmation_thanks" get "appointment_remin...
[]
[ { "body": "<p>Not a lot to review,</p>\n\n<p>obviously the most repeated part of your code is <code>appointment_reminder_responses</code>, if you create a variable called <code>root</code> and then built your routes with concatenations like <br>\n<code>root + \"/confirmation_thanks\"</code> then that would be a...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T20:09:31.850", "Id": "44902", "Score": "4", "Tags": [ "ruby", "ruby-on-rails", "url-routing" ], "Title": "Routes for reminders" }
44902
<p>I have a JavaScript function that takes in a user number (total amount placed on a betting table in denominations of 50) and returns an Array of the optimum chips (lowest # required) to form each stack.</p> <p>My function works, the correct array for each value tested is output - but since this should be running on...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T17:31:47.700", "Id": "78209", "Score": "0", "body": "I guess you could write the code to *look* more compact, but inlined as it is here should execute fast." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-0...
[ { "body": "<p>You could compress the code as follows. It doesn't check for early exit conditions, but since it's running on the front-end anyway, i.e. not at high volumes, the performance won't be noticeably degraded.</p>\n\n<pre><code>function chipStack(n){\n var chipValues = [1000,500,300,100,50];\n var...
{ "AcceptedAnswerId": "44907", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T17:23:55.330", "Id": "44906", "Score": "3", "Tags": [ "javascript", "optimization" ], "Title": "Number Division Theory" }
44906
<p>I'm using <code>NSInvocation</code> as a choke point in my app to help manage threading and reduce the amount of redundant code. The purpose of this class is to pass arguments from the view controllers to the API project on a background thread and return success/error on the main thread. I also have a log callback...
[]
[ { "body": "<p>This is one of my weakspots, but if you are ever concerned about a retain loop in a block, create a weak variable:</p>\n\n<pre><code>__weak typeof(self) weakSelf = self;\n</code></pre>\n\n<p>Now just use <code>weakSelf</code> anywhere you'd use <code>self</code> in that block, and there's no chanc...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T21:57:24.657", "Id": "44908", "Score": "9", "Tags": [ "multithreading", "objective-c", "memory-management", "ios", "category" ], "Title": "NSInvocation Implementation" }
44908
<p>I've just completed this binary search kata - which has some weird requirements - and I spent a little while "cleaning" up my code and making it more compact. I would appreciate some feedback on the readability of the <code>BinarySearch</code> class. I've packed a lot of logic into some of the lines and I'd like to ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T16:27:59.333", "Id": "78321", "Score": "1", "body": "please, don't include line numbers in the code or you're forcing people to remove them... can you edit it?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "201...
[ { "body": "<p>This is pretty good code. It <em>is</em> a little compact, but that only hurts readability in a few places. I will make some\nsuggestions that fluff it out just a bit, and might make it more\nunderstandable for some readers. Most of what I bring up here is\nquite minor. The important stuff is ...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T22:06:41.087", "Id": "44912", "Score": "5", "Tags": [ "ruby", "binary-search", "rspec" ], "Title": "BinarySearch Kata in Ruby" }
44912
<p>I'm doing a programming practice problem and was wondering if someone can suggest a better to create/setup the call back for the comparison function. I have the following classes:</p> <pre><code>public class myTreeItem&lt;T&gt; { private T item; private myTreeItem&lt;T&gt; left; private myTreeItem&lt;T&...
[]
[ { "body": "<h2>Comparator</h2>\n\n<p>There is no need for your interface.... <a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/Comparator.html\" rel=\"nofollow\">what's wrong with <code>Comparator</code></a>? Why do you need to have your own?</p>\n\n<p>The reason you appear to have it is because you ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T22:40:38.367", "Id": "44913", "Score": "6", "Tags": [ "java", "tree", "callback" ], "Title": "Alternate way for comparison call back function?" }
44913
<p>I just got into <code>struct</code>s and I decided to create a list using them:</p> <pre><code>#include&lt;stdio.h&gt; #include&lt;stdlib.h&gt; int main(void) { char counter; struct list { int x; struct list *pointer1; }; struct list test; struct list *pointer2; p...
[]
[ { "body": "<p>This is actually rather unconventional code. The head node of this list, <code>test</code>, resides on the stack. All of the subsequent nodes are allocated from the heap using <code>malloc()</code>. Since you never call <code>free()</code> on the memory returned by <code>malloc()</code>, you ha...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T23:10:45.510", "Id": "44917", "Score": "4", "Tags": [ "c", "linked-list", "pointers" ], "Title": "Creating a list using a struct in C" }
44917
<p>I need to pull the version # out of a Vim script that might look something like:</p> <pre><code> " some header blah blah " Version: 0.1 [a bunch of code] " Version: fake--use only the first version </code></pre> <p>The expected output is <code>0.1</code>. If a Version # doesn't exist, it should return the empty...
[]
[ { "body": "<p>I haven't found a terser approach using only built-ins, but having a little more confidence now in Powershell, I think I'd simply refactor out the group matching code:</p>\n\n<pre><code>filter Select-MatchingGroupValue($groupNum) {\n if (! $groupNum) {\n $groupNum = 0\n }\n select ...
{ "AcceptedAnswerId": "51478", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T00:39:39.117", "Id": "44920", "Score": "6", "Tags": [ "regex", "powershell" ], "Title": "Extract version string from text file with Powershell" }
44920
<p>I am doing some programming on the side and would just like to know if I'm going in the right direction with my code.</p> <pre><code>public class FileTransfer { #region Variables private const int MAX_CHUNK_SIZE = (1024 * 5000); private static BinaryWriter fileWriter; private static File...
[]
[ { "body": "<p>Why all these <code>private static</code> members? Instead of making them <code>private static</code>, you should be passing them around as parameters and return values, or take them in (from the constructor) as <em>dependencies</em>.</p>\n\n<p>These <code>private static</code> variables make the ...
{ "AcceptedAnswerId": "45003", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T00:57:44.643", "Id": "44921", "Score": "11", "Tags": [ "c#", "file", "stream" ], "Title": "File transfer over a stream" }
44921
<p>I've created this socket class to use in my web server application. I have two classes: one for the socket and the other for the webserver.</p> <pre><code>//#define WIN32_LEAN_AND_MEAN #include &lt;iostream&gt; #include &lt;string&gt; #include &lt;Winsock2.h&gt; #include &lt;Windows.h&gt; #include &lt;Ws2tcpip.h&g...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T14:53:44.500", "Id": "78520", "Score": "0", "body": "Don't delete the code from the question, nor edit it, after it has been reviewed: [see this for further details](http://meta.codereview.stackexchange.com/a/1483/34757)." } ]
[ { "body": "<p>You use \"short port\" in several places, but a port number should be an \"unsigned short\".</p>\n\n<p>You're calling Close() all over the place before throwing an exception. It smells like duplicate code. Consider catching the exception then freeing the resources.</p>\n\n<p>Instead of manually ...
{ "AcceptedAnswerId": "44951", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T02:29:45.733", "Id": "44928", "Score": "5", "Tags": [ "c++", "windows", "socket" ], "Title": "Socket class for use in web server" }
44928
<blockquote> <p>A prime number util, which provides 3 APIs - find the nth prime, find the next prime, and find all primes up to n.</p> </blockquote> <p>I must admit this code has been influenced a lot by discussions <a href="https://codereview.stackexchange.com/questions/38084/suggestions-for-improvement-on-project-...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T11:17:47.320", "Id": "78261", "Score": "0", "body": "Nice question!!" } ]
[ { "body": "<ol>\n<li><p>You should indicate in the javadoc of the class that it's thread-safe. </p></li>\n<li><p>You should use a private lock object instead of <code>synchronized</code> methods:</p>\n\n<pre><code>private final Object lock = new Object();\n...\npublic synchronized List&lt;Integer&gt; getPrimesU...
{ "AcceptedAnswerId": "44947", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T03:51:05.247", "Id": "44929", "Score": "5", "Tags": [ "java", "algorithm", "primes" ], "Title": "Prime number util class" }
44929
<p>Please let me know if I have over/under explained my question :)</p> <p>HTML table row - the numerals from each id attribute, in this example "408" and "409", are the database tables primary ID numbers, one database table row per HTML table cell.</p> <pre><code>&lt;tr&gt; &lt;td id="FieldId408"&gt;&lt;!-- inpu...
[]
[ { "body": "<ol>\n<li><p>For this:</p>\n\n<blockquote>\n<pre><code>// Create an array of '?,' values - one for each id\nforeach($deleteRowArray as $addBind) {\n $array[] = '?,';\n}\n\n// Remove the last array values comma\nend($array);\n$array[key($array)] = '?';\nreset($array);\n\n// Create the finished quer...
{ "AcceptedAnswerId": "44934", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T04:13:15.240", "Id": "44930", "Score": "5", "Tags": [ "php", "jquery", "mysql", "pdo" ], "Title": "PDO prepared statement - binding variable number of values" }
44930
<p>I need to have an unique ID for any type in C++ for a variant type. Is this code reliable for getting the ID? I don't care to have same ID for same type between multiple runs. Sorry for typos/formatting, I wrote the code on my phone and tested on Ideone.</p> <pre><code>#include &lt;iostream&gt; struct Counter { ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2019-06-23T13:59:55.093", "Id": "435492", "Score": "0", "body": "Use [`type_index`](https://en.cppreference.com/w/cpp/types/type_index/operator_cmp). (Yours is a standard problem with a standard solution from the standard library, which is thi...
[ { "body": "<p>Re. the algorithm, IMO it looks safe, with only two caveats:</p>\n\n<ul>\n<li><p>I'm not sure that it's thread-safe.</p></li>\n<li><p>It looks safe, because of the \"one-definition rule\". I worried that if multiple source files ('translation units') invoke <code>TypeID&lt;int*&gt;::value()</code>...
{ "AcceptedAnswerId": "44941", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T06:17:45.140", "Id": "44936", "Score": "13", "Tags": [ "c++", "c++11", "template-meta-programming" ], "Title": "Unique type ID in C++" }
44936
<p>I want some feedback on the program I developed in C for printing the permutations of a given string.</p> <pre><code>#include &lt;stdio.h&gt; bool isUnique(char x[], int y) { int i, j; for (i = 0; i &lt; (y-1); i++) for (j = i+1; j &lt; y; j++) if (x[i] == x[j]) return false; return t...
[]
[ { "body": "<ul>\n<li><p>Do not use single-character names for variables. This will make your code harder to understand. Give them names based on their significance to the program.</p></li>\n<li><p>Put your two arrays on separate lines for clarity:</p>\n\n<pre><code>char a[] = {'1','2','3','4'};\nchar b[] = {'...
{ "AcceptedAnswerId": "44940", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T06:25:29.920", "Id": "44938", "Score": "10", "Tags": [ "c", "strings", "recursion", "combinatorics" ], "Title": "Printing permutations of a given string" }
44938
<blockquote> <p>Construct a matrix with the following property:</p> <ol> <li><p>North-west to South East diagonals are squares.</p> </li> <li><p>Matrix[i][j] + 1 = Matrix[j][i] for each i less than j.</p> </li> </ol> </blockquote> <p>Example of such m a matrix is <a href="https://math.stackexchange.com/questions/720797...
[]
[ { "body": "<p>I don't believe that your description uniquely defines the matrix. However, you can fill the upper-right triangle merely by pattern recognition. Starting from the diagonal going up, each column is a sequence descending by 2. From there, just apply the transpose-increment rule.</p>\n\n<pre><code...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T06:43:00.687", "Id": "44939", "Score": "2", "Tags": [ "java", "matrix" ], "Title": "A matrix with square diagonals and transpose being increments of other" }
44939
<p>I have settled with this type of structuring of unit tests.</p> <p>Basic idea is that there is a base test class for the tested class, and a subclass for every tested method. They use the mocks and everything from the base test class, the point being that the test would remain small, and you don't have to create ev...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T08:34:06.133", "Id": "78253", "Score": "1", "body": "http://codereview.stackexchange.com/a/44879/7076" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T12:47:08.393", "Id": "78283", "Score": "1"...
[ { "body": "<p>There are a few major differences between what I understand from your code and what I understand from the post you mention.</p>\n\n<p><strong>Inheritance vs Nesting</strong><br>\nYour code suggests that there is a <em>subclass</em> for each tested method, although the post talks about <em>nested c...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T08:07:55.587", "Id": "44945", "Score": "1", "Tags": [ "c#", "unit-testing" ], "Title": "Structuring unit tests" }
44945
<p>This is a simple load more plugin, built for teaching purposes. For this reason, it's not pretty in terms of output.</p> <p>I'd like to know if this can be improved, or if anyone can spot any major problems with this. The one thing I'm concerned about is the 'templating', whereby it gets the template from the initi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-06-08T05:02:53.523", "Id": "245042", "Score": "0", "body": "May be you help jquery plugin http://makenskiy.com/demo/jquery.spoiler-list/documentation/index_eng.html" } ]
[ { "body": "<p>From some staring at your code</p>\n\n<ul>\n<li>There are no comments, at all</li>\n<li>You <code>$.ajax({</code> call should handle failure by implementing <code>error</code></li>\n<li><p>The <code>items</code> treatment in <code>success</code> seems little clumsy, first I would not put the funct...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T09:29:04.807", "Id": "44948", "Score": "5", "Tags": [ "javascript", "php", "jquery", "reinventing-the-wheel" ], "Title": "jQuery Load More Plugin" }
44948
<p>I want to get some best practices and code corrections.</p> <p><strong>JS</strong></p> <pre><code>function clock(){ var currentTime = new Date() var hours = currentTime.getHours() var minutes = currentTime.getMinutes() var seconds = currentTime.getSeconds() var timeOfDay = ( hours &lt; 12 ) ? "AM" : "PM"...
[]
[ { "body": "<p>initial findings:</p>\n\n<p>You aren't using the <code>init</code> function, so why keep it. Whatever code you don't need: get rid of it.<br>\nYour <code>clock</code> function calls itself sort-of recursively with a 1 second interval, due to your using the <code>setTimeout</code> function.<Br>\nYo...
{ "AcceptedAnswerId": "44957", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T12:03:44.927", "Id": "44955", "Score": "7", "Tags": [ "javascript", "datetime" ], "Title": "JS Clock widget" }
44955
<p>Is better to use <code>$id_name ( Class A Method b() )</code> OR <code>$id_name_2 ( Class A Method c())</code>?</p> <pre><code>&lt;?php Class A { function a(){ $params = array( 'id'=&gt; 1, 'name' =&gt; 'b', ); $id_name = $this-&gt;b($params); $id_name...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-27T02:42:34.633", "Id": "79284", "Score": "0", "body": "Is `$params` being used at all inside of the \"Code Performing Operations?\" If not, both methods are nearly identical." } ]
[ { "body": "<p>You want to be using method B. It will make for more readable code and will lead to less mystery bugs.</p>\n\n<p>One cool PHP trick for extracting an assosiative array into variables is the <a href=\"http://www.php.net/extract\" rel=\"nofollow\">Extract</a> method.</p>\n\n<pre><code>$params = arr...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T12:16:08.073", "Id": "44956", "Score": "1", "Tags": [ "php" ], "Title": "Practice extracting variables" }
44956
<p>I have a PL/SQL stored procedure which searches for a row in 3 different tables (not all columns are the same).</p> <p>The logic goes as follows:</p> <blockquote> <pre class="lang-none prettyprint-override"><code>Search for the item in the first table If item was found select the details of it from the f...
[]
[ { "body": "<p>I am not sure there is a way to reduce the number of if-statements and nesting. What is possible though is to improve the performance of the conditions you have that check those conditions.</p>\n\n<p>The count(*) is inefficient. Consider adding a 'ROWNUM = 1' condition to your where clause in a wa...
{ "AcceptedAnswerId": "45005", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T12:46:28.560", "Id": "44963", "Score": "3", "Tags": [ "sql", "oracle", "stored-procedure", "plsql" ], "Title": "Searching through tables for a value" }
44963
<p>I have a server side PHP file which processes Ajax requests from the client browser. Some requests are only valid if they originate from an Administrator in the application, others are only valid if they originate from a Manager in the application, and the rest are valid if any system user makes the request.</p> <p...
[]
[ { "body": "<p>you could find out initially whether the user is admin or manager and then maintain negative lists for the two.</p>\n\n<pre><code>boolean isManager = isManager();\nboolean isAdmin = isAdmin();\n\nmanagerNegativeList = {addToSchedule,...};\nadminNegativeList = { changeTitle,...}\n\nif(isManager){\n...
{ "AcceptedAnswerId": "44985", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T14:09:05.630", "Id": "44972", "Score": "4", "Tags": [ "php" ], "Title": "Better PHP Ajax Request Processing Structure" }
44972
<p>I have completed an application which gathers specific records and marks them as <code>Collected</code>. As of now, the application runs perfectly and does exactly what I need it to, but the problem comes in when a large data set is reviewed. If I am pulling records for one day or even maybe a week, it runs at a dec...
[]
[ { "body": "<p>There are a few optimizations that can be done in your code (such as using a <code>break</code> in the inner loop after a match is found - but reverting the order of the 2 loops) - but leaving the complexity order to O(n^2).</p>\n\n<p>A better approach instead is using a dictionary. Since you have...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T14:37:39.763", "Id": "44973", "Score": "5", "Tags": [ "c#", "performance", "linq", ".net-datatable" ], "Title": "Better method for updating data table" }
44973
<p>The code below takes a specified number of card decks, and shuffles them according to the Fisher-Yates method. Does this implementation have any bias?</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace randomShuffle { class Program { stati...
[]
[ { "body": "<h3>Comments:</h3>\n\n<p>about all of your comments add close to no value to your code.</p>\n\n<blockquote>\n<pre><code>//get random number from 0 to new range of unshuffled deck\nint randomDraw = r.Next(0, initial.Count);\n</code></pre>\n</blockquote>\n\n<p>Your comment just writes out, what your co...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T15:18:06.600", "Id": "44980", "Score": "11", "Tags": [ "c#", "random", "playing-cards", "shuffle" ], "Title": "Card shuffling with Fisher-Yates method" }
44980
<p>I've been creating javascript things for a good few months now, as practise but whenever I use a functions I just create it and plug in the arguments. I'm never touching modules or classes or anything, and I just want to know how this code could be better, using modules and classes. Various function are sort of par...
[]
[ { "body": "<p>On the first pass the code was pretty easy to follow but are all those global variable intended?</p>\n\n<p>Globals I noticed in my look through... May be more.</p>\n\n<pre><code>breakpoint\ntypeASlidersIds\ncurrentBreakpoint\ninitial\ntimer\nslider\nsliderParent\nsliderHtml\n</code></pre>\n\n<p>I ...
{ "AcceptedAnswerId": "44993", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T16:14:12.453", "Id": "44984", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Should I use modules here? Could someone explain objects?" }
44984
<p>I have multiple menus that will change languages in one Sub that will handle multiple events of the menus click, It is working for me right now, I'm just wondering if there is better way to do it... I'm using the menus name to call the process for each menus.</p> <pre><code> Private Shared Sub CheckMenuItem(ByVa...
[]
[ { "body": "<p>The <code>ToolStripItem</code> contains a property called <code>Tag</code> which is used to store extra information about a menu item. This is where you could store information about the language. Then your event could be generalized by using the information in <code>Tag</code>.</p>\n\n<pre><code>...
{ "AcceptedAnswerId": "47032", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T16:42:43.900", "Id": "44987", "Score": "3", "Tags": [ "vb.net", "winforms" ], "Title": "Handle multiple menu click events in one Sub" }
44987
<p>I am creating a user permission system. I will have my user permissions set up off of "objects" and not pages. For example, I have an <code>EVENTS</code> section. Within that section, there are <code>FORMS</code>, <code>FEES</code>, etc. I want to be able to handle permissions down to the child levels.</p> <p>Here ...
[]
[ { "body": "<p>The sub-query as a concept is not a problem... you need to do that work, and this is a decent way to do it.</p>\n\n<p>It would be better if it was expressed as a direct lookup... like:</p>\n\n<pre><code>WHERE `po`.`object`='EVENTS'\n OR exists (\n SELECT `sub`.`id`\n FROM `permission_o...
{ "AcceptedAnswerId": "44990", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T16:44:18.050", "Id": "44988", "Score": "5", "Tags": [ "optimization", "performance", "mysql", "sql" ], "Title": "SQL Query that pulls rows in current table based on parent ...
44988
<p>This code is to allow calling any stored procedure with one user defined table as the parameter.</p> <p>I usually use Entity Framework, but I just don't need it for my current solution, so I am rolling my own connection here:</p> <pre><code>public class GenericDataModel { public GenericDataModel(string connect...
[]
[ { "body": "<blockquote>\n <p>Looking for any resource leaks or other missed/hidden issues.</p>\n</blockquote>\n\n<p>Have a <code>using</code> statement for your <code>var transaction</code> instance: because <code>SqlTransaction</code> implements <code>IDisposable</code> (<a href=\"http://msdn.microsoft.com/en...
{ "AcceptedAnswerId": "44997", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T17:16:40.483", "Id": "44991", "Score": "4", "Tags": [ "c#", "sql" ], "Title": "Generic class to call table parametered stored procedures" }
44991
<p>I need some help refactoring my solution to the problem below:</p> <p><strong>Problem Statement</strong></p> <blockquote> <p>An Association of Computer Scientists meets on a weekly basis. There is a certain number of seats in the meeting room and all members know their seats. For example, if there are 10 seats and o...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T19:37:45.127", "Id": "78355", "Score": "2", "body": "Do you know the maximum number of inputs and do you have a time limit? I'm curious what kind of runtime is likely going to be required. I'm fairly certain that there is a sub-quad...
[ { "body": "<p>I plan to think up a better algorithm later and post an answer on that, but for now, I'd like to offer a critique of your existing code.</p>\n\n<hr>\n\n<p>Typically <code>using namespace std;</code> should be avoided in favor of either using the <code>std::</code> qualifier or just importing the i...
{ "AcceptedAnswerId": "45000", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T17:57:27.957", "Id": "44998", "Score": "11", "Tags": [ "c++", "complexity" ], "Title": "Refactoring my problem-solution to reduce complexity" }
44998
<p>I have a map of objects and errors associated with those objects.</p> <p>I have to do the following:</p> <ol> <li>populate the errors in the object</li> <li><p>populate errors for valid objects based on the following:</p> <ul> <li>check the indicator property in the object ( Y | N | other )</li> <li>if all have Y...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T18:40:16.863", "Id": "78347", "Score": "0", "body": "How many records are we talking about here? more than 10, more than 100 more than 10,000 or more than 1,000,000 ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate...
[ { "body": "<p>Just a few generic notes:</p>\n\n<ol>\n<li><p>I guess you're using SLF4J here:</p>\n\n<blockquote>\n<pre><code>Logger.info(\"Validation errors exist in the file for row {}\", someObj.toString());\n</code></pre>\n</blockquote>\n\n<p>The <code>toString()</code> call is unnecessary, SLF4J will call i...
{ "AcceptedAnswerId": "45063", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T18:26:40.503", "Id": "44999", "Score": "6", "Tags": [ "java" ], "Title": "Populate errors for objects" }
44999
<p>I'm reading/writing half precision floating point numbers in C#. These are basically 16 bit floats, compared to the usual 32/64 bit floats and doubles we are used to working with.</p> <p>I've taken some highly tested Java code from an obvious "expert on the subject" <a href="https://stackoverflow.com/a/6162687/1294...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T19:58:42.593", "Id": "78366", "Score": "1", "body": "Does it work? Does it do as you expect?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-26T04:40:49.733", "Id": "79106", "Score": "0", "bo...
[ { "body": "<blockquote>\n <p>Is this correct?</p>\n</blockquote>\n\n<p>Maybe.</p>\n\n<p>For a start, the <code>&gt;&gt;&gt;</code> operator doesn't exist in C#.</p>\n\n<p>Taking a guess, I replaced <code>&gt;&gt;&gt;</code> with <code>&gt;&gt;</code> and then wrote the following 'unit test' for it:</p>\n\n<pre...
{ "AcceptedAnswerId": "45709", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T19:07:55.540", "Id": "45007", "Score": "3", "Tags": [ "c#", "floating-point" ], "Title": "Half precision reader/writer for C#" }
45007
<p>I recently made a 140-lined Pong game in C# using forms.</p> <p>Since I'm very new to programming, I'd like if somebody would please read it and give me advice on where to improve, what you believe I did wrong and most of all, what should have been done better and how.</p> <p>Plus, would it be somewhat useful to i...
[]
[ { "body": "<p>Here are a few observations:</p>\n\n<ol>\n<li><p>In <code>Form1_KeyDown</code> and <code>Form1_KeyUp</code>, the logic would be cleaner organized into a <code>switch</code> statement:</p>\n\n<pre><code>private void Form1_KeyDown(object sender, KeyEventArgs e)\n{\n switch (e.KeyData)\n {\n ...
{ "AcceptedAnswerId": "45021", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T19:40:34.497", "Id": "45011", "Score": "13", "Tags": [ "c#", "beginner", "game", "winforms" ], "Title": "Small C# Pong game" }
45011
<p>I have a form that requires a calculation when clicked on a multiple drop down selector, and still displays the clicks of the courses in real time and lastly calculates the sum total of the courses.</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;style&gt; div { color:blue; } div#five { c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T20:30:34.897", "Id": "78378", "Score": "0", "body": "Could you elaborate on the purpose of the script inside the first <script>-tag and the div-elements before it? Are they relevant to the question?" }, { "ContentLicense": "...
[ { "body": "<p>From what I understand, the functionality you want is:</p>\n\n<ul>\n<li>Displaying the prices of all the selected items separately</li>\n<li>Displaying the sum of prices of items that are selected</li>\n</ul>\n\n<p>I'd do this by adding the price information directly to the html option elements, f...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T19:57:07.923", "Id": "45012", "Score": "2", "Tags": [ "javascript", "jquery", "dom" ], "Title": "How to do a small calculation on a drop down when clicked?" }
45012
<p>I'm refactoring some code around a couple of ASP.NET Web Forms pages and decided to try out a variation of the Abstract Factory pattern of my own design. I need to create an implementer of an abstract class based on what query string value is available.</p> <p>Here's (a simplified version of) what I have right now:...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T20:37:43.760", "Id": "78379", "Score": "0", "body": "What is your desired behavior if your querystring looked something like this: `?class1=someVal&class2=someOtherVal`? That's something to consider, since querystrings are client-fa...
[ { "body": "<p>I Think you should do it more generic:</p>\n\n<pre><code>public static class Factory\n{\n static Dictionary&lt;String, Func&lt;String, Abstract&gt;&gt; classes;\n\n public static Abstract GetInstance(String s){\n if(!classes.ContainsKey(s)) throw new Exception();\n Func&lt;Stri...
{ "AcceptedAnswerId": "45112", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T20:18:52.183", "Id": "45013", "Score": "6", "Tags": [ "c#", "design-patterns", "asp.net" ], "Title": "Advice on \"Factory\" Pattern Implementation" }
45013
<p>I decided to try to make a simple RPS implementation in Java 8, the following notes should be said first:</p> <ul> <li>At a later point it should support RPSLS aswell, as any other Gesture-game variant.</li> <li>At a later point it should support different views, for example a graphical one.</li> <li>I have made a ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-09-20T19:36:54.353", "Id": "115917", "Score": "2", "body": "Where are the tests?" } ]
[ { "body": "<ul>\n<li><p>I like your usage of Java 8. I'm learning a lot just by reading your code. I'm loving Java 8 a lot and I haven't even used it myself yet.</p></li>\n<li><p>Use a <code>GestureRule</code> class. Take a look at <a href=\"https://codereview.stackexchange.com/questions/36426/rock-paper-scisso...
{ "AcceptedAnswerId": "45027", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T20:25:11.983", "Id": "45015", "Score": "15", "Tags": [ "java", "game", "lambda", "rock-paper-scissors" ], "Title": "Basic Rock-Paper-Scissors implementation" }
45015
<p>How can I write this OR statement better, allowing for growth in number of values?</p> <pre><code>var isNewFile = (progressID == 10 || progressID == 20 || progressID == 21); </code></pre> <p>I was thinking of this:</p> <pre><code>var isNewFile = progressID.Contains (10,20,21) </code></pre> <p>OR using Linq:</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-20T16:56:46.020", "Id": "78375", "Score": "2", "body": "What's wrong with that? Do you need a dynamic list of possible IDs?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-20T16:59:02.993", "Id": "78376...
[ { "body": "<p>For something this simple, I think using the <code>||</code> is fine, however, if you need to use the list of acceptable integers more generally or avoid hard-coding the set in a single expression<sup>1</sup>, you can use something like this:</p>\n\n<pre><code>var newFileProgressIds = new[] { 10, ...
{ "AcceptedAnswerId": "45017", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-20T16:55:40.453", "Id": "45016", "Score": "2", "Tags": [ "c#", "linq" ], "Title": "Refactor C# OR statement using Linq" }
45016
<p>It returns <code>true</code> for:</p> <blockquote> <pre><code>a*(b+c) ()() (()) ((!!(123(x)))) </code></pre> </blockquote> <p>and returns <code>false</code> for:</p> <blockquote> <pre><code>(a((b+c)) )()( ))(( (rsd+3)*(-3-a)) </code></pre> </blockquote> <p>As you can see, the logic is simple. Can you confirm f...
[]
[ { "body": "<p>You need to maintain open and closed braces count in your method, to check the validity of the closed braces. </p>\n\n<pre><code>boolean isValid(String s, int i, int open, int closed){\n if(i == s.length()){\n if(open != closed) return false;\n return true;\n } \n\n if(s.g...
{ "AcceptedAnswerId": "45035", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T20:44:05.857", "Id": "45020", "Score": "6", "Tags": [ "java", "recursion", "linked-list", "validation" ], "Title": "Validating that all open/close parentheses are correctly...
45020
<p>I wrote a messy function and I am wondering if you see any way I could clean it up. Essentially it takes in a list <code>e_1=2&amp;e_2=23&amp;e_3=1</code> and makes a queryset out of it, maintaining the ordering.</p> <pre><code>from operator import itemgetter def ids_to_students(items, prefix=0): if prefix ==...
[]
[ { "body": "<p>Tuples are sorted primarily by the first item of each. If they are all unique, specifying <code>key=itemgetter(0)</code> makes no difference. </p>\n\n<p>This code</p>\n\n<pre><code>if prefix == 0:\n etuples = sorted([(k,v) for k,v in items if k[:2] == 'e_'], key=itemgetter(0))\n ituples ...
{ "AcceptedAnswerId": "45037", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T21:21:38.527", "Id": "45023", "Score": "7", "Tags": [ "python", "django" ], "Title": "Building SQL query" }
45023
<p>The lifetimes of various objects referring to each other are sometimes only known at runtime. For example, in a side scrolling shooter game, a <code>HomingMissile</code> instance might have a pointer to the <code>Target</code> instance it is following. But if the <code>Target</code> is killed before the missile arri...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T23:53:20.680", "Id": "78419", "Score": "0", "body": "I'm surprised that the std pointers aren't good enough. Target has to be owned by something which controls its lifetime. If you don't want to have Target in a shared_ptr and give ...
[ { "body": "<blockquote>\n<pre><code>Foo *foo = new Foo;\n</code></pre>\n</blockquote>\n\n<p>This isn't safe: an exception later on will leak the object.</p>\n\n<blockquote>\n<pre><code>///////////////////////////////////////////////////////////////////////\n</code></pre>\n</blockquote>\n\n<p>These waste vertica...
{ "AcceptedAnswerId": "45051", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T21:34:45.883", "Id": "45025", "Score": "5", "Tags": [ "c++", "c++11", "pointers", "smart-pointers" ], "Title": "Proposed solution to dangling pointers: a non-owning smart p...
45025
<p>I am experimenting with streams and lambdas in Java 8. This is my first serious foray using functional programming concepts; I'd like a critique on this code.</p> <p>This code finds the Cartesian product of three sets of <code>int</code>s. My questions/complaints about this snippet are:</p> <ul> <li>Are nested <co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T00:39:17.333", "Id": "78428", "Score": "1", "body": "What is `Product`... you should probably include that in the review?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T15:40:46.947", "Id": "7852...
[ { "body": "<p>Your code is odd in the sense that it is going to a lot of effort to calculate that 10<sup>3</sup> is 1000.</p>\n\n<p>I understand why you are doing it, but I took the liberty of changing the <code>count()</code> terminating function and replacing it with:</p>\n\n<pre><code>StringBuilder sb = new ...
{ "AcceptedAnswerId": "45052", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T21:47:25.560", "Id": "45026", "Score": "18", "Tags": [ "java", "functional-programming", "stream", "lambda" ], "Title": "Effective use of multiple streams" }
45026
<p>I have this script that I need to run a tab (jquery). Mainly I need to hide some div and add class (you sure have understood).</p> <p>How should it be written in a more elegant and readable?</p> <pre><code>function fun1(){ $('#tab1 a').addClass('selected'); $('#tab2 a').removeClass('selected'); $('#tab3 a').remove...
[]
[ { "body": "<p>It sure could be written in a more agreeable way ;)</p>\n\n<p>First off, you might want to handle more tabs and divs in the future, so you can gather their <code>id</code>s into an array:</p>\n\n<p>Either 2 arrays : <br>\n<code>var tabs = ['tab1','tab2','tab3'];</code><br>\n<code>var divs = ['div1...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T22:22:35.627", "Id": "45036", "Score": "5", "Tags": [ "javascript", "jquery", "beginner" ], "Title": "jQuery Tab function" }
45036
<p>I have developed a service to automatically detect whether an app has started. If the user forbid this app to start (could be chosen from a list of apps), a dialog will be shown.</p> <pre><code>public class AppStartReceiver extends Service { private static final int DELAY_IN_MS = 2000; private List&lt;Strin...
[]
[ { "body": "<ul>\n<li>Code-Style: Good</li>\n<li>Functionality: no problem seen</li>\n<li>Potential Bugs: only one I can see</li>\n<li>Android-Expert-Level: I am not an android expert.</li>\n<li>Android-Basic-Level: Everything looks sane</li>\n</ul>\n\n<p><strong>Bug</strong> (in jest):</p>\n\n<p>People can play...
{ "AcceptedAnswerId": "45048", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T22:28:43.460", "Id": "45039", "Score": "7", "Tags": [ "java", "android" ], "Title": "Android close running apps" }
45039
<p>Because we have a mix of both icons for core items and .png icons for custom items, I've developed an easy way to theme them (alter the color) all of them easily that will work across all browsers.</p> <p>Prior to this, I tried CSS and SVG options and they just weren't as simple as this option (but probably less ov...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T02:22:49.493", "Id": "78438", "Score": "1", "body": "Can you provide a fiddle? So that we can see it in action?" } ]
[ { "body": "<p>Pretty nice overall. You're missing a semi-colon or two, but otherwise it's a nice solution.</p>\n\n<p>The only real criticism I have are the \"magic numbers\" in there, like the 40x40 size that's hardcoded everywhere. Technically, you could derive the canvas dimension from the image, or pass the ...
{ "AcceptedAnswerId": "45062", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T22:38:38.847", "Id": "45041", "Score": "5", "Tags": [ "javascript", "jquery", "image", "canvas" ], "Title": "Utilizing HTML5 Canvas to apply color theme to .png icons" }
45041
<p>I have created a little console tool that simply does commands that you enter.</p> <p>The commands are stored in a txt file. Right now I only got 2 commands: <code>getTime</code> and <code>getCommands</code>.</p> <p>Pretty simple, but I'm not sure I'm doing anything the most optimal way, which is why I am asking ...
[]
[ { "body": "<ul>\n<li><p>While it is okay to put <code>using namespace std</code> in a local scope (such as a function), it's especially problematic to put it into a header file. By doing this, anyone including it will be forced to have that namespace code exposed globally, and you shouldn't force that on anyon...
{ "AcceptedAnswerId": "45047", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T23:28:55.587", "Id": "45043", "Score": "11", "Tags": [ "c++", "beginner", "console", "file" ], "Title": "Console command tool" }
45043
<p>This is a sign up function called on form submission. It firstly inserts key user data into the <code>users</code> table. If successful, secondary data is then inputted into respective tables (such as user job titles and user experience). I'm not really sure whether stacking queries 2-5 is the best way to do it, so ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T00:16:56.273", "Id": "78421", "Score": "2", "body": "Just so it's said, your code is pretty intimate with the structure of the DB. Which will end up being annoying later on, particularly if this is running outside of the model/DAL....
[ { "body": "<ol>\n<li><p>If the second or later query fails you'll have inconsistent data in your database. Consider using atomic <a href=\"http://www.php.net/manual/en/pdo.begintransaction.php\" rel=\"nofollow noreferrer\">transactions</a>.</p></li>\n<li><p><code>$query_2</code>, <code>$query_3</code> are bad n...
{ "AcceptedAnswerId": "45061", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T23:51:21.837", "Id": "45046", "Score": "10", "Tags": [ "php", "optimization", "php5", "pdo" ], "Title": "PDO sign up function inserting data into multiple tables" }
45046
<p>I have a manager class that will manage an unknown number of objects. I'm currently storing the objects in a <code>NSMutableArray</code> object, and when I need to find one, I iterate through the array comparing pointers.</p> <p>For example, I have an array called <code>managedObjects</code>. I get a delegate met...
[]
[ { "body": "<p>I'm not an Objective-C guy but, I do know that if you used some sort of hash table structure and could define a hashcode for these objects, that you'd be able to pull them out much faster. </p>\n\n<p>You said at times you \"need to find one\", I would assume you would know enough about it to be ab...
{ "AcceptedAnswerId": "45056", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T02:39:46.083", "Id": "45054", "Score": "6", "Tags": [ "optimization", "performance", "object-oriented", "objective-c", "pointers" ], "Title": "How best to keep track of...
45054
<p>I am writing a D3D9 hook plugin to give back to a community that helped me learn programming. It is a community based on programming and scripting for games.</p> <p>The plugin is supposed to hook d3d9.dll and allow clients to read pixels from the backbuffer. That is the entire extent of the plugin.</p> <p>Thus I h...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T04:13:36.403", "Id": "78464", "Score": "0", "body": "From a code review standpoint, I find it interesting that you feel a need to add these comments. +1 congrats, you pass the 1st post review ;) - note that answerers may review **an...
[ { "body": "<p><strong>Coding style</strong>:</p>\n\n<p>This is a list of improvements you can apply to make your code nicer\nin a C++ context:</p>\n\n<ul>\n<li><p>Prefer <code>enum</code>s or numerical constants over macros. <code>VERTEX_FVF</code> and <code>VERTEX_FVF_TEX</code>\nshould either be members of an...
{ "AcceptedAnswerId": "67456", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T03:37:00.117", "Id": "45058", "Score": "8", "Tags": [ "c++", "c++11", "memory-management", "graphics" ], "Title": "D3D9 leaks if any?" }
45058
<p>This is a chunk of code I wrote for a job interview at some point - it is a remote key-value storage REST API supporting CRUD operations.</p> <p>Maybe anyone has some feedback on this? It would be very helpful for me.</p> <p>I did not attach the tests, since it might be a little bit too much code. You don't have t...
[]
[ { "body": "<p>I'd write the error handling this way:</p>\n\n<pre><code>def render(self, request):\n operations = {\n 'POST': 'create',\n 'GET': 'read',\n 'PUT': 'update',\n 'DELETE': 'delete',\n }\n if request.method not in operations:\n response = {\n 'suc...
{ "AcceptedAnswerId": "45114", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T04:29:35.893", "Id": "45060", "Score": "3", "Tags": [ "python", "api", "twisted" ], "Title": "Simple REST API server" }
45060
<p>I am making a website that takes a bunch of dining hall information and puts it all together in a neater (and hopefully more mobile friendly) form. </p> <p>Here is the link: <a href="https://googledrive.com/host/0By7Z_HHj2VhnWmlhbWl4aF8xdFU/nuEats.html" rel="nofollow">https://googledrive.com/host/0By7Z_HHj2VhnWmlhb...
[]
[ { "body": "<p>From a once over,</p>\n\n<p><strong>DRY (Dont' Repeat Yourself)</strong></p>\n\n<ul>\n<li><p>You have a number of these blocks that seem all copy pasted:</p>\n\n<pre><code>&lt;!-- Sargent --&gt;\n&lt;div class=\"panel panel-default\"&gt;\n &lt;div class=\"panel-heading\"&gt;\n &lt;h4 cla...
{ "AcceptedAnswerId": "45309", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T07:30:45.070", "Id": "45067", "Score": "5", "Tags": [ "javascript", "jquery", "html", "css", "twitter-bootstrap" ], "Title": "Cleaning up a dining hall...website" }
45067
<p>Is there a more efficient way to write this? Seems redundant to me:</p> <pre><code> var leaves = $(".leaf"); var trees = $(".tree"); $(".my-class").on("click", function (e) { if ($(e.target).hasClass("leaf")) { trees.each(function() { $(this).attr("tabIndex", -1); ...
[]
[ { "body": "<p><a href=\"http://api.jquery.com/attr/#attr2\" rel=\"nofollow\"><code>.attr()</code></a> can work on all jQuery matched elements at once.</p>\n\n<p>Assuming that performance isn't a concern, I think that the clearest way would be to \"reset\" all nodes to have a <code>tabIndex</code> of <code>-1</c...
{ "AcceptedAnswerId": "45070", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T07:39:20.870", "Id": "45068", "Score": "3", "Tags": [ "javascript", "jquery" ], "Title": "Setting TabIndex efficiently" }
45068
<p>I have some animations happening after some delay calls the code to animate. It works fine, but the code to call the functions is not nice.</p> <pre><code> double delayInSeconds = 0.2; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds + 0.1 * NSEC_PER_SEC); dispatch_time_t popTim...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T16:42:16.993", "Id": "78527", "Score": "0", "body": "`animateWithCoreAnimaGenerallyWithIndex:`? Find & replace error or your own method?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T16:49:21.607", ...
[ { "body": "<p>Anything that you're using as a constant should be marked as such. </p>\n\n<pre><code>double const delayInSeconds = 0.2f;\n</code></pre>\n\n<hr>\n\n<p>Now then, we know in Objective-C, we have <code>NSArray</code> and its mutable cousin, and they can only hold objects. But also remember, Objecti...
{ "AcceptedAnswerId": "45119", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T13:36:49.727", "Id": "45084", "Score": "2", "Tags": [ "objective-c", "ios", "animation" ], "Title": "Best way to refactor this loop of animations with delay?" }
45084
<h1>Description</h1> <p>This is my code for the <a href="https://codereview.meta.stackexchange.com/questions/1471/weekend-challenge-reboot">Weekend Challenge Reboot</a> - Tic Tac Toe Ultimate.</p> <p>The game can be played here: <a href="http://www.zomis.net/ttt" rel="nofollow noreferrer">http://www.zomis.net/ttt</a>...
[]
[ { "body": "<p>There is not much to criticize in your code.... and there is a lot of code to go though.</p>\n\n<p>Mostly really neat, and, it takes a while to 'grok' it, but it comes together OK.</p>\n\n<p>Here's a laundry-list of small items (there are no big Items I can see):</p>\n\n<ul>\n<li><p>In TTUtils:</p...
{ "AcceptedAnswerId": "45125", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T15:23:32.000", "Id": "45086", "Score": "18", "Tags": [ "java", "game", "tic-tac-toe", "community-challenge" ], "Title": "Recursive and flexible approach to Tic-Tac-Toe" }
45086
<p>This code is starting to be used within several of my projects, and therefore I thought it's time to get it reviewed.</p> <h1>Description</h1> <p>The most common application for this code is that there is a computer opponent in a game which needs to make a decision based on some parameters. A list of all possible ...
[]
[ { "body": "<h3>AbstractScorer</h3>\n\n<ul>\n<li><p>Are you sure you need the precision of double for scoring? I only ask because I recently had reason to down-convert a system to float because it had many millions of scorable items and the memory saving ended up being significant.</p></li>\n<li><p><code>toStrin...
{ "AcceptedAnswerId": "45366", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T15:31:53.533", "Id": "45088", "Score": "26", "Tags": [ "java", "game", "ai" ], "Title": "A scoring approach to computer opponents" }
45088
<p>Can I get some pointers, critiques and/or comments on the following model? (p.s. performance seems great... tested all methods up to 10,000 records)</p> <pre><code>&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class o7th_Model extends CI_Model { private $msg; private $last_i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T18:50:09.397", "Id": "78815", "Score": "0", "body": "With that much code, could you add a description of what the code is doing ? It could help to know at first glance what your code is about." }, { "ContentLicense": "CC BY-...
[ { "body": "<p>This Function can be shorter.</p>\n<blockquote>\n<pre><code>public function qdelete(){\n $tbl = self::prepArgs(4, func_get_args());\n $this-&gt;db-&gt;delete('Storage_Users');\n if($this-&gt;db-&gt;affected_rows() &gt; 0){\n return TRUE;\n }else{\n $this-&gt;msg = 'There ...
{ "AcceptedAnswerId": "45262", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T15:54:30.650", "Id": "45090", "Score": "6", "Tags": [ "php", "php5", "codeigniter" ], "Title": "CodeIgniter Model I built" }
45090
<p>My design goal was to try and make a "clean" and well-designed Tic-Tac-Toe game but also to try and use concepts and programming constructs that I'm new to. </p> <p>I'm planning to implement an "AI Player" class later on. I know that Tic-Tac-Toe is a solved game so there are more effective approaches for AI logic ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T16:28:45.410", "Id": "78525", "Score": "2", "body": "why use extension methods if you can edit the class directly?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T16:34:57.263", "Id": "78526", ...
[ { "body": "<p>To answer the \"bonus question\" that may not be the right algorithm for the AI: it assumes that the human player is playing randomly.</p>\n\n<p>As a human player, I play to a) not-lose b) win. That's why most games (between experienced humans) end in a draw.</p>\n\n<p>With the algorithm you sugge...
{ "AcceptedAnswerId": "45107", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T16:15:59.700", "Id": "45091", "Score": "11", "Tags": [ "c#", "object-oriented", "multithreading", "game" ], "Title": "Clean and well-designed Tic-Tac-Toe game" }
45091
<p>I have been working with Java for a little more than a year. I recently have built a Tic Tac Toe game as an assignment for my Java class. After my instructor graded it, he wrote a comment around my validation method logic. Even though I got 100%, he said that the logic in my validation method is too cumbersome. He s...
[]
[ { "body": "<p>Start with replacing common code with function calls.\nFor example, you can create a method for checking if an entire row has the same text:</p>\n\n<pre><code>bool checkRow(int row)\n{\n int col = row*3;\n return button[col].getText().equals(button[col+1].getText())\n &amp;&amp; bu...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T20:07:59.920", "Id": "45097", "Score": "10", "Tags": [ "java", "game", "validation", "tic-tac-toe" ], "Title": "Conditionals validation for Tic Tac Toe" }
45097
<p>I have nginx serving files with uwsgi and I wanted to lock my server down just to allow SSH and Nginx to run.</p> <pre><code>#!/bin/bash i=/sbin/iptables # Flush all rules $i -F $i -X # Setup default filter policy $i -P INPUT DROP $i -P OUTPUT DROP $i -P FORWARD DROP # Allow unlimited traffic on loopback $i -A I...
[]
[ { "body": "<p>There is a miniscule chance of a failure between <code>/sbin/iptable -P INPUT DROP</code> and <code>/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT</code>. It really isn't likely, as there's not much that could go wrong, but it's theoretically possible. If you are remotely administering this...
{ "AcceptedAnswerId": "45109", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T20:43:27.333", "Id": "45098", "Score": "11", "Tags": [ "bash", "linux", "iptables" ], "Title": "Iptables Lockdown" }
45098
<p>I'm developing a Chrome extension so I can use bleeding-edge technologies like flexbox:</p> <p><a href="http://jsfiddle.net/VhZS5/14/" rel="nofollow">jsfiddle</a></p> <p><strong>HTML:</strong></p> <pre class="lang-html prettyprint-override"><code>&lt;label for="example-search"&gt;Classic search example&lt;/labe...
[]
[ { "body": "<p>Unless you're overwriting properties set elsewhere, there's no reason for this line because this is the default for all flex containers:</p>\n\n<pre><code>flex-flow: row nowrap;\n</code></pre>\n\n<p>If your goal is to make this work on browsers with either of the old Flexbox implementations, there...
{ "AcceptedAnswerId": "45116", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T20:47:12.437", "Id": "45099", "Score": "11", "Tags": [ "html", "css" ], "Title": "Input group with flex box" }
45099
<ul> <li><a href="https://en.wikipedia.org/wiki/Tic-tac-toe" rel="nofollow">Tic-tac-toe on Wikipedia</a></li> <li><a href="http://stackoverflow.com/tags/tic-tac-toe/info">Stack Overflow tag wiki</a></li> </ul>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T22:07:52.933", "Id": "45102", "Score": "0", "Tags": null, "Title": null }
45102
Tic Tac Toe is a popular exercise for beginning coders, as the finite resources and game mechanics can be easily grasped and represented in many ways. As it is a short game, it is possible to create an algorithm that never loses.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-22T22:07:52.933", "Id": "45103", "Score": "0", "Tags": null, "Title": null }
45103
<p>I am attempting problem 7 on Project Euler. I have come up with this solution which works fine for finding smaller nth prime numbers, but really lags when it comes to higher nth prime numbers. I am not quite sure where to start to make it more efficient.</p> <pre><code>public class TenThousandFirstPrime { pu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-23T01:28:28.067", "Id": "78563", "Score": "4", "body": "Re. how to make it faster, that's probably been explained in answers to some of the [other questions about prime numbers](http://codereview.stackexchange.com/questions/tagged/prim...
[ { "body": "<p>The square root calculation could just be done before the loop. Since this value does not change within the function, it doesn't need to be recalculated each time through the loop.</p>\n\n<pre><code>public static boolean isPrime(int num) {\n if (num % 2 == 0) return false;\n\n int squareRoo...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-23T00:44:19.467", "Id": "45115", "Score": "8", "Tags": [ "java", "performance", "primes", "programming-challenge" ], "Title": "Ten thousand and first prime checker takes a very l...
45115
<p>I just tried BDD for the first time and implemented a simple <a href="http://semver.org/" rel="nofollow noreferrer">Semantic Versioning</a> Bumper in Python.</p> <p>The class takes a version string in the format of <strong>major.minor.patch</strong> (i.e. 3.2.2, where major=3, minor=2, patch=2). Then you can bump a...
[]
[ { "body": "<p>Your problem seems to arise due to the fact, that your project is build from only one class (= unit).</p>\n\n<p>With acceptance tests you test a non-programmers view of your project, that is whether it fullfills given requirements. Acceptance tests are formulated in a style of someone who actually...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-23T01:03:02.403", "Id": "45118", "Score": "5", "Tags": [ "python", "unit-testing", "bdd" ], "Title": "First time BDD: Testing the same things in both acceptance and unit tests" }
45118
<p>I am trying to understand the concepts of <code>friend</code> functions, overloaded operators, and inheritance in C++. I am very confused on the specifics used for coding, since I am fairly new in programming, and working in the Visual Studio C++ environment in writing code. </p> <p>The following is the project det...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-23T06:09:49.173", "Id": "78579", "Score": "3", "body": "Your indentation is very inconsistent. Four spaces is preferred. One space in `main()` is a little strange." } ]
[ { "body": "<pre><code>using namespace std; \n</code></pre>\n\n<p>This is generally frowned upon, especially at the \"global\" level like this. Since you don't know what names might be defined inside <code>namespace std</code>, this has the potential to create conflicts with your code.</p>\n\n<pre><code>class Ph...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-23T06:00:02.473", "Id": "45127", "Score": "5", "Tags": [ "c++", "beginner", "operator-overloading" ], "Title": "Overloading operators in PhoneCall class" }
45127
<p>This is a hard question for me to ask, because I don't really know how to explain it. So, please, bear with me.</p> <p>Bootstrap menu, as I know, has 2 modes: "desktop" mode "phone/tablet" mode. The desktop mode is anything above 767px width, and the later is anything below or equal (to 767px).</p> <p>Easy, we cop...
[]
[ { "body": "<p>Actually, there's sort of a built in way to do this. Just attach a click handler to the links in your .navbar-nav and call the collapse hide method on the navbar-collapse class:</p>\n\n<pre><code>$('.navbar-nav').on('click', 'li a', function() {\n $('.navbar-collapse').collapse('hide');\n});\n</...
{ "AcceptedAnswerId": "53898", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-23T08:36:43.047", "Id": "45134", "Score": "3", "Tags": [ "javascript", "jquery", "twitter-bootstrap" ], "Title": "Twitter Bootstrap collapsing ONLY \"phone view\" navbar menu on c...
45134
<p>This game is similar to a Dungeons and Dragons game. How could I improve the efficiency of the program? For example, where can I add functions, records etc? This is for a school Controlled Assessment so any help would really be appreciated.</p> <pre><code>import random play1 = True str1 = int(input("Enter a val...
[]
[ { "body": "<p>I don't see any performance bottlenecks in the traditional sense. Namely I don't see any tight loops that have to do a lot of work where you are likely to be waiting for the computer to finish. Instead what I see are a lot of small opportunities for you to make the code a little easier to read. He...
{ "AcceptedAnswerId": "45144", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-23T12:45:58.230", "Id": "45137", "Score": "10", "Tags": [ "python", "game", "homework", "python-3.x" ], "Title": "Suggestions for a Dungeons and Dragons-like game" }
45137
<p>Below is my solution for <a href="http://www.codechef.com/MARCH14/problems/TMSLT">this 'Team Split' problem</a>.</p> <p>In summary, the problem is to find relative strength of 2 teams by finding the difference between their total strength (individual strengths can be found using a quadratic expression of form ax<su...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-23T16:38:44.447", "Id": "78623", "Score": "1", "body": "When exactly are you getting time limit exceeded? For what inputs?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-23T16:45:59.440", "Id": "78624"...
[ { "body": "<h1>Rewafadhabihlgdity</h1>\n\n<p>(If you can't tell, that is supposed to say 'readability'). Leaves some things to be desired.</p>\n\n<ul>\n<li><p>Variable names: All your variable names are three characters or less. This makes it very hard to read your code. Renaming <code>r</code> to <code>playerC...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-23T15:54:32.020", "Id": "45146", "Score": "15", "Tags": [ "java", "complexity", "programming-challenge" ], "Title": "'Team Split' problem" }
45146
<p>So today after few years of not programming in PHP I decided to go back, but to do so I needed to change all MySQL connections. So I want to check if I am using it good.</p> <p>Earlier I used to write something like this:</p> <pre><code>$user = clean($_COOKIE["Logged"]); $GameReg = mysql_fetch_array(mysql_query("S...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-23T17:13:16.987", "Id": "78625", "Score": "0", "body": "Probably not on the point you're trying to make but: you should do `$user = $_COOKIE[\"Logged\"]` before `$stmt->bindParam(':user', $user)`, no?" }, { "ContentLicense": "C...
[ { "body": "<p>It's good that you're moving over. Many people think it's too difficult to switch over, but in the long run, it's definitely worth it.</p>\n\n<p>Technically you can assign <code>$user</code> after you bind, because it's the actual execute call that substitutes. Although, in my opinion, it's easier...
{ "AcceptedAnswerId": "45192", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-23T16:38:48.410", "Id": "45147", "Score": "14", "Tags": [ "php", "mysql", "pdo" ], "Title": "Want to check if I am using PDO correctly" }
45147
<p>A <a href="http://en.wikipedia.org/wiki/White_elephant_gift_exchange" rel="nofollow">secret santa gift exchange</a> is a game where each player is randomly assigned a person to whom they anonymously give a gift. The algorithm is referred to as <a href="http://en.wikipedia.org/wiki/Derangement" rel="nofollow">Derange...
[]
[ { "body": "<p>I'm a bit unsure about whether the question is about a game of Secret Santa or if it's actually about derangement, specifically. Derangement requires that no element can appear <em>in its original position</em>. <strike>But that's irrelevant for a game of Secret Santa, since there's no ordering to...
{ "AcceptedAnswerId": "45160", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-23T19:14:43.463", "Id": "45155", "Score": "10", "Tags": [ "algorithm", "ruby" ], "Title": "A Ruby implementation of derangement (secret santa) algorithm" }
45155
<p>For class we were to make a MapReduce program in Python to find low value hashes of our name. I have completed the assignment but want to try and speed it up. The program currently takes about 45s to complete. I would like to see if there are any suggestions on speeding it up some.</p> <p>The requirements are to fi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-23T23:42:41.097", "Id": "78663", "Score": "0", "body": "Have you tried using `xrange()` instead of `range()` for the loops inside `mapfn`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T01:02:01.420", ...
[ { "body": "<p>From <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP 8</a> :</p>\n\n<blockquote>\n <p>Imports are always put at the top of the file, just after any module\n comments and docstrings, and before module globals and constants.</p>\n</blockquote>\n\n<p><em>Edit : Ok, from...
{ "AcceptedAnswerId": "45168", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-23T20:20:40.147", "Id": "45157", "Score": "2", "Tags": [ "python", "performance", "algorithm", "mapreduce" ], "Title": "MapReduce program for finding low value hashes" }
45157
<p>I'm writing a virtual machine in Python using RPython and the PyPy toolchain. The RPython will still work in the ordinary Python 2 interpreter; it's just a bit slow unless it's compiled to C code with PyPy.</p> <p>Does anyone have any positive or negative feedback about my VM?</p> <p>The virtual machine has 4 inst...
[]
[ { "body": "<pre><code>bcode = []\nstack = []\nregs = []\nsp = 0\nbcd = []\n</code></pre>\n\n<p>Global variables like this are frowned upon. To be pythonic you should really put them a in a class or something.</p>\n\n<pre><code>'''\nInstructions\n'''\nOP_EOP = 0\nOP_EOI = 1\nOP_PUSH = 2\nOP_PRINT = 3\n\ndef load...
{ "AcceptedAnswerId": "45164", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-23T21:35:12.847", "Id": "45158", "Score": "11", "Tags": [ "python", "python-2.x", "interpreter", "rpython" ], "Title": "Virtual machine using RPython and PyPy" }
45158
<p>I'm using a third-party library which utilizes <a href="http://www.boost.org/doc/libs/release/libs/smart_ptr/shared_ptr.htm" rel="noreferrer"><code>boost::shared_ptr</code></a> for memory management.</p> <p>The problem is that I need to allocate many objects and I have detected that the allocation and deallocation ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T01:07:10.153", "Id": "78677", "Score": "0", "body": "The main advantage of a pool is that released pointers can quickly be re-used. I don't see that functionality here. Once your pool is empty you need to re-create another pool." ...
[ { "body": "<p>Per the comments, this isn't really a \"pool\" because things don't go back into it when you're done using them. It's just an \"incremental allocator\" that does allocation in \"chunks\". A better name for it might be <code>shared_ptr_chunk_allocator</code> (and <code>chunk_size</code> instead of ...
{ "AcceptedAnswerId": "115006", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-23T22:47:33.710", "Id": "45161", "Score": "8", "Tags": [ "c++", "c++11", "memory-management", "boost", "smart-pointers" ], "Title": "Smart pointer memory pool" }
45161
<p>I'm working on a little game where you press a button and a new image appears. There's a glitch every time you ask a new image to display and it occurred to me that I should preload the necessary images. However, I'm not sure how to do this efficiently as I'm not using a variable to display the images. It's also bee...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T11:06:38.120", "Id": "78720", "Score": "0", "body": "Do all the images need to be individual? you'd most likely be better of using a sprite sheet loading that. http://stackoverflow.com/questions/8050152/why-use-a-sprite-sheet-rathe...
[ { "body": "<p>From a once over:</p>\n\n<ul>\n<li><p>Please indent your functions, bad:</p>\n\n<pre><code>function setup() {\nloadJajo('jajo.png');\nelem = document.getElementById('directions');\ndirectionSlide();\n}\n</code></pre>\n\n<p>better:</p>\n\n<pre><code>function setup() {\n loadJajo('jajo.png');\n ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-23T22:58:03.230", "Id": "45162", "Score": "5", "Tags": [ "javascript", "beginner", "image" ], "Title": "Preloading images in JavaScript" }
45162
<p>I'm currently in the process of coding a QuadTree. The QuadTree seperates into four quadrants, with 1 being the top right and 4 being the bottom right. I have this code to determine which quadrant the AABB fits into: </p> <pre><code>int getIndex(AABB aabb) { int index = -1; double vertMid = bounds.getX()...
[]
[ { "body": "<p>Note, you indicate in the text that you have quadrants:</p>\n\n<pre><code> 2 1\n 3 4\n</code></pre>\n\n<p>But your code has the quadrants:</p>\n\n<pre><code> 1 0\n 2 3\n</code></pre>\n\n<p>I recommend you have a function that works on just one point at a time. There are two points, the 'bottom lef...
{ "AcceptedAnswerId": "45176", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T00:34:15.153", "Id": "45172", "Score": "7", "Tags": [ "c++", "performance", "tree" ], "Title": "Determine quadrant of code" }
45172
<p>I have some triggers placing and sizing elements for video controls. It works well enough but mostly through trial and error and I am not sure if there is a better pattern:</p> <p>The full source can be found <a href="http://jsfiddle.net/Xa93a/" rel="nofollow">here</a> and webpage <a href="https://media.themetacity...
[]
[ { "body": "<p>This small snippet makes it hard to review.</p>\n\n<p>Your question:</p>\n\n<ul>\n<li><p>My biggest issue I think is when is it appropriate to have an element listen (eg on the specific element or on window) </p>\n\n<ul>\n<li>Let the element emit the event, the day that you need 2 video controls, ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T01:00:49.770", "Id": "45175", "Score": "4", "Tags": [ "javascript", "jquery", "html", "dom", "video" ], "Title": "Triggers placing and sizing elements for video controls" ...
45175
<p>I'm currently implementing my own QuadTree in C++. It runs well with 100 items, but once you start adding more it slows down. <code>remove</code>, <code>getAll</code>, and <code>insert</code> have all been profiled as taking a while. Any advice is appreciated! </p> <pre><code>class QuadTree { private: const ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T03:56:29.707", "Id": "78696", "Score": "0", "body": "I was about to say/add that in my answer. Is your insert performance improved now? Do you have any performance problem remaining?" }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p><code>getAll</code> returns a <code>set</code>, which is an ordered set. The ordering will be done by comparing Location*. I doubt you care about the order of Location* and it would be faster to use <code>std::unordered_set</code> instead.</p>\n\n<p>Similarly, <code>remove</code> and <code>insert<...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T01:55:15.967", "Id": "45178", "Score": "-1", "Tags": [ "c++", "performance", "tree" ], "Title": "QuadTree can't handle many elements" }
45178
<p>I am trying to implement ugly number sequence generation in Scala.</p> <p><strong>Ugly numbers</strong> are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15...</p> <p>I have implemented using var keyword like java implementation and it is working fine. Here is the <a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T12:12:13.903", "Id": "78734", "Score": "0", "body": "I got very good response here. pls check this link\n[to my cross-post on Stack Overflow](http://stackoverflow.com/questions/22601215/ugly-number-implementation-in-scala/22605264?n...
[ { "body": "<p>First off, I'd like to mention, that my Scala experience is limited, so please do point out any errors.</p>\n\n<p>You should implement your algorithm in it's own class implementing an appropriate interface/trait (probably <code>Iterator</code>, but there may be better ones).</p>\n\n<p>That would a...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T04:45:51.983", "Id": "45184", "Score": "4", "Tags": [ "scala" ], "Title": "Ugly number implementation in Scala" }
45184
<p>I am using this code in a lot of places:</p> <pre><code>if (ParameterName == null) { throw new ArgumentNullException("ParameterName"); } </code></pre> <p>But I think this is not DRY. The only difference here is <code>ParameterName</code>. Is it ok to use these lines everywhere, or is there a way to make it DRY...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T22:34:34.053", "Id": "78846", "Score": "1", "body": "This is where you wish you had C macros" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-27T11:21:07.070", "Id": "79339", "Score": "0", "bo...
[ { "body": "<p>You could try to extract it to a method, but you'd still have to call it for every parameter and you will lose the information, what the parameter's name is....</p>\n\n<pre><code>CheckNull(object ParameterName){\n if(parameterName == null){\n throw new ArgumentNullException(\"some param was...
{ "AcceptedAnswerId": "45196", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T10:29:20.080", "Id": "45191", "Score": "15", "Tags": [ "c#" ], "Title": "DRY the throwing of ArgumentNullException(\"ParameterName\")?" }
45191
<p>I was wondering if any of you know any best practices or design patterns so that I can have good logging in my programs without them looking messy or bloated.</p> <p>I am currently using C# and NLog, however I guess any advice here would be language and tool agnostic.</p> <p>The problem we have is that we want to ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-26T08:31:32.933", "Id": "79117", "Score": "2", "body": "What you want is not `logging`, *operations* actually either want an **audit trail** or **event sourcing**. Logs are not reliable: You logged `\"Something done on bar with id=...\...
[ { "body": "<p>This kind of trace logging could conceivably be solved with an <a href=\"http://en.wikipedia.org/wiki/Aspect-oriented_programming\">Aspect</a>. </p>\n\n<p>Aspect oriented programming allows you to add boilerplate-style code to your program without actually writing the boilerplate inline. You could...
{ "AcceptedAnswerId": "45194", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T09:48:12.737", "Id": "45193", "Score": "41", "Tags": [ "c#", "logging" ], "Title": "Logging without Code Bloat" }
45193
<p>I have more than 1000 items in my GridView. When scrolling though, it appears to make the app 'shutter'. Each time I load images from Picasso GC, it increases.</p> <pre><code>import java.util.ArrayList; import java.util.HashMap; import android.app.Activity; import android.content.Context; import android.view.Layou...
[]
[ { "body": "<h2>Easy things</h2>\n\n<ul>\n<li><p>auto-generated comments</p>\n\n<blockquote>\n<pre><code>@Override\npublic int getCount() {\n // TODO Auto-generated method stub\n return data.size();\n}\n</code></pre>\n</blockquote>\n\n<p>The method is not auto-generated any more, remove the comment. (this ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T11:34:52.357", "Id": "45201", "Score": "2", "Tags": [ "java", "android", "garbage-collection" ], "Title": "Gridview shuttering when scrolling" }
45201
<p>Here is my Bubblesort code:</p> <pre><code>public static List&lt;int&gt; BubbleSort(List&lt;int&gt; _digitList) { List&lt;int&gt; digitList = _digitList; bool didSwap = true; while (didSwap) { didSwap = false; for (int i = 0; i &lt; digi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T13:23:21.640", "Id": "78746", "Score": "4", "body": "If I were you, I'd write many test cases, with different kind of arrays (sorted, reversed, shuffled, all values different, a single value, etc) of different size (empty, small, hu...
[ { "body": "<p>It is normal in production quality qsort code to switch to another sorting method (maybe a unrolled bubble sort) when the size of the input is small (often 8 is used). QSort has very high overheads, but scales well, for a small input size the overheads are much more important than the scaling.<...
{ "AcceptedAnswerId": "45214", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T13:12:44.587", "Id": "45209", "Score": "0", "Tags": [ "c#", "sorting", "quick-sort" ], "Title": "Why is my Bubblesort implementation faster than my Quicksort code?" }
45209
<p>I have a multi-threaded app (WCF) that writes to a MySQL db. I want to use MySQL's built in connection pooling abilities.</p> <p>As far as I can tell, to do that, I should set <code>MySqlConnectionStringBuilder.MinimumPoolSize</code> to some value approximately equal to the number of threads I connect. Then Open/Cl...
[]
[ { "body": "<p>Yes, your code will use pooling.</p>\n\n<p>You might, for the sake of server efficiency, use a smaller <code>MinimumPoolSize</code> (say, 20), and a larger <code>MaximumPoolSize</code> (something a little larger than your maximum number of threads).</p>\n\n<p>You probably don't need all those conn...
{ "AcceptedAnswerId": "46763", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T13:28:00.323", "Id": "45211", "Score": "5", "Tags": [ "c#", "mysql", "connection-pool" ], "Title": "Multithreaded app for writing to a MySQL database" }
45211
<p>Based on several different sources, I have compiled the following as my basic HTML email template. Please let me know if I have missed anything important. I am not sure if I am using <code>\n</code> and <code>\r\n</code> correctly.</p> <pre><code>$semi_rand = uniqid(); $mime_boundary = "==MULTIPART_BOUNDARY_$semi...
[]
[ { "body": "<p>Some notes:</p>\n\n<p><strong>base64</strong></p>\n\n<p>It's not usual to <code>base64_encode</code> HTML. While the way you've done it will work, you run the risk of being marked as spam as spam filters see attempts at obfuscating emails as shady. Consider Quoted-Printable instead.</p>\n\n<p><str...
{ "AcceptedAnswerId": "46122", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T13:45:19.313", "Id": "45215", "Score": "2", "Tags": [ "php", "html", "email" ], "Title": "HTML email template" }
45215
<p>Unlike Perl, you can't to my knowledge match a regular expression inside an if statement in Python and assign the result to a varaible at the same moment. This leads to typical constructs like this:</p> <pre class="lang-py prettyprint-override"><code>match = re.search(REGEX, STRING) if match: # do something </c...
[]
[ { "body": "<p>You can make flow of your application more linear by either <code>return</code>-ing from the method when failing or do it <code>Python way</code> using <code>Exceptions</code>, e.g.:</p>\n\n<pre><code>try:\n if not do_action_1:\n raise Exception('Action 1 failed')\n if not do_action_2...
{ "AcceptedAnswerId": "45225", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-03-24T14:45:21.080", "Id": "45220", "Score": "35", "Tags": [ "python" ], "Title": "Search for a multiword string in a list of strings" }
45220
<p>Here is a practice question I am solving:</p> <blockquote> <p>Write a function to find the first non-repeated character in a string. For instance, the first non-repeated character in 'total' is 'o' and the first non-repeated character in 'teeter' is 'r'.</p> </blockquote> <p>How can I improve the efficiency ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T18:16:49.843", "Id": "78810", "Score": "0", "body": "first solution is O(n) so as good as it gets, but instead of 'More than one' and 'One Time' I would change the values to a boolean or int, checking if `charCount[string[j]] === 'O...
[ { "body": "<p>The runtime of the 1st solution you posted is not O(n<sup>2</sup>).\nYou are just traversing the string twice, which makes it O(2n) => O(n).</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T15:54:54.813", "Id": "78782", ...
{ "AcceptedAnswerId": "45247", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T15:15:03.897", "Id": "45228", "Score": "13", "Tags": [ "javascript", "algorithm", "strings" ], "Title": "Write a function to find the first non-repeated character in a string" ...
45228
<p>I have done some research about intentions of UnitOfWork pattern. In short, what I understood is that UoW is needed for transactions. But I saw some code examples where people use UoW as factory for Repository objects as well, one example is DbContext from EF. My first thought about it doesn't it break single respon...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T15:32:25.897", "Id": "78776", "Score": "0", "body": "Are you using [Linq-to-NHibernate](http://stackoverflow.com/questions/624609/linq-to-nhibernate)?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T1...
[ { "body": "<h3>Leaky abstractions</h3>\n<p>A specific implementation should not <em>leak</em> into an abstraction. By making <code>IUnitOfWork</code> extend <code>IDisposable</code>, that's what you're doing:</p>\n<blockquote>\n<pre><code>public interface IUnitOfWork : IDisposable\n</code></pre>\n</blockquote>\...
{ "AcceptedAnswerId": "45235", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T15:23:05.107", "Id": "45229", "Score": "2", "Tags": [ "c#", "design-patterns" ], "Title": "UnitOfWork as Repository object factory" }
45229
<p>I'm very new to learning PHP &amp; MySQL (I've got past experience with Java) and I'm doubting whether my code is organised well. I've got an index page which has two forms; the first is a form to login and the second is a form to sign up a user. So far I've only completed the signing up of a user. Please comment on...
[]
[ { "body": "<ol>\n<li><p>Iterating through the whole user table could be ineffective:</p>\n\n<blockquote>\n<pre><code>foreach ($db-&gt;query(\"SELECT username FROM usertable\") as $row) {\n</code></pre>\n</blockquote>\n\n<p>You could use a <code>WHERE username LIKE :username</code> condition here. (And you might...
{ "AcceptedAnswerId": "45241", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T16:14:46.043", "Id": "45234", "Score": "4", "Tags": [ "php", "mysql" ], "Title": "Am I organising my PHP code effectively?" }
45234
<p>The code is an implementation of the <a href="http://en.wikipedia.org/wiki/Gauss%E2%80%93Seidel_method" rel="nofollow">Gauss–Seidel method</a>. I would like a general review of the code.</p> <p>PS: I use code::blocks IDE</p> <pre><code>//generalized code for gauss seidal iteration method #include&lt;stdio.h&gt; #...
[]
[ { "body": "<p>A word of warning: I am very much a C newbie myself, so it may be good to take my advice with a grain of salt.</p>\n\n<h2>Formatting</h2>\n\n<p>The only good thing I can say about your formatting is that it's consistent. But a 1-space indent really isn't readable. I recommend 4 spaces instead. Ple...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-24T16:36:34.463", "Id": "45237", "Score": "10", "Tags": [ "c", "mathematics", "matrix" ], "Title": "Gauss-Seidal implementation" }
45237