body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>The following code is an implementation of heapsort on an array</p> <pre><code>public static void heapSort(int[] inputArray){ /* Creates an array A which will contain the heap */ /* A has size n+1 to allow 1-based indexing */ int n = inputArray.length; int[] A = new int[n+1]; int temp = 0; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-01T21:08:00.487", "Id": "74490", "Score": "2", "body": "Welcome to CodeReview.SE ! You are suppose to provide some actual working code to review. In your case, it seems to be pretty close to working so it would be really helpful if you...
[ { "body": "<p>Your constructHeap method works in O(n), and you call in O(n) times from removeMax method, so your code works in O(n^2), so it is not a correct implementation of Heapsort.</p>\n\n<p>Comments:</p>\n\n<pre><code>public static void heapSort(int[] inputArray) {\n</code></pre>\n\n<p>Why do you need ano...
{ "AcceptedAnswerId": "43168", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-01T20:29:55.610", "Id": "43165", "Score": "4", "Tags": [ "java", "algorithm", "performance" ], "Title": "Implementation of HeapSort" }
43165
<p>I'm pretty new to C# and have decided that I wanted to make a program that calculate the multiplication table of a selected number to practice on loops etc. I'm pretty satisfied, but I wondered if there is anything I can do to make the code better and more concise.</p> <pre><code>using System; using System.Collecti...
[]
[ { "body": "<p><code>int.Parse</code> will throw an exception if input isn't an integer. Consider using <code>int.TryParse</code> instead.</p>\n\n<p>You should verify that the user doesn't enter a negative integer for the 2nd argument.</p>\n\n<p>Your while loop should be a for loop.</p>\n\n<p>A multiplication is...
{ "AcceptedAnswerId": "43174", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-01T22:34:36.613", "Id": "43173", "Score": "8", "Tags": [ "c#", "beginner" ], "Title": "Simple C# multiplication table program" }
43173
<p>I am trying to learn how to tell if my code will be better off creating a class as opposed to using many functions. I am a new Python programmer trying to get the hang of when classes should be implemented.</p> <p>Determines whether the username is valid or invalid:</p> <pre><code>def is_good_user(user): is_us...
[]
[ { "body": "<p>It's a design choice.\nA class is \"meant to be\" a collection that encapsulates functionality and \"behavior\" in code. The purpose is to expose specifically an interface where a class's instances can live on their own. </p>\n\n<p>A function/method is an independent piece of code that in theory ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-01T23:20:23.817", "Id": "43175", "Score": "3", "Tags": [ "python", "beginner", "classes" ], "Title": "Using classes vs. using functions" }
43175
<p>I'm making a game in Java with LWJGL and I just implemented jumping. I don't really think the code is particularly well written or very efficient. Here is the code of my <code>Camera</code> class:</p> <pre><code>public void startJump(float height, float land){ jumpHeight = height; jumpLand = land; if(!f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-01T23:59:23.783", "Id": "74509", "Score": "2", "body": "You got bad performance? the code is good after all. A question: if a player is `jumping` `falling` will never be true? and if a player is `falling` `jumping` will never be true? ...
[ { "body": "<p>After your comment, the only change i could say is to change</p>\n\n<pre><code>private void jump(){ // called every frame\n if(jumping){\n if(y &gt;= -jumpHeight){\n y -= jumpSpeed;\n }else{\n jumping = false;\n falling = true;\n }\n }\n\...
{ "AcceptedAnswerId": "43187", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-01T23:50:52.937", "Id": "43179", "Score": "4", "Tags": [ "java", "opengl" ], "Title": "OpenGL first person jumping code" }
43179
<p>I'm working on a random number guessing game. I'm done with the code and it's working, but there is a part that I want to make better. I declared an instance of a <code>Guess</code> class I created, and now how to make this part more efficient.</p> <pre><code>int counter = 0; do { myGuess.UserGue...
[]
[ { "body": "<p>You can use a switch statement instead of if else if else if.</p>\n\n<p>You don't need to test if (counter &lt; 3) inside the do loop; instead you could exit the do loop when the count is too high.</p>\n\n<p>Similarly you could print the error message once if/after you exit the do loop unsuccessfu...
{ "AcceptedAnswerId": "43183", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T00:03:35.353", "Id": "43180", "Score": "6", "Tags": [ "c#", "game", "random", "console" ], "Title": "Random number guessing game" }
43180
<p>I am relatively new to the Qt framework and I was wondering if I should delete pointers in my program. I know that, in C++, if memory is not return it could lead to memory leak, but I am not sure if the same applies to Qt. </p> <pre><code>#include "mainwindow.h" #include &lt;QApplication&gt; #include &lt;QTextEdit...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T06:08:25.600", "Id": "74540", "Score": "2", "body": "ratchet freak's answer is more relevant (and correct) to your specific Qt question. You don't need to delete anything manually if it's parented." } ]
[ { "body": "<p>In Qt, there is a concept of parents and a hierarchy.</p>\n\n<p>In essence, it means that when a qobject owns another qobject (the other qobject's <code>parent</code> is the first) then the parent will take care of cleaning its children.</p>\n\n<p>There are 2 ways an object becomes a child of anot...
{ "AcceptedAnswerId": "43201", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T01:11:50.583", "Id": "43189", "Score": "9", "Tags": [ "c++", "memory-management", "qt" ], "Title": "Deleting pointers in Qt5" }
43189
<p>I'm more of an IT guy (no CS course) with a strong and passionate relationship with Unix and I love <a href="http://en.wikipedia.org/wiki/KISS_principle" rel="nofollow">KISS</a>.</p> <p>I'm writing an application to help my coworkers with their daily tasks. Every now and then I get request from coworkers to add fun...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T08:52:47.600", "Id": "74909", "Score": "0", "body": "There have been a number of comments on your Reddit thread that reference various things will be new to you. This resource is probably your best bet as a starting point: http://ww...
[ { "body": "<p>I wouldn't stress about tests if it's a smaller company, an internal application, and will not be distributed.</p>\n\n<p>Generally a framework is a good idea. It gives you everything that you're asking for.</p>\n\n<p>I'd recommend Yii for performance, but Cake because of its popularity, which make...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T01:16:53.010", "Id": "43190", "Score": "10", "Tags": [ "php", "object-oriented", "mvc", "file-structure" ], "Title": "Intranet PHP application" }
43190
<p>This code counts the number of nodes between any given two nodes in a circular linked list. Any feedback is appreciated:</p> <pre><code>public class CountNodesBetweenTwoNodes { Node first; Node fifth; private class Node&lt;Item&gt; { Item item; Node next; } public static void main(String[] args)...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T01:41:05.010", "Id": "74516", "Score": "3", "body": "4th should be \"fourth\" ;)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T01:55:22.487", "Id": "74517", "Score": "0", "body": "yeah! ...
[ { "body": "<p>Your program is really based only of case where you have 5 nodes. This make your code really hard to change if you want to have a \"list\" of node of a different size. </p>\n\n<ol>\n<li>The name of the class should represent a concept not an action, <code>CountNodesBetweenTwoNodes</code> could be ...
{ "AcceptedAnswerId": "43194", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T01:34:28.797", "Id": "43191", "Score": "7", "Tags": [ "java", "linked-list", "circular-list" ], "Title": "Counting number of nodes between two nodes" }
43191
<p><a href="http://en.wikipedia.org/wiki/MapReduce" rel="nofollow">MapReduce</a> is a programming model and an associated implementation for processing and generating large data sets. Users specify a map function that processes a key/value pair to generate a set of intermediate key/value pairs, and a reduce function th...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T04:15:34.707", "Id": "43197", "Score": "0", "Tags": null, "Title": null }
43197
MapReduce is an algorithm for processing huge datasets on certain kinds of distributable problems using a large number of nodes
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T04:15:34.707", "Id": "43198", "Score": "0", "Tags": null, "Title": null }
43198
<p><a href="http://meta.codereview.stackexchange.com/questions/1561/the-java-8-tag-here-to-stay">Please see this discussion in Meta</a>: There is some debate about whether this tag should exist.</p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T04:20:22.007", "Id": "43199", "Score": "0", "Tags": null, "Title": null }
43199
Java 8 - Release date in early 2014 - This tag is currently being discussed in Meta. Please see the tag Wiki text.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T04:20:22.007", "Id": "43200", "Score": "0", "Tags": null, "Title": null }
43200
<p>I'm doing a lexical analyzer for my programming language and I don't know if I'm doing it right. Can anyone can help me with this or suggest a better way of doing it?</p> <pre><code>#include&lt;stdio.h&gt; #include&lt;stdlib.h&gt; #include&lt;conio.h&gt; #include&lt;ctype.h&gt; #include&lt;string.h&gt; struct node...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T04:37:53.697", "Id": "74528", "Score": "1", "body": "Isn't this just C code? I don't think it should be tagged with [c++]. Also, `main()` should be `int`, not `void`." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
[ { "body": "<p>I think you're overcomplicating the problem by working a character at a time.</p>\n\n<ul>\n<li>Reading one character at a time using <code>getc()</code> is inefficient. You could fetch a bigger chunk at a time using <code>fread()</code>.</li>\n<li>Wrapping each character into a linked list node i...
{ "AcceptedAnswerId": "43206", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T04:35:23.433", "Id": "43202", "Score": "9", "Tags": [ "c", "homework" ], "Title": "Lexical analyzer for a programming language" }
43202
<p><a href="https://github.com/exebook/dnaof" rel="nofollow">https://github.com/exebook/dnaof</a></p> <p>I created this simple inheritance tool for JavaScript, could any one with deep knowledge in JavaScript prototyped inheritance review it?</p> <p>Here is the library itself:</p> <pre><code>kindof = function(K) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T07:27:07.420", "Id": "74548", "Score": "1", "body": "Just a tip, `__proto__` is non-standard. See here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto" }, { "ContentLicense": "CC...
[ { "body": "<p>From a once over, and borrowing from the comments:</p>\n\n<ul>\n<li><code>__proto__</code> is bad news, MDN mentions this in a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto\" rel=\"nofollow\">big red box of doom</a>.</li>\n<li>There is no m...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T06:15:27.460", "Id": "43208", "Score": "3", "Tags": [ "javascript", "inheritance" ], "Title": "dnaof() - inheritance made easy, my own make inheritance tool" }
43208
<p>I did an implementation of the Tonelli-Shanks algorithm as defined on Wikipedia. I put it here for review and sharing purpose.</p> <p><a href="http://en.wikipedia.org/wiki/Legendre_symbol" rel="nofollow">Legendre Symbol implementation</a>:</p> <pre><code>def legendre_symbol(a, p): """ Legendre symbol D...
[]
[ { "body": "<p>Good job! I don't have a lot to comment on in this code. You have written straightforward clear code whose only complexity stems directly from the complexity of the operation it is performing. It would be good to include some of your external commentary (such as the renames of <code>R</code> and <...
{ "AcceptedAnswerId": "43267", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T07:53:48.977", "Id": "43210", "Score": "14", "Tags": [ "python", "algorithm", "primes", "mathematics" ], "Title": "Tonelli-Shanks algorithm implementation of prime modular ...
43210
<p>I've been a PHP procedural programmer for several years but I'm trying to learn OOP and I'm getting a bit confused with some patterns and principles. I would appreciate it if you could give me some tips and advice.</p> <pre><code>interface LoginAuthenticator { public function authenticate(UserMapper $userMapper...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T08:57:25.857", "Id": "74553", "Score": "4", "body": "Please consider changing from MD5 hashing to PHP 5.5's [password_hash](http://us2.php.net/password_hash) (see Example 2, using as high a cost as your server can afford) and [passw...
[ { "body": "<p>You are right about your concerns regarding the mapper. A mappers job is to map, not to find. In this case its the job of a repository. The repository finds an entry in a database, uses the mapper to translate between the database fields and the model, and returns the model. I had some more detail...
{ "AcceptedAnswerId": "43314", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T08:16:08.840", "Id": "43211", "Score": "5", "Tags": [ "php", "object-oriented" ], "Title": "OOP UserAuthenticator Class" }
43211
<p>I made a function which creates <a href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve" rel="noreferrer">Bezier curves</a> of grade n. What do you think?</p> <pre><code>float interpolate(float n1, float n2, float prec) { return n1 + ((n2-n1) * prec); } std::vector&lt;Vector2f&gt; make_bezier(const std::vector...
[]
[ { "body": "<p>Just a few comments:</p>\n\n<pre><code>std::vector&lt;Vector2f&gt; make_bezier(const std::vector&lt;Vector2f&gt;&amp; anchors, double accuracy=10000.0)\n</code></pre>\n\n<p>You're using <code>float</code> for all your other floating point variables. Unless there's some <em>really</em> good reason ...
{ "AcceptedAnswerId": "43244", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T12:43:52.940", "Id": "43215", "Score": "16", "Tags": [ "c++", "c++11", "graphics" ], "Title": "Bezier curves of grade n" }
43215
<p>I have two snippets of code that I would like you to look at. I can't figure out which of the two is most efficient (or better practice, if applicable). I'm currently finding the row and column of a sprite in a sprite sheet in order to render it to the screen; which works find and dandy. However, I now have two algo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T15:42:24.587", "Id": "74573", "Score": "0", "body": "I am down-voting this because it's a) An \"A or B?\"-style question and b) because it is technically the exact same code (which you don't seem to be aware of), the only difference...
[ { "body": "<p>I prefer the first one, because having the named variable <code>numRows</code>:</p>\n\n<ul>\n<li>Certainly makes the code more \"self-documenting\": it's easier for me (the programmer) to understand what the algorithm is doing</li>\n<li>May make the code faster: because you only do the <code>floor...
{ "AcceptedAnswerId": "43220", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T12:54:47.493", "Id": "43216", "Score": "2", "Tags": [ "c++", "mathematics" ], "Title": "Two methods for finding a sprite in sprite sheet C++, which is better?" }
43216
<p>I need to test my new functionality by sending about 100 requests in one time.</p> <pre><code>public class MyTest { // ... @Test public void test() throws Exception { Runnable[] runners = new Runnable[size]; Thread[] threads = new Thread[size]; for(int i=0; i&lt;threads.length;...
[]
[ { "body": "<p>Your test case looks relatively comprehensive in the sense that, yes, it fires off the 100 concurrent threads, but, you ask &quot;how to make it more '<em>at the same time</em>' ?&quot;</p>\n<p>There are two aspects I can suggest:</p>\n<ul>\n<li>Use an <code>ExecutorService</code></li>\n<li>Use a ...
{ "AcceptedAnswerId": "43225", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T14:15:25.157", "Id": "43219", "Score": "6", "Tags": [ "java", "multithreading" ], "Title": "Sending n requests in one time" }
43219
<p>I have this Python program for calculating Leibniz of 'pi'. I am not able to shorten it more. Can anyone here optimise/shorten it?</p> <pre><code>s,a,b=0,[],[] for i in range(int(input())):a.append(input()) for x in a: for j in range(int(x)):s+=pow(-1,int(j))/((2*int(j))+1) b.append(s) s=0 for i in b:pr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T10:35:11.627", "Id": "74699", "Score": "4", "body": "Code golfing is off-topic for Code Review — see [help/on-topic]." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T10:38:00.210", "Id": "74700", ...
[ { "body": "<p>This is only micro optimization, I don't think it will make a difference, but here you go anyway:</p>\n\n<pre><code>b=[]\nfor i in range(int(input())):\n s=sum([pow(-1,j)/(2*j+1) for j in range(int(input()))])\n b.append(\"{0:.15f}\".format(s))\nfor x in b:print(b)\n</code></pre>\n\n<ul>\n<l...
{ "AcceptedAnswerId": "43224", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T15:10:38.657", "Id": "43222", "Score": "0", "Tags": [ "python", "python-3.x", "mathematics" ], "Title": "Calculating Leibniz of Pi" }
43222
<pre><code>def printTrg(rows): r1 = [1] r2 = [1, 1] trg = [r1, r2] r = [] if rows == 1: r1[0] = str(r1[0]) print(' '.join(r1)) elif rows == 2: for o in trg: for a in range(len(o)): o[a] = str(o[a]) print((' ')*(2-(a+1)), (' '.join(o...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T15:46:48.747", "Id": "74575", "Score": "0", "body": "Welcome to Code Review! It's an OK first question you have here, to make it even better you could provide example input/output of your program and explain a little bit what \"Pasc...
[ { "body": "<p>Some brief comments:</p>\n\n<ul>\n<li><p>Your variable names are quite short (often one letter), which makes the code harder to follow. Longer and more descriptive variable names would make it easier to read and debug (e.g., <code>trg</code> to <code>triangle</code>, <code>r1</code> to <code>row1<...
{ "AcceptedAnswerId": "43229", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T15:25:32.113", "Id": "43223", "Score": "10", "Tags": [ "python", "mathematics", "python-3.x", "console", "formatting" ], "Title": "Pretty-print Pascal's triangle" }
43223
<p>For a very simple databaseless website, I'm using an associative array to store logins like this:</p> <pre><code>$logins = array( 'user' =&gt; 'password', 'user2' =&gt; 'password2', ); </code></pre> <p>I check login attemps using this code:</p> <pre><code>$user = strtolower($_POST['username']); $pass = $_POST['pa...
[]
[ { "body": "<p>Storing passwords is a very bad idea; if the source-code somehow leaks or the server gets compromised somehow the passwords will be leaked. Only a <em>hash</em> of the password should be stored - so the code can check for a match but never actually retain the full password longer than required (a...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T16:06:31.890", "Id": "43226", "Score": "4", "Tags": [ "php", "array", "security", "form" ], "Title": "Checking login from associative array vulnerabilities" }
43226
<p>I am using the following code for calculating ranking and it is working great for not large data. But when it comes to large data, processing time takes almost a minute. Please can anyone suggest a better way or atleast a faster way to put the same mysql statement?</p> <pre><code> SELECT id, Names, TOTALSCORE, Rank...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T18:06:36.520", "Id": "74596", "Score": "0", "body": "Can we assume that id is indexed?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T18:15:46.390", "Id": "74597", "Score": "0", "body": "...
[ { "body": "<p>First, let's confirm the intention of your query. According to my interpretation, it ranks students according to the sum of their exam scores, best students first, but disqualifying anyone who has ever failed an exam by scoring lower than 33%. (Why does the disqualification rule exist? Does fai...
{ "AcceptedAnswerId": "43234", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T16:23:07.593", "Id": "43227", "Score": "1", "Tags": [ "performance", "mysql", "sql" ], "Title": "Performance problem: Ranking with ties and skipping rows on passmark condition"...
43227
<p>As part of learning C++, with special emphasis on C++11, I wanted to implement the equivalent of Boost's Variant (located <a href="http://www.boost.org/doc/libs/1_55_0/doc/html/variant.html">here</a>). My code is available at <a href="https://github.com/sonyandy/cpp-experiments/blob/master/include/wart/variant.hpp"...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T17:39:13.187", "Id": "74591", "Score": "0", "body": "Also per our help center, this is not the site for code that doesn't do what it is supposed to do. Does your code **work**?" }, { "ContentLicense": "CC BY-SA 3.0", "Cr...
[ { "body": "<p>There's a lot here, so I'm going to split my review into pieces. I want to start by just focusing on the metafunction section. Metafunctions may be short, but they're very powerful and important to get right - but in terms of correctness and usefulness.</p>\n\n<p>To start with:</p>\n\n<pre><code>t...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T17:26:44.443", "Id": "43230", "Score": "11", "Tags": [ "c++", "c++11", "template-meta-programming", "variant-type" ], "Title": "Clone of Boost Variant" }
43230
<p>I hacked together this little <a href="http://data.stackexchange.com/codereview/query/172183/more-than-one-answer-by-the-same-user">query on the Data Explorer</a></p> <p>The query finds questions where an answerer has posted two or more answers (which in itself is not necessarily a bad thing), it gives you the link...
[]
[ { "body": "<p><strong>General MySQL/MSSQL comparison</strong></p>\n\n<p>In regards to the rules for aggregate functions... you have <code>count(answer.id)</code> as one of your select values. As a consequence, you need a group by.</p>\n\n<p>The group by must consist of every value that is used as part of any no...
{ "AcceptedAnswerId": "43237", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T18:23:21.997", "Id": "43235", "Score": "8", "Tags": [ "sql", "stackexchange" ], "Title": "More than one answer by the same user" }
43235
<p>I wrote a little command line nerdy game, which helps you learn the basics of binary numbers. I would be happy to hear your comments:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;time.h&gt; #define CHARSIZE 10 void printbitssimple(int); void createbitsha...
[]
[ { "body": "<h1>Things you did well:</h1>\n\n<ul>\n<li><p>When you didn't take in parameters to a function, you declared them <code>void</code>.</p></li>\n<li><p>Good use of comments.</p></li>\n</ul>\n\n<h1>Things you could improve:</h1>\n\n<h3>Refactoring:</h3>\n\n<ul>\n<li><p>You can simplify your function <co...
{ "AcceptedAnswerId": "43242", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T18:54:56.210", "Id": "43238", "Score": "5", "Tags": [ "c", "game" ], "Title": "Binary numbers game" }
43238
<p>AWK is an interpreted programming language designed for text processing and typically used as a data extraction and reporting tool. It is a standard feature of most Unix-like operating systems. Awk was originally developed by Alfred Aho, Brian Kernighan and Peter Weinberger in 1977 and updated in 1985.</p> <p>When ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T21:03:55.110", "Id": "43250", "Score": "0", "Tags": null, "Title": null }
43250
AWK is an interpreted programming language designed for text processing and typically used as a data extraction and reporting tool.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T21:03:55.110", "Id": "43251", "Score": "0", "Tags": null, "Title": null }
43251
<p>I'm learning Python (coming from Java) so I decided to write KMeans as a practice for the language. However I want to see how could one improve the code and making it shorter and yet readable. I still find the code rather long. Also if you have comments regarding conventions or proper practices, I would really appr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-06T02:16:12.680", "Id": "75366", "Score": "0", "body": "From a mathematical standpoint, I don't think you should raise an exception if the number of clusters is not within the number of rows. Zero clusters would result in no clustering...
[ { "body": "<p>You use <code>vstack</code> a lot to build arrays row by row, with the additional complication of initializing the array variable to <code>None</code>, which needs a special case in your loops then. This complication could be avoided by intializing to zero-height 2D array instead, but in any case ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T21:21:43.297", "Id": "43253", "Score": "4", "Tags": [ "python", "numpy", "clustering" ], "Title": "KMeans in the shortest and most readable format" }
43253
<p>I've been doing a simple implementation of a to-do list to learn how to use Knockout.js. I would like a general review of what I've done so far (not much). It's my first application in JavaScript and I've never been very good at Html and CSS, so feel free to give a lot general good things to do, or not to do. </p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-05T13:48:14.080", "Id": "75216", "Score": "0", "body": "You can fairly easy save and load files using HTML5, so that would take care of your backend problem." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-...
[ { "body": "<p>Nice job.</p>\n\n<ol>\n<li><p>Try to load Todo.html without Todo.js. Such situation could happen after some incorrect changes. In my opinion it is better to show only initially required elements(inputs) by default.</p></li>\n<li><p>There is no need to use jquery and bootstrap.</p></li>\n<li><p>It ...
{ "AcceptedAnswerId": "43651", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T21:45:33.550", "Id": "43255", "Score": "20", "Tags": [ "javascript", "html", "knockout.js", "to-do-list" ], "Title": "Simple to-do list as a single page application" }
43255
<p>I am working through K&amp;R for review and I thought that I would write some of my own routines for conversion of binary strings to int and int to binary string. I realize this is reinvetning the wheel; I am just doing this for fun. Also, I am attempting to follow this coding style <a href="https://www.kernel.org/d...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T22:48:01.510", "Id": "74840", "Score": "2", "body": "I see that you have edited in your revised code into your question. That is fine, just understand that your revised code is unlikely to get a review, and that it would be better ...
[ { "body": "<p>In int2binstr the comment says, \"NULL returned on error check errno\" but you don't return NULL on error: instead you return a pointer to an empty string.</p>\n\n<p>Also, I find it unusual that int2binstr writes its result at the end of the passed-in buffer, instead of at the beginning.</p>\n\n<p...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T22:24:19.673", "Id": "43256", "Score": "7", "Tags": [ "c", "converting", "reinventing-the-wheel" ], "Title": "Binary string to integer and integer to binary string" }
43256
<p>Looking at the code, is this a proper example of encapsulation?</p> <p><strong>additionalComputer.php (class)</strong></p> <pre><code>&lt;?php /** Counts up the Number of Additional PC Options * and stores them into an array then sends them to the view. */ class additionalComputer { protected function ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T22:57:40.277", "Id": "74640", "Score": "0", "body": "Hi welcome to Code Review! We would need a more information on what your application is doing. This will help in reviewing your code." }, { "ContentLicense": "CC BY-SA 3.0...
[ { "body": "<p>Encapsulation is such an old term from the C++ days. Nowadays it's more <strong>SOLID</strong> principles that you should build your PHP code on.</p>\n\n<p>I'm going to say it in 2 different ways.</p>\n\n<ol>\n<li><p>Yes, it takes a bit of sense of Encapsulation. <em>However</em>, it's very messy...
{ "AcceptedAnswerId": "46083", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T22:38:59.733", "Id": "43257", "Score": "3", "Tags": [ "php", "object-oriented", "mvc", "laravel" ], "Title": "Simple application to experience encapsulation" }
43257
<p>I want to have a like system on my website on multiple pages like "news", "comments", "forum posts" etc. So I was wondering what was the best way to do it between:</p> <ul> <li>having like tables for each of my "modules" (news, comments...)</li> <li><p>having one table like :</p> <p>table: likes<br> id (int) | pag...
[]
[ { "body": "<p>This design violates <em>first normal form</em>, which is a concept that states that each data field should contain an atomic value (using type and ID together makes this a composite value).</p>\n\n<p>This makes certain types of queries more difficult, and you'll use more database space and suffer...
{ "AcceptedAnswerId": "43263", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-02T22:43:18.250", "Id": "43259", "Score": "0", "Tags": [ "php", "mysql" ], "Title": "Like system with MySQL on multiple types of pages" }
43259
<p>For CS class, I had to reverse the digits of an integer from the input. This is my solution:</p> <pre><code>System.out.println(new StringBuilder(new Integer(new Scanner(System.in).nextInt()).toString()).reverse().toString()); </code></pre> <p>My main question is this: is this too golfed?</p> <p>Obviously I could ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T00:13:29.047", "Id": "74648", "Score": "9", "body": "Well if you want all your program in one line this is excellent. If you want maintainable and readable code this is really not a good way to go!" }, { "ContentLicense": "C...
[ { "body": "<p>In Java, and in Code Review, the preference is for creating both highly readable, and highly efficient code.</p>\n\n<p>It is an almost bizarre fact, that one leads to the other.</p>\n\n<p>your code has one efficiency, and that is space-on-disk.... it is neither readable, nor high-performance.</p>\...
{ "AcceptedAnswerId": "43264", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T00:03:41.580", "Id": "43261", "Score": "15", "Tags": [ "java", "strings" ], "Title": "Reversing the digits of an integer" }
43261
<p>I'd already asked for my code to be reviewed earlier here</p> <p><a href="https://codereview.stackexchange.com/questions/42514/first-chess-project">First Chess project</a>)</p> <p><a href="https://github.com/darkryder/Chess-python" rel="nofollow noreferrer">Full code</a></p> <p>Considering the suggestions put for...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T00:45:01.203", "Id": "74662", "Score": "2", "body": "As a first impression, I would say get rid of all the [magic numbers](http://stackoverflow.com/questions/47882/what-is-a-magic-number-and-why-is-it-bad) in your code." }, { ...
[ { "body": "<p>This code seems much better than before, so congrats. Here are a few more things to adjust:</p>\n\n<ol>\n<li><p>Move your main game loop into a function and call it in an if block like this:</p>\n\n<pre><code>if __name__ = \"__main__\":\n #call your main function\n</code></pre>\n\n<p>This is so...
{ "AcceptedAnswerId": "43702", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T00:12:49.147", "Id": "43262", "Score": "3", "Tags": [ "python", "pygame" ], "Title": "First Chess Project (ver 1.1)" }
43262
<p>I've been trying to understand the original MVC implementation (<a href="http://heim.ifi.uio.no/~trygver/2003/javazone-jaoo/MVC_pattern.pdf" rel="nofollow">the Xerox Parc's one</a>). I'm sure it has flaws, but it's simple code to practice/learn the original MVC.</p> <p><a href="http://jsfiddle.net/2D4ST/" rel="nofo...
[]
[ { "body": "<p>I am assuming you are used to getters/setters because you are experienced in another language, please don't do this. Performance matters, there is no good reason to download all those functions for no good reason, <code>model-person.js</code> should be</p>\n\n<pre><code>var ModelPerson = (function...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T00:43:47.123", "Id": "43265", "Score": "3", "Tags": [ "javascript", "design-patterns", "mvc", "controller" ], "Title": "Xerox Parc MVC implementation" }
43265
<p>I was just writing code, and wanted to make a piece that removes everything after the character <code>?</code> if it's found within the URL.</p> <pre><code>if (strstr($url, "?")) { $url = strstr($url, "?", true); } </code></pre> <p>Can I make this any shorter? It doesn't feel right to type the "same thing" twi...
[]
[ { "body": "<p>You're using the same variable for two different purpose. It would be readable with separate variables:</p>\n\n<pre><code>$urlWithoutParameters = strstr($url, \"?\", true); \nif ($urlWithoutParameters !== FALSE) {\n // if you need additional processing\n}\n</code></pre>\n\n<p>It might be safer ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T02:29:11.987", "Id": "43269", "Score": "3", "Tags": [ "php", "strings", "url" ], "Title": "Removing everything after a certain character" }
43269
<p>I've two working ways to do so, but which one should I use?</p> <p>Common part: <code>var textarea = document.getElementById("textarea");</code></p> <p>First way:</p> <pre><code>function updateStatusBar() { var text = textarea.value; statusBar.value = "Words: " + (text ? text.match(/\b\S+\b/g).length : "0...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T10:34:54.083", "Id": "74698", "Score": "0", "body": "I would strongly recommend you, to count your characters by using something like: `textarea.innerText.length`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "...
[ { "body": "<p>A few comments on this...</p>\n\n<p><em>What is a character?</em> In your code, you are only counting non-spaces as characters. But, if the user enters <code>a a</code> that counts as 10 characters to me.....</p>\n\n<p>From my perspective, Characters can just be <code>text.length</code>.</p...
{ "AcceptedAnswerId": "43281", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T04:43:07.593", "Id": "43274", "Score": "4", "Tags": [ "javascript", "strings", "regex" ], "Title": "Counting the words in a textarea" }
43274
<p>Can anyone help improve the performance of my query? When I run it, it locks the database for 5 to 10 minutes.</p> <pre><code>SELECT u.username, u.email, u.created_at, p.firstname, p.lastname, p.address, p.address_2, p.city, p.country, p.state, p.zip, p.p...
[]
[ { "body": "<p>I don't see anything unreasonable about the query itself.</p>\n\n<p>However, if I'm interpreting the output of <code>EXPLAIN</code> correctly, the anti-join with <code>sheet_user_popup_not_adam</code> is being done using a full table scan. Run</p>\n\n<pre><code>SHOW INDEXES FROM sheet_user_popup_...
{ "AcceptedAnswerId": "43359", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T09:07:48.193", "Id": "43287", "Score": "5", "Tags": [ "performance", "mysql", "sql" ], "Title": "Query performance of a SELECT statement using WHERE and NOT IN" }
43287
<p>I've recently made a set of interfaces/classes to work with converting a spreadsheet into an object but I utilise an empty interface in my design:</p> <p>I have my interface which defines what a spreadsheet object should have:</p> <pre><code>public interface IParsedSpreadsheet&lt;TEntity&gt; where TEntity: IParsed...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T13:30:20.560", "Id": "74723", "Score": "1", "body": "Why don't you use reflection on `TEntity` to deduce the `validationMap` instead of receiving it on construction, and failing on any discrepency?" }, { "ContentLicense": "C...
[ { "body": "<p>An empty interface <em>is</em> a code smell. In C# you can use <a href=\"http://msdn.microsoft.com/en-us/library/aa288454%28v=vs.71%29.aspx\">attributes</a> to mark a class instead of making it implement an empty interface.</p>\n\n<p>As I suggested in my comment, you can use reflection to build yo...
{ "AcceptedAnswerId": "43301", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T09:19:12.423", "Id": "43288", "Score": "11", "Tags": [ "c#", "object-oriented", "generics", "interface" ], "Title": "Empty Interface usage - Is this a code smell?" }
43288
<p>I was assigned the task of copying some subsums from a given EXCEL-Sheet into the executing EXCEL-Sheet. </p> <p>This had to be done with an EXCEL-Macro, so non-programmers can easily use it. There was the need to compare the final sum of copied values to the sum of values in the given sheet, as it's about business...
[]
[ { "body": "<p>The indentation in <code>TelekomRechnungEinlesen</code> makes it hard to tell where it starts and where it ends. <code>Sub</code> and <code>End Sub</code> define a scope - anything in between should have a <kbd>Tab</kbd>:</p>\n\n<pre><code>Sub TelekomRechnungEinlesen()\n\n Dim lastSetTelekomRow...
{ "AcceptedAnswerId": "43360", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T09:37:25.617", "Id": "43290", "Score": "19", "Tags": [ "vba", "excel" ], "Title": "Importing data from an external EXCEL-Sheet" }
43290
<p>I am creating a service (<code>FaultTolerantCommunication</code>) that wraps a call to a (web) service. Its responsibility is to switch the endpoint URL in the event of a <code>TimeoutException</code>.</p> <p>Currently the web service is a soap web service but I am attempting to make it reusable for other remote se...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-12T11:28:33.767", "Id": "76443", "Score": "0", "body": "What happens with `Request` if all endpoints fail? You should at least limit the recursion level. Timeouts can occur even if the endpoint is still 'up' due to heavy load - switchi...
[ { "body": "<ol>\n<li><p>For this:</p>\n\n<blockquote>\n<pre><code>public TResponse Request(TRequest request, TClient client)\n{\n try\n {\n return DoRequest(request, client);\n }\n catch (TimeoutException timeoutException)\n {\n // Log the time out\n exceptionLogger.DbLogExce...
{ "AcceptedAnswerId": "44543", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T10:48:40.233", "Id": "43292", "Score": "8", "Tags": [ "c#", "recursion", "web-services", "timeout", "soap" ], "Title": "Web service proxy that switches endpoint URLs in...
43292
<p>I wrote this simple HTML parser in Ruby.</p> <p>Basically I have a folder that has files. Every file has crawled web pages. The only addition within these files is before the HTML content there is a page metadata, <code>#URL</code> is one of them.</p> <p>What I am aiming is to have two files:</p> <p>1)Will contai...
[]
[ { "body": "<p>You are trying to parse HTML with regexes, which is widely considered to be a bad idea. For example, all these tags would have equivalent link text and target URL:</p>\n\n<pre class=\"lang-html prettyprint-override\"><code>&lt;!-- \"normal\" --&gt;\n&lt;a href=\"http://example.com\"&gt;Link Text&l...
{ "AcceptedAnswerId": "43297", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T11:01:02.770", "Id": "43293", "Score": "1", "Tags": [ "ruby", "html", "strings", "parsing" ], "Title": "Ruby html href parser working slow" }
43293
<p>I've implemented <code>PeersContainer</code> class with all operations that I need. I need something like multimap in concurrent environment, moreover I need remove entities automatically on timeout. So, I decide to use <code>Cache&lt;Long, BlockingDeque&lt;Peer&gt;&gt;</code> combined with <code>Striped&lt;ReadWr...
[]
[ { "body": "<h1>1. Thread safety</h1>\n\n<p>From a concurrency stand-point, I don't see any issue with the code: reading is guarded by the <code>readLock</code>, all the updates are guarded by the <code>writeLock</code>, and you're using thread-safe <code>BlockingDeque</code>s for the values.</p>\n\n<p>However, ...
{ "AcceptedAnswerId": "43304", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T12:45:46.307", "Id": "43295", "Score": "8", "Tags": [ "java", "multithreading", "concurrency", "guava" ], "Title": "Cache<Long, BlockingDeque<Peer>> combined with Striped<R...
43295
<p>I have a module (in file dialect.rb) defined as such:</p> <pre><code>require 'dialect/generators/elements' module Dialect def self.included(caller) caller.extend Dialect::Generator::Element end def self.version "Dialect v#{Dialect::VERSION}" end end </code></pre> <p>Then I have the file dialect/g...
[]
[ { "body": "<p>The <code>require</code> line in the first file means that ruby runs the <em>second</em> file before the first file, which is <em>before</em> the <code>version</code> method is declared...</p>\n\n<p>Doing it the other way around will work, since only when <code>included</code> is called is the mo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T12:53:35.347", "Id": "43296", "Score": "1", "Tags": [ "ruby", "modules" ], "Title": "Calling a Class Method on a Module" }
43296
<p>I use the following code <code>&lt;div&gt;&lt;?php echo $obj-&gt;text; ?&gt;&lt;/div&gt;</code> in while loop.</p> <p>Is this the best way?</p> <p>Is there a better way, either to optimize or replace this code?</p> <pre><code>&lt;?php $akhbarkotah1 = $conn-&gt;prepare("SELECT text,time FROM small WHERE active...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T18:36:22.483", "Id": "74791", "Score": "0", "body": "Does this code work?" } ]
[ { "body": "<p>It looks like you don't really need to exit out of the PHP tag on this one.</p>\n\n<pre><code>&lt;?php\n $akhbarkotah1 = $conn-&gt;prepare(\"SELECT text,time FROM small WHERE active='0' ORDER BY time DESC LIMIT 10\");\n $akhbarkotah1-&gt;execute();\n while($obj = $akhbarkotah1-&gt;fetch(P...
{ "AcceptedAnswerId": "43307", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T14:36:22.307", "Id": "43305", "Score": "4", "Tags": [ "php" ], "Title": "Building <div>text</div> inside a while loop" }
43305
<p>C++11 is great. Probably one of the most beautiful features (in my opinion) is the so-called range-based-for-loop. Instead of</p> <pre><code>for ( std::size_t i(0); i &lt; range.size(); ++i ) { // do something to range[i]; } </code></pre> <p>or</p> <pre><code>for ( Range::iterator it(range.begin()); it != rang...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T16:20:54.367", "Id": "74760", "Score": "1", "body": "I can see no weaknesses, but I think you should consider renaming makeConditionalRange with something that focuses on client code appearance, not on \"making a conditional range\"...
[ { "body": "<p>You can use braces to return from your functions. That way, you won't have to repeat long and cumbersome types (DRY, as much as possible). For example, <code>ConditionalRange::end</code>:</p>\n\n<pre><code>iterator_type end() const\n{\n return { range.end(), range.end(), condition };\n}\n</code...
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T15:07:31.343", "Id": "43308", "Score": "15", "Tags": [ "c++", "c++11" ], "Title": "Making C++11 range-based for loops a bit more useful" }
43308
<p>I am looking over some existing code (see below). The problem of grouping in the same place the presentation logic of some fields (like price, currency) was solved as extension methods on <code>int</code>, <code>double</code>, and so on...</p> <p>I do not really like this. What do you think? How could it be done...
[]
[ { "body": "<p>The big switch statement in <code>AddCurrencyIndication</code> is a pretty good sign of where to start. If you had to add another type of currency, you'd have to go in and add new cases, which violates the open/close principle. There's a lot of places where you either do already, or potentially in...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T15:39:00.867", "Id": "43309", "Score": "10", "Tags": [ "c#", "formatting" ], "Title": "Value formatters (for entities like price, currencies so on)" }
43309
<p>This function updates the user last login date on the user collection. I guess there are too many brackets and much spaghetti. How can I shorten this code?</p> <pre><code>(function () { 'use strict'; var database = require('mongodb'); var util = require('util'); var constants = require('../consta...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T16:07:15.783", "Id": "74757", "Score": "1", "body": "Welcome to Code Review! Your question only contains code. Could you edit it with a proper context ? You could specify what your code is doing, what you think is the major point th...
[ { "body": "<p>Here's some points. I commented directly in the code.</p>\n\n<pre><code>(function () {\n 'use strict';\n\n //Why do you use `database` instead of `mongo` or `mongodb`.\n //It can become confusing later in the code when you are using `db`.\n //It will be hard to tell the diffence betwee...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T16:00:35.943", "Id": "43312", "Score": "1", "Tags": [ "javascript", "optimization", "node.js", "mongodb" ], "Title": "Update user's last login date" }
43312
<p>Here is my code: </p> <pre><code>$sql = &lt;&lt;&lt;END Select Sum(p)/Sum(w)*100 as present FROM attendance group by month END; $query = mysql_query($sql) or die($sql . ' - ' . mysql_error()); $names = array(); while ($row = mysql_fetch_array($query)) { $names[] = $row[0]; } </code></pre>
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T16:28:03.317", "Id": "74762", "Score": "0", "body": "Don't use mysql_* functions, are deprecated. Use mysqli_* or PDO." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T16:31:24.137", "Id": "74763",...
[ { "body": "<p>Regardless of how well you know the <code>mysql_*</code> functions, you shouldn't use them. There are counterparts within PDO. See <a href=\"https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php/12860046#12860046\">this answer</a> on stackoverflow for why.</p>\n\n<...
{ "AcceptedAnswerId": "43319", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T16:13:11.723", "Id": "43315", "Score": "2", "Tags": [ "php", "mysql" ], "Title": "Better way to load Mysql query in PHP Array" }
43315
<p>I have created a PHP login system based off of <a href="https://defuse.ca/php-pbkdf2.htm" rel="nofollow">this site</a>. My main concern is: Is it secure? I chose that because to me it looked secure, but a 2nd or 3rd opinion never hurts. The idea of the project is to have something I can just pull into a new project...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T17:18:30.500", "Id": "74770", "Score": "3", "body": "Hi @MrJack, welcome to Code Review! You've posted a lot of code here! I suggest that you break this code down to _manageable_ modules you want us to review, and put each in a diff...
[ { "body": "<h3>Preamble</h3>\n<p>As a matter of security, I can safely say that you would fail a professional security audit in seconds. You should be including the hashing library as an external component. You also need to forget everything you know about querying databases and start again.</p>\n<p>Also, look ...
{ "AcceptedAnswerId": "43323", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T16:40:19.187", "Id": "43317", "Score": "9", "Tags": [ "php", "mysql", "security", "authentication" ], "Title": "Login system based off of another site" }
43317
<p>To learn Python, I've been working through <a href="http://learnpythonthehardway.org/book/" rel="nofollow">Learn Python the Hard Way</a>, and to exercise my Python skills I wrote a little Python Hangman game (PyHangman - creative, right?):</p> <pre><code>#! /usr/bin/env python2.7 import sys, os, random if sys.ver...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T17:14:40.310", "Id": "74768", "Score": "0", "body": "A bit of a naive question why is '\\' escaped in the right leg but not in the left arm ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T17:45:15.3...
[ { "body": "<p>Python supports multi-line string literals. You could use those instead of using a list to encode your state image.</p>\n\n<pre><code>a = r\"\"\" 'hello' \\n\n more \"\"\"\nprint a\n</code></pre>\n\n<hr>\n\n<p>You have multiple methods called <code>set_XXX()</code> that return values instead of s...
{ "AcceptedAnswerId": "43383", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T16:45:17.100", "Id": "43318", "Score": "7", "Tags": [ "python", "game", "python-2.x", "hangman" ], "Title": "Python Hangman program" }
43318
<p>I'm working on a WPF app which uses ReactiveUI and Rx, there's part of the workflow that watches two data sources (<code>ReferenceData</code> and <code>PredictedData</code> properties on a View Model) and an area of that data source (<code>FocusArea</code> property) which is used to show a line graph of that data....
[]
[ { "body": "<p>When Switch unsubscribes from the previous Observable to connect to the new one, FromAsync should signal the cancellation token and also correctly eat the ThrowOnCancellation exception. </p>\n\n<p>While it'd probably be better to try to use a ReactiveCommand to model the loading bool (which might ...
{ "AcceptedAnswerId": "43362", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T17:10:30.093", "Id": "43320", "Score": "11", "Tags": [ "c#", "system.reactive" ], "Title": "ReactiveUI and Rx background calculations with cancellation" }
43320
<p>In an effort to reduce the images being used on the page, I've manipulated box-shading, etc. to make a "vector" looking monitor/ipad look. </p> <p>This is great and all, gets the job done, however, seems there is still a large load draw on the box-shading rendering. Is there a better method or tweak to this method ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T20:23:01.913", "Id": "74802", "Score": "0", "body": "Minor note : it's iPad and not ipad. I have no idea about what I could change your title to, but you don't need `review of`. Good result, it has a good look. Just for curiosity, w...
[ { "body": "<p>Your code is perfectly valid, according to the HTML and CSS validators at W3C:</p>\n\n<blockquote>\n <p><a href=\"http://validator.w3.org/check\" rel=\"nofollow\">HTML Validator</a><br>\n <a href=\"http://jigsaw.w3.org/css-validator/\" rel=\"nofollow\">CSS Validator</a></p>\n</blockquote>\n\n<p>...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T20:07:26.133", "Id": "43330", "Score": "8", "Tags": [ "html", "css", "video" ], "Title": "Creating an iPad-style video frame with CSS and without images" }
43330
<p>I'm working through some exercises to sharpen my Ruby skills. The following code is how I solved this particular question. I'd like to know what other developers think of this solution. I'm self taught, which means: I'm not getting any feedback as I learn, so I just want to make sure that I'm learning the <em>right<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T03:23:40.427", "Id": "74879", "Score": "0", "body": "i'd say specs -- 4, code -- 3. i'd answer more fully but I don't have anything to add to Phillip's solution, which I like a lot other than the word \"titlieze\"" }, { "Co...
[ { "body": "<p>Your code is readable, but it doesn't feel very \"rubyish\" to me. I think that's due to needing to setup and track some extra variables and track the index of the word in question -- having to case it depending on the index, etc.</p>\n\n<p>It also bugs me a little bit that <code>title=</code> i...
{ "AcceptedAnswerId": "43334", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T20:12:41.377", "Id": "43331", "Score": "11", "Tags": [ "strings", "ruby", "unit-testing" ], "Title": "Proper capitalization for book titles" }
43331
<p>I use the following code: <code>fetchAll</code> and <code>for($mich=0;$mich&lt;10;$mich++)</code>.</p> <p>Is this the best way?</p> <p>Is there a better way, either to optimize or replace this code?</p> <pre><code>&lt;?php include("cache/phpfastcache.php"); phpFastCache::setup("storage","auto"); $cache = phpFastC...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T21:34:15.923", "Id": "74819", "Score": "0", "body": "Does your *actual* code have this [non-]indentation?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T21:48:38.700", "Id": "74822", "Score":...
[ { "body": "<p>Using <code>fetchAll</code> usually is not a problem. There are some things to optimize here in my opinion:</p>\n\n<ul>\n<li><p>Use a <code>foreach</code> loop instead of <code>for</code> loop. Your result is already limited. No need to duplicate this here. This removes the iterator counter and as...
{ "AcceptedAnswerId": "43354", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T21:24:15.173", "Id": "43338", "Score": "2", "Tags": [ "php", "pdo" ], "Title": "Are fetchAll() and for() good choices for my code?" }
43338
<p>I'm new to PHP security and have made this login file:</p> <pre><code>&lt;?php header('Content-type: application/javascript'); $hostname_localhost = ""; $database_localhost = ""; $username_localhost = ""; $password_localhost = ""; $salt1 = ""; $salt2 = ""; $localhost = mysql_connect($hostname_localhost,$username...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T22:45:27.393", "Id": "74837", "Score": "0", "body": "There are most definitely things wrong. It appears you followed an old tutorial, so consider finding one that was recently written next time. (Here is one)(http://www.sunnytuts.co...
[ { "body": "<p>I don't know PHP, but it looks like you have an SQL injection vulnerability here:</p>\n\n<pre><code>$query_search = \"select * from users where username = '\".$username.\"' AND password = '\".$sha1_password. \"'\";\n</code></pre>\n\n<p>And here:</p>\n\n<pre><code>\"select * from users where us...
{ "AcceptedAnswerId": "43390", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T21:24:43.620", "Id": "43339", "Score": "2", "Tags": [ "php", "beginner", "mysql", "security" ], "Title": "Login code probably not secure" }
43339
<p>I submitted this problem for an interview, and I was wondering if I could have done better. My solution works, and I solved in about 12-15 minutes. I feel like I did a bad job with the code. Please be honest.</p> <p>Here is the question:</p> <blockquote> <p>Given a non-negative number represented as an array of...
[]
[ { "body": "<p>The goal in my answer is code conciseness. Order of magnitude of runtime is the length of the array, which would only need to be re-created if the new array has additional digits. If you're only adding +1, it's somewhat simpler to perform the carry operation.</p>\n\n<pre><code>public int[] plusO...
{ "AcceptedAnswerId": "43349", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T22:10:09.010", "Id": "43343", "Score": "10", "Tags": [ "java", "algorithm", "interview-questions" ], "Title": "Add one to a number represented as an array of digits" }
43343
<p>I wrote some Python code to solve the following problem. I'm curious to see if someone else can find a better solution, or critique my solution.</p> <p>How would you design a stack which, in addition to push and pop, also has a function min which returns the minimum element? Push, pop and min should all operate i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T15:10:54.253", "Id": "74964", "Score": "1", "body": "Your requirements sound impossible to me unless you make some additional assumptions. Proof: The optimal comparison sorting algorithm (given a simple comparer and nothing more) ha...
[ { "body": "<p>This assumes your stack has integer values, or values that can be translated in constant time to integers. If you're creating the stack from scratch and building the class yourself, create an array of integers where the indices are the values of the elements, and the values at those indices are t...
{ "AcceptedAnswerId": "43355", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T22:15:01.160", "Id": "43344", "Score": "5", "Tags": [ "python", "stack" ], "Title": "Retrieve min from stack in O(1)" }
43344
<p>I have a function that reads a string like this</p> <pre><code>(AnimalCount+HumanCount) </code></pre> <p>and the result of this function is an array of strings</p> <pre><code>[ "(" , "AnimalCount" , "+" , "HumanCount" , ")" ] </code></pre> <p>Now, I have done 2 functions in order to do this:</p> <p>The first on...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T22:47:24.330", "Id": "74839", "Score": "0", "body": "Please can you specify in which ways you want this to be improved?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T22:53:42.583", "Id": "74846"...
[ { "body": "<ol>\n<li><p><code>Validate</code> is a misleading name for what the function does. It does not validate anything - rather it checks if the given character is one of a special set. So it should be named <code>IsSpecial</code> or <code>IsTokenDelimiter</code>.</p></li>\n<li><p>Growing an array one ent...
{ "AcceptedAnswerId": "43398", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T22:44:16.253", "Id": "43347", "Score": "6", "Tags": [ "beginner", "strings", "delphi" ], "Title": "Produce an array of strings from a single string" }
43347
<p>Here's a novel-length summary of the issue:</p> <p>I'm trying to write a VB.net program to help me collect remote site statistics from system-generated logs, but I'm a little like a carpenter who only knows how to use a hammer, and my project has turned into a bit of a monstrosity; as embarrassing as my code is, I ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T02:10:23.040", "Id": "74870", "Score": "0", "body": "What does the data look like in searchedlist? What kind of class is entry? What does the outage class look like? One way to help cut down on the loops is keep a record of each ...
[ { "body": "<p>It seems to me that the main thing you need to do is sort out your logic.</p>\n\n<p>The way I'd expect things to work would be that for any given site, a <code>DOWN</code> entry indicates that site has gone down, and it's counted as remaining down until you see an <code>UP</code> entry for the sam...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T23:06:43.033", "Id": "43350", "Score": "8", "Tags": [ "optimization", "strings", "vb.net", "hash-map" ], "Title": "Collect and calculate average times from log, then display t...
43350
<p>I've been reading <a href="http://www.cis.upenn.edu/~bcpierce/tapl/">Types and Programming Languages</a> and I wanted to try to implement the first language in Haskell to understand it properly</p> <p>I have barely written any Haskell before and not used Parsec so I would grateful for any feedback on this code</p> ...
[]
[ { "body": "<p>Where you used <code>case</code> you could have used pattern matching. This yields more idiomatic code in many cases.</p>\n\n<pre><code>isNumerical :: Term -&gt; Bool\nisNumerical TmZero = True\nisNumerical (TmSucc subterm) = isNumerical subterm\nisNumerical (TmPred subterm) = isNumerical subterm\...
{ "AcceptedAnswerId": "45272", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T23:16:42.553", "Id": "43351", "Score": "5", "Tags": [ "beginner", "haskell", "parsec" ], "Title": "Using Parsec for simple arithmetic language" }
43351
<p>I want to write code that does backward stepwise selection using cross-validation as a criterion.</p> <p>I have only started learning R a month ago and I have almost zero programming experience prior to that. Hence, I would appreciate any comments on the code.</p> <p>(I understand that there are issues with the ba...
[]
[ { "body": "<p>Your code is good. I could not find important corrections to be made. I could find only some small cosmetic improvements - nothing serious.</p>\n\n<p>For example. You do not need the <code>caret</code> package loaded for this task. You do not need to use <code>next</code> at the end of the <code>w...
{ "AcceptedAnswerId": "43847", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T23:21:44.987", "Id": "43352", "Score": "2", "Tags": [ "beginner", "r" ], "Title": "Backwards stepwise regression code in R (using cross-validation as criteria)" }
43352
<p>I am a relative beginner to Python and as such I've been working on little things here and there in the office that strike me as something interesting that might be fun to try and code a solution.</p> <p>Recently, I was working with some cell phone data and decided to write a little script that would triangulate a ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T21:43:40.737", "Id": "74858", "Score": "0", "body": "@Conor Yes, that is fine...I did fail to mention that I would like to convert it to an Arcpy script or tool at some point in the future (which led me to post here) but I just want...
[ { "body": "<p><em>Let's start with part I :</em></p>\n\n<p><strong>Don't repeat yourself</strong></p>\n\n<p>You can define small functions to avoid duplicating code for all signals.</p>\n\n<p>Also, you can use the relevant data structure to store information. For instance, the strength of the signal go by 3, le...
{ "AcceptedAnswerId": "43389", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-03T21:15:57.727", "Id": "43353", "Score": "5", "Tags": [ "python", "beginner", "python-2.x", "geospatial" ], "Title": "Improving a triangulation test script" }
43353
Maintainability refers to the nature, methods, theory and art of maximizing the ease with which an asset may be sustained, modified or enhanced throughout the duration of its expected useful life.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T00:38:14.923", "Id": "43357", "Score": "0", "Tags": null, "Title": null }
43357
<p>I'm trying to parse a CSV file into objects. I've already got a very efficient CSV parser (SuperCSV). The problem arises when trying to create the object with the data that is being read out.</p> <p>I've got a nested <code>foreach</code> that iterates firstly through a map (that represents a CSV row) and then thro...
[]
[ { "body": "<h2>Map.Entry&lt;....&gt;</h2>\n<p>HashMaps (Maps in general) require time to do key lookups.</p>\n<p>You can save a significant number of these by changing your inner loop:</p>\n<blockquote>\n<pre><code>for(String key : csvRow.keySet())\n{\n contact.setDetails(key, csvRow.get(key));\n contactL...
{ "AcceptedAnswerId": "43364", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T03:04:17.123", "Id": "43361", "Score": "8", "Tags": [ "java", "performance", "parsing", "memory-management" ], "Title": "Object Creation during loops" }
43361
<p>My first crack at clojure... if you have time to provide input, I'd appreciate it. I'm as much interested in style as proper usage. I'm just getting started.</p> <p>The task to start with an vector of N zeros, and then "scramble" it by: Select 2 items in the vector. If one is less than 4, and the other is greater t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T04:52:51.063", "Id": "74889", "Score": "0", "body": "There's no code yet, you mean?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T04:56:46.157", "Id": "74890", "Score": "0", "body": "lol...
[ { "body": "<p>I am also relatively new to Clojure, but here are my first thoughts:</p>\n\n<ul>\n<li><p>I like that you work with a vector, because random access of vectors with <em>(nth)</em> and <em>assoc</em> is faster. I also like your naming. thanks for providing a deftest, but please, user a proper inlinin...
{ "AcceptedAnswerId": "44007", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T04:51:33.903", "Id": "43368", "Score": "1", "Tags": [ "beginner", "clojure" ], "Title": "Scamble a vector, preserving the sum" }
43368
<p>I've created this thin wrapper class for a socket project that I'm working on. Can someone review my class and give me some points on if I'm on right track?</p> <pre><code>#include &lt;iostream&gt; #include &lt;WinSock2.h&gt; const int MAX_RECV_LEN = 8096; const int MAX_MSG_LEN= 1024; const int PORT_NUM = 1200;...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-05T02:00:11.453", "Id": "75136", "Score": "0", "body": "You may want to look at my versions. It may give you some ideas: [part1](http://codereview.stackexchange.com/questions/38402/stream-that-opens-an-http-get-and-then-acts-like-a-nor...
[ { "body": "<p>There are at least a few things I think I'd do differently, at any rate.</p>\n\n<pre><code>const int MAX_RECV_LEN = 8096;\nconst int MAX_MSG_LEN= 1024;\nconst int PORT_NUM = 1200;\n</code></pre>\n\n<p>The ALL_CAPS convention was originally invented for macros. At least as far as I can tell, it wa...
{ "AcceptedAnswerId": "43374", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T05:00:47.303", "Id": "43369", "Score": "7", "Tags": [ "c++", "c++11", "windows" ], "Title": "Socket wrapper class" }
43369
<p>This seems a bit redundant to me, but I'm not sure of how else I might be able to write this. Normally I'd use a <code>switch</code> statement, but I don't think that'll work here. I realize I could also do this in a <code>for</code> loop, but the main heart of the question is what's inside the loop itself. "<cod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T13:05:42.350", "Id": "74941", "Score": "2", "body": "`Array.isArray` will also work with non-objects. You don't need to check if it's an object." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T21:11:4...
[ { "body": "<p>I think at the very least I'd rearrange the cases to make the dichotomy between <code>Array.isArray</code> and <code>!Array.isArray</code> more direct and apparent:</p>\n\n<pre><code>while (i &lt; x) {\n if (typeof arr[i] === 'string') {\n text = arr[i];\n }\n else if (typeof arr[i...
{ "AcceptedAnswerId": "43473", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T05:42:16.267", "Id": "43371", "Score": "10", "Tags": [ "javascript" ], "Title": "Is there a more succinct way of writing this simple JavaScript loop?" }
43371
<p>Can I make this program that extracts text data from a file (size in MBs) even better performance-wise? I need to reduce the execution time.</p> <pre><code>import java.io.*; public class ReadData { public static void main(String[] args) { FileReader input = null; BufferedReader br = null; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T06:46:49.227", "Id": "74896", "Score": "5", "body": "The majority of the time it will probably spend in printing it to stdout - which is very likely the console in most cases unless you have some redirection going on. If that is not...
[ { "body": "<p>It's a pretty small and straight-forward program and not really much to improve on. ChrisWue also brings up the good point that printing to <code>stdout</code> for every line is costly but if you need to print it to <code>stdout</code> there's not much to do about it.</p>\n\n<p>But one thing you c...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T05:49:40.010", "Id": "43372", "Score": "4", "Tags": [ "java", "performance", "io" ], "Title": "Extracting text data from a file" }
43372
<p>Goal: Create a combination of emails based from inputted first name, last name, middle name, and a domain. Add in common separators. Then I'll check which one is correct with the rapportive API. This is the first part of the bigger script.</p> <p>If you are given the <code>string</code> variables</p> <pre><code>{f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T09:12:24.700", "Id": "74914", "Score": "1", "body": "Is there any pattern in the expected permutations?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T10:32:39.407", "Id": "74925", "Score": "...
[ { "body": "<p>Since your list is not \"all permutation\", but is painstakingly built by hand, I would not suggest using array's <code>permutation</code> API or something like that, but keep the curated mode you are using.</p>\n\n<p>I would suggest building it in a more readable way. In your way of <code>[fi].pr...
{ "AcceptedAnswerId": "43748", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T05:54:26.753", "Id": "43373", "Score": "8", "Tags": [ "ruby", "strings", "array", "combinatorics" ], "Title": "Generate permutations with symbols" }
43373
<p>I would very much appreciate a general review of my PHP code which grabs information from a mySQL database and also inserts some information into the database.</p> <p><strong>Overview :</strong></p> <ol> <li><p>Users go to <strong><em>/main.php</em></strong> and answer math questions. The 20 math questions are pul...
[]
[ { "body": "<p>Starting from the top…</p>\n\n<p>Common <strong>idioms for repeating a loop</strong> 20 times are:</p>\n\n<pre><code>for ($i = 0; $i &lt; 20; $i++) {\n # Do something\n}\n</code></pre>\n\n<p>or</p>\n\n<pre><code>for ($i = 1; $i &lt;= 20; $i++) {\n # Do something\n}\n</code></pre>\n\n<p>What ...
{ "AcceptedAnswerId": "43391", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T09:28:38.817", "Id": "43387", "Score": "5", "Tags": [ "beginner", "php5", "mysqli" ], "Title": "Arithmetic quiz using PHP5 and mySQLi" }
43387
<p>I noticed, that accelerometer and gyrometer sensor data tend to have problems. The gyrometer is not very precise and the accelerometer is getting problems with vibrations. I built a quadrocopter (to be honest more then one). My first one had a poor frame and the motors (very big ones) were vibrating a lot, because t...
[]
[ { "body": "<p>A few notes:</p>\n\n<pre><code>inline float smaller_float(float value, float bias) {\n return value &lt; bias ? value : bias;\n}\n</code></pre>\n\n<p>This seems intended to do exactly the same thing as <code>std::min</code> in the standard library. You're probably better off using the standard ve...
{ "AcceptedAnswerId": "43425", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T10:41:07.630", "Id": "43393", "Score": "8", "Tags": [ "c++", "arduino" ], "Title": "Gyrometer/accelerometer sensor fusion with sigmoid transfer function" }
43393
<p>I am making a PHP script which fetches the data of the emails whose sending date and time has been reached and then send emails to those records. I am following the steps below and integrating it in an API, that is.</p> <p><a href="https://github.com/infusionsoft/PHP-iSDK" rel="nofollow">GitHub code</a></p> <p>Ste...
[]
[ { "body": "<blockquote>\n<pre><code>// Test Connnection\nif ($myApp-&gt;cfgCon(\"connectionName\")) {\n echo \"Connected...\";\n} else {\n echo \"Not Connected...\";\n}\n</code></pre>\n</blockquote>\n\n<p>Does it make sense to continue the program and run the SQL query if it's not connected? If not stop i...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T10:42:08.783", "Id": "43394", "Score": "4", "Tags": [ "php", "email" ], "Title": "To send the email on some given date and time" }
43394
<p>I was a PHP developer and I started writing a product in C# without studying the basic structure. Now, I have around 100+ views with similar code. After 1 year into development, I now realize that something is not right.</p> <p>How can I separate the server tags when they are so intertwined in the code? Is it okay ...
[]
[ { "body": "<p>This is how I see server variables and local variables interacting. There is not really any other way to get the values between the two that I'm aware of.</p>\n\n<p>As for the code, I one minor point:change <code>Emp</code> to <code>Employee</code> for variable names. This will eliminate confusi...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T12:26:58.850", "Id": "43399", "Score": "9", "Tags": [ "c#", "javascript", "asp.net-mvc-4" ], "Title": "Accessing server side variables in views and JavaScript" }
43399
<p>Is it possible to simplify the code below?</p> <pre><code>dynamic model = GetExpandoObject(); //model type of ExpandoObject var result = model.FirstOrDefault(x =&gt; x.Key == "node").Value; if (result != null) { result = ((ExpandoObject)result).FirstOrDefault(x =&gt; x.Key == "children"); if (result != n...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T16:22:07.993", "Id": "74993", "Score": "1", "body": "please let us know if we are on the right track here @sreginogemoh" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T18:32:22.667", "Id": "75036"...
[ { "body": "<p>The first thing that pops out is the repetitive calls that look like this:</p>\n\n<blockquote>\n <p>result = ((ExpandoObject)result).FirstOrDefault(x => x.Key == \"node\").Value;</p>\n</blockquote>\n\n<p>Which are all similar. Half of your calls end in <code>.Value</code> and the other half don'...
{ "AcceptedAnswerId": "43418", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T12:53:09.000", "Id": "43400", "Score": "15", "Tags": [ "c#", ".net", "linq" ], "Title": "Finding elements inside ExpandoObject" }
43400
<p>I have a script that sends multiple commands after logging in a remote machine via SSH.</p> <p>Problem is, it's barely readable. I've tried quoting everything with "", but it's terrible (everything appears in pink), and here documents are just as bad (everything appears in gray). I'm using Gedit as an editor, but I...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T14:39:03.217", "Id": "74956", "Score": "1", "body": "As far as I understood that question, you are asking about: \"How can I make my Editor parse strings as code?\". Is that correct?" }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>You're quoting the heredoc terminator, so $2 will certainly not be expanded</p>\n\n<p>When you want to pass multiple commands to ssh, wrap them as a single script to an interperter, thus ssh sees one single command.</p>\n\n<p>Lots of whitespace for readability.</p>\n\n<p>And yes, not much opportun...
{ "AcceptedAnswerId": "43417", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T13:22:26.887", "Id": "43403", "Score": "2", "Tags": [ "bash" ], "Title": "Bash pass multiple commands to SSH and make readable" }
43403
<p>I sent a PR to a repo the other day and want to make sure I have the right idea for URI validation.</p> <pre><code>function validateURI(files) { //... // files can be either a string or an array of paths // validates the relative path exists or is an http(s) URI // returns a filtered list of valid p...
[]
[ { "body": "<p>Very interesting,</p>\n\n<p>I only have 1 snarky comment, if <code>files</code> is an array of 'paths', maybe you should call it <code>paths</code> ;)</p>\n\n<p>Also, as a user of this function, I might want to override your regex so you might want to provide support for that.</p>\n", "comment...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T14:15:31.230", "Id": "43405", "Score": "3", "Tags": [ "javascript", "node.js", "grunt.js" ], "Title": "Validate that a relative path exists or is an external URI" }
43405
<p>According to my lecture notes, there are benefits to refactoring the code from original code to refactor code.</p> <p>Reasons for refactoring:</p> <blockquote> <p>Replace Temp with Query</p> <ul> <li>You are using many temporary variables to hold the result of an expression</li> <li>This can result in...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T14:59:11.420", "Id": "74960", "Score": "0", "body": "Honestly, neither can I. Are you sure this is your lecture's notes? Refactoring basePrice into a method and calling that twice only makes things worse IMO, in case it's a multithr...
[ { "body": "<p>You have misunderstood one thing that your lecturer said, extracting a calculation to a method does not mean that you should call it multiple times within the same method!</p>\n\n<p>You are probably doing <code>double basePrice = _quantity * _itemPrice;</code> on more than one place in your code, ...
{ "AcceptedAnswerId": "43414", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T14:46:13.420", "Id": "43409", "Score": "-2", "Tags": [ "c#" ], "Title": "How does this refactored code make my code better?" }
43409
<p>I have multiple models which all have the same functions in my framework. I decided to create one "parent" model and all of my other models would extend and inherit its functions like <a href="http://pastebin.com/55NjGqmS" rel="nofollow">this</a>.</p> <p>My other models would be like this:</p> <pre><code>class Gam...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-24T17:24:59.157", "Id": "89206", "Score": "0", "body": "Always a good idea have intermediate layer of classes that hold the same behaviour for child classes, but read my answer below for more details of your implementation." } ]
[ { "body": "<p>Well, having a parent model that is extended for all your model classes is always a good idea if they all share the same behaviour and help you with your development. I have implemented a similar approximation within my models and I'm doing something similar to what you do, but instead of writing ...
{ "AcceptedAnswerId": "51632", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T15:08:14.150", "Id": "43412", "Score": "1", "Tags": [ "php", "object-oriented", "codeigniter", "framework" ], "Title": "Using one parent model and other extending it in a P...
43412
<p>Can someone help me further optimize the following Cython code snippets? Specifically, <code>a</code> and <code>b</code> are <code>np.ndarray</code> with <code>int</code> value (range(256)) in them. They are one dimension arrays with dynamic length. <code>resultHamming</code> is a one-dimension array with float va...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-06T20:13:32.640", "Id": "75492", "Score": "0", "body": "What are you trying to achieve here? What is the specification of your function `compare`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-06T22:13:57...
[ { "body": "<p>As a general rule for optimizing with cython, try to avoid python function calls if possible, i.e. replace pythonic <code>sum</code> with numpy <code>sum</code> or explicit for loop, replace bit number table with numpy array, and try to declare types for all variables. </p>\n\n<p>You can also prec...
{ "AcceptedAnswerId": "43659", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T15:18:41.813", "Id": "43413", "Score": "7", "Tags": [ "python", "optimization", "performance", "array", "cython" ], "Title": "Optimize Cython code with np.ndarray conta...
43413
<p>I've decided to make an implementation of the C++11 class <code>function</code>. I was checking that I have done everything correctly and have not missed anything:</p> <pre><code>template &lt; typename &gt; class function; template &lt; typename _Ret, typename... _Args &gt; class function&lt;_Ret(_Args...)&gt; { p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T17:42:48.230", "Id": "75019", "Score": "3", "body": "Maybe you could provide a compilable online example where you use your `function` to store (and then run) a function pointer, a pointer-to-member-function, a stateless lambda, a s...
[ { "body": "<p>Your code has no chance of working, because the only non-static data member of your <code>function&lt;void(void)&gt;</code> is a single pointer of type <code>void (*)(void)</code>. There's no room to store any other kind of functor.</p>\n\n<p>In other words, you've implemented the concept of \"fun...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T17:15:29.920", "Id": "43423", "Score": "1", "Tags": [ "c++", "c++11", "reinventing-the-wheel" ], "Title": "std::function implementation" }
43423
<p>I started to learn PHP OOP recently and searched the web for some practical exercises and I found one that said to build a select input that is generated and populated with options by the object. I just want to ask for some opinions on code quality. Could it be done better? What is the biggest flaw? </p> <p>The ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T18:11:54.007", "Id": "75027", "Score": "0", "body": "`I found one that said to build a select input that is generated and populated with options by the object.` I'm wondering if it's your code ?" }, { "ContentLicense": "CC B...
[ { "body": "<p>A few minors:</p>\n<ol>\n<li><p>Your spacing is a bit inconsistent (e.g. missing spaces here <code>completeSelect{</code> and here <code>$this-&gt;setIn=$val;</code>)</p>\n</li>\n<li><p>Your naming convention is a bit inconsistent as well. I don't do much PHP but class names are usually <code>Pasc...
{ "AcceptedAnswerId": "43520", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T18:02:56.707", "Id": "43427", "Score": "6", "Tags": [ "php", "beginner" ], "Title": "Select input that is generated and populated with options" }
43427
<p>I'm writing a pretty complicated piece of UI with angularjs. I've been using angular for about 2 weeks. I'm going to post the controllers I feel are the most confusing to read, and am wondering the following:</p> <ul> <li>Could these be more "angular" (done in a more angular way?)</li> <li>Is it normal to have this...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T18:51:20.473", "Id": "75040", "Score": "0", "body": "What are your code doing ? We would need a bit more of context." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T18:53:32.257", "Id": "75041", ...
[ { "body": "<p>That code is hard too grok, I find it stretches too much horizontally. From that perspective : </p>\n\n<ul>\n<li><p>Don't skip newlines for <code>if</code> blocks, it is okay to skip the curly braces\n<br>No:</p>\n\n<pre><code>if ($scope.event.key == event_key &amp;&amp; $scope.segment_index == se...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T18:43:38.377", "Id": "43430", "Score": "4", "Tags": [ "javascript", "angular.js" ], "Title": "Segment builder" }
43430
<p>I'm learning Ruby and working through some exercises. I completed the following exercise without truly understanding why and how it works. I know that's an embarrassing thing to say but I feel like my subconscious mind wrote the code and conscious me (or maybe unconscious me you could say) is having trouble understa...
[]
[ { "body": "<p>For someone who wasn't conscious when he wrote this code, it looks quite nice :)</p>\n\n<p>Some observations:</p>\n\n<p><strong>Tests should do only one thing</strong></p>\n\n<p>This is OK in most of your tests, but you got a little 'lazy' at the last two tests - make a different test for each <co...
{ "AcceptedAnswerId": "43634", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T19:41:34.917", "Id": "43431", "Score": "6", "Tags": [ "ruby", "converting" ], "Title": "Converting between Fahrenheit and Celsius" }
43431
<p>I'm interested in optimizing my code. Can someone help me understand the best way to trim this code down with DRY methodology?</p> <p>So I've got these two classes here preforming WMI queries on two separate Win32 classes. My questions are:</p> <ol> <li>Should I keep them separated in different classes based on th...
[]
[ { "body": "<p>How about leveraging <code>Enum.ToString()</code>?</p>\n\n<p>Given these two enums:</p>\n\n<pre><code>public enum Win32OperatingSystem\n{\n FreePhysicalMemory,\n TotalVirtualMemorySize,\n FreeVirtualMemory\n}\n\npublic enum Win32ComputerSystem\n{\n Name,\n Manufacturer,\n Model\n...
{ "AcceptedAnswerId": "43436", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T19:49:27.930", "Id": "43432", "Score": "5", "Tags": [ "c#", "optimization" ], "Title": "Class Seperation vs Polymorphism" }
43432
<p>I have a checking function that checks the correct type for a class Check_Annotation, I was wondering if there is a better way to implement this, my current code right now is:</p> <pre><code>def _check_list_or_tuple (self, param, annot, value, check_history): assert isinstance(value, type(annot)), "AssertionEr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-05T20:43:31.180", "Id": "75337", "Score": "0", "body": "I don't think you need to initialize check_history at all. Just have `check_history = str(annot[X])`" } ]
[ { "body": "<p>I don't have time to check all of this, but here are some ideas ...\n - place long strings in parenthesis and break them up into multiple lines\n - if those strings are used more than once, use variables for them\n - break out the for loops as a separate function</p>\n\n<pre><code>type_error_msg =...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T20:26:27.090", "Id": "43437", "Score": "1", "Tags": [ "python", "algorithm" ], "Title": "Better implementation of checking function" }
43437
<p>I have an array of objects. Each object has two properties, <code>id</code> and <code>quantity</code>.</p> <p>I wrote a function to add an object to the array. But the function must check if the object already exists within the array. If it does exist the function must increment the <code>quantity</code> property. ...
[]
[ { "body": "<p>Why are you using an array to do the job of a map? Use the right data structures....</p>\n\n<p>... instead, use a hashmap (associative array) of <code>[id, quantity]</code>. If <code>id</code> exists in hashmap, then increment up the value at <code>hashmap[id]</code>.</p>\n", "comments": [ ...
{ "AcceptedAnswerId": "43442", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T20:29:45.147", "Id": "43438", "Score": "14", "Tags": [ "javascript", "array" ], "Title": "Writing a function to add or modify an existing object inside an array" }
43438
<p>This is a Windows service that will run on about 600 machines. It is used to track the job server that a user is connected to (pushed through some kind of load balancer, not my area). I store this information in a SQL table and want to make sure that I don't have any SQL leaks.</p> <p>this grabs information from ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T22:42:49.433", "Id": "75094", "Score": "0", "body": "if you are going to downvote please explain why so that I can form better questions in the future" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T2...
[ { "body": "<p>Your code is asymmetrical....</p>\n\n<p>You open your <code>SQLConnection</code> inside the using block, but you close it outside in the final block.... anyway, <a href=\"http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection%28v=vs.110%29.aspx\">the Close is completely redund...
{ "AcceptedAnswerId": "43457", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T20:37:20.157", "Id": "43439", "Score": "5", "Tags": [ "c#", "sql-server" ], "Title": "Do I have any SQL leaks?" }
43439
<p>I have been trying to wrap my head around all the new options in ECMAscript 6 and to do this I tried to develop a simple setup which would allow me to place absolutely positioned <code>&lt;div&gt;</code>s on the page.</p> <p><strong>main.js:</strong></p> <pre><code>import {Screen} from './objects/screen'; import {...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-05T16:26:39.650", "Id": "75269", "Score": "0", "body": "Traceur does not support private in class bodies.. https://github.com/google/traceur-compiler/issues/57 That's a bit of a let down." }, { "ContentLicense": "CC BY-SA 3.0",...
[ { "body": "<p>Most interesting,</p>\n\n<ul>\n<li>In <code>BaseObject</code>, you should really have a constructor that builds <code>this.listeners</code>, it would make your code much cleaner afterwards</li>\n<li>I am not sure why your listeners are not private in <code>BaseObject</code> ?</li>\n<li>I am not su...
{ "AcceptedAnswerId": "43522", "CommentCount": "11", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T20:38:10.723", "Id": "43440", "Score": "15", "Tags": [ "javascript", "object-oriented", "ecmascript-6" ], "Title": "JavaScript/ECMAscript 6 classes organization" }
43440
<p>I need some advice to see if my simple Windows socket class is good enough to be used in a simple chat application.</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;Windows.h&gt; class Socket { private: WSADATA wsaData; SOCKET hSocket; sockaddr_in serv...
[]
[ { "body": "<p>WSAGetLastError() returns an <code>int</code>. Throwing an int is legal but not quite usual. Your <code>catch(std::exception&amp; e)</code> statements are fairly useless, given that Win32 APIs are unlikely to throw a std::exception object.</p>\n\n<p>Your default constructor is dangerous: you can't...
{ "AcceptedAnswerId": "43539", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T20:42:09.063", "Id": "43443", "Score": "11", "Tags": [ "c++", "windows", "socket" ], "Title": "Windows socket class" }
43443
<p>I will preface by saying that this data set is much larger than what I have here. I'm having to loop through an XML file to get data and display it on a site with jQuery. I have to use jQuery because I'm working within a framework that I can't edit so I'm having to manipulate the data after the fact. This is causing...
[]
[ { "body": "<p>Don't use selector all the time. DOM locating waste most resource and time. as less selector as possible. use variable cache the jQuery object.</p>\n\n<p>Data is look like a root: </p>\n\n<pre><code>var $data = $(\"Data\");\n</code></pre>\n\n<p>Rather than parse start with \"category_number\", why...
{ "AcceptedAnswerId": "43482", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T21:26:46.943", "Id": "43449", "Score": "3", "Tags": [ "javascript", "jquery", "parsing", "xml", "ajax" ], "Title": "Parsing XML data to be put onto a site with jQuery" ...
43449
<p>I've been going through LPHW (learn Python the hard way) lessons and I am now at exercise No36 where I have to create a similar game. </p> <p>Could you please review it and point out beginner mistakes?</p> <pre><code>from sys import exit inventory = [] ground = ['Bones', "Commander's Key", 'Security Code', 'Shipm...
[]
[ { "body": "<p>I would be inclined to reduce some of the duplication using dictionaries and functions, if not classes. </p>\n\n<p>For example, you repeatedly take user input from defined choices, which could all be done by:</p>\n\n<pre><code>def get_input(choices):\n for choice in sorted(choices):\n pr...
{ "AcceptedAnswerId": "44111", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T21:34:15.980", "Id": "43450", "Score": "5", "Tags": [ "python", "beginner", "game", "homework", "python-2.x" ], "Title": "Fallout-style homework game" }
43450
<p>I am initializing a PHP array as follows</p> <pre><code>$newArray = array(); $newArray['2014-13-03']['SMD']['IMPR'] = 5; $newArray['2014-13-03']['SMD']['CLICK'] = 10; </code></pre> <p>I just wanted to check if you think this is a wrong way to insert data into an array. It is working just fine, but I still wanted t...
[]
[ { "body": "<p>I would do the definition inline with the declaration:</p>\n\n<pre><code>$newArray = array(\n '2014-13-03' =&gt; array(\n 'SMD' =&gt; array(\n 'IMPR' =&gt; 10,\n 'CLICK' =&gt; 10\n )\n )\n);\n</code></pre>\n\n<p>If you wanted to lean towards the more compa...
{ "AcceptedAnswerId": "43454", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T21:47:00.403", "Id": "43452", "Score": "5", "Tags": [ "php", "array" ], "Title": "Multidimentional array initialization" }
43452
<p>I designed a program that calculates the square root of a number using Newton's method of approximation that consists of taking a guess (<code>g</code>) and improving it (<code>improved_guess = (x/g + g)/2</code>) until you can't improve it anymore:</p> <pre><code>#include &lt;iostream&gt; #include &lt;iomanip&gt; ...
[]
[ { "body": "<p>Looks fairly good over all, but a few things jumped out at me. Please note that the stylistic ones are opinion based.</p>\n\n<hr>\n\n<p>Make sure you don't get into a habit of <code>using namespace std;</code>. It's acceptable in some places, but it can form a bad habit very easily. Your code is a...
{ "AcceptedAnswerId": "43491", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T22:25:04.920", "Id": "43456", "Score": "8", "Tags": [ "c++", "mathematics" ], "Title": "Square root approximation with Newton's method" }
43456
<p>I've been studying C# for about 6 months and am trying to make a simple example for an n-tier application. I want to learn to do things in the most proper and professional way. This example uses a table in the database called "Settings" where various application settings can be persisted to the database. I figure on...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-06T10:00:50.100", "Id": "75383", "Score": "1", "body": "So nobody has commented on this yet... I think it looks good from a quick glance. I haven't thoroughly went over it but from I've seen it looks good. Just thought I should say tha...
[ { "body": "<p>Of your questions, 1, 4, 5 all seem to hit on a common theme I think you might be missing the point of. The <a href=\"http://en.wikipedia.org/wiki/Single_responsibility_principle\">Single Responsibility Principle</a> says that every object should have exactly one reason to change. The nuances of t...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T23:03:53.587", "Id": "43463", "Score": "15", "Tags": [ "c#", "design-patterns" ], "Title": "Simple example of N-Tier, entity framework, unit of work, repository, business logic layer"...
43463
<p>Here is my solution to this problem; please be brutally honest/strict, if I would have written this code, in a 45 minute interview, what would you think? (I am aiming for Google,Facebook).</p> <p>Here is the problem I solved:</p> <p>*Given a linked list, reverse the nodes of a linked list k at a time and return it...
[]
[ { "body": "<h2>Brutally honest?</h2>\n<p>If this is an interview, and you provide this line of code:</p>\n<blockquote>\n<pre><code>Queue linkQueue = new LinkedList();\n</code></pre>\n</blockquote>\n<p>Your resume gets put in the pile of 'ignore this person if they apply again'... ;-)</p>\n<p>Genercis have been ...
{ "AcceptedAnswerId": "43465", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T23:06:14.517", "Id": "43464", "Score": "20", "Tags": [ "java", "algorithm", "linked-list", "interview-questions" ], "Title": "Reversing k-sized sequences in a linked-list" ...
43464
<p>Here is my attempt at the UTTT <a href="/questions/tagged/code-challenge" class="post-tag" title="show questions tagged &#39;code-challenge&#39;" rel="tag">code-challenge</a> (in response to the the <a href="https://codereview.meta.stackexchange.com/a/1472/27623">Weekend-Challenge Reboot</a>). Here is what I would ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-05T00:10:33.157", "Id": "75116", "Score": "0", "body": "I think if you move the game logic out the main is better. Something like while (isGameRunning ()) do game logic manage input etc. All with functions." } ]
[ { "body": "<p>A few comments:</p>\n\n<p>[ ... ]</p>\n\n<pre><code>for (; (x % 3) != 0; x--); // quickly set x to left bound of sub-board\nfor (; (y % 3) != 0; y--); // quickly set y to upper bound of sub-board\n</code></pre>\n\n<p>I think I'd move the code to round to a multiple of three into a function of its ...
{ "AcceptedAnswerId": "43481", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T23:59:34.227", "Id": "43466", "Score": "39", "Tags": [ "performance", "c", "game", "tic-tac-toe", "community-challenge" ], "Title": "Ultimate Tic-Tac-Toe in C" }
43466
<p>I'm trying to do a SPOJ problem called twosquares where you check whether the current number can be obtained by adding two squares together. However, I'm getting a "time limit exceeded" message.</p> <p>I'm creating a Sieve of Eratosthenes program. If the number <em>n</em> is prime and</p> <blockquote> <p><em>n...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-05T19:55:13.153", "Id": "75330", "Score": "1", "body": "clean up your formatting a little bit please" } ]
[ { "body": "<p>Your code is a mess, does not follow any standard naming conventions, and the indentation makes it really difficult.</p>\n\n<p>It is not really worth reading. You need to fix it.</p>\n\n<p>But, since you have tagged this <a href=\"/questions/tagged/algorithm\" class=\"post-tag\" title=\"show quest...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-05T00:45:39.920", "Id": "43469", "Score": "3", "Tags": [ "java", "optimization", "algorithm", "primes", "mathematics" ], "Title": "Sum of two squares" }
43469
<p>I've decided to implement a simple smart pointer:</p> <pre><code>#pragma once //simple and basic reference by Aldrigo Raffaele #include "Common.h" #include "Exceptions.h" class MemWrp { private: uint numref; public: void* content; MemWrp(void* content) { thi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T20:10:19.830", "Id": "75124", "Score": "11", "body": "C++ includes smart pointers already, why implement another? Also, this question is probably better suited to the Code Reviews Stack Exchange." }, { "ContentLicense": "CC ...
[ { "body": "<p>Is <code>destructor</code> a new C++ keyword?</p>\n\n<p>In the assignment operator you want to decrement the reference count even when rhs is null.</p>\n\n<p>Calling delete on a void* content in MemWrp won't call the T destructor.</p>\n\n<p>Allowing <code>Ref(int ptr)</code> construction doesn't m...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-04T20:08:54.340", "Id": "43472", "Score": "1", "Tags": [ "c++", "reinventing-the-wheel", "smart-pointers" ], "Title": "Smart pointer implementation" }
43472