body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I have a web page with a set of icons that are grey by default:</p> <p><img src="https://i.stack.imgur.com/WrlEu.png" alt="enter image description here" /></p> <p>If a user clicks one, it toggles green (<code>.toggleClass('green')</code>):</p> <p><img src="https://i.stack.imgur.com/0pxOp.png" alt="enter image descri...
[]
[ { "body": "<p>I usually don't review CoffeeScript, because I find it too hard too read. Your code is not too hard to read, so I will give it a shot.</p>\n\n<p>I think in essence, you are trying too hard to show all but the one section, I would simply had all sections, and then show the one section you need. I w...
{ "AcceptedAnswerId": "46267", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T12:18:09.747", "Id": "46262", "Score": "7", "Tags": [ "coffeescript" ], "Title": "Avoiding nested conditionals and comparing strings" }
46262
<p><a href="http://learnyouahaskell.com/" rel="nofollow">Learn You a Haskell</a> gives this <a href="http://learnyouahaskell.com/starting-out#im-a-list-comprehension" rel="nofollow">exercise</a>:</p> <blockquote> <p>Here's a problem that combines tuples and list comprehensions: which right triangle that has intege...
[]
[ { "body": "<p>There is no need for <code>List</code>s <code>a</code>,<code>b</code>, and <code>c</code>, only one of them is needed.</p>\n\n<p>So the flatmap could just use <code>a</code> three times: </p>\n\n<pre><code>a.flatMap(x =&gt; \n a.flatMap(y =&gt; \n a.flatMap(z =&gt; sumsEqualsTo24(x, y, z))))\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T13:36:52.177", "Id": "46270", "Score": "2", "Tags": [ "scala" ], "Title": "Find Pythagorean Triple with Perimeter == 24" }
46270
<p>I have written a numbers to text challenge for some people in my organisation to practice their Python skills. I am an economist working with pandas, but I am trying to teach them some stuff about general programming as well. I am not a trained computer scientist or anything, so what I know is just what I have picke...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T13:56:26.877", "Id": "80769", "Score": "0", "body": "The amount of documentation in your code is impressive. I have no time to have a look right now but a pretty similar question was asked recently, maybe you'll find something relev...
[ { "body": "<p>I will review a single function the <code>get_number()</code>.</p>\n\n<ol>\n<li><p>From what I have seen in your code there is completely no benefit of passing messages as variables <code>message1</code> and <code>message2</code>. It is easer to read code which looks like this:</p>\n\n<pre><code>u...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T13:42:27.717", "Id": "46273", "Score": "5", "Tags": [ "python", "strings", "python-2.x", "numbers-to-words" ], "Title": "Numbers to Text Program - Python Training" }
46273
<p>I want to create a small web widget, you can see it at this <a href="http://jsfiddle.net/easilyBaffled/ta8YR/1/" rel="nofollow noreferrer">jsfiddle</a>. Right now it is organized by placing lists within lists and content within those lists. All of this is supposed to sit, as a bar, fixed to the bottom of your window...
[]
[ { "body": "<p><a href=\"http://html5doctor.com/\" rel=\"nofollow\">Here's how HTML5Doctor describes <code>&lt;ul&gt;</code> and <code>&lt;li&gt;</code></a>:</p>\n\n<blockquote>\n <h2>ul</h2>\n \n <p>The ul element represents a list of items, where the order of the\n items is not important — that is, where c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T14:04:07.447", "Id": "46275", "Score": "4", "Tags": [ "html", "css", "layout" ], "Title": "Am I over using <ul> for layout?" }
46275
<p>I have to deal with a really ugly looking response I get back from a particular device. The string represents a table. Each section of the string represents the form:</p> <pre><code>["id", "date_time", "path", "type","duration","count", "rate"] </code></pre> <p>Which as an example looks like:</p> <pre><code>"1,20...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T15:07:53.360", "Id": "80791", "Score": "0", "body": "Can you add information about how this function is supposed to be used? At the moment, this is just the definition of a function taking no parameter and calling a `SendRecieve` fu...
[ { "body": "<p><strong>Disclaimer</strong> </p>\n\n<p>Because a lot of context is missing, here's the code I will review :</p>\n\n<pre><code>def split_entry(entry):\n splitentry = entry.split(',')\n for ii in range(len(splitentry))[::-1]:\n start_bracket = splitentry[ii].count('[')\n end_brac...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T14:43:49.147", "Id": "46279", "Score": "0", "Tags": [ "python", "strings", "python-2.x", "formatting" ], "Title": "Dealing with a dirty table" }
46279
<p>I want to include about 10 jQuery plugins in a project but do so in a better way than just pasting them into a JS file.</p> <p>I want to capture various device data and other data passed from the server-side (in a HTML meta tag) and I want some of this to decide which jQuery scripts to run - or none in the case of ...
[]
[ { "body": "<p>On the whole, I think you need to work on <a href=\"http://en.wikipedia.org/wiki/KISS_principle\" rel=\"nofollow\">keeping it simple</a>.</p>\n\n<ul>\n<li><p>I would not write my own cross-browser event handling function if I use jQuery, I would leverage <a href=\"http://api.jquery.com/category/ev...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T15:03:57.433", "Id": "46281", "Score": "3", "Tags": [ "javascript", "jquery", "object-oriented", "cross-browser" ], "Title": "Re-writing rough JS code with loads of jQuery plu...
46281
<p><code>Schedule</code> is a simple class that could be used in program to manage when a task should be repeated (a todo list, for example). Its constructor requires a start date and an optional end date, then type of repetition (daily, weekly or monthly) has to be set. If weekly is chosen, then the days of weeks when...
[]
[ { "body": "<p>I would strongly reccomend that you use the <a href=\"http://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html\"><code>java.time</code></a> package instead of the <code>java.util</code> classes, if that is at all possible.</p>\n\n<hr>\n\n<p>One thing you could improve involves the i...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T15:06:50.193", "Id": "46282", "Score": "10", "Tags": [ "java", "unit-testing", "datetime", "scheduled-tasks" ], "Title": "Schedule class (exercise for test driven development)...
46282
<p>I have started using BEM syntax for my HTML and CSS. I got the idea from Harry Roberts' blog post <a href="http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/" rel="nofollow">"MindBEMding – getting your head 'round BEM syntax"</a>.</p> <p>Please note I am not looking to use this for HTML ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T16:15:45.770", "Id": "80803", "Score": "0", "body": "Where is the CSS? is this Live code?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T16:30:55.240", "Id": "80808", "Score": "1", "body...
[ { "body": "<p>Something minor that irritates me and may or may not irritate others, is your lack of newlines inside your <code>p</code> tags. Within these tags you can multi line and it won't be translated to your browser output.</p>\n\n<pre><code>&lt;p&gt;\n Lorem ipsum dolor sit amet, consectetur adipisic...
{ "AcceptedAnswerId": "46318", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T15:37:46.207", "Id": "46287", "Score": "7", "Tags": [ "html", "css", "email", "bem" ], "Title": "BEM email structure" }
46287
<p>I'm hoping to get some feedback on how to improve and optimise a program I wrote which takes three values as input (via the terminal) and uses them in the <a href="http://www.purplemath.com/modules/quadform.htm">quadratic formula</a>.</p> <p>I'm aware this is mostly micro-optimisation, but any advice whatsoever wou...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T06:51:18.427", "Id": "81123", "Score": "0", "body": "There is also a [follow-up question](http://codereview.stackexchange.com/q/46322/9357)." } ]
[ { "body": "<p>A few things jump me here:</p>\n\n<h3>1. Class Names</h3>\n\n<p>Your class name is queer. The Java standard is to use <code>PascalCasing</code> for class names. You use <code>Pascal_Snake_Case</code>. That's kinda funny ;) Also you named your class after what it contains somewhere deep down, and n...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T16:32:28.010", "Id": "46293", "Score": "13", "Tags": [ "java", "beginner", "mathematics" ], "Title": "Quadratic expression calculator" }
46293
<p>I'm upgrading my project from YouTube's V2 API to their V3 API. I'm also taking the time to upgrade to Jasmine 2.0 since I already need to look at my test cases.</p> <p>Here's a couple of test cases and the corresponding code. Am I doing 'it' correctly? Maybe I should have a spy?</p> <pre><code>define([ 'comm...
[]
[ { "body": "<p>This looks okay to me, the only thing I will comment on is this:</p>\n\n<pre><code> if (response.error) {\n if (options.error) {\n options.error({\n error: response.error\n });\n }\n\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T16:56:31.640", "Id": "46297", "Score": "4", "Tags": [ "javascript", "unit-testing", "youtube", "jasmine" ], "Title": "Testing async YouTube API calls using Jasmine 2.0" }
46297
<p>I have an XML document that contains "ads" and includes information about the department name, image name, link to URL, and alt text. I have a PHP function that accepts two arguments, department name and the number of "ads" to display. It reads through the entire XML document, and stores the information in arrays ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T17:39:27.393", "Id": "80825", "Score": "0", "body": "Is using XML a requirement?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T17:45:29.687", "Id": "80826", "Score": "0", "body": "I woul...
[ { "body": "<p>If you can use any format, use serialized PHP, it's by far the fastest.</p>\n\n<pre><code>&lt;?php\n\nclass Ad {\n\n public $alt;\n\n public $departmentName;\n\n public $linkTo;\n\n public $name;\n\n}\n\nfunction formatAd(Ad $ad) {\n return \"&lt;div class='adRight'&gt;&lt;a href='{$ad-&gt;li...
{ "AcceptedAnswerId": "56114", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T17:34:15.560", "Id": "46302", "Score": "3", "Tags": [ "php", "performance", "random", "xml" ], "Title": "Displaying random \"ads\" from an XML document" }
46302
<p>I needed a variadic function to pack and unpack bits into integer types. This is my first attempt:</p> <pre><code>template&lt;typename T&gt; constexpr T pack(bool b) { return b; } template&lt;typename T, typename... Types&gt; constexpr T pack(bool b, Types... args) { return (b &lt;&lt; sizeof...(Types)) | ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T17:50:20.297", "Id": "80829", "Score": "0", "body": "Two minor things I see: 1.) Replace each `std::endl` with `\"\\n\"` 2.) In C++, `main()` doesn't need a `void` parameter." }, { "ContentLicense": "CC BY-SA 3.0", "Crea...
[ { "body": "<h2>Missing overflow check</h2>\n\n<p>One serious flaw that I see in this code is that the user needs to determine the number of parameters to <code>unpack</code>. This is a no go for a function whose output depends on a runtime input. Even worse there is no check that would tell the user that the ac...
{ "AcceptedAnswerId": "46304", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T17:42:05.913", "Id": "46303", "Score": "6", "Tags": [ "c++", "c++11", "bitwise", "variadic" ], "Title": "Bit packing and unpacking" }
46303
<p>I have two <code>ModelForm</code>s that are the same, except that one of them has its form layout built in a view and one has a <kbd>submit</kbd> button. These are pretty long and I have a ton of duplicate code. I have tried subclassing, but I don't understand it well enough to make it work right. I end up unable to...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T17:16:25.803", "Id": "81061", "Score": "1", "body": "Can you please wrap your code at 80 columns as per PEP8? It's hard to read at the moment with all the scrolling." } ]
[ { "body": "<p>Here's an approach. </p>\n\n<p>Start out by defining a empty class, say, FormTemplate that inherits from forms.ModelForm and let both SurveyForm and UpdateSurveyForm inherit from FormTemplate. Make sure that works. I guess FormTemplate will need an <code>__init__()</code> that forwards <code>super...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T17:57:44.913", "Id": "46305", "Score": "8", "Tags": [ "python", "form", "django" ], "Title": "How to DRY up my forms.py?" }
46305
<p>Jasmine is a behavior-driven development framework for testing JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM. And it has a clean, obvious syntax so that you can easily write tests. </p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T18:27:09.350", "Id": "46308", "Score": "0", "Tags": null, "Title": null }
46308
<p>I'm writing a simple Pong game. I have a method <code>bounce()</code> that makes everything run: the ball, the paddles, score etc. and it uses 12 arguments: 3 counters, 2 paddles, ball, 5 textures, 1 color. I'm a beginner to programming and only have couple months college experience so I don't know if that's too muc...
[]
[ { "body": "<p>Glad to see you made it here.</p>\n\n<p>There is no predefined number of \"<em>this many arguments and no further</em>\" so it is a subjective decision. In my experience, I would say that as soon as you see more than 5 arguments you have to be pretty sure that that is a good way to go.</p>\n\n<p>A...
{ "AcceptedAnswerId": "46315", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T18:30:58.480", "Id": "46310", "Score": "11", "Tags": [ "java", "game", "animation" ], "Title": "Simple Pong game" }
46310
<p>I have put together a small wrapper class to simplify creating parameterized ADODB queries with VB6/VBA. At this point I'm keeping things simple, so it's only supporting <em>input parameters</em> and from what I've tested it seems to work exactly as intended.</p> <p>The main reason for writing this, is because creat...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-03-02T17:44:09.713", "Id": "149233", "Score": "0", "body": "There is already a way to create parameterized queries in ADO.NET: http://support.microsoft.com/kb/200190" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "201...
[ { "body": "<p>This seems extra complexity with no purpose.</p>\n\n<p>You take any type variable and automatically convert it to a parameter (this is good).</p>\n\n<p>But then something strange happens, you look at the type of the variable and convert that to a string so you can call a function named after the t...
{ "AcceptedAnswerId": "46346", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-04-04T18:44:11.750", "Id": "46312", "Score": "32", "Tags": [ "sql-server", "vba", "sql-injection", "vb6", "adodb" ], "Title": "Creating ADODB Parameters on the fly" }
46312
<p>I'm not a JavaScript programmer. I have next to no idea about "what's out there" of libraries and so on. Therefore it's not unlikely that the referred to Windows HTML Application (HTA) code here, which is a mix of HTML5, CSS3 and JScript 5.6, may be incompatible with such libraries, common naming conventions, whatev...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T19:21:17.173", "Id": "80871", "Score": "0", "body": "Have you considered jsbin.com, or jsfiddle.net, or plnkr.co instead of writing your own environment?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-0...
[ { "body": "<p>A few things immediately caught my eye:</p>\n\n<ul>\n<li><p>You're using a weird construct: <code>new function() {}</code>. The <code>function(){}</code> expression already creates a new function, but in addition to that you're using it with <code>new</code> to invoke it as a constructor for new o...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T18:47:18.257", "Id": "46313", "Score": "1", "Tags": [ "javascript", "beginner", "css", "html5", "windows" ], "Title": "What are practical issues using this code with commo...
46313
<p>I have a bunch of functions that return strings based upon score ranges. Then I have another function that sums everything up and assigns a numeric weight.</p> <pre><code>@property def risk_status(self): """ This function assigns numeric weight to risks. It returns an over all integer score. """ # Build a ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T20:48:41.393", "Id": "80905", "Score": "1", "body": "I don't know if it will speed things up a lot, but instead of building your raw_string_of_risks and then breaking it into a list, why don't you just create the list ... `risks = [...
[ { "body": "<p>Concatenating an splitting seems like you're making extra work for yourself. I suggest summing the results of a string-to-integer translation.</p>\n\n<pre><code>from collections import defaultdict\n\n_RISK_SCORE = defaultdict(int, [('Extreme Risk', 3), ('High Risk', 2), ('At Risk', 1)])\n\n@prope...
{ "AcceptedAnswerId": "46358", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T18:48:40.660", "Id": "46314", "Score": "4", "Tags": [ "python", "performance", "django" ], "Title": "Code efficiency with many records" }
46314
<p>I have <code>Article</code> and <code>Category</code>, with a <code>has_and_belongs_to_many</code> relation between the two.</p> <p>I want to use <code>Article.in_categories(category_ids)</code> to get any <code>Article</code> that is in any of the <code>category_ids</code> passed, and I want to handle the possibil...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T19:28:46.983", "Id": "81071", "Score": "1", "body": "Not quite an answer, so I'll comment instead: I'd suggest handling possible `nil` values elsewhere, and simply not call `in_categories` unless you have some IDs and it makes sense...
[ { "body": "<p>Generally you'll want to make sure this always gets passed an array so I'd choose to set the argument to an empty array rather than nil. Since in the successful case the method receives an array, you should treat it as such. If you ever expect to get a nil passed in (like you might from params), y...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T19:57:29.127", "Id": "46319", "Score": "2", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Searching has_and_belongs_to_many relations for article categories" }
46319
<h2>Problem Statement</h2> <blockquote> <p>Given \$n\$ digits and \$m\$ indices \$x\$ from \$1. \ldots,n\$, calculate the difference \$b_y = a_x - a_y\$ for all indices \$y \; (y &lt; x)\$. Then, calculate \$B1\$, the sum of all \$b_y\$ which are greater than \$0\$ and \$B2\$, the sum of all \$b_y\$ which ar...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T20:40:56.473", "Id": "80904", "Score": "0", "body": "Don't know if it will speed it up much, but put the int(stra[curr]) before the inner for loop." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-08-27T10:1...
[ { "body": "<p>A better algorithm usually wins over micro-optimizations.</p>\n\n<ul>\n<li><p>Do you really need to do all these calculations every time? Maybe you could cache them and re-use the results.</p></li>\n<li><p>You could perform all the string to int conversions up front, afterwards only looking up num...
{ "AcceptedAnswerId": "46781", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T20:10:25.147", "Id": "46320", "Score": "10", "Tags": [ "python", "optimization", "performance", "programming-challenge" ], "Title": "How can I make my solution for Chef and...
46320
<p>After taking some great advice on <a href="https://codereview.stackexchange.com/questions/46293/quadratic-expression-calculator">this question</a>, I'm hoping for some more feedback on my quadratic expression calculator.</p> <p>This is my code as stands:</p> <pre><code>public class Quadratic_Equations { priva...
[]
[ { "body": "<p>The static Scanner is a problem, a better way to do it is with the Java try-with-resources. If you add the scanner as an input parameter to the prompt function, you can do:</p>\n\n<p>Change your prompt method from:</p>\n\n<blockquote>\n<pre><code>private static double promptUserUntilValidInput(Str...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T20:32:46.803", "Id": "46322", "Score": "8", "Tags": [ "java", "beginner" ], "Title": "Quadratic Expression Calculator 2" }
46322
<p>Today, my project was to make a matrix in my web browser. It is really slow, so help with optimizing it would be nice. It runs slow on my PC, yet alone my iPod 4 which this is going to be for.</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Matrix&lt;/title&gt; &lt;style type="text/css"&gt; bo...
[]
[ { "body": "<p><a href=\"http://jsfiddle.net/xy2EN/6/\">Here's what I did</a></p>\n\n<pre><code>var theMatrix = (function (containerId, lines, columns) {\n // We wrap everything in a closure, and expose only a single\n // global. Avoids global pollution, and keeps everything in\n // one place.\n\n va...
{ "AcceptedAnswerId": "46336", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T22:13:30.997", "Id": "46327", "Score": "5", "Tags": [ "javascript", "html", "css", "matrix" ], "Title": "Dynamic matrix in web browser" }
46327
<p>I know there is a better way to store data. What is the most concise way to simplify this script?</p> <pre><code>from random import randint from sys import exit import os os.system('clear') print "Welcome to the dice rolling simulator!" raw_input("Press enter to begin.") total = 0 completed = [0, 0, 0, 0, 0, 0,...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-05-12T17:56:14.063", "Id": "239759", "Score": "0", "body": "I tried all the above codes but it shows invalid syntax T.T" } ]
[ { "body": "<p>So, first, it's all a bit confusing when the indentation is messed up (which is important in Python). You should first get that in order.</p>\n\n<p>Also globals are usually a bad idea, and they're not necessary here. It also appears that, even properly executed, you've built this program as an inf...
{ "AcceptedAnswerId": "46333", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T22:16:52.003", "Id": "46328", "Score": "11", "Tags": [ "python", "python-2.x", "random", "simulation", "dice" ], "Title": "Dice-rolling simulator" }
46328
<p>Please be brutal, and let me know how I've done on this problem, provided I coded it at an interview for a top tech firm.</p> <p><strong>Time it took me:</strong> 44 minutes</p> <p><strong>Worst case time complexity:</strong> O(n<sup>2</sup>)? Am I right?</p> <p><strong>Space Complexity:</strong> O(n)?</p> <p><...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T22:49:44.607", "Id": "80921", "Score": "1", "body": "From where do you get these problems? :)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T22:54:27.467", "Id": "80922", "Score": "0", "b...
[ { "body": "<ol>\n<li><p>Split it up! The current method does more than one thing, I'd create at least three helper methods:</p>\n\n<pre><code>int[][] parseInput(String[] input);\nint getMaxOfMinHeightInColumns(int[][] peoples);\nint getMinOfMaxHeightInRows(int[][] peoples);\n</code></pre>\n\n<p>It would be eas...
{ "AcceptedAnswerId": "46337", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T22:25:19.517", "Id": "46329", "Score": "9", "Tags": [ "java", "algorithm", "interview-questions" ], "Title": "Sorting and searching problem related to a group of people standin...
46329
<p>I have the following C++ interface (in Qt) for a tree node, inspired somewhat by Valve's implementation of a culling octree:</p> <pre><code>/** * @brief Interface for a recursive tree node. */ class ITreeNode { public: /** * @brief Virtual destructor. */ virtual ~ITreeNode() {} /** * @...
[]
[ { "body": "<blockquote>\n <p>Is this interface complete? Does it attempt to do too much or too little?</p>\n</blockquote>\n\n<p>In my opinion, interfaces should be as small as possible, providing only methods that are really required to be called without knowing (or casting to) the actual subclass. I don't kno...
{ "AcceptedAnswerId": "51543", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T23:06:12.277", "Id": "46334", "Score": "5", "Tags": [ "c++", "tree", "interface", "qt" ], "Title": "Interface for a tree node in Qt" }
46334
<p>I'm trying to get a certain number of date ranges given a start date. Here's my code:</p> <pre><code>var startDate = new DateTime(2014, 1, 1); var dates = new List&lt;DateBlock&gt;(); int counter = 0; while(counter &lt; 6) { if (startDate &gt;= DateTime.UtcNow) { dates.Add(new DateBlock { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T14:22:53.320", "Id": "81026", "Score": "0", "body": "So it should only start adding date ranges when the start date is in the future?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T14:33:17.237", ...
[ { "body": "<p>The loop to find the starting date is clearly not needed. This can be done with library object TimeSpan -- like this:</p>\n\n<pre><code>void Main()\n{\n var startDate = new DateTime(2014, 1, 1);\n var dates = new List&lt;DateBlock&gt;();\n\n int priorPeriods = ((DateTime.UtcNow-startDate).Days...
{ "AcceptedAnswerId": "46374", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T02:02:35.303", "Id": "46343", "Score": "5", "Tags": [ "c#", "datetime" ], "Title": "Date ranges from a given start date" }
46343
<p>I want my socket class to be reviewed, including recommendations and optimizations.</p> <p>Sokect.hpp</p> <pre><code> class Socket { protected: Socket(SOCKET s); Socket(); SOCKET s_; sockaddr_in sa_; int* count_; private: static void StartSocket(); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T03:52:21.350", "Id": "80960", "Score": "0", "body": "you can see those post and get some recommendations http://codereview.stackexchange.com/questions/43369/socket-wrapper-class\r\nhttp://codereview.stackexchange.com/questions/4344...
[ { "body": "<p>I think you have too many different responsibilities bound up into one class. That ends up not only making that class more complex, but adding extra complexity overall as well. As a starting point, I'd have a really trivial class that does nothing but stack-based management of the WSAStartup/WSACl...
{ "AcceptedAnswerId": "46354", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T03:43:24.940", "Id": "46350", "Score": "14", "Tags": [ "c++", "windows", "socket" ], "Title": "First socket class" }
46350
<p>I find myself using a lot of <code>.find</code> functions within what I'm developing. The reason being that I need to run this same function on a TON of different characters eventually, and the easiest way I could find to do this was make appropriate sections <code>classes</code> and wrap each character in their res...
[]
[ { "body": "<p>The most immediate problems:</p>\n\n<ul>\n<li><p>Use better variable names than <code>x</code> and <code>y</code>. It's almost unreadable this way. If one of them is the player data object and the other one a jQuery DOM object, why not name them <code>player</code> and <code>dom</code> respectivel...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T04:29:05.060", "Id": "46352", "Score": "4", "Tags": [ "javascript", "jquery", "html", "classes", "dom" ], "Title": "New Game - Am I going down the right path for DOM manip...
46352
<p>I am using Unity3D and I made a super simply pooling system to reuse a specific object. My only concern is I am not sure if I am doing it the best possible way. If I were doing this in C++ there would be a bunch of pointers and be passing pointers to the objects.</p> <p>Now in C# I understand many things are hidden...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T11:25:14.130", "Id": "84278", "Score": "0", "body": "Off topic and entirely optional, but I recommend using Microsoft's C# coding style guidelines for ease of reading for both yourself and other programmers: http://msdn.microsoft.co...
[ { "body": "<p>Classes, such as your <code>GameObject</code> are passed by reference (i.e. as a pointer) by default. No duplication happens and you do not need a keyword for that. C# handles it all for you.</p>\n\n<p>Structs and primitive types such as <code>Vector3</code> or <code>int</code> are value types whi...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T04:30:03.673", "Id": "46353", "Score": "3", "Tags": [ "c#", "unity3d" ], "Title": "Pooling System: is it worth improving or not for a simple implementation?" }
46353
<p>When the app is run on an iPhone or simulator, tapping the screen spawns a dog class and displays an image of the dog.</p> <p>I'd like comments, issues, whatever. Is this a decent first Objective-C project, and can others learn from it?</p> <p>The code is meant to demonstrate Objective-C, Cocoa and UIKit.</p> <p>...
[]
[ { "body": "<p>Because this question is so, so large, I won't get into all the specifics of everything I see. I will point out some things, and provide some examples from one file or another, and as you work through my answer, you should work through your project to find all the other instances of an example I ...
{ "AcceptedAnswerId": "46454", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T05:51:26.463", "Id": "46357", "Score": "5", "Tags": [ "objective-c", "ios", "cocoa" ], "Title": "Spawning a Dog class" }
46357
<p>I'm new to C, and as an exercise I'm building 4 different factorial algorithm implementations and measuring their running time. I'm looking for this feedback, especially:</p> <ul> <li><p>The implementation of the factorial algorithms. Can the they be improved? Is there something you would do different? Is something...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T17:11:05.473", "Id": "81059", "Score": "1", "body": "Just use a library, like [GMP's](https://gmplib.org/manual/) [mpz_fac_ui()](https://gmplib.org/manual/Number-Theoretic-Functions.html#Number-Theoretic-Functions)" } ]
[ { "body": "<p>I find it odd that the input to the factorial functions is a <code>double</code> rather than an <code>int</code>. There's no need to consider non-integral values of <code>n</code>, nor is there a need to allow large <code>n</code>. In fact, <em>n</em>! will start losing precision at around <em>n...
{ "AcceptedAnswerId": "46368", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T10:11:22.387", "Id": "46361", "Score": "4", "Tags": [ "c", "algorithm", "performance", "beginner", "console" ], "Title": "Different factorial algorithm implementations ...
46361
<p>I am trying to make a linked list using 3 classes, however I cannot find ANY information online about it, and I can't seem to figure it out myself.</p> <p>If you could please correct and explain what I am doing wrong, I would greatly appreciate it.</p> <p><strong>LinkTest.h:</strong></p> <pre><code>#include &lt;s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T10:50:49.040", "Id": "80993", "Score": "0", "body": "Linked Lists are not normally classified by how many classes they have. What made you classify it that way?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "20...
[ { "body": "<p>At first glance, your code appears to work, but there is some confusion going on. I'll highlight what I consider to be the four top issues instead of making an exhaustive list.</p>\n\n<ol>\n<li>The <code>Test::get()</code> method is actually a setter, not a getter, and should be named <code>Test:...
{ "AcceptedAnswerId": "46366", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T10:19:08.310", "Id": "46362", "Score": "4", "Tags": [ "c++", "linked-list" ], "Title": "3-class linked list" }
46362
<p>This post is a follow-up to <a href="https://codereview.stackexchange.com/questions/46310/when-should-i-consider-the-number-of-my-method-arguments-too-big">Simple Pong game</a></p> <p>I took the some advice from the previous post and I'm almost done with cleaning up the code. I didn't make any wrapper classes, beca...
[]
[ { "body": "<p>I don't know Java, but I can tell you that in the first /* ... <em>/ section, both if statements are the same.\nAlso, in the second /</em> ... */ section, rather than having 2 if's, just say</p>\n\n<pre><code>if((firstifcondition) OR (secondifcondition))\n{\n ...\n}\n</code></pre>\n", "co...
{ "AcceptedAnswerId": "46369", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T10:54:53.313", "Id": "46363", "Score": "7", "Tags": [ "java", "game", "classes", "animation" ], "Title": "Cleaning up and commenting on my code for Pong game" }
46363
<p>How can I make this matrix effect more like the matrix movie?</p> <pre><code>#include&lt;stdlib.h&gt; #include&lt;stdio.h&gt; int main() { srand((unsigned) time(0)); int i,j; system("color 0a"); while(1) { i = rand() % 2; j= rand() % 2; if(j) { printf("%d ", i); } else { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T15:18:55.373", "Id": "81037", "Score": "0", "body": "How is it not like the movie... what are you trying to do?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T16:53:36.023", "Id": "81055", "S...
[ { "body": "<p>If you are talking optimization (not sure you are) then one clear change is to remove printf -- printf is very slow. You are only displaying <code>0</code>, <code>1</code>, and <code></code>.</p>\n\n<p>putc is much faster -- it does not have to parse for formatting. If you change the code to use...
{ "AcceptedAnswerId": "46382", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T13:23:26.930", "Id": "46370", "Score": "4", "Tags": [ "optimization", "c" ], "Title": "Matrix falling effect" }
46370
<p>Recently I built a map with custom markers (pins) and a sorting function to display each by type (Member, Supplier, Prospect, New Member). </p> <p>The HTML (check boxes wired up with <code>sort()</code> function): </p> <pre><code>&lt;input type="checkbox" value="Supplier" onclick="sort()" id="switch2" /&gt; ...
[]
[ { "body": "<p>Let's be frank - this code is a mess.</p>\n\n<ul>\n<li><p>A bunch of global variables and functions. That's never good. You should at least wrap these inside a container function. Or better - turn it into an object.</p></li>\n<li><p>In the middle of the function definitions there's suddenly call ...
{ "AcceptedAnswerId": "46376", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T14:04:32.530", "Id": "46371", "Score": "3", "Tags": [ "javascript", "html", "sorting", "google-maps" ], "Title": "Google Maps JavaScript API v3: Sorting Markers with Check ...
46371
<p><strong>MonoGame</strong> is an Open Source implementation of the Microsoft XNA 4 Framework. Our goal is to allow XNA developers on Xbox 360, Windows &amp; Windows Phone to port their games to the iOS, Android, Mac OS X, Linux and Windows 8 Metro. PlayStation Mobile, Raspberry PI, and PlayStation 4 platforms are cu...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T14:39:31.640", "Id": "46372", "Score": "0", "Tags": null, "Title": null }
46372
MonoGame is an Open Source implementation of the Microsoft XNA 4 Framework. Our goal is to allow XNA developers on Xbox 360, Windows & Windows Phone to port their games to the iOS, Android, Mac OS X, Linux and Windows 8 Metro. PlayStation Mobile, Raspberry PI, and PlayStation 4 platforms are currently in progress.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T14:39:31.640", "Id": "46373", "Score": "0", "Tags": null, "Title": null }
46373
<p>We are following passive controller approach and when user clicks on submit, server side validations are fired. There are many other fields on the screen that needs to be validated.</p> <p>I would like to get feedback about the following approach.</p> <ol> <li>Is it ok to have validations in Presenter.</li> <li>As...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T16:25:48.630", "Id": "81046", "Score": "1", "body": "please don't make the changes in the code, it invalidates the answers and makes it hard for someone new to the question follow along" }, { "ContentLicense": "CC BY-SA 3.0"...
[ { "body": "<p>I think you have a typo in the last outside if statement, I assume you meant two different variables when you wrote this: </p>\n\n<pre><code>if((!string.IsNullOrWhiteSpace(this.View.FromCustomerId) &amp;&amp; !string.IsNullOrWhiteSpace(this.View.FromCustomerId) &amp;&amp; (isValidFromCustomerId &a...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T15:42:39.913", "Id": "46378", "Score": "4", "Tags": [ "c#", "asp.net", "unit-testing", "mvp" ], "Title": "Server side validations and unit testing in MVP" }
46378
<p>I solved <a href="http://projecteuler.net/problem=1" rel="nofollow">this</a> a while ago. In the moment I solved it I was learning Scheme and, well, I still am. I'm not looking at the best solution (I searched for it and coded it already, in Python), what I want is to improve this code, maintaining the same (brute) ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T16:08:49.223", "Id": "81040", "Score": "1", "body": "Not sure how it happened, but it doesn't look like the code is valid right now. I believe you intended something more like: `(define (sum-multiples lower-limit upper-limit) (sum-m...
[ { "body": "<p>So, any time you want to write a \"helper\" recursive function, the standard way to write that is to use a named <code>let</code>. So here's how I might restructure your program (but keeping the same algorithm):</p>\n\n<pre><code>(define (sum-multiples start end)\n (let loop ((sum 0)\n ...
{ "AcceptedAnswerId": "46386", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T15:45:14.880", "Id": "46379", "Score": "6", "Tags": [ "beginner", "scheme", "programming-challenge", "racket" ], "Title": "Project Euler 1 (sum of multiples of 3 or 5 under...
46379
<p>I am creating a class to be the end all defacto class for handling unit conversions. This is particularly difficult in my company's industry where imperial architectural strings are used as units. I wanted this class to be perfect in just about every way as it is the class that we will be giving our summer interns a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T18:09:04.270", "Id": "81064", "Score": "0", "body": "I think that unit conversions are not what your interns are going to write every day, so I'm not sure it's a good example. For example, how many classes overload arithmetic operat...
[ { "body": "<p>One obvious starting point: replace your code like this:</p>\n\n<pre><code> public static bool operator ==(Dimension d1, Dimension d2)\n {\n //compare the two dimensions for equality\n //return a bool based on their relative values\n if (d1.internalDecimalUnit == d2.inte...
{ "AcceptedAnswerId": "46408", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T17:40:18.700", "Id": "46390", "Score": "12", "Tags": [ "c#", "strings", "converting" ], "Title": "Class for handling unit conversions" }
46390
<p>I feel like there is room for improvement in the push/pop methods. Any suggestions?</p> <pre><code>#include &lt;exception&gt; template &lt;typename T&gt; class List { public: List(); ~List(); void PushBack(const T &amp;data); void PushFront(con...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T17:47:16.247", "Id": "81063", "Score": "3", "body": "Hm, I realised there is no way of iterating through it. I should implement an iterator" } ]
[ { "body": "<ul>\n<li><p>Consider using a different naming convention for your data members and methods, such as camelCase or snake_case. Your user-defined types are already uppercase, which is okay. Whichever you choose, it's more readable to keep them separate.</p></li>\n<li><p>The push/pop methods here impl...
{ "AcceptedAnswerId": "46401", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T17:44:03.727", "Id": "46391", "Score": "6", "Tags": [ "c++", "linked-list", "reinventing-the-wheel" ], "Title": "Singly linked list implementation" }
46391
<p>This is my first PHP script (although I like to think I'm a good general coder). </p> <p>The script accepts a number from the user, uses it to generate a regular expression, and then returns all dictionary words that match that expression. </p> <p>It's currently live <a href="http://www.joereddington.com/major/ma...
[]
[ { "body": "<p>One thing I would do is that <code>str_replace</code> can receive an array of items to look for and an array of its replacement:</p>\n\n<p><a href=\"http://www.php.net/manual/en/function.str-replace.php\" rel=\"nofollow noreferrer\">PHP str_replace</a></p>\n\n<pre><code>// Provides: You should eat...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T18:29:37.623", "Id": "46394", "Score": "3", "Tags": [ "php", "regex" ], "Title": "Generate regular expression based on inputted number" }
46394
<p>Let's say I need to write a function that applies a function to each item in a List, and then appends it to an accumulator. When the List is empty, return the accumulator.</p> <pre><code>go :: [a] -&gt; (a -&gt; [b]) -&gt; [b] -&gt; [b] go [] f acc = acc go (x:xs) f acc = go xs f (acc ++ f x) myFold :: [a] -&gt; (...
[]
[ { "body": "<p>First, your function is <code>concatMap</code> from Prelude.</p>\n\n<p>More idiomatic ways to write it:</p>\n\n<pre><code>myFold :: (a -&gt; [b]) -&gt; [a] -&gt; [b]\nmyFold = concat . map\n-- or\nmyFold f = foldr (\\x acc -&gt; (f x) ++ acc) []\n</code></pre>\n\n<p>If efficiency is a concern, it'...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T18:33:26.747", "Id": "46395", "Score": "2", "Tags": [ "haskell" ], "Title": "Implement a fold-like Function in Haskell" }
46395
<p>Originally asked here: <a href="https://codereview.stackexchange.com/q/45310/507">Dynamically call lambda based on stream input</a></p> <p>The following version is based heavily on the answer provided by <a href="https://codereview.stackexchange.com/a/45334/507">@iavr</a>, though I hope that I have done enough more...
[]
[ { "body": "<p>It is becoming really good, but there are still a few things that can be done:</p>\n\n<ul>\n<li><p>There already is a standard way to \"clean\" a type: <a href=\"http://en.cppreference.com/w/cpp/types/decay\"><code>std::decay</code></a>. It does a little bit more than just removing the reference a...
{ "AcceptedAnswerId": "46448", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T18:37:30.300", "Id": "46397", "Score": "11", "Tags": [ "c++", "c++14", "lambda", "template-meta-programming" ], "Title": "Dynamically call lambda based on stream input: Try...
46397
<p>I just spent almost one day to figure out the following code, which analyzes the output data from material science programs called VASP and Bader. As a Python beginner, I earnestly ask some aces to help me make this code more pythonic, or efficient. Because I know that although the code can run smoothly, it definite...
[]
[ { "body": "<h2>Coding style</h2>\n\n<p>For starters, read <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow noreferrer\">PEP 8</a>, which is the Python style guide. This gives suggestions on whitespace around operators and commas, variable names, and the like. Your code isn’t bad if it does...
{ "AcceptedAnswerId": "46403", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T18:44:55.423", "Id": "46398", "Score": "5", "Tags": [ "python", "numpy" ], "Title": "Pythonic way to manipulate arrays: a case study" }
46398
<p>The <a href="http://www.codechef.com/APRIL14/problems/ADIGIT" rel="nofollow">challenge</a> is to reconstruct an <em>n</em>-digit number using the following information:</p> <blockquote> <p>On each step, you choose an index <em>x</em> from 1 to <em>n</em>. For all indices <em>y</em> (<em>y</em> &lt; <em>x</em>)...
[]
[ { "body": "<p>1) I would change the inner for loop this way (very little optimization, unlikely it will bring better performance)</p>\n\n<pre><code>int ans=0;\nint y=index-1;\nfor(int j=0; j&lt;y; j++)\n{\n int diff = a[y] - a[j];\n\n if(diff &gt; 0)\n ans += diff;\n else\n ans -= diff;\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T19:04:00.140", "Id": "46399", "Score": "5", "Tags": [ "java", "programming-challenge", "complexity" ], "Title": "Calculate difference of indices" }
46399
<p>The <code>InputHandler</code> class for my game detects key presses, turns each one into a <code>GameAction</code>, and raises an event:</p> <pre><code>public class InputHandler { public delegate void ActionListener(GameActions gameAction); public event ActionListener ActionRequested; private void Pro...
[]
[ { "body": "<blockquote>\n<pre><code>var pressedKeys = keyboardState.PressedKeys();\nvar inputActions = pressedKeys.Select(GetInputAction).ToList();\nvar downActions = inputActions.Select(ia =&gt; ia.Down);\n</code></pre>\n</blockquote>\n\n<p>This is what's painted you into the corner you're in. You're not showi...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T19:39:45.220", "Id": "46404", "Score": "7", "Tags": [ "c#", "xna" ], "Title": "Turn multiple key presses into single GameAction" }
46404
<p>I've written this class as an exercise for a synchronization construct to be used across multiple threads.</p> <p>The intent is to have worker threads <code>Increment()</code> it, do some work, then finally <code>Decrement()</code>it.</p> <p>Meanwhile, when a master thread decides to shut down the program, it sign...
[]
[ { "body": "<h3>The Good</h3>\n<p>I don't write multithreaded code very often, so other reviewers will probably have other comments (read: I'm a <a href=\"/questions/tagged/multithreading\" class=\"post-tag\" title=\"show questions tagged &#39;multithreading&#39;\" rel=\"tag\">multithreading</a> beginner myself)...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T19:59:59.150", "Id": "46407", "Score": "5", "Tags": [ "c#", "multithreading", "thread-safety", "lock-free" ], "Title": "CountdownLatch Thread-Safety Check" }
46407
<p>I have some code which is designed for the following purposes:</p> <ol> <li>Implement a cache structure which stores cached elements, as well as a method for reloading those elements.</li> <li>Ensure the new structure can use any type of <code>IEnumerable</code> to store the elements.</li> <li>Implement a dynamic c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T07:12:40.640", "Id": "81274", "Score": "3", "body": "This seems unnecessary: \"Ensure the new structure can use any type of `IEnumerable` to store the elements.\" and it contradicts with \"Ensure the dynamic cache can only use `List...
[ { "body": "<p>Interface design is wanting.</p>\n\n<p>This looks like this was made by mistake:</p>\n\n<pre><code>internal interface ICache : IEnumerable\n{\n bool Contains(object element);\n}\n</code></pre>\n\n<p>It should implement <code>IEnumerable&lt;T&gt;</code> which already provides <code>IEnumerable</...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T20:16:08.143", "Id": "46409", "Score": "6", "Tags": [ "c#", "generics" ], "Title": "Maintaining a cache structure with elements" }
46409
<p>I have been working with C++11 code that uses <code>std::vector[]</code> to store coordinates. Most often this code uses 2D or 3D but it occurred to me that it may be generally useful for n-dimensional Euclidean distance calculations.</p> <p>Because these calculations are used within a simulation, they should be as...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-07-26T12:50:01.533", "Id": "254755", "Score": "0", "body": "If you want performance, forcing a memory allocation for each coordinate sounds like a bad idea." } ]
[ { "body": "<p>I know that this won't answer any of your questions, but instead of using <code>std::vector&lt;T&gt;</code>, you should consider using <code>std::array&lt;T, N&gt;</code> to represent your data. Here is why this design could be more interesting:</p>\n\n<ul>\n<li><code>std::array&lt;T, N&gt;</code>...
{ "AcceptedAnswerId": "46417", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T20:21:36.300", "Id": "46410", "Score": "12", "Tags": [ "c++", "c++11", "template-meta-programming" ], "Title": "n-dimensional Euclidean space calculation templates" }
46410
<p>I am generating a content bar with jQuery, that can be inserted into any webpage. It is a <code>&lt;ul&gt;</code> with two smaller lists within it. Those two minor lists have a header and a text box. The whole thing can be resized vertically, and each block within can be resized horizontally.</p> <p>Is there a way ...
[]
[ { "body": "<p>Well, lists generally speaking should be used for lists, so <code>&lt;div&gt;</code>'s and <code>&lt;spans&gt;</code>s would probably be more semantically accurate, but hard to say what the purpose of this is. </p>\n\n<p>Additionally, if you're using headings, it would probably be worth it to chan...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T21:48:38.407", "Id": "46411", "Score": "2", "Tags": [ "javascript", "jquery", "html", "css", "jquery-ui" ], "Title": "Resizeable HTML" }
46411
<p>I have previously asked <a href="https://codereview.stackexchange.com/questions/42823/pong-game-written-in-c-and-using-sdl-2-0">here</a> for a review of my Pong game. Since then I have implemented most of the recommendations but I'm not sure I did so correctly, the result can be found on my <a href="https://github.c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-11-11T06:40:58.050", "Id": "342076", "Score": "0", "body": "When running I show: error: 'abs' was not declared in this scope" } ]
[ { "body": "<ul>\n<li><p>You don't need <code>return 0</code> at the end of <code>main()</code>. Reaching that point already implies a successful termination, so the compiler will insert it for you.</p></li>\n<li><p>Prefer to avoid raw pointers and manual memory management whenever possible. Instead, utilize s...
{ "AcceptedAnswerId": "46416", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-05T23:45:17.873", "Id": "46414", "Score": "6", "Tags": [ "c++", "game", "c++11", "sdl" ], "Title": "Pong game written in C++ and using SDL 2.0 (part 2)" }
46414
<p>This question is more-or-less code agnostic. Provided code analysis would be helpful though.</p> <p>Background: I've never got along with logging too well - probably because I've never had a need to review the non-error level logs. I comply with logging practices on work projects, but I usually don't do any logging...
[]
[ { "body": "<blockquote>\n <p><strong>my logs will contain too much information</strong></p>\n</blockquote>\n\n<p>Think of your log as a database of logged records. You might have all logged records contain the same number of fields (client#, action, result, etc) and each event decides which fields to fill in ...
{ "AcceptedAnswerId": "46434", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T01:03:13.080", "Id": "46419", "Score": "3", "Tags": [ "python", "logging" ], "Title": "How in-depth should the logging be?" }
46419
<p>A few weeks ago I posted a code review of a linked list so I decided to implement bubble sort on my journey of learning C. Here is the referenced linked list library, though this isn't really what's being reviewed (feel free if you'd like!).</p> <p>Linked lists seem inefficient for bubble sort as deletes and gets b...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T04:16:58.110", "Id": "81107", "Score": "0", "body": "If you want your other code reviewed, you need to post it here, not a link to it." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T04:17:38.087", ...
[ { "body": "<h1>Things you did well</h1>\n\n<ul>\n<li><p>You initialize your variables when you declared them.</p></li>\n<li><p>You initialize variables inside of your <code>for</code> loops.<sup>(C99)</sup></p></li>\n<li><p>Your pointer arithmetic looks pretty sound.</p></li>\n</ul>\n\n<h1>Things you can improv...
{ "AcceptedAnswerId": "46431", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T03:53:39.347", "Id": "46427", "Score": "12", "Tags": [ "c", "array", "linked-list", "sorting", "makefile" ], "Title": "Bubble Sort in C: Array vs Linked List" }
46427
<p>Recently I had a problem (not in C++) that required merging a number of sorted lists of values. This is effectively the generalised case of merging together two sorted lists. However, instead of merging them into one single list, the requirement was instead to effectively put them into "buckets" of like values. As a...
[]
[ { "body": "<p>My immediate reaction would be to accept a collection of ranges of some sort (e.g., Boost Range, or even just a pair of iterators).</p>\n\n<p>Since the range (or iterator) types would be template parameters, the user can pass normal iterators or move iterators as s/he sees fit, so one piece of cod...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T05:02:37.947", "Id": "46430", "Score": "6", "Tags": [ "c++", "c++11", "mergesort" ], "Title": "Generic Multiway Merge" }
46430
<p>I am not happy with this code as I am sure there are better ways to do what I'm trying to achieve. I'm a beginner and I've used what I know to date to complete this.</p> <pre><code>import java.util.Random; import java.util.Scanner; public class SeventySix { public static void main(String[] args) { S...
[]
[ { "body": "<p>You should make your entire application more Object Oriented. \nA good place to start would be to move the deck of cards and associated functions into other classes.</p>\n\n<p>Here's an implementation of a deck stolen from a <a href=\"https://stackoverflow.com/a/15942601/334274\">StackOverflow Que...
{ "AcceptedAnswerId": "46440", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T09:02:07.440", "Id": "46439", "Score": "15", "Tags": [ "java", "beginner", "game", "playing-cards" ], "Title": "First attempt at a Blackjack game" }
46439
<p>I found a bit better implementation for Java <code>Arrays.sort(int[])</code>. To make this code review more simple I divide this questions to several parts.</p> <p>The goal of this question is to find more ways to increase the performance even better.</p> <p><strong>Edit:</strong> Tested over Java 6, win 64 bit. I...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T11:14:25.930", "Id": "81132", "Score": "0", "body": "I still think it's called merge sort and not marge sort. Also your caption does not mention anything of a bubblesort, and still I find a method with that name in your code..." }...
[ { "body": "<p>This is a lot of code, and I can't cover it all. But I have a few observations:</p>\n\n<p>Your code is practically undocumented. Even for private methods, a short explanation would be useful. Especially when implementing a sorting algorithm, the documentation should also state algorithmic complexi...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T10:45:13.583", "Id": "46444", "Score": "5", "Tags": [ "java", "mergesort" ], "Title": "Racing Java Arrays.sort with NON recursive Merge Sort implementation" }
46444
<p>I'd like to add a bulk of items into a sparse array, starting at a certain index. I came along this requirement in order to accomplish client side pagination while <strong>not retrieving all data from server</strong> (assuming server returns the <strong>right</strong> data, given the required indexes). </p> <p>To k...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T17:37:47.617", "Id": "81182", "Score": "1", "body": "Your problem starts with \"I need to store the items in a sparse array\". You really really don't need to store the items in a sparse array here. Sparse arrays are not just slow, ...
[ { "body": "<p>You don't need to worry about sparse arrays in JavaScript and there is no need to instantiate with the Array constructor. If you insert into a random index then the rest of the array is just padded with <code>undefined</code> references:</p>\n\n<pre><code>var items = [];\nitems[5] = 'foo';\nconsol...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T11:33:38.383", "Id": "46446", "Score": "5", "Tags": [ "javascript", "pagination", "underscore.js" ], "Title": "Adding a bulk of items in the middle of a sparse array" }
46446
<p>I have been trying to learn C by making a Hangman game. It's not perfect, but with C, I worry that my coding practices will not be very good. I'm also new to allocating memory myself, so I feel I may have done something wrong there. I would very much appreciate reviews of my code.</p> <p>The game takes in a text ...
[]
[ { "body": "<p>There's a lot of code here (the poor indentation in making it harder to read), but I'll skim through and recommend several things I've found.</p>\n\n<ul>\n<li><p>Some of your indentation is off. Remember to have all code within curly braces indented, preferably by four spaces. More importantly, ...
{ "AcceptedAnswerId": "46500", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T13:21:15.517", "Id": "46453", "Score": "5", "Tags": [ "c", "game", "memory-management", "console", "hangman" ], "Title": "My HangMan Game" }
46453
<p>As you're probably aware, PHP doesn't support type hinting for scalar types. I feel this might be good practice to build into my framework, although I'm aware some of you might disagree seeing as PHP is a loosely-typed language.</p> <p>But I'd like some feedback on the implementation of this. Do you think it's effi...
[]
[ { "body": "<p><em>\"So just after some thoughts on this really... good or bad?\"</em></p>\n\n<p>Bad, really bad, I'm afraid. You're trying to make the language do something it doesn't <em>want</em> to do, or even: can't do. You're gluing feathers to a fish's fins, and throwing it up into the air, so it can mimi...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T14:00:31.307", "Id": "46458", "Score": "2", "Tags": [ "php" ], "Title": "Type hinting for scalar types" }
46458
<p>I was given a task where given a string of '0's and '1's, return the longest substring where the count of '0's and '1's are equal. I was told also that the code should be <em>O(n)</em> and space <em>O(1)</em>. </p> <p>Below is what I came up with:</p> <pre><code>def max_equal_sub(s): ''' I get the substrin...
[]
[ { "body": "<p>Taking this from an algorithmic perspective, rather than a python perspective (I don't know python well enough to write something sensible in it).</p>\n\n<p>Your algorithm can be expressed as the logic:</p>\n\n<ol>\n<li>Create a virtual list of balanced strings</li>\n<li>Starting from every positi...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T14:28:33.340", "Id": "46459", "Score": "8", "Tags": [ "python", "optimization", "algorithm", "strings", "complexity" ], "Title": "Longest 'balanced' substring" }
46459
<blockquote> <p>Write a program to do addition of intervals to an interval store.</p> <p>An interval is represented by an array of two elements - the lower and the upper bound (you can assume integers). Assume that intervals are constructed properly (e.g. the lower bound is not greater than the upper bound...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T18:02:28.967", "Id": "81191", "Score": "5", "body": "In the future, please consider asking about [tag:python] and [tag:ruby] in separate questions that mention each other." }, { "ContentLicense": "CC BY-SA 3.0", "Creatio...
[ { "body": "<p>If you have range [a,b], and want to add a range [c,d], there are 6 possible scenarios if you make the assumption, <code>a &lt; b, c &lt; d</code></p>\n\n<pre><code>b &lt; c - undershoot\na &lt; c, b &gt;= c, b &lt;= d - left overlap\na &lt;= c, b &gt;= d - total overlap\na &gt;= c, b &lt;= d - su...
{ "AcceptedAnswerId": "46798", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T15:26:44.420", "Id": "46463", "Score": "7", "Tags": [ "python", "algorithm", "ruby", "interval" ], "Title": "Adding intervals to an interval store" }
46463
<p>I have to parse a file line-by-line and in single line I have split by ",". The first string is the name and the second is the count.</p> <p>Finally, I have to display the Key and Count, for example:</p> <blockquote> <pre class="lang-none prettyprint-override"><code>Peter,2 Smith,3 Peter,3 Smith,5 </code></pre> ...
[]
[ { "body": "<p><strong>Which iterator to use</strong><br>\nI believe it is a matter of taste which iterator to use, though I find the first option is better because:</p>\n\n<ul>\n<li>It is more readable - you understand what is going on at every line - your <code>readLine()</code> each time, and then <code>split...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T15:53:06.280", "Id": "46465", "Score": "10", "Tags": [ "java", "parsing", "comparative-review", "csv" ], "Title": "Parsing CSV file with BufferedReader vs Scanner" }
46465
<p>I have been working on a certain task these days and after several hours of torture, I have done it! However, I believe the code that I have "crafted" is quite difficult to be understood and to be honest, I wouldn't be able to understand it if I wasn't the one who made it. Anyways, this is my code. I would like to r...
[]
[ { "body": "<p>I tried to answer when this question was on SO, but you removed and reposted it here.. so here's a non-code-review. This is not a comment on your code, but a suggestion for an entirely different approach.</p>\n\n<p>That's much more complicated then it has to be.</p>\n\n<p>Look into delta swaps. <c...
{ "AcceptedAnswerId": "46475", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T16:26:40.070", "Id": "46469", "Score": "7", "Tags": [ "c#", "bitwise" ], "Title": "Bit exchange operation" }
46469
<p>Based on <a href="https://codereview.stackexchange.com/q/46397/507">Dynamically call lambda based on stream input: Try 2</a></p> <p>This fixes most of the points pointed out by <a href="https://codereview.stackexchange.com/a/46448/507">@Morwenn</a>.</p> <p>It has been generalized so anybody can call it.<br> The on...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T17:23:56.093", "Id": "81178", "Score": "0", "body": "Which C++14-only features, if any, are you using?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T17:24:49.357", "Id": "81179", "Score": "0...
[ { "body": "<p>I was about to add more things to my answer on your previous post and noticed meanwhile that your already asked a following question (that's almost too fast! :o). I have done some additional reading about C++14 and integer sequences. And I have found some things in the standard that could help to ...
{ "AcceptedAnswerId": "46481", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T17:07:51.067", "Id": "46473", "Score": "7", "Tags": [ "c++", "template", "template-meta-programming", "c++14" ], "Title": "Dynamically call lambda based on stream input: Tr...
46473
<p>In <a href="/questions/tagged/c%2b%2b" class="post-tag" title="show questions tagged &#39;c++&#39;" rel="tag">c++</a>, a template <a href="http://en.cppreference.com/w/cpp/language/parameter_pack" rel="nofollow">parameter pack</a> is a template parameter that accepts zero or more template arguments (non-types, types...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T17:29:34.263", "Id": "46477", "Score": "0", "Tags": null, "Title": null }
46477
In C++, a parameter pack is a parameter that accepts zero or more arguments.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T17:29:34.263", "Id": "46478", "Score": "0", "Tags": null, "Title": null }
46478
<p><img src="https://i.stack.imgur.com/j10XI.png" alt="enter image description here"></p> <p>This code is super slow. I'm looking for advice on how to improve its performance.</p> <pre><code>#!/usr/bin/python # -*- coding: utf-8 -*- # # rss feed indexing bot # import requests import urlparse import time import c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-08T13:14:33.287", "Id": "81517", "Score": "1", "body": "As the diagram shows, your system consists of several components, any of which may be slow. You should carry out some experiments to find the bottleneck." } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T17:48:12.267", "Id": "46479", "Score": "2", "Tags": [ "python", "performance", "web-scraping", "rss" ], "Title": "Prototype spider for indexing RSS feeds" }
46479
<p>For homework, I have to code a program in Python that effectively simulates a bank ATM.</p> <pre><code>print('Welcome to Northen Frock Bank ATM') restart=('Y') chances = 3 balance = 67.14 while chances &gt;= 0: pin = int(input('Please Enter You 4 Digit Pin: ')) if pin == (1234): print('You entered y...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-12-26T03:34:01.437", "Id": "213587", "Score": "0", "body": "this program didnot run it is syntax error in elif option==2:" } ]
[ { "body": "<p>The best way to do this would be to take each of your sections, and give them each a function of their own. Also, when it's possible, separate user input functions from purely logic to improve readability!</p>\n\n<p>For example, it could start looking like this:</p>\n\n<pre><code>def verify_pin(pi...
{ "AcceptedAnswerId": "46489", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T18:32:50.543", "Id": "46482", "Score": "6", "Tags": [ "python", "python-3.x", "homework", "finance" ], "Title": "Bank ATM program in Python" }
46482
<p>I'm looking for code review, optimizations and best practices.</p> <p>Also verifying complexity to be O(n), where <em>n</em> is the string length.</p> <pre><code>public final class InfixToPostfix { private static final char PLUS = '+'; private static final char MINUS = '-'; private static final char M...
[]
[ { "body": "<p><strong>Method comments vs. naming</strong><br>\nWhen the method and parameters are well names, in 9 out of 10 cases, the comment above the method is redundant. For example, <code>higherPrecedence(char op1, char op2)</code> - if you call <code>op1</code> <code>firstOperator</code> and <code>op2</c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T19:08:32.127", "Id": "46486", "Score": "3", "Tags": [ "java", "algorithm", "converting", "stack" ], "Title": "Infix to postix conversion" }
46486
<p>So here it is, my <a href="/questions/tagged/linked-list" class="post-tag" title="show questions tagged &#39;linked-list&#39;" rel="tag">linked-list</a> implementation in Java. I have coded against Java's <code>List&lt;E&gt;</code> interface as if my <code>LinkedList&lt;E&gt;</code> could replace the standard <code>...
[]
[ { "body": "<h2>Lots of extra objects</h2>\n<p>The largest single criticism I have is the creation of LinkedLists where they are not necessary. Creating Objects in Java is a performance issue, especially when done often.</p>\n<p>Methods like the following:</p>\n<blockquote>\n<pre><code>@Override\npublic E get(fi...
{ "AcceptedAnswerId": "46496", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T20:06:03.677", "Id": "46490", "Score": "11", "Tags": [ "java", "linked-list", "reinventing-the-wheel" ], "Title": "LinkedList implementation implementing the List interface in ...
46490
<p>I was eventually going to add another computer and more options to this (i.e., Rock-paper-scissors-lizard-Spock) but I wanted to make sure I was using the best practice for this type of game. Any help would be appreciated. </p> <pre><code># The traditional paper scissors rock game import os def clear(): os.sys...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T23:14:52.167", "Id": "81236", "Score": "0", "body": "I started analyzing the improved version of your question, but it has been removed for some reason. Line-by-line analysis is gone, but I wrote my version of a program: http://code...
[ { "body": "<p>There is much to improve. I recommend you read <a href=\"http://legacy.python.org/dev/peps/pep-0008/\">PEP 8</a>, the official Python style guide. It includes many important tips like:</p>\n\n<ul>\n<li><p>Use consistent 4-space indentation</p></li>\n<li><p>Multiple statements on the same line are ...
{ "AcceptedAnswerId": "46498", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T20:16:59.177", "Id": "46492", "Score": "5", "Tags": [ "python", "beginner", "game", "rock-paper-scissors" ], "Title": "Rock, Paper, Scissors in Python" }
46492
<p>I'm learning Haskell and thought it would be fun to write an AI for the game <a href="http://gabrielecirulli.github.io/2048/" rel="nofollow noreferrer">2048</a> in Haskell.</p> <p>In my implementation I got rid of the randomized aspects of the game.</p> <p>This makes the program deterministic (or pure). However, I...
[]
[ { "body": "<p>First of all - way to go! Type signatures, pattern matching, monads - you're clearly on the right track.</p>\n\n<p>Some general tips:</p>\n\n<ol>\n<li><p>Don't reinvent the wheel!</p>\n\n<p>When you encounter a function that looks like this:</p>\n\n<pre><code>secondFromTuple :: (a,a) -&gt; a\nseco...
{ "AcceptedAnswerId": "46592", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T20:24:47.097", "Id": "46493", "Score": "6", "Tags": [ "game", "haskell", "ai" ], "Title": "Poor AI for 2048 written in Haskell" }
46493
<p>To create a Logging system for a larger application, I came up with the following draft. The log sinks aren't detailed yet, but the factory method for logger creation and a rough draft of the logger itself are. Is this a good start and worth continuing? Or are there pitfalls you can see?</p> <pre><code>class Loggin...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T21:33:28.857", "Id": "81220", "Score": "0", "body": "Have you looked at [Boost.log](http://boost-log.sourceforge.net/libs/log/doc/html/index.html)?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T21:3...
[ { "body": "<p>As noted in the comments:</p>\n\n<p>I would make the factory retain ownership:</p>\n\n<pre><code>class LoggerFactory {\n\ntypedef std::map&lt;std::string, std::unique_ptr&lt;Logger&gt;&gt; Container;\ntypedef Container::iterator iterator;\ntypedef Container::const_iter...
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T21:00:25.533", "Id": "46499", "Score": "7", "Tags": [ "c++", "c++11", "logging", "factory-method" ], "Title": "C++11 Logging Architecture" }
46499
<h1>Background</h1> <p>When a user leaves a page, if they haven't submitted form data, a button is animated to draw the user's attention. (This is a poor UX choice--all the form data should be submitted--but it is what I have to work with at the moment).</p> <p>Only the text, which is centered on the button, must wig...
[]
[ { "body": "<p>I honestly don't know if this will work properly in all browsers (read: I doubt it), but you could conceivably animate the <code>text-indent</code> property to oscillate between +n and -n.</p>\n\n<p><a href=\"http://jsfiddle.net/96Tdn/\" rel=\"nofollow\">Here's a quick, <em>quick</em> hack</a> bas...
{ "AcceptedAnswerId": "46518", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T22:13:33.887", "Id": "46504", "Score": "1", "Tags": [ "jquery", "html", "css", "form", "animation" ], "Title": "Eliminate nested HTML elements for jQuery animation?" }
46504
<p>Following-up on <a href="https://codereview.stackexchange.com/questions/46312/creating-adodb-parameters-on-the-fly">Creating ADODB Parameters on the fly</a> and pushing the &quot;wrapping&quot; of ADODB a step further, I have written two more classes that allows me to expose methods that don't require a <code>Conne...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-09-19T14:03:40.203", "Id": "115778", "Score": "1", "body": "You should try to avoid using SELECT * as it can slow down querying for no good reason.\nSELECT x,y,z is easier to understand and is as fast/faster than SELECT *." }, { "...
[ { "body": "<p>A quick code inspection with MZ-Tools reveals the following:</p>\n\n<blockquote>\n <p>Local variables <code>names</code>, <code>fieldValues</code> and <code>row</code> can be safely removed from the <code>Create</code> method.</p>\n</blockquote>\n\n<p>That's all the tool is picking up though.</p>...
{ "AcceptedAnswerId": "192953", "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-04-06T22:21:36.233", "Id": "46506", "Score": "13", "Tags": [ "sql", "vba", "vb6", "adodb" ], "Title": "Materializing any ADODB Query" }
46506
<p>This program is for a class project and requires me to read data from a text file then display a list of totals. Here are the instructions/requirements:</p> <blockquote> <p>The fields in each record will be separated by a comma.</p> <p>Format: Age, Gender, Marital Status, District#</p> <p>For example: 1...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T23:03:17.117", "Id": "81235", "Score": "3", "body": "Please use spaces instead of tabs here. Tabs mess up the markdown." } ]
[ { "body": "<p>Try to visualize how your items are related. Think how your code runs, step by step, like in slow-mo. You will realize you can sum up long and tedious code into simplest, more abstract, styles.</p>\n<p>Let me start from the last portion of your code:</p>\n<pre><code> Console.WriteLine(&quot;Dis...
{ "AcceptedAnswerId": "46514", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T22:50:55.140", "Id": "46507", "Score": "5", "Tags": [ "c#" ], "Title": "Census Data Display from Text File" }
46507
<p>This is something I wrote as a reply to a deleted "Rock/paper/scissors [updated]" question. Since I can't post it as an answer (and the line-by-line analysis is gone as well), it might be nice to get a code review.</p> <pre><code>"""A game of rock/paper/scissors.""" import random SIGNS = ("rock", "paper", "scisso...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T07:22:57.313", "Id": "81275", "Score": "4", "body": "Consider using `__str__` for `print_results` and returning a string. Then you can use the built in `print` with a counter." } ]
[ { "body": "<p>So this all looks pretty good, with not much to review. I didn't see the previous question, so I will throw my two cents in here.</p>\n\n<p>You define the following at the top of your file:</p>\n\n<pre><code>SIGNS = (\"rock\", \"paper\", \"scissors\")\nVERBS = (\"crushes\", \"covers\", \"cut\")\nY...
{ "AcceptedAnswerId": "46565", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T23:11:52.147", "Id": "46508", "Score": "11", "Tags": [ "python", "game", "rock-paper-scissors" ], "Title": "Rock, paper, scissors" }
46508
<p>Perform a graph clone. Verifying complexity to be O(E). Looking for code review, optimizations and best practices. </p> <pre><code>class NodeOfGraph&lt;T&gt; { private final T item; NodeOfGraph(T item) { this.item = item; } public T getItem() { return item; } } public class G...
[]
[ { "body": "<p>Clone is an ugly API. <a href=\"http://www.artima.com/intv/bloch13.html\" rel=\"noreferrer\">Josh Bloch has a lot to say about it.</a></p>\n<p>My opinion on it, is that you should use it as a last resort, and, when you do use it, it should be a short-cut to a public copy-constructor.</p>\n<p>In ot...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-06T23:41:51.740", "Id": "46510", "Score": "6", "Tags": [ "java", "algorithm", "graph", "reinventing-the-wheel" ], "Title": "Clone of an undirected graph" }
46510
<p>I have been reading about SQL injection and I want to secure my code.</p> <p>I am not asking anyone to write me a code, but I just want to learn it in simple terms. The best way for me to learn is to edit my code so I can compare them.</p> <pre><code>&lt;?php if (isset ($_POST['email'])) { //Connect to the d...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T00:53:57.503", "Id": "81242", "Score": "1", "body": "*The best way for me to learn is to edit my code so I can compare them.* I'm not so sure about that. We *review* code here, so no one will just be editing your code to make it b...
[ { "body": "<p>So, you want to defend against possible injection attacks. That's great. But I struggle to understand why you're bothering to escape all parameters in various ways, but then let the whole thing down by not using the easiest, fastest and rather safe tool you have: <strong><em>prepared statements</e...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T00:46:16.107", "Id": "46512", "Score": "2", "Tags": [ "php", "mysql", "security" ], "Title": "How to prevent SQL injection PHP and MySQL?" }
46512
<p>I have next/previous buttons on my site and all they do is slide sections of the site from left to right and vice versa, it is smooth and looks good on a desktop but on mobile devices it is a bit slow and jumpy. </p> <pre><code>if (type == "prev") { $(this).hide('drop', { direction: 'right' }, 600, function () ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T13:40:13.580", "Id": "81316", "Score": "0", "body": "There is not much to code review really. You will have more luck on Stackoverflow." } ]
[ { "body": "<p>It sounds like the issue isn't really the code, just the performance of the hardware: A mobile device just can't redraw everything as fast as a desktop browser. Writing stuff in single lines does not increase performance!</p>\n\n<p>However, you could try the hardware acceleration \"hack\" <a href=...
{ "AcceptedAnswerId": "46550", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T01:09:04.077", "Id": "46517", "Score": "4", "Tags": [ "javascript", "optimization", "jquery", "mobile" ], "Title": "Smoothen page transition for mobile devices" }
46517
<p>I'm designing a small account/password manager using C# and SQL Server CE. LINQ to SQL is my ORM of choice.</p> <p>Here's the data model representing how the SQL Server CE database is set up:</p> <p><img src="https://i.stack.imgur.com/uAcvZ.png" alt="Data Model"></p> <p>And here's my GUI with a cheesy color-codin...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T17:33:39.317", "Id": "84354", "Score": "5", "body": "I'd question the design of the thing, a password manager should treat passwords as first-class citizens - if it's just another text *field*, you have a potential security issue." ...
[ { "body": "<p>What you call <em>business logic methods</em> is actually your <em>data access logic</em>. And you've put that in a bunch of <code>static</code> methods on what I'm assuming is a <code>static</code> class, which means the GUI code / \"populate fields/accounts\" is <em>tightly coupled</em> with tha...
{ "AcceptedAnswerId": "48076", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T02:02:01.950", "Id": "46519", "Score": "12", "Tags": [ "c#", "performance", "sql-server", "winforms", "linq-to-sql" ], "Title": "Password Manager UI: Populating DataGri...
46519
<p>I'm writing away for this website, and I've come into a problem. I need to display only one <code>td</code> based on the corresponding radio button pressed. However, there are two 'master' radio buttons that dictate how many radio buttons are shown, and after that, which are selected. - if that makes any sense!</p> ...
[]
[ { "body": "<p>You could use polymorphism to represent the states, and to apply the needed formatting.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T03:36:23.227", "Id": "81260", "Score": "0", "body": "Reading up on them no...
{ "AcceptedAnswerId": "46523", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T03:16:05.560", "Id": "46522", "Score": "3", "Tags": [ "javascript", "jquery", "asp.net", "css" ], "Title": "Horrible nested if statement for changing CSS based on RadioButt...
46522
<p>The code I want to refactor look as following:</p> <pre><code>public bool CheckPay(Int64 orderID) { vpc_OrderInfo = orderID; RequestParams = string.Format( "vpc_Version={0}&amp;vpc_Command={1}&amp;vpc_AccessCode={2}&amp;vpc_MerchTxnRef={3}&amp;vpc_Merchant={4}&amp;vpc_User={5}&amp;vpc_Pa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T10:19:20.987", "Id": "81284", "Score": "0", "body": "Why not convert to a switch statement? The data appears to be a single key-value pair." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T10:22:31.613...
[ { "body": "<p>You could convert the if statements to a switch. The value being checked is the same in each if and would only be true in one instance. This should make the code easier to read.</p>\n\n<p>Also, the query variable is being assigned, but not being used anywhere in the function so this can be remov...
{ "AcceptedAnswerId": "46536", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T08:00:17.317", "Id": "46530", "Score": "7", "Tags": [ "c#" ], "Title": "How to refactor multiple if statements?" }
46530
<p>Given a large bounding rectangle ("envelope"), a list of points, and a maximal aspect ratio, the goal is to find a rectangle within the envelope, whose aspect ratio is bounded within the given aspect ratio, that contains a largest number of points from the list.</p> <p>For example: if the envelope is the rectangle ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T10:39:17.573", "Id": "81291", "Score": "1", "body": "Given envelope `(0,0) (80,200)` aspect ratio 1:1 points `(1,200) (2, 200) (3, 200) (4, 200)` this algorithm would find `result.miny = 200` and `result.maxy = 200 + 80 = 280` which...
[ { "body": "<p>The obvious solution is move the max-point-coverage logic into a function, and then call it with an array of just the x or y values, the min/max boundaries, and the \"span\" (i.e. largest width/height allowed).</p>\n\n<p>In other words, start by checking if the square can perfectly cover the envel...
{ "AcceptedAnswerId": "46543", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T08:27:56.563", "Id": "46531", "Score": "4", "Tags": [ "javascript", "algorithm", "node.js" ], "Title": "Reducing code duplication in a geometric function" }
46531
<p>I am getting <code>List ids</code> and by using those <code>ids</code> I am creating a <code>Map</code> by fetching related data of id from database, here I am checking <code>prevId</code> with <code>currId</code> if these are not equal then I am putting them into <code>oCMap</code>.</p> <p>Can this code be optimiz...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-09T05:10:04.293", "Id": "81664", "Score": "0", "body": "shall I move all the constant local variable to class level and declare them as static or its ok if I keep it there only... which one is the better way?" } ]
[ { "body": "<p><strong>Indentation</strong><br>\nJava's indentation convention is 4 spaces, and not 2 as in your code. You may choose the align <code>=</code> signs between grouped lines, but if you do - be consistent - in your assignment block there are 3 different indentations...</p>\n\n<p><strong>Variables, c...
{ "AcceptedAnswerId": "46540", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T09:34:45.720", "Id": "46533", "Score": "7", "Tags": [ "java", "optimization" ], "Title": "Creating map from ids" }
46533
<p>For a school project I have been asked to create a login system for a website. The language I have to use is PHP with no database as of yet (for a later assignment). I'm just wondering if this code has any security flaws.</p> <p>Here is my current code:</p> <p><strong>Navigation.php</strong> note that this is to b...
[]
[ { "body": "<p>Here's my 2 cents as Java \"developer\" with a little experience in c# and vba.</p>\n\n<p>Your security here largely depends on whether you send the password and username in clear text or encrypted. You should force HTTPS protocol for access to the page. </p>\n\n<p>You might also want to show erro...
{ "AcceptedAnswerId": "46539", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T11:25:50.677", "Id": "46537", "Score": "4", "Tags": [ "php", "html", "security", "form", "session" ], "Title": "Security - Login system" }
46537
<p>I am looking for a review on the following code which is for <a href="http://www.codechef.com/APRIL14/problems/ADIGIT">this question</a>. I am looking for a general review of the code. I am specifically also looking for advice on how to make this code run more efficiently.</p> <pre><code>#include&lt;iostream&gt; #i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T12:48:04.983", "Id": "81308", "Score": "0", "body": "Getting something to run in under a second could just be you getting a better computer. It would be better instead to ask for a review, as that is what this site is for, and perha...
[ { "body": "<ul>\n<li><p>Try not to get into 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>. It may be okay for small programs, but it can cause problems for larder ones.</p></li>\n<li><p>Use <cod...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T12:36:05.830", "Id": "46547", "Score": "7", "Tags": [ "c++", "programming-challenge" ], "Title": "Chef and Digits" }
46547
<p>Is this the best way to do this sort?</p> <pre><code>assets.OrderBy(a =&gt; a.GalleryItems != null &amp;&amp; a.GalleryItems.FirstOrDefault() != null ? a.GalleryItems.OrderBy(gi =&gt; gi.SortOrder).First().SortOrder : 1000) </code></pre> <p>Basically I have a group of assets, which contain ...
[]
[ { "body": "<p>What about something like this:</p>\n\n<pre><code>assets.OrderBy(a =&gt; a.GalleryItems != null &amp;&amp; \n a.GalleryItems.Any()\n ? a.GalleryItems.Min(gi =&gt; gi.SortOrder) \n : 1000)\n</code></pre>\n\n<p>It's actually a bit faster, sinc...
{ "AcceptedAnswerId": "46555", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-04-07T13:50:47.700", "Id": "46552", "Score": "5", "Tags": [ "c#", "linq" ], "Title": "Linq sorting on sort order of inner group" }
46552
<p>I just began learning programming and I'm learning Objective-C. I'm taking an online course and in that course we were doing a magic crystal ball app. Then I decided to use what I learned and make my own app.</p> <p><code>Viewcontroller .h</code></p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @class MBFQuotes; @in...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T14:12:10.670", "Id": "81324", "Score": "0", "body": "Regarding your P.S. statement I removed, select all of the code and press CTRL-K." } ]
[ { "body": "<h1>ViewController.h</h1>\n<p>First, this name isn't really descriptive at all, is it? We need to know more about this view controller. In fact, standard naming convention is to suffix all view controller subclasses with <code>ViewController</code> anyway, so this is basically an unnamed view contr...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T14:06:57.943", "Id": "46554", "Score": "4", "Tags": [ "beginner", "objective-c", "ios", "random" ], "Title": "Random quote generator" }
46554
<p>I am trying to remove file extension of a file with many dots in it:</p> <pre><code>string a = "asdasdasd.asdas.adas.asdasdasdasd.edasdasd"; string b = a.Substring(a.LastIndexOf('.'), a.Length - a.LastIndexOf('.')); string c = a.Replace(b, ""); Console.WriteLine(c); </code></pre> <p>Is there any better way of d...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T15:32:42.377", "Id": "81348", "Score": "13", "body": "Googling this exact question title yields [this Stack Overflow answer](http://stackoverflow.com/a/7356223/1188513) as the first search result..." }, { "ContentLicense": "...
[ { "body": "<p>If you can, just use <a href=\"http://msdn.microsoft.com/library/system.io.path.getfilenamewithoutextension%28v=vs.110%29.aspx\"><code>Path.GetFileNameWithoutExtension</code></a></p>\n\n<blockquote>\n <p>Returns the file name of the specified path string without the extension.</p>\n</blockquote>\...
{ "AcceptedAnswerId": "46562", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T14:46:09.427", "Id": "46559", "Score": "2", "Tags": [ "c#" ], "Title": "How to remove file extension using C#?" }
46559
<p>I'm planning to make a small game for learning purposes. So far, I've got the hang of the canvas element and using the context to draw things on it, as well as object notation and classes in JavaScript. </p> <p>But before moving on to making the rest of the game, I'd like you to please take a look at my code and se...
[]
[ { "body": "<p>Interesting,</p>\n\n<ul>\n<li><p><a href=\"http://jsperf.com/path-rect-vs-fillrect/7\" rel=\"nofollow\">http://jsperf.com/path-rect-vs-fillrect/7</a> will tell you that <code>fillRect</code> is faster than what you use in <code>clearCanvas</code>.</p></li>\n<li><p><code>window.onload</code> &lt;- ...
{ "AcceptedAnswerId": "46582", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T14:48:02.400", "Id": "46560", "Score": "6", "Tags": [ "javascript", "html5", "canvas" ], "Title": "Plan to make a small game - got a hang of canvas and made a cube fly around" ...
46560
<p>I've had ideas for something like this in the past but I've finally implemented one and I could definitely use some code review for it. Obviously the quality of the names generated will depend on what the whole thing is seeded with, but that's a separate question. My concerns are the quality and readability of the...
[]
[ { "body": "<p>So, here's a quick lesson on Objective-C <code>@properties</code>.</p>\n\n<p>When you declare a <code>@property</code>, you've created 3 things. An instance variable, a setter, and a getter.</p>\n\n<p>For example, <code>@property NSString *foo;</code> is almost the same as this:</p>\n\n<pre><code...
{ "AcceptedAnswerId": "46600", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T15:31:36.683", "Id": "46566", "Score": "3", "Tags": [ "game", "objective-c", "random" ], "Title": "Random Name Generator" }
46566
<p>Here is a class of one of my applications I'm trying to learn writing good code with. <strong>Old Code:</strong></p> <pre><code>//----------------------------------------------------------------------- // &lt;copyright file="Client.cs" company="-"&gt; // Copyright (c) -. All rights reserved. // &lt;/copyright&g...
[]
[ { "body": "<p>Looks like very nice code, I only have 2 remarks:</p>\n\n<ul>\n<li><p>You declare a ton of one liners between <code>public Client(TcpClient tcpClient, int id)</code> and <code>public void Write(string message)</code> which harms the reading flow if you want to follow the code. I would suggest to p...
{ "AcceptedAnswerId": "46580", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T17:08:31.383", "Id": "46572", "Score": "7", "Tags": [ "c#" ], "Title": "IDisposable Interface for an Server/Client connection client" }
46572
<p>I am comparing two integer values, but there is chance of <code>parseInt</code> giving NaN. I would like to know if I need to do any additional checks.</p> <pre><code>var txtFromCustomerId = document.getElementById(FROMCUSTOMERID_FIELDNAME); var txtToCustomerId = document.getElementById(TOCUSTOMERID_FIELDNAME); if...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T18:19:38.997", "Id": "81389", "Score": "1", "body": "If this data comes from the user typing it in, it seems to me that you ought to check the data the user typed in before you get to this function and not even call this if the valu...
[ { "body": "<ul>\n<li>A blank string <strong>is not</strong> equal to <code>null</code>, therefore it can get through. </li>\n<li><code>parseInt('')</code> returns a <code>NaN</code>.</li>\n<li>Always use <code>parseInt()</code> with the radix (the second parameter). In some implementations, it doesn't default t...
{ "AcceptedAnswerId": "46577", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T18:14:13.070", "Id": "46574", "Score": "2", "Tags": [ "javascript" ], "Title": "Is it ok to have NaN while comparing fields in JavaScript?" }
46574
<p>This is my first Laravel package. It uses hybrid Auth package to authenticate users using their social network accounts. It can retrieve information to store in a local database.</p> <p>Its purpose is to be able to link several social networks accounts into one single user. That way, if you login with Facebook or...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T18:47:40.150", "Id": "46578", "Score": "2", "Tags": [ "php", "authentication", "laravel" ], "Title": "Social user login" }
46578
<p>I'm currently working on a very simple one-file project:</p> <p>Lumix provides the possibility for the camera TZ41 (and others) to load GPS data and tourist information from a DVD to a SD-card so that you can see on the camera (which has GPS and the SD card inside) this information. Sadly, the software to copy it o...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T20:30:06.660", "Id": "81411", "Score": "0", "body": "A quick note ... for multiline strings, you can use parenthesis rather than += ... `helptext = ('abc' [newline] 'def' [newline] 'ghi')`" } ]
[ { "body": "<p>This is really nice code. Clean, documented, idiomatic. I couldn't have written it any better, but that doesn't mean I wouldn't find stuff to improve further ;-)</p>\n\n<h2>Regarding the Code</h2>\n\n<p>For example, this regex: <code>\\s*(\\d{8})\\s*(\\d{8})\\s*(.*)\\s*</code>. The <code>\\s*</cod...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T20:13:41.050", "Id": "46587", "Score": "5", "Tags": [ "python", "parsing", "regex", "linux", "file-system" ], "Title": "Packaging a single-file Python copy-tool" }
46587
<p>I am slowly learning C and C++, and decided after a few lessons to dive in myself without any help. I developed this prime number generator. It seems fast, but I'm wondering if I'm <strong>following the best practices for C++</strong>, or if I am missing anything important.</p> <pre><code>#include "stdafx.h" #inclu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-08T03:04:38.903", "Id": "81444", "Score": "5", "body": "to check for a prime, no need to loop all from 2 to n, just odd numbers from 2 to sqrt(n) is enough" } ]
[ { "body": "<ul>\n<li><p>In C++, you should now use <code>std::cout</code> and <code>std::cin</code> instead of <code>printf()</code> and <code>scanf()</code> respectively. These are found in <a href=\"http://en.cppreference.com/w/cpp/header/iostream\" rel=\"nofollow\"><code>&lt;iostream&gt;</code></a>, and you...
{ "AcceptedAnswerId": "46594", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T21:19:16.990", "Id": "46590", "Score": "23", "Tags": [ "c++", "beginner", "primes" ], "Title": "Prime number generator in C++" }
46590
<p>For this project, I do not have access to Boost or C++11.</p> <p><strong>Note:</strong> I updated the question's description to clarify what I am doing. I have not changed the code though, so no answer has been invalidated.</p> <p>I have to deal with functions that return error codes.<br> When one of these functio...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-08T00:17:38.490", "Id": "81434", "Score": "0", "body": "In your example at the end, i'd much rather see you provide a function that returns an `ostream` ref. Then the caller doesn't have to do all that farting around with converting s...
[ { "body": "<p>This strikes me as really fitting better on SO than here. At least IMO, what you need more than a review of this code is an idea of how to replace it with something better.</p>\n\n<p>I guess for the sake of topicality, I'll review at least the interface you've devised. You start with a function th...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T22:03:01.573", "Id": "46596", "Score": "4", "Tags": [ "c++", "strings", "formatting", "stream" ], "Title": "Format string inline" }
46596
<p>This function checks if a list is sorted.</p> <pre><code>isSorted' :: (Ord a) =&gt; [a] -&gt; [a] -&gt; a -&gt; Bool isSorted' [] [] _ = True isSorted' (x:xs) [] _ = isSorted' xs xs (head xs) isSorted' orig (x:xs) a | a &gt; x = False | otherwise = isSorted' orig xs a </code></pre> <p>I don't like how this fun...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-08T02:34:38.190", "Id": "81443", "Score": "0", "body": "The classic formulation would be something like: the first item in the list is less than the second, and the rest of the list (after the first item) is sorted." }, { "Cont...
[ { "body": "<p>Generally, when you're using explicit recursion in Haskell, there is an easier way. There are many higher order function that will do this recursion for you (<code>map</code>, <code>fold</code> and <code>filter</code> being the quintessential examples).</p>\n\n<p>In this case, we want to go throug...
{ "AcceptedAnswerId": "46608", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-08T02:16:40.880", "Id": "46606", "Score": "6", "Tags": [ "haskell" ], "Title": "Is a List Sorted?" }
46606