body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I want to teach about "encapsulation" and chose <code>Date</code> with <code>Year</code>, <code>Month</code> and <code>Day</code> as an example -- because it demonstrates type-safety w.r.t. preventing accidental swapping of parameters. I want to demonstrate encapusulation to the extreme, meaning I want to hide the <...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T01:17:13.997", "Id": "77314", "Score": "3", "body": "I would avoid naming anything with just the lowercase letter `l`, as this code does in `operator<`, due to its common visual similarities with the number `1` or capital letter `I`...
[ { "body": "<blockquote>\n <p>because it demonstrates type-safety w.r.t. preventing accidental swapping of parameters</p>\n</blockquote>\n\n<p>It does that: because the constructors which take an <code>int</code> parameter are marked <code>explicit</code>.</p>\n\n<blockquote>\n <p>has anyone comments about my ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-16T12:03:20.427", "Id": "44505", "Score": "16", "Tags": [ "c++", "c++11", "datetime", "type-safety" ], "Title": "Type-safe Date class with total encapsulation" }
44505
<p>I am the <a href="https://codereview.stackexchange.com/users/27623/syb0rg">half-robot side of syb0rg</a> that will be posting the recent answers of Code Review to the <a href="http://chat.stackexchange.com/rooms/12723/cr-answers">CR Answers chatroom</a>. <strong>Here is the list of review suggestions I would like, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-16T15:03:16.857", "Id": "77241", "Score": "8", "body": "Have an upvote: you'll be wanting to use the chatroom!" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-16T19:29:18.470", "Id": "77265", "Score...
[ { "body": "<p>For starters, indent your code consistently — the standard in Ruby is two spaces. That includes indenting the contents of your <code>begin-rescue-end</code> blocks.</p>\n\n<p>Normally, I don't like to make such a huge fuss about indentation, but in this case I think it's highly important, because...
{ "AcceptedAnswerId": "44515", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-16T14:59:36.733", "Id": "44511", "Score": "59", "Tags": [ "performance", "ruby", "security", "stackexchange", "chat" ], "Title": "Chat bot for posting recent answers" }
44511
<p>Is there any way to make this more efficient?</p> <pre><code>.386 ; assembler use 80386 instructions .MODEL FLAT ; use modern standard memory model INCLUDE io.h ; header file for input/output cr EQU 0dh ; carriage return Lf EQU 0ah ; line feed maxArr EQU 5 ;...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-01-28T22:29:54.590", "Id": "142958", "Score": "0", "body": "The *SEARCH* routine doesn't use its 2nd parameter *elemCount*." } ]
[ { "body": "<p>There are some opcodes I haven't seen before: <code>output</code>, <code>input</code>, and <code>atod</code>; are these new opcodes, macros, or what?</p>\n\n<p>\"if any overflow, end number entry\" might not be correct behaviour: perhaps you should prompt again for correct input, or abend the prog...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-16T15:25:37.850", "Id": "44513", "Score": "7", "Tags": [ "homework", "assembly" ], "Title": "Search procedure to find inputted DWORD in MASM Array" }
44513
<p>I just wrote this gem <a href="https://github.com/glebm/order_query" rel="nofollow">order_query</a> to find next or previous records relative to the record assuming a (possibly complex) <code>ORDER BY</code> over the records. For example, this is needed to show a link to the next result from the current search resul...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-16T19:06:18.433", "Id": "77263", "Score": "0", "body": "I believe it would be better if you pasted in your question the actual code you want us to review." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-16T...
[ { "body": "<p>I will stick to reviewing the code you've posted, although it seems tied to other code.</p>\n\n<p>First of all: Use descriptive variable names. <code>x</code>, <code>y</code>, <code>q</code>, and so forth aren't great for legibility. Use <code>query</code>, <code>position</code> and similar full w...
{ "AcceptedAnswerId": "44719", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-16T18:19:23.120", "Id": "44520", "Score": "7", "Tags": [ "ruby", "sql", "ruby-on-rails", "active-record" ], "Title": "ActiveRecord extension to find next / previous record(s) ...
44520
<p>I've written some python code to solve the <a href="http://en.wikipedia.org/wiki/Four_color_theorem" rel="nofollow">map coloring problem</a>. In my code, I represent the problem using <code>Territory</code> and <code>MapColor</code> objects:</p> <pre><code>class Territory: def __init__(self, name, neighbors, c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-16T21:03:03.153", "Id": "77284", "Score": "0", "body": "Welcome to CodeReview.SE ! Your question seems interesting and properly ask (nice description and example). However, could you give more information about the `i` parameter to the...
[ { "body": "<p>Your code looks good but I think you should have a look at <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP 8</a> which is the Style Guide for Python Code. Among other things, it says :</p>\n\n<blockquote>\n <p>Comparisons to singletons like None should always be done ...
{ "AcceptedAnswerId": "44669", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-16T18:21:10.743", "Id": "44521", "Score": "5", "Tags": [ "python", "algorithm", "recursion", "graph", "heap" ], "Title": "Constraint Programming: Map color problem" }
44521
<p>I'm new to Python and want to make sure I'm not developing bad habits. If you could please review this code below and give me any tips, practice ideas or critiques you might have. Any ideas on which aspects of the language I should focus on early would also be appreciated.</p> <pre><code>#!usr/env/python #Modeling ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-16T22:16:37.517", "Id": "77300", "Score": "0", "body": "Your `Team` class is useless, no? It has no use (a player is not assigned to a team), so I don't think you need it." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
[ { "body": "<p>The idea of a class in python is to keep track of a state. Your OnField class does nothing else than appending and removing players from <code>players_on_field</code>(which is outside the class). Therefor, <code>sub_in</code> and <code>sud_out</code> could be defined outside the class.</p>\n\n<pre...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-16T19:43:39.493", "Id": "44525", "Score": "6", "Tags": [ "python", "beginner" ], "Title": "Modeling a soccer team with substitutions" }
44525
<p>A friend of mine dabbles in lua, and he recently sent me a code which applies an equation we were discussing. I personally am very mediocre with lua, but my Python senses are tingling - I feel as though this code could almost certainly be shortened. Any thoughts?</p> <pre><code>print("Choose what you want to find:"...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-16T20:21:24.173", "Id": "77277", "Score": "4", "body": "We can only review code that you have written *yourself*. Has your friend given you permission to post this code here? (There is a rather banal reason for this restriction: all us...
[ { "body": "<p>I have never written any Lua code before, but a short view in a tutorial at <a href=\"http://www.lua.org/\">http://www.lua.org/</a> let me come up with this:</p>\n\n<p>Extract a method which returns 3 values:</p>\n\n<pre><code>print(\"Choose what you want to find:\")\nprint(\"Health\")\nprint(\"Si...
{ "AcceptedAnswerId": "44531", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-16T20:14:15.833", "Id": "44527", "Score": "8", "Tags": [ "lua" ], "Title": "Lua Formula Code" }
44527
<p>I'm setting up a Django development environment using Vagrant to run an Ubuntu virtual machine on VirtualBox. As this is a student project run mostly by very amateur coders and I want everyone to be able to contribute, I want the environment to be as convenient as possible.</p> <p>What I'm trying to achieve:</p> <ul...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T00:53:19.297", "Id": "78230", "Score": "1", "body": "I'd recommend you look at using https://github.com/seb-m/pyinotify or similar for this; it's the \"corrrect\" way to do it (certainly far more correct than walking through every s...
[]
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-03-16T20:25:28.303", "Id": "44528", "Score": "14", "Tags": [ "python", "beginner", "django", "less-css" ], "Title": "Django on virtual machine - watching changes in static files and...
44528
<p>This is loosely based on one of W3_School samples:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;p&gt;Hello World!&lt;/p&gt; &lt;p&gt;The DOM is very useful!&lt;/p&gt; &lt;p&gt;This example demonstrates forEach() function&lt;/p&gt; &lt;script&gt; var x=Array.prototype.slice.call(document.getE...
[]
[ { "body": "<p>The only purpose of this script appears to be to illustrate the use the <code>Array.prototype.slice.call</code> \"idiom\" and the <code>forEach</code> function. So it's hard to make \"improvements\" when the purpose of the code isn't its actual result (which is trivial).</p>\n\n<p>What the code ac...
{ "AcceptedAnswerId": "44532", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-16T20:26:09.393", "Id": "44529", "Score": "4", "Tags": [ "javascript", "html", "dom" ], "Title": "forEach and NodeList" }
44529
<p>I am still working on A Z80 CPU emulator and I have decided to prototype it in javascript and then translate it into a faster language, It might be ported to C but more likely is Java - this means I cannot use pointers or jump-tables. It both compiles assembly and interprets it however both are giant nested switch-c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T00:47:45.347", "Id": "77307", "Score": "3", "body": "You say you ultimately want to implement this in C or Java, which makes this tricky to answer. I have some ideas but they are solely for a JavaScript version, and they won't trans...
[ { "body": "<blockquote>\n <p>I cant think of a more elegant way, is this the best way?</p>\n</blockquote>\n\n<p>It's quite a good way: it's clear; and it's simple, so perhaps it's easily extended when you have a complicated bit.</p>\n\n<p>The copy-and-paste duplication in the compiler is the repeated <code>RAM...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-16T23:40:00.920", "Id": "44537", "Score": "8", "Tags": [ "javascript", "assembly", "simulation" ], "Title": "Switch-case Monstrosity for CPU Emulator" }
44537
<p>I am writing a python script that will call mandrills export activity api for every blog on a worpress mu install except for the main site. The script is designed to be called from a cron job on a regular schedule. The code I have is here.</p> <pre><code>__author__ = 'Taylor' import datetime import mandrill import...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T10:10:03.517", "Id": "77530", "Score": "0", "body": "Rather than hard coding API keys and passwords (or passing them as command line arguments), you could look at the [`keyring`](https://pypi.python.org/pypi/keyring) module instead....
[ { "body": "<p>Here are some points:</p>\n\n<blockquote>\n <p>and wanted to learn more about classes in python</p>\n</blockquote>\n\n<p>If you write some piece of code to learn something, delete it and rewrite it.</p>\n\n<blockquote>\n <p>construct[o]r and method <code>export_activity</code> could be refactore...
{ "AcceptedAnswerId": "44650", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T00:09:48.723", "Id": "44539", "Score": "12", "Tags": [ "python", "object-oriented", "functional-programming" ], "Title": "Refractoring OOP vs. Functional Programming Approach" ...
44539
<p>I built a simple Node app, and the code "works", with no failures, no syntax errors, and does not break, but one component doesn't work right. I showed a snippet <a href="https://stackoverflow.com/questions/22444848/function-failing-silently-with-perfect-syntax-how-should-i-debug?noredirect=1#comment34136300_2244484...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T00:56:06.533", "Id": "77309", "Score": "2", "body": "Code review is a site for posting code to be reviewed, not for posting links to code you want reviewed. While it's okay to post a link to the full project, at a minimum, you shou...
[ { "body": "<p>From a once over:</p>\n\n<ul>\n<li><p>Your <code>console.log</code> statement should be wrapped in a condition so that you can turn off all logging to the console. Node can really slow down because of logging to the console.</p></li>\n<li><p>If you are going to log to the console, then it would ma...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T00:50:34.063", "Id": "44541", "Score": "3", "Tags": [ "javascript", "mysql", "node.js" ], "Title": "My node app with valid syntax is failing silently, but not breaking. Infrastruc...
44541
<p>I recently gave an interview and was asked the following question. I posted this here <a href="https://stackoverflow.com/questions/22445688/finding-path-in-maze">Finding path in Maze</a> also, and someone suggested I should try Code Review. So here it goes.</p> <p>A maze is a group of linked Places. Each Place has...
[]
[ { "body": "<p>I'm sorry, but that code is really convoluted. </p>\n\n<p>First off, does this actually work? The comparisons <code>direction == \"N\"</code>(etc.) should fail at compile time due to incomparable types (<code>String</code> and <code>StringBuilder</code>) and <code>nDir.equals(\"\")</code> would al...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T02:22:55.643", "Id": "44544", "Score": "10", "Tags": [ "java", "recursion", "pathfinding", "backtracking" ], "Title": "Finding path in Maze" }
44544
<blockquote> <p>Excel column letters to actual numbers, if you recall, Excel names its columns with letters from A to Z, and then the sequence goes AA, AB, AC... AZ, BA, BB, etc. You have to write a function that accepts a string as a parameter (like "AABCCE") and returns the actual column number. And then do the e...
[]
[ { "body": "<p>Your code is basically fine, and your unit tests are good. All I have is nitpicks.</p>\n\n<p>\"Excel\" in the method names are a bit redundant.</p>\n\n<p>In <code>getExcelColumnNumber()</code>, group <code>- 'A' + 1</code> with parentheses as <code>- ('A' - 1)</code>. Then the compiler can gener...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T02:54:42.250", "Id": "44545", "Score": "19", "Tags": [ "java", "algorithm", "number-systems" ], "Title": "Excel column string to row number and vice versa" }
44545
<p>I've been messing with metaprogramming and variadic templates in C++, and I came up with this very primitive implementation of a tuple:</p> <pre><code>constexpr bool GreaterThanZero(int N) { return N &gt; 0; } template &lt;int, typename...&gt; struct Helper; template &lt;int N, typename Head, typename... Tail...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T12:48:30.713", "Id": "77336", "Score": "2", "body": "Your implementation does not handle empty tuples :)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T19:55:25.250", "Id": "77425", "Score": ...
[ { "body": "<p>Below is how I would clean this up, or maybe partially re-write [<a href=\"http://coliru.stacked-crooked.com/a/ac1e7947152acd6a\">live example</a>]:</p>\n\n<pre><code>// helpers\ntemplate &lt;typename T&gt;\nstruct id { using type = T; };\n\ntemplate &lt;typename T&gt;\nusing type_of = typename T:...
{ "AcceptedAnswerId": "44832", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T04:53:23.577", "Id": "44546", "Score": "16", "Tags": [ "c++", "c++11", "template", "template-meta-programming", "variadic" ], "Title": "Very basic tuple implementation"...
44546
<p>I am writing a new web service that will be performing a lot of large data load operations. To do so I am moving the data to a temporary table then merging the data in to the live data via a stored procedure.</p> <p>That part I have down and working and am very confident in. What I am doing now is trying to optimiz...
[]
[ { "body": "<p>If you want to combine <code>ContinueWith()</code> and <code>async</code> this way, then you <strong>need</strong> to use <code>Unwrap()</code>. (And it <em>is</em> available, though my ReSharper doesn't seem to think so, maybe you use that too?) If you don't do that, you're not actually waiting f...
{ "AcceptedAnswerId": "44569", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T04:55:41.173", "Id": "44547", "Score": "9", "Tags": [ "c#", "asynchronous", "task-parallel-library", "async-await" ], "Title": "Writing highly asynchronous code" }
44547
<p>I find sometimes it is useful to capture the notion of invertible functions.</p> <p>The idea is that if two functions <code>f :: a -&gt; b</code> and <code>g :: b -&gt; a</code> are the inverse function of each other, and if there is another function <code>h :: b -&gt; b</code>, then <code>h</code> can also work on...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T08:49:16.403", "Id": "77321", "Score": "11", "body": "By no means I claim that they theoretically fit here, but somehow, I suspect that by using [lens isomorphisms](http://hackage.haskell.org/package/lens-4.0.7/docs/Control-Lens-Iso...
[ { "body": "<p><strong>Naming:</strong></p>\n<p>There are a lot of names I'd change. Some of them matter more than others (local names in a let are not that big a deal even if they're terrible, but a name for a widely used function should be suggestive, if possible). Some of them I'm more sure of than others.<...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T07:11:05.360", "Id": "44550", "Score": "46", "Tags": [ "haskell", "matrix" ], "Title": "Capture the notion of invertible functions" }
44550
<p>Here is my Code. But I feel that my code isn't really that much object oriented.</p> <p>There is a small piece of "styling" in it as well, the "message error" thing at the end. </p> <p>Should that be in my class or should it go somewhere else?</p> <pre><code>&lt;?php require 'contact.class.php'; ?&gt; &lt;form a...
[]
[ { "body": "<p>Here are some observations noticed:</p>\n\n<p>For something to be OOP it needs to be somewhat reusable. As always use SOLID principles to achieve this.</p>\n\n<p>Because you are using styling it broke some of the rules. Consider returning outputs such as errors and such to be pure text without sty...
{ "AcceptedAnswerId": "44568", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-03-17T07:56:29.893", "Id": "44551", "Score": "7", "Tags": [ "php", "object-oriented" ], "Title": "OOP simple contact form" }
44551
<p>I needed to write a small program to convert floats from any base to any other base. The thing is, it got big. I know there are other ways to implement the conversions (such as doing subtractions instead of divisions), but isn't there a more simple way to do the whole process? I feel like I'm missing something. Any ...
[]
[ { "body": "<p>It is not necessary to deal separately with the integral and fractional parts.</p>\n\n<ul>\n<li>When converting from string, remove the point, convert as integer and scale according to the position where the point was.</li>\n<li>When converting to string, scale to integer, convert and insert point...
{ "AcceptedAnswerId": "44562", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T08:57:42.110", "Id": "44553", "Score": "4", "Tags": [ "python", "optimization", "converting" ], "Title": "Converting float from arbitrary base to arbitrary base" }
44553
<p><a href="https://codereview.stackexchange.com/questions/44361/form-controls-single-event-handler-for-multiple-controls-without-sacrifices">This question</a> I asked previously mentions a function named <code>BuildControlCollection</code>, which I didn't go into the details of since it wasn't relevant. However, becau...
[]
[ { "body": "<blockquote>\n <p><em>I don't know what this is called, so I haven't been able to Google a real implementation, so I've had to make my best guess at it. [...] If anyone can tell me what the bit <strong>flagging</strong> thing used in <code>MsgBox</code> is called, that would be really useful too.</e...
{ "AcceptedAnswerId": "44581", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T09:21:03.930", "Id": "44555", "Score": "8", "Tags": [ "vba", "ms-access" ], "Title": "Generating a collection of controls" }
44555
<p>I have to create some APIs for a online game and I decided to learn to use namespaces correctly.</p> <p>I used the factory pattern, then the <code>loadModule</code> method checks if in the Modules folder there is a class named $module and then it return the object. The folders are synchronized with the namespaces.<...
[]
[ { "body": "<p>My thoughts:</p>\n\n<ol>\n<li><p>Imho <code>Database</code> should not belong to <code>Utilities</code> namespace. Working with database is likely a core part of your application, \"Utilities\" suggest auxiliary tools to make your life easier. But maybe the class does something different than I ex...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T13:11:01.847", "Id": "44565", "Score": "6", "Tags": [ "php", "object-oriented", "namespaces" ], "Title": "My first project using namespaces" }
44565
<p>I am trying to create a function that I want to use in my real data. Is there any way to optimize the following function? This is a function I created to filter the data. </p> <pre><code>filter &lt;- function(x, m, delt) { series &lt;- x series_filtered &lt;- rep(0,length(series)) delta_t &lt;- delt # time st...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-12T06:32:01.767", "Id": "77337", "Score": "1", "body": "This isn't so much a question, as a code writing request. This is not trivial to interpret without any real information on the purpose or action of the function." }, { "Co...
[ { "body": "<p>I have tried this, but I don't know, how much (and even if) faster it is. Anyway, you used a lot of redundant code (creating variables M, h_unbiased, delta_t etc.).</p>\n\n<pre><code>filter2 &lt;- function(x, m, delt) {\n series &lt;- x\n tau_crit &lt;- 3 # critical period (hours)\n theta_crit ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-12T06:16:34.853", "Id": "44566", "Score": "0", "Tags": [ "r" ], "Title": "Optimizing the function in R by replacing for loop" }
44566
<p>I've created this router for my framework and wanted to get some feedback on if it's the most efficient way to search the routes.</p> <p>The main router</p> <pre><code>public static function route($modules = true){ $route = (isset($_GET['route']) &amp;&amp; $_GET['route'] != '') ? trim($_GET['route'], '/') : '...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T13:30:31.757", "Id": "44571", "Score": "2", "Tags": [ "mvc", "php5" ], "Title": "Modular dynamic based routing with wildcards" }
44571
<p>The program counts attributes of various (geo-)objects and prints them to different files. </p> <p>One of the options compares two different datasets with each other. </p> <pre><code>parser.add_option("-c", "--compare datasets", dest="compare", help="If you want to campare two datasets (from diff...
[]
[ { "body": "<p>Simplify all the things! You and your users will benefit from simplicity.</p>\n\n<h2>Option parsing</h2>\n\n<p>If the <code>--compare</code> option is either <code>True</code> or <code>False</code>, make it a boolean flag with <code>False</code> as the default value. Your users won't have to remem...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T14:05:50.493", "Id": "44575", "Score": "6", "Tags": [ "python" ], "Title": "Compare result files from two different runs the smart way?" }
44575
<p>Rock Paper Lizard Spock Monkey Banana</p> <p>My <a href="https://codereview.stackexchange.com/questions/44177/rpsls-refactored-to-object-oriented">original post</a><br> Based off of Malachi's <a href="https://codereview.stackexchange.com/questions/36482/rpsls-game-in-c">post</a></p> <p>I've changed the way rules w...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T14:58:04.540", "Id": "77353", "Score": "5", "body": "Who said Banana! Where? Where?" } ]
[ { "body": "<p>It might be simpler to define rules like this ...</p>\n\n<pre><code>List&lt;Tuple&lt;Gesture,Gesture,string,string&gt;&gt; Rules = new List&lt;Tuple&lt;Gesture,Gesture,string,string&gt;&gt; {\n Tuple.Create(Gesture.Rock,Gesture.Scissors,\"Crushes\",\"Get Crushed By\"),\n ... etc ...\n};\n</c...
{ "AcceptedAnswerId": "44592", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T14:44:20.157", "Id": "44577", "Score": "12", "Tags": [ "c#", "game", ".net", "community-challenge", "rock-paper-scissors" ], "Title": "RPSLSMB OOP Version 2" }
44577
<p>So I noticed Chrome has quirky behaviour when it encounters <code>script</code> tags whose <code>src</code> is a base64 value. I decided to write a quick jQuery method that is supposed to work around it:</p> <pre><code>jQuery.extend({ /** * Takes a script decodes the base64 src, puts it into the body of t...
[]
[ { "body": "<p>Awesome,</p>\n\n<ul>\n<li>Well commented</li>\n<li>Nothing bad on JsHint.com</li>\n<li>Quiet and robust handling of parameters</li>\n<li>It does exactly what it says on the tin</li>\n</ul>\n\n<p>Unrelated to CR, but this is github worthy.</p>\n", "comments": [ { "ContentLicense":...
{ "AcceptedAnswerId": "44603", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T15:47:27.850", "Id": "44583", "Score": "6", "Tags": [ "javascript", "jquery", "dom" ], "Title": "Fix base64 data URI scripts function" }
44583
<p>Part of my program is a variable-sized set of Star Systems randomly linked by Warp Points. I have an A* algorithm working rather well in the grid, but the random warp point links mean that even though the systems have X,Y coordinates for where they're located on a galactic map, a system at 2,3 isn't always linked di...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T23:56:20.867", "Id": "77477", "Score": "0", "body": "A* requires you to be able to accurately estimate the lower bound of the distance that would be required to get from A to B. If you can calculate that, then teleports do not inte...
[ { "body": "<p>The efficiency of heuristic pathfinding algorithms comes from the fact that you are able to discard earlier (or that you work more directed).\nDiscarding any heuristic means the best you can get is a lucky hit (which is rather unlikely) or the Dijkstra algorithm, which is not that efficient (compa...
{ "AcceptedAnswerId": "44597", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T15:48:44.807", "Id": "44584", "Score": "9", "Tags": [ "c#", "recursion", "search", "pathfinding" ], "Title": "Efficient pathfinding without heuristics?" }
44584
<p>Following along another code review (<a href="https://codereview.stackexchange.com/questions/44349/printing-out-json-data-from-twitter-as-a-csv">Printing out JSON data from Twitter as a CSV</a>) I would like to submit a slightly adapted code for review. </p> <p>This code imports JSON data obtained from Twitter and ...
[]
[ { "body": "<p>I've found another answer on <a href=\"https://github.com/alexhanna\" rel=\"nofollow\">https://github.com/alexhanna</a> to this question that I've been able to adapt and enrich to somewhat meet my needs:</p>\n\n<pre><code>import json\nimport sys\nfrom csv import writer\nimport time\nfrom datetime...
{ "AcceptedAnswerId": "44607", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T16:00:05.487", "Id": "44585", "Score": "6", "Tags": [ "python", "json", "twitter" ], "Title": "JSON data from Twitter to Edgelist?" }
44585
<p>I was writing some geometry-related code again and had a closer look at my function supposed to compute the Euclidean distance between two points (N-dimensional points by the way, hence the <code>N</code> template parameter). Here is a simplified version:</p> <pre><code>template&lt;std::size_t N, typename T&gt; aut...
[]
[ { "body": "<p>My concern now is that you make multiple calls to get the actual distance.<br>\nEvery-time you do that then you incur the expense of the <code>sqrt()</code> operation.</p>\n\n<p>I suppose it depends on the exact use case of your application which happens more often. But if this is for general code...
{ "AcceptedAnswerId": "44844", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T16:28:23.960", "Id": "44589", "Score": "13", "Tags": [ "c++", "c++11", "mathematics", "template" ], "Title": "Expression template to compute the Euclidean distance" }
44589
<p>I've taken a look at the SPL Listener/Observer model but found that it doesn't work when using static methods. So I wrote my own but it's very simply. Can anyone suggest ways to make it more like the Model standards and if there is anything obvious that I've missed?</p> <pre><code>&lt;?php namespace modular\core; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T18:19:42.140", "Id": "77393", "Score": "1", "body": "Question (maybe its just me but i want to help you out): are you asking to turn your static class into a more traditional OOP class since you are using too many static classes?" ...
[ { "body": "<p>I see several problems here:</p>\n\n<ul>\n<li><p>It's hard to understand your code because you have not documented any of the methods and their arguments. I have trouble understanding what's the purpose of <code>$event</code>, <code>$key</code> and <code>$callback</code> arguments. First off I tho...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T16:30:56.420", "Id": "44591", "Score": "10", "Tags": [ "php", "design-patterns", "mvc", "php5" ], "Title": "Listener/Observer Model in PHP" }
44591
<p>I'm implementing an algorithm that traverses a graph of nodes (after a given input) and outputs 3 things:</p> <ol> <li>Number of Strongly connected components </li> <li>Size of the largest strongly connected component</li> <li><p>(And here I think is the step that slows down my algorithm) The number of SCC's that a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T18:40:39.493", "Id": "77401", "Score": "0", "body": "Your sentences `This means that, for every node in that SCC, none of them has a path to other nodes outside the SCC. Only other nodes outside of the SCC connect to them.` seem to ...
[ { "body": "<h2>Generics</h2>\n\n<p>Java Generics will not accept the declaration: <code>List&lt;Integer&gt;[]</code> You cannot have an array of a generically typed component. There are ways to make it neater, but, you should be using <code>List&lt;List&lt;Integer&gt;&gt;</code> in a general case.</p>\n\n<h2>Va...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T18:35:22.867", "Id": "44599", "Score": "5", "Tags": [ "java", "algorithm", "performance" ], "Title": "Speeding up this Tarjan's algorithm" }
44599
<p>Here is a fast recursive Fibonacci-like <code>for</code> loop. How can it be more readable, and is it possible remove <code>TArg</code>s? </p> <pre><code>public static class Fibonacci { public static BigInteger Calculate(BigInteger number) { var fibo = AnonRecursiveFiboFunc&lt;BigInteger&gt;( ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T19:41:22.003", "Id": "77422", "Score": "0", "body": "I'm not sure I understand why you are using a delegate instead of using an actual function. It seems to me like this is taking the scenic route instead of the interstate." }, ...
[ { "body": "<ol>\n<li><p>I like to say <code>T1</code> <code>T2</code> instead of <code>TArg1</code>, it just makes it more clear to me what is going on. Your code would look more like this.</p>\n\n<pre><code>delegate Func&lt;T1, T2, T3, T4&gt; Recursive&lt;T1, T2, T3, T4&gt;( Recursive&lt;T1, T2, T3, T4&gt; r);...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T19:19:49.803", "Id": "44602", "Score": "10", "Tags": [ "c#", "recursion", "generics", "fibonacci-sequence" ], "Title": "Recursive Fibonacci with Generic delegates" }
44602
<p>I have written an age calculator that takes a <code>birthDate</code> as input.</p> <p>I'd like a general review of this. I'm especially concerned about the <code>message</code> variable and the lines after the <code>try/catch</code> statement.</p> <pre><code>namespace Age { class Program { static v...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T19:52:56.253", "Id": "77424", "Score": "0", "body": "Is there something specific that you would like a feedback about your code or you just want a general review ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": ...
[ { "body": "<blockquote>\n<pre><code>Console.Write(\"Enter your birtdate: \");\nDateTime birthDate = DateTime.Parse(Console.ReadLine());\n</code></pre>\n</blockquote>\n\n<p>Your <code>catch</code> block looks like it's assuming a <code>ParseException</code> that would be thrown by the above <code>DateTime.Parse<...
{ "AcceptedAnswerId": "44612", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T19:47:05.550", "Id": "44606", "Score": "24", "Tags": [ "c#", "beginner", "datetime" ], "Title": "Simple Age Calculator" }
44606
<p>I am creating a TicTacToe game for my college project, and when I finished the code for computer AI, I ended up with a big chunk of code.</p> <p>It allows the computer to make the winning move, stopping the player from winning and making a random move if the computer can't make any winning move or stop the player f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T20:17:06.553", "Id": "77430", "Score": "0", "body": "Sometimes it's possible to use a dictionary in place of a series of if statements. Have you considered this approach?" }, { "ContentLicense": "CC BY-SA 3.0", "Creation...
[ { "body": "<p>When confronted with a problem like this it helps to implement the <a href=\"http://en.wikipedia.org/wiki/Chain_of_responsibility_pattern\">chain-of-responsibility pattern</a>. In this case, you have a hierarchy of sorts, with a winning move, defensive move, and a random move.</p>\n\n<p>You should...
{ "AcceptedAnswerId": null, "CommentCount": "12", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T20:07:45.207", "Id": "44608", "Score": "22", "Tags": [ "java", "game", "tic-tac-toe", "ai" ], "Title": "Tic Tac Toe computer AI" }
44608
<p>I'm looking to improve my code to make it more efficient, such as shortening it but continuing to gain the same output, or to add some more complex functions into the code.</p> <pre><code>restart ='Y' while restart not in ('N', 'n', 'NO', 'no'): print ("Making A Cup Of Tea") num_orders = int(input("How many...
[]
[ { "body": "<p>It's not always about shortening code, but in most cases about having your code easy to maintain. For example, if this code is to go in production, I would change it as follows:</p>\n\n<pre><code>\"\"\"A script for ordering a tea party.\"\"\"\n\nYES = ('y', 'yes')\nMILK_SIZES = ('small', 'medium',...
{ "AcceptedAnswerId": "44688", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T20:37:20.420", "Id": "44614", "Score": "14", "Tags": [ "python", "python-3.x", "console" ], "Title": "Drink order program" }
44614
<p>My code below is for a sort of onscreen keyboard. I was just wondering if it could be written shorter with a lot of <code>if</code>s and <code>else</code>s. </p> <pre><code>function input(key) { fieldName = currentSide+'_scratchfield'; field = document.getElementById(fieldName); del =...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T10:21:09.583", "Id": "77531", "Score": "1", "body": "I'm not sure I understand the logic: If a user inputs the `\"del\"` key, the field's value is set to the string \"DELETE\", meaning that the _next_ input will set the field's valu...
[ { "body": "<p>I am not sure about getting it shorter, but it could be improved.</p>\n\n<ul>\n<li>Indentation is a bit of a problem, check out <a href=\"http://jsbeautifier.org/\">http://jsbeautifier.org/</a> and paste your code to see what I mean</li>\n<li>Use <code>var</code> to declare your variables!</li>\n<...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T21:49:43.177", "Id": "44619", "Score": "5", "Tags": [ "javascript" ], "Title": "Onscreen keyboard" }
44619
<p>I am just coding some classic brute force password cracking program, just to improve myself.</p> <p>I've explained how my program works at the start of the code. Check some of those screenshots to understand easier.</p> <p>My program works really well but it's a bit dirty and it can be faster if I solve these two ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T03:17:44.317", "Id": "77498", "Score": "0", "body": "\"I want to make it higher like 6 cores ... Can we really do it?\" Yes that can be done. To do it, I think you need to use \"multithreading\". Support for multithreading is built-...
[ { "body": "<ul>\n<li><p>Prefer 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>.</p></li>\n<li><p>Make sure to include <code>&lt;string&gt;</code>.</p></li>\n<li><p>For the <code>&lt...
{ "AcceptedAnswerId": "44630", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T21:50:03.377", "Id": "44620", "Score": "26", "Tags": [ "c++", "performance", "beginner" ], "Title": "Brute force password-cracker" }
44620
<p>I wrote a little function which formats a ms timestamp in a human readable way. I know there are lots of scripts out there, but I needed a very simple one, which only outputs minutes and hours. </p> <p>I was wondering if there is any way to shorten or improve this code snippet, because to me it seems to be very lon...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T15:19:42.933", "Id": "78317", "Score": "1", "body": "One of the scripts out there is [fromNow using moment.js](http://momentjs.com/docs/#/displaying/fromnow/)." } ]
[ { "body": "<p>Hope this might be helpful - </p>\n\n<pre><code>function getRelativeTime(ms){\n var SECOND_MS = 1000;\n var MINUTE_MS = 60 * SECOND_MS;\n var HOUR_MS = 60 * MINUTE_MS;\n var DAY_MS = 24 * HOUR_MS;\n var WEEK_MS = 7 * DAY_MS;\n var MONTH_MS = 30 * DAY_MS;\n\n var lookup = [\"mo...
{ "AcceptedAnswerId": "44626", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T22:23:34.073", "Id": "44623", "Score": "11", "Tags": [ "javascript", "datetime" ], "Title": "Output human readable time" }
44623
<p>I'm currently trying to develop some code that will handle parsing and building of a custom binary protocol. The protocol itself is still fairly fluid but the basic core features are decided. These include</p> <ul> <li>It has a start and end deliminator</li> <li>It contains a header and payload set of data. The...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T00:42:36.490", "Id": "77481", "Score": "0", "body": "Am I right in assuming that you don't want any comments on the format of the protocol/packets, because \"protocol specification itself is outside of my control\"?" }, { "C...
[ { "body": "<h2>Protocol</h2>\n\n<p>It's strange to use a \"custom protocol\". Has no-one invented one you can reuse?</p>\n\n<p>In a binary protocol with STX and ETX I'm used to seeing DLE being used as well:</p>\n\n<pre><code>&lt;DLE&gt;&lt;STX&gt; &lt;PAYLOAD&gt; &lt;DLE&gt;&lt;ETX&gt;.\n</code></pre>\n\n<p>.....
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-17T23:13:22.767", "Id": "44625", "Score": "11", "Tags": [ "c#", "unit-testing" ], "Title": "Writing and reading of a custom binary protocol" }
44625
<p>Should I have made a line break <code>convert_to_quick_mode(</code> and <code>from_exported_cdf,</code></p> <pre><code> convert_to_quick_mode( from_exported_cdf, </code></pre> <p>code:</p> <pre><code>class QuickModeConverter(object): def run(self, from_exported_cdf, fr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T04:35:00.030", "Id": "77504", "Score": "0", "body": "I suspect that you may have a deeper issue that causes you to have this unusual problem in the first place. Maybe it's a poor abstraction, maybe it's poor naming. Could you provid...
[ { "body": "<p>Best option would be to just use <code>*args</code> (or <code>**kwargs</code> if order does not matter), as follows:</p>\n\n<pre><code>class QuickModeConverter(object):\n def run(self, *args):\n convert_to_quick_mode(*args)\n</code></pre>\n", "comments": [ { "ContentLic...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T01:40:41.317", "Id": "44632", "Score": "2", "Tags": [ "python", "formatting" ], "Title": "Formatting the Lengthy Parameters in a better way" }
44632
<p>I am a beginner and I have made a Reservation Form in HTML. I'm pretty sure it will look horrible to any developer out there, but hey, that's why I've posted it.</p> <p>I'd like a general review of this. I'm especially concerned about the quality and enhancements of this form. What should I do to add attractive loo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T05:14:20.397", "Id": "77508", "Score": "2", "body": "\"What should I do to add attractive looks\" - Add a CSS stylesheet" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T05:17:54.813", "Id": "77509...
[ { "body": "<ol>\n<li>You are missing ending paragraph tags</li>\n<li>your tags should be lowercase\n<ul>\n<li>I think that Uppercase is normal for straight HTML, but I suggest using something other than straight HTML. I suggest XHTML or HTML5, and in that case everything should be lowercase.</li>\n</ul></li>\n...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T04:00:43.813", "Id": "44640", "Score": "10", "Tags": [ "beginner", "html", "form" ], "Title": "Reservation Form in HTML" }
44640
<h3> Preamble </h3> <p>So, as most of you have likely also noticed, chat components, at least at a basic level, are becoming very common with lots of apps. I found myself tweaking and redesigning the interface from my last project all the time, so I decided to just create an easy to drop in solution. I'd love to get...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T11:42:58.253", "Id": "77542", "Score": "0", "body": "Are you asking us to review the usage code from an end-user (as a developer who might use this class) perspective?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDat...
[ { "body": "<h1><code>[ChatController new];</code></h1>\n<p>This is perfectly fine syntax, but an Objective-C purists doesn't necessarily like the <code>new</code> method that much. <code>new</code> is simply an <code>NSObject</code> method that looks like this:</p>\n<pre><code>+ (instancetype)new {\n return...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T06:00:14.637", "Id": "44644", "Score": "5", "Tags": [ "objective-c", "ios", "user-interface" ], "Title": "Custom iOS chat interface design & functionality" }
44644
<p>Based on some code on internet, I implemented a dynamic array of structures in C.</p> <p>I am really interested in some feedback on this. Maybe there are some places where it can cause memory leaks or other pitfalls? (I am also concerned if there can be situation that I free a pointer twice in my case, and how to ...
[]
[ { "body": "<p>I have 3 suggestions.</p>\n\n<ul>\n<li><p>If you need to allocate memory and initialize it to zero use <code>calloc</code>.<br/>\nUsing <code>calloc</code> is better than using <code>malloc + memset</code></p>\n\n<p>So change your <code>initArray</code> function like:</p>\n\n<pre><code>void initAr...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T07:58:55.887", "Id": "44649", "Score": "9", "Tags": [ "c", "array", "memory-management" ], "Title": "Dynamic array of structs in C" }
44649
<p>I'm building a virtualised grid in JS/HTML and finding browser performance with large grids fairly slow, particularly in IE10/11. The following jsfiddle roughly represents my worst case scenario, approx 1000 cells:</p> <p><a href="http://jsfiddle.net/FGr7g/1/" rel="nofollow">http://jsfiddle.net/FGr7g/1/</a></p> <...
[]
[ { "body": "<p>First off, your code doesn't seem very optimal. This doesn't effect the speed as far as I can see, but does effect the readability, which may limit the help you get here.</p>\n\n<ul>\n<li>Why do you create a second <code>div</code> inside <code>#grid</code>?</li>\n<li>Why do you assign the styles ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T09:08:51.093", "Id": "44651", "Score": "5", "Tags": [ "javascript", "performance", "jquery" ], "Title": "Optimise JavaScript DOM update" }
44651
<p>To check a win in my TicTacToe game, I have created a 2D array that contains all the combination that a game can be won in, like so: </p> <pre><code> private int[][] winningCombinations = new int[][] { {0, 1, 2}, {3, 4, 5}, {6, 7, 8}, //horizontal wins {0, 3, 6}, {1, 4, 7}, {2, 5, 8}, //virt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T10:22:38.387", "Id": "77532", "Score": "0", "body": "I believe I may have mis-directed you in a previous answer of mine. The 'winning combinations' array should have zero-based indexes... like values `{0, 1, 2}, {3, 4, 5}, .....`" ...
[ { "body": "<h2>Matrices ... 1D or 2D format</h2>\n\n<p>In computing it is common to have matrix-like problems. Graphics, mathematics, and Tic-Tac-Toe.</p>\n\n<p>It is often easier to have the matrix data stored as a 1D array, or 'flattened'.</p>\n\n<p>Whether you have it as a 1D or a 2D array does not really ma...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T09:50:00.670", "Id": "44653", "Score": "2", "Tags": [ "java", "array", "matrix", "tic-tac-toe", "ai" ], "Title": "Turning 1D array to 2D array in TicTacToe" }
44653
<p>Recently I have been making an MVC application with a fluid, responsive design in mind. One of the views has been to implement a fast responsive active directory details page. This is the first time I've really gone head-first into using jQuery/JavaScript with JSON results. Usually I stick to backend coding and so...
[]
[ { "body": "<p>From a once over,</p>\n\n<ul>\n<li><code>s</code>, <code>v</code> and <code>t</code> are unfortunately named properties of <code>vCard</code></li>\n<li>I am confused between the code in <code>vCard.image</code> and <code>getImg</code>, they both call <code>'@Url.Action(\"GetImageThumb\", \"Person\...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T10:51:52.637", "Id": "44655", "Score": "4", "Tags": [ "javascript", "jquery", "html", "css", "active-directory" ], "Title": "Active Directory details page" }
44655
<p>I have to apply window leveling on Canvas Medical Image (CR). I have to get a pixel array from C# <code>Component.lutArr</code>, which is a lookup table array coming as a C# component and which I use in JavaScript. On click of the button, I have to call the function <code>ApplyWLCust()</code>. In this function, al...
[]
[ { "body": "<p>I think we need more code,</p>\n\n<ul>\n<li>Where are <code>imagewc</code>, <code>imageww</code>, and <code>lutArr</code> defined ? Those are all 3 unfortunate variable names by the way</li>\n</ul>\n\n<p>Regardless, I think a large speed up should be gained from calling <code>Recalculate</code> on...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T11:28:54.273", "Id": "44656", "Score": "5", "Tags": [ "javascript", "optimization", "algorithm", "performance", "image" ], "Title": "How to speed up window leveling (brigh...
44656
<p>I have a list of opened nodes, with each step about 3000 nodes are opened and I want to put to the opened list only those nodes that are not already there. For now I'm just comparing each new one to all of the ones already in the opened list and only add it if it's not there. But that is around n*3000^2 comparisons ...
[]
[ { "body": "<ol>\n<li><p>Instead of implementing <code>isSame</code> implement <a href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#equals(java.lang.Object)\" rel=\"nofollow noreferrer\"><code>equals</code></a> and <a href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#hashC...
{ "AcceptedAnswerId": "44666", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T12:24:19.113", "Id": "44662", "Score": "9", "Tags": [ "java", "performance" ], "Title": "Comparing list elements in an effective way" }
44662
<p>I have a type that models the Arithmetic concept and use it as an opaque <code>typedef</code> (AKA strong <code>typedef</code>, see Note below) in some projects. </p> <p>I've put the code into <a href="https://github.com/gnzlbg/arithmetic_type" rel="nofollow">its own repository</a> along with some tests and would l...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T13:05:05.863", "Id": "77567", "Score": "0", "body": "I am no expert on arithmetic types so I might be mistaken, but wouldn't it be better to forward each `operator` to the exact same one on the underlying type?" }, { "Conten...
[ { "body": "<p>Here are some small things you can improve:</p>\n\n<ul>\n<li><code>constexpr inline</code> isn't necessary: <code>constexpr</code> already implies <code>inline</code>.</li>\n<li><p>In the following function:</p>\n\n<pre><code>constexpr friend inline Arithmetic operator+(Arithmetic a,\n ...
{ "AcceptedAnswerId": "44665", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T12:36:12.190", "Id": "44663", "Score": "7", "Tags": [ "c++", "c++11", "boost" ], "Title": "Model of Arithmetic concept for usage as Opaque typedef" }
44663
<p>I have some doubt when I should create an object in an Unit Test when the object needs to be stopped cleanly.</p> <p>Usecase: I have a class ComplexClass which has 3 functions:</p> <ul> <li>Start(): starts a Thread</li> <li>Stop(): stops the thread</li> <li>GetX(): which gets a value</li> </ul> <p>When I test thi...
[]
[ { "body": "<p>This somewhat depends on which principle you value higher. Small repetition:</p>\n\n<h2>F.I.R.S.T</h2>\n\n<h3>F: Fast</h3>\n\n<p>Pretty self-explaining. Unit tests have to be as fast as possible for TDD to be viable. </p>\n\n<h3>I: Independent</h3>\n\n<p>Unit tests are not depending on anything el...
{ "AcceptedAnswerId": "44678", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T15:10:21.190", "Id": "44676", "Score": "6", "Tags": [ "python", "unit-testing" ], "Title": "Create and destroy object in Unit Test" }
44676
<p>I'm not that experienced with PHP and I'm trying to make it so when I load a page, instead of directly browsing to the file, it will be "included" instead.</p> <p>I have the code finished and it works. I just wanted to get an opinion of if it's safe (will people be able to exploit it in anyway?) and if I'm going a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T16:10:47.280", "Id": "77630", "Score": "0", "body": "what prevents a user to access /directory1/directory2/file2.php - is this code part of a routing code?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03...
[ { "body": "<p>As it uses the <code>basename</code> function it should be safe enough.</p>\n\n<p>One note though: I would personally <em>always</em> have a lookup table (PHP \"array\") for whitelisting files unless there is a very specific reason <em>not</em> to do so. That way I will have full control and the r...
{ "AcceptedAnswerId": "44683", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T16:01:07.963", "Id": "44679", "Score": "5", "Tags": [ "php", "beginner" ], "Title": "Including a file (is this safe and effective?)" }
44679
<p>I have the following code, which works as I need it to, however, it repeats itself over and over.</p> <p>I'm relatively new to PHP and haven't grasped recursive functions yet. Which I've been told I'll need to understand as this function could potentially have many levels.</p> <pre><code>if ($_POST['parent'] == "N...
[]
[ { "body": "<p>You seem to always end with the check: Is there another parent? Or as it can be formulated, <strong>while</strong> there is another parent, grab that parent.</p>\n\n<p>Luckily for you, there are <strong>while</strong> loops.</p>\n\n<pre><code>while (!empty($parent)) {\n $query = $connection-&gt...
{ "AcceptedAnswerId": "44685", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T17:20:55.477", "Id": "44682", "Score": "6", "Tags": [ "php" ], "Title": "Need to condense the following into a looping function" }
44682
<p>I am learning algorithms in graphs. I have implemented topological sort using Java. Kindly review my code and provide me with feedback. </p> <pre><code>import java.util.LinkedList; import java.util.Queue; import java.util.Stack; public class TopologicalSortGraph { /** * This Topological Sort implemen...
[]
[ { "body": "<pre><code>class Graph {\n public int vertices;\n LinkedList&lt;Node&gt; nodes = new LinkedList&lt;Node&gt;();\n}\n</code></pre>\n\n<h2><code>Graph</code></h2>\n\n<p><code>Graph</code>, as other data structures in general, should be declared \n<code>public</code>. Because you want them to be ab...
{ "AcceptedAnswerId": "44736", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T18:59:41.857", "Id": "44689", "Score": "15", "Tags": [ "java", "algorithm", "graph" ], "Title": "Topological sort in Java" }
44689
<p>I have a program that has to initialize a few big things (connect to a few databases, parse some XML) and without the initialization being successful the program would not be able to continue.<br> Right now I have my main method throwing just a general Exception</p> <pre><code>public static void main(String[] args)...
[]
[ { "body": "<ol>\n<li><p>What would the users like? It's usually an error message and a log file with the details and stacktraces for bug reports/support calls/debugging. You can throw exceptions out from <code>main</code> but it's not user-friendly (unless the users are the people who develop the software).</p>...
{ "AcceptedAnswerId": "44695", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T19:15:35.203", "Id": "44690", "Score": "5", "Tags": [ "java", "exception-handling" ], "Title": "Proper action when a Java program fails" }
44690
<p>This code has a method that I call for in <code>main</code>.</p> <p>I am given a list with temperatures. What I need to do is to write out the biggest absolute difference of 2 neighbour numbers. For example, if I have {1, 3, 4, 10, 7, 4}, the result is 6 (between 4 and 10) and also all other pairs that have the s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T19:24:44.837", "Id": "77654", "Score": "0", "body": "@Vogel612: I got it now. It just needed CTRL+K." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T19:26:09.827", "Id": "77656", "Score": "0"...
[ { "body": "<h2>General</h2>\n\n<ul>\n<li><p>Your code style is neat. I like that you are using <code>System.out.printf</code> instead of concatenating strings. You should consider using <code>%n</code> instead of <code>\\n</code>in the format because it is platform independent.</p></li>\n<li><p>Math.abs() - <co...
{ "AcceptedAnswerId": "44692", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T19:17:04.780", "Id": "44691", "Score": "4", "Tags": [ "java", "array" ], "Title": "Working with list in Java" }
44691
<p>I've implemented a simple linked list in C# using generic <code>T</code> for values. I did not inherit from any of .Net's fun and helpful classes like <code>IEnumerable&lt;T&gt;</code>, or <code>IList&lt;T&gt;</code> :D. This is just after an hours worth of work. I've tested everything and I believe it all works wel...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T20:00:05.927", "Id": "77659", "Score": "0", "body": "I'd have named them `LinkedList` and `LinkedListNode` if my goal was to not be confusing. Otherwise it sounds like something Java related. A namespace will already keep it apart f...
[ { "body": "<p>Overall, this isn't bad. I do see a few things that bug me though.</p>\n\n<ol>\n<li>Regions - I find they clutter up the code and don't add much value. I would not use them.</li>\n<li><p>Code blocks, regardless how many lines they are should be surrounded by <code>{}</code>. This makes it much ...
{ "AcceptedAnswerId": "44705", "CommentCount": "11", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T19:50:49.147", "Id": "44693", "Score": "16", "Tags": [ "c#", ".net", "linked-list" ], "Title": "Simple Linked List" }
44693
<p>For the record, this is part of a homework assignment, but I have already implemented a solution. I am simply wondering if there is a better way to do it.</p> <p>Background: I am asked to write a procedure, (complete ls), that takes a list of elements and creates a fully connected graph from them, i.e. complete. I ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T20:02:48.937", "Id": "44696", "Score": "1", "Tags": [ "recursion", "scheme", "graph" ], "Title": "Completing a Graph in Scheme" }
44696
<p>I'm writing a small text-based game in Java to learn the language. I'm concerned that I may be making some poor design decisions. I'll introduce 2 elements: A character and monsters. A singleton character should be able to fight a wide array of monsters.</p> <p>Here is the monster class:</p> <pre><code>public abst...
[]
[ { "body": "<p>You don't need a separate class for it!</p>\n\n<p>I don't see any <strong>real</strong> difference between a Bandit and a Skeleton and a regular monster. You don't add or change any methods in the subclasses, and you don't add any new variables (other than the static ones).</p>\n\n<p>The most impo...
{ "AcceptedAnswerId": "44701", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T20:11:38.013", "Id": "44698", "Score": "12", "Tags": [ "java", "game" ], "Title": "Making additional subclasses at any time should be as painless as possible" }
44698
<p>This is one of my first useful scripts. I run it on a highlighted text selection within Notepad++, but I've provided a sample formula and commented out the Scintilla-specific references.</p> <p>I'm a rank amateur: Am I using good idiom? Is my approach to a state machine sensible?</p> <pre><code># input_text = edit...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T21:06:39.993", "Id": "77941", "Score": "0", "body": "I just found this question that seems related and that I intend to look through: http://stackoverflow.com/questions/5492980/what-are-the-best-python-finite-state-machine-implement...
[ { "body": "<p>You can use <a href=\"http://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists\">list unpacking</a> to transform :</p>\n\n<pre><code> takeaction = state_table[current_state][a][1]\n current_state = state_table[current_state][a][0]\n</code></pre>\n\n<p>into the more...
{ "AcceptedAnswerId": "44774", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T20:25:15.270", "Id": "44699", "Score": "10", "Tags": [ "python", "excel", "state-machine" ], "Title": "Excel-formula-analysis state machine" }
44699
<p>I have a <code>DelayQueue</code> in Java, which multiple threads will read from. They will then perform a task, and call a requeue method which performs some mathematical logic (no odd concurrent access), and then calls <code>queue.put(this)</code>. I'm aware that both <code>take</code> and <code>put</code> are bloc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T20:46:49.060", "Id": "77677", "Score": "0", "body": "are your queue operations thread safe?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T20:49:07.270", "Id": "77679", "Score": "0", "bod...
[ { "body": "<p>Why are you requeueing the instance instead of completing the operation...... ? Just asking...</p>\n\n<p>If you really have to reque the instance, and if there is no other locking happening around the code you have shown, then there should be no problems with deadlocks.</p>\n\n<p>Once you have <co...
{ "AcceptedAnswerId": "44704", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T20:39:31.700", "Id": "44703", "Score": "1", "Tags": [ "java", "concurrency" ], "Title": "Am I risking a deadlock in this manner of re-queueing up events?" }
44703
<p>I have quickly wrote a Perl script to convert a mediawiki to a dokuwiki. I know there's an existing script to make that, but I would have a simpler usage code and some use of the API from mediawiki. It was also a good occassion to use pQuery module. I know I can improve some things and I'm going to make a generic co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T01:47:02.730", "Id": "77728", "Score": "0", "body": "The code looks good." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T08:20:20.540", "Id": "77767", "Score": "0", "body": "Hi zdd, ok co...
[ { "body": "<p>This looks fairly good, which is why I'll be fairly harsh.</p>\n\n<h2><code>generate_file_name</code></h2>\n\n<p>Even with single arguments, I'd suggest using a line like <code>my ($title) = @_;</code> rather than <code>shift</code>: Using <code>@_</code> is the dominant idiom, and it will be less...
{ "AcceptedAnswerId": "45014", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T21:14:58.550", "Id": "44707", "Score": "6", "Tags": [ "perl", "converting" ], "Title": "Convert a mediawiki to dokuwiki script" }
44707
<p>I sometimes hear people say how they can distinguish between good and bad coders of a certain programming language or even programming in general simply by looking at the code they write.</p> <p>I'm relearning C, and I was just wondering whether my program follows best practices in terms of my commenting, the way I...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T22:09:12.310", "Id": "77687", "Score": "4", "body": "Does your original code not have indentation? You should add it here, so that your code is clearer." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-1...
[ { "body": "<blockquote>\n <p>I sometimes hear people say how they can distinguish between good and bad coders of a certain programming language or even programming in general simply by looking at the code they write.</p>\n</blockquote>\n\n<p>I think that's true, to some extent. How else (except by the code the...
{ "AcceptedAnswerId": "44713", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-18T22:01:03.987", "Id": "44709", "Score": "11", "Tags": [ "c", "strings" ], "Title": "Reversing an inputted sentence" }
44709
<p>If the number is present, the output should show the numbers that are not present.</p> <pre><code>.model small .Stack 100 .data array db 5, 12, 23, 45, 60, 67, 96, 100 len equ $-array key db 100 msg1 db "found$" msg2 db "not found$" .code ...
[]
[ { "body": "<pre><code>.model small\n</code></pre>\n\n<p>Hard to imagine somebody writing new code for DOS, but okay...</p>\n\n<pre><code> msg1 db \"found$\"\n msg2 db \"not found$\"\n</code></pre>\n\n<p>Seems to me these deserve better names:</p>\n\n<pre><code>fnd_msg db \"found$\"\nnot_fnd_...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T04:14:42.913", "Id": "44723", "Score": "4", "Tags": [ "strings", "assembly" ], "Title": "Alp in MASM 8086" }
44723
<p>Basically, I'm trying to make a Simplifier that can take inputs in the form of a <code>String</code> and print out the solution step-by-step. Now that I've got it working, I think it has some cleanliness issues.</p> <pre><code>public static void test(String eqn) { char[] order = { '^', '*', '/', '+'}; //order...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T05:33:50.590", "Id": "77741", "Score": "0", "body": "@Jamal Thanks for the edit... (I see that you had edited my previous post as well, thanks for that too) :-)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "20...
[ { "body": "<h2>Algorithm</h2>\n<p>The algorithm works well enough. You have captured the essence of the problem in your code, and reading your code it is apparent what it does, and why.</p>\n<p>This is a good thing. It is not very often that the intent of the code is so easy to discern.</p>\n<p>The draw-back of...
{ "AcceptedAnswerId": "44748", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T05:24:59.040", "Id": "44726", "Score": "8", "Tags": [ "java", "optimization", "design-patterns" ], "Title": "Optimizing \"simplifier\"" }
44726
<p>I am a beginner and I have made a Fare Chart in HTML. I'm pretty sure it will look horrible to any developer out there, but hey, that's why I've posted it.</p> <p>I'd like a general review of this. I'm especially concerned about the quality and enhancements of this form. What should I do to add attractive looks and...
[]
[ { "body": "<p>HTML is a markup language. The only thing bad here is the missing closing tags for <code>body</code> and <code>html</code>, and your indentation.</p>\n\n<blockquote>\n <p>What should I do to add attractive looks and show that fare &amp; time which is allotted by me?</p>\n</blockquote>\n\n<p>CodeR...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T05:59:19.267", "Id": "44727", "Score": "8", "Tags": [ "html" ], "Title": "Fare Chart in HTML" }
44727
<p>I want a review of this code.</p> <pre><code>&lt;?php $array = $_POST['array']; //array holding numbers $array = array_reverse($array); // reversing the array echo "&lt;br&gt; Credit card Before :- "; for($i=0;$i&lt;sizeof($array);$i++) echo $array[$i]; echo "&lt;br&gt;"; echo "&lt;br&gt; ...
[]
[ { "body": "<p>There's a few glaring issues with your code. Namely your lack of consistent styling. Secondly, you're not doing certain things correctly (iterating over an array rather than imploding it). As this is a code review, I will not be touching on the correctness of the algorithm. Below you'll find two p...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T07:56:33.000", "Id": "44731", "Score": "3", "Tags": [ "php", "validation", "finance" ], "Title": "Credit card validation with reversed array" }
44731
<p>I'm using Kohana's routing with the route being defined as domain/controller/action. To demonstrate my question let's consider sign-in flow. Currently, if I want to sign-in user I need to return form first and then proceed with data sent by user. Do I need to have two actions, each for the corresponding flow (return...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T11:53:04.347", "Id": "77790", "Score": "0", "body": "Can you not route get and post requests to different actions?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T12:14:04.207", "Id": "77796", ...
[ { "body": "<p>The <a href=\"http://en.wikipedia.org/wiki/Single_responsibility_principle\" rel=\"nofollow\">single responsibility principle</a> also extends to methods. By using one action, you are creating a method which does two entirely unrelated things, which violates this principle.</p>\n\n<p>Also, you ar...
{ "AcceptedAnswerId": "44755", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T10:11:49.527", "Id": "44738", "Score": "-1", "Tags": [ "php", "http" ], "Title": "get and post in one action do different stuff - is it OK?" }
44738
<p>My JavaScript is fairly new and want to learn new ways to create clean, fast code. Can you have a look at this code and guide me on how to optimise this code to improve my skills? I have provided the HTML even though I am not able to edit the actual html as its generated but lets pretend I could..</p> <p>What I am ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T14:12:40.640", "Id": "77822", "Score": "0", "body": "Could you please describe what this code does, and edit the title accordingly?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T16:07:09.583", "...
[ { "body": "<p>Caching the jquery set for $(el) and using it to make subqueries should be a little faster, and I usually find it to be more readable. For example:</p>\n\n<pre><code>var $el = $(el);\n//snip\n$el.find('.p_img img').attr({src : json.images[2].url, alt : json.images[2].altText});\n</code></pre>\n\n<...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T10:39:39.507", "Id": "44739", "Score": "7", "Tags": [ "javascript", "optimization", "performance", "beginner" ], "Title": "Pulling JSON using jQuery and manipulating the Front...
44739
<p>I built this as a simple example of using raw JS to perform a simple GET request with a data callback.</p> <p>Suggestions on how this could be improved in any way, while keeping it simple, would be much appreciated.</p> <p>JS:</p> <pre><code>/*jslint unparam: true, white: true */ var app = (function() { "use...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T12:08:04.267", "Id": "77794", "Score": "0", "body": "you are aware this is not cross-browser compatible? [here's something I used when I did something similar](http://stackoverflow.com/a/15640875/1803692)" }, { "ContentLicen...
[ { "body": "<p>From a once over:</p>\n\n<ul>\n<li>There should be a way to handle errors, this is only good for sunny day scenarios</li>\n<li>It would be more useful if you also passed the <code>xmlhttp</code> object to the callback : <code>callback(data, xmlhttp);</code></li>\n<li>As stated by Vogel612, it wont...
{ "AcceptedAnswerId": "44746", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T11:25:09.707", "Id": "44742", "Score": "4", "Tags": [ "javascript", "ajax", "reinventing-the-wheel" ], "Title": "Raw JS AJAX method" }
44742
<p>This is my first model RSpec test:</p> <pre><code>require 'spec_helper' describe CashFlow do context 'DB Fields' do it { should have_db_column :amount_cents } it { should have_db_column :amount_currency } it { should have_db_column :user_id } it { should have_db_column :target_date } it { sh...
[]
[ { "body": "<p>First thing: congratulations on starting with rspec! Way to go. </p>\n\n<p>My first remark would be to <strong>remove your three first contexts</strong> (Fields, Associations &amp; Validations). </p>\n\n<p>Why? Because <strong>those are not testing any parts of your code - they are testing ActiveM...
{ "AcceptedAnswerId": "44968", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T11:25:49.113", "Id": "44743", "Score": "4", "Tags": [ "beginner", "ruby", "unit-testing", "ruby-on-rails", "rspec" ], "Title": "RSpec tests for a cash flow model" }
44743
<p>My project is written in node JS + Express and has the following architecture:</p> <ul> <li>routes (e.g controllers)</li> <li>models (stateless functional modules)</li> <li>app</li> </ul> <p>Models objects only doing SQL queries like this:</p> <pre><code>exports.setPassword = function (id, password, callback) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T10:48:23.397", "Id": "78259", "Score": "1", "body": "Don't store plaintext passwords in the database. Use a proper password hash, like bcrypt, scrypt or PBKDF2. See [How to securely hash passwords?](http://security.stackexchange.com...
[ { "body": "<p>That does not look very DRY ( Dont repeat yourself ), not to mention that it does not look good that every function must be aware of the connection string.</p>\n\n<p>For updates, you could do something like this:</p>\n\n<pre><code>exports.setPassword = function (id, password, callback) {\n generi...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T11:44:49.873", "Id": "44744", "Score": "3", "Tags": [ "javascript", "node.js", "express.js" ], "Title": "Node exports, architecture" }
44744
<p>I've written a function to call with the deferred library to generate a large task queue, and at first without the recursion it timed out (deadlineexceeded) so now I'm trying with a recursion but is it safe that the function will terminate? I actually ran it with GAE and it did the correct task - deleted all the emp...
[]
[ { "body": "<p>Yes, that function terminate (unless the semantics of <code>blobstore</code> are stranger than expected and <code>blobs</code> is an infinite generator). One thing to be concerned about might be that, should your query take a very long time, you would not delete a single blob before a <code>Deadli...
{ "AcceptedAnswerId": "44819", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T12:28:41.083", "Id": "44745", "Score": "5", "Tags": [ "python", "recursion", "error-handling", "google-app-engine" ], "Title": "Generating a large task queue" }
44745
<p>I created a console program that tests report results from JasperReport. It retrieves the list of reports, splits it, and passes each sublist to a new thread. Each thread executes its own reports and compares the results with reference files.</p> <p>My colleague says multithreading is wrong, but as usual he doesn't...
[]
[ { "body": "<p>I can only see one 'bug' problem with this code, but there are a few other 'style' and 'simplicity' issues.</p>\n\n<h2>reportsDaTestare</h2>\n\n<p>What is this? It appears out of nowhere:</p>\n\n<blockquote>\n<pre><code>for (Report report : reportsDaTestare) {\n ....\n}\n</code></pre>\n</blockq...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T13:21:53.240", "Id": "44749", "Score": "10", "Tags": [ "java", "multithreading" ], "Title": "Inner class calling outer class method" }
44749
<p>I recently wrote code that would query a collection of objects and rank them according to a given criteria and then filter based on an object property. I attach the code below. I would like to know if my approach can be improved upon such as made more efficient and extensible. Is there a better approach or just anot...
[]
[ { "body": "<h2>Lambdas</h2>\n<blockquote>\n<p>I know that lambdas in Java 8 would make the code much cleaner. What other improvements are available?</p>\n</blockquote>\n<p>I am not sure I agree with the Lambdas in J8 statement. They have their place, but clean code is readable code, and only a small subset of p...
{ "AcceptedAnswerId": "44823", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T14:26:03.647", "Id": "44756", "Score": "6", "Tags": [ "java", "collections" ], "Title": "Clean, efficient and extensible code for querying collections" }
44756
<p>I am getting list of <code>badCatsNames</code> from webservices, now I have two asp.net bulleted lists here,</p> <ul> <li>Bulleted List 1 - Available Cats</li> <li>Bulleted List 2 - Purchasing Cats</li> </ul> <p>Now I need to check each bad cat name if bad cat is in available cats list, if bad cat name is then tak...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T14:50:39.097", "Id": "77829", "Score": "3", "body": "Can anyone what? Please edit the title to best reflect the code's *purpose*. Any requests can be in the post body." }, { "ContentLicense": "CC BY-SA 3.0", "CreationD...
[ { "body": "<p>From a once over:</p>\n\n<ul>\n<li><p>Naming: <code>badCatNames</code> not <code>badCatsNames</code>, <code>listPurchasingCats</code> -> I have no clue what this means, is this a list of cats for sale ?</p></li>\n<li><p>Searching on a text : please consider the <code>contains</code> selector: <a h...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T14:45:50.977", "Id": "44759", "Score": "5", "Tags": [ "javascript", "jquery" ], "Title": "Bad cats for sale" }
44759
<p>I have written the following code to get <code>ImageColorPicker</code> child:</p> <pre><code>foreach (CustomTabItem customTabItem in SelectedWindowsTabControl.Items) { TabItem ti = tabControl.ItemContainerGenerator.ContainerFromItem(customTabItem) as TabItem; Popup popup = (Helpers.FindVisualChild&lt;Popup&...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T15:05:14.517", "Id": "77833", "Score": "7", "body": "You should try to find a woman that also wants a child this will increase chances. Now seriously: Try to find more descriptive (and less ambiguous) titles :)" }, { "Conten...
[ { "body": "<p>I don't like a class that's just called <code>Helpers</code> - that's generally a code smell, something that ends up a big dumping ground for anything that doesn't quite fit anywhere else. Be more specific when naming things, perhaps <code>VisualHierarchyHelper</code> would be a better name?</p>\n...
{ "AcceptedAnswerId": "44762", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T14:53:31.817", "Id": "44760", "Score": "14", "Tags": [ "c#", "wpf", "xaml" ], "Title": "Is there a better way to get a child?" }
44760
<p>I'm new to PHP and web development in general. Is this a good coding style for me as a beginner? I don't care about password hashing. I use MD5 which is, as far as I know, not a good encryption method, and I'm trying to create just the login for now.</p> <p><strong>connection.php:</strong></p> <pre><code>&lt;?ph...
[]
[ { "body": "<p>Here are few things I observed:</p>\n\n<ol>\n<li><p>You repeated <code>session_start()</code> twice in your <code>member.php</code> - you can only do that once in order to start the session</p></li>\n<li><p>You are not sanitizing your input for bad values - its best practice to do so to avoid SQL ...
{ "AcceptedAnswerId": "44766", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T16:04:38.340", "Id": "44764", "Score": "5", "Tags": [ "php", "beginner", "html" ], "Title": "Trying to create login" }
44764
<p>I created a linked server in SSMS so that I could run reports on a SpiceWorks SQLite database. there are a few quirks in the whole system.</p> <p>These simple queries are becoming some of the most expensive queries on my reporting SQL Server, I kind of know why, is there a way that I can do this differently?</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T17:14:41.123", "Id": "77874", "Score": "0", "body": "Just a minor suggestion, but maybe you could specify the columns to retrieve from the second query." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19...
[ { "body": "<p>Ouch.... you are not filtering the data you are selecting from the OPENQUERY source....</p>\n\n<p>But, let's get some things straight first.... you say:</p>\n\n<blockquote>\n <p>either way I don't think it would have been clean and straightforward anyway</p>\n</blockquote>\n\n<p>Using OPENQUERY a...
{ "AcceptedAnswerId": "44773", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T16:22:40.560", "Id": "44767", "Score": "10", "Tags": [ "sql", "sql-server", "sqlite" ], "Title": "Another way to run reports on a SpiceWorks SQLite database using a linked serv...
44767
<p>I have two queries; one runs <em>significantly</em> faster than the other, but the faster one is the one that I would have bet money on to be less efficient. These are both being executed through a front end C# console based application and are stored as procedures in SQL Server 2008 R2.</p> <p>Basically, I have th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-06-08T18:36:06.780", "Id": "314635", "Score": "0", "body": "there is not ModelRequests table in the queries" } ]
[ { "body": "<p>You have </p>\n\n<blockquote>\n<pre><code>OPTION (OPTIMIZE FOR (@DateStart UNKNOWN, @DateEnd UNKNOWN));\n</code></pre>\n</blockquote>\n\n<p>in the second query.</p>\n\n<p>Add it to the first one and see what happens, but I am guessing that it might speed that one up as well.</p>\n\n<hr>\n\n<p>This...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T16:45:32.983", "Id": "44770", "Score": "7", "Tags": [ "performance", "sql", "sql-server", "t-sql" ], "Title": "Inefficient query actually more efficient?" }
44770
<p>While writing <a href="https://codereview.stackexchange.com/a/44090/9357">this review</a>, I saw a need for a <code>Counter</code> object similar to <a href="http://docs.python.org/3.3/library/collections.html#collections.Counter" rel="noreferrer">Python's</a>. It seemed like it would be easy to write such a class,...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T10:09:54.487", "Id": "78041", "Score": "1", "body": "NB: This data structure is generally known as a [Multiset or Bag](http://en.wikipedia.org/wiki/Set_(abstract_data_type)#Multiset)." } ]
[ { "body": "<blockquote>\n <p>Is there a common Java library that serves a similar purpose, or am I\n reinventing-the-wheel?</p>\n</blockquote>\n\n<p>As far as I know the JRE doesn't offer this out of the box.</p>\n\n<blockquote>\n <p>Are the semantics for null keys and zero counts reasonable?</p>\n</blockquo...
{ "AcceptedAnswerId": "44784", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T17:43:57.453", "Id": "44772", "Score": "30", "Tags": [ "java", "unit-testing", "collections", "null", "junit" ], "Title": "Just a lowly counter that turned out to be su...
44772
<p>I'm building a media viewer web app for a kiosk in node that uses data in mongo. To render the viewer, it gathers together all the Asset objects (representing video files), each of which belong to a Category, each of which belong to a Medium.</p> <p>This is my first time using mongo and node together, so I decided ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T18:42:05.260", "Id": "77900", "Score": "0", "body": "Welcome to Code Review! Your question looks good to me if your code work as is, without the commented code. We don't fix broken code, since your question is asking for a review it...
[ { "body": "<p>A short review;</p>\n\n<ul>\n<li>Consider using JsHint</li>\n<li>Declare <code>data</code> with <code>var</code>, otherwise you are polluting the global namespace</li>\n<li>Consider <code>err</code> more often, the assumption that there will be no error will bite you</li>\n<li>Do not simply log to...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T18:22:27.430", "Id": "44776", "Score": "4", "Tags": [ "javascript", "node.js", "asynchronous", "mongodb", "mongoose" ], "Title": "Optimizing async joins for mongodb (mongo...
44776
<p>In 8-puzzle I want to count the number of moves it would take to move a specific tile to it's goal place. The problem is my method for this is >100 lines long which is obviously way too much. I'll only include part of that method that counts steps to move the piece to the right row if the goal row is higher. It give...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T20:44:16.753", "Id": "77936", "Score": "0", "body": "You don't care about the other pieces being in a different position before and after do you ?" } ]
[ { "body": "<h2>Concerns</h2>\n\n<p>This logic is complicated and long winded... so much so, that you cut a huge portion of it, or otherwise there is a big bug... You have the condition inside the while-loop:</p>\n\n<blockquote>\n<pre><code> // If the tile needs to be moved upwards (row coord is smaller in\n ...
{ "AcceptedAnswerId": "44815", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T19:22:01.930", "Id": "44783", "Score": "5", "Tags": [ "java", "matrix" ], "Title": "In 8-puzzle finding nr of steps moving a tile to the right place" }
44783
<p>This is the first time that I have played around with AsyncTask in Android and I wanted to make sure I'm using it correctly. The idea is I'm grabbing all the rows from a table in the database using <code>dao</code> and putting them into an Arraylist based off my Item class. Once finished, I added it to a custom Adap...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-20T14:08:02.653", "Id": "83630", "Score": "0", "body": "Why don't you use the [Loader API](http://developer.android.com/guide/components/loaders.html)?" } ]
[ { "body": "<p>All in all, this code is great. I don't see much in the way of problems. There are a few nit-picks:</p>\n\n<blockquote>\n<pre><code> } catch (ClassCastException e) {\n throw new ClassCastException(activity.toString()\n + \" must implement OnFragmentInteractionListener\");\...
{ "AcceptedAnswerId": "44816", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T20:15:29.713", "Id": "44789", "Score": "11", "Tags": [ "java", "multithreading", "android", "sqlite" ], "Title": "Using an AsyncTask to populate a ListView in a Fragment Fr...
44789
<p>I'm wondering if I am doing this in the most efficient way. </p> <p>So I'm declaring my function <code>el</code> which is equal to a macro (Google Tag Manager), then I reassign or overwrite that previously-defined var which grabs the innerText/textContent of the element. It then converts the string to lowerCase an...
[]
[ { "body": "<p>You can using chaining, move the <code>toLowerCase()</code> to simplify a little and return the last statement directly:</p>\n\n<pre><code>function() {\n var el = {{element}};\n el = (el.innerText || el.textContent);\n return el.charAt(0).toUpperCase() + el.slice(1).toLowerCase();\n...
{ "AcceptedAnswerId": "44792", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T20:17:44.030", "Id": "44790", "Score": "5", "Tags": [ "javascript" ], "Title": "Declaring JavaScript variable and then overwriting it multiple times" }
44790
<p>I've written JavaScript for a while, but lately I've been writing a lot of C#. I wanted to write a method that could take the column name of a <code>DataTable</code> and return an average for those values. Having never written closures in C#, but being comfortable with them in JavaScript, I came up with this:</p> ...
[]
[ { "body": "<p>I would recommend reading <a href=\"http://ericlippert.com/2009/11/12/closing-over-the-loop-variable-considered-harmful-part-one/\" rel=\"nofollow noreferrer\">this article</a> by Eric Lippert </p>\n\n<p>You'll definitally want an extension method for this... let me hit the google real quick.... U...
{ "AcceptedAnswerId": "44801", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T20:52:28.710", "Id": "44796", "Score": "6", "Tags": [ "c#", "closure" ], "Title": "Closures in C#, necessary or not?" }
44796
<p>I have recently answered a <a href="https://stackoverflow.com/questions/22441747/c-winapi-creating-treeview-with-nodes-and-checkboxes/22443388#22443388">question on Stack Overflow</a> where OP wanted to programmatically determine if <code>TreeView</code>'s node is checked or not, among other things. My answer got ac...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T21:09:28.547", "Id": "77942", "Score": "2", "body": "Could you post the code here instead of linking to it on another Stack Exchange site? It makes the reviewing process easier for the reviewers, so they don't have to jump back and...
[ { "body": "<p>I have learned more about tree view check-boxes than I wanted to ;)</p>\n\n<p>From a first glance I only have 2 observations:</p>\n\n<ul>\n<li>You have 10 lines of copy pasted code in there, you should have a function for that</li>\n<li><p>This looks terrible:</p>\n\n<pre><code>// Return zero if i...
{ "AcceptedAnswerId": "45210", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T21:03:32.647", "Id": "44798", "Score": "7", "Tags": [ "c++", "performance", "winapi" ], "Title": "Testing if TreeView's node is checked" }
44798
<p>This is my first "useful" Haskell program. It's invoked with filenames as arguments where the last filename is the destination to which the content of all other files will be concatenated. As far as I can tell it's working but I don't like the two returns in the main function and would like to know how I can get rid...
[]
[ { "body": "<p>For your <code>argc &lt;- return $ length args</code> , the reason the compiler is telling you to use the return is because in <code>do</code> notation, monadic binding lines must be the form:</p>\n\n<pre><code>binding &lt;- value wrapped in whatever monad you're using\n</code></pre>\n\n<p>So <cod...
{ "AcceptedAnswerId": "44803", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T21:03:39.723", "Id": "44799", "Score": "10", "Tags": [ "haskell", "monads" ], "Title": "Probably unneeded returns" }
44799
<p>I have to implement a simple program in SSE, and I don't know if I have done it in the right way (it's my first program in SSE).</p> <p>This is the C++ program:</p> <pre><code>double distance (int x1, int x2, int y1, int y2) { double x = abs(x2 - x1); double y = abs(y2 - y1); double dist = sqrt(x*x + ...
[]
[ { "body": "<p>Your SSE code looks like a reasonably accurate translation of your original C, <em>but</em> that C code doesn't immediately jump out as the best way to do things. In particular, I don't see where you gain anything by taking the absolute value before you do your multiplication. Given that your're s...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T21:31:30.113", "Id": "44802", "Score": "4", "Tags": [ "c++", "assembly", "sse" ], "Title": "Is this C++ program correctly implemented in SSE?" }
44802
<p>I have a class that I call "Icons"</p> <p>Icons.h</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @interface Icons : NSObject + (UIImage *) someIcon; + (UIImage *) someOtherIcon; + (NSString *)imageToNSString:(UIImage *)image; + (UIImage *)stringToUIImage:(NSString *)string; @end </code></pre> <p>Icons...
[]
[ { "body": "<p>I do something similar, except rather than creating my own class, I create a <code>UIImage</code> class category.</p>\n\n<p>File names are called <code>UIImage+Icon.h</code> and <code>UIImage+Icon.m</code>.</p>\n\n<p>In the <code>.h</code>, we have this:</p>\n\n<pre><code>@import UIKit.UIImage;\n\...
{ "AcceptedAnswerId": "44807", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T21:49:43.497", "Id": "44806", "Score": "7", "Tags": [ "objective-c", "ios" ], "Title": "Storing icons statically as strings in custom class" }
44806
<p><strong>Task:</strong> </p> <p>Create an interactive slider that allows the user to view a given image gallery. </p> <p><strong>Slider controls:</strong> </p> <ul> <li>See previous slide </li> <li>See next slide </li> <li>Quick navigation through the images / Paging - transition to an arbitrary slide </li> </ul> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T22:57:33.470", "Id": "77971", "Score": "0", "body": "Just to be clear, when you say \"slider\", you mean \"slideshow\", correct? Not like a slider you'd use to control e.g. volume." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>From a once over:</p>\n\n<ul>\n<li>Do not use <code>window.onload = function () {</code> use <code>window.addEventListener(\"load\",</code></li>\n<li>In <code>arrImgs</code>, if all your images have the same folder as a prefix, then you should add support for an image folder</li>\n<li>Avoid Hungar...
{ "AcceptedAnswerId": "45874", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T22:48:27.063", "Id": "44810", "Score": "6", "Tags": [ "javascript", "object-oriented", "html", "dom", "user-interface" ], "Title": "Interactive slider" }
44810
<p>I am parsing excel data and need to create object based on StartDate-EndDate difference.</p> <p>Is there a better way to have only one linq perform this task and return two different result sets ? Only difference in both linq is just the variable on which its applied.</p> <pre><code>private Dictionary&lt;string, D...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T23:12:28.300", "Id": "77974", "Score": "0", "body": "I love `var` with a passion, but in this specific context it's not clear what type `monthlyRows` and `dailyRows` are." }, { "ContentLicense": "CC BY-SA 3.0", "Creation...
[ { "body": "<p>Assuming <code>monthlyRows</code> and <code>dailyRows</code> are both <code>IEnumerable&lt;ExcelDataRow&gt;</code>, a first step could be to <em>extract a method</em> (assuming return type here, I only skimmed through your code):</p>\n\n<pre><code>private Dictionary&lt;DateTime, List&lt;DataPoint&...
{ "AcceptedAnswerId": "44813", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-19T23:03:54.153", "Id": "44811", "Score": "5", "Tags": [ "c#", "linq" ], "Title": "Identical linq for different index" }
44811
<p>I am trying to learn C++ by myself. I looked up a sample question after going through some text. Though I would like someone to review my code. I'm basically asking you to break it to show some flaws or some thing I missed. As a beginner I tried exhaustively to improve it and now hit a wall to analyse robustness o...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T04:29:59.063", "Id": "78012", "Score": "4", "body": "Gentlemen && / || Ladies! This has been the most enlightening code review ever. A first for me :) . I am learning from the best." } ]
[ { "body": "<p>I won't review it all: just one comment as follows.</p>\n\n<p>Have you tested it and verified whether the output is correct?</p>\n\n<p>Some known-good test results (which you can assert your code should produce) are: 0C is 32F; -40C is -40F; and 100C is 212F.</p>\n\n<p>I think this is a bug:</p>\n...
{ "AcceptedAnswerId": "44829", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T02:21:09.590", "Id": "44821", "Score": "25", "Tags": [ "c++", "beginner" ], "Title": "Print out table with start/end temperatures and step size" }
44821
<p>I am a beginner and I have made Colorful Lights using check-boxes in HTML. I'm pretty sure it will look horrible to any developer out there, but hey, that's why I've posted it.</p> <p>I'd like a general review of this. I'm especially concerned about the quality and enhancements of this form.</p> <pre><code>&lt;htm...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T06:02:01.917", "Id": "78020", "Score": "0", "body": "Why do you use checkboxes for this? Any element can have mouseover events, and using checkboxes when you don't seem to use them as, well, checkboxes seems odd" } ]
[ { "body": "<p>1) I'd start with a better HTML template, you forgot the DOCTYPE and meta tags:</p>\n\n<pre><code>&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n &lt;meta charset=\"UTF-8\"&gt;\n &lt;title&gt;&lt;/title&gt;\n&lt;/head&gt;\n&lt;body&gt;\n\n&lt;/body&gt;\n&lt;/html&gt;\n</code></pr...
{ "AcceptedAnswerId": "44828", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T02:28:41.400", "Id": "44822", "Score": "10", "Tags": [ "javascript", "beginner", "html" ], "Title": "Colorful Lights in HTML" }
44822
<p>It's harder to do than <a href="https://codereview.stackexchange.com/a/44829/9357">criticize</a>. Here's my attempt to implement a Celsius-to-Fahrenheit conversion table in C++.</p> <pre><code>#include &lt;cstdlib&gt; #include &lt;cstring&gt; #include &lt;iomanip&gt; #include &lt;iostream&gt; #define DEGREE_SIGN ...
[]
[ { "body": "<p>I would have gone (and actually have gone in production code) for a <code>Temperature</code> class providing methods to obtain the values in the different units. This makes the streaming output slightly trickier but avoids the code repetition and makes it easier to lets say add Kelvin to it.</p>\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T04:57:23.067", "Id": "44836", "Score": "23", "Tags": [ "c++", "validation", "floating-point", "unit-conversion" ], "Title": "Celsius → Fahrenheit conversion table" }
44836
<p>I'm new with Angular promise and I would like to know how to improve my code.</p> <p>I have a service which preload media or data by calling an API. The media API return an array of urls to preload.</p> <pre><code>'use strict'; angular.module('myApp').service('PreloaderService', ['$http', '$q', 'localStorageServi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T11:11:53.297", "Id": "78045", "Score": "2", "body": "I'm really trying hard not to be \"that guy\", but I can't help myself: \"data\" and \"media\" are plural forms already, so \"datas\" and \"medias\" isn't quite right. (The singul...
[ { "body": "<p>This took a while to parse, it's probably me, I found few flaws with the code, except for a distinct lack of comments.</p>\n\n<ul>\n<li><p>I would have made <code>url</code> in <code>preload</code> an optional, 2nd parameter, I would probably want to call preload a few times with different URL's (...
{ "AcceptedAnswerId": "46215", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T09:53:19.563", "Id": "44840", "Score": "5", "Tags": [ "javascript", "angular.js", "promise" ], "Title": "Angular promise in service" }
44840
<p>I have a small Coldfusion section of our site that all uses similar JavaScript and CSS files and page design. The code is currently repeated for each file, and I'd like to factor it out and set something up using a master page and templates.</p> <p>Master.cfm page:</p> <pre><code>&lt;!--- Master template, includes...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-05T18:12:24.447", "Id": "92076", "Score": "0", "body": "The `#pageName#` concerns me. What will be setting that? Are you sure that you aren't subjecting the site for a url inject attack" } ]
[ { "body": "<p>My ColdFusion is a little rusty, but why would you not have the setting of the master dependent variables and the call to the master page both contained within the same page? Other than that, sure, you're implementing this the same way everyone does unless it's specifically built into the language...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T10:05:35.840", "Id": "44841", "Score": "10", "Tags": [ "html", "template", "coldfusion" ], "Title": "Structuring a master page" }
44841
<p>Method:</p> <ul> <li>Input: a string which represents an integer or a non-integer value.</li> <li>Output: a string which represents the same value multiplied by 100.</li> </ul> <p>Requirements:</p> <ul> <li>No floating-point unless needed.</li> <li>No leading 0s in the part left of the floating-point.</li> <li>No...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-21T12:23:17.560", "Id": "78262", "Score": "0", "body": "@palacsint already answered this, but in a nutshell the issue is simply that floating point data types are imprecise and math operations on floats produce rounding errors at the e...
[ { "body": "<ol>\n<li><p>It would be much easier with <a href=\"http://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html\" rel=\"nofollow noreferrer\"><code>BigDecimal</code></a>s:</p>\n\n<pre><code>String input = \"00007.880000\";\nBigDecimal hundred = BigDecimal.valueOf(100);\nBigDecimal result = new...
{ "AcceptedAnswerId": "44850", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T12:16:48.873", "Id": "44848", "Score": "10", "Tags": [ "java", "strings" ], "Title": "Converting a numerical string to the equivalent multipled by 100" }
44848
<p>I want to have a continuous date sequence like ['2014-01-01','2014-01-02', ...]</p> <p>Then I define a stream to do that.</p> <pre><code>def daySeq(start: Date): Stream[Date] = Stream.cons(start, daySeq(plusDays(start, 1))) </code></pre> <p>I get the sequence within range [start, end) by calling </p> <pre><code...
[]
[ { "body": "<p>I suggest using Joda-Time's <code>LocalDate</code> instead of Java's <code>Date</code> to represent dates without a time zone.</p>\n\n<p>Assuming you only need to traverse the days once, use an <code>Iterator</code> instead of a <code>Stream</code>.</p>\n\n<pre><code>def dayIterator(start: LocalDa...
{ "AcceptedAnswerId": "45124", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T12:27:15.123", "Id": "44849", "Score": "6", "Tags": [ "scala", "datetime", "stream" ], "Title": "Construct date sequence in Scala" }
44849
<p>I'm writing a JavaScript library, and I am using this function for type detection:</p> <pre><code>function type(obj){ return Object.prototype.toString.call(obj).replace(/([\[\]]|object|\s)/gi, ""); } </code></pre> <p>Their works ok, but compared to jQuery and MooTools it stinks.</p> <p><a href="http://jsperf...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T12:40:11.573", "Id": "78054", "Score": "0", "body": "This is micro-optimization, don't worry about it. 7,767,355 ops/sec in FF is more than enough. How often do you check the type of something anyway?" }, { "ContentLicense":...
[ { "body": "<p>Interesting question, since there is only 1 line to review and a limited amount of ways to get the 'type` of an object</p>\n\n<p>I will say that </p>\n\n<pre><code>function type(obj){\n return Object.prototype.toString.call(obj).replace(/([\\[\\]]|object|\\s)/gi, \"\");\n}\nvar o = new (function...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T12:34:02.397", "Id": "44851", "Score": "4", "Tags": [ "javascript", "performance" ], "Title": "Improving the performance of my \"type\" function" }
44851
<p>Basically, I have two separate tables, Campaign and CampaignDetails. They relate via CampaignID. I want a service that can handle both at the same time, as they're closely related and when one gets updated- so will the other.</p> <p>At the moment I'm combining the two but it's starting to get a bit hard to look at<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T13:24:32.007", "Id": "78073", "Score": "0", "body": "You have a design issue. Your `ICampaignService` is too low level. Post an example method that uses `UpdateCampaignDetails(CampaignDetails)` and we will have a better idea what ca...
[ { "body": "<p>Overview of your service looks like this. I've put T-SQL commands that execute in each methods comment.</p>\n\n<pre><code>interface ICampaignService\n{\n //INSERT = INSERT INTO CAMPAIGN....\n void InsertX( ... );\n\n //UPDATE = UPDATE CAMPAIGN....\n void UpdateX( ... );\n\n //DELETE...
{ "AcceptedAnswerId": "44876", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-20T13:05:06.813", "Id": "44854", "Score": "4", "Tags": [ "c#", "design-patterns", "entity-framework" ], "Title": "Should I create two seperate Services and then combine them or ha...
44854