body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>It works just fine, but is there any other way to write this shorter?</p> <p>Nurses are only available to intensive care patients (room I) and TV's and telephones are only available to non intensive care patients (room D or room P). Also, <code>X_COST</code> has a value of 0.</p> <pre><code>if (room.equals("I")) {...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T01:00:11.490", "Id": "84215", "Score": "0", "body": "After writing code that says \"if (room.equals(\"I\"))... there is absolutely no point adding a comment that says exactly the same thing. Make your code readable, so that you rare...
[ { "body": "<p>Code like the following ...</p>\n\n<pre><code> if (phone.equals(\"T\"))\n\n phoneCost = 15 * (double)days;\n //System.out.println(phoneCost);\n\n else\n\n phoneCost = X_COST;\n</code></pre>\n\n<p>... is copy-and-pasted into more than one type of room.</p>\n\n<p>Instead of...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T00:06:33.527", "Id": "47301", "Score": "8", "Tags": [ "java" ], "Title": "Conditional statements relating to hospital management" }
47301
<p>First, I've extended the String class to detect uppercase and lowercase characters:</p> <pre><code>class String def is_uppercase? self == self.upcase end def is_lowercase? self == self.downcase end end </code></pre> <p>I then use these instance methods to fulfil my main goal...
[]
[ { "body": "<p>First off, I'd rename those two <code>String</code> methods. You obviously had a plan in mind when you added them (i.e. that the strings you'd be checking would be 1 character long), but from a more general perspective, it's fraught with ambiguity.</p>\n\n<p>For instance, is the string <code>\"Hel...
{ "AcceptedAnswerId": "47376", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T01:11:50.030", "Id": "47305", "Score": "2", "Tags": [ "ruby", "strings", "ruby-on-rails" ], "Title": "Transfer the format of an old string to a new string" }
47305
<p>I'm working on a card game in Java that simulates the drinking game Kings Cup for a school project. I'm having trouble putting the pieces together, and was wondering if someone could tell me what I could do to improve my code.</p> <pre><code> @author :Kimberly IDE :NETBEANS public cl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T03:33:06.200", "Id": "82869", "Score": "1", "body": "well when I get some more time I will give a much more thorough review of the code but I find a few things wrong with your inheritance rules. A super class of Player being impleme...
[ { "body": "<p>I'm probably missing a fair bit, but these are the things I picked up on:</p>\n\n<hr>\n\n<p>Why does Card extend Deck? They are both objects in their own right and don't require inheritance.</p>\n\n<p>If Player is intended to be an object it shouldn't have any static variables or methods. You migh...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T02:22:46.643", "Id": "47310", "Score": "8", "Tags": [ "java", "beginner", "game", "playing-cards" ], "Title": "Kings Cup drinking game" }
47310
<p>This is from my project <a href="http://corylutton.com/codecount.html">codecount</a> I use personally that is very similar to cloc.exe or SLOCCount. The part that I am questioning is where I am calculating when I am in a comment block and have deep nesting, I basically am replacing the sections with blank. I would...
[]
[ { "body": "<p>A couple of points:</p>\n\n<p>In Python there is no need to place parentheses after <code>if</code>. For example, </p>\n\n<pre><code>if(filename.size == 0):\n</code></pre>\n\n<p>Can be replaced with</p>\n\n<pre><code>if filename.size == 0:\n</code></pre>\n\n<p>In fact, the latter is the preferred ...
{ "AcceptedAnswerId": "47313", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T02:24:48.063", "Id": "47311", "Score": "7", "Tags": [ "python" ], "Title": "A source Code Counter" }
47311
<p>I am interested in improving my coding standards in Python so I decided to post one my more recent and smaller "for fun" projects here for review. The code below implements a rather simple backtracking algorithm to solve SAT, which is based on Knuth's SAT0W found here: <a href="http://www-cs-faculty.stanford.edu/~un...
[]
[ { "body": "<p>This review will focus on <strong>the command-line driver</strong>. Others will no doubt elaborate on the rest of your code.</p>\n<h2>Piece-by-piece review</h2>\n<pre><code>if __name__ == '__main__':\n</code></pre>\n<p>The Python convention is to <strong>extract everything that follows into a func...
{ "AcceptedAnswerId": "47327", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T02:27:27.650", "Id": "47312", "Score": "3", "Tags": [ "python" ], "Title": "Simple SAT Solver In Python" }
47312
<p>I'd like to know if there's any better way to write this query:</p> <pre><code>(from a in Context.Pages join b in Context.Visitors on a.PageID equals b.PageFK join c in Context.Visits on b.VisitorID equals c.VisitorFK join d in Context.Signups on c.VisitID equals d.VisitFK where d.DateOptinUtc.HasValue &amp;&amp; a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T07:46:49.693", "Id": "82891", "Score": "2", "body": "Doesn't necessarily look bad. What does the generated SQL look like? EF may have optimized this pretty well and the database's query optimizer may further optimize it. Is there a...
[ { "body": "<p>Aside from the performance issues you should make the query more readable by using relevant variable names instead of <code>a</code>, <code>b</code>, <code>c</code>, <code>d</code>, <code>g</code>, and <code>h</code>. In addition, the ambiguous <code>ListReport</code> class name should be changed...
{ "AcceptedAnswerId": "47473", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T03:33:04.753", "Id": "47314", "Score": "1", "Tags": [ "c#", "beginner", "entity-framework" ], "Title": "Group By And Two Counts" }
47314
<p>I've created a Java class, <code>Date</code>, in which I basically create date strings and set dates. Is there anything I can do besides adding comments to improve/shorten my code? </p> <p>I've tested all of my methods to see if they work correctly, and they all work as planned. I haven't done tests that force the...
[]
[ { "body": "<ul>\n<li><strong>Your class does not handle months with less than 31 days, in-real-life-speaking your unit test for adding five days to 28th April is already wrong</strong></li>\n<li><code>stringMonth</code> can be left as a <code>private static final</code> array, so that you are not re-creating it...
{ "AcceptedAnswerId": "47319", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T03:44:09.207", "Id": "47316", "Score": "6", "Tags": [ "java", "object-oriented", "datetime" ], "Title": "Creating date strings and setting dates" }
47316
<pre><code>int number; DateTime dateTime; using (var oracleConnection = new OracleConnection(ConnectionString)) using (var oracleCommand = oracleConnection.CreateCommand()) { oracleConnection.Open(); oracleCommand.CommandText = "SELECT * FROM FROM MY_TABLE"; using (var reader = oracleCommand.ExecuteReade...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-06-28T20:23:12.320", "Id": "173280", "Score": "0", "body": "The desire to improve code is implied for all questions on this site. Question titles should reflect the purpose of the code, not how you wish to have it reworked. See [ask]." ...
[ { "body": "<p>A few comments:</p>\n<h3>Exceptions:</h3>\n<p>Keep in mind, even with using-statements, exceptions can happen. Make sure to catch them. I'd suggest, you wrap the whole snippet in a try-catch-block if that didn't happen already.</p>\n<h3>Types:</h3>\n<p>Why are you using the dynamyic type? Make it ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T06:38:23.700", "Id": "47322", "Score": "3", "Tags": [ "c#", ".net", "oracle" ], "Title": "C# with Oracle ODP.NET" }
47322
<p>I have written a very XNA spritebatch like interface for drawing sprites in OpenGL. When begin is called the vertex data buffer is mapped to a float*. The index buffer and vertex buffer are bound in begin, and it's assumed no other drawing is done in this OpenGL context between begin and end. In between begin and en...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T11:38:20.453", "Id": "83626", "Score": "0", "body": "I don't have any answers, but is it worth breaking down BufferSprite into smaller functions (temporarily) so you can profile the separate parts of it to identify which part is slo...
[ { "body": "<p>I would avoid the testing for calling <code>Begin</code> and <code>End</code> appropriately by creating a separate class that does the <code>begin</code> actions during construction and the <code>end</code> actions during destruction.</p>\n\n<p>As for speeding up the code, I think the first real s...
{ "AcceptedAnswerId": "48270", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T06:50:12.163", "Id": "47325", "Score": "10", "Tags": [ "c++", "optimization", "c++11", "opengl", "graphics" ], "Title": "Sprite drawing class" }
47325
<blockquote> <p>Given a sorted array, return the 'closest' element to the input 'x'.</p> </blockquote> <p>I do understand the merits of unit testing in separate files, but I deliberately added it to the main method for personal convenience, so don't consider that in your feedback.</p> <p>I'm looking for request cod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T07:20:18.663", "Id": "82887", "Score": "0", "body": "your 'closest' definition seems queer. Are you sure you didn't mean `Math.Min(Math.Abs(x-el[i])` where `i` is all elements of the array?" }, { "ContentLicense": "CC BY-SA ...
[ { "body": "<p>Here's my solution which seems to work fine :</p>\n\n<pre><code>public static int getClosestK(int[] a, int x) {\n\n int low = 0;\n int high = a.length - 1;\n\n if (high &lt; 0)\n throw new IllegalArgumentException(\"The array cannot be empty\");\n\n while (low &lt; high) {\n ...
{ "AcceptedAnswerId": "47341", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T07:00:01.407", "Id": "47328", "Score": "10", "Tags": [ "java", "algorithm", "array" ], "Title": "Find the value nearest to k in the sorted array" }
47328
<p>I want to generate a sequence using Linq that goes from 10 to 100 with a step size of 10. The sequence also must contain a custom value (in the correct order).</p> <p>This is what I have now, and I'm wondering if there is a smarter way of doing it using Linq expressions.</p> <pre><code>var pageSize = 25; //number ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T07:48:32.500", "Id": "82893", "Score": "0", "body": "Why should the result include 25?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T07:52:55.697", "Id": "82894", "Score": "0", "body": "...
[ { "body": "<p>Size of initial list in the following code is less:</p>\n\n<pre><code>var x = Enumerable.Range(1, 10)\n .Select(x_ =&gt; x_ * 10)\n .Concat(new[] {25})\n .Distinct()\n .OrderBy(x_ =&gt; x_)\n .ToList();\n</code></...
{ "AcceptedAnswerId": "47423", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T07:45:38.660", "Id": "47332", "Score": "12", "Tags": [ "c#", "linq", "interval" ], "Title": "Generate sequence in Linq" }
47332
<p>I've been working on a rough idea for a templating engine (mostly as a learning project) using the F# syntax. How "correct" is my code in terms of being idiomatic F#? Are there F# features which would make the code simpler? More easily understood? </p> <p>The template files are loaded at runtime using a script I've...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T08:55:52.937", "Id": "82910", "Score": "0", "body": "using `#r` with a `.exe` is not a good idea, you should be compiling to a `.dll` if you are using `#r` as you can run into issues with initialization." }, { "ContentLicens...
[ { "body": "<p>There are a few suggestions which immediately occur to me: some are minor changes which could improve the clarity of the code and there is one major change which would shorten the code quite a bit.</p>\n\n<p>The minor changes:</p>\n\n<ol>\n<li><p>For <code>List.fold</code> you can just pass a fun...
{ "AcceptedAnswerId": "47630", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T08:04:58.933", "Id": "47334", "Score": "1", "Tags": [ "f#", "template-meta-programming" ], "Title": "Basic templating engine in F# using F# syntax" }
47334
<p>I am building an application full of forms and so I thought it is good idea to create a class to populate form fields.</p> <p>Here is my class and I am sure it can be optimized more than now and could be better.</p> <pre><code>class JS_Forms { public function __construct() { //$this-&gt;register_f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T13:58:06.023", "Id": "82949", "Score": "2", "body": "Is your intent to auto populate a form from a database row? You've not provided any example of how this would be used. As far as coding best practices goes, this leaves a little t...
[ { "body": "<p>One of the issues you will run into in the future is the coupling of your presentation output (HTML) to the functionality of the class. You also have many sections of repeating output which should likely be outside of each case statement, but within the loop. </p>\n\n<p>You wish to optimize the cl...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T10:21:26.807", "Id": "47338", "Score": "1", "Tags": [ "php", "classes", "form" ], "Title": "Optimized Form fields generating class" }
47338
<p>I am trying to solve the <a href="https://www.hackerrank.com/contests/sep13/challenges/sherlock-and-the-beast" rel="nofollow">Sherlock and The Beast</a> HackerRank challenge. Most tests timeout, however when I try a custom stretch test case (T = 20 and all N = 100000), it returns successfully, so I'm not sure what t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T16:09:38.800", "Id": "82978", "Score": "1", "body": "You say that you're testing this with `n=100000`? It quite clearly can't give correct results for any value of `n` greater than `63`, so I think you need to start by checking your...
[ { "body": "<p>My non-exhaustive list of comments, considering that you seem to prefer (based on observed skill level) plain Java and do not want to use Java 8 yet.</p>\n\n<ol>\n<li><p>Adhere to the Java's coding standards. One of the catches here is that method names are in camelCase, so it would be <code>priva...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T10:46:00.870", "Id": "47339", "Score": "4", "Tags": [ "java", "algorithm", "programming-challenge" ], "Title": "Hackerrank - Sherlock and the Beast" }
47339
<p>The previous code (as displayed in <a href="https://codereview.stackexchange.com/questions/46807/timer-utilizing-stdfuture">Timer utilizing std::future</a>) is now:</p> <pre><code>#include &lt;chrono&gt; #include &lt;functional&gt; #include &lt;future&gt; #include &lt;iostream&gt; #include &lt;list&gt; #include &lt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T13:23:28.527", "Id": "82945", "Score": "0", "body": "`typedef std::mutex mutex;`? Also you can't return -1 from `main`." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T19:21:40.850", "Id": "84987"...
[ { "body": "<p>Generally speaking, the code already seems really good. Therefore, I have nothing more than a few notes:</p>\n\n<ul>\n<li><p>It is more of a matter of taste, but I would use some <a href=\"http://en.cppreference.com/w/cpp/language/type_alias\" rel=\"nofollow noreferrer\">type aliases</a> instead o...
{ "AcceptedAnswerId": "48327", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T12:15:59.717", "Id": "47347", "Score": "10", "Tags": [ "c++", "multithreading", "c++11", "timer" ], "Title": "Follow-up: Timer utilizing std::future" }
47347
<p>So, I wanted a separate project to act as the data layer for my website project.</p> <p>Classes in the website should reference the data layer after getting input from the user and should get back information regarding the result of whatever actions are performed and then communicate those results to the user.</p> ...
[]
[ { "body": "<p>A couple of general points:</p>\n\n<p>You shouldn't be using properties to set an error message like that. The error message is associated with the action you attempted on the object- in this case the delete- not the object itself. After the error has been handled, it doesn't make any sense for th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T13:11:36.957", "Id": "47350", "Score": "5", "Tags": [ "c#", "object-oriented" ], "Title": "OOP between projects" }
47350
<p>I can have a maximum of three concurrent threads processing tasks. Each of these threads can process 1 to 100 tasks simultaneously (by connecting to an external system). The time taken to process 100 tasks at once in one thread is the same as it takes to process 1 task in one thread because the overhead of connectin...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T15:42:49.080", "Id": "82971", "Score": "0", "body": "I've rollback your last edit, you should modify your code base on feedback that you received from an answer, because this can invalidate answer. Please see this meta-post about [a...
[ { "body": "<p>I am not a Java expert, but</p>\n\n<ul>\n<li>In your description you talk about tasks and jobs, however your code is only using task, which makes your code harder to follow.</li>\n<li>If you are going to log <code>\"waiting for task\"</code> then you should also log <code>\"waiting for semaphore\"...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T13:25:41.113", "Id": "47352", "Score": "11", "Tags": [ "java", "concurrency" ], "Title": "Concurrent task processing queue" }
47352
<p>I'm making a simple guessing game in C. Basically what I need is some help double-checking my work, more specifically a verification that the my binary search in my case statements look okay. The goal is to have an initial guess of 50, then work off that. If "L" is selected, the search goes from 51-100, if "H", it w...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T15:30:29.223", "Id": "82965", "Score": "0", "body": "The \"C99 function implementation error\" that you are experiencing is because you have not enabled C99 mode with your compiler; it isn't because C99 doesn't support it." }, {...
[ { "body": "<p>Looks good to me. I can only nitpick:</p>\n\n<ul>\n<li>Instead of <code>printf(\"...\\n\")</code>, it's better to use <code>puts(\"...\")</code></li>\n<li>If you really <em>must</em> use the ASCII codes, then at least add a comment there to know that 72 is <code>H</code>, 76 is <code>L</code>, and...
{ "AcceptedAnswerId": "47406", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T14:40:29.387", "Id": "47353", "Score": "11", "Tags": [ "c", "binary-search", "number-guessing-game" ], "Title": "Binary search use in simple guessing game" }
47353
<p>I recently wrote a simple echo server in Java 7 using the NIO APIs so it was asynchronous and non-blocking. Then I decided, as a learning experience, to redo it with Java 8 hoping to use a more functional style and not have nested callbacks. I'm struggling to understand how to use the new <code>CompletableFuture</co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-21T07:47:47.470", "Id": "83721", "Score": "0", "body": "\" is slower than the Java 7 version.\": Can we see the other version? Maybe we could spot the difference." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "201...
[ { "body": "<ol>\n<li><p>As far as I see <code>supplyAsync</code> and <code>thenAcceptAsync</code> uses <code>ForkJoinPool.commonPool()</code> which does not use more than three threads on my machine (and it depends on the number of available processors). It could be a bottleneck if you have more than three clie...
{ "AcceptedAnswerId": "47863", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T14:48:35.363", "Id": "47354", "Score": "10", "Tags": [ "java", "asynchronous", "networking", "socket", "java-8" ], "Title": "Echo server with CompletableFuture" }
47354
<p>Yesterday I posted a <a href="https://codereview.stackexchange.com/questions/47292/directory-that-lists-employee-information">question</a> involving multiple nested queries. The queries pulled information from the database and created a directory listing of all employees. There are two many-to-many relationships i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T20:31:48.903", "Id": "83029", "Score": "0", "body": "Have you thought about using concatenated subqueries instead. See http://www.hellotecho.com/concatenating-subqueries-with-multiple-results-in-mysql for an example." }, { "...
[ { "body": "<p>in your while statement you are listing all sorts of information inside of one list item tag, I am not so sure this is intentional, it looks like it is going to be really messy. I think you should look into creating sub-lists there especially for the multiple Department names and Job Names. you ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T15:37:26.443", "Id": "47358", "Score": "3", "Tags": [ "php", "performance", "mysql", "mysqli" ], "Title": "Directory that lists employee information - follow-up" }
47358
<p>Here is my implementation to project Euler Problem 11. I did this problem a bit later, when I learned how to input from a txt file. The problem context can be seen <a href="http://projecteuler.net/problem=11">here</a>. I did add "\n" to the end of each line, after copying the numbers into a txt file, I'm not sure of...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T16:19:39.013", "Id": "82981", "Score": "1", "body": "[My answer to your previous question](http://codereview.stackexchange.com/a/47277/22222) about `const&` still applies to your `std::vector` parameters." }, { "ContentLicen...
[ { "body": "<p>Your functions returning a <code>unsigned long long</code> are missing a return which leads to undefined behavior (<a href=\"https://stackoverflow.com/questions/1610030/why-can-you-return-from-a-non-void-function-without-returning-a-value-without-pr/1610454#1610454\">more details on this question<...
{ "AcceptedAnswerId": "47371", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T16:03:22.347", "Id": "47361", "Score": "5", "Tags": [ "c++", "programming-challenge" ], "Title": "Project Euler Problem 11: Largest product in a grid" }
47361
<p>I currently have a Python script that parses a file (in this case an XML file) and makes line by line replacements as necessary, depending on the values of multiple arrays. As it stands now the script works great, but feel like it could be a lot better. I'll also need to add few more arrays later on and am worried a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T16:46:09.057", "Id": "82993", "Score": "0", "body": "Would you ever expect to need to do the inverse transformation, i.e., replacing \"new string one\" with \"old string one\"?" }, { "ContentLicense": "CC BY-SA 3.0", "Cr...
[ { "body": "<p>One bug I see is that you perform the string substitutions sequentially, rather than \"simultaneously\". For example, suppose you had an input file with contents</p>\n\n<pre><code>abc\n</code></pre>\n\n<p>with substitution code</p>\n\n<pre><code>arrayOne = [\"a\", \"b\"]\narrayTwo = [\"b\", \"c\"...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T16:16:24.250", "Id": "47365", "Score": "7", "Tags": [ "python", "strings" ], "Title": "Making line by line replacements using values from multiple arrays" }
47365
<p>Below is my code. This is a function that will be applied as a sorting method to a grid based data set. The data in the column to be sorted can be stuff like: <code>123456</code>, <code>123456:123444</code>, and <code>12345:12359:139943</code>. So far, I have tested it and it works, but I want to know in which situa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T17:56:41.337", "Id": "83003", "Score": "1", "body": "Can you give an example of some numbers you want to be sorted and what you would expect the result to be?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014...
[ { "body": "<p>@Flambino was a bit faster : </p>\n\n<pre><code>function sortSKU( a, b )\n{\n var aParts = a.split( ':' ),\n bParts = b.split( ':' ),\n partCount = aParts.length,\n i;\n\n if( aParts.length != bParts.length )\n return aParts.length - bParts.length;\n\n for( i ...
{ "AcceptedAnswerId": "47382", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T16:21:53.567", "Id": "47366", "Score": "8", "Tags": [ "javascript", "sorting" ], "Title": "Sort function to sort item numbers separated by colon" }
47366
<p>The below code is recursive function that list directories in 2 levels:</p> <pre><code>static Dictionary&lt;string,string&gt; pList=new Dictionary&lt;string, string&gt;(); static void ListDirec(string path, int start, int end) { var dirInfo = new DirectoryInfo(path); var folders = dirInfo.GetDirectories()...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T21:27:01.233", "Id": "83038", "Score": "0", "body": "You are asking for help in writing code to add the data to a dictionary. This code does not exist yet, so it is not ready for a Code Review. When your code works as designed, brin...
[ { "body": "<p>To relate your parent directories to their children, you could have <code>plist</code> declared like this:</p>\n\n<pre><code>static Dictionary&lt;String, List&lt;String&gt;&gt; plist = new Dictionary&lt;string, List&lt;string&gt;&gt;();\n</code></pre>\n\n<p>Each time you hit a child folder, you ad...
{ "AcceptedAnswerId": "47370", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T16:31:31.923", "Id": "47367", "Score": "2", "Tags": [ "c#", "recursion", "directory" ], "Title": "Recursive function for listing directories" }
47367
<p>Before looping through an Excel document using a library I found, and wanted to know how long it would take to loop through the whole thing. </p> <p>There are 40k rows.</p> <p>I looped through only the first 5k and it took just 2 minutes. So, I thought, that looping through 40k would take just 16 minutes total.<...
[]
[ { "body": "<blockquote>\n<pre><code>public static void Validate(ExcelConfiguration config)\n</code></pre>\n</blockquote>\n\n<p>I wouldn't make this a <code>static</code> method, but without knowing more about your project it's just a nitpick. The name is highly misleading though. Without looking at the code, on...
{ "AcceptedAnswerId": "47487", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T16:31:55.760", "Id": "47368", "Score": "10", "Tags": [ "c#", "excel" ], "Title": "Looping through an Excel document in C#" }
47368
<p>I am designing a website for a company that manages buildings/real estate. I did not have much use for a CSS library like Bootstrap or Foundation, except on one page of the website. This page contains a list of selected buildings. When a user clicks on the name of a building, the building's information appears an...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T17:55:06.940", "Id": "83002", "Score": "1", "body": "I can't see what's kicking this all off. What is calling swap?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T18:55:40.967", "Id": "83018", ...
[ { "body": "<p>Let's start by removing that inline JS call. Let's use the <code>href</code> to indicate the building. We'll remove the hash later. We also add a class to find these links to attach event handlers:</p>\n\n<pre><code>&lt;a href=\"#azusa\" class=\"swap-trigger\"&gt;Azusa&lt;/a&gt;\n</code></pre>\n\n...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T17:46:57.437", "Id": "47375", "Score": "2", "Tags": [ "javascript", "jquery", "css", "html5", "twitter-bootstrap" ], "Title": "jQuery for image swapping and some JS for te...
47375
<p>I am making an application where I will be fetching tweets and storing them in a database. I will have a column for the complete text of the tweet and another where only the words of the tweet will remain (I need the words to calculate which words were most used later).</p> <p>How I currently do it is by using 6 di...
[]
[ { "body": "<p>(subject to further changes)</p>\n\n<p>In your simple example, how are the hashtags and usernames actually derived from the tweet?</p>\n\n<p>My suggestion is to tokenize the tweet by whitespaces first, then look at the individual words to determine if they must be stored (\"Vote\") or discarded (\...
{ "AcceptedAnswerId": "47424", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T17:54:21.730", "Id": "47378", "Score": "5", "Tags": [ "java", "performance", "strings", "regex", "twitter" ], "Title": "More efficient way to make a Twitter status in a...
47378
<p>I've got 2 simple text files:</p> <blockquote> <p><strong>besede.txt</strong></p> <p><em>To je vsebina datoteke z besedami. V njej so razlicne besede ki imajo lahko pomen ali pa tudi ne.</em></p> </blockquote> <blockquote> <p><strong>skrivno.txt</strong></p> <p><em>4 3 19 2 3 2 4 3</em></p> </blockquote> <p>I wrote...
[]
[ { "body": "<p>There are quite some things you can improve here, this list may not cover everything that could be improved though:</p>\n\n<ol>\n<li><p>Adhere to the Java naming conventions. Classes are named in PascalCase for example, so it would be <code>public class Meow</code>. On other places it seems fine.<...
{ "AcceptedAnswerId": "47384", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T18:31:43.290", "Id": "47383", "Score": "11", "Tags": [ "java", "file" ], "Title": "Reading text from 2 files" }
47383
<h1>Use Case</h1> <p>So our lead programmer loves to follow the <a href="http://en.wikipedia.org/wiki/Not_invented_here" rel="nofollow">NIH Anti-Pattern</a> and consequently I'm not allowed to use Underscore.js and can only use Vanilla JS... and we have to support IE8.</p> <p>The goal is to produce an aggregation of ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T22:12:13.630", "Id": "83060", "Score": "0", "body": "Does the data always come in the format shown in the demo?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T22:16:28.240", "Id": "83063", "S...
[ { "body": "<p>From a once over : </p>\n\n<ul>\n<li>This is a problem : <code>var search = JSON.stringify(obj);</code> because <code>JSON.stringify()</code> <a href=\"https://stackoverflow.com/a/4920304/7602\">does not guarantee any order</a>.. To be completely correct I think you are going to need to pass the p...
{ "AcceptedAnswerId": "47399", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T20:03:38.873", "Id": "47390", "Score": "2", "Tags": [ "javascript", "functional-programming" ], "Title": "Aggregation of a collection of object's nested array-properties" }
47390
<p>First attempt was done <a href="https://codereview.stackexchange.com/q/36938/507">here</a><br /> Second attempt was done <a href="https://codereview.stackexchange.com/q/40159/507">here</a></p> <h3>Huge comment at top</h3> <pre><code>/* * Export single function that creates the passportControl object * The function...
[]
[ { "body": "<p>I think you're nailing it.</p>\n\n<p>As a nitpick, the indentation is a bit off in the <code>registerUser</code> function definition.</p>\n\n<p>Another tiny thing in the same function, instead of this:</p>\n\n<blockquote>\n<pre><code>function(err, localUser) {\n if (err) {done(err); return; }\n...
{ "AcceptedAnswerId": "47440", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T20:12:21.560", "Id": "47392", "Score": "5", "Tags": [ "javascript", "node.js", "passport" ], "Title": "node.js Passport Wrapper 3" }
47392
<p>I have not done any parameter checking, however I think the meat of the class is there. Let me know what you think. </p> <pre><code>#include &lt;cstddef&gt; #include &lt;vector&gt; using namespace std; template&lt;class T&gt; class TreeNode { private: T* data; TreeNode&lt;T&gt;* parent; vector&lt; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T21:44:29.633", "Id": "83043", "Score": "0", "body": "You have some needless `TreeNode<T>*` (constructor, mamber function declarations) - make it `TreeNode*`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-0...
[ { "body": "<ul>\n<li><p>Do not get in the habit of using <a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\"><code>using namespace std</code></a>.</p></li>\n<li><p>Since you're using <code>&lt;cstddef&gt;</code> for <code>size_t</code>, you should make it <...
{ "AcceptedAnswerId": "47403", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T21:26:20.197", "Id": "47395", "Score": "11", "Tags": [ "c++", "classes", "tree" ], "Title": "Tree Template Class Implementation for C++" }
47395
<p>I am putting together a fairly simple server that listens for a connection then creates this thread - textbook Java code - then accepts data on that connection.</p> <p>I am following a protocol that the manufacturer has laid out for start of message (0xfd) and EOM (0xfe) as below. I then simply populate a byte ar...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T00:37:07.820", "Id": "83082", "Score": "1", "body": "You never check for `bytecounter > 1023`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T02:25:59.303", "Id": "83092", "Score": "0", "b...
[ { "body": "<p>Some variables, such as <code>socketAlive</code> and <code>hexforlog</code>, aren't being used.</p>\n\n<p>Another quirk I noticed is that you don't really take advantage of the capabilities of <code>DataInputStream</code>. If you just want to read a byte at a time, <em>any</em> <code>InputStream<...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T21:31:23.237", "Id": "47396", "Score": "6", "Tags": [ "java", "array", "io", "socket", "device-driver" ], "Title": "Keeping track of byte count in a binary protocol handle...
47396
<p>Please be brutal, and treat this as a top 5 technical interview. I am trying to follow Google's way of writing Java code, as per their .pdf file online of code review. (Side note: do any of you see any improvement in me?)</p> <p>Suppose I am asked to find the minimum number of coins you can find for a particular su...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T22:05:25.440", "Id": "83058", "Score": "2", "body": "Can you provide the link to that pdf ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T22:28:36.340", "Id": "83066", "Score": "0", "bod...
[ { "body": "<p>You could change the innermost loop to foreach-style to make it slightly more readable:</p>\n\n<pre><code>for (int coin : coins) {\n if (i &gt;= coin &amp;&amp; i - coin &gt;= 0 &amp;&amp; calculationsCache[i - coin] + 1 &lt; calculationsCache[i]) {\n calculationsCache[i] = calculationsC...
{ "AcceptedAnswerId": "47412", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T21:51:34.237", "Id": "47397", "Score": "14", "Tags": [ "java", "algorithm", "interview-questions", "change-making-problem" ], "Title": "Find Minimum Number of coins" }
47397
<p>Dabbling around with Roslyn and made a small analyzer just now. This one will show a warning in Visual Studio when you have a try-catch statement that only has a <code>catch(Exception e)</code>.</p> <p>I realize the working code (<code>AnalyzeNode</code>) is rather small, but I'm looking for feedback on best-practi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T12:57:43.173", "Id": "84407", "Score": "0", "body": "The tests that Microsoft have developed for some of their own diagnostic analyzers can be found [here](https://roslyn.codeplex.com/SourceControl/latest#Src/Diagnostics/Test/)." ...
[ { "body": "<p>I've never coded a diagnostics analyzer, so I don't know if that's a possibility, but I think these:</p>\n\n<pre><code>private const string DiagnosticId = \"SingleGeneralException\";\nprivate const string Description = \"Verifies whether a try-catch block does not contain just a single Exception c...
{ "AcceptedAnswerId": "48094", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T22:01:33.670", "Id": "47400", "Score": "14", "Tags": [ "c#", "roslyn" ], "Title": "DiagnosticAnalyzer for Roslyn that guards against catch-all exception clauses" }
47400
<p>Written in 100% managed code, the Roslyn project exposes the C# and VB compilers as a service.</p> <blockquote> <p>Historically, the managed compilers we’ve shipped in Visual Studio have been opaque boxes: you provide source files, and they churn those files into output assemblies. Developers haven’t been pr...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T22:02:15.073", "Id": "47401", "Score": "0", "Tags": null, "Title": null }
47401
A version of the C# and VB compilers that is written in managed code.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T22:02:15.073", "Id": "47402", "Score": "0", "Tags": null, "Title": null }
47402
<p>In Objective-C, many of the NSString or NSMutableString methods for comparing or manipulating strings require a <em>range</em> argument--that is, an argument of data type <code>NSRange</code> (a struct containing a starting position and a length). This applies outside of NSString (NSArray for example), but NSString...
[]
[ { "body": "<p>I see a couple of ways to clean this up.</p>\n\n<p>First of all, you mention not wanting to use <code>#define</code>, but let's not forget about <code>#undef</code>. You could define a macro as the first line of this method and undefine it as the last line of the method.</p>\n\n<p>For example:</p...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T22:08:46.330", "Id": "47404", "Score": "5", "Tags": [ "c", "objective-c" ], "Title": "Cleaning up repeated calls to NSMakeRange()" }
47404
<p>I have code which is matching features within regions. The first thing it does it matches features from one region to an entire database of region features. </p> <p>I have a mapping from query feature index (<code>qfx</code>) into database feature index (<code>ax</code>). A database feature index has associated wit...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T00:41:47.210", "Id": "83083", "Score": "0", "body": "Considering that this is a code review site, I thinks it's worth mentioning that your code is really hard to read, largely due to naming. The first line has `qrid` and `qrid2_nns`...
[ { "body": "<p>What would you think of</p>\n\n<pre><code>match_iter = izip(*valid_lists)\nrid2 = defaultdict(list)\nfor qfx, rid, fx, fs, fk in match_iter:\n rid2[rid].append(qfx, fx, fs, fk)\n</code></pre>\n\n<p>Seems like that might cut the time in the final loop by almost 50%. The extraction from match_ite...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T22:40:20.020", "Id": "47407", "Score": "3", "Tags": [ "python", "performance", "numpy", "hash-map" ], "Title": "Building a dict/list of lists" }
47407
<p>I've written this email program in Python, and I would like to get some feedback on it. (i.e. closing the server twice after the raw input, etc.)</p> <pre><code>import console import socket import smtplib from getpass import getpass user = raw_input('What is your name? ').title() host_name = socket.gethostname() p...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2019-02-17T14:43:21.577", "Id": "413231", "Score": "0", "body": "`if ...: smtpserver.close() else: smtpserver.close()` -> `smtpserver.close()`" } ]
[ { "body": "<ul>\n<li><p>I would suggest putting all the code in main() except for the imports. Then at the bottom, do</p>\n\n<pre><code>if __name__ == '__main__':\n main(sys.argv)\n</code></pre>\n\n<p>The advantage of structuring your file this way is that you can run the python interpreter and import your c...
{ "AcceptedAnswerId": "47414", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T23:14:10.350", "Id": "47411", "Score": "7", "Tags": [ "python", "beginner", "python-2.x", "email" ], "Title": "Python Email Program" }
47411
<p>I encountered with the following code in the work. The <code>MyItemCoordinator</code> should receive <code>MyItem</code> objects, process them, add them to <code>MyItemList</code> collection and then pass them to the listeners.</p> <p>My questions are:</p> <ol> <li>When I saw <code>NewMyItem</code> method I though...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T12:05:51.050", "Id": "83143", "Score": "2", "body": "`MyItemList` allows direct manipulation of the internal state, bypassing `AddMyItemToList` etc." } ]
[ { "body": "<p>You're right, but you should take this to its logical conclusion. </p>\n\n<ul>\n<li>Creating item belongs to a factory class.</li>\n<li>Tracking a list of items (coordinating?) is another responsibility.</li>\n<li>Handling the new item (or list? Not clear from the code) belongs to a third class.</...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T23:23:16.480", "Id": "47413", "Score": "4", "Tags": [ "c#", "collections", "factory-method" ], "Title": "Does the class have unnecessary and violating Single responsibility princi...
47413
<p>I have an HTTP server class (.hpp &amp; cpp). I am trying to improve reserve data from the socket class because I have <code>s.getline()</code> to get HTTP call. My <code>s.RecvData()</code> gets data line by line in an infinite loop to build HTTP struct.</p> <p>This is my old code:</p> <pre><code>while (1) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T09:30:30.570", "Id": "83124", "Score": "0", "body": "You should go for [regular expressions](http://en.cppreference.com/w/cpp/regex) to parse the header. You can check out other HTTP server's source code to see how they implement th...
[ { "body": "<p>First of all, a few notes about style:</p>\n\n<ul>\n<li>You probably have a typo in <code>loacation_End_chars</code>. I think that you meant <code>location_End_chars</code> instead.</li>\n<li>Also, you should be consistent with <code>location_tab_char</code> and use <a href=\"http://en.wikipedia.o...
{ "AcceptedAnswerId": "47450", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T01:09:16.367", "Id": "47416", "Score": "5", "Tags": [ "c++", "strings", "c++11", "http" ], "Title": "Parsing httpline" }
47416
<p>I am working on a very simple game and thought it would be a good opportunity to learn and use the Factory Method pattern for creating game objects. I studied the pattern but I'm a bit confused about the Java implementation so thought I would share what I have come up with and get some opinions. </p> <p>Please keep...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T12:59:33.947", "Id": "83517", "Score": "0", "body": "What problem does the Factory pattern solve? You need to \"feel\" the pain of the problem a bit before you seek to adding all this complexity of the pattern. Your example shows `n...
[ { "body": "<p>This pattern can be difficult to understand outside of an application with many modes of operation. There are two advantages to using the factory patterns: you can swap in different implementations, and you can vary the construction parameters without changing client code.</p>\n\n<p>Where do these...
{ "AcceptedAnswerId": "47431", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T01:48:48.620", "Id": "47422", "Score": "5", "Tags": [ "java", "design-patterns", "factory-method" ], "Title": "Java implementation of the Factory Method pattern" }
47422
<p>I am currently writing a program that allows me to search for files in a user-specified directory. My current code is as follows:</p> <pre><code>if os.path.exists(file_path)!= True: print('\n******* Path does not exist. *******\n') else: while True: aa = '''\nWhich search characteristics wou...
[]
[ { "body": "<p>Overall, you need to look into PEP 8. Other then that, you need to apply a strategy pattern to get rid of redundant <code>if</code>/<code>else</code> loop. See more detailed analysis below.</p>\n\n<h1>Line by line analysis</h1>\n\n<pre><code>if os.path.exists(file_path)!= True:\n</code></pre>\n\n<...
{ "AcceptedAnswerId": "47497", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T02:28:26.980", "Id": "47427", "Score": "6", "Tags": [ "python", "exception-handling", "python-3.x", "search" ], "Title": "Searching for files in a specified directory" }
47427
<p>Regular expressions are one of the worst aspects of debugging hell. Since they are contained in string literals, It's hard to comment how they work when the expressions are fairly long.</p> <p>I have the following regular expression:</p> <pre><code>\b\d{3}[-.]?\d{3}[-.]?\d{4}\b </code></pre> <p>Source: <a href="h...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T03:44:11.243", "Id": "83094", "Score": "2", "body": "What language are you embedding the regexes in? Java? Please tag." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T03:48:09.323", "Id": "83095",...
[ { "body": "<p>Whatever you do, <em>don't</em> append strings like that! If you look at the generated bytecode, you'll see that the compiler does exactly what you told it to do:</p>\n\n<pre><code>$ javap -c Main\nCompiled from \"Main.java\"\npublic class Main {\n public Main();\n Code:\n 0: aload_0 ...
{ "AcceptedAnswerId": "47602", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-04-17T03:36:00.017", "Id": "47432", "Score": "2", "Tags": [ "java", "strings", "regex" ], "Title": "Regex to match phone numbers, with comments" }
47432
<p>I just wrote this but I'm not sure if this is good practice. Can someone give me advice as to whether it's good or how I can do better or even it's bad code?</p> <p>The point is that I need a sub List-array-set of the enum. The <code>SubType.ELSE</code> shall have another name in reality (I know that was a bad ch...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T23:01:37.507", "Id": "83687", "Score": "0", "body": "I would not complicate the code with hashmap/enummap/etc caches as the answers suggest. It seems [premature optimization](http://programmers.stackexchange.com/a/80092/36726)." }...
[ { "body": "<p>I suggest two changes to <code>values(SubType)</code>:</p>\n\n<ul>\n<li>Return a <code>Set</code> instead of a <code>List</code>.</li>\n<li>Prepare all the possible results at class-loading time, so that <code>values(SubType)</code> could be accomplished by a simple lookup. The code is slightly m...
{ "AcceptedAnswerId": "47448", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T05:44:58.487", "Id": "47437", "Score": "17", "Tags": [ "java", "enum" ], "Title": "Enum with getting subset" }
47437
<p>I have a few views that all follow the same pattern. They select a primary key from some main table and then a few semicolon seperated strings of captions of related rows over many-to-many relations. All columns that are used in joins are either primary keys or have a manually set index and are of type <code>NUMBER(...
[]
[ { "body": "<p>Oracle regular Character types are limited to 4000 bytes. Really, Oracle should find a way to extend that, but until they do, using CLOB is the only real option.</p>\n\n<p>On the other hand, Oracle has a rich infrastructure available for creating user defined functions. You are already creating th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T07:00:31.513", "Id": "47441", "Score": "5", "Tags": [ "sql", "oracle" ], "Title": "Length limited listagg for muliple m:n relations in a view" }
47441
<p>If you have a Gmail ID, then you can also receive emails on the same account even if you add extra dots in the username or add '+' and some characters. </p> <p>Say your Gmail ID is montypython@gmail.com. You will receive emails on same account even if it is sent to:</p> <ul> <li>monty.python@gmail.com</li> <li>mo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T01:29:12.547", "Id": "84402", "Score": "0", "body": "Note that `gmail.com` is not the only domain used for Google's mail service; `googlemail.com` works as well." } ]
[ { "body": "<pre><code>def return_gmail_user(email):\n</code></pre>\n\n<p><code>Return</code> isn't a very descriptive word to use as the beginning of a function name. Call it <code>parse_gmail_user</code> or something along those lines instead.</p>\n\n<pre><code> username = email.split('@')[0]\n domain =...
{ "AcceptedAnswerId": "47458", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T10:00:14.500", "Id": "47451", "Score": "5", "Tags": [ "python", "email" ], "Title": "Giving actual username from Gmail ID" }
47451
<p>I am running this query and it takes several minutes to complete. How can I tune it (unfortunately I don't have the privileges to run an SQL tuning advisor)?</p> <pre><code>select 'Master' || d.ntt_id || '_' || d.deal_nummas, p.prof_currency, sum(p.prof_ts1), sum(p.prof_ts2), sum(p.prof_ts3), sum(p.prof_ts4), sum...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T12:15:45.340", "Id": "83147", "Score": "2", "body": "Could you tell us more about what the `profiles` table is for? I really have to question the sanity of a schema with so many columns." } ]
[ { "body": "<p>I'll echo what 200_success said about the schema. But working with what you have, I would think breaking it down into two steps (via temp table if this is a one-time aggregation, or via a view if repeat query) may improve performance. Then just perform your <code>SUM()</code> operations on the tem...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T10:30:01.213", "Id": "47453", "Score": "5", "Tags": [ "sql", "oracle" ], "Title": "Tuning a query for performance" }
47453
<p>I have a Symfony2 project. I have an Entity <code>Asset</code> which can have relations with <code>Category</code>. I store a <code>categoryCount</code>-field within the <code>Asset</code> to determine if an asset has one, to select those fast via a DQL-query depending on the current user state.</p> <p>Now found my...
[]
[ { "body": "<p>You can try to use <a href=\"https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Query/Filter/SQLFilter.php\" rel=\"nofollow noreferrer\">SQLFilter</a> for this purpose. It allows you to tune SQL query based on some logic. You can pass information about your user's state into filter...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T10:46:31.663", "Id": "47455", "Score": "5", "Tags": [ "php", "php5", "doctrine" ], "Title": "Filtering queries based on the current user state" }
47455
<p>How can I shorten this (working) code to create future dates in ruby for use as params in URLs?</p> <p>I'm doing:</p> <pre><code>require 'cgi' require 'time' now=Time.new() now_year=now.strftime('%Y').to_i now_month=now.strftime('%m').to_i now_day=now.strftime('%d').to_i now_hour=now.strftime('%H').to_i start_ho...
[]
[ { "body": "<p>You can <a href=\"http://www.ruby-doc.org/core-2.1.1/Time.html#method-i-2B\" rel=\"noreferrer\">add seconds directly to a <code>Time</code> object</a>, so you could do:</p>\n\n<pre><code>now = Time.now.utc\nstarts = now + 3600 # Add 1 hour's worth of seconds (60 * 60)\nends = now + 7200 # Add 2 ...
{ "AcceptedAnswerId": "47460", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T11:01:04.560", "Id": "47456", "Score": "5", "Tags": [ "ruby", "datetime", "url" ], "Title": "Adding time offsets to create future dates" }
47456
<p>For a website, I've got some inline PHP, posted below. It's supposed to log traffic to the website, and it does its job fine. But at the end of the day, I'm not even close to a PHP developer, and this is really just hacked together from Googling and inferring from other, more familiar languages. How can I improve...
[]
[ { "body": "<p>I don't think its really SQL-injection, but <code>$hostname</code> is not taken from server but from DNS.</p>\n\n<p>Theoretically i can add some kind of malicious domain name and affect your query. But from other hand, domain syntax is really limited. I don't think you can use it to do some seriou...
{ "AcceptedAnswerId": "47498", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T11:28:55.233", "Id": "47461", "Score": "3", "Tags": [ "php", "mysql", "php5", "mysqli" ], "Title": "Inline PHP IP access log" }
47461
<p>Which one of these two would you prefer writing in your code?</p> <p><strong>This:</strong></p> <pre><code>tweet = tweet.replaceAll("@\\w+|#\\w+|\\bRT\\b", ""); tweet = tweet.replaceAll("\n", " "); tweet = tweet.replaceAll("[^\\p{L}\\p{N} ]+", " "); tweet = tweet.replaceAll(" +", " ").trim(); </code></pre> <p>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T18:10:25.263", "Id": "83256", "Score": "1", "body": "FWIW, (and I'm sure you know this) even in the second example you can comment each line by putting the comment at the end of the code with a // comment. I find those pretty readab...
[ { "body": "<p>This is probably a matter of preference. <s>But performance-wise it's definitely faster to do the second one. Especially as there should be a new instance of String created for every assignment you perform.This means, you create 3 Instances of String, that are just \"useless garbage\".</s> </p>\n\...
{ "AcceptedAnswerId": "47469", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T11:49:38.633", "Id": "47465", "Score": "11", "Tags": [ "java", "performance", "strings", "regex" ], "Title": "What would be preferred aesthetically and performance wise?" }
47465
<p>I cannot figure out why I didn't get 100% success from the Codility's Perm-Missing-Element test even I solve with \$O(n)\$. I will appreciate any advice/answers.</p> <p>You can see the problem, my code, and the scores <a href="https://codility.com/demo/results/demoVTDAWC-P25/">on the Codility site</a>, as well as h...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T13:19:36.640", "Id": "83161", "Score": "0", "body": "Doesn't codility provide you more details about this ? Type of test cases for instance" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T13:23:29.383...
[ { "body": "<p>From the site :</p>\n\n<pre><code>WRONG ANSWER\ngot -2147483647 expected 1\n</code></pre>\n\n<p>So int has overflow because you count everything up.\nMine solution to that problem :</p>\n\n<pre><code>public int solution(int[] A) {\n int previous = 0;\n if (A.length != 0) {\n Arrays.so...
{ "AcceptedAnswerId": "47477", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T12:45:36.860", "Id": "47471", "Score": "30", "Tags": [ "java", "performance", "algorithm", "programming-challenge" ], "Title": "Perm-Missing-Elem: 100% functional score, bu...
47471
<p>Could I get some feedback on my simple start to an admin template: <a href="http://jsfiddle.net/spadez/GHKxW/3/" rel="nofollow">http://jsfiddle.net/spadez/GHKxW/3/</a></p> <p><strong>HTML</strong></p> <pre><code> &lt;div class="wrapper"&gt; &lt;div class="left"&gt; &lt;a href="#"&gt;&lt;img src="nav_sp...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T08:05:56.120", "Id": "83502", "Score": "0", "body": "Answers seem pretty on point for what little you have here, but I'd also add that you should remember to use `alt=\"logo\"` to add some more semantic value to your content images....
[ { "body": "<p>This looks pretty good for a start.</p>\n\n<p>the only thing that I see right away is your CSS formatting</p>\n\n<pre><code>a {\n text-decoration: none\n}\n\nhtml, body {height: 100%; max-height: 100%; padding:0; margin:0;}\n.wrapper {display:table; width:100%; height:100%;}\n.wrapper &gt; div ...
{ "AcceptedAnswerId": "47479", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T13:16:27.803", "Id": "47475", "Score": "4", "Tags": [ "html", "css" ], "Title": "Admin CSS sidebar template" }
47475
<p>I really like the ruby <code>?</code> <code>:</code> syntax for <code>if</code>/<code>else</code> statements.</p> <p>However, I'm not sure how to do the following with a nested statement:</p> <pre><code>if information.is_empty? if leader? || possessor? link_to('update ' + contextual('your') + ' credentials!'...
[]
[ { "body": "<ol>\n<li><p>The <code>?:</code> is called a <a href=\"http://en.wikipedia.org/wiki/%3F:\" rel=\"nofollow noreferrer\">ternary operator</a>. It's not specific to Ruby; a lot of languages have it (in fact, I believe I linked you to that wikipedia page in a comment <a href=\"https://codereview.stackexc...
{ "AcceptedAnswerId": "47485", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T14:05:45.577", "Id": "47481", "Score": "5", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Concise nested statements" }
47481
<p>This class (<code>PanelScrollable</code>) is part of my <code>view</code> package, in an MVP designed Java Swing system. I am not using any MVP frameworks, it's all custom.</p> <p>The reason I'm posting this code is that I fear too much of the rendering logic is directly accessing Swing components, making it diffic...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T17:44:42.483", "Id": "83251", "Score": "0", "body": "+1 nice code, good thought-out question. One small note: are `Componentable` and `PanelScrollable` both purposefully left with the default access restriction? Otherwise, I'd rec...
[ { "body": "<p>This code is awesomely written. I still have a few really small remarks:</p>\n\n<h3>Ordering members:</h3>\n\n<blockquote>\n <p>If openness separates concepts, then vertical density implies close association. So lines of code that are <strong>tightly related should appear vertically dense.</stron...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T14:30:35.013", "Id": "47486", "Score": "10", "Tags": [ "java", "swing", "mvp" ], "Title": "PanelScrollable - a reusable class for rendering a changeable number of panels" }
47486
<p>After asking a <a href="https://stackoverflow.com/q/23129913/300996">question on StackOverflow</a> about the two .NET caching systems taking dependencies on each other I gave implementing them a go. I posted them as my own answer there but before accepting the answer I'd like some second opinions on the implementati...
[]
[ { "body": "<p>Overall looks very good, clean and well done. I only see minor tiny little things...</p>\n<h3>Nitpick - &quot;Initialise&quot; vs &quot;Initialize&quot;</h3>\n<p>This is just a minor nitpick, but it's kind of jumping at me:</p>\n<blockquote>\n<pre><code>private void Initialise()\n{\n HttpRuntim...
{ "AcceptedAnswerId": "47511", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T14:56:22.617", "Id": "47488", "Score": "5", "Tags": [ "c#", ".net", "cache" ], "Title": "HTTPCache and MemoryCache cross dependency" }
47488
<p>After refactors and refactors and the discovery of very common patterns on many of the classes of the software I wrote, I decided that it would be fine to have something like an arbitrary-keyed map, that would require the key to be stored in the object (which allows to use the object's name as a key for instance).</...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T20:40:58.553", "Id": "83288", "Score": "1", "body": "`arbitrary-keyed map, that would require the key to be stored in the object` You mean like `std::set<T>` ?" } ]
[ { "body": "<blockquote>\n <p>[...]I decided that it would be fine to have something like an arbitrary-keyed\n map, that would require the key to be stored in the object (which allows to use \n the object's name as a key for instance).</p>\n</blockquote>\n\n<p>To restate your problem: you want the add behavio...
{ "AcceptedAnswerId": "47525", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T15:27:46.340", "Id": "47491", "Score": "10", "Tags": [ "c++", "c++11", "template", "collections", "container" ], "Title": "Is my C++11 generic container a good design?"...
47491
<p>I have a project that I've been trying to get just right for the past three months and it's still not quite there yet.</p> <p>I'm injecting some jQuery and jQueryUI code into pages that I have no control over and I need to be able to "sandbox" my code away from anything that may or may not be there at DOM-ready, or...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T17:39:57.650", "Id": "83249", "Score": "0", "body": "Is the last line of your javascript intentional? `})(myJQuery, myJQuery);`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T18:04:49.983", "Id":...
[ { "body": "<p>As far as experience goes, what my team does is to actually <strong>agree on a single version of a library and <em>stick to it</em></strong> for the entire production release. That way, each developer will not encounter bugs due to differences. We then talk about upgrades in a meeting to agree on ...
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T16:08:11.623", "Id": "47494", "Score": "11", "Tags": [ "javascript", "jquery", "jquery-ui", "namespaces" ], "Title": "Namespacing jQuery/jQueryUi into markup that I don't cont...
47494
<p>So, I thought I'd do this using scipy.constants:</p> <pre><code>import numpy as np from scipy.constants import physical_constants constants = np.array([(k,)+v+(v[2]/abs(v[0]),) for k,v in physical_constants.items()], dtype=[('name', 'S50'), ('val', 'f8'), ('units', 'S10'), ('abs_...
[]
[ { "body": "<p>I think the biggest problem here is that you're trying to do too much in a single line. It seems obscure because it <em>is</em> obscure. If I were looking at this outside of a Code Review setting, I would think that someone had purposefully obfuscated it or condensed it for some character count ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T16:30:12.400", "Id": "47496", "Score": "6", "Tags": [ "python", "python-3.x", "numpy" ], "Title": "Determining the least-accurately known physical constants" }
47496
<p>To get an idea of what the controller code reflects, here is a screenshot:</p> <p><img src="https://i.stack.imgur.com/fMeVE.png" alt="enter image description here"></p> <p>Basically, the idea is that you print out a list of football players which you can then filter by their name, price, field position, and team. ...
[]
[ { "body": "<p>First of all, for a better user experience, I would avoid pagination in favour of infinite scroll. <a href=\"http://jsbin.com/zusal/2/edit\" rel=\"nofollow\">Here is a simple Angular infinite scroll implementation</a></p>\n\n<p>I presume you are aware of minification-proof technique <code>.control...
{ "AcceptedAnswerId": "47633", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T16:47:12.940", "Id": "47499", "Score": "4", "Tags": [ "javascript", "angular.js" ], "Title": "Controller structure for a browser game module with filters and pagination" }
47499
<p>Last week I asked to review my "Guess a number" game in Java <a href="https://codereview.stackexchange.com/questions/47028/guess-a-number-game-in-java">here</a></p> <p>I learned so much that I decided to try a little harder game and put into practice all the amazing feedback I received there. Would you please revie...
[]
[ { "body": "<p>Nice improvement from the initial version. Good job! Here are a couple of brief notes.</p>\n\n<ol>\n<li>I'm very wary of having any method named <code>run()</code> outside of classes which implement the <a href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/Runnable.html\" rel=\"nofollow\"...
{ "AcceptedAnswerId": "47506", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T17:52:56.100", "Id": "47504", "Score": "10", "Tags": [ "java", "game", "hangman" ], "Title": "\"Hangman\" game follow-on" }
47504
<p>So knowing the little pieces is something different and putting them together is something different. </p> <p>Here is the code where I try to follow good oop practices and 3 - layered structure. </p> <p>Any review is greatly appreciated: </p> <p>The form is located at <strong>registirationform.jsp</strong>.</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T11:00:04.117", "Id": "83375", "Score": "0", "body": "Short answer: You have `new DatabaseConnectionImpl()` and `catch (SQLException e)` in your servlet class, therefore your web layer is not separated from data access layer." }, ...
[ { "body": "<p>I know you're asking strictly for feedback about the layers (which look fine to me), but in case you're looking for other feedback too:</p>\n\n<pre><code>if(username.equals(\"\")\n || password.equals(\"\")\n || email.equals(\"\")){\n</code></pre>\n\n<p>You need to null check thes...
{ "AcceptedAnswerId": "47520", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T18:30:46.290", "Id": "47507", "Score": "6", "Tags": [ "java", "object-oriented", "mvc" ], "Title": "A simple web-app code - user registration. Is the layering ok?" }
47507
<p>Here is my Boyer Moore code in Python:</p> <pre><code>def BoyerMoore(stringy, substring): if stringy == substring: return 0 ASCIIcharset = [-1]*256 for x in xrange(len(stringy)): ASCIIcharset[ord(stringy[x])] = x stringLen = len(stringy) substringLen = len(substring) for i i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T20:11:18.393", "Id": "83283", "Score": "0", "body": "No time for a proper review atm but the pythonic way to write your first loop is : `for i,x in enumerate(stringy): ASCIIcharset[ord(x)] = i`. Also, I have doubts about the `s1[x] ...
[ { "body": "<p>The following examples show that there is something wrong in your code :</p>\n\n<pre><code>print(BoyerMoore('azertyuiop', 'zertyuio' )) # 1 - fair enough\nprint(BoyerMoore( 'zertyuio' , 'azertyuiop')) # -1 - so far so good\nprint(BoyerMoore('azertyuiop', 'azertyuiop')) # 0 - ok\nprint(BoyerMoor...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T18:43:00.643", "Id": "47508", "Score": "4", "Tags": [ "python", "performance", "strings" ], "Title": "Increase performance of Boyer Moore" }
47508
<p>As a beginner I am always determined to improve myself. I've got written the following Code using jQuery that is working fine. However, I am sure that there are cleaner ways for achieving the same.</p> <p>Right now, I am struggling with the this keyword and the asynchronous loading of the JSON file. Moreover, I am ...
[]
[ { "body": "<ul>\n<li><p>Storing <code>deferred</code> in the model and then passing a callback to <code>getData</code> is a bit obscure. You could write it like this instead:</p>\n\n<pre><code>getData: function() {\n var deferred = $.Deferred();\n\n if(!this.data) {\n $.getJSON('...',).done(functio...
{ "AcceptedAnswerId": "47518", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T19:58:28.160", "Id": "47516", "Score": "6", "Tags": [ "javascript", "jquery", "beginner", "json", "asynchronous" ], "Title": "Load JSON file into model using Javascript...
47516
<p>I'm writing a script for others to use on their websites. I'd like to use jQuery in this script. Because I don't have control over what frameworks people use on their sites, I need to make sure jQuery is available and that it's version 1.8 or higher. Here's my take on it. Does anyone see anything I could/should be d...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T22:14:04.797", "Id": "83297", "Score": "1", "body": "I'd rather parse `navigator.userAgent` to detect if a browser is IE, what you are doing feels quite hacky and is probably inefficient. Please see http://stackoverflow.com/question...
[ { "body": "<p>Before actually diving into creating a jQuery checker (nice idea by the way), you might really want to check some cases before building the code. There are several issues with your script here:</p>\n\n<ul>\n<li><p>Your script assumes that there is jQuery. What if there's no jQuery at all? How woul...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-17T20:37:52.897", "Id": "47519", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Dynamically loading jQuery when it's not available or version isn't high enough" }
47519
<p>I'm fairly new to JS/jQuery (a few months), and I think it's time to start getting involved in the community. So I wrote a little plugin. Nothing revolutionary. Really, the project is to write a clean, workable plugin. Any and all thoughts and suggestions on how I can make the code cleaner, or the animations smoothe...
[]
[ { "body": "<p>I like your code, it is easy to follow, has comments, well named variables etc. The only thing I would point out is that you are repeating yourself here and there. So I will focus on that:</p>\n\n<ul>\n<li><p>This piece of code:</p>\n\n<pre><code>if (o.left) {\n nav.css({\n 'width': o.wi...
{ "AcceptedAnswerId": "47778", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T00:10:39.600", "Id": "47524", "Score": "3", "Tags": [ "javascript", "jquery", "beginner", "css", "plugin" ], "Title": "Menu Bar Animation Plugin" }
47524
<p>I'm building a Ruby API client. My brief is to extract ids out of various inputs and fetch the relevant data. It's working just fine at the moment but I think it's a little clumsy.</p> <p>My specs (which pass):</p> <pre><code>shared_examples 'it requests ids' do |resource| it 'sends the ids to Foo::Client' do ...
[]
[ { "body": "<p><strong>You should expect</strong><br>\nStarting a couple of years back, <code>rspec</code> is moving to a <a href=\"http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax\" rel=\"nofollow\">new expectation syntax</a>, you should consider porting to it:</p>\n\n<pre><code>shared_examp...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T01:03:57.033", "Id": "47526", "Score": "5", "Tags": [ "ruby", "api" ], "Title": "Extracting ids out of arguments of different types" }
47526
<p>First of all, I am not using JQuery but <a href="https://github.com/cheeriojs/cheerio" rel="nofollow">Cheerio</a>. I have never actually used JQuery in "real life" -- I started with Cheerio, which is a subset and doesn't actually work in a browser environment.</p> <p><em>(Note: I don't have enough reputation here t...
[]
[ { "body": "<p>Here's what I did, comments in the code.</p>\n\n<pre><code>$ = cheerio.load(self.formPage.toString());\npath = require('path'); //Move out path from the loop to avoid re-requiring it\n$('form').each(function (index, form) {\n\n var $form = $(form);\n\n // Removed action here. You seem to use it ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T01:45:36.667", "Id": "47528", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "Speed and ID concerns converting DOM object into JQuery objects" }
47528
<p>I'm generating domains with random names. I used the map function because it packages the results into a list which I can then <code>join()</code> into a string but the way I used the lambda function could be confusing to people reading this later.</p> <pre><code>def generateHost(): charSet = 'abcdefghijklmnopqrs...
[]
[ { "body": "<p>The answer to <a href=\"https://stackoverflow.com/questions/2257441/python-random-string-generation-with-upper-case-letters-and-digits\">this question</a> suggests the following:</p>\n\n<pre><code>''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(length))\n</code></pre>\...
{ "AcceptedAnswerId": "47531", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T02:04:22.857", "Id": "47529", "Score": "12", "Tags": [ "python", "beginner", "strings", "random" ], "Title": "Creating a string of random characters" }
47529
<p>I've created a <code>MovingAverage</code> class, but it is not optimized for performance at all. I care about performance a little bit because I'm using this class in trading (I collocate on exchange and so on and so on; let's talk about performance of this particular class).</p> <p>How would you improve it for bet...
[]
[ { "body": "<p>If performance of this code is critical, then it could make sense to avoid heap allocations for <code>Candle</code>s. I think the most reasonable way to do that would be make <code>Candle</code> into a <code>struct</code>.</p>\n\n<p>Though <a href=\"https://stackoverflow.com/q/441309/41071\">mutab...
{ "AcceptedAnswerId": "48614", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T06:22:40.143", "Id": "47542", "Score": "3", "Tags": [ "c#", "performance" ], "Title": "Moving average implementation" }
47542
<p>I'm learning go. I wrote a simple logparser for SLF4J in Python some time ago and tried to port it to go as an exercise. The algorithm is identical, but the go-solution isn't quite as fast (the Python solution is about 1.5 times faster for large enough logfiles). Is there any way to get more speed out of it? It do n...
[]
[ { "body": "<p>You should use <code>bufio.Scanner</code> rather than a <code>bufio.Reader</code>. It won't make your code any faster, but it'll simplify things a bit.</p>\n\n<p>One reason your code is slow is that you're converting every line from <code>[]byte</code> to <code>string</code>. You can avoid this by...
{ "AcceptedAnswerId": "47770", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T07:56:43.150", "Id": "47549", "Score": "3", "Tags": [ "performance", "beginner", "go" ], "Title": "Make logparser faster" }
47549
<p>Left view of a Binary Tree is set of nodes visible when tree is visited from left side. Left view of following tree is 12, 10, 25.</p> <pre><code> 12 / \ 10 30 / \ 25 40 </code></pre> <p>Looking for code review, optimizations and best practices. Also verifying space com...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T10:29:50.343", "Id": "83372", "Score": "0", "body": "\"Left view of a Binary Tree is [the] set of nodes ...\" should translate to something like `public static List<T> leftView(BinaryTree<T>)`." } ]
[ { "body": "<p>Although the algorithms seems fine, there are issues with the choosen abstractions.</p>\n\n<p><code>LeftView</code> is a factory of lists, which are left views of an inner tree. <code>LeftView</code> is not a data structure itself, but a factory of it, configured by a list, that are converted to a...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T08:01:02.053", "Id": "47550", "Score": "2", "Tags": [ "java", "algorithm", "tree" ], "Title": "Print left view of the tree" }
47550
<p>This post is a <a href="https://codereview.stackexchange.com/questions/47066/check-if-xmlnode-with-certain-attribute-exists-and-create-xmlnode-if-not">follow up question</a>.</p> <p>The purpose of this class should became clear without any further explanation. Raise your hand. If not, then I will have to improve t...
[]
[ { "body": "<blockquote>\n <p>//TODO: ReSharper warns about \"Possible multiple enumeration of\n IEnumerable\", whats this all about?</p>\n</blockquote>\n\n<p>Because you are working with an <code>IEnumerable</code> it's possible that the underlying implementation of the method will re-execute any re-loading o...
{ "AcceptedAnswerId": "47554", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T08:05:44.573", "Id": "47551", "Score": "2", "Tags": [ "c#", "xml" ], "Title": "Manage XML file with custom XmlFileHandler class" }
47551
<p>I'm working on a Pong game and right now I'm working on being able to register multiple KeyDown presses simulatenously. I used the Win32 native method <code>GetKeyBoardState</code> first to loop through all of the virtual keys and see if any of the keys matched the game input keys. Now this worked just fine but in t...
[]
[ { "body": "<p>What is impacting you performance so heavily is the creation of Tuples <strong>everytime</strong> you recieve a keypressed event.</p>\n\n<p>creating objects is <strong>slow</strong>. What you should do instead is, directly apply the changes to the moving objects (your two pong-thingies).</p>\n\n<p...
{ "AcceptedAnswerId": "47734", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T09:16:00.937", "Id": "47556", "Score": "3", "Tags": [ "c#", "object-oriented", "event-handling" ], "Title": "Registering multiple keypresses simultaneously, very slow" }
47556
<p>Simple idea: just have a plugin (more a basic function). That I can use with jQuery in different ways it offers, means:</p> <pre><code>var myNewVar = $.myNewFunction( myVar ); var myNewVar = $().myNewFunction( myVar ); </code></pre> <p>I want to know if what I did is the good way to doesn't repeat the code, or if ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T09:49:41.033", "Id": "83367", "Score": "0", "body": "And I'm open to any other suggestion about my code if there is" } ]
[ { "body": "<p>Since your function - as far as I can tell - doesn't rely on a jQuery collection, I'd stick to always using \"1 true way\" of calling it.<br>\nI.e. I assume that</p>\n\n<pre><code>$(\"some &gt; selector\").formArrayToObject(arr) === $.formArrayToObject(arr);\n</code></pre>\n\n<p>that is, the two w...
{ "AcceptedAnswerId": "47565", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T09:43:33.130", "Id": "47559", "Score": "1", "Tags": [ "javascript", "jquery", "plugin" ], "Title": "jQuery plugin creation and declaration for usage with $(). or $" }
47559
<p>For my Advanced Data Mining class (undergrad) we were to design a program that would predict the next word a user is likely to type via automatic text classification using the n-gram model.</p> <p>The following is what I came up with. The reason I am posting this is because I am about to graduate and I want to be a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T09:27:13.537", "Id": "83612", "Score": "0", "body": "Thanks for the edit! I was struggling with the formatting of the post if you couldn't tell haha" } ]
[ { "body": "<p>Your code looks <em>at first glance</em> quite complete and professional, so onto the points. I hereby assume that you are using Java 7, since you have not made any restrictions and it is the most common version, though I may be wrong.</p>\n\n<ol>\n<li><p>Consider changing your programs design. Cu...
{ "AcceptedAnswerId": "47564", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T10:08:54.473", "Id": "47560", "Score": "5", "Tags": [ "java", "optimization", "data-mining" ], "Title": "AutoComplete program using the n-gram model" }
47560
<p>I have a task to print all zero subsets of 5 numbers, input from the console. I have succeeded in implementing a working code, but it seems it is quite complex (it is like inception) and if the count of the numbers is to be greater, it would be rather pointless to use such a method.</p> <pre><code>using System; usi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T11:24:11.850", "Id": "83376", "Score": "0", "body": "The zero subset sum problem algorithms are briefly [described here](http://en.wikipedia.org/wiki/Subset_sum_problem). Just implement one of them..." }, { "ContentLicense":...
[ { "body": "<h3>Your input loop:</h3>\n<blockquote>\n<pre><code>for(int i = 0; i &lt;= 4; i++)\n</code></pre>\n</blockquote>\n<p>is overly complicated to understand for the task at hand. Usually you iterate differently:</p>\n<pre><code>for (int i = 0; i &lt; Numbers.Length; i++)\n</code></pre>\n<hr>\n<blockquote...
{ "AcceptedAnswerId": "47574", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T10:53:42.990", "Id": "47562", "Score": "7", "Tags": [ "c#", "array", "console" ], "Title": "Sum of subset of 5 numbers equals 0" }
47562
<p>Next is an algorithm to calculate the histogram for a given YUV420sp image. The YUV data is given by the hardware camera as an <code>unsigned char*</code>.</p> <p>The algorithms works correctly, but I'm looking to optimize it for speed.</p> <pre><code>void calculateHistogram(const unsigned char* yuv420sp, const i...
[]
[ { "body": "<p><strong>Style</strong></p>\n\n<p>Everything looks quite good to me.</p>\n\n<p>The only thing that I find a bit disturbing is the empty line after comments : it split relevant things apart and it makes the code harder to read.</p>\n\n<p>You could add a bit of documentation explaining what your code...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T11:12:02.153", "Id": "47566", "Score": "4", "Tags": [ "optimization", "c", "statistics" ], "Title": "Optimization for histogram computation algorithm in C" }
47566
<p>I've been developing sites using Dreamweaver for the last 15 years, I do a lot of code editing manually so I have quite a good knowledge of the PHP language.</p> <p>I'm diving into object orientated programming and getting to grips with classes objects and the like.</p> <p>I hope to eventually port the game to a f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T13:38:49.147", "Id": "83391", "Score": "2", "body": "I think the rule of \"class names should start with a capitalized word\" apply in php too User and Game" } ]
[ { "body": "<h1>Formatting</h1>\n\n<p>@MarcoAcierno's comment is correct, and you also have a few other formatting errors.</p>\n\n<p>We can start with <strong>capitalization</strong>! I'll quote a couple things here that could be considered <a href=\"http://framework.zend.com/manual/1.12/en/coding-standard.html\...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T11:44:30.300", "Id": "47569", "Score": "1", "Tags": [ "php", "object-oriented", "game", "classes" ], "Title": "Creating a Party Game to learn OOP" }
47569
<p>I'm working on a <a href="http://en.wikipedia.org/wiki/Bookmarklet" rel="nofollow">bookmarklet</a> that will be cached for 24 hours only, after that time it will be reloaded from the original source. Is there something I could improve?</p> <pre><code>javascript:(function () {var currentTime=new Date();var month=cur...
[]
[ { "body": "<h1>Use timestamps.</h1>\n\n<p>It's faster since you don't need to get the date, month and year. In the following script, the only function called for the date is <code>getTime()</code>. Additionally, if you use the newer <code>Date.now()</code>, you skip creating a date object.</p>\n\n<p>In the exam...
{ "AcceptedAnswerId": "47573", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T13:00:40.120", "Id": "47571", "Score": "2", "Tags": [ "javascript", "cache", "bookmarklet" ], "Title": "JavaScript bookmarklet with a 24 hour cache" }
47571
<p>I have these relevant tables in an MVC website:</p> <ul> <li><code>Server</code></li> <li><code>ServerPlayer</code></li> <li><code>ServerPlayerChat</code></li> </ul> <p>Servers have <code>serverPlayers</code> and <code>ServerPlayers</code> have <code>ServerPlayerChats</code>. Simple enough and expectable.</p> <p>...
[]
[ { "body": "<p>Use Players.SingleOrDefault() instead of Where and FirstOrDefault.\nIf you use the function GetPlayer just one time, remove it.</p>\n\n<pre><code>public ServerPlayer GetServerPlayer(string playername)\n{\n ServerPlayer player = Players.SingleOrDefault(x =&gt; x.UserName == player name);\n i...
{ "AcceptedAnswerId": "48982", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T15:19:49.283", "Id": "47582", "Score": "2", "Tags": [ "c#", "linq", "asp.net", "entity-framework", "chat" ], "Title": "Adding chat to an MVC database" }
47582
<p>I’ve got a matrix of data and I want to take the average of the positive and negative parts of the values. Is there a more Pythonic way of doing it?</p> <pre><code>from numpy import * … exposures = matrix([0]*numPaths*numExposures) exposures.shape = numPaths, numExposures … # fill matrix @vectorize def plusv(x)...
[]
[ { "body": "<p>There are a few things which we could improve:</p>\n\n<p>When importing a module, you would not usually import all symbols from that module. You can however rename the module to make it more convenient, e.g.:</p>\n\n<pre><code>import numpy as np\n# now we can do np.matrix(…), np.transpose(…), etc....
{ "AcceptedAnswerId": "47603", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T15:20:58.327", "Id": "47584", "Score": "7", "Tags": [ "python", "matrix", "numpy" ], "Title": "Average of positive and negative part of numpy matrix" }
47584
<p>Is this repository code written according to best practices? The Last Section I included it in the repository as well.</p> <pre><code>class HR_Repository&lt;T&gt; : IRepository&lt;T&gt; where T : class { private readonly LoginDataContext dataContext; public HR_Repository(LoginDataContext dataContext) {...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T19:12:47.853", "Id": "83435", "Score": "1", "body": "I don't feel like compiling this, but I assume that it must not work? That seems to be why this was closed, since its clearly written. I rather wish someone who cared enough to cl...
[ { "body": "<p>I don't like the underscore in the class name, <code>HR_Repository</code>. It's a generic name for a <em>generic class</em>, which is good, but seeing that it <em>implements</em> <code>IRepository&lt;T&gt;</code> I would expect something like this:</p>\n<pre><code>public class EmployeeRepository :...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T15:47:50.320", "Id": "47587", "Score": "2", "Tags": [ "c#", "design-patterns" ], "Title": "Is the following repository pattern properly applied?" }
47587
<p>I'm working on Ocaml.org 99 problems, and I solved the <a href="http://ocaml.org/learn/tutorials/99problems.html#Decodearunlengthencodedlistmedium" rel="nofollow">run-length decode one</a>.</p> <p>Here is the solution given by the site:</p> <blockquote> <pre><code>let decode l = let rec many acc n x = ...
[]
[ { "body": "<p>Elegance is a matter of taste, so you'll probably get different answers for that point. Personally, I find your solution easier to understand: it makes good use of the algebra defined through the <code>rld</code> type.</p>\n\n<p>From an efficiency standpoint, your algorithm creates as <code>Many</...
{ "AcceptedAnswerId": "57448", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T16:09:55.053", "Id": "47588", "Score": "2", "Tags": [ "functional-programming", "comparative-review", "compression", "ocaml" ], "Title": "Comparing run-length decoding algo...
47588
<p>I recently had to work in a tricky piece of work for a project I am working on. You can find its code <a href="https://github.com/mariosangiorgio/RateMyApp/tree/experiments" rel="nofollow">on GitHub</a> and I'd like to have a feedback about some specific parts of it.</p> <p>The project is a library and if you look ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-22T15:29:44.380", "Id": "83971", "Score": "1", "body": "Even though this code is reviewable (and I'm working on an answer for it), code that is expected to be reviewed should be contained within the question. Do you also want your `Rat...
[ { "body": "<p>First, I would recommend that you take a look at the <a href=\"http://en.wikipedia.org/wiki/Null_Object_pattern\" rel=\"nofollow noreferrer\">null object pattern</a> to avoid the <code>!= null</code> check here:</p>\n<pre><code>if (rateMyApp != null)\n rateMyApp.appLaunched(activity);\n</code><...
{ "AcceptedAnswerId": "48056", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T16:23:50.833", "Id": "47590", "Score": "3", "Tags": [ "java", "android" ], "Title": "Holding a reference of the active Android Activity" }
47590
<p>I implemented my own sorting in VBA because it doesn't provide its own, and it's healthy to test yourself. It was surprisingly difficult and I ended up make a few tweaks that I didn't expect to make in order for it to sort.</p> <pre><code>Public Sub quicksort(ByRef arr As Variant, _ ByVal left...
[]
[ { "body": "<p>Few notes.</p>\n\n<ul>\n<li>All algorithms on ranges are much simpler if the range is considered semi-open (that is, <code>right</code> is just beyond the last interesting element.</li>\n<li>The <code>While l &lt; r</code> loop does a very important job; important enough to factor it into a separa...
{ "AcceptedAnswerId": "47624", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T16:24:15.670", "Id": "47591", "Score": "10", "Tags": [ "algorithm", "sorting", "vba", "quick-sort" ], "Title": "In place quicksort" }
47591
<p>I've implemented a Segment Tree in Python3:</p> <pre><code>import math INF = int(2e9) class SegmentTreeNode: def __init__(self, l, r, v=INF): self.left = l self.right = r self.value = v def merge(self, left, right): if left is not None and right is not None: s...
[]
[ { "body": "<p><code>SegmentTreeNode</code> objects have three attributes: <code>left</code>, <code>right</code> and <code>value</code>, but only <code>value</code> is ever used. Using plain integers instead of custom objects should speed things up, as it avoids overhead both in object creation and in attribute ...
{ "AcceptedAnswerId": "48143", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T17:33:48.050", "Id": "47596", "Score": "6", "Tags": [ "python", "algorithm", "python-3.x", "tree" ], "Title": "Segment tree in Python3" }
47596
<p>Have I made any obvious mistakes?<br/> Is this code clean?<br/> Is there a better way to do this in python?<br/></p> <pre><code># -*- coding: utf-8 -*- import feedparser from feedgen.feed import FeedGenerator from random import shuffle from feedformatter import Feed import time from datetime import datetime tstart...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T18:22:21.607", "Id": "83421", "Score": "4", "body": "While the objective of this site is quite clear, it is always nice when askers give some more context than just the pure code to review. For example, you could highlight parts of ...
[ { "body": "<p>These lines appear to be out of order:</p>\n\n<blockquote>\n<pre><code>extract_entries = lambda url: feedparser.parse(url).entries\naddEntries = lambda entries: [feed.items.append(entry) for entry in entries]\nmerg = lambda urls: [addEntries(extract_entries(url)) for url in urls]\nshuffle(feed.ent...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T18:12:14.173", "Id": "47598", "Score": "4", "Tags": [ "python", "rss" ], "Title": "Simple hack to merge RSS feeds" }
47598
<p>I've been trying to optimize this piece of code:</p> <pre><code>void detect_optimized(int width, int height, int threshold) { int x, y, z; int tmp; for (y = 1; y &lt; width-1; y++) for (x = 1; x &lt; height-1; x++) for (z = 0; z &lt; 3; z++) { tmp = mask_product(mask,a,x,y,z); if (tmp...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T18:51:40.723", "Id": "83429", "Score": "0", "body": "The indentation after `tmp = 255;` indicates that you want that if to be wrapped into the other one's body. Is that correct? If so, then you are missing parenthesis. If not, then ...
[ { "body": "<p>I am afraid I can't do much about the performance but here are some other tips:</p>\n\n<ul>\n<li>The <code>z</code> loop bound is not checked against <code>NUM_COLORS</code> (which I believe is the size of the array for this index).</li>\n<li><code>z</code> should be renamed to something like <cod...
{ "AcceptedAnswerId": "47605", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T18:48:36.473", "Id": "47600", "Score": "10", "Tags": [ "optimization", "c", "image" ], "Title": "Detect optimized" }
47600
<p><strong>Warning: the code below is NOT multi read/write!</strong></p> <p>It'l work fine as long as you don't have multiple writes OR don't require resize. But with multiple writers, the code can enter a deadlock state. I'm revising the code and if I do manage to work around these issues, I'll post them in a linked ...
[]
[ { "body": "<p>When you say this queue doesn't support multiple \"writers\", what do you mean? Do you mean multiple producers? Because both pushing (producing) and popping (consuming) from a queue are mutative (\"writing\") operations. And if you don't support the scenario of \"one writer pushing items and one w...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T20:28:17.047", "Id": "47606", "Score": "2", "Tags": [ "c++", "c++11", "lock-free", "atomic" ], "Title": "(nearly) lock-free job queue of dynamic size (multiple read/write)" }
47606
<p>I have this regexp working, simple, but I feel like it may not be the best way to code it. Basically, I have a playlist separated by line breaks returned as tcp data like so:</p> <pre><code>file: http://192.168.100.214/Music/justchill.mp3 Artist: Brian G Title: Just Chill Track: 1 Date: 2014 Genre: Instrumental Pos...
[]
[ { "body": "<p>You can use the <code>String.prototype.replace</code> function to \"loop\" through all the relevant lines of the data. It accepts a regex pattern, and a function to handle the the matched text and return the replacement text. Here, however, we don't care about actually replacing anything; we just ...
{ "AcceptedAnswerId": "47608", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T20:38:46.553", "Id": "47607", "Score": "2", "Tags": [ "javascript", "parsing", "regex" ], "Title": "Parsing playlists efficiently" }
47607
<p>Here is my two-player Tic Tac Toe game. How can I improve it? </p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; //Simple Display void Display(std::vector&lt;char&gt; const &amp;grid){ //Creating a onscreen grid std::cout &lt;&lt; " " &lt;&lt; 1 &lt;&lt; " " &lt;&lt; 2 &lt;&lt; " " &lt;&l...
[]
[ { "body": "<p>I'll just review what you have here, although something like this would work better with classes (you could always attempt this implementation later).</p>\n\n<ul>\n<li><p>Your vector isn't quite grid-like as it's only one-dimensional. It may also be why <code>Display()</code> is a bit confusing, ...
{ "AcceptedAnswerId": "47670", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T21:08:40.480", "Id": "47609", "Score": "6", "Tags": [ "c++", "game", "c++11", "tic-tac-toe" ], "Title": "Tic Tac Toe in C++" }
47609
<p>This is the function which I wrote and am currently using in my project. I want to know if there is a better way to write it:</p> <pre><code>function pageLoader(pageIndex){ $(".ServicesSectionWrapper,.ServicesSectionWrapper .Selector,.ServicesSection,.JournalSectionWrapper,.JournalSectionWrapper .Sele...
[]
[ { "body": "<ol>\n<li>Dont put so much <code>}}}}</code> it just looks bad and you will not know if everything is ok.</li>\n<li><p>I'm wrong or just a</p>\n\n<pre><code>$(\".AboutSectionWrapper, #AboutWrapper, #ManagerWrapper, #DeveloperWrapper, #DesignerWrapper, .AboutSection\").fadeIn(400, function()\n ...
{ "AcceptedAnswerId": "47619", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T22:38:11.320", "Id": "47615", "Score": "4", "Tags": [ "javascript", "jquery" ], "Title": "Page loader function" }
47615
<p>I just finished writing a basic binary conversion class in Ruby. I'm curious to see if anyone has suggestions for improvements. In particular, I'm looking for the cleanest, shortest, most succinct code possible, while staying away from hacky shortcut stuff.</p> <p>In creating this I wanted to use a minimum of funct...
[]
[ { "body": "<ol>\n<li><p>The name <code>Converter</code> is pretty ambiguous. It could mean anything.</p></li>\n<li><p>I'd suggest doing less work in the initializer, and more lazy evaluation.</p></li>\n<li><p>Skip that <code>self</code> line in the initializer - it's an initializer; it'll always return <code>se...
{ "AcceptedAnswerId": "47625", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T00:32:27.297", "Id": "47622", "Score": "7", "Tags": [ "ruby", "converting", "rspec" ], "Title": "Binary converter and sufficient tests" }
47622
<p>I want to make sure that the code is correct in terms of its design, code correctness, best practices &amp; Junit testing.</p> <p>The complete description is given below: </p> <p>Functioning of the app quickly estimates the Final Cost depending on different markups. The following are the markups:</p> <ul> <li>Fla...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T07:10:25.827", "Id": "84263", "Score": "3", "body": "Do not try to document the standard library in comments, as IDEs already conveniently provides that documentation, and there is the Internet for the rest. Just explain what cannot...
[ { "body": "<p>I scanned through your code and also stepped through it with a debugger, line-by-line. The more I looked, the more things I found that I wanted to point out.</p>\n\n<hr>\n\n<p>Let's start by looking at some unnecessary comments:</p>\n\n<pre><code>// BASE PRICE\nprivate static String BASE_PRICE = \...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T00:34:20.897", "Id": "47623", "Score": "10", "Tags": [ "java", "design-patterns", "unit-testing", "mvc", "console" ], "Title": "Markup calculator application using MVC" }
47623
<p>I have a project (<a href="http://corylutton.com/ldaplib.html" rel="nofollow">ldaplib</a>) I am working on that needs to do ASN1-BER decoding and encoding. The function I have for the decoding portion is slightly more complex but neither are all that complicated. I would like to get some feedback on the overall ap...
[]
[ { "body": "<p>Some ideas:</p>\n\n<h2>String concatenation</h2>\n\n<p>The method you're using for string concatenation (successively using the <code>+=</code> operator) is <a href=\"http://www.skymind.com/~ocrow/python_string/\" rel=\"nofollow\">the slowest method</a> in Python for constructing strings. Conside...
{ "AcceptedAnswerId": "47677", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T01:45:51.100", "Id": "47626", "Score": "5", "Tags": [ "python", "python-3.x", "serialization", "ldap" ], "Title": "ASN.1 BER Encoding and Decoding" }
47626
<p>I have this implementation of the split algorithm that different from <code>.split()</code> method you can use with multiple delimiters. Is this a good way of implementing it (more performance)?</p> <pre><code>def split(str, delim=" "): index = 0 string = "" array = [] while index &lt; len(str): ...
[]
[ { "body": "<p>There's no need to iterate using that <code>while</code>, a <code>for</code> is good enough.</p>\n\n<p>Also string concatenation (<code>+=</code>) is expensive. It's better to use a list and join its elements at the end<sup>1</sup>.</p>\n\n<pre><code>def split(s, delim=\" \"):\n words = []\n ...
{ "AcceptedAnswerId": "47628", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T02:33:46.017", "Id": "47627", "Score": "9", "Tags": [ "python", "strings" ], "Title": "Function to split strings on multiple delimiters" }
47627
<p>TL;DR: The Bash script converts a published, somewhat-structured text file into a format usable by my testing infrastructure. It's slow, I think it's ugly -- although it is fully functional.</p> <hr> <p>The NIST provides <a href="http://csrc.nist.gov/groups/STM/cavp/documents/mac/gcmtestvectors.zip" rel="nofollow"...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T05:48:35.340", "Id": "83492", "Score": "0", "body": "I am not sure I understand what the _incredibly slow_ `sed` invocation is supposed to do. When `FAIL\\n$` is encountered, insert an `md FAIL 0` after it, did I get it right? A mor...
[ { "body": "<p>Rewriting it in AWK would definitely result in a huge improvement, enough to say that writing it in Bash was a poor choice. Many of the considerations for this problem favour AWK:</p>\n\n<ul>\n<li>The input is line-oriented.</li>\n<li>Nearly every line has the same <code>key = value</code> format...
{ "AcceptedAnswerId": "47641", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T04:21:59.633", "Id": "47631", "Score": "6", "Tags": [ "performance", "bash", "converting", "sed" ], "Title": "Bash script to convert NIST vectors to debug scripts" }
47631
<p>I've wanted to make a Pong game for awhile, so I eventually got around to it now, it didn't take that long except for the reflections which I unfortunately didn't end up being satisfied with. I wanted to implement a more elegant solution utilizing trigonometry to calculate ball curvature upon impact, but alas it was...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T20:19:27.440", "Id": "83562", "Score": "1", "body": "For an extra challenge think about how you can pull all your pong code out into a seperate library and then have another type of GUI (such as WPF, or Silverlight, or ASP)." }, ...
[ { "body": "<p><strong>IGameView.cs</strong></p>\n\n<p>You have a method called Release with the comments of Release as Releases all the resources allocated by this IGameView. This is the purpose of the interface IDisposable in the System namespace. I would recommend changing to that instead of Release.</p>\n\n...
{ "AcceptedAnswerId": "47675", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-19T08:27:49.543", "Id": "47635", "Score": "2", "Tags": [ "c#", "object-oriented", "game", "multithreading", "collision" ], "Title": "Pong Game in WinForms" }
47635