body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I have been attempting to write a code that converts Prefix expressions to Postfix expressions.</p> <p>So far here's what I have made (note that I am new and hence it may not be efficient!) </p> <pre><code>/*************************************************** NOTE: This code fails to realise the precedence of ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T11:05:52.080", "Id": "48378", "Score": "0", "body": "May be here is bug: `a[++top] = x;` You will write first value at index 1, not 0." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T11:13:39.497", ...
[ { "body": "<p>You are talking about Polish notation (PN) and reverse Polish notation (RPN):</p>\n\n<ul>\n<li><a href=\"http://en.wikipedia.org/wiki/Polish_notation\" rel=\"nofollow\">http://en.wikipedia.org/wiki/Polish_notation</a></li>\n<li><a href=\"http://en.wikipedia.org/wiki/Reverse_Polish_notation\" rel=\...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T10:35:40.640", "Id": "30426", "Score": "2", "Tags": [ "java", "algorithm", "homework", "converting" ], "Title": "Conversion of expression from Prefix to Postfix notation (Prob...
30426
<p>The problem is <a href="http://www.haskell.org/haskellwiki/99_questions/11_to_20" rel="nofollow">here</a>, the solutions are <a href="http://www.haskell.org/haskellwiki/99_questions/Solutions/18" rel="nofollow">here</a>. I don't see a solution like mine (maybe the 4th), it seems to work though.</p> <pre><code>-- --...
[]
[ { "body": "<p>Yes you forgot to cover some cases.</p>\n\n<p>Your compiler should be able to detect one of them. Here is what <code>ghc -Wall</code> says:</p>\n\n<pre><code>slice.hs:2:1: Warning:\n Pattern match(es) are non-exhaustive\n In an equation for `slice':\n Patterns not matched: [] _ (GHC.T...
{ "AcceptedAnswerId": "30434", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T11:12:19.297", "Id": "30431", "Score": "1", "Tags": [ "haskell" ], "Title": "99 Haskell problems, problem 18" }
30431
<p>Here is my solution <a href="https://stackoverflow.com/questions/18326787/display-message-if-close-window-in-asp-net-but-not-on-postback">for this stackoverflow question.</a></p> <p>It is designed to return an <code>onbeforeunload</code> message when the user leaves the page (excluding postbacks). It does this by l...
[]
[ { "body": "<p>Interesting question,</p>\n\n<p>I think the biggest thing is that <code>callee</code> is <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments/callee\" rel=\"nofollow\">going the way of the Dodo bird</a>.</p>\n\n<p>JsHint does not like y...
{ "AcceptedAnswerId": "60376", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T12:17:41.763", "Id": "30435", "Score": "1", "Tags": [ "javascript", "jquery", "asp.net" ], "Title": "Wrapping postback functions to call custom code at execution" }
30435
<p>Which is the best practice in getting data from repository? passing just by object or by Id?</p> <pre><code>public IQueryable&lt;Attendance&gt; GetByPersonId(int id) { return DbSet.Where(ps =&gt; ps.PersonId == id); } </code></pre> <p>or </p> <pre><code>public IQueryable&lt;Attendance&gt; GetByPer...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T07:59:51.603", "Id": "51064", "Score": "2", "body": "I personally would probably just pass the Id as then the caller does not have to assume knowledge of the method. Otherwise they have to pass an entire person object because who k...
[ { "body": "<p>I think you may pass complete entity because you already have it, this allow you do another condition type if you need.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T06:24:56.687", "Id": "30...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T13:09:45.650", "Id": "30436", "Score": "3", "Tags": [ "c#", "entity-framework" ], "Title": "Pass by Entity or EntityId in repositories?" }
30436
<p>I'd like to improve my code, but I'm not sure where to start. Everything works as I want it to; I just think it's ugly. </p> <p>I'll split this into two parts:</p> <ol> <li><p>I have two drop-downs that I'll explain later. In these drop-downs, I have options to set currency and language. I use a hidden form to set...
[]
[ { "body": "<p>My 2 cents:</p>\n\n<ul>\n<li>Use jQuery toggleClass : <a href=\"http://api.jquery.com/toggleClass/\" rel=\"nofollow\">http://api.jquery.com/toggleClass/</a></li>\n<li>Use camelCase : currencycode -> currencyCode etc.</li>\n<li>Use English everywhere : 'monnaie' should not be there</li>\n<li>Boolea...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T14:06:22.013", "Id": "30441", "Score": "3", "Tags": [ "javascript", "jquery" ], "Title": "Setting currency and language values" }
30441
<p>So far I've implemented a way to add to my <code>RedBlackTree</code> (will be used with A* pathfinding - hence the F value). I'm not entirely sure how to improve it further.</p> <p>I want to add a remove function to this tree, but can't find anything online that suits my style of tree. Any help? I only need to del...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T16:35:17.333", "Id": "48399", "Score": "4", "body": "Asking how to add something to your code is off topic for this site. Though asking how to improve it in general isn't." }, { "ContentLicense": "CC BY-SA 4.0", "Creatio...
[ { "body": "<h2>Edit / Update:</h2>\n\n<p>I noticed that you have a misplaced curly bracket (<code>}</code>) that makes it so that your last class is inside of your first class, <strong>meaning that this code shouldn't compile</strong>. </p>\n\n<hr>\n\n<p>For some reason I don't like <code>Else if</code> at the...
{ "AcceptedAnswerId": "30521", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T14:26:13.993", "Id": "30442", "Score": "6", "Tags": [ "c#", "algorithm", "tree", "pathfinding" ], "Title": "A* path finding algorithm for a red-black tree" }
30442
<p>I'd like this code reviewed.</p> <pre><code>import java.util.NoSuchElementException; public class MergeSort { private Node first; private Node last; private static class Node { int element; Node next; Node(int element, Node node) { this.element = element; ...
[]
[ { "body": "<p>Starting with some Java API documentation:</p>\n\n<blockquote>\n <p>public class NoSuchElementException\n extends RuntimeException</p>\n \n <p>Thrown by the nextElement method of an Enumeration to indicate that there are no more elements in the enumeration.</p>\n</blockquote>\n\n<p>This is not...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T18:08:47.857", "Id": "30445", "Score": "1", "Tags": [ "java", "sorting", "linked-list", "mergesort" ], "Title": "Merge sort with a linked list" }
30445
<p>I have a jQuery "checkbox checked/unchecked" function that works well. This is a checkbox for turning a particular URL parameter on or off. But I believe this code could be written a lot tighter. Does anyone have any suggestions?</p> <pre><code>$('#mapControl').live('click', function(){ var thisUrl = $(location)....
[]
[ { "body": "<p>This is tighter I think:</p>\n\n<pre><code>function addParameter( url , name , value )\n{\n var justHostname = ( location.href == ( location.protocol + \"//\" + location.host + \"/\" ),\n separator = justHostname?\"?\":\"&amp;\"\n return url + separator + encodeURIComponent(name) + \"=\" + ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T18:16:54.780", "Id": "30446", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Determine whether a checkbox is checked or unchecked" }
30446
<p>So, I'm diving into C and decided to create cons cells. I'd like some thoughts on style and correctness. There are no warnings with <code>-Wall -g</code> and Valgrind doesn't complain about anything.</p> <p>I'm really not sure what to do when the list is <code>NULL</code> in the <code>first</code> function.</p> <p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T01:56:31.633", "Id": "48449", "Score": "0", "body": "I like it! Apart from the in-band error return in `first` I think it is very good C." } ]
[ { "body": "<p>A few comments:</p>\n\n<p><code>typedef</code> your <code>struct</code>s:</p>\n\n<pre><code>typedef struct Cell\n{\n int val;\n struct Cell *next;\n} Cell;\n</code></pre>\n\n<p><code>typedef</code> means you no longer have to write <code>struct</code> all over the place:</p>\n\n<pre><code>Ce...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T18:18:19.867", "Id": "30447", "Score": "1", "Tags": [ "c" ], "Title": "Basic cons cells in C" }
30447
<p>I wrote this little program, but I'm not sure if it's properly written. Actually, it can't handle leap years (every year is 365 days long) and you have to write the earlier date before. It seems to be working correctly.</p> <p>Can you tell me if it's okay or not, and what should I change in it to make it good?</p>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T20:17:35.370", "Id": "48416", "Score": "2", "body": "You are doing it the hard way. Convert your dates into unix time stamps (or similar single value ratio). Do a single subtraction then divide by (24*60*60)." } ]
[ { "body": "<ul>\n<li><p><a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\">Do not use <code>using namespace std</code> in global scope</a>.</p></li>\n<li><p><em>Never use global variables</em>. Right away, this will introduce all sorts of problems, includ...
{ "AcceptedAnswerId": "30451", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T18:42:13.923", "Id": "30448", "Score": "7", "Tags": [ "c++", "algorithm", "datetime", "reinventing-the-wheel" ], "Title": "Day counter between two dates" }
30448
<p>In the effort to improve my C knowledge, I tried creating a wildcard search function:</p> <pre><code>bool wildcard(char *value, char *wcard) { size_t vsize = strlen(value); size_t wsize = strlen(wcard); bool no_match = false; if (wsize &gt; vsize) { return false; } for (int w = 0,...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T10:12:01.667", "Id": "49297", "Score": "0", "body": "By the way, when you're not coding for recreational/educational purposes, just use the POSIX `fnmatch()` function." } ]
[ { "body": "<p>There's no need for the <code>goto</code>s whatsoever. Just use the appropriate <code>bool</code>s. You also complicate the logic by giving a variable and a <code>goto</code> the same name.</p>\n\n<p>I'd put <code>MULTICHAR</code>'s work in a function for clarity.</p>\n\n<p>Personally, I prefer ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T21:26:25.180", "Id": "30456", "Score": "4", "Tags": [ "c", "strings", "search" ], "Title": "Wildcard search in C" }
30456
<p>I have implemented the following code:</p> <pre><code>class A { abstract void f1(Object obj, Object data); } class A1:A { void f1(Object obj, Object data) { m1(obj,data); } void m1(Object obj, Object data) { } } class A2:A { void f1(Object obj, Object data) { m...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T06:37:25.693", "Id": "48427", "Score": "0", "body": "Your code is strange why you do that :\n obj.f1(obj);\n\nfor me is not necessary to pass obj at f1 because is \"this\" in the body methode." } ]
[ { "body": "<p>The code still looks a bit strange to me.</p>\n\n<pre><code>obj.f1(obj);\n</code></pre>\n\n<p>Why are you passing the object as a parameter when the method already is a member? Skip the parameter and use <code>this</code> instead.</p>\n\n<p>You should also try to minimize the number of method the ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T06:25:28.837", "Id": "30458", "Score": "1", "Tags": [ "c#", "design-patterns" ], "Title": "Refactoring implementation in.NET" }
30458
<p>Are there any issues in this code?</p> <pre><code>/// &lt;summary&gt; /// This function gets the unique identifier of a member by the given /// login user name of that member on our web site. /// &lt;/summary&gt; /// &lt;param name="userName"&gt;The username&lt;/param&gt; public static string GetMemberNumberByUserI...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T21:50:42.200", "Id": "48431", "Score": "0", "body": "As mentioned below, not closing the connection. Also I would consider not handling the exception and letting it bubble up instead" } ]
[ { "body": "<p>One thing is that you never close the SQL connection. I would change that structure a bit and put things inside a <code>using</code> block:</p>\n\n<pre><code>using (SqlConnection database = new SqlConnection(connectionString))\n{\n try\n {\n //other code\n }\n catch(Exception)\...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T21:34:49.810", "Id": "30460", "Score": "3", "Tags": [ "c#", "database" ], "Title": "Getting the unique identifier from a given login username" }
30460
<p>I want to get the filename and last 23 characters when I drag into a textbox.</p> <p>I have it working, but I would like to just have one line. Currently, I think I am doing a bit of a workaround. As I must use a string array, and I only want one string, so I don't really need an array.</p> <pre><code>private voi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T23:30:04.860", "Id": "48442", "Score": "0", "body": "Thanks as always Jamal, much appreciated for the corrections:)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T23:31:37.010", "Id": "48443", ...
[ { "body": "<p>Yes, you can write everything in one line, but you will not be happy with the result. And no, .Net creators did not think of implementing a single call which would return exactly 23 characters of dropped file name. :) Silly them. :) </p>\n\n<p>Meanwhile, your code makes sense. I see only two possi...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T23:18:48.327", "Id": "30468", "Score": "1", "Tags": [ "c#" ], "Title": "Drag Drop, get filename and last 23 characters" }
30468
<p>This is an implementation of a trie, that I will be using on a code editor to parse keywords from a given <em>programming</em> language. I decided to use a trie when I asked <a href="https://stackoverflow.com/questions/18347793/optimizing-a-word-parser">this question</a>, and the implementation seems to perform pret...
[]
[ { "body": "<p>On the assumption that the list of keywords does not change often, the fastest code will be to precompile your trie into a tree of switch statements like this, where <code>p</code> is the current character pointer, and suppose your keywords are <code>a</code>, <code>aa</code>, <code>ab</code>, <co...
{ "AcceptedAnswerId": "31547", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T23:33:29.063", "Id": "30469", "Score": "3", "Tags": [ "optimization", "c", "performance", "parsing", "trie" ], "Title": "Improving Trie Implementation" }
30469
<p>I've been told that my code is horribly-written. It works exactly the way I want it to, but I have been told that it needs to be safer and more efficient.</p> <p><a href="https://gist.github.com/Thorbis/b858c303a8e1452f251e" rel="nofollow">Here's the code</a>.</p> <p>Here's the main PHP script:</p> <pre><code>&l...
[]
[ { "body": "<p>There is quite a lot that can be done</p>\n\n<p>For a start use mysqli_ functions as mysql_ functions are deprecated</p>\n\n<p>on database queries, it is good practice to check for errors (like this)</p>\n\n<pre><code>// $dbunames = mysql_query(\"SELECT * FROM users WHERE website='$website'\");\n$...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T00:43:27.697", "Id": "30472", "Score": "3", "Tags": [ "php", "recursion" ], "Title": "Recursive Directory Copy" }
30472
<p>I've got a CSV that contains users and permissions in the below format, where users can have as little as one or as many as eight different permissions:</p> <pre class="lang-none prettyprint-override"><code>USER,PERM1,PERM2,PERM3,PERM4,PERM5,PERM6,PERM7,PERM8 jdoe,perm1,perm2 tsmith,perm1,perm2,perm3,perm4,perm5,pe...
[]
[ { "body": "<p>This is shorter:</p>\n\n<pre><code>import csv\n\n\ndef reformat_ul(original_ul, formated_ul):\n with open(formated_ul, 'w') as output2:\n output2.write('USER,PERM\\n')\n with open(original_ul) as user_list:\n dict_reader = csv.DictReader(user_list)\n for row ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T01:00:12.460", "Id": "30473", "Score": "4", "Tags": [ "python", "regex", "csv" ], "Title": "Managing a CSV of users and permissions" }
30473
<p>For the following problem statement, I design following classes. Can you please tell me if this is the correct implementation or if there can be a better one?</p> <p>Let's say there is call center with three levels of employees: fresher, technical lead (TL), product manager (PM). There can be multiple employees, b...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T10:50:25.897", "Id": "48508", "Score": "0", "body": "I think \"CallManager` is a very bad name, it does not describe what the class does (\"manage\" can mean almost anything). There is a method named \"..AllocateCall\", this is clos...
[ { "body": "<ol>\n<li>I like the <code>Employee</code> class with the built-in <code>Manager</code> chain.</li>\n<li>I think <code>Call</code> class should be \"dumb\" like the <code>Employee</code>. The methods seem like call processing - what the <code>CallManager</code> should be doing.</li>\n<li>Id say part ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T01:05:24.417", "Id": "30474", "Score": "2", "Tags": [ "c#", ".net" ], "Title": "Design class to handle calls for support functions" }
30474
<p>How might I refactor this to get rid of all the if-else?</p> <pre><code> def self.dispatches_for(object) scope = Dispatch.asc(:days) if object.class == Habit scope.where(:habit=&gt;object).map{|d|d} elsif object.class == User scope.where(:coach=&gt;object).map{|d|d} elsif object.class =...
[]
[ { "body": "<pre><code>def self.dispatches_for(object)\n klass = object.class.to_s.downcase.to_sym\n raise \"unacceptable class\" unless klass.in? [:habit, :coach, :content]\n scope = Dispatch.asc(:days)\n scope.where(klass=&gt;object).map{|d|d}\nend\n</code></pre>\n", "comments": [ { "Cont...
{ "AcceptedAnswerId": "30480", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T01:30:55.930", "Id": "30475", "Score": "0", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Creating a generic function for objects of different classes" }
30475
<p>I am new to C, so I have been trying to get practice doing some coding.</p> <p>Usually I use languages like Java, python, ruby, etc: Garbage collected languages. So manually cleaning up is new to me and I would appreciate any advice on whether there are major flaws in my approach.</p> <p>Also any other comments on...
[]
[ { "body": "<p>The code looks nice. Just a few comments: </p>\n\n<p>In <code>new_node</code>, your word-copying is wrong as you use <code>sizeof(nword)</code> where\n<code>nword</code> is a pointer. Using <code>sizeof</code> on a pointer gives only the size of the\npointer itself, not the size of what it poin...
{ "AcceptedAnswerId": "30530", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T05:14:29.857", "Id": "30486", "Score": "3", "Tags": [ "c", "memory-management" ], "Title": "Does this C binary search tree have memory leaks?" }
30486
<p>I have implemented a recursive <code>O(n log n)</code> algorithm for solving the maximum sub-array problem. I would like a general review for it.</p> <p>Here the <code>max_subarray</code> is the main function, and the <code>static</code> one is the auxillary function for it.</p> <pre><code>#include&lt;stdio.h&gt; ...
[]
[ { "body": "<p>Your program fails when all of the members of an array are negative, it simply returns <code>0</code> instead of the maximum negative number. </p>\n\n<hr>\n\n<p>Recursion here is slowing you down. Using <a href=\"https://en.wikipedia.org/wiki/Maximum_subarray_problem#Kadane.27s_algorithm\" rel=\...
{ "AcceptedAnswerId": "38603", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T06:34:06.747", "Id": "30489", "Score": "7", "Tags": [ "c", "recursion" ], "Title": "Maximum Subarray Problem - Recursive O(n log n) algorithm" }
30489
<p>I implemented an iterative \$O(n)\$ algorithm for solving the maximum sub-array problem. I would like a general review for it.</p> <p>Here the <code>max_subarray</code> is the main function and the ones which are <code>static</code> are auxiliary functions for it.</p> <pre><code>#include&lt;stdio.h&gt; int max_su...
[]
[ { "body": "<h3>Subarray representation</h3>\n\n<ul>\n<li><strong>Name of <code>low</code> and <code>high</code>:</strong> I prefer <code>lower</code> and <code>upper</code> because they contain the same number of characters, so that code lines up nicely. ☺︎</li>\n<li><p><strong>Inclusive-inclusive intervals:</s...
{ "AcceptedAnswerId": "36538", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T06:36:20.337", "Id": "30491", "Score": "4", "Tags": [ "c", "array" ], "Title": "Maximum Subarray Problem - Iterative O(n) algorithm" }
30491
<p>I have an accordion that checks if there is data to be displayed and if so, the accordion show the data from the specific month.</p> <p>Is there a way to simplify the code below?</p> <pre><code>&lt;?php $conn = mysql_connect("localhost","user","pass"); mysql_select_db("lista_de_analize"); mysql_set_cha...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T07:14:04.167", "Id": "48466", "Score": "0", "body": "What's the point of filtering by month if you want all of them? Are you looking for counts or averages?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-0...
[ { "body": "<p>Hopefully you can understand what I have done, I have written comments in English</p>\n\n<pre><code>&lt;?php\n\n// mysql_ is deprecated use mysqli_\n// die on error\n$link = mysqli_connect(\"localhost\",\"user\",\"pass\") or die(mysqli_connect_error());\nmysqli_select_db($link, \"lista_de_analize\...
{ "AcceptedAnswerId": "30493", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T07:12:49.967", "Id": "30492", "Score": "2", "Tags": [ "php", "mysql" ], "Title": "Displaying data for a specific month with an accordion" }
30492
<p>I'd like feedback on my callbacks/promises alternative, please.</p> <p><a href="https://github.com/Lcfvs/yld/" rel="nofollow">The yld repository</a></p> <pre><code>var yld; yld = (function () { 'use strict'; var slice, clearer, defer, prepare, yld; slice = Array.prototype.slice; clearer = { yld: { ...
[]
[ { "body": "<p>Interesting question;</p>\n\n<p>I honestly can't follow the code, and I tried a while. I like to think of myself as above average in JavaScript, which means that from a readability/maintainability perspective you have a problem. It might be related to the fact that you have no comments in there ;)...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T09:04:30.157", "Id": "30498", "Score": "2", "Tags": [ "javascript", "node.js", "callback", "promise" ], "Title": "My yld NPM - callbacks/promises alternative" }
30498
<p>I've been reading the security issue on logging out from a website system written in PHP, using sessions.</p> <p>My current code is:</p> <pre><code>session_start(); if (isset($_SESSION["logged_in"])) { unset($_SESSION["logged_in"]); unset($_SESSION["ss_fprint"]); unset($_SESSION["alive"]); session...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T10:27:38.383", "Id": "48505", "Score": "1", "body": "die() is usually used to indicate an error, I would use exit; instead." } ]
[ { "body": "<p>looks alright enough. i would change is replace all those unset() lines with just <code>$_SESSION = array();</code></p>\n\n<p>and check the <a href=\"http://sg3.php.net/session_destroy\" rel=\"nofollow\">manual</a>, it has a sample to clear your session cookies if you have them enabled.</p>\n", ...
{ "AcceptedAnswerId": "30501", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T09:33:14.003", "Id": "30500", "Score": "1", "Tags": [ "php", "security", "session" ], "Title": "Secure logout: session termination" }
30500
<p>I've tried implementing priority queue with fixed size in Java using <code>TreeSet</code> and overriding <code>add()</code> method:</p> <pre><code>public class FixedSizePriorityQueue&lt;E&gt; extends TreeSet&lt;E&gt; { private final int capacity; public FixedSizePriorityQueue(final int capacity) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T10:10:00.930", "Id": "48500", "Score": "1", "body": "Are you sure you want your `FixedSizePriorityQueue` be a `TreeSet`? Do you want to support all methods of a `TreeSet` ? I would internally use a `TreeSet` but not extend it." },...
[ { "body": "<p>Two thoughts:</p>\n\n<ol>\n<li><p>If there is other code and you need all the features of a TreeSet great, otherwise delegate to a TreeSet member variable.</p></li>\n<li><p>Your code <code>if (capacity &lt;= 0)</code> is somewhat superfluous because of the next test <code>if (size() &lt; capacity)...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T10:01:05.937", "Id": "30504", "Score": "4", "Tags": [ "java", "queue" ], "Title": "Fixed size priority queue" }
30504
<p>I wrote this little code in c++. It calculates the needed time for a given speed of a medium (for example the speed is 1024 B/s, the file size is 1MB, it'll take 17 minutes and 4 seconds to finish). The code works, but I'm not sure if it's proper. </p> <p>Can you tell me if it's okay or not?</p> <pre><code>#includ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T12:08:10.783", "Id": "48519", "Score": "0", "body": "This code is incredibly clean and easy to read, however, you might want to eliminate the output for `days_needed` when `days_needed` is 0. Think about that. It will make the progr...
[ { "body": "<p>The code looks good though, did you miss on the <code>minutes needed</code>?</p>\n<p>All the calculations you're doing are on <code>int</code>. You may consider using <code>float</code> at some places.</p>\n<blockquote>\n<p>e.g.:</p>\n<p>file-size-in-MB may be 3.4MB</p>\n<p>transmission-speed-in-b...
{ "AcceptedAnswerId": "30509", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T11:25:30.497", "Id": "30506", "Score": "5", "Tags": [ "c++", "algorithm" ], "Title": "Time calculator for a given speed and file size" }
30506
<p>For a project I need to replicate a website and I was wondering if any of you could take a quick look to see if I made any obvious mistakes. Right now it's just the HTML part, but I would like to make sure everything is correct in the HTML part before I move on to the CSS. Picture added below. Thanks in advance!</p>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T12:31:29.477", "Id": "48521", "Score": "0", "body": "Are you asking whether your HTML could be a faithful replica of the site (given the right CSS)? Or are you asking for general review of your code?" }, { "ContentLicense": ...
[ { "body": "<p>Not important in this case, but it’s a good practice in general:<code>meta</code>-<code>charset</code> should be the first element in <code>head</code>.</p>\n\n<p>You shouldn’t duplicate the information \"Vraag het aan Anna\" in the <code>alt</code> attribute. But anyway, to me this image doesn’t ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T12:03:07.020", "Id": "30510", "Score": "2", "Tags": [ "html" ], "Title": "replica site checkup" }
30510
<p>I've written a GM script to filter some results from Experteer.com results: specifically, many of the rows are "only for Premium members" and don't allow you to click through or see details, so I've written the script to hide those results from cluttering the display. </p> <p>I'm very much a newbie to JavaScript an...
[]
[ { "body": "<p>If you want to maximize the speed, to iterate big arrays, use</p>\n\n<pre><code>for (var i = 0, l = array.length; i &lt; l; i++)\n</code></pre>\n\n<p>instead of</p>\n\n<pre><code>for (var i = 0; i &lt; array.length; i++)\n</code></pre>\n\n<p>Moreover, if you want to get the elements of a class, th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T12:13:59.790", "Id": "30511", "Score": "1", "Tags": [ "javascript", "beginner", "web-scraping", "userscript" ], "Title": "Greasemonkey script for filtering out results from ex...
30511
<p>I have 2 nested resources in one of my Rails apps and the way the index is handled by the inner resources bothers me somewhat:</p> <pre><code>def index @program = Program.approved.find(params[:program_id]) if params[:program_id] if params[:tags] tags = params[:tags].split(" ") if @program ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T13:57:00.373", "Id": "48723", "Score": "0", "body": "What the url to #index will look like with tags?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T14:27:26.350", "Id": "48725", "Score": "0"...
[ { "body": "<p>You could get rid of the code duplication by making use of the fact, that arel expressions are lazily evaluated:</p>\n\n<pre><code>def index\n @program = Program.approved.find(params[:program_id]) if params[:program_id]\n\n sites =\n if @program\n Site.where(program_id: @program)\n el...
{ "AcceptedAnswerId": "30534", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T12:46:32.517", "Id": "30512", "Score": "1", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Rails 3 nested controller method" }
30512
<p>This is my implementation based on <code>Map&lt;K,V&gt;</code> interface. The BST is a linked binary tree with root reference, both internal and external nodes (<code>MyBSNode</code>) contains <strong>(key, value)</strong> entries</p> <p>What do you think? There's something to improve?</p> <pre><code>public BSPosi...
[]
[ { "body": "<p>The algorithm looks fine. Some other notes:</p>\n\n<ol>\n<li><p>I would use longer variable names than <code>r</code>, <code>k</code>, <code>e</code> etc. Longer names would make the code more readable since readers/maintainers don't have to decode or memorize the abbreviations.</p></li>\n<li>\n\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T15:41:08.943", "Id": "30519", "Score": "3", "Tags": [ "java", "binary-search", "tree" ], "Title": "Binary Search Tree insert method (map interface)" }
30519
<p>I wrote this converter code. It can convert a number from 1-100 into words. It works perfectly, but it seems to be too complicated to me. </p> <p>Can you tell me whether it's okay or not? </p> <pre><code>#include &lt;iostream&gt; int main() { int number; int first_digit; int second_digit; std::cou...
[]
[ { "body": "<p>Code will break on <code>20</code></p>\n\n<pre><code>if(number &gt;= 11 &amp;&amp; number &lt;= 20)\n{\n switch(number)\n {\n ......\n case 19:\n std::cout&lt;&lt;\"nineteen\";\n break;\n /// No Twenty here.\n }\n}\n</code></pre>\n", "comments": []...
{ "AcceptedAnswerId": "30527", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T19:35:33.927", "Id": "30525", "Score": "6", "Tags": [ "c++", "algorithm", "numbers-to-words" ], "Title": "Convert number to words" }
30525
<p>I'm a bit clumsy at writing JavaScript. I have some nice code like this:</p> <pre><code>(function($){ $.fn.forceNumeric = function(){ return this.each(function(){ $(this).keyup(function(){ if (!/^[0-9]+$/.test($(this).val())){ $(this).val($(this).val().re...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T17:17:58.960", "Id": "48634", "Score": "0", "body": "can you also show the html? there seem to be an awful lot of divs here, I can't quite maek sense of them" } ]
[ { "body": "<p>You could start by minimizing your function calls. like so </p>\n\n<p><strong>ORIGINAL</strong></p>\n\n<pre><code>$.fn.forceNumeric = function(){\n return this.each(function(){\n $(this).keyup(function(){\n if (!/^[0-9]+$/.test($(this).val())){\n $(this).val($(t...
{ "AcceptedAnswerId": "30531", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T20:14:21.270", "Id": "30528", "Score": "0", "Tags": [ "javascript", "jquery", "validation" ], "Title": "Function to show or hide validation error messages" }
30528
<p>I'm wondering how I could improve my list's element-adding speed or just the whole list implementation.</p> <p>The adding function first checks if the object is unique. If not, it will just check if the new data is better (the lower the value, the better) than the old one, then swap the values or just skip adding a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T21:23:38.823", "Id": "48567", "Score": "0", "body": "If this is C++ and not C, shouldn't you be using `std::string` instead of `char*`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T21:26:31.667", ...
[ { "body": "<ul>\n<li>Are you suppose to add elements to an empty list? If you are adding to an empty list, then you can add them in ascending order or descending order. </li>\n<li>The problem you have is that you will be adding unknown element to the list i.e it could be &lt; or == or > than this element. In th...
{ "AcceptedAnswerId": "30685", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T20:57:06.163", "Id": "30533", "Score": "4", "Tags": [ "c++", "optimization", "linked-list" ], "Title": "How to improve my list's speed" }
30533
<p>I am learning C and tried to make a basic singly linked list. I am looking for some feedback on my implementation. I have implemented deletion and reversal functions. Be hard on me as I am trying to improve.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; //very basic linked list implimentation i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T22:38:42.977", "Id": "48987", "Score": "0", "body": "Your current `deleteNodes` is wrong. What happens if the first two elements are to be deleted?" } ]
[ { "body": "<p>I suggest using this declaration:</p>\n\n<pre><code>typedef struct _node {\n int val;\n struct _node *next;\n} node;\n</code></pre>\n\n<p>After that, you can declare <code>node *t</code> instead of <code>struct node *t</code>. Also, you'll use <code>sizeof(node)</code> instead of <code>sizeof(st...
{ "AcceptedAnswerId": "30541", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T22:42:15.667", "Id": "30536", "Score": "5", "Tags": [ "c", "linked-list" ], "Title": "Simple linked list implementation" }
30536
<p>Any reviews/ways to speed up/general improvements for my Merge Sort? Maybe something to simplify it or add more to it?</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace prjT02L08_Predator_Prey { abstract class MergeSort { public static Li...
[]
[ { "body": "<pre><code>abstract class MergeSort\n</code></pre>\n\n<p>This class shouldn't be <code>abstract</code>, it should be <code>static</code>.</p>\n\n<pre><code>public static List&lt;Node&gt; Sort(List&lt;Node&gt; input)\n</code></pre>\n\n<p>Why does the method require <code>List</code>? Wouldn't it be be...
{ "AcceptedAnswerId": "30556", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T04:34:28.613", "Id": "30545", "Score": "5", "Tags": [ "c#", "performance", "recursion", "sorting", "mergesort" ], "Title": "Merge Sort Implementation" }
30545
<p>I wrote this pretty simple program (it's an exercise from a book). It counts the words in a simple string. The book is a very old one (I think it's from 2003) and uses char arrays. Because of this, I don't know if this solution is a proper one or not.</p> <p>Can you tell me whether it is okay or not? </p> <pre><co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T16:47:48.790", "Id": "48628", "Score": "0", "body": "If you enter multiple spaces each will register as a word Try: 'A B C' (note two spaces between words). This will return 5. Its an OK algorithm to start with as long as they the...
[ { "body": "<p>I am far from an expert in C++ but I am going to give this a shot.</p>\n\n<pre><code>int count_words(std::string);\n</code></pre>\n\n<p>you have this declared inside of the main() function. This is a function prototype and should be outside of the main function ex:</p>\n\n<pre><code>#include &lt;i...
{ "AcceptedAnswerId": "30551", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T07:00:55.337", "Id": "30547", "Score": "8", "Tags": [ "c++", "algorithm", "strings" ], "Title": "Number of words in a string" }
30547
<p>I have around 150 lines of code that I managed to optimize.</p> <p>But, because my two methods and the six if-statements almost are identical, could there be room for improvement? Maybe it could be done with only one button and one listbox? </p> <p>As I'm out of ideas and could learn more myself, I'd like to know...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T11:09:06.483", "Id": "48618", "Score": "1", "body": "Please, don't call your controls like `button7`, change that to descriptive names." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T12:00:37.950", ...
[ { "body": "<p>Yeah, you can simplify your code. To have a single method for both of them, you would need to specify whether the check was negated and what action to perform (that could be done using a delegate).</p>\n\n<p>To simplify it even more, use a loop over the three boxes (possibly using a <code>Dictiona...
{ "AcceptedAnswerId": "30558", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T08:54:30.787", "Id": "30553", "Score": "4", "Tags": [ "c#", "generics" ], "Title": "Refactoring my windowsFormApp code" }
30553
<p>I am an average coder trying to improve my Python by doing solved problems in it.</p> <p>One of the problem I did is <a href="http://codeforces.com/contest/340/problem/B" rel="nofollow">this</a>, here is the code I tried which I have based on the <a href="http://codeforces.com/contest/340/submission/4383413" rel="n...
[]
[ { "body": "<p>Firstly you need to put all the global statements into a function because of <a href=\"https://stackoverflow.com/questions/11241523/why-does-python-code-run-faster-in-a-function\">Python code runs faster in a function compared to global scope</a>.</p>\n\n<p>You don't need the <code>arr</code> vari...
{ "AcceptedAnswerId": "30574", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T11:20:36.880", "Id": "30557", "Score": "0", "Tags": [ "python", "optimization" ], "Title": "Is any further optimization possible? (Codeforces)" }
30557
<p>Consider this code where I read an input file with 6 columns (0-5):</p> <ol> <li>Initialize a variable <code>history_ends</code> to 5000.</li> <li>When the <code>column0</code> value (i.e. job[0] &lt; 5000) I add 5000 lines of the input file in a list (<code>historyjobs</code>) else the rest of the lines until the ...
[]
[ { "body": "<p>Comments about coding style:</p>\n\n<ul>\n<li>inconsistent indentation makes the code harder to read</li>\n<li>preferred indentation width in python is 4 spaces</li>\n</ul>\n\n<p>Why is the question tagged python3 ? This is python2 code.</p>\n\n<hr>\n\n<pre><code>history_begins = 1; history_ends =...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T14:43:14.687", "Id": "30565", "Score": "4", "Tags": [ "python" ], "Title": "Reading an input file with 6 columns" }
30565
<p>Artificial Intelligence is a branch of computer science which aims to replicate or simulate human-style intelligence (or significant aspects of it). The term was coined by <a href="https://en.wikipedia.org/wiki/John_McCarthy_(computer_scientist)" rel="nofollow noreferrer">John McCarthy</a>, who invented the <a href...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T16:42:20.587", "Id": "30568", "Score": "0", "Tags": null, "Title": null }
30568
Artificial intelligence (AI) is the branch of computer science and technology that studies the development of machines able to simulate aspects of human intelligence.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T16:42:20.587", "Id": "30569", "Score": "0", "Tags": null, "Title": null }
30569
<p>I'm trying to get my head around asyncronous programming in node.js. My example is reading all the files from a directory.</p> <p>I know I can avoid asyncronous programming by using the syncronous methods:</p> <pre><code>var fs = require('fs'); names = fs.readdirSync("."); for(i in names) { fileinfo = fs.statSy...
[]
[ { "body": "<p>If you want to expose directory contents with stats as a Bacon EventStream or a Property, you can use the combine-family of functions to combine the filename and stats without monkey-patching:</p>\n\n<pre><code>var fs = require(\"fs\")\nvar Bacon = require(\"../dist/Bacon.js\")\n\n// statsForFile ...
{ "AcceptedAnswerId": "30678", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T17:05:49.033", "Id": "30571", "Score": "2", "Tags": [ "javascript", "node.js", "bacon.js" ], "Title": "How do I handle the file system?" }
30571
<p>An atomic operation is one which can be considered, from the perspective of the larger computing context in which it occurs, to be executed in a single step. During its execution, no other process can read or alter its state. Atomic operations should either succeed or fail; if the operation can halt in some other, ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T17:19:21.947", "Id": "30575", "Score": "0", "Tags": null, "Title": null }
30575
An atomic operation is one which can be considered, from the perspective of the computing context in which it occurs, to be executed in a single step. Atomic operations either succeed entirely or fail, with no intermediate states.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T17:19:21.947", "Id": "30576", "Score": "0", "Tags": null, "Title": null }
30576
<p>I am using this as a learning exercise primarily and want to ensure my code is optimal. The main thing is that it is reliable and I am made aware of any flaws.</p> <p>Could it be made more efficient or more readable? How about style?</p> <p>I thought about returning a <code>char*</code>, but then the caller woul...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T18:03:34.590", "Id": "48646", "Score": "0", "body": "I'd change the name `invokeid` to something more clear and relevant to its role in the function. I'll write an actual answer in a few minutes." } ]
[ { "body": "<ul>\n<li><a href=\"https://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc\">Don't typecast return of malloc in C</a>. Same thing goes for <code>calloc</code></li>\n<li><code>invokeid</code> seems to me two words so why no underscore? Be consistent even if it seems obvious.</li>\n<...
{ "AcceptedAnswerId": "30604", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T17:34:21.473", "Id": "30579", "Score": "4", "Tags": [ "c", "formatting", "integer" ], "Title": "Integer-to-hex string generator" }
30579
<p>I have been doing some JS lately and I would like to get some constructive criticism.</p> <p><a href="https://github.com/Nikamura/YoutubeToSpotify-JavaScript/" rel="nofollow">The project I am working on</a></p> <pre><code>var SpotifiedList = [], youtubeSongs, spotifySongs = 0, spotifiedSongs = 0, playNext; $(docu...
[]
[ { "body": "<h2>General</h2>\n\n<p>I could work with this code, I only have a few remarks.</p>\n\n<p><strong>Globals</strong></p>\n\n<p>You should consider as a minimum to have your 4 globals in an object.</p>\n\n<pre><code>var player = \n{\n spotifiedList : [],\n youtubeSongs : 0,\n spotifySongs : 0,\n spot...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T17:48:56.220", "Id": "30580", "Score": "5", "Tags": [ "javascript", "css", "converting" ], "Title": "YouTube-to-Spotify converter" }
30580
<p>I have a very simple code that allows me to keep track of what the user inserts in a <code>raw_input</code>.</p> <p>The kind of controls I check are <code>if the user inserts "f" the program is finished</code> or <code>if the user inserts nothing, the program keeps on running remembering all the inputs the user has...
[]
[ { "body": "<p>Here is what I came up with:</p>\n\n<pre><code>#!/usr/bin python\nfrom os import system as sys\n\ndef GetReceipt():\n prompt = \"Insert receipt number (if you finished insert 'f'): \"\n inserted_text = ''\n while True:\n sys('clear')\n inserted_text = raw_input(prompt).upper...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T17:54:38.510", "Id": "30581", "Score": "1", "Tags": [ "python", "beginner" ], "Title": "Python raw_input and conditions" }
30581
<p>This program prints out a 10x10 square and uses only bit operations. It works well, but I don't like that global array. </p> <p>Can you tell me if the code is proper or not?</p> <pre><code>#include &lt;iostream&gt; const std::size_t HEIGHT = 10; const std::size_t WIDTH = 10; char graphics[WIDTH/8][HEIGHT]; inli...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T19:14:50.177", "Id": "48659", "Score": "1", "body": "Why not pass the array as an argument and then make it local to `main`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T19:19:23.963", "Id": "4...
[ { "body": "<p>That global array is indeed not good. You'll need to pass around an array, but you shouldn't do it with a C-style array. Doing that will cause it to <em>decay to a pointer</em>, which you should avoid in C++. If you have C++11, you could use <a href=\"http://en.cppreference.com/w/cpp/container/...
{ "AcceptedAnswerId": "42263", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T19:10:16.350", "Id": "30584", "Score": "11", "Tags": [ "c++", "matrix", "bitwise" ], "Title": "10x10 bitmapped square with bits" }
30584
<p>A function (often anonymous) bound to the referencing environment in its original lexical scope in such a way that it will still have access to that environment (its variables and other references) if executed outside that scope.</p> <p>It is the binding between the function and its original scope which distinguish...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T20:05:24.533", "Id": "30586", "Score": "0", "Tags": null, "Title": null }
30586
A function (often anonymous) bound to the referencing environment in its original lexical scope in such a way that it will still have access to that environment (its variables and other references) if executed outside that scope.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T20:05:24.533", "Id": "30587", "Score": "0", "Tags": null, "Title": null }
30587
<p>I've got information that is imported from a CSV file that my site grabs every day with PHP. I'm just learning RegEx so I'm able to do what I need to do but am looking to get more efficient with my coding.</p> <p>Some of example of the kinds of strings that would come in would be:</p> <pre><code>15 SE NORFOLK 5 NN...
[]
[ { "body": "<p>Leave out the square brackets:</p>\n\n<pre><code>^\\d+\\s+[A-Z]+\\s+\n</code></pre>\n\n<p>Square brackets are used for \"character classes\", like</p>\n\n<pre><code>[A-Z]\n</code></pre>\n\n<p>which matches exactly one letter out of the range A to Z.</p>\n\n<p><code>\\d</code> already is a class: a...
{ "AcceptedAnswerId": "30591", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T20:43:03.373", "Id": "30590", "Score": "1", "Tags": [ "php", "regex", "csv" ], "Title": "Grabbing city names and numbers from a CSV file" }
30590
<pre><code> public static Integer[] eliminateDuplicate(int[] a) { if (a == null) { throw new NullPointerException(); } List&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;(); for (int i = 0; i &lt; a.length; i++) { // include last element by default, if not t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T21:15:00.920", "Id": "48669", "Score": "1", "body": "It would help if you added some comments about your intent and any problems you encountered or things you are unsure of. Code is not, in itself, documentation." }, { "Con...
[ { "body": "<p>Minor point - don't use an old c-style for loop to iterate through an array unless you absolutely have to (and you don't have to here). Please, this is 2013 not 2003 - generics have been here for a decade. You can use foreach:</p>\n\n<pre><code>if a.length &gt; 0 {\n int lastValue = a[0];\n li...
{ "AcceptedAnswerId": "30596", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T20:54:03.020", "Id": "30592", "Score": "-2", "Tags": [ "java", "array" ], "Title": "Eliminating duplicates in an array of ints" }
30592
<p>It's an exercise from a book. There is a given long integer that I should convert into 8 4-bit values. The exercise is not very clear for me, but I think I understood the task correctly. </p> <p>I googled how to return with an array in a function. In the splitter function I add the last 4 bits into the values arra...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T21:57:25.210", "Id": "48674", "Score": "0", "body": "I'm assuming a vector is out of the question?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T22:13:30.500", "Id": "48675", "Score": "0", ...
[ { "body": "<p>This is how I would've implemented it with extensive use of the STL and C++11. It is a bit shorter than yours, but also more idiomatic. I've added comments throughout to help explain what each part does.</p>\n\n<p>The main thing to note here is that you should return a <em>container object</em> ...
{ "AcceptedAnswerId": "30605", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T21:25:44.023", "Id": "30593", "Score": "5", "Tags": [ "c++", "bitwise", "integer" ], "Title": "Split a long integer into eight 4-bit values" }
30593
<p>I am trying to parse this XML file. I have the extension and I need to get the description, icon, and class from the XML. My code works(ish) (I know how to continue from where I am), but it doesn't seem very elegant. Is there a better way of doing this?</p> <p>Here is the PHP code:</p> <pre><code>&lt;?php if($xml ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T21:01:33.123", "Id": "48670", "Score": "0", "body": "You could put the attribute checks into the XPath query. Have a look at this XPath tutorial: http://schlitt.info/opensource/blog/0704_xpath.html" } ]
[ { "body": "<p>I'd make heavier use of <code>xpath</code>:</p>\n\n<pre><code>$xml = simplexml_load_string($x); // assume XML in $x\n$class = $xml-&gt;xpath(\"//type[@extension = 'doc']/../../@class\")[0];\n$icon = $xml-&gt;xpath(\"//type[@extension = 'doc']/../@icon\")[0];\n$description = $xml-&gt;xpath(\"//type...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T20:58:05.567", "Id": "30594", "Score": "0", "Tags": [ "php", "xml" ], "Title": "Better SimpleXML parsing method" }
30594
<p>I have recently started code kata and learning for myself, as I would like to learn test-first development. I have started doing a shopping cart as my code kata. I have included a test as well. I would like to know what are the ways I could improve my below code. I know I need to use dependency injection next ste...
[]
[ { "body": "<ol>\n<li><code>public double Price { get; set; }</code> clearly should be of type <code>Decimal</code>. That is what <code>Decimal</code> for.</li>\n<li><code>private static List&lt;CartItem&gt; CartItems = null;</code> can be safely refactored to <code>Dictionary&lt;int, CartItem&gt;</code> with <c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-31T23:31:36.900", "Id": "30600", "Score": "4", "Tags": [ "c#", "e-commerce" ], "Title": "Shopping cart code kata" }
30600
<p>I'm working my way through <em>The Java Programming Language, 4th edition</em>. This is exercise 2.2:</p> <blockquote> <p>Write a LinkedList class that has a field of type Object and a reference to the next LinkedList element in the list.</p> </blockquote> <p>Is this an adequate solution? Is there a more effici...
[]
[ { "body": "<p>I would say it is an adequate solution. The product may not feel very useful yet, but it's probably not supposed to be. In some sense, the exercise is formulated ambiguously. Your <code>Node</code> class can be used to construct linked lists and as such is a building block of instantiated linked l...
{ "AcceptedAnswerId": "30612", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T00:31:05.517", "Id": "30602", "Score": "2", "Tags": [ "java", "linked-list" ], "Title": "Critique of LinkedList class" }
30602
<p>I am coding a Hanning filter which is a recursive relation: </p> <pre><code>y[i] = 0.25*(x[i] + 2*x[i-1] + x[i-2]) </code></pre> <p>And here is my code were I attempt to unroll 3 times:</p> <pre><code>public void HanningFilter(float[] array) { int len = array.length; int i; for (i = 2; i...
[]
[ { "body": "<p>The standard advice is, premature optimization is evil. Write the code cleanly and let the compiler and JIT do their job. If, after profiling the code for your entire program, this particular function is found to be a hot spot, then try it with loop unrolling and see if it makes a difference. B...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T01:09:57.220", "Id": "30603", "Score": "4", "Tags": [ "java", "optimization" ], "Title": "Does this loop unrolling make sense?" }
30603
<p>Nearly time to hand this project in, and I want it to be as close to perfect as possible. So, any issue (no matter how small) - let me know. If you have any ideas that would improve the efficiency or readability of my code (e.g. delegates), let me know.</p> <p>I am already aware that I should use camelCase for vari...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T05:33:19.853", "Id": "48700", "Score": "0", "body": "1. Split that giant method into smaller methods 2. Don't use `List`, use the correct data structure for the [open list](https://bitbucket.org/BlueRaja/high-speed-priority-queue-fo...
[ { "body": "<ul>\n<li><p>It is better to declare by interface instead of implementation.</p>\n\n<pre><code>List&lt;Node&gt; OpenList = new List&lt;Node&gt;();\nHashSet&lt;Node&gt; ClosedList = new HashSet&lt;Node&gt;();\n</code></pre>\n\n<p>Can become:</p>\n\n<pre><code>IList&lt;Node&gt; OpenList = new List&lt;N...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T05:05:17.243", "Id": "30606", "Score": "7", "Tags": [ "c#", "performance", "pathfinding" ], "Title": "Path finding - again" }
30606
<p>I want to make a graph from input from a text file in the format:</p> <pre><code>vertex1 vertex2 cost time </code></pre> <p>where vertex1 and vertex2 are strings that form an edge and cost and time are the properties of that edge. This information will be used to construct the Graph based on cost. I want to plan ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-29T04:22:16.150", "Id": "97468", "Score": "0", "body": "In `main()`, where are `v1` and `v2` declared?" } ]
[ { "body": "<p><strong>Overall</strong></p>\n\n<p>Resolve all standard library entities with <code>std::</code>. <em>Never</em> put <code>using namespace</code> declarations in a header file, where most of his belongs.</p>\n\n<p><strong>Class Edge</strong></p>\n\n<p>You use initializer lists in some places (<cod...
{ "AcceptedAnswerId": "30610", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T09:05:06.693", "Id": "30609", "Score": "4", "Tags": [ "c++", "graph" ], "Title": "Do I need to delete a vector?" }
30609
<p>I am reading the book <em>Clean Code</em> by Rob Martin and am trying to write the cleanest possible code. </p> <p>I wrote this script as part of my project. Could you please criticise it and let me know how it could be improved?</p> <pre><code>/** * File Downloading, Unzipping and extracting Content - PHP * ...
[]
[ { "body": "<p>I haven't read the book you mention, although it looks good so I might buy it and have a read.</p>\n\n<p>A few things for me</p>\n\n<p>There are echo statements in the code, I am assuming that is for debugging and you are going to remove them.</p>\n\n<p>In a couple of places you use die(), and th...
{ "AcceptedAnswerId": "30652", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T11:55:49.703", "Id": "30611", "Score": "1", "Tags": [ "php", "object-oriented", "classes" ], "Title": "File-downloading, unzipping and extracting content with a PHP script and ...
30611
<pre><code> class PropFinal(CrawlSpider): name = "propfinal" allowed_domains = [over 200 allowed domains here] start_urls = ["http://www.putnam-fl.com/coc/index.php?option=com_content&amp;view=article&amp;id=385&amp;Itemid=114" ] def __init__(self, *args, **kwargs): ##Is there a bette...
[]
[ { "body": "<p>For your requests list, I suggest defining a dictionary like that:</p>\n\n<pre><code>requests_dict = {\n 'putnam': 'http://www.putnam-fl.com/clerks_web_apps/foreclosure_trans/get_cases.php',\n 'palmbeach': 'https://mypalmbeachclerk.clerkauction.com/',\n ...\n}\n</code></pre>\n\n<p>and the...
{ "AcceptedAnswerId": "30621", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T14:03:23.963", "Id": "30615", "Score": "2", "Tags": [ "python", "object-oriented", "scrapy" ], "Title": "Scrapy -- Very Procedural -- Better Alternatives?" }
30615
<p>This is my first attempt at Quick Sort and am looking for some helpful criticisms on how I can make my code better. Thank you</p> <pre><code>def manSort(self, unSorted): if len(unSorted) &lt;= 1: return unSorted else: greater = [] less = [] pivots = unSorted[len(unSorted)/2] ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T08:06:53.703", "Id": "64520", "Score": "0", "body": "What about the function that has 2 nested `for` loops that iterate over each element and swaps the lowest, returns the same list but sorted?\nIt's not what the task requires but, ...
[ { "body": "<p>There is an unnecessary complication: you put <code>pivots</code> in <code>pivotPlace</code> before the loop, and then do extra work to skip it in the loop.</p>\n\n<p>You could also loop over <code>unSorted</code> directly instead of looping with an index.</p>\n\n<pre><code>pivotPlace = []\nfor it...
{ "AcceptedAnswerId": "30693", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T18:30:25.270", "Id": "30624", "Score": "1", "Tags": [ "python", "algorithm", "quick-sort" ], "Title": "QuickSort critique" }
30624
<p>I'd like to extract HTML content of websites and save it into a file. To achieve this, I have the following (working) code:</p> <pre><code>output = codecs.open("test.html", "a", "utf-8") def first(): for i in range(1, 10): root = lxml.html.parse('http://test'+str(i)+'.xyz'+'?action=source').getroot() ...
[]
[ { "body": "<p>Try something like this, you can definitely clean up the two list comprehensions you have, but for now this should suffice. </p>\n\n<pre><code>def first():\n with codecs.open(\"test.html\", \"a\", \"utf-8\") as output:\n for i in range(1, 10):\n txt = []\n root = lx...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T19:21:07.903", "Id": "30627", "Score": "3", "Tags": [ "python", "html" ], "Title": "Simplification of Python code (HTML extraction)" }
30627
A command-line interface (CLI) is a means of interacting with a computer program where the user (or client) issues commands to the program in the form of successive lines of text (command lines).
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T19:46:43.823", "Id": "30629", "Score": "0", "Tags": null, "Title": null }
30629
Gradle is a project automation tool that builds upon the concepts of Apache Ant and Apache Maven and introduces a Groovy-based DSL instead of the more traditional XML form of declaring the project configuration.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T19:48:39.270", "Id": "30631", "Score": "0", "Tags": null, "Title": null }
30631
<p>Elm is a functional language that compiles to JavaScript. It competes with projects like React as a tool for creating websites and web apps. Elm has a very strong emphasis on simplicity, ease-of-use, and quality tooling.</p> <p>References: </p> <ul> <li><p><a href="http://guide.elm-lang.org/" rel="nofollow">An Int...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T19:51:35.657", "Id": "30632", "Score": "0", "Tags": null, "Title": null }
30632
Elm is a functional programming language for declaratively creating web browser based graphical user interfaces.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T19:51:35.657", "Id": "30633", "Score": "0", "Tags": null, "Title": null }
30633
<p><strong><a href="https://eclipse.org/" rel="nofollow noreferrer">Eclipse IDE</a></strong> is an open-source IDE platform written mostly in Java and primarily used for Java development through the use of the <a href="https://www.eclipse.org/jdt/" rel="nofollow noreferrer">Java Development Tools</a> (JDT) plug-ins. It...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-09-01T19:52:40.363", "Id": "30634", "Score": "0", "Tags": null, "Title": null }
30634
In computer programming, Eclipse is a multi-language integrated development environment (IDE) comprising a base workspace and an extensible plug-in system for customizing the environment. THIS TAG SHOULD ONLY BE USED FOR CODE INVOLVING THE IDE ITSELF, NOT FOR CODE SIMPLY WRITTEN WITH IT.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T19:52:40.363", "Id": "30635", "Score": "0", "Tags": null, "Title": null }
30635
In computer science, a pointer is a programming language data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T19:54:57.653", "Id": "30637", "Score": "0", "Tags": null, "Title": null }
30637
Wikipedia is a collaboratively edited, multilingual, free Internet encyclopedia supported by the non-profit Wikimedia Foundation.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T19:57:13.243", "Id": "30639", "Score": "0", "Tags": null, "Title": null }
30639
An assembly language is a low-level programming language for a computer, or other programmable device, in which there is a very strong (generally one-to-one) correspondence between the language and the architecture's machine code instructions.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T20:08:00.757", "Id": "30641", "Score": "0", "Tags": null, "Title": null }
30641
Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. One starts at the root (selecting some node as the root in the graph case) and explores as far as possible along each branch before backtracking.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T20:10:45.347", "Id": "30643", "Score": "0", "Tags": null, "Title": null }
30643
<p>Since the mid-1970's versions of BASIC was the most popular or in many cases, the only programming language available on microcomputers. Like today when you buy a computer, the OS is slightly different, or an OEM version.</p> <p>BASIC was developed at Dartmouth College in 1964, and it is said to be based on or infl...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-09-01T20:12:22.523", "Id": "30644", "Score": "0", "Tags": null, "Title": null }
30644
BASIC (an acronym for Beginner's All-purpose Symbolic Instruction Code) is a family of general-purpose, high-level programming languages whose design philosophy emphasizes ease of use.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T20:12:22.523", "Id": "30645", "Score": "0", "Tags": null, "Title": null }
30645
<p><a href="http://blog.codinghorror.com/why-cant-programmers-program/" rel="nofollow">Link - The original blog post by Jeff Atwood</a></p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T20:20:28.543", "Id": "30646", "Score": "0", "Tags": null, "Title": null }
30646
A programming challenge, popularized by Jeff Atwood, that prints the numbers from 1 to 100, where multiples of three print "Fizz," multiples of five print "Buzz," and multiples of both three and five print "FizzBuzz."
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T20:20:28.543", "Id": "30647", "Score": "0", "Tags": null, "Title": null }
30647
In computer science, garbage collection (GC) is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T20:22:24.693", "Id": "30649", "Score": "0", "Tags": null, "Title": null }
30649
In computer science, a literal is a notation for representing a fixed value in source code.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T20:23:53.043", "Id": "30651", "Score": "0", "Tags": null, "Title": null }
30651
In computer science, polymorphism is a programming language feature that allows values of different data types to be handled using a uniform interface.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T20:26:55.257", "Id": "30654", "Score": "0", "Tags": null, "Title": null }
30654
RSS Rich Site Summary (originally RDF Site Summary, often dubbed Really Simple Syndication) is a family of web feed formats used to publish frequently updated works—such as blog entries, news headlines, audio, and video—in a standardized format.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T20:28:17.217", "Id": "30656", "Score": "0", "Tags": null, "Title": null }
30656
In computer programming, the scope of an identifier is the part of a computer program where the identifier, a name that refers to some entity in the program, can be used to find the referred entity.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T20:28:57.813", "Id": "30658", "Score": "0", "Tags": null, "Title": null }
30658
<p>In computer science, a tree is a <a href="/questions/tagged/graph" class="post-tag" title="show questions tagged &#39;graph&#39;" rel="tag">graph</a> in which there is exactly one path between any two nodes. Often, the nodes are treated as a hierarchical data structure, such that there is a root node, and each child...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T20:31:19.183", "Id": "30659", "Score": "0", "Tags": null, "Title": null }
30659
A tree is a graph in which there is exactly one path between any two nodes. It is often used as a hierarchical data structure.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T20:31:19.183", "Id": "30660", "Score": "0", "Tags": null, "Title": null }
30660
Twitter is an online social networking service and microblogging service that enables its users to send and read text-based messages of up to 140 characters, known as "tweets". Use this tag for questions which may arise when developing FOR Twitter. This tag is NOT for support questions about using the Twitter website o...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T20:31:54.967", "Id": "30662", "Score": "0", "Tags": null, "Title": null }
30662
<p>Please review my code to help improve its quality.</p> <pre><code>public void printHeadOfNonIntersectingLinkedList(List&lt;Standalone&gt; listStandalones) { final Map&lt;Node, Node&gt; tailHeads = new HashMap&lt;Node, Node&gt;(); for (Standalone ll : listStandalones) { Node temp = ll.first; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-02T14:35:51.107", "Id": "48781", "Score": "1", "body": "It needs some comments to tell people what the hell it's supposed to do ...." } ]
[ { "body": "<p>First of all, you have provided very little context for your code. Therefore, my criticism may not be valid in the context of your full program.</p>\n\n<p>Second, you have not a <em>single</em> comment in your code. One can argue that code does not need comments once it is self-documenting. But yo...
{ "AcceptedAnswerId": "30704", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-02T00:30:27.957", "Id": "30666", "Score": "2", "Tags": [ "java", "linked-list" ], "Title": "Printing heads of stand-alone lists" }
30666
<p>I am a newbie to C. I've just wrote a linked list program, compiled it, and received a segmentation error. I have no clue where it went wrong. Can somebody help me?</p> <pre><code># include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; struct snode{ struct snode *next; int val; }; struct slist{ struct snode *...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-02T05:44:19.973", "Id": "48752", "Score": "1", "body": "There's at least an argument that this belongs on Stack Overflow since you aren't asking for a review of working code but are asking for help with resolving a bug." } ]
[ { "body": "<p>One key problem is:</p>\n\n<pre><code> if(mylist-&gt;head = NULL){\n</code></pre>\n\n<p>First, you've not checked whether <code>mylist</code> itself is NULL, and on the first call to <code>slist_insert()</code>, it is NULL. That alone leads to trouble.</p>\n\n<p>Second, you've got an assignment ...
{ "AcceptedAnswerId": "30672", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-02T01:23:17.983", "Id": "30667", "Score": "-2", "Tags": [ "c", "linked-list" ], "Title": "Linked list in C" }
30667
The brainfuck programming language is an esoteric programming language noted for its extreme minimalism. It is a Turing tarpit, designed to challenge and amuse programmers, and was not made to be suitable for practical use.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-02T07:24:58.380", "Id": "30677", "Score": "0", "Tags": null, "Title": null }
30677
<p>I have been looking around for a good place to get my code reviewed for some time. I just stumbled on this site and I was hoping some people could tell me if I'm progressing in the right direction. This is a snippet from a sudoku game I'm making. The full source code can be viewed at <a href="http://www.lesshardt...
[]
[ { "body": "<p>I don't seem to see the need for the methods to be declared <em>inside</em> the constructor. You aren't making any property <em>\"private\"</em>. Also, declaring methods this way makes copies of the methods for each instance.</p>\n\n<p>I suggest you move them out to the prototype instead. That way...
{ "AcceptedAnswerId": "30692", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-02T08:18:12.543", "Id": "30680", "Score": "1", "Tags": [ "javascript", "sudoku", "canvas" ], "Title": "Drawing a sudoku board to a canvas" }
30680
<p>I'm currently learning programming for the first time and I've created the following implementation of quick sort in C#. I basically read a very basic overview of how quick sort works recursively and implemented it without looking at any concrete examples of its implementation so that I could learn the most from it....
[]
[ { "body": "<pre><code>new List&lt;int&gt;(input).ForEach(x =&gt; Console.Write(x + \",\"));\n</code></pre>\n\n<p>I see absolutely no reason to do this. In general, <code>List.ForEach()</code> is <a href=\"https://stackoverflow.com/a/226299/41071\">considered bad form by some and you should use normal <code>fore...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-02T08:47:09.583", "Id": "30681", "Score": "4", "Tags": [ "c#", "beginner", "sorting", "quick-sort" ], "Title": "Implementation of quick sort in C#" }
30681
<p>I have a <code>VenuesController</code> and an <code>EventsController</code>. My venues controller has an <code>admin_add</code> method that, well, allows an administrator to add a venue to the database. It looks like this:</p> <pre><code>public function admin_add() { if ($this-&gt;request-&gt;is('post')) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-12T03:18:19.513", "Id": "87049", "Score": "0", "body": "Sometimes you can't avoid having lots of `if` statements in your code. In your case the only thing I notice that I personally don't like is that you have sections of code inside `...
[ { "body": "<p>Why do you have the following lines repeating:</p>\n\n<pre><code> if ($this-&gt;Venue-&gt;save($this-&gt;request-&gt;data)) {\n if ($this-&gt;Venue-&gt;save($this-&gt;request-&gt;data)) {\n</code></pre>\n\n<p>I think you may try to merge them to one and the associated logic too.</p>\n", ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-02T09:31:36.940", "Id": "30682", "Score": "3", "Tags": [ "php", "controller", "cakephp" ], "Title": "Admin method in CakePHP to add a venue to the database" }
30682
<p>I am making a GWT application and have to prevent client code from using null values in collections. I found <a href="https://stackoverflow.com/a/6997191">an answer</a> but GWT doesn't support <code>Queue</code> and its implementations as <a href="http://www.gwtproject.org/doc/latest/RefJreEmulation.html#Package_jav...
[]
[ { "body": "<ul>\n<li><p>Throwing <code>NullPointerException</code> from methods like <code>add</code>, <code>set</code> are OK, cause the element to be added can't be <code>null</code>. But throwing NPE from <code>addAll</code> method is not cool. From <a href=\"http://docs.oracle.com/javase/7/docs/api/java/uti...
{ "AcceptedAnswerId": "30691", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-02T11:59:52.737", "Id": "30688", "Score": "1", "Tags": [ "java", "array", "collections", "null" ], "Title": "A custom Java collection which doesn't support nulls" }
30688
<p>I have a PDO class below:</p> <pre><code>class DB { private $dbh; private $stmt; static $db_type; static $connections; public function __construct($db, $id="") { switch($db) { case "db1": try{ $...
[]
[ { "body": "<p>A <a href=\"https://stackoverflow.com/questions/18572590/pdo-connection-to-multiple-databases/18572640#18572640\">quick recap from SO</a></p>\n\n<ol>\n<li><p>If you want to implement the Singleton pattern (first read about SOLID, though, and pay special attention to injection), make the constructo...
{ "AcceptedAnswerId": "30690", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-02T12:05:10.763", "Id": "30689", "Score": "1", "Tags": [ "php", "mysql", "singleton" ], "Title": "PDO class for multiple databases" }
30689
<p>I use a worker thread for some data processing in my MFC project. In the thread-controlling function, it needs to use some parameters (declared as member variables) to the data-processing. I use a sub-dialog (which is triggered by a menu item and contains a few edit controls) to change the values of the parameters, ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-02T14:34:19.260", "Id": "30694", "Score": "3", "Tags": [ "c++", "multithreading", "synchronization" ], "Title": "Simple multithreading and synchronization problems in MFC" }
30694
<p>I am trying to display the leave history of a particular employee. But, when I choose a particular month (for example, I choose to display January instead of displaying the history of January), it displays all the history from this year. Is there anything wrong with my code?</p> <pre><code>&lt;?php echo 'View the...
[]
[ { "body": "<p>To answer your question: everything</p>\n\n<p>Now you may ask, why?</p>\n\n<ul>\n<li>Very bad variable naming style</li>\n<li>unreadable code (so manh if-else if -else</li>\n<li>You Repeat yourself all over the code</li>\n<li>No seperation of concern (business logic and presentation is tightly cou...
{ "AcceptedAnswerId": "30698", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-02T15:17:23.380", "Id": "30696", "Score": "-1", "Tags": [ "php" ], "Title": "Is there anything wrong with my code?" }
30696
<p>Recently, I've noticed that my code looks so ugly because there were a bunch of functions and global variables. So, I started reading a little bit about design patterns. Now I come with something that's working for me, but I am not sure if it's good practice.</p> <p>Anyway, I would like you to take a look at the c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T15:31:44.580", "Id": "48835", "Score": "6", "body": "Contrary to some of the answers below, note that a lot of people define prototypes as a *form of OOP* http://stackoverflow.com/questions/186244/what-does-it-mean-that-javascript-i...
[ { "body": "<p>The best pattern to start \"OOP\" in JavaScript is the Revealing Pattern:</p>\n\n<pre><code>var revealed = function(){\n var a = [1,2,3];\n var abc = function(){\n return (a[0]*a[1])+a[2];\n }\n\n return {\n name: 'revealed',\n abcfn: abc\n }\n}();\n</code></pre>\n\n<p>From...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-02T20:35:35.820", "Id": "30701", "Score": "7", "Tags": [ "javascript", "jquery", "object-oriented" ], "Title": "Responsive module and tooltip module" }
30701
<p>I'm fairly new at JavaScript, and I'm finding that JS is a language with what seems like an unusually high number of gotchas for the inexperienced, so some criticisms of this code would be particularly appreciated.</p> <p>The function <code>getProperties</code> below is a relatively simple function that returns an ...
[]
[ { "body": "<p>As you said, I have a little issue with the use of a try/catch statement. I tried to write it again using, imo, neater constructs:</p>\n\n<pre><code>function getProperties(o) {\n var results = []; \n function properties(obj) {\n var props, i;\n if (obj == null) {\n r...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-02T21:36:33.710", "Id": "30702", "Score": "1", "Tags": [ "javascript" ], "Title": "Function to get all properties of an object" }
30702
<p>The following is a code to detect a loop in a linked list. This question is prepared strictly for interview purposes. This code has been modeled as per Linkedlist.java</p> <ol> <li><p>How should I decide if a function like <code>hasLoop()</code> should be included as an instance method or should be a static method ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T18:57:46.923", "Id": "48863", "Score": "1", "body": "I know this is for an interview, but if I were hiring, I would want you to tell me that you would design the linked list api such that you would never end up with a loop." }, ...
[ { "body": "<p>To answer your first question, I would create the method as a static method, because similar to sorting, detecting loops is basic functionality, that is applicable to <code>List</code>s in general, not only a specific <code>List</code> object.</p>\n\n<p>I would not recommend inheriting from the or...
{ "AcceptedAnswerId": "30723", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-02T23:07:47.187", "Id": "30707", "Score": "0", "Tags": [ "java", "linked-list", "interview-questions" ], "Title": "Detect if linked list contains a loop" }
30707
<p><a href="https://stackoverflow.com/questions/18564239/c-sharp-implementing-ilistt-ilist-inotifycollectionchanged">I posted this question over at Stackoverflow, which was off-topic</a>.</p> <p>I was using <code>ObservableCollection</code> in a number of places in my WPF application for very large arrays. This caused...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T02:50:21.610", "Id": "48810", "Score": "2", "body": "Can you compare the two pieces of code. Perhaps it's just a red herring the increase in processing occurring around the same time as your code change?" }, { "ContentLicen...
[ { "body": "<ol>\n<li>The implementation of <code>IList</code> is inconsistent: You have implemented <code>IsFixedSize</code> explicitly while <code>IsSynchronized</code> and <code>SyncRoot</code> are not, yet they are all three part of the <code>IList</code> interface. You should probably implement <code>IList<...
{ "AcceptedAnswerId": "32787", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T00:19:36.680", "Id": "30708", "Score": "9", "Tags": [ "c#", ".net" ], "Title": "Implementing IList<T>, IList & INotifyCollectionChanged" }
30708