body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
Machine learning provides computer algorithms that automatically discover patterns in data and make intelligent decisions from them.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T07:00:03.227", "Id": "35161", "Score": "0", "Tags": null, "Title": null }
35161
Google Chrome is a web browser available on mobile, TV, and desktop platforms. Developed by Google, it uses the Blink layout engine and application framework.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T07:01:53.500", "Id": "35163", "Score": "0", "Tags": null, "Title": null }
35163
<p>Feel free to tell about every possible issue (style, errors, inffective solution etc.) you found. Here is the main part of what I want to be reviewed, through there is some related code on <a href="https://github.com/datalinkE/graph/tree/edd0764f76eb548f39d90249f0cf41912f989e8e" rel="nofollow">GitHub</a>.</p> <h3>H...
[]
[ { "body": "<p>Generally speaking, it seems to be coded pretty well. I can just find one or two things that could be improved:</p>\n\n<hr>\n\n<pre><code>else\n{\n continue;\n}\n</code></pre>\n\n<p>This piece of code at the end of a <code>while</code> seems fairly useless. I guess it would be the same without ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T07:45:58.317", "Id": "35165", "Score": "3", "Tags": [ "c++", "c++11", "tree", "graph" ], "Title": "Implementation of Prim's minimum spanning tree" }
35165
Initialization is the first assignment for a data object or variable.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T08:57:18.040", "Id": "35167", "Score": "0", "Tags": null, "Title": null }
35167
<p>Two possible solutions but which one? Or is there a Better?</p> <p>I have a class MP3Track with members: Track number (int), track name (String), artist (String), in faourites (boolean) etc. My catalogue class contains two <code>ArrayList</code>s, one containing all tracks (vectorMain) and the other containing favo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T12:25:04.310", "Id": "56934", "Score": "0", "body": "What is the purposeof the 'track number'? Is it the track number of an album? It appears that it is not the album track number but something used for internal processes... what is...
[ { "body": "<p>In Solution 3, assuming you initialize <code>mp31</code> and <code>mp32</code> to null, you can replace this</p>\n\n<pre><code>//Check if we found track 1\nif(vectorMain.contains(mp31)){\n //Set temp var new track number\n mp31.setTrackNo(t2);\n}\n</code></pre>\n\n<p>With:</p>\n\n<pre><code>...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T11:20:51.710", "Id": "35173", "Score": "2", "Tags": [ "java" ], "Title": "Solution for swapping ArrayList data members with another" }
35173
<p>I am working on the following script for python2.7 which "works" on small files. </p> <p>I ran a sample on an input file of 188kB and it took approx. 1.15 min to complete. However, I need to process a 5GB file using this script and I did the math, it will take 11.48 years to finish it the way it is now. </p> <p>sa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T11:50:10.313", "Id": "56926", "Score": "2", "body": "Don't write `.keys()`!" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T11:58:13.837", "Id": "56927", "Score": "0", "body": "see updated...
[ { "body": "<p>Remove all usages of the keys method. Note, this was already mentioned in the comments to your question, but it seems to have mostly done the trick for your problem.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDat...
{ "AcceptedAnswerId": null, "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T11:45:31.540", "Id": "35175", "Score": "2", "Tags": [ "python", "optimization" ], "Title": "Optimize python script for speed" }
35175
<p>I find myself using subject blocks in my tests to setup example because it is succinct. However is this considered bad form and can it have undesired consequences?</p> <pre><code>require 'spec_helper' describe "stations/index" do before(:each) do stub_user_for_view_test assign(:stations, [ stub_...
[]
[ { "body": "<p>There are no unintended consequences, but it is a little unusual and may surprise the reader. However, it is a small surprise.</p>\n\n<p>It usually communicates intent well to use <code>subject</code> to declare the subject, and <code>before</code> to setup preconditions unrelated to the subject....
{ "AcceptedAnswerId": "38838", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T15:05:21.037", "Id": "35178", "Score": "2", "Tags": [ "ruby", "ruby-on-rails", "rspec", "tdd" ], "Title": "Using RSpec subject to setup a test" }
35178
<p>Just wondering what I did bad/could have done better. It's a simple script for pulling information from Leafly about cannabis strains. I've also added in a function to search. I am fairly new to Python. Anything is greatly appreciated. I also realize nothing is commented. I will quickly answer any questions, but ...
[]
[ { "body": "<p>You have two unused imports:</p>\n\n<pre><code>import pprint\nimport sys\n</code></pre>\n\n<ul>\n<li><p>In your methods, I notice that you are not using local variables and instead you're setting instance variables. There is no need for that, unless those variables need to be used outside of your ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T15:55:45.117", "Id": "35179", "Score": "5", "Tags": [ "python", "performance", "beginner" ], "Title": "Python Leafly API" }
35179
<p>I like to create tools for memoization since it can sometimes be useful. I recently created a generic tool for memoizing the results of <a href="https://en.wikipedia.org/wiki/Pure_function" rel="nofollow">pure functions</a>.</p> <p>Here is an example of how it works:</p> <pre><code>// Dummy function auto func(int ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T20:51:18.907", "Id": "56967", "Score": "3", "body": "See http://stackoverflow.com/q/9729212/1157100" } ]
[ { "body": "<p>Thanks to <a href=\"https://stackoverflow.com/a/9729954/1364752\">an answer</a> to a similar question on StackOverflow (thanks @200_success), I improved the implementation of <code>operator()</code>. Using <code>_memory.count</code> is pretty inefficient compared to <code>_memory.find</code> since...
{ "AcceptedAnswerId": "35765", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T16:15:16.840", "Id": "35180", "Score": "8", "Tags": [ "c++", "c++11", "functional-programming", "cache", "memoization" ], "Title": "Generic pure functions memoization" ...
35180
C++/CLI is based on C++, modified to allow compilation of a mixture of native code and code for Microsoft's Common Language Infrastructure (CLI). It replaces Microsoft's Managed Extensions for C++, which aimed for stronger C++ conformance.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-11-11T17:51:06.723", "Id": "35184", "Score": "0", "Tags": null, "Title": null }
35184
<p>Use this tag for code that is to be compiled as <a href="http://en.wikipedia.org/wiki/C%2B%2B03" rel="nofollow noreferrer">C++03</a>, published as ISO/IEC 14882:2003 in 2003.</p> <ul> <li>Predecessor: C++98</li> <li>Successor: C++11</li> </ul>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-11-11T17:53:02.420", "Id": "35185", "Score": "0", "Tags": null, "Title": null }
35185
Code that is written to the 2003 version of the C++ standard. Use in conjunction with the 'c++' tag.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-11-11T17:53:02.420", "Id": "35186", "Score": "0", "Tags": null, "Title": null }
35186
A class, data structure, or abstract data type (ADT) whose instances are collections of other objects.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T17:56:52.573", "Id": "35188", "Score": "0", "Tags": null, "Title": null }
35188
<p>I have these lines of code in my view:</p> <pre><code>&lt;?php $count = count($product-&gt;getTags()); $tagsStr = ''; foreach($product-&gt;getTags() as $key =&gt; $tag){ $tagsStr.= " " . $tag-&gt;getTag(); if(($key == 0 &amp;&amp; $count &lt; 1) || ($key == 0 &amp;&amp; $count &gt;1 &amp...
[]
[ { "body": "<pre><code>$tagsStr = implode(', ', array_map(function ($tag) { return $tag-&gt;getTag(); }, $product-&gt;getTags()-&gt;toArray()));\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T18:33:21.967", "Id": "56961", ...
{ "AcceptedAnswerId": "35194", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T17:58:22.290", "Id": "35189", "Score": "1", "Tags": [ "php", "strings" ], "Title": "Building a string made easier?" }
35189
Pong is an early tennis arcade game that features simple two-dimensional graphics.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T18:08:37.743", "Id": "35191", "Score": "0", "Tags": null, "Title": null }
35191
A control structure used to loop over a set of instructions, which operates as long as a particular condition is met.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T18:52:48.960", "Id": "35197", "Score": "0", "Tags": null, "Title": null }
35197
<p>I would like to refactor this code a bit further and make it better and more generic.</p> <p>As of right now, it is doing what I want it to do (reading a list of URL's, splitting the query and the ampersand and writing the split into appropriately named files). However, I would like to take the hash list out and ma...
[]
[ { "body": "<p>This is only partly an answer, intended more as a thought exercise about what you might do. I provide a couple examples that you might want to pick and choose parts of, but you probably will not want to just grab the whole. So let's dive in.</p>\n\n<p>What would benefit from this being more genera...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T19:33:55.960", "Id": "35198", "Score": "0", "Tags": [ "python", "parsing", "url", "file" ], "Title": "Reading and writing an unknown character into an appropriately named file...
35198
<p>In programming, annotations are used to add information to a code element which cannot be expressed by the type system.</p> <h2>In Java</h2> <p>Sources: <a href="http://docs.oracle.com/javase/tutorial/java/annotations/" rel="nofollow">Oracle docs</a>, <a href="http://en.wikipedia.org/wiki/Java_annotation" rel="nof...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T20:42:21.260", "Id": "35201", "Score": "0", "Tags": null, "Title": null }
35201
In programming, annotations are used to add information to a code element which cannot be expressed by the type system.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T20:42:21.260", "Id": "35202", "Score": "0", "Tags": null, "Title": null }
35202
<p>I am fairly new to Python coding, although I have been coding on and off for 30ish years. I am sure I am writing Python with too much influence from the other languages, such as REXX, VB, and some Powershell.</p> <p>Maybe I should use more functions? Please let me know where the following the code is straying from...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T22:42:04.450", "Id": "56974", "Score": "8", "body": "If you have two separate pieces of code to review, I think you should post them as two separate posts." } ]
[ { "body": "<p>Where are your functions? I see three large chunks of loops and if/elif/else blocks, but absolutely 0 functions.</p>\n\n<p>Just because python is a scripting language, doesn't mean you should treat it as one. This is a piece of work that you created, not a one-off script that you will throw away a...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T20:45:00.570", "Id": "35203", "Score": "-5", "Tags": [ "python", "beginner", "networking", "file-system" ], "Title": "TV guide program and client server with sockets" }
35203
<p>I am new to database design but am fairly familiar with SQL and its syntax. I want to create a database for an e-commerce website that will sell a single product type such as a shirt. They could be different sizes, colors, and design. I formulated list of information I thought would be necessary to collect from a vi...
[]
[ { "body": "<p>You need to add foreign keys that reference the primary keys of the tables they are linked to. </p>\n\n<p>I don't usually do a whole lot with building the actual tables but I know that you are missing the foreign keys.</p>\n\n<p>In this Table:</p>\n\n<blockquote>\n<pre><code>CREATE TABLE `shipping...
{ "AcceptedAnswerId": "35545", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T20:55:00.887", "Id": "35204", "Score": "4", "Tags": [ "beginner", "sql", "mysql", "e-commerce" ], "Title": "E-commerce database design" }
35204
<p>The task is to add data or values to members of a given <code>enum</code> class. The compiler should check if a value for each <code>enum</code> member is available, and not just the default constructor empty values. It is a tool to verify that no values are forgotten during a change.</p> <p>The interface is modele...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T23:10:58.037", "Id": "56978", "Score": "4", "body": "One common solution for this kind of problems is to use [X-macros](http://en.wikipedia.org/wiki/X_Macro). Well used, you know that the number of elements will be the same." }, ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T22:34:32.510", "Id": "35208", "Score": "20", "Tags": [ "c++", "c++11", "library", "enum", "template-meta-programming" ], "Title": "Building a good C++11 template library -...
35208
<p>This program takes blank spaces before some chars like > &lt; />, and if there is more than one blank space in the line, it will reduce to one.</p> <pre><code>return source.replaceAll("\\s{2,}", " ").replaceAll("[[\\&gt;][\\s]][[\\s][\\&gt;]]", "&gt;").replaceAll("[[\\&lt;][\\s]][[\\s][\\&lt;]]", "&lt;").replaceAll...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T00:16:49.367", "Id": "56982", "Score": "7", "body": "Why do you need this? If you have a decent XML-parser then does it really matter how many spaces there are before `>`-characters? Because you **DO** use a XML-parser to parse your...
[ { "body": "<p>This will suffice:</p>\n\n<pre><code>source.replaceAll(\"\\\\s+([&lt;&gt; ]|/&gt;)\", \"$1\");\n</code></pre>\n\n<p><img src=\"https://www.debuggex.com/i/di6o0MQJ9GZe1NlZ.png\" alt=\"Regular expression visualization\"></p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", ...
{ "AcceptedAnswerId": "35228", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-11T23:47:28.887", "Id": "35210", "Score": "1", "Tags": [ "java", "regex", "xml" ], "Title": "Reducing number of blank spaces" }
35210
<p>There are some blocks in my code.</p> <p>To make it easier to read, I often append comment after the end</p> <p>such as </p> <pre><code> end # end upto end # fileopen </code></pre> <p>Because sometimes the indentation still not easy for read.</p> <p>Is there any better practice?</p> <p>And my indentation is...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T00:04:17.093", "Id": "56988", "Score": "3", "body": "Refactor for readability. The trailing comments are irritating and do nothing for readability, they only detract." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate...
[ { "body": "<p>Compare your code to how I'd write it:</p>\n\n<pre><code>require \"faker\"\n\nreal_sn = 2124100000\n\nFile.open(\"lib/tasks/tw_books.txt\", \"r\").each do |line|\n# author = Faker::Lorem.words(2..5).join(' ').gsub('-','').gsub('\\s+','\\s')\n\n 1.upto(1000).each do |x|\n\n location = Faker::Lo...
{ "AcceptedAnswerId": "35213", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T00:02:34.620", "Id": "35212", "Score": "2", "Tags": [ "ruby" ], "Title": "How to make the end of loop more readable in Ruby" }
35212
<p>I need to concatenate a bunch of delimited text files. In the process, I need to add a new column to the data based on part of the name of one of the directories containing each file. The script works, but I have a feeling that it is inelegant in the extreme.</p> <p>In particular, I'm wondering whether I should be ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T08:43:00.760", "Id": "57004", "Score": "3", "body": "Just do `next(reader)` to skip the header." } ]
[ { "body": "<p>There is some repetition between your header-reading routine and the rest of the code. You could incorporate it into the main loop to remove that duplication and avoid opening the first file twice. You already use <code>next(reader)</code> nicely to read the header; use the same technique to ski...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T08:10:01.577", "Id": "35218", "Score": "5", "Tags": [ "python", "beginner", "python-3.x" ], "Title": "Script for concatenating delimited text files" }
35218
<p>I was referred here from StackOverflow, so here is what I posted over there:</p> <p>So, for an assignment, I have to construct a binary search tree, plus an assortment of related functions. I have them all working, but I'm looking for a way to optimize my way of finding in-order predecessors and successors. Here's ...
[]
[ { "body": "<p>CodeReview is a good place for this question....</p>\n\n<p>There are a few things that you should consider...</p>\n\n<h2>Style</h2>\n\n<p><code>node</code> is a bad name for a Java class. Standards for Java are that Class names are CamelCase, and your <code>node</code> class should be called <code...
{ "AcceptedAnswerId": "35225", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T08:20:09.227", "Id": "35219", "Score": "2", "Tags": [ "java", "optimization", "homework", "tree" ], "Title": "In-order Predecessor BST review" }
35219
<p>I'm building a hash table for this problem:</p> <blockquote> <p><strong>Implement a class for storing a set of integers:</strong></p> <pre><code>class FixedSet { public: FixedSet(); void Initialize(const vector&lt;int&gt;&amp; numbers); bool Contains(int number) const; }; </code></pre> <p>After ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T20:39:12.797", "Id": "57181", "Score": "0", "body": "Ann, I don't understand why the code of Bucket is more or less repeated in FixedSet. I guess I am being stupid, but can you please explain." }, { "ContentLicense": "CC BY...
[ { "body": "<p>I tried running your implementation on my machine but with the following input (input is 25 random integers within the interval <code>[0; 10^9]</code>) <code>Initialize</code> never completes (it's stuck in the bucket <code>while (flag)</code> loop):</p>\n<pre><code>25\n882868245\n264589055\n95566...
{ "AcceptedAnswerId": "35284", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T08:27:02.283", "Id": "35220", "Score": "13", "Tags": [ "c++", "performance", "homework", "hash-map" ], "Title": "Perfect Hashing Implementation" }
35220
<p>I have written a common class for finding display sizes in pre-honeycomb and for the latest versions of Android. Could anyone review my code and suggest possible modifications for this code?</p> <pre><code>import android.annotation.TargetApi; import android.content.Context; import android.graphics.Point; import and...
[]
[ { "body": "<p>First of all, this line:</p>\n\n<pre><code>if (Integer.valueOf(android.os.Build.VERSION.SDK_INT) &lt; 13) {\n</code></pre>\n\n<p>Should be replaced with this:</p>\n\n<pre><code>if (Build.VERSION.SDK_INT &lt; Build.VERSION_CODES.HONEYCOMB_MR2) {\n</code></pre>\n\n<p>Because a) There's no need to us...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T10:04:11.683", "Id": "35222", "Score": "4", "Tags": [ "java", "android" ], "Title": "Getting display size compact class in Android" }
35222
<p>This is one of the first RSpec tests I've written, and I'm not really sure what the best practices are etc. </p> <p>My question basically is: what would you do differently? What is good? What is bad?</p> <p>The complete code can be found <a href="https://gist.github.com/asmand/d1ccbcd01789353c01c3" rel="nofollow">...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T22:17:14.783", "Id": "57084", "Score": "2", "body": "@CMW [There are reasons why we close questions that just link to code instead of editing the question for the OP.](http://meta.codereview.stackexchange.com/q/467/2041)" }, { ...
[ { "body": "<h1>Spec</h1>\n\n<h2>The Good</h2>\n\n<p>There's not much here that needs changing. </p>\n\n<ul>\n<li>You only check one condition per <code>it</code> or <code>specify</code></li>\n<li>Good use of <code>let</code>, <code>subject</code>, <code>before</code>, etc. to keep the test DRY and simple.</li>...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T11:15:08.110", "Id": "35223", "Score": "4", "Tags": [ "ruby", "rspec" ], "Title": "Weekly flex calculator" }
35223
<p>My question is for validation of my code (any loop holes / bugs) and guidance the best methodology to implement for my requirement.</p> <p>I am developing a Python application that will have many classes. We need to communicate in between each class - pass data. It would be very clumsy if across all classes I crea...
[]
[ { "body": "<p>I don't see why you need a singleton. You are already passing around container references as parameters. So, if you only create one container in <code>__main__</code> and pass that to the class instances, they will all be accessing the same container.</p>\n\n<p>Instead of calling <code>Singleton()...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T11:56:48.217", "Id": "35226", "Score": "0", "Tags": [ "python", "classes", "singleton", "container" ], "Title": "Creating a singleton container class for intrer-class messagin...
35226
<p>I'm adding a function to my test library to assist in testing if two <code>IDictionary</code> objects contain the same keys/values.</p> <p>I need the method to be generic and support a dictionary that has collections as values. So I thought I'd try to do it without using class types.</p> <p>It <em>appears</em> to ...
[]
[ { "body": "<p>Your code doesn't work, because items in a dictionary aren't ordered in any way.</p>\n\n<p>Example code that fails your test:</p>\n\n<pre><code>dictionary(\n new Dictionary&lt;int, int&gt; { { 0, 0 }, { 1, 1 } },\n new Dictionary&lt;int, int&gt; { { 1, 1 }, { 0, 0 } });\n</code></pre>\n\n<p>...
{ "AcceptedAnswerId": "35255", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T17:15:11.390", "Id": "35233", "Score": "4", "Tags": [ "c#", "unit-testing", "hash-map" ], "Title": "Test if two IDictionary objects contain the same values" }
35233
<p>I'm currently working on a BMI calculator and just wondered if there was a shorter or more condensed version of doing the <code>if</code> validating statement.</p> <p>I have currently done it this way for both Height and Weight, but I find it to be a mess and it seems to cluttered. There must be a way of shortening...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T18:36:10.267", "Id": "57034", "Score": "0", "body": "That's not a natural way of asking for height. Users should be able to enter height as 5'9\", for example, and the computer should parse it. It would also simplify the code." },...
[ { "body": "<p>What about some while blocks?</p>\n\n<pre><code>int heightft = 0;\nboolean validHeight = false;\ndo {\n height = scanner.nextInt();\n validHeight = heightft &gt;=2 &amp;&amp; heightft &lt;=7;\n} while( !validHeight );\n</code></pre>\n", "comments": [ { "ContentLicense": "CC...
{ "AcceptedAnswerId": "35240", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T18:32:13.950", "Id": "35235", "Score": "7", "Tags": [ "java", "validation" ], "Title": "Shorter way of prompting for a height of x feet y inches?" }
35235
<p>I'm wondering what people think about Dependency Injection vs Service Locator patterns. Specifically I'm using Prism with MEF. I'm also using the MVVM pattern.</p> <p>So I have a service which I export. I also have a class which doesn't export its class type as I don't need that to be registered with MEF. This clas...
[]
[ { "body": "<ol>\n<li><p><a href=\"http://blog.ploeh.dk/2010/02/03/ServiceLocatorisanAnti-Pattern/\" rel=\"noreferrer\">Service locator is an anti-pattern</a> because it tends to create implicit dependencies which are not easy to see and usually cause grieve when trying to write unit tests. Especially your imple...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T20:05:50.090", "Id": "35247", "Score": "5", "Tags": [ "c#", "dependency-injection" ], "Title": "Looking for advice - Dependency Injection over Service Locator in Mef" }
35247
<p>I'm kind of new to C++ and was just wondering if anyone could give me tips on how I could make my code more efficient (I added some comments to the code to help you understand it better).</p> <p>Is it a good idea to use <code>switch</code> <code>case</code>s? Is there a way I can use more functions/arrays/pointers?...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T20:21:31.483", "Id": "57061", "Score": "1", "body": "Right off the bat, `srand()` should go in `main()`. If you call it repeatedly (such as where you have it now), you'll receive the same random values each time." }, { "Con...
[ { "body": "<p>Since there aren't any loops in your code that aren't waiting for the user to provide some input, it's probably way premature to talk about efficiency. Is your code measurably slow? Does it leave you hanging? If not, unless you have an unusual need, save questions on efficiency for later.</p>\n\n<...
{ "AcceptedAnswerId": "35273", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T20:09:05.063", "Id": "35248", "Score": "7", "Tags": [ "c++", "beginner", "random", "game" ], "Title": "Roulette game in C++" }
35248
<p>I did most of my PHP coding back with PHP 4, and among the projects I did was a popular pagination class. I've been meaning to bring it up to date with PHP 5 and OOP practices. I've also been working on updating my database code, using PDO over the deprecated mysql* functions. What I'd like from you is your input an...
[]
[ { "body": "<p>Okay, I’m going to list anything and everything that came in my mind while reading your code.</p>\n\n<ol>\n<li>Start documenting your code for better maintainability</li>\n<li>Validate every and any user input</li>\n<li>Use proper camelCase notation for property and method names</li>\n<li>Separate...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T21:09:27.773", "Id": "35251", "Score": "1", "Tags": [ "php", "object-oriented", "classes", "pdo", "pagination" ], "Title": "Critique Requested on PHP Pagination Class" }
35251
<p>This copies the level graphics but uses a scale parameter. If the scale is 1, it copies a screen size segment. If it's 2, it copies a half-screen size piece and scales it to the screen size, etc.</p> <p>How can I optimise this game level code or achieve the same outcome but simpler?</p> <pre><code> public void ren...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T01:01:07.703", "Id": "57093", "Score": "1", "body": "Can you provide a bit more code? Where the screenwidth, screenheight, wherex, wherey, halfpwidth and halfpheight variables are declared? Where else they are used? What is their in...
[ { "body": "<p>First, lets eliminate the <code>test</code> and <code>test2</code> variables, which are uneeded (we already have <code>scaledstartx</code> and <code>scaledstarty</code>). Second keep <code>screenwidth/2</code> and <code>screenheight/2</code> in variables to avoid recalculating it over and over (th...
{ "AcceptedAnswerId": "35266", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T22:40:52.487", "Id": "35258", "Score": "2", "Tags": [ "java", "game", "graphics" ], "Title": "Platform game rendering method" }
35258
<p>I recently wrote a code for a encoder and decoder that works off of a key and the only way to decode the message is with this program and the case-sensitive key. I have yet to incorporate punctuation but that will come soon. I am currently designing a GUI using the Tkinter module. I would love any feedback.</p> <p...
[]
[ { "body": "<h3>Concept</h3>\n\n<p>Interesting idea to use the pseudo-random number generator seed as an encryption key. Note, however, that there's no guarantee that the PRNG implementation will be consistent from release to release of Python, or that it will act identically across platforms. The same goes fo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T22:47:19.630", "Id": "35259", "Score": "3", "Tags": [ "python", "strings" ], "Title": "Successful Encoder and Decoder for messages" }
35259
<p>I recently wrote a small demo that allows users to send and receive files from an HTML5 Javascript application. It's all client-side. I thought this would be a good place to get feedback about what I've done.</p> <p>It's hosted here: <a href="http://danielsadventure.info/HTML5FileDemo/" rel="nofollow">http://dani...
[]
[ { "body": "<p>Your code looks fine to me,</p>\n\n<p>I would probably have <code>aceInputXml</code>, <code>aceInputXslt</code> and <code>aceOutputXml</code> be properties of 'editors'.</p>\n\n<p>Then you could slightly rewrite setupAce as</p>\n\n<pre><code>function setupAce() \n{\n var key;\n editors = \n {\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-12T23:26:30.563", "Id": "35263", "Score": "1", "Tags": [ "javascript", "html5", "file" ], "Title": "HTML5 File API Demo" }
35263
<p>I am an artist and a total beginner in C++.</p> <p>I would like to find a better method of importing my variables from a <code>values.txt</code> file, which may contain 18 values in one column:</p> <pre><code>63.64474122 5.214728341 0.405110193 0.261556475 -2.00743E-09 2.76001E-10 34.45902482 15.62249852 0.2208616...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T03:43:35.713", "Id": "57215", "Score": "0", "body": "As a fly-by comment, it seems like this should possibly be something like a `struct xydmct { double x, y, d, m, c, t; }` with appropriate constructor, `operator>>` and `operator<<...
[ { "body": "<p>Storing the data in 18 independent variables is awkward. The naming of your variables suggests that each group of six <code>double</code>s represents an object, which I've called a <code>Sexdoublet</code>.</p>\n\n<p>Throwing all the code into <code>main()</code> is poor practice; there should be ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T01:29:59.053", "Id": "35265", "Score": "2", "Tags": [ "c++", "beginner", "io" ], "Title": "Better importation of variables from .txt file" }
35265
<p>I wrote a python function that writes a integer to a file in binary form. But are there any ways that I can reduce the number of steps, is there a more efficient way to write a integer to a file?</p> <pre><code>def IntWrite(FileName, Integer): #convert to hexadecimal data = str('{0:0x}'.format(Integer)) ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T03:02:29.693", "Id": "57102", "Score": "2", "body": "This is more of a SO question. See [struct](http://docs.python.org/dev/library/struct.html#module-struct).pack, struct.unpack, in this case with a format character of `i` or `I`, ...
[ { "body": "<p>Python comes with a built-in <a href=\"http://docs.python.org/3/library/pickle.html\" rel=\"nofollow\"><code>pickle</code></a> module for serialization:</p>\n\n<pre><code>&gt;&gt;&gt; import pickle\n&gt;&gt;&gt; with open('data', 'wb') as f: pickle.dump(9 ** 33, f)\n&gt;&gt;&gt; with open('data', ...
{ "AcceptedAnswerId": "35291", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T01:55:56.453", "Id": "35267", "Score": "4", "Tags": [ "python", "file", "integer", "serialization", "io" ], "Title": "Writing integer to binary file" }
35267
<p>I'm looking for bugs. I tried to test all functionality in a variety of ways.</p> <pre><code>#by JB0x2D1 from decimal import Decimal import math import numbers import operator from fractions import Fraction class Mixed(Fraction): """This class implements Fraction, which implements rational numbers.""" ...
[]
[ { "body": "<h3>1. Bugs</h3>\n\n<p>Your doctests do not pass:</p>\n\n<pre class=\"lang-none prettyprint-override\"><code>$ python3.3 -mdoctest cr35274.py\n**********************************************************************\nFile \"./cr35274.py\", line 76, in cr35274.Mixed.__new__\nFailed example:\n Mixed(M...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T04:19:59.353", "Id": "35274", "Score": "4", "Tags": [ "python", "rational-numbers" ], "Title": "Mixed number fractions class" }
35274
<p>This code works 100%, but I am trying to see if I can use a <code>for</code>-statement to make my second method less-cumbersome and more efficient instead of making so many variables. </p> <p>I have to show the differences between each quarter for every department.</p> <p>My array has 6 Departments and 4 Quarters....
[]
[ { "body": "<p>Refactoring should get you there</p>\n\n<pre><code> total1 = dept1Qrt1 - dept1Qrt2;\n total2 = dept1Qrt2 - dept1Qrt3;\n total3 = dept1Qrt3 - dept1Qrt4;\n System.out.println( \" \\n The Quarterly Differences For Department-1 is :\");\n System.out.println( \" *************************...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T06:01:14.177", "Id": "35276", "Score": "6", "Tags": [ "java", "beginner", "array" ], "Title": "Reporting quarterly changes for each department" }
35276
<p>Please review this JavaScript text editing webapp. Review the code quality. Give me suggestions to simplify the code.</p> <pre><code>var textarea = document.getElementById("textarea"), statusBar = document.getElementById("status-bar"), inputFile = document.getElementById("input-file"), appname = "Notepad", ...
[]
[ { "body": "<ul>\n<li><p>First of all, you should declare all of these in it's own scope, not in the global scope. That way, other code (or your own code) won't collide with naming. A simple IIFE would do:</p>\n\n<pre><code>(function(){\n //All code in here\n}());\n</code></pre></li>\n<li><p>Your code assumes t...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T07:02:06.247", "Id": "35280", "Score": "1", "Tags": [ "javascript" ], "Title": "JavaScript text editing webapp" }
35280
<p>I have the following set. <code>a = [1,2,3,4,5]</code> and i want to find all of the following sequences of consecutive elements:</p> <pre><code>1, 1,2 1,2,3 1,2,3,4 1,2,3,4,5 2, 2,3, 2,3,4, 2,3,4,5 3, 3,4 3,4,5 4 4,5 5 </code></pre> <p>This is the following code that I use and works correctly. My only problem is ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T12:17:50.493", "Id": "57124", "Score": "0", "body": "Do you just want to print them out, or do you want them stored in `all`." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T12:19:23.560", "Id": "...
[ { "body": "<p>You cannot get better than <code>O(n²)</code> because the result has the size of <code>O(n²)</code></p>\n\n<p>The Output has <code>(n+1)*n/2</code> elements therefore you will always need <code>O(n²)</code> time to do the output.</p>\n\n<p>You can only try to reduce the constant factor.</p>\n", ...
{ "AcceptedAnswerId": "35300", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T12:10:58.420", "Id": "35289", "Score": "1", "Tags": [ "c++", "complexity" ], "Title": "Find all consecutive sequences in an ordered set" }
35289
<p>Last week I posted a piece of code to apply Dijkastra algorithm to calculate the shortest path between to nodes in a graph. Now, I've made some improvements, but I am still having difficulties.</p> <p>I have a class <code>Graph</code> that is going to be constructed by two other classes. A vector of elements are ...
[]
[ { "body": "<p>According to the rules of this site, we don't fix non-working code. However, I think that this question deserves a response anyway, since problems with your programming style are a major impediment to reaching a solution. To be frank, the snippet you emphasized looks overwhelming.</p>\n\n<p>You ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T12:44:49.820", "Id": "35290", "Score": "2", "Tags": [ "c++", "algorithm", "graph" ], "Title": "Applying Dijkastra's algorithm on a graph of five nodes" }
35290
<p><a href="http://en.wikipedia.org/wiki/ColdFusion_Markup_Language" rel="nofollow">CFML</a> is the main scripting language for the <a href="/questions/tagged/coldfusion" class="post-tag" title="show questions tagged &#39;coldfusion&#39;" rel="tag">coldfusion</a> web application platform. In addition to Adobe's ColdFus...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T17:17:50.180", "Id": "35301", "Score": "0", "Tags": null, "Title": null }
35301
CFML is the main scripting language for the ColdFusion web application platform. In addition to Adobe's ColdFusion server, CFML code can also run on the JVM, the .NET framework, Google App Engine, Railo, New Atlanta BlueDragon, and Open BlueDragon. Use this tag for code written in CFML, and add other tags for the targe...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T17:17:50.180", "Id": "35302", "Score": "0", "Tags": null, "Title": null }
35302
<p>Which of the following is better coding style and why?</p> <pre><code>print("We have x = %i" %x) print("We have x = "+str(x)) </code></pre>
[]
[ { "body": "<p>Your first example was better. <code>print(\"We have x = %i\" %x)</code> because you are working with a string object. It takes less memory than working with 2 string objects and an int.</p>\n\n<p>Since you are asking with a python3 tag, here is a newer format for python string formatting using s...
{ "AcceptedAnswerId": "35305", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T17:23:19.207", "Id": "35303", "Score": "-2", "Tags": [ "python", "python-3.x" ], "Title": "Best way to print the value of a variable?" }
35303
<p>How can I write a better database query wrapper?</p> <pre><code>//code for connection exports.connect = function(callback) { client.connect(function(err, conInfo){ if (err) callback(err); conInfo = "Connection at " + client.host + ":" + client.port + "/" + client.database + " used b...
[]
[ { "body": "<p>I don't do JS, even less <code>node.js</code>, but from the looks of it you seem to be taking in a <code>string</code> for your query, which means client code can do something like <code>\"select x, y, sum(z) from mytable where x = \" + someValue + \" group by x, y\"</code> - which is prone to SQL...
{ "AcceptedAnswerId": "35709", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T18:42:23.877", "Id": "35306", "Score": "2", "Tags": [ "javascript", "sql", "node.js" ], "Title": "SQL database query wrapper" }
35306
<p>I am writing non-blocking code as it should be in Node.JS. If I want run function A after B I do it using callback.</p> <p>But I find <a href="http://nodeguide.com/style.html" rel="nofollow">this</a> style guide:</p> <blockquote> <p>Use closures, but don't nest them. Otherwise your code will become a mess.</p>...
[]
[ { "body": "<p>as a personal preference I like the \"Right\" way that you have listed. it looks cleaner to me. </p>\n\n<p>On the other hand I see lots of Java and JavaScript where they have nested functions that are not used anywhere else in the code, personally I don't like this, it looks way to complicated an...
{ "AcceptedAnswerId": "35325", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T18:49:32.563", "Id": "35307", "Score": "4", "Tags": [ "javascript", "node.js", "error-handling", "closure" ], "Title": "Writing a user's profile image to disk using nested ...
35307
<p>PROMELA is a process modeling language whose intended use is to verify the logic of parallel systems. Given a program in PROMELA, the SPIN model checker can verify the model for correctness by performing random or iterative simulations of the modeled system's execution, or it can generate a C program that performs a...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T19:40:20.120", "Id": "35311", "Score": "0", "Tags": null, "Title": null }
35311
PROMELA (Process or Protocol Meta Language) is a process modeling language whose intended use is to verify the logic of parallel systems.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T19:40:20.120", "Id": "35312", "Score": "0", "Tags": null, "Title": null }
35312
<p>I have an application which currently uses AJAX for CRUD operations on a simple <code>Person</code> object. The following script works fine, but I'm looking for some pointers on how to structure my code. Currently, I have four methods for CRUD operations, and I'll extend my <code>person</code> module as needed, bu...
[]
[ { "body": "<p>Right, I'm on a break, so this is just a few pointers to help you along. I'll probably get back to this answer and add some more details in days to come...</p>\n\n<p>the first thing I noticed is that you declared your <code>person</code> module somewhere half-way your <code>ready</code> callback f...
{ "AcceptedAnswerId": "35338", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T22:21:03.733", "Id": "35316", "Score": "5", "Tags": [ "javascript", "jquery", "design-patterns" ], "Title": "JavaScript Module Pattern with AJAX" }
35316
<p>I must implement a simple <a href="http://en.wikipedia.org/wiki/Caesar_cipher" rel="noreferrer">Caesar cipher</a> class. Initializer takes two parameters - number of positions to shift the alphabet (integer) and the alphabet used (as string, not necessarily the standard English alphabet). The class must have two ins...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T23:18:32.530", "Id": "57193", "Score": "0", "body": "`Caesar.new(1).encrypt('1337')` → `NoMethodError: undefined method \\`+' for nil:NilClass`. The parameter may be invalid, but the error message should be more helpful." } ]
[ { "body": "<p>The only (conceptual) problem I see in your code is that both <code>encrypt</code>/<code>decrypt</code> perform a O(n) operation (<code>detect</code>) for every character (so at then end it's a O(n*m) algorithm), that's unnecessarily inefficient. Build a hash object to use as an indexer:</p>\n\n<p...
{ "AcceptedAnswerId": "35501", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T22:34:37.517", "Id": "35317", "Score": "8", "Tags": [ "ruby", "caesar-cipher" ], "Title": "Caesar cipher in Ruby" }
35317
<p>Release 10 of Adobe's <a href="/questions/tagged/coldfusion" class="post-tag" title="show questions tagged &#39;coldfusion&#39;" rel="tag">coldfusion</a> platform (Codenamed: Zeus) was released on May 15, 2012. New or improved features available in all editions include:</p> <ul> <li>Security enhancements</li> <li>H...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T23:49:16.777", "Id": "35319", "Score": "0", "Tags": null, "Title": null }
35319
A tag for code targeting release 10 of Adobe's ColdFusion platform.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T23:49:16.777", "Id": "35320", "Score": "0", "Tags": null, "Title": null }
35320
<p>The question is:</p> <blockquote> <p>Each new term in the Fibonacci sequence is generated by adding the previous two terms.<br> By starting with 1 and 2, the first 10 terms will be:</p> <p>1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... </p> <p>By considering the terms in the Fibonacci sequence whose values...
[]
[ { "body": "<p>Assuming you want to stick with a minimalist for-loop implementation, it could be simplified by using Python's simultaneous assignment feature to eliminate a variable and perform the \"swap\" gracefully. Of course, the question does not require you to produce the even-valued items of the Fibonacc...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T00:28:15.127", "Id": "35322", "Score": "10", "Tags": [ "python", "project-euler", "fibonacci-sequence" ], "Title": "Project Euler Question #2: Sum of even Fibonacci numbers under ...
35322
<blockquote> <p>You will prompt a user for a month, a day and a year. You will then tell the user how many days since January 1 of that year the input date is. For example if the user inputs a 3 for the month, a 2 for the date, and 2000 for the year the program outputs the number of days as being 62. Note 200...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T04:20:52.803", "Id": "57218", "Score": "1", "body": "Looks better! I'm not sure if you're still encountering issues or asking for more code (both are off-topic), but I could still provide a few pointers." }, { "ContentLicen...
[ { "body": "<p>Your code could use a lot of work, but it should be easier to clean up the algorithmic things after getting the language cleaned up. I'll go after the \"obvious\" things for now, which is still a good start.</p>\n\n<ul>\n<li><p><a href=\"https://stackoverflow.com/questions/1452721/why-is-using-na...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T04:08:11.223", "Id": "35326", "Score": "1", "Tags": [ "c++", "datetime" ], "Title": "Telling the user the number of days it's been since January 1st" }
35326
<p>I've just posted this <a href="/a/35330/9357">solution</a> in my review of @adrienlucca's question, which is to read three rows of six tab-separated doubles.</p> <pre><code>#include &lt;fstream&gt; #include &lt;iostream&gt; #include &lt;string.h&gt; #include &lt;vector&gt; struct Sexdoublet { double x, y, d, m...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T08:52:07.363", "Id": "57229", "Score": "0", "body": "If you primarily need to check for a successful `in` when looping, do you still need to check the `push_back()`? I'll admit I've never seen the latter being used like that before...
[ { "body": "<p>the first use can be replaced with:</p>\n\n<pre><code>while(in &gt;&gt; s) {\n data.push_back(s)\n}\n</code></pre>\n\n<p>the second case is much more readable with a simple if else:</p>\n\n<pre><code>std::ifstream f;\nif(argc &gt;= 2 &amp;&amp; 0 != strcmp(\"-\", argv[1])) {\n f.open(argv[1]...
{ "AcceptedAnswerId": "35333", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T08:35:12.773", "Id": "35331", "Score": "7", "Tags": [ "c++", "c++11", "error-handling", "io" ], "Title": "Reading three rows of six tab-separated numbers" }
35331
<p>I am a total novice to web development, but I am trying to be a WordPress developer and have been actively at it for some weeks now. All self-taught with the world's best tool as my aid: the internet. Anyway, I was hoping that you guys could look at my (no doubt: shoddy) code and tell me what you think I could do to...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T16:09:28.243", "Id": "57306", "Score": "1", "body": "Can you provide the generated HTML? Template code isn't very useful outside of your project (ie. I can't run it in a site like jsfiddle.net or codepen.io to see how it works)." ...
[ { "body": "<p>One thing that I can see is that you are not consistent with the units you use for measurement on padding, margins you should be consistent with this as different browsers will display <code>%</code> and <code>px</code> differently. </p>\n\n<p>I have heard that you should always try to use <code...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T10:19:22.303", "Id": "35335", "Score": "6", "Tags": [ "css", "wordpress" ], "Title": "Evaluate a Contact Form CSS" }
35335
<p>I recently worked with an architect who structured his base class like this:</p> <pre><code>public abstract class Base&lt;T&gt; { public abstract T Get(int id); internal T InternalGet(int id, IRepository&lt;T&gt; repository) { // Do more magic return repository.Get(id); } } </code></p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T11:49:16.920", "Id": "57239", "Score": "4", "body": "This question appears to be off-topic because it is not **your** code that you are asking to have reviewed" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "201...
[ { "body": "<p>The problem with building a good base class is that ideally, you should know exactly what kind of functionality will the derived classes need from the base class.</p>\n\n<p>If you think they'll need more than is actually necessary, you'll write more code unnecessarily and it will also make the bas...
{ "AcceptedAnswerId": "35346", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T11:12:31.010", "Id": "35337", "Score": "9", "Tags": [ "c#", "design-patterns", "dependency-injection", "inheritance" ], "Title": "Why would I want to always have to explici...
35337
<p>Trying to return the below values from an RSS feed. I have sorted out the RSS feed side of things but I am not sure if what I am doing is the best way to extract the data that I need. I have looked at beautifulsoup and regex's, re.search but not sure what is the best way to do this. </p> <p>Values that I need; (bo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T05:08:40.790", "Id": "57242", "Score": "0", "body": "And.. what's the question? What do you want us to find?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T05:17:31.410", "Id": "57243", "Scor...
[ { "body": "<p>You can do the whole thing with a single regexp:</p>\n\n<pre><code>import re\n\ndata = \"\"\"\n&lt;p&gt;Fire Danger Ratings\n&lt;br /&gt;Bureau of Meteorology \nforecast issued at: Mon, 4 Nov 2013 05:30 AM&lt;/p&gt;\n\n&lt;p&gt;Central: LOW-MODERATE&lt;/p&gt; \n\"\"\"\n\nrgx = re.compile(\...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T04:59:35.633", "Id": "35339", "Score": "3", "Tags": [ "python" ], "Title": "extract string from body of text" }
35339
<p>Is there a shorter or maybe a cleaner way of doing:</p> <blockquote> <p>Using your <code>is_prime?</code> method, write a new method, <code>primes</code> that takes a (non-negative, integer) number <code>max</code> and returns an array of all prime numbers less than <code>max</code>.</p> </blockquote> <pre><code...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-09-28T08:48:20.667", "Id": "193921", "Score": "0", "body": "Yes, there is an algorithm that works 300x faster than one you described, see full details: http://stackoverflow.com/questions/26792960/why-doesnt-my-ruby-coding-for-finding-prim...
[ { "body": "<p>Here it is using <a href=\"http://www.ruby-doc.org/stdlib-1.9.3/libdoc/prime/rdoc/Prime.html#method-i-prime-3F\" rel=\"nofollow\"><code>Prime#prime?</code></a>:</p>\n\n<blockquote>\n <p>Suppose I want to get all the prime numbers less than <code>9</code></p>\n</blockquote>\n\n<pre><code>require '...
{ "AcceptedAnswerId": "35342", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T06:24:08.547", "Id": "35340", "Score": "3", "Tags": [ "ruby", "primes" ], "Title": "Printing out prime numbers from an array given a max number" }
35340
<p>Let <code>a,b,c</code> be a boolean value. I need to print all values of expression <code>a &amp;&amp; b &amp;&amp; c</code>. I'm writing the class</p> <pre><code>public class BooleanTriple{ private boolean a,b,c; public BooleanTriple(boolean a, boolean b, boolean c){ this.a =a; this.b=b; this.c=c;} /*...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T15:57:58.263", "Id": "57257", "Score": "2", "body": "`Does it work?`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T15:58:23.890", "Id": "57258", "Score": "0", "body": "I don't understand...
[ { "body": "<p>I'll give you a hint. Think of a &amp;&amp; b &amp;&amp; c as a 3 digit binary number </p>\n\n<p>So all possibles values will be:</p>\n\n<pre><code>a | b | c\n0 | 0 | 0\n0 | 0 | 1\n0 | 1 | 0\n0 | 1 | 1\n1 | 0 | 0\n1 | 0 | 1\n1 | 1 | 0\n1 | 1 | 1\n</code></pre>\n\n<p>As you can see, you want to fli...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T15:55:35.557", "Id": "35347", "Score": "1", "Tags": [ "java" ], "Title": "All values of boolean-triple" }
35347
<p>I am having a slight issue here, i am trying to think of a faster way of finding two elements from 2 different lists that match. The problem is that if i have lists which both have 1000 elements ( rules ) and the very last one [index.1000] matches then in order to find it i have to loop through booth lists from top ...
[]
[ { "body": "<p>Too long for a comment, so, your <code>match</code> function can be shortened to this:</p>\n\n<pre><code>public ContextRule match(Context messageContext, ContextRuleList contextRules) {\n for(ContextRule contextRule : contextRules) {\n if(this.match(messageContext, contextRule)) {\n ...
{ "AcceptedAnswerId": "35370", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T13:19:09.800", "Id": "35357", "Score": "3", "Tags": [ "java", "performance" ], "Title": "Trying to find a better way of finding something rather then looping through list from top ...
35357
<p>The overall question is: I need feedback on the security of the idea and the script. Do I need to do more in raw code, or is this ok, taking into account my other information?</p> <ol> <li><p>Let's assume these following first:</p> <ul> <li>All images are stored on a subdomain (e.g. <code>images.example.com</cod...
[]
[ { "body": "<p>First thing I would consider is using functions so that it becomes easier readable.</p>\n\n<pre><code>function hasAllowedExtension($filename); // returns bool\nfunction isAllowedType($filetype); // returns bool\n</code></pre>\n\n<p>That way you can shorten the first lines to</p>\n\n<pre><code>$fil...
{ "AcceptedAnswerId": "35363", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T13:38:47.623", "Id": "35359", "Score": "1", "Tags": [ "php", "security" ], "Title": "Secure file upload example" }
35359
<p>Using ARC, I'm calling the following function in an iOS app every time the app gets opened in the <code>applicationDidBecomeActive</code> function.</p> <p>My concern is that it could create a memory leak because it's creating new instances of <code>UIViewControllers</code> every time the app gets opened from the ba...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T09:49:14.900", "Id": "57386", "Score": "0", "body": "I don't think so, though it might depend on if the view deck controller retains the web view controller. simple way to check though: run in instruments" } ]
[ { "body": "<p>This code doesn't appear to leak. To be sure, however, you should use the <code>leaks</code> instrument to periodically check your code. </p>\n\n<p>To do such,</p>\n\n<ol>\n<li>Select Product -> Profile (or, ⌘ I)</li>\n<li>Choose `Leaks`</li>\n<li>Select Profile</li>\n<li>Exercise your app (i.e. g...
{ "AcceptedAnswerId": "37086", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T13:51:11.897", "Id": "35360", "Score": "4", "Tags": [ "objective-c", "ios", "memory-management" ], "Title": "applicationDidBecomeActive: Am I causing a memory leak?" }
35360
<p>I've implemented the following code which allows me to bolt modules of code on to my core library via the prototype chain. It's quite prescriptive so any user creating a module has to create an init method and also has to define a queue method:</p> <p>(working fiddle: <a href="http://jsfiddle.net/wG9Pv/" rel="noref...
[]
[ { "body": "<p>Looks fine to me,</p>\n\n<p>I would consider making extend a property of prototype though.</p>\n\n<p>For nitpickings, I think</p>\n\n<pre><code>function Test() {\n this.tester = 'The instance was successfully created';\n};\n</code></pre>\n\n<p>is preferred to </p>\n\n<pre><code>test = function(...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T16:23:01.313", "Id": "35367", "Score": "8", "Tags": [ "javascript" ], "Title": "A simple javascript plugin architecture" }
35367
<p>As an exercise, I have implemented a linked queue whose <code>enqueue</code> and <code>dequeue</code> methods are synchronized. There is a <code>Producer</code> thread which keeps inserting elements into the queue as long as there are less than 10 items in it. When the queue is full, the thread waits. The second thr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T18:50:08.577", "Id": "57320", "Score": "1", "body": "`public boolean isEmpty() { return first == null; }` needs to be synchronized otherwise it could have a stale version of `first`." } ]
[ { "body": "<p>It is apparent that you have put some thought in to this implementation, and apart from the not-synchronized isEmpty() method, it all looks functional.</p>\n\n<p>I have some minor nit-picks though, and please bear in mind that these are just my opinion...</p>\n\n<p>I prefer to have the notifyAll m...
{ "AcceptedAnswerId": "35382", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T18:06:38.893", "Id": "35371", "Score": "6", "Tags": [ "java", "algorithm", "multithreading", "thread-safety" ], "Title": "Thread safe enqueue and dequeue method in Queue" }
35371
<p>This is the <code>CalculatorAdvanced</code> Kata from the Kata gem. I've just finished it and would love some feedback on my solution.</p> <blockquote> <pre class="lang-none prettyprint-override"><code>CalculatorAdvanced Kata Add Method Allow the expression to handle new lines between numbers - ...
[]
[ { "body": "<p>I am not going to re-write your code but give some pointers instead, I hope it's helpful:</p>\n\n<ul>\n<li>Those four methods (<code>add</code>, ...) do basically the same thing, why don't you abstract them?</li>\n<li><code>inject</code> accepts a symbol: <code>@values.inject(:+)</code></li>\n<li>...
{ "AcceptedAnswerId": "35431", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T18:21:01.920", "Id": "35372", "Score": "2", "Tags": [ "ruby", "calculator", "math-expression-eval", "rspec" ], "Title": "Advanced Calculator Kata" }
35372
<p>I'm a mediocre programmer at best and am pretty terrible at JavaScript. But I have been tasked with creating a Google Maps application. This application is driven by a dynamic report with a Java layer on top of it. This Java layer spits out generated Google API JavaScript. </p> <p>The problem I am running into is ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T21:09:09.087", "Id": "57329", "Score": "0", "body": "To clarify… you expect that sometimes there may be `circles[0]`, `circles[1]`, … `circles[999]` as well as many `balloons[]` and `txtMark[]`? Do the `balloons[]` and `txtMark[]` a...
[ { "body": "<p>I can't really speak to performance issues, since there are too many unknowns. E.g. oes the user need 1000+ locations all at once? What is acceptable performance?<br>\nI will say that simply loading everything (<em>and</em> the kitchen sink) and plotting it all seems pretty inelegant. But coming u...
{ "AcceptedAnswerId": "35480", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T18:45:42.143", "Id": "35374", "Score": "0", "Tags": [ "javascript", "beginner", "serialization", "google-maps" ], "Title": "Generating redundant data for Google Maps marker...
35374
<p><a href="http://wordpress.org/about/" rel="nofollow">http://wordpress.org/about/</a></p> <p>WordPress is a blogging platform most commonly used with PHP and MySQL</p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T19:05:39.560", "Id": "35376", "Score": "0", "Tags": null, "Title": null }
35376
WordPress is a free and open source blogging tool and a content-management system (CMS) based on PHP and MySQL.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T19:05:39.560", "Id": "35377", "Score": "0", "Tags": null, "Title": null }
35377
<p>I have a “featured projects” view that requires its subviews conform to a non-uniform grid: one narrow column with 3 items, then one wide column with 2 items, followed by another narrow column with 3 items. The width that is used for each subview is determined by the model’s <code>display</code> attribute. If there ...
[]
[ { "body": "<p>This looks pretty good. My main suggestion for improvement would be we how you set and create the columns. I would try and make this more dynamic so the amount of columns can more easily change, and can be set from code using this view. </p>\n\n<p>To do this I'd create an array to represent the co...
{ "AcceptedAnswerId": "35615", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T19:56:38.930", "Id": "35378", "Score": "2", "Tags": [ "javascript", "coffeescript", "backbone.js" ], "Title": "Backbone subviews with non-uniform layout" }
35378
<p>dapper is a micro-ORM, offering core parameterization and materialization services, but (by design) not the full breadth of services that you might expect in a full ORM such as LINQ-to-SQL or Entity Framework. Instead, it focuses on making the materialization <em>as fast as possible</em>, with no overheads from thin...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T19:56:46.540", "Id": "35379", "Score": "0", "Tags": null, "Title": null }
35379
dapper is the micro-ORM for .NET developed and used by the stackoverflow team, focusing on raw performance as the primary aim.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T19:56:46.540", "Id": "35380", "Score": "0", "Tags": null, "Title": null }
35380
<p>I'm trying to convert an <code>std::string</code> to an <code>int</code> with a default value if the conversion fails. C's <code>atoi()</code> is way too forgiving and I've found that <code>boost::lexical_cast</code> is quite slow in the case where the cast fails. I imagine it's because an exception is raised. I do...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T16:45:14.977", "Id": "57424", "Score": "1", "body": "Hi, regarding [this suggested edit](http://codereview.stackexchange.com/review/suggested-edits/14356), feel free to add your *bullet-proof* solution as another answer - editing ot...
[ { "body": "<p>There's a few things that jump out at me both in your implementation and standard options you missed. A few (scattered) thoughts follow.</p>\n\n<hr>\n\n<p>Returning a default if you care about error checking doesn't make sense. How would you determine if conversion failed if there's not an integer...
{ "AcceptedAnswerId": "35454", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T22:59:55.020", "Id": "35388", "Score": "6", "Tags": [ "c++", "converting", "boost" ], "Title": "Converting std::string to int without Boost" }
35388
<p>How can I make this program run faster? On enter, I have a string from the console. For example:</p> <pre><code>1 1 7 3 2 0 0 4 5 5 6 2 1 </code></pre> <p>On exit, it will be</p> <pre><code>6 20 </code></pre> <p>Could you recommend a way to make this run faster?</p> <pre><code>import java.io.BufferedReader; i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T00:21:42.240", "Id": "57346", "Score": "4", "body": "Welcome to Code Review! Can you please describe what the program does?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T00:39:09.623", "Id": "57...
[ { "body": "<p>Yeah, without giving too much away (this is obviously homework)....</p>\n\n<p>First though, the assumption I make is that the assignment is:</p>\n\n<ol>\n<li>find the length of the longest series of either increasing, or decreasing numbers</li>\n<li>sum the values in this longest sequence.</li>\n<...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-14T23:21:46.533", "Id": "35390", "Score": "0", "Tags": [ "java", "performance", "strings", "homework", "console" ], "Title": "Processing a string from the console" }
35390
<p>I wrote a chatbot in Ruby for <a href="http://turntable.fm" rel="nofollow">turntable.fm</a>, a chatroom where users can listen to music together. It interacts with users in a room, who can type in specific keywords and get responses from it. It also enforces some rules. For example, if people playing music go AFK fo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-17T17:37:53.107", "Id": "57658", "Score": "2", "body": "I don't have much time to build an elaborate answer, but here's my two cents : first, much of the data you store in the state should be the responsibility of the room queue ; for ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T00:19:09.043", "Id": "35392", "Score": "3", "Tags": [ "ruby", "design-patterns", "event-handling" ], "Title": "Encapsulating behavior spread across multiple event handlers" }
35392
<p>Please review my strstr implementation. This is an interview question that does not allow the use of <code>strlen()</code>. Is there a better way than using a boolean below?</p> <pre><code>#include &lt;iostream&gt; #include &lt;cstring&gt; char* my_strstr(char * s1, const char *s2) { if ( s1 == NULL || s2 == NULL...
[]
[ { "body": "<p>Yep.</p>\n\n<p>You implemented the standard brute force implementation. </p>\n\n<p>Personally I think that is fine. For some silly reason though a lot of interviewers expect you to swat up on string manipulation for interviews and want you to know the non brute force versions off the top of your ...
{ "AcceptedAnswerId": "35407", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T00:42:34.150", "Id": "35396", "Score": "7", "Tags": [ "c++", "strings", "interview-questions" ], "Title": "strstr implementation" }
35396
<p>Please review my answer for this interview question:</p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; std::vector&lt;int&gt; merge2Sorted ( std::vector&lt;int&gt; left, std::vector&lt;int&gt; right ) { //finger matching algo auto itLeft = left.begin(); auto itRight = right.begin(); auto i...
[]
[ { "body": "<p>Pass your parameters by const reference to avoid a copy:</p>\n\n<pre><code>std::vector&lt;int&gt; merge2Sorted(std::vector&lt;int&gt; const&amp; left, std::vector&lt;int&gt; const&amp; right)\n// ^^^^^^ ^^^^^^\n</code></pre>\n\n<p>...
{ "AcceptedAnswerId": "35402", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T01:01:50.620", "Id": "35397", "Score": "4", "Tags": [ "c++", "c++11", "interview-questions", "vectors", "mergesort" ], "Title": "Merge two sorted arrays together" }
35397
<p>I'm learning backbone.js in parallel with unit testing. I've just made a simple model and wanted to unit test it. Do I have the right idea? I am simply making a model with some default values.</p> <pre><code>Person = Backbone.Model.extend({ defaults: { name: "fetus", age: 0, child: '' }, initialize...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-08-31T17:24:19.697", "Id": "111928", "Score": "0", "body": "I think that it's an awesome approach to learning Backbone, that is, to learn how to unit test it simultaneously as you learn it. Now, to take a step back, I don't think that you...
[ { "body": "<p>If your <code>Person</code> was initialized with a name other than \"fetus\", your test would fail.. but your test has <em>several reasons for failing</em> and that's what makes it not-so-good: that same test would also fail if a <code>Person</code> was \"born\" with a child (!) or if <code>age</c...
{ "AcceptedAnswerId": "35436", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T02:24:38.430", "Id": "35399", "Score": "4", "Tags": [ "javascript", "unit-testing", "backbone.js" ], "Title": "First ever unit test. Am I headed in the right direction?" }
35399
<p>Case 1_a:</p> <pre><code> zip_file = file.sub(directory, '').sub!(/^\//, '') zipfile.add( zip_file, file) </code></pre> <p>Case 1_b:</p> <pre><code> zipfile.add( file.sub(directory, '').sub!(/^\//, ''), file) </code></pre> <p>Case 2 : If the String contains lots of parameters , I prefer write in an ...
[]
[ { "body": "<p>Case 1_a. Don't mix pure functions (<code>sub</code>) with destructive functions (<code>sub!</code>). Whenever possible use pure methods:</p>\n\n<pre><code>zip_file = file.sub(directory, '').sub(/^\\//, '')\nzipfile.add(zip_file, file)\n</code></pre>\n\n<p>But can't you write simply?</p>\n\n<pre><...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T03:16:05.490", "Id": "35400", "Score": "4", "Tags": [ "ruby" ], "Title": "Coding style in Ruby format in an method and variable assign" }
35400
<p>I have tried to comment my code as much as I can. If you have any questions about it, please feel free to ask. The code itself should have a lot of details and the comments mostly explain what is going on. The task description is in the code.</p> <pre><code>#pragma config(Sensor, dgtl1, allowButton, sensorTouc...
[]
[ { "body": "<p><strong>Program design issues:</strong></p>\n\n<ul>\n<li><p>Do not ever use global variables. In this case, the variables <code>contestantsAllow</code> and so on should be declared locally in main, because there is no reason to have them in the global namespace.</p>\n\n<p>Had you been using a more...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T03:21:10.030", "Id": "35401", "Score": "1", "Tags": [ "c", "game" ], "Title": "ROBOTC Jeopardy program" }
35401
<p>I wrote some very basic R code.</p> <p>This has at least two problems.</p> <ol> <li><p>It uses a very basic imperative-programming style instead of good R style.</p></li> <li><p>It draws the result as an ellipse, not a circle. This effect is barely visible on RGui on Windows, but extremely visible in RStudio on L...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-21T21:19:37.400", "Id": "58469", "Score": "1", "body": "fix for Problem 2: `image(gg, asp=1)`" } ]
[ { "body": "<p>A vectorized solution using <code>outer</code> (Outer Product of Arrays):</p>\n\n<pre><code>edge &lt;- 100\nmagicradius &lt;- .81\nmagicmargin &lt;- .01\nwidth &lt;- (2*edge) + 1\n\nx &lt;- -edge:edge\ny &lt;- -edge:edge\n\nmat &lt;- outer(x, y, function(x,y) sqrt(x^2 + y^2))\nind &lt;- mat &gt; (...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T06:34:31.220", "Id": "35404", "Score": "2", "Tags": [ "r" ], "Title": "Basic graphical R code draws an ellipse instead of a circle" }
35404
<p>Here is the code that I am using on a website's contact form:</p> <p>HTML file:</p> <pre><code> &lt;form name="ajax-form" id="ajax-form" action="php-file.php" method="post"&gt; &lt;label for="name"&gt;Name: * &lt;span class="error" id="err-name"&gt;please enter name&lt;/span&gt; &lt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-16T20:37:07.010", "Id": "57542", "Score": "1", "body": "Does `cleanupentries` also clean up newlines? Otherwise it would be trivial to inject additional headers into the outgoing mail." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>Your code is safe as far as I can tell. You may consider adding some additional levels of spam checking though to stop invalid requests sooner. </p>\n\n<ol>\n<li>Use a token generated by your server when the form renders, pass that to php-file.php to check when processing the submission, if it isn...
{ "AcceptedAnswerId": "35524", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T06:53:56.100", "Id": "35405", "Score": "2", "Tags": [ "php", "security", "ajax" ], "Title": "Is this contact form safe?" }
35405
<p>I have a Lua project that uses some syntax sugar described in <a href="http://lua-users.org/wiki/DecoratorsAndDocstrings" rel="nofollow">DecoratorsAndDocstrings</a>, near the bottom of the page. It looks like this:</p> <pre class="lang-lua prettyprint-override"><code>random = docstring[[Compute random number.]]...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T07:39:33.480", "Id": "35408", "Score": "4", "Tags": [ "lua" ], "Title": "Can this \"syntax sweetener\" be improved?" }
35408
<p>I am making a filter to get posts by status that are saved by post metavalue in a Wordpress plugin. It is a question and answer system, where the question and answer are post objects.</p> <pre><code> // Filter post where function posts_where( $where ) { global $wpdb, $dwqa_general_settings; switch ( $t...
[]
[ { "body": "<p>I remember answering a question that was similar to this one, in that it also needed a stored procedure.</p>\n\n<p>this code could use several stored procedures. I don't know how sprocs work in MySQL but I assume that you can still code them.</p>\n\n<p>it looks to me like you are trying to write ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T07:52:23.817", "Id": "35409", "Score": "2", "Tags": [ "php", "mysql", "plugin", "wordpress" ], "Title": "Wordpress filter post by metavalue" }
35409
<p>I have a script, which updates my table's column and writes an id to it.</p> <p>I need to check whether the column is empty or not. If it is not, I add a <code>,</code>.</p> <pre><code>$subs = mysql_fetch_array(mysql_query("SELECT subscribed_user_id FROM users WHERE user_id=".(int)$_GET['user'])); $subs_array = ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T09:30:10.190", "Id": "57384", "Score": "1", "body": "I don't really understand what you're trying to do? Just add a , if the column is not empty? Why? Your script is also prone to SQL injections." }, { "ContentLicense": "CC ...
[ { "body": "<p>With regard to your question about adding <code>,</code>, just do</p>\n\n<pre><code>$new_user_id = $_COOKIE['user_id'];\n\nif ($subs['subscribed_user_id'] === '') {\n $new_user_id = $subs['subscribed_user_id'] . ',' . $new_user_id;\n}\n</code></pre>\n\n<p>With that said, the details of how you ad...
{ "AcceptedAnswerId": "35428", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T08:50:47.713", "Id": "35422", "Score": "1", "Tags": [ "php", "mysql" ], "Title": "How to improve my PHP adding script?" }
35422
<p>I have this<code>Point</code> Class:</p> <pre><code>public class Point { private final int CONSTANT_VALUE = 0; private int _x; private int _y; public Point(int x, int y) { _x = x; _y = y; } public Point(Point other) { _x = other._x; _y = ot...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T10:10:43.537", "Id": "57390", "Score": "0", "body": "I personally prefer the short if, if the code is so short: `_x = x < 0 ? CONSTANT_VALUE : x;`, but this is a matter of taste. But By the way, CONSTANT_VALUE is not defined anywher...
[ { "body": "<ul>\n<li><p>There looks to be a bug in <code>setY</code>: it assigns to <code>_x</code> instead of <code>_y</code>.</p></li>\n<li><p>This code can avoid aliasing problems on small classes like <code>Point</code> by making them immutable. That is, remove the <code>setX</code> and <code>setY</code> me...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T09:55:08.827", "Id": "35424", "Score": "2", "Tags": [ "java" ], "Title": "Aliasing in Set and Get?" }
35424
<p>I would like to know if my chosen layout is HTML5 standards compliant, or if I'm using the heading tags incorrectly (or any other tag for that matter)?</p> <p><strong>Main Header</strong></p> <ul> <li><code>&lt;h1&gt;</code> for website name</li> <li><code>&lt;h2&gt;</code> for webpage name</li> <li><code>&lt;h3&g...
[]
[ { "body": "<p>In HTML5 <code>h1</code> elements can be treated as relative to their semantic container, so it is not bad practice to have an <code>h1</code> as the main page header text <em>and</em> further <code>h1</code>'s for each <code>section</code>, <code>aside</code>, <code>article</code>, etc.</p>\n\n<p...
{ "AcceptedAnswerId": "35460", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T10:06:55.770", "Id": "35425", "Score": "4", "Tags": [ "html", "css", "html5" ], "Title": "Is there anything incorrect about this layout, semantically or otherwise?" }
35425
<p>I am working on a Windows project using C++03 (C++11 is not an option), and without using Boost. I have several resources that are accessed by multiple threads at various times - a queue, for example, with data added by one thread and removed by another. Individual methods of the involved classes generally perform ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T14:31:05.860", "Id": "57412", "Score": "0", "body": "`std::vector appears to default-construct, then assign`. No It copy constructs into place. Because you have already created the object before the `push_back` is called." }, { ...
[ { "body": "<p>first I suggest you use <em>pointers</em> to keep the mutex reference; this makes it possible to have a non-owning state when the pointer is 0 (the state when default initialized)</p>\n\n<p>also you created a <strong>copy constructor</strong> and a <strong>destructor</strong>, so you still need a ...
{ "AcceptedAnswerId": "35433", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T11:08:07.337", "Id": "35430", "Score": "2", "Tags": [ "c++", "locking", "winapi", "c++03", "raii" ], "Title": "RAII-style lockable objects" }
35430
<p>Let's say I have a collection of expensive-to-generate objects stored in an IEnumerable: </p> <pre><code>IEnumerable&lt;Expensive&gt; expensiveObjects = CreateExpensiveIEnumerable(); </code></pre> <p>Now I will iterate over everything in <code>expensiveObjects</code> and afterwards, I want to know if it was em...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T18:26:41.597", "Id": "57436", "Score": "0", "body": "I'm confused, you say the objects are “stored” in the `IEnumerable` but you also don't want to iterate it twice, which looks like the objects are generated each time. So which one...
[ { "body": "<p>It depends on the type that's implementing your <code>IEnumerable</code>. Per <a href=\"https://stackoverflow.com/questions/13738329/how-does-tolist-on-an-ienumerable-work\">this Jon Skeet SO answer</a>, calling <code>.ToList()</code> doesn't automatically mean an enumeration.</p>\n\n<p>I'd make s...
{ "AcceptedAnswerId": "35455", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T17:55:38.170", "Id": "35442", "Score": "3", "Tags": [ "c#", "ienumerable" ], "Title": "Check IEnumerable Count" }
35442
<p>I want you to look the following code for validating dictionary schemas. There are some libraries out there that do the same thing, but I just wanted to write my own for fun and not to overload my current project with a big third party library.</p> <p>Feel free to comment regarding code optimization, duplication, A...
[]
[ { "body": "<h3>1. Error messages</h3>\n\n<p>The biggest problem with this code is that the error messages are useless. If the purpose is to validate data structures, then you have to think about what happens when validation fails. How easily are users going to be able to track down the cause of the problem?</p>...
{ "AcceptedAnswerId": "35486", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T18:50:50.850", "Id": "35446", "Score": "1", "Tags": [ "python", "unit-testing" ], "Title": "Remove duplication in python code for dict schema validation" }
35446
<p>I'm experimenting with std::future, but haven't found any materials that deal with the usecase I have in mind and was hoping someone could either confirm or deny the validity of the approach excerpted below:</p> <pre><code>class Thing { private: std::string mValue; public: Thing() : mValue( "" ) {} v...
[]
[ { "body": "<p>There are two things that concern me in the code you offer:</p>\n\n<ul>\n<li>The Thing instances pointed to by <code>tA</code>, <code>tB</code>, <code>tC</code> are leaked. In this case it looks like it would be trivial to address this by stack allocating them, and passing their address to the <co...
{ "AcceptedAnswerId": "35483", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T19:32:55.033", "Id": "35448", "Score": "3", "Tags": [ "c++", "c++11" ], "Title": "Using std::future to manipulate objects in C++11" }
35448
Prolog is the most commonly used logic programming language. It supports non-deterministic programming through backtracking and pattern matching through unification.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T20:26:58.077", "Id": "35451", "Score": "0", "Tags": null, "Title": null }
35451
<p>This is a program for converting Roman numerals to their decimal equivalents. There must be a better way of distinguishing between, for example, 'IV' and 'VI', than what I have currently written.</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; using namespace std; class romanType{ public: rom...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T21:49:23.423", "Id": "57458", "Score": "1", "body": "perhaps you should look at Enum" } ]
[ { "body": "<ul>\n<li><p><strong>Try not to use <a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\"><code>using namespace std</code></a> and <a href=\"https://stackoverflow.com/questions/1107705/systempause-why-is-it-wrong\"><code>system(\"PAUSE\")</code></a...
{ "AcceptedAnswerId": "35456", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T21:15:30.323", "Id": "35453", "Score": "15", "Tags": [ "c++", "homework", "converting", "roman-numerals" ], "Title": "Roman numerals to decimal" }
35453
<p><a href="http://www.microsoft.com/com/default.mspx" rel="nofollow">Component Object Model (COM)</a> specifies an architecture, a binary standard, and a supporting infrastructure for building, using, and evolving component-based applications. </p> <p>Some of the core features of COM are: </p> <ul> <li>A remoting ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-16T01:37:48.677", "Id": "35464", "Score": "0", "Tags": null, "Title": null }
35464
Component Object Model (COM) is a component technology from Microsoft, featuring remoting, language independence and interface-based programming.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-16T01:37:48.677", "Id": "35465", "Score": "0", "Tags": null, "Title": null }
35465
<p>I'm writing yet another MVC framework just for learning purposes and I would like you to review my code. Whenever I'm coding, I have that feeling that my code is horrible and is not the most efficient way to achieve something.</p> <p>Right now the request class takes a URL path from <code>ORIG_PATH_INFO</code> or f...
[]
[ { "body": "<p>From quick glance I see a lot of logic in the constructor, usually not recommended. </p>\n\n<p>I would also avoid hard-coded indices for segments and use regular expressions to parse the URLs. Basically the less hard-coded strings are in the code, the better. </p>\n\n<p>You can place them together...
{ "AcceptedAnswerId": "35548", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-16T12:02:55.997", "Id": "35478", "Score": "5", "Tags": [ "php", "mvc", "url-routing" ], "Title": "PHP router class" }
35478