body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>Is there any way to improve this code? It looks a bit ugly for me.</p> <pre><code>if($url_chunks_num == 1) { $this-&gt;controller = $this-&gt;pageData[0]; } elseif($url_chunks_num == 2) { $this-&gt;controller = $this-&gt;pageData[0]; $this-&gt;action = $this-&gt;pageData[1]; } elseif($url_chunks_num &gt...
[]
[ { "body": "<p>There seems to be some code repetition. Perhaps this could be improved like this:</p>\n\n<pre><code>if ($url_chunks_num &gt;= 1)\n $this-&gt;controller = $this-&gt;pageData[0];\nif ($url_chunks_num &gt;= 2)\n $this-&gt;action = $this-&gt;pageData[1];\nif ($url_chunks_num &gt; 2)\n $this-&gt;...
{ "AcceptedAnswerId": "12915", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-21T22:57:24.697", "Id": "12912", "Score": "3", "Tags": [ "php", "url-routing" ], "Title": "Setting controller, action, and values based on the number of URL chunks" }
12912
<pre><code>count = 0 def merge_sort(li): if len(li) &lt; 2: return li m = len(li) / 2 return merge(merge_sort(li[:m]), merge_sort(li[m:])) def merge(l, r): global count result = [] i = j = 0 while i &lt; len(l) and j &lt; len(r): if l[i] &lt; r[j]: result.append...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-22T07:12:44.690", "Id": "20833", "Score": "0", "body": "Do you mean it to be a simple code review? Or is there any specific aspect of the code that you would like reviewed?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationD...
[ { "body": "<p>Rather than a global count, I would suggest using either a parameter, or to return a tuple that keeps the count during each recursive call. This would also assure you thread safety.</p>\n\n<pre><code>def merge_sort(li, c):\n if len(li) &lt; 2: return li \n m = len(li) / 2 \n return merge...
{ "AcceptedAnswerId": "12956", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-22T06:29:05.900", "Id": "12922", "Score": "9", "Tags": [ "python", "homework", "mergesort" ], "Title": "Inversion count using merge sort" }
12922
<p>I'm building an option panel for a Wordpress theme. I'm just learning PHP and I wonder if there is any better (shorter) way to generate the social media links. Here's what I came up with and even tho it works, I think there are cleaner way to write it</p> <pre><code>&lt;ul&gt; &lt;?php if ( of_get_option('mm_sm_vim...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-22T08:05:30.447", "Id": "20845", "Score": "0", "body": "Your code is scrambled, plesse edit it." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-22T08:09:04.827", "Id": "20846", "Score": "0", "bo...
[ { "body": "<p>You could take the common bits out into a function:</p>\n\n<pre><code>&lt;?php\nfunction my_thing($name, $title) {\n if ( of_get_option(\"mm_sm_$name\") ) {\n ?&gt;\n &lt;li&gt;\n &lt;a href=\"&lt;?php echo of_get_option(\"mm_sm_$name\"); ?&gt;\"&gt;&lt;img src=\"&lt;?php echo ge...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-22T08:04:42.537", "Id": "12927", "Score": "1", "Tags": [ "php" ], "Title": "Generating social media links" }
12927
<p>I am running a Markov Chain Monte Carlo algorithm for updating a density distribution. There is a specific section of my code which tries to fill a very large matrix <code>thetha.mh</code> (of dimension 5000x2x60). the following code snippet is trying to fill the first dimension of my matrix, but the specific operat...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-22T00:13:17.830", "Id": "20858", "Score": "0", "body": "What do you mean by \"too much time\"?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-22T00:35:27.347", "Id": "20859", "Score": "0", "bod...
[ { "body": "<p>The functions you use (kde, dkde, hpi, ...) do not seem to be standard R functions and you are not very explicit on your exact data structur, so it's hard to help. Could you provide more info on that (packages used, ...)?</p>\n\n<p>What I think to realize though - but correct me if I'm wrong - is ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-21T23:53:50.260", "Id": "12935", "Score": "3", "Tags": [ "matrix", "r" ], "Title": "Updating a density distribution" }
12935
<p>I have the following dataset</p> <pre><code>kkk&lt;-data.frame(days=1:100,positive=rbinom(100,1,0.05)) </code></pre> <p>Over the monitoring period of 100 days, if an event occurs then for that day <code>kkk$positive==1</code> else <code>kkk$positive==0</code></p> <p>The following function, samples <code>k=s.freq...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-21T17:24:44.933", "Id": "20862", "Score": "2", "body": "You can, for one, replace that entire allocation of `monitor.ss` where you are \"building sample space\" with this single line: \n\n `monitor.ss <- embed(1:dim(ddd)[1], j)[ , ...
[ { "body": "<p>This question is probably not appropriate for stackoverflow, since it requires mainly code review.</p>\n\n<p>First of all, there is a logics problem with your while loop. Changing <code>|</code> to <code>&amp;</code> reduces the number of loops considerably.</p>\n\n<p>Furthermore you should not us...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-21T17:05:00.247", "Id": "12937", "Score": "2", "Tags": [ "performance", "r" ], "Title": "Speed up a sampling function" }
12937
<p>I have a question about lock upgrading.Specifically what bothers me is between readlock.unlock() and following writelock.lock()... I am providing a nearly complete implementation for a sample cache.I just omitted actual loading of cached data from database. </p> <p>I appreciate if you can review the code and share...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-20T16:34:51.413", "Id": "20867", "Score": "0", "body": "From the javadoc: \"Reentrancy also allows downgrading from the write lock to a read lock, by acquiring the write lock, then the read lock and then releasing the write lock. Howev...
[ { "body": "<p>Your fears are valid. Once you let go of the lock, all bets are off. When you get the write lock, you <em>will</em> need to check if another thread has mutated the cache. Don't think of it as \"ugly\"; think of it as \"correct\". Continue to use comments to explain what you're doing and why you're...
{ "AcceptedAnswerId": "12940", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-20T16:31:54.357", "Id": "12939", "Score": "2", "Tags": [ "java", "locking", "concurrency" ], "Title": "ReentrantReadWriteLock lock upgrade method" }
12939
<p>I'm working on my way to write most efficient, reusable and robust code, and this is why I'd like to receive some support. I've written a datetimepicker script that allows datetime chosing, and a shortcut button that will subtract from higher date (the right input) a variable number of minutes:</p> <p>Is there a wa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-21T07:31:08.047", "Id": "20883", "Score": "0", "body": "Are you having a problem with your code?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-21T07:31:24.933", "Id": "20884", "Score": "0", "b...
[ { "body": "<p>A quick review:</p>\n\n<p><strong>High Level Overview</strong></p>\n\n<p>This code is okay except for 2 major items: you are not declaring your variables, making them escape all scope. And you use non-English variable names and function names, not every developer speaks Polish, though we should al...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-21T07:27:31.803", "Id": "12951", "Score": "1", "Tags": [ "javascript", "jquery", "datetime" ], "Title": "Datetimepicker script" }
12951
<p>I am trying to compose an illustrative example which shows how to implement move semantics on an object that will be stored in a <code>vector</code>.</p> <p>Please consider the following code, which is my illustrative example so far. It is designed to be a canonical, pedantically correct implementation of an object...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-22T17:18:48.853", "Id": "20896", "Score": "0", "body": "I had posted another question very similar to this, but deleted it and replaced it with this one. The other question had used `unique_ptr` which ultimately was orthogonal to what...
[ { "body": "<ul>\n<li><p>One small error: Mark the move constructor as <code>noexcept</code>, otherwise <a href=\"https://stackoverflow.com/q/10127603/1968\">there are situations where it won’t be used</a>. The linked case is different since the class has a copy-constructor, yet I can imagine that there are stil...
{ "AcceptedAnswerId": "12972", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-22T17:17:48.227", "Id": "12954", "Score": "7", "Tags": [ "c++", "c++11" ], "Title": "Canonical Implementation of Move Semantics" }
12954
<p>I took a base from <a href="http://www.webdeveloper.com/forum/showthread.php?t=161951" rel="nofollow">here</a> and built on it. You call the function with <code>onkeypress</code> (hence live changing).</p> <p>The function gives output like this for domestic numbers:</p> <blockquote> <p>(123) 456–7890</p> </block...
[]
[ { "body": "<p><a href=\"http://www.regular-expressions.info/\" rel=\"nofollow\">Regular expressions</a> are a quicker way to get it done. Here's a naïve implementation that's (I believe) functionally equivalent to yours:</p>\n\n<pre><code>var mask = function (content) {\n var val = content.value.replace(/[^\\d...
{ "AcceptedAnswerId": "12963", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-22T21:12:17.760", "Id": "12958", "Score": "4", "Tags": [ "javascript", "formatting" ], "Title": "Liveupdate phone number forms and test for international numbers" }
12958
<p>Recently me and colleague had a discussion about the following piece of code (simple bool function that checks if string is a number, <code>+1000</code> not allowed, <code>-1000</code>, <code>1234</code> ... allowed). </p> <p>He felt that it was hackish, while I thought it was nice, clean and elegant (since it use...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-22T21:40:54.917", "Id": "20909", "Score": "0", "body": "[Don't cross post](http://stackoverflow.com/questions/11163638/is-this-code-elegant-or-hack#comment14643018_11163638)." }, { "ContentLicense": "CC BY-SA 3.0", "Creatio...
[ { "body": "<p>I had to really look at your code and think about what it was doing before I figured it out. That tells me that this code is not elegant by my definition of \"elegant\". My definition of elegant is something like,</p>\n\n<blockquote>\n <p>Easy to understand, easy to maintain, efficient in execu...
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-22T21:31:50.903", "Id": "12959", "Score": "4", "Tags": [ "c++", "stl" ], "Title": "Checking if a string is a number with STL" }
12959
<p>I am new to MVC and Zend, so I have little idea what I am doing at the moment, but here is my question.</p> <p>The following code is my get method for an API I am attempting to build in order to learn both. It works as is, but given the sparsity of code I have seen in example methods, and the fact that Zend seems t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-23T08:15:26.973", "Id": "20933", "Score": "0", "body": "Can't comment on the Zend stuff since I don't quite understand what's going on here, but the first thing that jumps out at me is that it's possible for your encode call to act on ...
[ { "body": "<p>By using Zend_Rest_Route you are on a good way. I wouldn't recommend making it the default route though, as I had trouble when using MVC-stuff which required additional params not specified in the route, e.g. for a paginator. You could also <a href=\"http://framework.zend.com/manual/1.11/en/zend.c...
{ "AcceptedAnswerId": "12988", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-23T04:47:09.727", "Id": "12964", "Score": "3", "Tags": [ "php", "api", "url-routing", "zend-framework" ], "Title": "Zend Framework getAction method" }
12964
<p>I have a working script that I wrote in Python which for e-mail messages that consist only of a plain text part + an HTML part, discards the HTML and keeps only the plain text part.</p> <p>The script is not exactly elegant and, as can be seen from the code, it smells like it is C (in particular, I simulate the use ...
[]
[ { "body": "<p>I think the code is quite fine as it is. Some small notes:</p>\n\n<pre><code>if composition == (TEXTPLAIN + TEXTHTML) or composition == TEXTPLAIN:\n</code></pre>\n\n<p>Just to make sure: this code tests that <code>TEXTPLAIN</code> is set and that <code>MISCPARTS</code> is <em>not</em> set. I would...
{ "AcceptedAnswerId": "12970", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-23T09:04:48.460", "Id": "12967", "Score": "4", "Tags": [ "python", "email" ], "Title": "Script to drop HTML part of multipart/mixed e-mails" }
12967
<p>For reasons unknown I've recently taken up generating word squares, or more accurately <a href="http://en.wikipedia.org/wiki/Word_square#Double_word_squares" rel="nofollow">double word squares</a>. Below you can see my implementation in Python, in about 40 lines. The code uses this <a href="http://github.com/causes/...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T14:36:13.857", "Id": "21148", "Score": "0", "body": "Would you like to find all word squares or just the first one?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T08:04:05.923", "Id": "21199", ...
[ { "body": "<p>Am working on a few minor improvements, but I think the major saving to be had is in removing the line </p>\n\n<pre><code>square2, isquare2 = square[:], isquare[:]\n</code></pre>\n\n<p>Instead, do</p>\n\n<pre><code>sofar = square[x], isquare[y]\nfor o in options[sofar]:\n square[x], isquare[y] ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-23T13:25:58.417", "Id": "12974", "Score": "3", "Tags": [ "python" ], "Title": "Word Square generation in Python" }
12974
<p>After becoming interested in various bits of functional programming provided by non-functional languages, I've recently decided to start learning Haskell. As I'm fairly experienced with conventional imperative programming languages, I decided to make my "hello world" something a little more complex - an implementa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-07T23:27:13.293", "Id": "21696", "Score": "0", "body": "would you please consider accepting my answer - or do you still have questions" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-11T10:43:31.690", "...
[ { "body": "<p>one obvious change would be to add type signatures,\ni additionally introduced some type synonyms to distinguish between all those <code>Doubles</code>. A bit explanation could be done towards the algorithm - I don't know what it actually want to achieve. I am no programmer so the non understandin...
{ "AcceptedAnswerId": "12998", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-23T13:27:49.533", "Id": "12975", "Score": "4", "Tags": [ "haskell" ], "Title": "Simple Gradient Descent Algorithm In Haskell" }
12975
<p>I think I have correctly implemented <a href="http://en.wikipedia.org/wiki/Powerset" rel="nofollow">Powerset</a> in Clojure.</p> <pre><code>(use '(clojure set)) (defn powerset [input result] (if (nil? (first input)) (concat result #{}) (set (reduce concat (for [x input] (let [set-...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-24T03:36:55.847", "Id": "21010", "Score": "0", "body": "Feedback from @stevelknievel on twitter: use if-let" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-24T07:45:24.890", "Id": "21013", "Score": ...
[ { "body": "<p>A couple of random comments on your code:</p>\n\n<ul>\n<li><p>it doesn't parse correctly, I guess the closed paren right after <code>loop</code> bindings is misplaced. I couldn't run it even after fixing that.</p></li>\n<li><p>why do you need a second input parameter? I would expect the signature ...
{ "AcceptedAnswerId": "13002", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-23T15:33:46.237", "Id": "12979", "Score": "8", "Tags": [ "clojure" ], "Title": "Powerset in Clojure" }
12979
<p>I'm training a bit with C, and I'm trying to build a bit array. I would like to have some comments about my code, because I'm not sure that it's the best way to do it.</p> <pre><code>// BAL.c #include &lt;assert.h&gt; #include &lt;limits.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include "BAL.h" #...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-23T20:54:37.660", "Id": "20971", "Score": "2", "body": "Sorry, I don't have the time to write a full review but I have one thing to say. Assertions are not a replacement for error checking. As these functions are being exported, you sh...
[ { "body": "<p>Quite clean implementation, but some remarks:</p>\n\n<ol>\n<li><p>The header shouldn't compile. It references <code>size_t</code>, but doesn't include stdlib.h.</p></li>\n<li><p>BAL_Any can be faster if you just compare the characters in the pBits array to zero, you don't need to check each indivi...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-23T17:07:10.217", "Id": "12981", "Score": "6", "Tags": [ "c", "bitwise" ], "Title": "Managing a bit array" }
12981
<p>How can I improve my remove function? Could someone also give me a solid explanation of the <code>free()</code> function?</p> <p>Here is my remove function:</p> <pre><code>void removeData(void *data, struct accList *theList) { if(theList-&gt;head == NULL) //nothing can be deleted return; ...
[]
[ { "body": "<p>First, about <code>free()</code>. If you need memory, you call <code>malloc()</code> and it will give you a pointer that points to a block of memory that is yours now. The OS will (hopefully) take care that no one else will use this memory. But, as with all resources, be it sockets, open files or ...
{ "AcceptedAnswerId": "12992", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-23T21:24:21.063", "Id": "12990", "Score": "2", "Tags": [ "c", "linked-list" ], "Title": "Linked list remove() and free()" }
12990
<p>I've seen plenty of examples and questions on how to do this, but the issue is that they all rely on a massive database on the server-side. I figured I could try to move that to the client-side. Here's what I have:</p> <pre><code>(function() { var data, pos, read, write, fcnt, tcnt, i, forums, threads, l, fid, id, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-23T22:11:23.330", "Id": "20979", "Score": "0", "body": "Please explain what you're code is doing before posting it. The title alone is not necessarily sufficient information for any random person on this site to know what you're attemp...
[ { "body": "<p>No big issues that I can see, but here are a few tips.</p>\n\n<hr>\n\n<p>When using for-in loops, add a <code>hasOwnProperty</code> check, like this:</p>\n\n<pre><code>for (var i in obj) {\n if (obj.hasOwnProperty(i) {\n // do stuff\n }\n }\n</code></pre>\n\n<p>Otherwise the loop will...
{ "AcceptedAnswerId": null, "CommentCount": "11", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-23T21:27:11.633", "Id": "12991", "Score": "1", "Tags": [ "javascript" ], "Title": "Forum \"read/unread\" in JavaScript" }
12991
<p>I wanted a timer, rather like the Visual Basic object, and I wanted it with no cumulative error. And I wanted it flexible, so I wouldn't have to write another one. I'm very lazy BTW, so lazy that I will go to great lengths to avoid having to write something a second time. Actually, this fits quite well with the "wri...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-24T12:21:43.117", "Id": "21025", "Score": "0", "body": "Add docstrings!" } ]
[ { "body": "<p>My first impression is that it's overengineered by Python standards. (Or maybe just by my standards, which are a little on the cowboy side.)</p>\n\n<p>Some specific crits:</p>\n\n<ul>\n<li>Don't use prints for error cases in the config; raise exceptions instead. For\ndiagnostics that aren't necess...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-24T00:02:29.667", "Id": "12995", "Score": "4", "Tags": [ "python", "object-oriented", "timer" ], "Title": "Timer class, to be taken as a model for other classes" }
12995
<p>I am very new to Java and programming theory and am desperately trying to improve my knowledge. This is the first program I've made without help and really would appreciate some feedback. I know there must be 1,000,000 better ways to do what I did.</p> <p>Notes:</p> <ul> <li>I want to move away from <code>main()</...
[]
[ { "body": "<p>You seem to be repeating sections like this.</p>\n\n<pre><code>for (int i = 0; i &lt;= 0; i++) {\n int randomGenNumber = (int) (Math.random()*13);\n\n dealersCards.add(card[randomGenNumber]);\n}\n</code></pre>\n\n<p>First, it does not make sense to use a <code>for</code> loop if the number o...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-24T12:24:37.307", "Id": "13004", "Score": "5", "Tags": [ "java", "object-oriented", "beginner", "game", "playing-cards" ], "Title": "Using multiple methods with Blackjack" }
13004
<p>So this is my code and I would like to add subtraction, multiplication and division. If you have any suggestions on algorithms to use I would be very happy to see it. I do not wish to copy the code, I just want an outline of how to simply, and efficiently create a calculator. I want to make a calculator for KIDS wit...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-24T14:53:58.410", "Id": "21030", "Score": "2", "body": "Your creating an app for kids so young they are still learning to count and you think it's appropriate to put ads in?" }, { "ContentLicense": "CC BY-SA 3.0", "Creation...
[ { "body": "<p>Not very familiar with Android development, so some of this may be totally off the rails.</p>\n\n<p>Depending on how educational you want this to be, you could visually demonstrate simple algorithms to teach how various operations work (e.g. animations). Also, since you're targeting little kids, I...
{ "AcceptedAnswerId": "13307", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-24T12:34:31.107", "Id": "13005", "Score": "3", "Tags": [ "java", "android", "calculator" ], "Title": "Basic android calculator" }
13005
<p>I've created a simple Javascript library to be able to create "classes" and extend them defining instance and static methods and variables.</p> <p>It consists in a simple function Class with two methods: create and extend.</p> <pre><code>var Class = function(){}; Class.extend = function(obj){ var Extended = ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-24T14:12:18.997", "Id": "21029", "Score": "0", "body": "[Fixed your code](http://jsfiddle.net/R6jGe/3/)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-25T20:41:30.007", "Id": "21101", "Score": "0",...
[ { "body": "<p>I read your code several times, and I could only find few observations:</p>\n\n<ul>\n<li>jQuery has <code>extend</code> as well, the idea of it is sound, you could consider working with <code>arguments</code> and allow for n objects like jQuery does</li>\n<li>I am not sure that always overriding t...
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-24T13:17:56.037", "Id": "13006", "Score": "3", "Tags": [ "javascript", "object-oriented", "classes", "prototypal-class-design" ], "Title": "Implementation of Javascript Classes a...
13006
<p>For the following C linked list implementation, please give me some suggestions for improved efficiency, style and design. This implementation is not 100% complete, please give some suggestions for additional features. Notice the data type for the list is void*, I want it to be as generic as possible.</p> <p>accLis...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-22T01:15:49.680", "Id": "45330", "Score": "0", "body": "What happens to the size variable of the accList ? Should be updated whenever you add a new node in the list right ?" } ]
[ { "body": "<p>I see two issues with the removeData function. The first is in the \"single item list\" section:</p>\n\n<pre><code>else if(theList-&gt;head == theList-&gt;tail) //there is one element in the list\n{\n free(theList-&gt;head);\n theList-&gt;head = NULL;\n}\n</code></pre>\n\n<p>W...
{ "AcceptedAnswerId": "13011", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-24T14:13:41.143", "Id": "13007", "Score": "8", "Tags": [ "c", "linked-list" ], "Title": "C linked list implementation" }
13007
<p>Everything in this code is completely working, but I still feel that this code needs to be refactored. any suggestions? </p> <pre><code>&lt;?php class Db_CheckUsername{ protected $_conn; protected $_username; protected $_minimumChars = 8; protected $_errors = array(); pu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-24T20:01:38.687", "Id": "21040", "Score": "0", "body": "consider writing ORM model" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-24T20:08:03.060", "Id": "21041", "Score": "0", "body": "one fun...
[ { "body": "<p>I meant to write one or two brief points when I started writing this, but erm, ended up a bit more :). Anyway, some of the stuff is quite briefly explained, so if anything needs more elaboration/defense, let me know and I'll edit in more information.</p>\n\n<p><strong>SQL Injection</strong></p>\n...
{ "AcceptedAnswerId": "13021", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-24T14:35:46.477", "Id": "13008", "Score": "2", "Tags": [ "php", "mysqli" ], "Title": "Username verification class" }
13008
<p>My code here is completely working, but I feel like I destroyed or didn't follow the DRY rule, what suggestions can you give to me for this code??</p> <pre><code>&lt;?php require_once("./includes/Utilities.php") ;?&gt; &lt;?php require_once("./includes/Db_Resources/db_connection.php");?&gt; &lt;?php require_once("....
[]
[ { "body": "<p>Here are some things that I would recommend:</p>\n\n<ul>\n<li><strong>PHP tags</strong>. There's no point in closing and reopening PHP tags if there is no non-PHP code in between. For this file, a single opening PHP tag is all you need for the entire thing. Closing PHP tags (anywhere in the file) ...
{ "AcceptedAnswerId": "13022", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-24T14:43:26.220", "Id": "13010", "Score": "2", "Tags": [ "php", "form", "mysqli" ], "Title": "Inserting data in the database through POST" }
13010
<p>I created an XML wrapper to easily access XML data. Please tell me what do you think about it.</p> <ul> <li>Performance</li> <li>Scalability </li> <li>Anything else...</li> </ul> <p>This is how you use it:</p> <pre><code>var xml = new Xml(dataString); xml.load("UserEmail"); alert(xml.length + ", " + xml.getValueA...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-23T12:59:06.310", "Id": "21034", "Score": "0", "body": "It can usefully handle very simple XMLs. It doesn't retrieve the value of attributes. It gives worthless values for element nodes. It doesn't support a decent selector engine. If ...
[ { "body": "<p>From a quick read : </p>\n\n<ul>\n<li><p><code>Xml</code> seems like a bad name for your wrapper, you should consider something like <code>xmlParser</code> ?</p></li>\n<li><p>I would allow access to <code>data</code> and <code>elements</code> by using <code>this</code> instead of <code>var</code> ...
{ "AcceptedAnswerId": "39174", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-23T12:48:47.103", "Id": "13014", "Score": "3", "Tags": [ "javascript", "xml", "parsing" ], "Title": "Javascript XML Parser wrapper" }
13014
<h2>Further Information</h2> <ul> <li>See <a href="http://en.wikipedia.org/wiki/Blackjack" rel="nofollow" title="Wikipedia Blackjack">Blackjack on Wikipedia</a></li> </ul>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-24T18:38:14.857", "Id": "13016", "Score": "0", "Tags": null, "Title": null }
13016
Card Game – Where the aim is to get your cards as closer to 21 then the dealer, while not going over. J, Q, K are worth 10. A are either 11 or 1.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-24T18:38:14.857", "Id": "13017", "Score": "0", "Tags": null, "Title": null }
13017
<p>I wanted to learn how to work with file I/O properly and found an assignment in my college papers and decided to write it:</p> <pre><code>//Write a C program which reads data about books and inputs them into a file named books.txt, like this: // //book_name#author_name#page_num#code#is_lent# // //book_name is an ar...
[]
[ { "body": "<p>I'm not a C guru, so just two small notes:</p>\n\n<ol>\n<li><p>It does something strange (seems an endless loop) for the following input:</p>\n\n<pre><code>Book title: a\nName of the author: a\nNumber of pages: a\n</code></pre></li>\n<li><p>The <code>50</code> magic number should be a named consta...
{ "AcceptedAnswerId": "13033", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-24T19:43:52.113", "Id": "13018", "Score": "4", "Tags": [ "c", "strings", "io" ], "Title": "Simple text file I/O for book data" }
13018
<p>I'm a little frustrated with the state of url parsing in python, although I sympathize with the challenges. Today I just needed a tool to join path parts and normalize slashes without accidentally losing other parts of the URL, so I wrote this:</p> <pre><code>from urlparse import urlsplit, urlunsplit def url_path_...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-25T05:43:32.700", "Id": "21054", "Score": "1", "body": "Why can't you just use `os.path.join` for taking care of the joining and such?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-25T11:31:36.060", "...
[ { "body": "<p>I fully agree with Blender. Just use the os.path module. It provides a method to join paths and it also has methods to normalize pathnames (eg. os.path.normpath(pathname)) to use it on every OS with different separators.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", ...
{ "AcceptedAnswerId": "24416", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-24T22:34:16.367", "Id": "13027", "Score": "15", "Tags": [ "python", "parsing", "url" ], "Title": "Joining url path components intelligently" }
13027
<p>In the world of casinos, there are different types of games and jackpots. In this example, there are normal jackpots, multi-casino jackpots. I have a separate model for each of these. I need to display these in-line with each other. For instance, I'm grabbing the top 10 Caribbean Stud jackpots (Model: Jackpot), then...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-01-30T22:54:04.663", "Id": "143334", "Score": "0", "body": "Which version of Rails are you using?" } ]
[ { "body": "<p>First of all, the fact that you are mixing the use of <code>Jackpot</code> and <code>MultiJackpot</code> in this way suggests that they are really 2 different instances of a common, underlying concept. That calls into question whether they really need to be implemented as two different models. But...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-24T20:37:48.260", "Id": "13030", "Score": "2", "Tags": [ "ruby-on-rails", "ruby" ], "Title": "Casino jackpot models" }
13030
<p>Here's something I tried putting together as I'm learning. Critiques on anything are welcome. There's also a logic bug in the Plane module I can't identify.</p> <p>The long and the short are that it takes the URI "some float/some float/some float/some float", and makes the first 2 (x,y) coord where something is, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-25T04:45:37.343", "Id": "21052", "Score": "0", "body": "On a side note, this is on github https://github.com/JimmyHoffa/HaskJunk" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-25T19:10:54.857", "Id": "...
[ { "body": "<p>Here are some suggestions. Get rid of data types that do not carry their weight. For example, Shape should really be one of the constructors.</p>\n\n<p>plane.hs</p>\n\n<pre><code>module Plane where\n\ntype X = Float\ntype Y = Float\ntype Location = (X, Y)\ntype Size = (Float, Float)\n\ndata Artifa...
{ "AcceptedAnswerId": "13129", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-25T04:40:44.590", "Id": "13035", "Score": "10", "Tags": [ "beginner", "haskell", "computational-geometry", "collision" ], "Title": "Artifact collision in plane module" }
13035
<p>My CSS feels dirty and I have no idea how to improve it. </p> <p>Suggestions are greatly appreciated!</p> <pre><code>html, body { border:0; margin:0; padding:0; } body { font: normal 12px helvetica,sans-serif; } .header { background-color:#242424; height:40px; } .header h1, h2 { text-transform:uppercase; ...
[]
[ { "body": "<p>You can try tools like <a href=\"http://csstidy.sourceforge.net/\" rel=\"nofollow\">CSSTidy</a> to clean your CSS. Here is an online tool who use CSSTidy with the result of the cleaning with default setup: <a href=\"http://www.cleancss.com/\" rel=\"nofollow\">http://www.cleancss.com/</a></p>\n\n<p...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-25T06:12:04.007", "Id": "13036", "Score": "7", "Tags": [ "optimization", "css" ], "Title": "CSS Optimization? How can I clean my code" }
13036
<p>The code works, but I guess it could be much better.</p> <pre><code>/* DESCRIPTION The strncpy() function is similar, except that at most n bytes of src are copied. Warning: If there is no null byte among the first n bytes of src, the string placed in dest will not be null-terminated. NOTE If the length of src is l...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-25T13:08:25.973", "Id": "21063", "Score": "1", "body": "Why are you writing C-like code when working with C++? What functionality do you want to achieve what you wouldn't get from using `std::string` and it's functionalities?" }, {...
[ { "body": "<p>This would be my solution:</p>\n\n<pre><code>#include &lt;string&gt;\n#include &lt;iostream&gt;\n\nint main() {\n // C++, so use what it provides you. A relatively flexible string library.\n std::string a = \"Hello \";\n std::string b = \"World!\";\n std::string c;\n\n // easy, simp...
{ "AcceptedAnswerId": "13126", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-25T11:39:55.107", "Id": "13040", "Score": "2", "Tags": [ "c++", "c" ], "Title": "C like Cpp code to do strncpy and copy a string to a buffer which is not long enough" }
13040
<p>I've been given the following PHP code:</p> <pre><code>if(empty($search)){ $_SESSION['keyword_exists'] = "no"; }else{ if(isset($_SESSION['old_keyword']) &amp;&amp; $_SESSION['old_keyword'] != $search){ $_SESSION['keyword_exists'] = "no"; } } if(isset($_REQUEST['limits...
[]
[ { "body": "<p>Let's start with the basics:</p>\n\n<ul>\n<li>$_SESSION: This is a global array that holds all your <a href=\"http://php.net/manual/en/features.sessions.php\" rel=\"nofollow\">session information</a>.</li>\n<li>$_REQUEST: This is a global array that contains the contents of $_GET, $_POST and $_COO...
{ "AcceptedAnswerId": "13115", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-25T13:17:26.120", "Id": "13044", "Score": "4", "Tags": [ "php", "search" ], "Title": "Improve search keyword" }
13044
<p>I've written a general purpose repeat function which allows you to repeat a callback function X times separated by I intervals with the option to start immediately or after the interval. It can also default to just looping infinitely, which is what <code>setInterval</code> does. Is there a better approach, or any im...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-04-08T22:46:37.460", "Id": "155591", "Score": "0", "body": "Also good to note the difference in setTimeout and setInterval - http://stackoverflow.com/questions/729921/settimeout-or-setinterval" } ]
[ { "body": "<p>It's pretty much commented in the code. The usage is still the same as the one you used. <a href=\"http://jsfiddle.net/J8Umt/\" rel=\"nofollow\">Here's a demo</a>.</p>\n\n<pre><code>function repeatXI(callback, interval, repetitions, immediate) {\n\n //general purpose repeater function\n func...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-25T14:45:00.833", "Id": "13046", "Score": "3", "Tags": [ "javascript" ], "Title": "JavaScript: Repeat a function X times at I intervals" }
13046
<p>If you look at the condition of <code>If calculated Then</code> in the code below, this is what slowing down the code. While the code provided seem fast with <code>Const initBit = 4</code> try it with something over 12. I want to be able to use this code (with calculated param as <code>true</code>) with <code>initBi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-25T17:38:13.800", "Id": "21083", "Score": "3", "body": "I think the relevant code here is only a few lines. But because of all the WriteLining I'm not sure." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-2...
[ { "body": "<p>I found the perfect way! It was right in front of me; I just had to look at the data itself.</p>\n\n<pre><code>Private Sub initBits(ByVal maxBit As Integer)\n\n maxBits = ((1 &lt;&lt; maxBit)) - 1\n ReDim CountBit(maxBits)\n ReDim MapBit(maxBits)\n\n For i = 1 To maxBits\n Count...
{ "AcceptedAnswerId": null, "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-25T17:29:23.900", "Id": "13048", "Score": "3", "Tags": [ "c#", ".net", "vb.net", "bitwise" ], "Title": "Finding patterns in a growing collection" }
13048
<p>I thought to spent my free time by solving a puzzle: <a href="http://www.spotify.com/int/jobs/tech/best-before/" rel="nofollow">Best Before Spotify Puzzle</a>.</p> <p>I coded in Java, and yeah I did not clean up my code (just a rough work) and I have yet to optimize... so I did check for possible test cases (includ...
[]
[ { "body": "<p>Oh dear, your code looks horrible. Note, that there are not so many people willing to review such a code. It is a must to follow the <a href=\"http://www.oracle.com/technetwork/java/codeconv-138413.html\">code conventions</a> and format your code correctly. The latter can easily be done with an ID...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-25T18:46:22.263", "Id": "13049", "Score": "2", "Tags": [ "java", "unit-testing", "contest-problem" ], "Title": "Spotify Best Before puzzle" }
13049
<p>This works, but nvl AND case seem redundant. Basically, if null then 'N' else 'Y.</p> <p>CHICKEN_HATCH_DATE is a DATE data type.</p> <pre><code> select stricken_chicken_id, case nvl(to_char(chicken_hatch_date),'N') when 'N' then 'N' else 'Y' end chicken_hatch_date ...
[]
[ { "body": "<p>I'm not sure what's wrong with your code, but if you don't like all of those <code>'N'</code>'s would </p>\n\n<pre><code> select stricken_chicken_id,\n case when to_char(chicken_hatch_date) is null then\n 'N'\n else\n 'Y'\n end chicken_hatch_dat...
{ "AcceptedAnswerId": "13054", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-25T19:15:46.223", "Id": "13052", "Score": "4", "Tags": [ "sql", "oracle", "null" ], "Title": "Simplify Oracle SQL: Treat null date as 'N' and non-null date as 'Y'" }
13052
<p>I am creating a database class in PHP but I feel that there's something wrong with my code. Is there any suggestion to refactor this? I feel like there's something wrong and missing in this code.</p> <pre><code>&lt;?php require_once("db_constants.inc.php"); Class MySqli_Database { public $db; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T09:30:20.203", "Id": "21123", "Score": "2", "body": "What does this class offer that wasn’t available before? At the moment, nothing." } ]
[ { "body": "<p><strong>What is the purpose of this class?</strong></p>\n\n<blockquote>\n <p>Creating a database class in PHP with mySQLI</p>\n</blockquote>\n\n<p>MySQLi is a \"database class.\" (Whatever meaning of \"database class\" you choose)</p>\n\n<ul>\n<li>Are you trying to make a class that adds on to M...
{ "AcceptedAnswerId": "13066", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T01:32:19.283", "Id": "13056", "Score": "3", "Tags": [ "php", "mysqli" ], "Title": "Creating a database class in PHP with MySQLi" }
13056
<p>I'm looking to see if my current evolution of ETL logic is getting in the ball park of "how it's done in the real world". </p> <ol> <li>Specifically, do I use the metaphors correctly (<code>Extract</code>, <code>Transform</code>, <code>Load</code>)?</li> <li>Is this code reasonably clear for another developer's co...
[]
[ { "body": "<p>A few things that caught my eye:</p>\n<h3>Naming</h3>\n<pre><code>public Date FromDate {[...]}\npublic Date ToDate {[...]}\n</code></pre>\n<p>if that weren't readonly Properties, i'd assume they are conversion methods. Try to find a better name like: <code>StartDate</code> / <code>EndDate</code>.<...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T02:32:21.523", "Id": "13057", "Score": "3", "Tags": [ "c#", "etl" ], "Title": "ETL code to synchronize external system to internal database" }
13057
<p>What I am trying to accomplish is to create an efficient thread-safe singleton base class (as stated in the title).</p> <p>So this is my singleton class, which is used via inheritance (see below).</p> <pre><code>#pragma once #ifndef SINGLETON_HEADER_INCLUDED #define SINGLETON_HEADER_INCLUDED #include &lt;memory&gt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T12:47:54.027", "Id": "21131", "Score": "1", "body": "By the way, this is a prime example of [cargo cult programming](http://en.wikipedia.org/wiki/Cargo_cult_programming). The code merely has the *semblance* of actual, meaningful cod...
[ { "body": "<p>Your code doesn’t compile, and if it would compile, it would crash.</p>\n\n<p>You are trying to assign a <code>shared_ptr</code> to a raw pointer. You are also trying to <code>delete</code> a <code>shared_ptr</code> and this leads me to believe that you don’t understand <a href=\"http://en.wikiped...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T05:19:45.447", "Id": "13059", "Score": "1", "Tags": [ "c++", "c++11", "singleton" ], "Title": "Thread-safe singleton class using std::shared_ptr in C++(11)" }
13059
<p>Could someone review my linked list code? Specificially, is the design to separate <code>Node</code> and actions to create linked list appropriate?</p> <pre><code>template &lt;typename T&gt; class Node { public: Node() : next(0) { } Node(T value) : val(value), next(0) { } T val; Node* next; pr...
[]
[ { "body": "<p>The overall structure looks ok, but two things:</p>\n\n<ol>\n<li><p>If T is int and you repeatedly call <code>addVal(0)</code>, the list stays unchanged. Consider just setting <code>begin</code> to NULL, it's a more reliable way to tell if the list is empty.</p></li>\n<li><p><code>isPresentN</code...
{ "AcceptedAnswerId": "13062", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T07:48:04.747", "Id": "13060", "Score": "13", "Tags": [ "c++", "linked-list" ], "Title": "Linked list in C++" }
13060
<p>A Linked List is a data structure in which the elements contain references to the next (and optionally the previous) element. Lists, where nodes have links to both the next and the previous element are usually referred to as <em>doubly-linked</em>. Another form of the Linked List is the <em>Circular Linked List</em...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T08:52:30.927", "Id": "13063", "Score": "0", "Tags": null, "Title": null }
13063
A linked list is a data structure in which the elements contain references to the next (and optionally the previous) element.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T08:52:30.927", "Id": "13064", "Score": "0", "Tags": null, "Title": null }
13064
<p>I'm not used with perl but had the need to add a couple of features, I wish I can adopt a more perl-ish coding.</p> <p>Any help is welcome.</p> <p>This is to add style classes to paragraphs if strarting with <code>!</code>, <code>?</code> and a <code>clear: both</code> with <code>%</code></p> <p>Original:</p> <...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-31T23:43:44.890", "Id": "22947", "Score": "0", "body": "If you can I would move towards using [Markdent](http://p3rl.org/Markdent), which is easier to extend." } ]
[ { "body": "<p>Note that a substitution only occurs if there is a match, and then it will return the number of substitutions it makes. This means that a <code>true</code> value is returned if a match/substitution happens.</p>\n\n<p>With that in mind, you don't need the <code>m/.../</code> in addition to the subs...
{ "AcceptedAnswerId": "13085", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T12:09:22.333", "Id": "13071", "Score": "2", "Tags": [ "perl" ], "Title": "Markdown.pl extending" }
13071
<p>I'm trying to develop a base for a blog using some of the new tags introduced in HTML5 and I want to not only make sure I'm using them correctly, but my code is also semantic. </p> <p>Here is just the <em>'sample'</em> document.</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T17:12:57.133", "Id": "21164", "Score": "2", "body": "Also, `<meta charset=\"utf-8\">`. It's probably simpler." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T17:30:13.280", "Id": "21168", "Sco...
[ { "body": "<p>In my opinion for the most part, that looks good. However, there are a few small things I would question.</p>\n\n<ul>\n<li><p>Do you really need the wrapper <code>div</code> element? I would remove it so you have the <code>header</code> as the first child of the <code>body</code>.</p></li>\n<li><p...
{ "AcceptedAnswerId": "13075", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T12:36:11.460", "Id": "13073", "Score": "14", "Tags": [ "html5" ], "Title": "Semantic HTML5 and proper use of tags" }
13073
<p>Is there a more elegant way of doing this? I really think this looks ugly.</p> <pre><code>private static string InsertMethodNameHere( bool hasCondition1, bool hasCondition, bool hasCondition3) { if (!hasCondition1 &amp;&amp; !hasCondition2 &amp;&amp; !hasCondition3) return "0...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-29T00:40:29.090", "Id": "21310", "Score": "0", "body": "Might I ask why you think it's ugly? It looks perfectly readable to me." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-07T12:37:48.230", "Id": "2...
[ { "body": "<p>How about this?</p>\n\n<pre><code>private static string InsertMethodNameHere(bool hasCondition1, bool hasCondition2, bool hasCondition3)\n{\n return ((hasCondition1 ? 1 : 0) +\n (hasCondition2 ? 2 : 0) +\n (hasCondition3 ? 4 : 0)).ToString(CultureInfo.InvariantCulture);\n}...
{ "AcceptedAnswerId": "13077", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T13:36:35.930", "Id": "13076", "Score": "20", "Tags": [ "c#" ], "Title": "Multiple if then return with conditions" }
13076
<p>I'm learning F# and have a couple of routines much of whose functionality looks common so I am looking to refactor them together.</p> <p>Here are the routines (which for the record I lifted from elsewhere:</p> <pre><code>let Prices time ID (polling:float) = let sync = System.Threading.SynchronizationContext.Cur...
[]
[ { "body": "<p>This is a bit difficult to answer, because you did not share code sample that fully type-checks (and so it is hard to make sure the answer is correct). However, I think you're very close. When refactoring two similar functions, you just need to abstract out the bits that differ.</p>\n\n<p>In your ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T05:43:32.760", "Id": "13080", "Score": "2", "Tags": [ "f#" ], "Title": "Getting prices and volume" }
13080
<p>I have a form written in the usual way. After submitting, if there are errors in the form, the form page itself is the target of the redirect, with a query string appended. The query string contains the error messages, but also the values submitted with the form. The query string and its format are provided by a 3<s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T16:11:15.283", "Id": "21154", "Score": "0", "body": "Rather than unpacking the returned form contents from your PHP validator, have you considered doing client-side form validation in JavaScript?" }, { "ContentLicense": "CC ...
[ { "body": "<p>I went ahead with the one-by-one re-populating from GET (on a timeline and all that!). The form doesn't need to be highly reusable and won't be modified very frequently after roll-out, so in this particular case, it was a matter of 'getr done' rather than 'getr done the best way'.</p>\n\n<p>For th...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T15:59:51.697", "Id": "13083", "Score": "3", "Tags": [ "php" ], "Title": "Populating form contents from GET - especially radio buttons" }
13083
<p>I just recently learned about Project Euler and have started doing the problems on there. I cleared problem 1 and 2, had no idea how to do 3 and 4, and started to do 5. I've seen the post regarding the quick mathematic solution, but I'd like to know if there are better ways to do it programmatically.</p> <p>For thos...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T16:47:53.083", "Id": "21160", "Score": "0", "body": "If your solution works, in what way do you want to make it \"better\"?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T16:52:08.260", "Id": "21...
[ { "body": "<p>Maybe you can reason as follows:</p>\n\n<p>Multiplying all the numbers together from 1->10 gives you <code>3628800</code> which is indeed divisible by the numbers 1->10, but it is not the minimum number. Ask yourself why? take the last number 10 for instance. Do we really need to multiply 10 in...
{ "AcceptedAnswerId": "13091", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T16:34:48.860", "Id": "13086", "Score": "13", "Tags": [ "java", "performance", "programming-challenge" ], "Title": "Smallest Multiple" }
13086
<p>Currently my below code takes an average 9.27300 every time I run it. This is an iOS application and I can't expect the user to sit there for roughly 10 seconds.</p> <p>This code takes an array (originalData) of <code>placeObjects</code> and calculates the distance from the selected location (CLLocation* searched)....
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-29T00:10:20.657", "Id": "104701", "Score": "1", "body": "Please do not edit new code into the question after receiving reviews." } ]
[ { "body": "<p>Your problem is with the code after the actual sort. For each item in the final array you scan over the whole original array recalculating the distance each time. That means that you'll calculate a distance some 500*500=250000 times.</p>\n\n<p>The simplest solution would be to add a <code>distance...
{ "AcceptedAnswerId": "13100", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T18:15:53.977", "Id": "13088", "Score": "4", "Tags": [ "objective-c", "ios" ], "Title": "Optimize sorting of Array according to Distance (CLLocation)" }
13088
<p>I have been reading <a href="https://stackoverflow.com/questions/254514/php-and-enums">this</a> thread on Stack Overflow about simulating enums in PHP and it seems that the most common approach is to use class constants. My problem with that is I can't use it for type hints, so I have added a static function that ch...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-02T16:25:44.590", "Id": "21417", "Score": "0", "body": "I'm not really sure I understand what you are trying to accomplish here... Maybe [this](http://us3.php.net/manual/en/function.gettype.php) will help?" }, { "ContentLicense...
[ { "body": "<p>Why not just pass the data type you are looking for as a second argument to <code>get_Type()</code> then call the <code>Defines()</code> or similar method inside to verify it is the correct type? You can even provide a default data type should you use one more frequently.</p>\n\n<pre><code>functio...
{ "AcceptedAnswerId": "13292", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T19:31:04.303", "Id": "13093", "Score": "3", "Tags": [ "php", "enum", "constants" ], "Title": "Class to simulate enums in PHP" }
13093
<p>I am looking to refactor the three lines of code in the else part of the conditional, you'll see where I have it commented.</p> <p>You'll notice a naming convention for the id's: id, id-div, as seen in the first line: club-community-service, club-community-service-id</p> <p>I want to shorten that up. I thought may...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-10-05T13:34:37.487", "Id": "195378", "Score": "1", "body": "As we all want to make our code more efficient or improve it in one way or another, try to write a title that summarizes what your code does, not what you want to get out of a re...
[ { "body": "<p>If you have control over the <code>div</code> tags and can make the html something like this:</p>\n\n<pre><code>&lt;div id='club-community-service-div' data-rel='club-community-service' class='check-toggle'&gt;\n</code></pre>\n\n<p>then you can do something like this:</p>\n\n<pre><code>$('.check-t...
{ "AcceptedAnswerId": "13112", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T20:07:15.867", "Id": "13095", "Score": "-1", "Tags": [ "javascript", "jquery" ], "Title": "refactor 3 lines of javascript to minimize code" }
13095
<p>This function combines a Twitter feed and an Instagram feed and sorts the items by date. I just want to write better, more efficient code, so any tips on how to transform this into more of a "pro" JavaScript function would be much appreciated! Would it work to combine all these functions into one namespace?</p> <p>...
[]
[ { "body": "<p><a href=\"https://codereview.stackexchange.com/questions/11233/optimizing-and-consolidating-a-big-jquery-function/11235#11235\">Starting with the steps here</a>, I am left with <a href=\"http://jsfiddle.net/Qt5Ns/\" rel=\"nofollow noreferrer\">this</a>.</p>\n\n<p>From here the first thing I notice...
{ "AcceptedAnswerId": "13103", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T20:53:07.073", "Id": "13096", "Score": "1", "Tags": [ "javascript", "jquery", "twitter", "instagram" ], "Title": "Combining Twitter and Instagram feeds" }
13096
<p>I'm quite new to JavaScript, and I'm trying to understand the idea behind inheritance in JavaScript. I've read a bit about it, and I don't want to mess with prototypes (which I don't yet fully understand) so, I wrote this code using the <a href="https://github.com/Raynos/xtend" rel="nofollow noreferrer"><code>xtend<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T13:07:38.193", "Id": "21212", "Score": "2", "body": "To learn how to create factory objects, try reading Addy Osmoni's \"JavaScript Design Patterns\"" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T13...
[ { "body": "<p>The real problem with this is that if you create a lot of objects with this, each Human has its own copies of the <code>getName()</code> and <code>getAge()</code> functions, each Boy has his own copy of the <code>playFootball()</code> function, and each Girl has her own copy of the <code>singASong...
{ "AcceptedAnswerId": "13376", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T22:09:17.773", "Id": "13098", "Score": "4", "Tags": [ "javascript", "object-oriented", "node.js" ], "Title": "JavaScript (multiple) inheritance / mixins" }
13098
<p>What are some advantages and disadvantages of providing default implementations for dependencies. I have chosen to do this because it allows the objects to be easily used in the application but also allows me to mock for unit testing.</p> <pre><code>public class RoleProvider : RoleProviderBase { private IRoleDa...
[]
[ { "body": "<p>I personally don't see any problem with this (maybe someone else might provide better insight) but in this situation I do tend to do it differently but instantiating it via constructor overloading and making the private field readonly.</p>\n\n<p>e.g. </p>\n\n<pre><code>public class RoleProvider : ...
{ "AcceptedAnswerId": "13117", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T00:03:18.920", "Id": "13099", "Score": "3", "Tags": [ "c#" ], "Title": "Defaulting dependencies" }
13099
<p>This is continuation and implementation of feedback found in this post: <a href="https://codereview.stackexchange.com/questions/12757/basic-user-registration-code-in-php">Basic user registration code</a></p> <p>I just began to use the PDO object, I'm not sure if i'm using it efficiently. Are there any security issu...
[]
[ { "body": "<p>Will edit this when I have time, but for now a few brief notes:</p>\n\n<p><strong>Assuming POST keys exist</strong></p>\n\n<p>Review the section in <a href=\"https://codereview.stackexchange.com/a/12769/7308\">my other post</a>.</p>\n\n<p><strong>Exception handling</strong></p>\n\n<p>Catching an e...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T00:17:52.287", "Id": "13102", "Score": "2", "Tags": [ "php", "mysql", "pdo" ], "Title": "Basic user registration code in PHP: Part 2" }
13102
<p>So this question is prompted by two things.</p> <ol> <li>I found some code in our source control doing this sort of things.</li> <li>These SO questions: <ul> <li><a href="https://stackoverflow.com/questions/297213/translate-an-index-into-an-excel-column-name">https://stackoverflow.com/questions/297213/translate-a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T03:20:51.100", "Id": "21189", "Score": "3", "body": "Using LINQ to perform trivial transformations repeatedly will always hurt you performance-wise. If you specifically want performance, stay away from LINQ." }, { "ContentL...
[ { "body": "<p>Calling any function in general will give you a small (miniscule) performance hit. Recursive functions (AFAIK) cannot be inlined so that can't be optimized away. LINQ revolves around calling other functions so that's the worst choice to make if you want to write good performing code. I've said ...
{ "AcceptedAnswerId": "13110", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T02:42:56.410", "Id": "13105", "Score": "33", "Tags": [ "c#", "performance", "strings", "converting" ], "Title": "Integer to Alphabet string (\"A\", \"B\", ....\"Z\", \"AA\"...
13105
<p>I wrote a script to scroll pages when menu buttons are clicked, similar effect like: <a href="http://css-tricks.com/examples/SmoothPageScroll">http://css-tricks.com/examples/SmoothPageScroll</a></p> <pre><code>var m1 = document.getElementById('m1'), m2 = document.getElementById('m2'), m3 = document.getEleme...
[]
[ { "body": "<p>There are a few things you can do differently</p>\n\n<ol>\n<li>Animations are most often accomplished by getting the difference between start and end values, and animating a factor from zero to 1. Multiply that with the difference, and you get an offset.</li>\n<li>Instead of relying on an interval...
{ "AcceptedAnswerId": "13118", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T06:18:26.423", "Id": "13111", "Score": "6", "Tags": [ "javascript" ], "Title": "Smooth page scrolling in JavaScript" }
13111
<p>I am pretty new to Rails and in fact this is the first thing I have made. This is a todo list type app. My JS and Rails is a big mess. I have just kinda hacked it up to work. Please suggest better ways to do things. Styling suggestions are welcome too.</p> <pre><code>class UsersController &lt; ApplicationController...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T12:31:58.080", "Id": "21210", "Score": "0", "body": "should i include the controller and views then ? Copying all the code doesn't seem a good idea." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-21T18:...
[ { "body": "<p>A few quick suggestions, without really looking thoroughly into the code:</p>\n\n<ul>\n<li>Saving <strong>any</strong> passwords in clear text is a Very Bad Idea™.</li>\n<li>Why are you limiting the max-length of the password?</li>\n<li>Do not set styles in JS, set classes instead and then style t...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T12:21:19.227", "Id": "13119", "Score": "1", "Tags": [ "javascript", "jquery", "ruby", "ruby-on-rails", "to-do-list" ], "Title": "To-do-list web app in Ruby on Rails and CS...
13119
<p>Here is my progress calculator class. It is used for downloads/uploads. It takes bytes in and calculates the percentage(to the nearest 5%) that should show on a progress bar. Please let me know how I could improve it. Thanks a lot!!</p> <pre><code>public class ProgressCalculator { private int totalAmount; ...
[]
[ { "body": "<p>It's really hard to tell what this class does. From what you say, I feel like you have a number of <code>TransferTask</code>s and want to have a sort of <code>ProgressTracker</code> for them. So, as for me, your goal is to make user's code look like this:</p>\n\n<pre><code>ProgressTracker progress...
{ "AcceptedAnswerId": "13122", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T12:38:29.483", "Id": "13121", "Score": "3", "Tags": [ "java", "android" ], "Title": "Download Progress Calculator" }
13121
<p>I seem to have this tendency to write custom methods, i.e. code that isn't reusable. The following seems to be one example of trying to do too much in a single method. But the point I'm not sure about is, in order to split it up, I'd have to redo the for loop each time. Is that acceptable?</p> <p>Any general point...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T14:23:51.560", "Id": "21228", "Score": "0", "body": "How exactly are you thinking about splitting the method? Why do you think it would require redoing the loop? Why do you think that would be a problem?" }, { "ContentLicens...
[ { "body": "<p>Just a few small notes:</p>\n\n<ol>\n<li><p>The method has seven parameters which isn't a good smell. Maybe some of them could be class field.</p></li>\n<li><p>First, I'd reverse some conditions and use guard clauses to make the code flatten.</p>\n\n<pre><code>for (int i = 0; i &lt; dtSProcList.Ro...
{ "AcceptedAnswerId": "13216", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T13:55:03.077", "Id": "13125", "Score": "5", "Tags": [ "c#", "design-patterns" ], "Title": "Design issues, tendency to write custom methods" }
13125
<p>I'm wondering about the difference between these two linq statements</p> <pre><code>bool overlap = GetMyListA().Intersect(GetMyListB()).Any(); // 1. </code></pre> <p>vs</p> <pre><code>bool overlap = GetMyListA().Any(i =&gt; GetMyListB().Contains(i)); // 2. </code></pre> <p>Will statement 2. call GetMyListB() for...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T15:10:58.543", "Id": "21233", "Score": "0", "body": "Both will yield the same result (assuming there are no side-effects in `GetMyListA()` or `GetMyListB()`). I'd say 1 is the most readable and 2 the most logical." }, { "Con...
[ { "body": "<p>Assuming LINQ to objects (i. e. these are in-memory collections not LINQ to Entities IQueryables or something):</p>\n\n<blockquote>\n <p>Will statement 2. call GetMyListB() for each item in ListA?</p>\n</blockquote>\n\n<p>Yes. If you want to avoid this, you'll have to store the result of GetMyLis...
{ "AcceptedAnswerId": "15268", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T15:02:34.950", "Id": "13127", "Score": "8", "Tags": [ "c#", "linq" ], "Title": "Which linq statement is better to find there is an overlap between two lists of ints?" }
13127
<p>I want to simplify this C code into different functions:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;stdlib.h&gt; #include &lt;libxml/xmlmemory.h&gt; #include &lt;libxml/parser.h&gt; // Declare functions void parseSystemProperties(char *xmlFileName); void parseSystemModules(xmlDo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T15:13:56.247", "Id": "21236", "Score": "0", "body": "Briefly looking at the code (ignoring correctness), I'd say you should worry more about trimming off your comments. Any time you have more comments than you have code, that shoul...
[ { "body": "<p>A few observations, Avoid comments that do not tell the reader any thing that they can not understand by reading the code. They just add to the visual noice. Instead add comments as to how the function fits in with the rest of the program, or how the function is to be used.</p>\n\n<pre><code>#incl...
{ "AcceptedAnswerId": "13131", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T15:03:32.377", "Id": "13128", "Score": "1", "Tags": [ "c", "xml" ], "Title": "Parsing an XML configuration file for network monitoring" }
13128
<p>I find my self often doing things like this in Ruby on Rails:</p> <pre><code>@count = 0 LineItem.all.each do |item| if (item.cart_id == @cart.id) @count += item.quantity end end </code></pre> <p>So many things look wrong with this, but I want to initialize my variable (@count) before the loop, an...
[]
[ { "body": "<p>From what I can see, you are just collecting the <code>item.quantity</code> of all matching\nitems. This can be accomplished by</p>\n\n<pre><code>@count = LineItem.all.find_all{|i| i.cart_id == @cart.id}.map{|i| i.quantity}.inject(0,:+)\n</code></pre>\n\n<p>Do you mean that you might be doing some...
{ "AcceptedAnswerId": "13132", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T15:25:41.887", "Id": "13130", "Score": "3", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Instance variables and do loops in ruby on rails" }
13130
<p>Any suggestions to improve the performance of the following code? This code is exceeding the time limit for the last four cases. This is a solution to the problem <a href="https://www.interviewstreet.com/challenges/dashboard/#problem/4fcf919f11817" rel="nofollow">https://www.interviewstreet.com/challenges/dashboard/...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-28T03:42:32.043", "Id": "62778", "Score": "0", "body": "How about rewriting it to be a bit clearer? I see at least one function in there you can factor out, there're probably more. As is it's difficult to understand and unmaintainable....
[ { "body": "<pre><code>def main():\n N = int(raw_input())\n if(0&lt;=N&lt;=100000):\n</code></pre>\n\n<p>There really isn't much point in checking this. Your code works regardless of the value, and you don't need to worry about whether the contest will feed you larger values</p>\n\n<pre><code> x = [...
{ "AcceptedAnswerId": "13144", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T16:48:12.293", "Id": "13133", "Score": "2", "Tags": [ "python", "performance", "contest-problem" ], "Title": "Median solving from Interview street in Python" }
13133
<p>Is this an acceptable use of typedef in the class, Inventory?</p> <p><strong>Inventory.h</strong></p> <pre><code>#ifndef INVENTORY_H #define INVENTORY_H #include "Item.h" #include &lt;unordered_map&gt; class Inventory { public: typedef std::unordered_map&lt;Item, int&gt; ItemTable; ///&lt; Items and their qu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-28T21:34:10.047", "Id": "21306", "Score": "0", "body": "Normally, I absolutely hate typeset but you've used it very nicely." } ]
[ { "body": "<p>Very much so. It reduces typing on your part and increases readability on the reader's part.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-28T15:54:15.000", "Id": "21297", "Score": "0", "body": "It also reduces ...
{ "AcceptedAnswerId": "13143", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-28T01:57:37.470", "Id": "13138", "Score": "7", "Tags": [ "c++" ], "Title": "Acceptable use of typedef in class?" }
13138
<p>In C++ (and C++11), classes defining a <code>+</code> and <code>+=</code> operators often define a <code>-</code> and <code>-=</code> operators that do nearly the same thing (except <code>+</code> is replaced with <code>-</code> in the function). </p> <p>What is the best way to avoid duplicated code here (and still...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T21:52:15.900", "Id": "21261", "Score": "1", "body": "Have you looked at [Boost.Operators](http://www.boost.org/libs/utility/operators.htm)?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T21:52:33.953...
[ { "body": "<p>I actually quite like this pattern and use it relatively often. I'm not sure if there is something better than functors for this - if there is, I'm not really aware of it. That being said, with C++11, I'd write this in a slightly different way:</p>\n\n<pre><code>struct num {\n int val;\n\n const...
{ "AcceptedAnswerId": null, "CommentCount": "17", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-27T21:50:40.713", "Id": "13140", "Score": "8", "Tags": [ "c++", "c++11", "operator-overloading" ], "Title": "Avoid duplicated += -= operator code" }
13140
<p>i had made a small code snippet for multiple inheritance in js. this code is working for me but actually i like to get the review, that its good and if any problem; provide the solution. etc. the code snippet is below.</p> <pre><code>/** * WebbaseUtility provide the bundle of utilities used for support the webbase...
[]
[ { "body": "<p>First of all, I responded to the <a href=\"http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/2ba05b0f5e4a9648\" rel=\"nofollow\">post in c.l.js</a>, and this content in part reiterates the comments there.</p>\n\n<p>My first thought is that you should look at some of the avai...
{ "AcceptedAnswerId": "13375", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-28T07:28:24.850", "Id": "13147", "Score": "1", "Tags": [ "javascript", "object-oriented" ], "Title": "javascript multiple inheritance code review" }
13147
<p>I had code that violated the Single Responsibility Principle in a <a href="https://stackoverflow.com/questions/11224170/refactoring-code-to-avoid-anti-pattern">question on Stack Overflow</a>.</p> <p>In order to overcome that problem, I changed the code as follows.</p> <ol> <li>Is this a good practice in order to o...
[]
[ { "body": "<p>I'm not sure about some of your questions, but a few ideas I have are:</p>\n\n<ol>\n<li>Could you make the the account status and even account types an\nenumeration? I tend to try and err on the use of enumerations over string literals. I believe the latest version of Linq to SQL supports this?<...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-28T07:37:08.053", "Id": "13148", "Score": "3", "Tags": [ "c#", "object-oriented", "design-patterns", ".net", "finance" ], "Title": "Usage of Single Responsibility Principle w...
13148
<p>I have written an algorithm in C#. It is recursive, but it is not optimal. Maybe you have suggestions for improvement? (I already posted this question on stackoverflow but the question was closed there).</p> <p>This is the exercise (I made it up myself). There are 3 or more buckets and there are 4 or more balls. Th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-28T09:05:21.937", "Id": "21287", "Score": "2", "body": "Why is that one unwanted?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-19T17:28:56.947", "Id": "22326", "Score": "1", "body": "Looks li...
[ { "body": "<p>The obvious answer (for the unwanted duplicate) is to maintain a set of the previous column counts. So when it comes to (the second) [1,2,2], you can check whether it's in the set of { [3,1,1], [2,2,1], [1,3,1], [1,2,2], [2,1,2] } and conclude that you don't want to print the line and so exit the ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-28T08:32:46.093", "Id": "13149", "Score": "2", "Tags": [ "c#", "algorithm", "recursion" ], "Title": "How can I remove unwanted combinations from my algorithm in C#?" }
13149
<p>I wrote the following code for printing all the paths to the leaf nodes in a tree (NOT a binary tree ) without using recursion. I have used a stack and performed dfs on the tree. Whenever I reach a leaf node I pop all the elements in the stack right till the root so that the function starts over again from the root ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-29T13:51:40.560", "Id": "21338", "Score": "0", "body": "Obvious question: why not do it recursively? This will make the code much simpler, and potentially more efficient. Furthermore, your code isn’t valid C++ and leaks memory. You sho...
[ { "body": "<p>In order that things appear in the code:</p>\n\n<pre><code>using namespace std;\n</code></pre>\n\n<p>This is unnecessary and generally bad practice. I would ask about it if I saw it in an interview question, although it is not harmful in this case.</p>\n\n<pre><code>struct node\n{\n node(int d...
{ "AcceptedAnswerId": "13349", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-28T08:45:22.180", "Id": "13150", "Score": "5", "Tags": [ "c++", "performance", "algorithm", "tree", "stack" ], "Title": "Tree-traversal without recursion" }
13150
<p>This was for an assignment. I had to write a function to compare two roman numerals. This had to return <code>true</code> only if the second number was larger than the first and had to be done without converting the letters into integers. Also prefix subtraction didn't apply so all the letters came in descending ord...
[]
[ { "body": "<p>It gives wrong results for <code>9</code> (<code>IX</code>) and <code>5</code> (<code>V</code>).</p>\n\n<p>Some notes about the code:</p>\n\n<ol>\n<li><p>In the following block the <code>$evaluate = 8;</code> and the <code>break;</code> statements are unnecessary, they never run because of the <co...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-28T11:18:53.003", "Id": "13153", "Score": "3", "Tags": [ "php", "algorithm", "homework" ], "Title": "PHP function to compare two Roman numerals" }
13153
<p><a href="http://stackoverflow.com/tags/srp/info">Source: the SRP tag wiki on StackOverflow</a></p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-28T11:59:06.417", "Id": "13154", "Score": "0", "Tags": null, "Title": null }
13154
In object-oriented programming, the single responsibility principle states that every object should have a single responsibility, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-28T11:59:06.417", "Id": "13155", "Score": "0", "Tags": null, "Title": null }
13155
<p>I'm looking to bullet-proof this method. Specifically, I never want an item to be left without calling the following:</p> <pre><code>MailMethods.UpdateMessageState(item.Mail_ID, 2, ex.Message); </code></pre> <p><strong>The Method</strong></p> <pre><code>private static void SendMail(MailItemViewModel item) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-28T14:59:09.267", "Id": "21292", "Score": "0", "body": "You should consider refactoring this code. The method is too long and is \"[arrow code](http://www.codinghorror.com/blog/2006/01/flattening-arrow-code.html)\"... in some places yo...
[ { "body": "<p>There are a couple things I would do:</p>\n\n<ul>\n<li>You can collapse your catch for SmtpException,\nNullReferenceException, and Exception into a single catch block,\nsince all blocks have identical code.</li>\n<li>You can split off your handling of To, CC, and BCC addresses into a\nhelper metho...
{ "AcceptedAnswerId": "13165", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-28T13:51:50.677", "Id": "13159", "Score": "1", "Tags": [ "c#" ], "Title": "Bullet-proofing an email scheduler in C#" }
13159
<p>Can someone critique this Java code?</p> <pre><code>package javaapplication; import java.util.Date; import java.lang.Long; interface infix_operator { public int apply(int x, int y); } class f implements infix_operator { public int apply(int x, int y) { return x + (2 * y); } } class g imple...
[]
[ { "body": "<p>Just a couple of points which are more from a stylistic point-of-view rather than strict language requirements or algorithmic correctness:</p>\n\n<ul>\n<li>Classes should be named upper-case: <code>Car</code>, <code>House</code>, <code>TwoTimesPlusOne</code>, <code>Addition</code></li>\n<li>Interf...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-28T16:26:37.613", "Id": "13161", "Score": "2", "Tags": [ "java", "hashcode" ], "Title": "Retrieving current time and computing a hash value" }
13161
<p>In <a href="https://github.com/GCorbel/comment-my-projects" rel="nofollow noreferrer">my project</a>, I have this kind of code to test my controllers:</p> <pre><code>#encoding=utf-8 require 'spec_helper' describe ProjectsController do let!(:project) { build_stubbed(:project, user: user) } let(:user) { build_st...
[]
[ { "body": "<p>I found <a href=\"https://codereview.stackexchange.com/a/695\">this answer</a> helpful; I also like using the shoulda matchers to clean things up.</p>\n\n<p>Yes, I think you should test your assignments. If you use the shoulda matchers, this becomes much less painful, for example:</p>\n\n<pre><cod...
{ "AcceptedAnswerId": "26182", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-28T16:35:23.893", "Id": "13162", "Score": "1", "Tags": [ "ruby", "unit-testing", "ruby-on-rails", "controller", "rspec" ], "Title": "Refactoring my controller specs" }
13162
<p>I'm working code sample <a href="http://jsbin.com/ugilev" rel="nofollow">here</a>.</p> <p>Note: <em>Above <strong>only</strong> tested in Firefox 13.0.1, iPad (non-retina) and Chrome 20.0.x.</em></p> <p>Here's the relevant code:</p> <pre><code>var $outside = $(document) .add($('html')) .add($(':not[' + da...
[]
[ { "body": "<p>After several days of hard work, I think that I've found the answers to my questions.</p>\n\n<ol>\n<li><p>The best element I've found to check for outside click/focus is <code>$(document)</code>.</p>\n\n<p>Caveat: When on iPad, the event needs to be <code>touchstart</code>, not <code>click</code>....
{ "AcceptedAnswerId": "13488", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-28T18:41:06.143", "Id": "13166", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "Click and/or focus outside & -webkit-tap-highlight-color" }
13166
<p>I've previously posted this on Stack Overflow, and am considering submitting it to Boost for wider distribution, but thought perhaps it would be best to put it up here for peer review first, and see whether there are clear improvements that can be made first.</p> <pre><code>// infix_iterator.h // #if !defined(INFI...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-03T12:58:46.360", "Id": "21441", "Score": "0", "body": "Why do you take a `charT const *d` instead of a `const std::basic_string<charT>&`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-22T07:33:15.987", ...
[ { "body": "<p>The only thing at all that I can criticise in the code is the inconsistent placement of whitespace between infix operators and in pointer / reference declarations.</p>\n\n<pre><code>class charT=char,\npublic std::iterator&lt;std::output_iterator_tag,void,void,void,void&gt;\n</code></pre>\n\n<p>… e...
{ "AcceptedAnswerId": "13209", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-29T05:32:19.730", "Id": "13176", "Score": "68", "Tags": [ "c++", "c++11", "iterator" ], "Title": "infix_iterator code" }
13176
<p><a href="http://en.wikipedia.org/wiki/Roman_numerals" rel="nofollow">Roman numerals on Wikipedia</a></p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-29T07:28:28.903", "Id": "13178", "Score": "0", "Tags": null, "Title": null }
13178
The Roman numeral system is an ancient way of representing numbers. The most common symbols are I, V, X, L, C, D, M.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-29T07:28:28.903", "Id": "13179", "Score": "0", "Tags": null, "Title": null }
13179
<p>I am refactoring my controllers, trying to improve the way common data is loaded for the actions. Initially, I was using <code>before_filter</code> methods to do this but read that helper methods were preferred.</p> <pre><code>class CategoriesController &lt; ApplicationController before_filter :authenticate_user!...
[]
[ { "body": "<p>To load data, you can see the gem <a href=\"https://github.com/ryanb/cancan/\" rel=\"nofollow\">Cancan</a>. It think it can do something like you do. I find your code very clear.</p>\n\n<p>Instead of this:</p>\n\n<pre><code>if !organisation.nil?\n</code></pre>\n\n<p>You can do this:</p>\n\n<pre><c...
{ "AcceptedAnswerId": "13194", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-29T07:31:42.503", "Id": "13180", "Score": "1", "Tags": [ "ruby", "ruby-on-rails", "controller" ], "Title": "Loading data in controllers" }
13180
<p>The following search script creates a JSON response for an autocomplete field. The tables and fields search from are flexible to allow using the same script for different type of searches - the idea is to search from each database field separately and see how often a term appears and sort them in descending order.</...
[]
[ { "body": "<p><strong>Upgrading PHP</strong></p>\n\n<p>Upgrade your PHP version. After reading this code I determined that you are running at the most 4.0.6. <code>key_exists()</code> was replaced with <code>array_key_exists()</code> in 4.1.1, and this was some time ago. An old version of PHP runs the risk of h...
{ "AcceptedAnswerId": "13245", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2012-06-29T07:36:14.600", "Id": "13181", "Score": "2", "Tags": [ "php", "sorting", "mysql", "json" ], "Title": "Search script for autocomplete suggestions" }
13181
<p>I was solving problem <a href="http://projecteuler.net/problem=18" rel="nofollow noreferrer">18</a> and <a href="http://projecteuler.net/problem=67" rel="nofollow noreferrer">67</a> on Project Euler and came up with an algorithm that actually goes through <em>almost</em> all the possibilities to find the answer in ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-29T17:06:24.517", "Id": "21350", "Score": "0", "body": "Since you seem to understand how dynamic programming works, would you kindly describe your algorithm using words?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate...
[ { "body": "<blockquote>\n <p>Is my approach not a Brute force?</p>\n</blockquote>\n\n<p>Nope, you've implemented dynamic programming</p>\n\n<pre><code>n = []\nfor i in range(100):\n n.append(map(int,raw_input().split()))\nnewresult = [int(59)]\n</code></pre>\n\n<p>I'm not clear why you pass 59 to int, it do...
{ "AcceptedAnswerId": "13206", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-29T13:27:55.580", "Id": "13186", "Score": "3", "Tags": [ "python", "project-euler" ], "Title": "Isn't this dynamic programming?" }
13186
<p><a href="http://aws.amazon.com/s3/" rel="nofollow"><strong>Amazon S3</strong> (Simple Storage Service)</a> is an online storage web service offered by <a href="http://aws.amazon.com/" rel="nofollow">Amazon Web Services</a>. Amazon S3 provides storage through a simple web services interface. It gives any developer a...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-29T13:28:48.803", "Id": "13187", "Score": "0", "Tags": null, "Title": null }
13187
This tag refers to the Amazon S3 (Simple Storage Service) Web Services from Amazon.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-29T13:28:48.803", "Id": "13188", "Score": "0", "Tags": null, "Title": null }
13188
<p>I recently got serious about learning Haskell and upon finishing chapter 4 in Real World Haskell, I decided to try out my accumulated knowledge on a project of my own.</p> <p><a href="https://github.com/linduxed/kalaha-solver/tree/55146b8cb5fb23590aaaf65d9b4cd3d38bfcea3a" rel="nofollow">This code hosted on github i...
[]
[ { "body": "<p>I would suggest two refactorings:</p>\n\n<p>First note that you can indeed simply merge the four loops by giving them tuple results. After a few smaller changes I arrived at the following code:</p>\n\n<pre><code>moveOneLap :: [Pot] -&gt; Int -&gt; Int -&gt; (([Pot], Bool), Int, Bool)\nmoveOneLap l...
{ "AcceptedAnswerId": "13246", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-29T13:29:33.083", "Id": "13189", "Score": "4", "Tags": [ "haskell" ], "Title": "How to avoid big tuple return types?" }
13189
<p>As with my <a href="https://codereview.stackexchange.com/questions/13189/how-to-avoid-big-tuple-return-types">other question</a> this is regarding my <a href="https://github.com/linduxed/kalaha-solver/tree/55146b8cb5fb23590aaaf65d9b4cd3d38bfcea3a" rel="nofollow noreferrer">Kalaha solver</a>.</p> <p>Currently the wa...
[]
[ { "body": "<p>The standard trick is to skip portions of the search space that cannot bring a better solution than the ones found so far. For this you need to:</p>\n\n<ul>\n<li>Remember the best solution found so far (or several best solutions, if you want).</li>\n<li>Estimate an upper bound on possible scores t...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-29T14:02:40.173", "Id": "13195", "Score": "5", "Tags": [ "optimization", "haskell", "recursion" ], "Title": "Kalaha Solver: finding the marbles" }
13195
<p>Assume I have an article list, each with the following format:</p> <p><strong>Article</strong><br> <img src="https://i.stack.imgur.com/wnOZY.jpg" alt="enter image description here"><br> In the header I'm placing: the article's title, the author and the image,<br> the paragraph belongs to the section, in the footer ...
[]
[ { "body": "<p>You've got things confused a little. </p>\n\n<p>Here's what's wrong:</p>\n\n<ol>\n<li>I prefer to use <code>&lt;header&gt;</code> <strong>only once</strong> on the page. This explains what the header of the page is. You may use it more often if you like.</li>\n<li>I prefer to use <code>&lt;footer&...
{ "AcceptedAnswerId": "15456", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-29T19:27:01.400", "Id": "13200", "Score": "4", "Tags": [ "html5" ], "Title": "HTML5: Section in Article is Untitled Section in the Outliner" }
13200
<p>So I have a customers site I am remaking into an mvc3 app and they have an existing JavaScript pricing calculator. Is this safe and efficient? I am no JavaScript guy, but it looks pretty solid to me.</p> <pre><code> &lt;script type="text/javascript"&gt; window.onload = function () { //Carpet ...
[]
[ { "body": "<p>About the only thing that I don't like in it is that you have to edit the code each time a price changes. I'd prefer that to come from a dynamic source, especially if you are going to use it in more than one spot.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", ...
{ "AcceptedAnswerId": "13228", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-29T20:27:56.390", "Id": "13201", "Score": "4", "Tags": [ "javascript", "html", "calculator" ], "Title": "Calculator for calculating price per feet amounts" }
13201
<p>I just started to program Python. As my first application I implemented an interactive console which automatically python modules before a new code block is evaluated. Here is the code:</p> <pre><code>### module "module_reloading_console.py" import sys import code import imp import readline import os class ModuleR...
[]
[ { "body": "<h1>Automatic tools</h1>\n\n<p><em>PEP8</em>: I'd say your code's OK style wise, but this is what the checker said:</p>\n\n<pre><code>1:1: E266 too many leading '#' for block comment\n19:40: E261 at least two spaces before inline comment\n27:80: E501 line too long (86 &gt; 79 characters)\n29:80: E501...
{ "AcceptedAnswerId": "91096", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-29T21:10:11.767", "Id": "13203", "Score": "2", "Tags": [ "python" ], "Title": "Python interactive console which automatically reload modules" }
13203
<p>The below sections of code are part of a list administration project I am working on to teach myself C#. This is from a tab that is used for list administration. There is a drop down box that allows selection of list administrators, which populates a dropdown box with available lists.</p> <p>Once a list is selected...
[]
[ { "body": "<p>It seems to me that if <code>File.AppendAllText</code> throws an exception <code>dbConn</code> won't be closed.\nThe <code>dbConn.Close()</code> should be in a <code>finally</code> block. (<a href=\"https://stackoverflow.com/questions/901149/exception-inside-catch-block\">Exception inside catch bl...
{ "AcceptedAnswerId": "56612", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-29T21:17:13.997", "Id": "13204", "Score": "5", "Tags": [ "c#", "mysql" ], "Title": "Query and data manipulation" }
13204
<p>I'm using this PHP to modify A elements in a DOM fragment (a vBulletin <code>$post['message']</code> if that matters) so that links to external sites always open new tabs. This is actually the default in vBulletin but it's not always reliable. Anyway, the code works, but looking at the loop makes me think it could b...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-29T22:24:39.817", "Id": "21359", "Score": "0", "body": "interesting that you inverted the loop and counted down from `NodeList::length` - did you have a particular reason for doing it that way?" }, { "ContentLicense": "CC BY-SA...
[ { "body": "<p>To make it elegant clean code I would:</p>\n\n<ul>\n<li>make proper use of blank lines;</li>\n<li>abide by the coding standards defined by <a href=\"http://www.php-fig.org/\" rel=\"nofollow\">PHP-FIG</a>;</li>\n<li>use the <code>DOMNodeList</code> object as an array so I can use <code>foreach()</c...
{ "AcceptedAnswerId": null, "CommentCount": "12", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-29T22:21:09.923", "Id": "13208", "Score": "2", "Tags": [ "php", "dom" ], "Title": "Looping through DOM to modify elements" }
13208
<p>I am trying to solve a puzzle. I came up with a few classes to represent results. They looked similar, so I defined a common <code>Result</code> class. But what if I need to define different results according to different functions?</p> <p>In other words, do I need <code>TypeOneResult</code> and <code>TypeTwoResult...
[]
[ { "body": "<p>I'm not sure I understood your question fully, but from what I could understand, you do not need to have both TypeOneResult and TypeTwoResult. In fact, you probably do not need either of them. You can use the value of the <code>type</code> member of the CommonResult class to distinguish among th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-30T01:22:39.247", "Id": "13210", "Score": "1", "Tags": [ "java" ], "Title": "java code design puzzle for common function result module" }
13210
<p>Is this the best way of doing this. The sample code is a simple lookup of postnr (read zipcode). I'm trying to encapsulate <strong>all</strong> the client side logic inside one "class".</p> <ol> <li>Is this the way of doing callbacks? The this/that stuff sort of creeps me out a little</li> <li>Should the constructo...
[]
[ { "body": "<p><strong>Update:</strong> To answer your specific questions (which I just now realized I completely neglected):</p>\n\n<ol>\n<li><p>The <code>this/that</code> stuff is one way of doing \"context resolution\" (you used the word \"callback\", but that's when you pass a function to another function). ...
{ "AcceptedAnswerId": "13224", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-30T07:55:33.103", "Id": "13212", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "Encapsulation of client side logic in web page" }
13212
<p>I have to display all the numbers between 200 and 600 (both numbers inclusive) that are divisible by 8:</p> <pre><code>for($i=200;$i&lt;=600;$i++) { if($i%8==0) echo $i.','; } </code></pre> <p>It reaches maximum execution time.</p>
[]
[ { "body": "<ol>\n<li><p>Why do you test each number?</p>\n\n<p>Rather than <code>$i++</code> you can use <code>$i += 8</code>. Then the test becomes redundant. </p></li>\n<li><p>Your output is terminated by <code>,</code></p>\n\n<pre><code>...584,592,500,\n ^^^^ Extra trailing comma.\n</code></pr...
{ "AcceptedAnswerId": "13223", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-30T12:46:35.300", "Id": "13217", "Score": "5", "Tags": [ "php" ], "Title": "Displaying all the numbers between 200 and 600" }
13217
<p>I am trying to learn to format XSL more efficiently. I can tell by the definition of duplicate variables and nearly identical templates that I did not create this efficiently at all. How could I have formed this better?</p> <pre><code>Here is my XSL: you can see all of it at http://wwwstage.samford.edu/calendar/A...
[]
[ { "body": "<p>Some tips to improve your coding:</p>\n\n<p>(a) don't do this:</p>\n\n<pre><code>&lt;xsl:variable name=\"pubdate\"&gt;\n &lt;xsl:value-of select=\"r25:events/@pubdate\"/&gt;\n&lt;/xsl:variable&gt;\n</code></pre>\n\n<p>when you can do this:</p>\n\n<pre><code>&lt;xsl:variable name=\"pubdate\" sel...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-30T14:37:36.037", "Id": "13220", "Score": "1", "Tags": [ "xml", "xslt" ], "Title": "How can I optimize my XSL file?" }
13220
<p>I have used the following code for a stack implementation. The <code>top</code> keeps track of the topmost node of the stack. Now since <code>top</code> is a data member of the node function, each <code>node</code> created will have a <code>top</code> member, which ideally we wouldn't want.</p> <ol> <li>Is this goo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-30T15:19:13.240", "Id": "21385", "Score": "0", "body": "making `top` global or static means you can use only one stack in your program! You might want to distinguish between the `node` and `list` classes." }, { "ContentLicense"...
[ { "body": "<ol>\n<li><p>In the <code>pop</code> and the <code>print</code> function, the <code>new node</code> seems unnecessary, since the next line modifies the pointer to point to the <code>top</code>. It could be simply</p>\n\n<pre><code>node *n = top;\n</code></pre></li>\n<li><p>The <code>delete n;</code> ...
{ "AcceptedAnswerId": "13225", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-30T15:12:10.980", "Id": "13226", "Score": "4", "Tags": [ "c++", "stack", "linked-list" ], "Title": "Linked list stack implementation" }
13226