body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I want you to pick my code apart and give me some feedback on how I could make it better or more simple. This code finds a common ancestor for binary search tree. This code accounts duplicates as well as incomplete tree, and also throws an exception if input element is not in the tree.</p>
<pre><code>public class ... | [] | [
{
"body": "<p>Most of the code is pretty good!</p>\n\n<p>I find your interface a bit weird. Instead of <code>public void makeBinarySearchTree(Integer[] a)</code>, I suggest <code>public void addElements(int[] elements)</code> to be consistent with your <code>addElement(int)</code> method. There's no need to t... | {
"AcceptedAnswerId": "31394",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T00:35:03.810",
"Id": "31334",
"Score": "2",
"Tags": [
"java",
"tree"
],
"Title": "Least common ancestor for binary search tree"
} | 31334 |
<p>My professor wants me to do this:</p>
<blockquote>
<p>Write a number of interchangeable counters using the Counter interface below:</p>
</blockquote>
<pre><code>public interface Counter {
/** Current value of this counter. */
int value();
/** Increment this counter. */
void up();
/** Decrement this counter. */
v... | [] | [
{
"body": "<p>Your <code>BasicCounter</code> is impeccable. (The indentation of the braces is a bit off, but maybe that's an artifact from pasting into this site.) I would suggest renaming <code>counterVariable</code> to just <code>count</code>, since it would be silly to name everything <code>fooVariable</co... | {
"AcceptedAnswerId": "31337",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T01:18:42.310",
"Id": "31335",
"Score": "2",
"Tags": [
"java",
"homework",
"beginner"
],
"Title": "Beginner Java Counter code"
} | 31335 |
<p>I'm building a mini-app that will display when changes to the DOM have been made by JavaScript. I have all of the functions that I can think of listed in the code. Is there a way to consolidate the functions into one, and have the overrides still function correctly?</p>
<pre><code>var DomChanges = (function() {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T17:24:02.287",
"Id": "49945",
"Score": "0",
"body": "Are you unable to use [Mutation Observers](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver)?"
}
] | [
{
"body": "<pre><code>//\n// maybe this:\n//\n\"appendChild removeChild insertBefore insertAfter insertAttribute removeAttribute replaceChild createElement\"\n.split(\" \")\n.forEach(\n function ( ftype ) {\n var corefn = this[ftype]\n this[ftype] = function () {\n DomChange( ftype, ... | {
"AcceptedAnswerId": "31340",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T02:26:31.423",
"Id": "31336",
"Score": "3",
"Tags": [
"javascript",
"dom"
],
"Title": "DOM override app"
} | 31336 |
<p>I'm writing a program for my intro to comp sci course where I'm supposed to prompt the user to enter a stream of integers, and then return the largest two. We were given the hint to use a scanner and a while loop with the condition <code>.hasnext</code>.</p>
<p>Please review my code:</p>
<pre><code>package Homewor... | [] | [
{
"body": "<p>Your logic is actually correct. Perhaps you just don't know what to type in your terminal window to terminate the input stream. After typing in your numbers, you need to send an end-of-file (\"EOF\") character. On Unix, you do that by hitting <kbd>Control</kbd><kbd>D</kbd>. On Windows, it's <k... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T03:46:29.320",
"Id": "31339",
"Score": "3",
"Tags": [
"java",
"homework",
"beginner"
],
"Title": "Print largest two integers from a stream"
} | 31339 |
<p>I've been practicing implementing a linked list from scratch. Can someone help review my code?</p>
<pre><code>class Node {
Node next;
int num;
public Node(int val) {
num = val;
next = null;
}
}
public class LinkedList {
Node head;
public LinkedList(int val) {
head... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T18:54:51.097",
"Id": "57984",
"Score": "1",
"body": "Just realized my append function doesn't check if head is null at the beginning also. My current function would throw an NPE if it was null."
}
] | [
{
"body": "<ol>\n<li><p>Your implementation does not allow for an empty list.</p>\n\n<ol>\n<li>It's a bit odd to only have the constructor which takes a node value.</li>\n</ol></li>\n<li><p>You should probably implement the <code>List</code> interface.</p></li>\n<li><p>You should look into generics instead of h... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T04:48:26.433",
"Id": "31341",
"Score": "11",
"Tags": [
"java",
"linked-list"
],
"Title": "Java code for Linked List"
} | 31341 |
<p>I wrote a script for validate the input field for following requirements</p>
<ol>
<li>Not null</li>
<li>Multiple of hundreds </li>
<li>Less than needed amount</li>
</ol>
<p>Here is my script:</p>
<pre><code> $('#investAmount,#invest-button').bind('keypress', function(event){
if(event.which == ... | [] | [
{
"body": "<p>I'm not much of a jQuery freak, but I still have some points on this code. In your amountValidation function, you have some duplication and overhead:</p>\n\n<blockquote>\n<pre><code>if(errAmount == true)\n</code></pre>\n</blockquote>\n\n<p>can be written:</p>\n\n<pre><code>if(errAmount)\n</code></... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T05:02:22.420",
"Id": "31342",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"validation"
],
"Title": "Simplify jQuery validation"
} | 31342 |
<p>This is the original version of code written by my coworker that replaces every null cells with an empty string.</p>
<pre><code>for (int i = 0; i < dGV_factory.Rows.Count; i++)
{
this.dGV_factory["dGV_factory_groupID", i].Value
= this.dGV_factory["dGV_factory_groupID", i].Value ?? "";
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T05:20:33.153",
"Id": "49895",
"Score": "0",
"body": "Opinion based close vote?? I'd really appreciate which part sounds very opinionated, and I'd be glad to edit. Really, I'm just looking for a guidance."
},
{
"ContentLicens... | [
{
"body": "<p><code>List.ForEach</code> might have its uses, but I wouldn't use it here. It's not \"wrong\" per se, but a classic <code>foreach</code> loop </p>\n\n<ul>\n<li>is at least as easy to read as your LINQ expression,</li>\n<li>does not require the explicit <code>Cast<...>()</code>,</li>\n<li>doe... | {
"AcceptedAnswerId": "31351",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T05:08:04.857",
"Id": "31344",
"Score": "5",
"Tags": [
"c#",
"linq"
],
"Title": "Null replacement - Is this LINQ readable?"
} | 31344 |
<p>I'm building a rails app that, among other things, imports text markdown files as blog posts. The idea is that the truth is in the markdown files, so any time those are edited, created, or deleted, the blog should reflect this. Of course, I had to make this more complicated and insist that I should be able to edit, ... | [] | [
{
"body": "<p>There are actually 2 kinda distinct pieces of code to review here: The file I/O, and the syncing.</p>\n\n<p><strike>For now, this'll be a partial review, looking only at the file I/O, as I haven't had time to look at the sync code.</strike> Update: Added some thoughts on the syncing at the end of ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T05:35:10.650",
"Id": "31345",
"Score": "1",
"Tags": [
"ruby",
"ruby-on-rails",
"postgresql",
"markdown",
"sync"
],
"Title": "Importing markdown files"
} | 31345 |
<p>I received the following question in a technical interview today (for a devops/SRE position):</p>
<blockquote>
<p>Write a function which returns true if the two rectangles passed to it
as arguments would overlap if drawn on a Cartesian plane. The
rectangles are guaranteed to be aligned with the axes, not arb... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T08:47:58.117",
"Id": "49909",
"Score": "1",
"body": "By the way, please excuse the horribly amateurish graphic. I'm NOT a graphics guy and had to go fetch Inkscape to even manage this pathetic thing here."
},
{
"ContentLice... | [
{
"body": "<p>You have common code, which moreover has applications beyond this one, so should you not pull it out into a function? Then you can reduce <code>overlap</code> to</p>\n\n<pre class=\"lang-py prettyprint-override\"><code>def overlap(r1, r2):\n '''Overlapping rectangles overlap both horizontally &... | {
"AcceptedAnswerId": "31529",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T08:46:16.267",
"Id": "31352",
"Score": "32",
"Tags": [
"python",
"interview-questions",
"collision",
"computational-geometry"
],
"Title": "Overlapping rectangles"
} | 31352 |
<p>I'm quite new to Zend and unit testing in general. I have come up with a small application that uses Zend Framework 2 and Doctrine. It has only one model and controller and I want to run some unit tests on them.</p>
<p>Here's what I have so far:</p>
<p>Base doctrine 'entity' class, containing methods I want to use... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T10:59:07.303",
"Id": "50158",
"Score": "1",
"body": "Just a quick question: Are you, at any point, creating a mockup of the actual entities and/or entity manager? If you don't, there's a good chance you might accidentally alter actu... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T09:43:51.367",
"Id": "31353",
"Score": "1",
"Tags": [
"php",
"unit-testing",
"zend-framework",
"doctrine"
],
"Title": "Zend Framework and Doctrine 2 - are my unit tests suffic... | 31353 |
<p>This method works correctly and verifies whether a user has permissions to view or edit the first parameter (value). I think it is not the best implementation, because there are too many conditions and the <code>List</code> object isn't necessary. How to improve it?</p>
<pre><code>protected override Exception GetVa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T10:42:29.757",
"Id": "49912",
"Score": "0",
"body": "Unless you call this method very often, I really doubt its performance is going to be a problem. Have you profiled your code? Is this method really the part that's slowing it down... | [
{
"body": "<p>I think the assignment of your <code>entities</code> (bad name) is <strong>uber-abusing</strong> ternary expressions.</p>\n\n<p>That said, my first thought was <em>why on Earth would you want to <strong>return</strong> an <code>Exception</code></em>? So I googled up a bit and found <a href=\"https... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T10:16:22.637",
"Id": "31354",
"Score": "3",
"Tags": [
"c#",
"performance"
],
"Title": "Improve performance by excluding multiple conditions and List"
} | 31354 |
<p>I want to run the timer at 2:00 a.m. and shutdown the application.
This is my code:</p>
<pre><code> var ShutdownTimer = new Timer();
var currentTime = DateTime.Now;
int hoursUntilShutdown;
switch (currentTime.Hour)
{
case 1:
hoursUntilShutdown = 1;
break;
case 2:
hoursUntilShut... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T12:33:39.313",
"Id": "49917",
"Score": "1",
"body": "The whole `switch` can be replaced by `hoursUntilShutdown = (26 - currentTime.Hour) % 24`, where `%` is the remainder of the division, as in C (I don't use C#, so I can only assum... | [
{
"body": "<p>The whole <code>switch</code> can be replaced by</p>\n\n<pre><code>hoursUntilShutdown = (26 - currentTime.Hour) % 24\n</code></pre>\n\n<p>where <code>%</code> is the remainder of the division, as in C (I don't use C#, so I can only assume it's the same).</p>\n",
"comments": [],
"meta_data"... | {
"AcceptedAnswerId": "31360",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T12:06:19.743",
"Id": "31357",
"Score": "2",
"Tags": [
"c#",
".net"
],
"Title": "I want to run the timer at 2:00 a.m. and shutdown the application"
} | 31357 |
<p>I have been working on a toggle script, but I find myself repeating my code. Is there a way of combining it all?
<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>jQuery(document)... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T14:54:01.843",
"Id": "49938",
"Score": "0",
"body": "Have you looked at *event delegation*?"
}
] | [
{
"body": "<p>You can either write a method that is bound to the global scope and takes two arguments, the onClick element and the slideToggle element, and does just what you want (without writing redundant code).</p>\n\n<pre><code>function bindToggleTwo(cElem, tElem) {\n $(cElem).click(function() {\n $(... | {
"AcceptedAnswerId": "31403",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T14:39:22.930",
"Id": "31367",
"Score": "5",
"Tags": [
"javascript",
"beginner",
"jquery",
"html",
"css"
],
"Title": "jQuery toggle script"
} | 31367 |
<p>I need some tips on how I can improve the design of the following code. Everything works correctly in the program. It takes a string and shows each token, the only tokens being numbers and operators. The output shows all the tokens and what type of token they are. </p>
<pre><code>public class Tokenizer {
int po... | [] | [
{
"body": "<p>This code looks quite nice, actually. If this was a homework assignment, you could almost turn it in right now. I only have some minor issues with the code, plus some bugs, and would then like to talk about alternatives to structure your lexer (the words <em>tokenizer</em>, <em>lexer</em> and <em>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T16:06:34.823",
"Id": "31370",
"Score": "9",
"Tags": [
"java",
"strings",
"parsing"
],
"Title": "String tokenizer design"
} | 31370 |
<p>I have the following code which changes the text in a certain element on click depending on the text value present in the element at the time the event is fired.</p>
<p><a href="http://jsfiddle.net/TNDhL/" rel="nofollow">http://jsfiddle.net/TNDhL/</a></p>
<pre><code>$('#left').on('click', function (){
if ($("#text... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T18:31:32.570",
"Id": "49946",
"Score": "0",
"body": "do you need that fuzzy match?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T18:36:44.917",
"Id": "49947",
"Score": "0",
"body": "Ah..... | [
{
"body": "<p>The easier (imho) solution would be to store what you want in an nested object containing the matches :</p>\n\n<pre><code>var selectors = {\n left: {\n 'something': ['third text replacement', 'more here'],\n 'third text replacement': ['now the next item', 'something new here'],\n }\n};\n\n... | {
"AcceptedAnswerId": "31402",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T17:38:13.043",
"Id": "31374",
"Score": "0",
"Tags": [
"javascript",
"jquery"
],
"Title": "Simplifying multiple click events into something more extendable"
} | 31374 |
<p>I've read the docs online explaining Log N and I do understand that the basic concept of it, but I'm still not sure I've managed to nail it.</p>
<blockquote>
<p><strong>The problem</strong></p>
<p>This exercise is called <em>"Complementary Pairs"</em> and given an array <em>A</em>
and an integer <em>K</em>... | [] | [
{
"body": "<p>This is not O(n log n) algorithm, because this part is quadratic:</p>\n\n<pre><code> for (var i = 0; i < firstArray.length; i++) {\n for (var j = 0; j < secondArray.length; j++) {\n if (firstArray[i] + secondArray[j] == k) {\n count += 2\n }\n }\n }\n</code></pre>\n\... | {
"AcceptedAnswerId": "31386",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T18:09:40.123",
"Id": "31377",
"Score": "5",
"Tags": [
"javascript",
"algorithm",
"programming-challenge",
"recursion"
],
"Title": "Finding complementary pairs"
} | 31377 |
<p>I'd like someone to suggest a better way to create this pattern in Java which I'm sure is possible:</p>
<pre><code>*********
* *
* *
* *
* *
* *
* *
* *
*********
</code></pre>
<p>I'm working my way through a new Java book and am examining string patterns.</p>
<pre><code>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-17T01:46:21.247",
"Id": "50009",
"Score": "0",
"body": "When doing a lot of string concatenations, you should instead use a `StringBuilder`. This is for performance reasons, so it is actually not very important for your problem."
},... | [
{
"body": "<p>It's ok for a first iteration.</p>\n\n<ol>\n<li>But your 2nd iteration should be <code>drawRectangle(int width, int height)</code>. That will force you to not hard-code your numbers.</li>\n<li>Your 3rd iteration should be noticing that your rectangle only has 2 different rows (one row fills up the... | {
"AcceptedAnswerId": "31381",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T18:30:18.913",
"Id": "31379",
"Score": "6",
"Tags": [
"java",
"ascii-art"
],
"Title": "Making a rectangular-shaped pattern"
} | 31379 |
<p>I have a page where a user needs to click two checkboxes before continuing (agree to two terms of service). My jQuery is fairly straightforward, you have to have both check boxes checked to continue:</p>
<pre><code>$("#agree1, #agree2").click(function () {
if ($("#agree1").is(':checked') == true && $("#... | [] | [
{
"body": "<p>You can look for only the checked checkboxes, and then check that you found two:</p>\n\n<pre><code>if ($(\"#agree1:checked,#agree2:checked\").length == 2) { ... }\n</code></pre>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"Cre... | {
"AcceptedAnswerId": "31389",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T20:04:51.453",
"Id": "31382",
"Score": "5",
"Tags": [
"javascript",
"jquery"
],
"Title": "Check if two checkboxes are checked"
} | 31382 |
<p>I have the following data structure:</p>
<pre><code>data XComposeString = XComposeString { keyEvents :: [Event], s :: Result }
deriving (Eq, Show)
data XComposeFile = XComposeFile { strings :: [XComposeString] }
deriving (Eq, Show)
</code></pre>
<p>Where <code>Event</code> and <code>Result</code> just <code>S... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T17:17:01.073",
"Id": "52404",
"Score": "0",
"body": "Are you using [TrieMap](http://hackage.haskell.org/package/TrieMap) package?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-16T17:21:49.033",
"Id... | [
{
"body": "<p>Can you add minimal imports so your code compiles? I had to guess:</p>\n\n<pre><code>import Data.ListTrie.Map as M hiding (null)\nimport qualified Data.Map as Map\nimport Data.Maybe\nimport Data.List\n\n\ndata Event = Event deriving (Show, Eq, Ord)\ndata Result = Result deriving (Show, Eq)\n</code... | {
"AcceptedAnswerId": "32773",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T20:18:00.437",
"Id": "31383",
"Score": "2",
"Tags": [
"haskell"
],
"Title": "Improve Trie manipulation in Haskell code"
} | 31383 |
<p>This is a data structure I wrote:</p>
<ul>
<li>It is an circular first-in-first-out queue (a ringbuffer); </li>
<li>It has batched removal/popping - it returns an array of a fixed buffer size; </li>
<li>It is unbounded, and grows itself as needed;</li>
<li>It is generics-compliant (at the cost of primitives). </... | [] | [
{
"body": "<p>0) It seems simpler to me to just copy the remainder of the buffer in a normal array every time some chunk is removed instead of using a circular buffer. Using a LinkedList would not even require copying anything. But I must admit if you have millions of bytes, a <code>LinkedList<Byte></c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T21:12:30.140",
"Id": "31388",
"Score": "3",
"Tags": [
"java",
"performance",
"thread-safety",
"circular-list"
],
"Title": "Unbounded, High-performance(?), Generic, Thread-Safe... | 31388 |
<p>This is a program I made to bounce the letter a across the screen. I made a few others, but this one I made with a recursive <code>bounce()</code> method. I know <code>main()</code> is a bit empty, but I intend to make an input menu that main refrences, so it seemed better to put the code in another method. </p>
... | [] | [
{
"body": "<p>Before explaining why I think recursion might be a bad idea here, let me show you the solution I came up with. </p>\n\n<pre><code>class Wave8 {\n\n public static void bounce() {\n String spaces = \"\";\n for (int i=0; i<80; i++, spaces += \" \")\n {\n System.out.println(spaces ... | {
"AcceptedAnswerId": "31393",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-16T22:43:21.903",
"Id": "31392",
"Score": "4",
"Tags": [
"java",
"optimization",
"recursion"
],
"Title": "Is this recursion a bad idea and does it make for clean code?"
} | 31392 |
<p>I am trying to open two CSV files, one for reading and one for writing. The script should continue only if both files were successfully opened. My code seems to accomplish that but it seems like it could be improved further.</p>
<p>My questions are:</p>
<ol>
<li>Should I consider a different approach?</li>
<li>My ... | [] | [
{
"body": "<p>You might want to pass the filenames to <code>main()</code> as parameters, to promote code re-use and testing. Then in <code>__main__:</code> you could <code>import sys</code> and check for <code>len(sys.argv) > 1</code> ... setting the input, and output filenames thereby.</p>\n\n<p>(You can p... | {
"AcceptedAnswerId": "31411",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-09-16T23:52:41.703",
"Id": "31395",
"Score": "8",
"Tags": [
"python",
"csv",
"file"
],
"Title": "Python: Open Multiple Files"
} | 31395 |
<p>I'm working on a simple CMS with the intent of making it as secure as possible (a personal challenge) and the code as clean as possible. I think I've a long way to go so I would appreciate any input, or bug spotting!</p>
<p><strong>Common.php</strong></p>
<pre><code><?php
// Errors, errors everywhere. Let... | [] | [
{
"body": "<p>You talk security, but you make some really bad mistakes.</p>\n\n<p>To start with the error_reporting. NEVER, simply NEVER have E_ALL as error_reporting level on a production enviroment.</p>\n\n<p>You are catching Exceptions, that is good. But what about E_NOTICE? and E_WARNING? you can catch thes... | {
"AcceptedAnswerId": "31423",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-17T00:09:12.127",
"Id": "31396",
"Score": "3",
"Tags": [
"php",
"sql",
"security",
"sql-server"
],
"Title": "Simple CMS system"
} | 31396 |
<p>What is the general design pattern for declaring variables in a class?</p>
<p>I have a homework assignment to create a simple Java program which asks the user for a range of two variables. The program then creates a random variable from within this range and prompts the user to guess the number.</p>
<p>I'm having ... | [] | [
{
"body": "<p>You can read <a href=\"http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html\" rel=\"nofollow\">this</a> to understand scope of variables or method.</p>\n\n<p>In short:</p>\n\n<ol>\n<li><code>public</code> - Any member of a class declared as public can be accessed outside of the cl... | {
"AcceptedAnswerId": "31406",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-17T01:36:04.420",
"Id": "31400",
"Score": "2",
"Tags": [
"java",
"random",
"homework",
"interval",
"number-guessing-game"
],
"Title": "Guessing a random number between a r... | 31400 |
<p>Just getting into functional programming and F# with the most appropriately titled <a href="http://rads.stackoverflow.com/amzn/click/1107684064" rel="nofollow">Functional Programming Using F#</a>. I wrote the following function definition for problem 2.4 but I'm thinking there's most likely a more elegant and/or idi... | [] | [
{
"body": "<p>First of all, I think that your <code>isIthChar</code> function is an overkill: it usually doesn't make sense to write a function that's <em>that</em> short.</p>\n\n<p>To write the <code>occurrencesFromIth</code> itself, I would use sequence expression to generate the indexes to test and then use ... | {
"AcceptedAnswerId": "31429",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-17T02:11:49.240",
"Id": "31401",
"Score": "2",
"Tags": [
"recursion",
"f#"
],
"Title": "Recursive function refactoring help: occurrences of char in string starting at ith char"
} | 31401 |
<p>This code can be found in the <a href="http://webEbenezer.net/build_integration.html" rel="nofollow noreferrer">archive here</a>. Usually I have a .cc file, but in this case it's all in a header. Am wondering about that. It needs to work in VS12. If possible I'll post more code from the archive for review. I st... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-17T02:56:47.950",
"Id": "50011",
"Score": "1",
"body": "Is this code from your archive, or someone else's?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-17T03:21:27.617",
"Id": "50013",
"Score": "... | [
{
"body": "<p>Though std::exception does not have a constructor for taking an error message; the other standard excretions do. So you can make your exception class simpler by inheriting from one of these.</p>\n\n<pre><code>class failure : public ::std::runtime_error {\n\n public:\n failure (std::string... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-17T02:53:58.140",
"Id": "31404",
"Score": "4",
"Tags": [
"c++"
],
"Title": "Exception classes"
} | 31404 |
<p>Just looking for some pointers on how I could improve the code. This is my first game ever and python is my first language so it's bit messy but I'll be happy to explain stuff if needed. I'm kinda frustrated cause some bits look really ugly and I hope you guys can help me out. Here it is:</p>
<p><strong>EDIT</stron... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T21:23:23.220",
"Id": "50236",
"Score": "1",
"body": "There's no need for a try-except block to surround the imports. You probably don't want to run the script if imports fail, right?"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<h2>1. First version</h2>\n\n<ol>\n<li><p>I can't run it:</p>\n\n<pre><code>>>> import game\nImportError: No module named Vec2D\n</code></pre>\n\n<p>There's no <code>Vec2D</code> package available from the <a href=\"https://pypi.python.org/pypi\">Python Package Index</a>. So where does this ... | {
"AcceptedAnswerId": "31539",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-17T06:35:54.527",
"Id": "31408",
"Score": "10",
"Tags": [
"python",
"game",
"pygame"
],
"Title": "Pong with Pygame"
} | 31408 |
<p>I have a <code>Task</code> model in Django which looks like the following:</p>
<pre><code>class Task(TimeStampedModel):
project = models.ForeignKey(Project, related_name='tasks')
date = models.DateField(_('date'))
task = models.TextField(_('what\'s the task?'))
status = models.CharField(
_('... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T06:46:15.670",
"Id": "50138",
"Score": "1",
"body": "I think grouping on the client side is fine, given the list is limited. I am currently building stuff which lets you do some processing in the client itself. I see that performanc... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-17T07:34:43.270",
"Id": "31410",
"Score": "3",
"Tags": [
"python",
"datetime",
"django",
"angular.js",
"lodash.js"
],
"Title": "Implementing \"day wise task management\" syst... | 31410 |
<p>I'm supplying a HashMap with data in the following way:</p>
<pre><code>HashMap<String,MyClass> myHashMap = new HashMap<String,MyClass>();
myHashMap.put( "foo", new MyClass(2,4) );
myHashMap.put( "bar", new MyClass(0,10) );
myHashMap.put( "a", new MyClass(0,0) );
myHashMap.put( "b", new MyClass(0,1) ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-17T10:33:06.877",
"Id": "50046",
"Score": "1",
"body": "I don't think that there is enough information to offer a good alternative. What are the values \"foo\", 2, 4, etc? Where does the data originate (for both keys and values)? How a... | [
{
"body": "<p>A simple way (but maybe not the best looking one), is this:</p>\n\n<pre><code>String[] names = new String[]{\"foo\",\"bar\",\"a\",\"b\",\"c\",\"d\"};\nint[] parameter1 = new int[]{2,0,0,0,0,0};\nint[] parameter2 = new int[]{4,10,0,1,0,42};\n\nfor (int i=0; names.length>i; i++)\n myHashMap.pu... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-17T09:55:35.193",
"Id": "31417",
"Score": "3",
"Tags": [
"java"
],
"Title": "How to fill in this HashMap neatly without code duplication?"
} | 31417 |
<p>I have an array of objects that each have a name/value property. The array can contain multiple objects with the same name property. I want to serialize this array into the form: </p>
<pre><code>name:value,value|name:value|name:value,value,value
</code></pre>
<p>So basically each property is separated by a <code... | [] | [
{
"body": "<p>Why do you want it serialized specifically in that form? Just use the universal, built-in JSON serialization:</p>\n\n<pre><code>var serialized = JSON.stringify(myvar);\nvar reconstituted = JSON.parse(serialized);\n</code></pre>\n\n<p>Done, <code>reconstituted</code> is a normal object again.</p>\n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-05T16:02:14.720",
"Id": "31420",
"Score": "0",
"Tags": [
"javascript",
"jquery"
],
"Title": "Serialize name/value pairs"
} | 31420 |
<p>I have two different ways of populating a <code>List</code> with querying another <code>List</code>. They are:</p>
<pre><code>var list = _surveyList.Where(x => x.Date == selectedDate).Select(s => s.Joint).ToList();
</code></pre>
<p>And:</p>
<pre><code>var list = from s in _surveyList
where s.Date... | [] | [
{
"body": "<p>These aren't completely the same. The first will return a <code>List<T></code> and the second will return an <code>IEnumerable<T></code>.</p>\n\n<p>You would need to make this change in order for these to be equivalent.</p>\n\n<pre><code>var list = (from s in _surveyList\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-17T16:03:31.937",
"Id": "31431",
"Score": "1",
"Tags": [
"c#"
],
"Title": "Which of these two is better in terms of readability and function?"
} | 31431 |
<p>I am creating my models manually. I have five tables in my database as follows:</p>
<ol>
<li><code>Members</code></li>
<li><code>MemberTypeMasters</code></li>
<li><code>Payments</code></li>
<li><code>Relationships</code></li>
<li><code>StatusMasters</code></li>
</ol>
<p>My database looks like this:</p>
<p><img sr... | [] | [
{
"body": "<p>The above classes are used by entity framework for persistance, don't confuse these with the Models in MVC. While its possible to use them directly in MVC, its considered bad practise to so tightly couple your presentation layer to your persistance layer.</p>\n\n<p>Look at tools like AutoMapper th... | {
"AcceptedAnswerId": "32225",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-17T16:05:27.020",
"Id": "31432",
"Score": "1",
"Tags": [
"c#",
"entity-framework",
"asp.net-mvc-4"
],
"Title": "Creating models manually in MVC"
} | 31432 |
<p>This is a typical bouncing ball program. I'm looking to improve and perhaps add to the program. For example, is it possible to be able to click on a ball and have it pause? </p>
<pre><code>import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.ev... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-17T18:10:12.813",
"Id": "50093",
"Score": "4",
"body": "“For example, is it possible to be able to click on a ball and have it pause?” This site is about reviewing and improving your code, but it's not here to write your code for you, ... | [
{
"body": "<p>when I was looking through your code I noticed that you have some Variables that you defined Globally</p>\n\n<pre><code>int x = random(480);\nint y = random(480);\nint speedX = random(30);\nint speedY = random(30);\nint radius = random(20);\nint red = random(255);\nint green = random(255);\nint bl... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-17T16:20:18.027",
"Id": "31434",
"Score": "1",
"Tags": [
"java",
"multithreading"
],
"Title": "Bouncing ball program"
} | 31434 |
<p>I have written Java code that finds the frequency of the occurrence of a word in a sentence. It is working fine. The only thing I want to do is to optimize this code.</p>
<pre><code>String str = "I am a Boy I am a";
String[] splitStr = str.split(" ");
int count = 0;
List<String> list... | [] | [
{
"body": "<p>You can simplify your code to a great extent by using a <code>Map<String, Integer></code> instead of <code>List<String></code>. The map would store the mapping from each word to it's count in the array. </p>\n\n<p>You can modify your code like so:</p>\n\n<pre><code>String str = \"I am ... | {
"AcceptedAnswerId": "31441",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-17T17:40:17.820",
"Id": "31440",
"Score": "6",
"Tags": [
"java",
"optimization",
"strings"
],
"Title": "Occurrence of a word in a sentence"
} | 31440 |
<p>I've just written my first angularjs directive, and I was hoping to get some feedback. I already have two doubts myself.</p>
<ul>
<li>Why is it that I must use <code>tElement.append()</code> to append the canvas element? <code>tElement.html()</code> doesn't work, at all. That just returns <code>[[object HTMLCanvasE... | [] | [
{
"body": "<p>Angular includes a tiny subset of jQuery called <code>jqLite</code> which is what you get with <code>angular.element</code>. The <code>html()</code> <a href=\"https://github.com/angular/angular.js/blob/v1.2.0-rc.3/src/jqLite.js#L523\" rel=\"nofollow\">method</a> on it specifically only accepts a ... | {
"AcceptedAnswerId": "33418",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-17T19:08:10.420",
"Id": "31444",
"Score": "3",
"Tags": [
"javascript",
"angular.js"
],
"Title": "First angularjs directive"
} | 31444 |
<p>I'm new to Go, and as a learning project I've been implementing RC4, attempting to follow pseudo-code in the <a href="http://en.wikipedia.org/wiki/RC4" rel="nofollow">Wikipedia</a> <a href="http://web.archive.org/web/20080404222417/http://cypherpunks.venona.com/date/1994/09/msg00304.html" rel="nofollow">links</a> (a... | [] | [
{
"body": "<p>Here is a simple translation of the Wikipedia RC4 key-scheduling algorithm (KSA) and pseudo-random generation algorithm (PRGA) into Go.</p>\n\n<pre><code>package main\n\nimport \"fmt\"\n\n// Key-scheduling algorithm (KSA)\nfunc ksa(key []byte) []byte {\n s := make([]byte, 256)\n for i := ran... | {
"AcceptedAnswerId": "31683",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-17T21:47:17.420",
"Id": "31446",
"Score": "3",
"Tags": [
"go",
"cryptography"
],
"Title": "RC4 implementation in Go"
} | 31446 |
<p>I am updating some old reports that are using <code>mysql_</code> statements and trying to use the MySQL PDO stuff. I was told that PDO is far better since I was running into runtime issues with some of my reports. My old report took 91 seconds to run, and my PDO version takes 106 seconds. While 15 seconds may no... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T02:19:23.217",
"Id": "50125",
"Score": "0",
"body": "Fixed my non-working $cart_total by using fetch vs fetchALL (not sure why I had fetchAll)."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T08:56:29... | [
{
"body": "<p>If I were you, I would try to add some sort of index to your MySQL database for this fields:</p>\n\n<pre><code>cb.customers_basket_date_added\ncb.customers_id\n</code></pre>\n\n<p>when this is done I would make changes your SQL, something similar to this:</p>\n\n<pre><code>SELECT DISTINCT \n cb... | {
"AcceptedAnswerId": "31456",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-17T23:46:53.167",
"Id": "31449",
"Score": "1",
"Tags": [
"php",
"mysql",
"pdo"
],
"Title": "Optimize PHP and MySQL with PDO"
} | 31449 |
<p>This draws scanline of the image to <code>System.Drawing.Graphics</code>. It's quite simple and it's optimized in order to merge neigbour samples with the same color into single rectangle (instead of drawing sample-by-sample in 1x1 rectangles).</p>
<p>I don't like the duplication of this code inside and outside the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T02:43:17.160",
"Id": "50128",
"Score": "0",
"body": "My first thought is to pull out updateAlpha and your FillRectangle methods into a method with a single parameter that would replace (i|glyphBitmap.Width) Then you could just call ... | [
{
"body": "<p>First off I have to say I found this code very hard to understand. It took me quite some time to finally understand what this code actually does.</p>\n\n<p>First off the function takes 6 arguments. That's way too many. Clearly the positionX and positionY should be combined into one Point object.</... | {
"AcceptedAnswerId": "31473",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T00:18:27.800",
"Id": "31450",
"Score": "6",
"Tags": [
"c#",
"image"
],
"Title": "Drawing scanline of an image"
} | 31450 |
<p>I'm developing a small craps game in C++, and my C++ skills are a bit rusty. I really need someone to review my code to ensure that I have correctly implemented the game according to the rules. </p>
<p><strong>Game rules:</strong></p>
<blockquote>
<ol>
<li>The player or shooter rolls a pair of standard dice
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T14:13:15.953",
"Id": "50172",
"Score": "2",
"body": "The shooter loses his turn if a 7 is rolled after there is a point."
}
] | [
{
"body": "<ul>\n<li><p><a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\">Try not to use <code>using namespace std</code></a>.</p></li>\n<li><p>The parameters in <code>main()</code> are only necessary if you're executing from the command line.</p></li>\n<... | {
"AcceptedAnswerId": "31452",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T04:54:46.500",
"Id": "31451",
"Score": "11",
"Tags": [
"c++",
"algorithm",
"game",
"random",
"dice"
],
"Title": "Craps game rules and code"
} | 31451 |
<p><code>get_item_count</code> calls to an API and gets a count. There are several pages to get this count from until there are no more results.</p>
<p>How do I improve this code to remove all of the extra variables and make it easier to read?</p>
<pre><code>final_count = 0
page = 1
final_count = individual_count = ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T05:54:37.423",
"Id": "50133",
"Score": "2",
"body": "Do you want get_item_count() to be executed only once, that is, for page = 1 ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T07:36:01.317",
"... | [
{
"body": "<p>Cryptic but cool way with ruby 2.0 lazy enumerators :</p>\n\n<pre><code>(2..Float::INFINITY).lazy\n .map {|page| get_items(config, page) }\n .take_while {|count| count > 20 }\n .reduce( get_item_count(config, 1), :+ )\n# => returns final count\n</code></pre>\n\n<p>if @toto2 is right and y... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T05:36:02.280",
"Id": "31453",
"Score": "6",
"Tags": [
"ruby"
],
"Title": "Get individual item count"
} | 31453 |
<p>Please help me optimize this bubble sort code. It's working fine otherwise.</p>
<pre><code>int[] randomIntegers = {2,3,1,1,4,5,8,-2,0};
for(int i=0;i<randomIntegers.length;i++){
for(int j=i;j<(randomIntegers.length-1);j++){
if(randomIntegers[i]>randomIntegers[j+1]){
randomIntegers[i] += random... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T12:52:57.563",
"Id": "50162",
"Score": "0",
"body": "As pointed out by @Guffa, this is not bubble sort (see [wikipedia](http://en.wikipedia.org/wiki/Bubble_sort), or Guffa's answer). Also it is quite odd to swap the elements by add... | [
{
"body": "<p>If you need to optimize bubble sort, you're doing it wrong. It's not really worth optimizing something that's inherently slow. You should just use a better sorting algorithm.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T08:59:38.19... | {
"AcceptedAnswerId": "31463",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-09-18T07:42:37.853",
"Id": "31460",
"Score": "1",
"Tags": [
"java",
"performance",
"sorting"
],
"Title": "Optimizing bubble sort code"
} | 31460 |
<p>What the code does is convert an image to a bitmap without having to create 3 arrays to make the conversion. It basically uses 1/3rd of the memory that it would normally use.</p>
<p>I'm trying to refactor this method to make it shorter, less complex and more readable. So far, I've been unsuccessful in the 4 attempt... | [] | [
{
"body": "<p>Half of the code deals with reading a file into a byte array, which is a very generic operation. Split the code into two functions, one accepting a file and another accepting a byte array. The former can call the latter.</p>\n\n<pre><code>private static Bitmap decodeBitmap(File file, boolean pre... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T07:44:53.187",
"Id": "31462",
"Score": "1",
"Tags": [
"java",
"converting",
"image"
],
"Title": "Converting an image to a bitmap"
} | 31462 |
<p>I'm looking for remarks on pretty much anything. This has been my first project that's meant for use by others and I'd like to have it as clean as possible. I will post the main source code here but because of the size you might prefer reading it on <a href="https://github.com/Vannevelj/TVDBSharp">Github</a> instead... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T18:55:37.690",
"Id": "50227",
"Score": "3",
"body": "IMO there's way too much comments, it really slows down the reading. Things like builders don't need comments or even your unit tests. They should be straightforward enough so the... | [
{
"body": "<p>Some minor stuff for now:</p>\n\n<ol>\n<li><p>Any specific reason to use <code>StringBuilder</code> rather than <code>string.Format()</code>? I personally find</p>\n\n<pre><code>string.Format(\"http://thetvdb.com/api/{0}/series/{1}/all/\", ApiKey, showID)\n</code></pre>\n\n<p>easier to read than</... | {
"AcceptedAnswerId": "36006",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T10:17:09.227",
"Id": "31468",
"Score": "6",
"Tags": [
"c#",
"unit-testing",
"xml",
"api"
],
"Title": "API wrapper for translating XML requests and responses into objects"
} | 31468 |
<p>I have written this code to find second largest element in an array of random integers. If it needs to be optimized, then do comment on it. First of all I'm populating all the elements into the list which does not have any repeating value, then sorting, then in <code>list.size()-2</code> I have second largest ele... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T20:40:13.507",
"Id": "50231",
"Score": "1",
"body": "Just for your information, if you want to generalise this, you can have a look at http://en.wikipedia.org/wiki/Selection_algorithm ."
}
] | [
{
"body": "<p>After sorting </p>\n\n<pre><code>int highestElementIndex = list.indexOf(Collections.max(list)); \nSystem.out.println(\"Second highest element is : \" + list.get(highestElementIndex - 1));\n</code></pre>\n\n<p>Without sorting I think your code is all right.</p>\n",
"comments": [
{
... | {
"AcceptedAnswerId": "31506",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T10:58:39.543",
"Id": "31470",
"Score": "3",
"Tags": [
"java",
"optimization",
"array"
],
"Title": "Find the second-largest number in an array of elements"
} | 31470 |
<p>At first it was like this:</p>
<pre><code>public abstract class TicTacToeViewAbstract implements TicTacToeView {
private final List<OnCellClickListener> onCellClickListeners;
private boolean movesBlocked;
private boolean gameFinished;
private TicTacToeModel model;
protected TicTacToeViewA... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T12:48:47.750",
"Id": "50161",
"Score": "2",
"body": "I'm a bit puzzled why you would need to create a view based on a view. Since you pass toRestore in the constructor, I don't see why you need to also pass the model since I would ... | [
{
"body": "<p>I would vote for the second, i.e. the one with a basic constructor called by others.</p>\n\n<p>But what is important is how to decide. The criteria that come to mind are:</p>\n\n<ul>\n<li>what if you should refactor later?</li>\n<li>which is the most clear when using this class?</li>\n</ul>\n\n<p>... | {
"AcceptedAnswerId": "31480",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T11:24:42.573",
"Id": "31471",
"Score": "1",
"Tags": [
"java",
"comparative-review",
"tic-tac-toe"
],
"Title": "Multiple independent or layered constructors for TicTacToe?"
} | 31471 |
<p>I ran a sonar analysis on my code and it told me the cyclomatic complexity is too high (sonar's limit is ten branches).</p>
<p>Here is my code:</p>
<pre><code>public void myMethod(){
try{
// do something
catch(SomeException e){
throw new WrappingException("issue when doing something " + e.getMessage(), e... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T13:28:30.283",
"Id": "50166",
"Score": "3",
"body": "If the Exceptions that you are interested in catching share common super classes (but not as far up the ancestor stack as `Exception`) then you **could** catch the super class rat... | [
{
"body": "<p>As JohnMark13 stated in the comments above, if the exceptions you want to catch share a common supertype (possibly besides the basic <code>Exception</code> class), then you could catch the supertype instead of all the subtypes. If you have created the <code>SomeException</code> and <code>AnotherEx... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T13:18:12.020",
"Id": "31477",
"Score": "7",
"Tags": [
"java",
"exception-handling"
],
"Title": "Reducing cyclomatic complexity"
} | 31477 |
<p>Originally I submitted a question here: <a href="https://codereview.stackexchange.com/questions/29807/better-approach-to-using-the-c-serialport-class">SerialPort class for a library</a></p>
<p>I cleaned up my code a bit and rewrote a few things. I've had a number of problems along the way and I've still not gotten ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T15:38:08.863",
"Id": "50209",
"Score": "1",
"body": "“I want to return the entire exception” You really shouldn't do that. If you can't handle an exception, let it bubble up. In general `catch (Exception ex)` or just `catch` (with n... | [
{
"body": "<p>Not sure if still relevant, but here you go:</p>\n\n<ol>\n<li><p>Consider refactoring <code>if (this.disposed) { }</code> into a method like <code>ThrowIfDisposed()</code>. If you ever want to change the dispose method or add logging or whatnot then you have to change only one place. Code duplicat... | {
"AcceptedAnswerId": null,
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T14:16:49.923",
"Id": "31483",
"Score": "7",
"Tags": [
"c#",
"serial-port"
],
"Title": "SerialPort C# Class"
} | 31483 |
<p>I wrote this small test, i would love to know if it's possible to achieve the same result in a more "efficient" way, before any moderator closes this question, it's not subjective because my defention of efficient here means less lines of code, and less memory usage.</p>
<p>Here is a Demo :
<a href="http://jsfiddl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-04T05:36:28.570",
"Id": "50175",
"Score": "0",
"body": "Is there even a question here?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-04T05:38:30.097",
"Id": "50176",
"Score": "0",
"body": "@re... | [
{
"body": "<p>As you define efficient to be \"less lines of code\", here it is:</p>\n\n<pre><code>function moveIt(){\n var textToInsert = '';\n var textLength = 10;\n\n for (var i = 0; i <= textLength; i++)\n textToInsert+= (i==position)?'[-]':'-';\n (position==textLength)?position=0:posit... | {
"AcceptedAnswerId": "31486",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-04T05:30:49.530",
"Id": "31485",
"Score": "0",
"Tags": [
"javascript"
],
"Title": "Efficient text scroller"
} | 31485 |
<p>A serial port is a physical interface through which data is transferred (uni- or bidirectionally) one bit at a time. Largely superseded in the consumer market by USB, serial connections are still commonly used in many other specialist applications. Typical applications include scientific/medical instruments, industr... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T15:06:50.733",
"Id": "31497",
"Score": "0",
"Tags": null,
"Title": null
} | 31497 |
A serial port is a physical interface through which data is transferred (uni- or bidirectionally) one bit at a time. Largely superseded in the consumer market by USB, serial connections are still commonly used in many other specialist applications. Typical applications include scientific/medical instruments, industrial... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T15:06:50.733",
"Id": "31498",
"Score": "0",
"Tags": null,
"Title": null
} | 31498 |
<p>I'm using Twitter Bootstrap's navbar. While testing different screen resolutions, I noticed that on lower resolutions, sometimes the submenu would get cut off by the right side of the page.</p>
<p>In the code below, when a dropdown is opened, I'm getting the width of the dropdown menu and dropdown submenu, adding t... | [] | [
{
"body": "<p>A couple things you can do:</p>\n\n<p>Use <code>.on()</code> to save a few function calls:</p>\n\n<pre><code>$('.dropdown-toggle').on('click', function() { ... });\n</code></pre>\n\n<p>You can also actually use the cache you save called <code>dropdownList</code>:</p>\n\n<pre><code>var subDropdown ... | {
"AcceptedAnswerId": "31555",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T19:13:24.580",
"Id": "31501",
"Score": "7",
"Tags": [
"javascript",
"jquery"
],
"Title": "Adjust bootstrap dropdown menu based on page width"
} | 31501 |
<p>I am using the DatabaseHelper class to execute SQL statements e.g. ExecuteDataReader, ExecuteDataTable etc. The signature for ExecuteReader is:</p>
<pre class="lang-vb prettyprint-override"><code>Public Overloads Shared Function ExecuteReader(ByVal connectionString As String, _
... | [] | [
{
"body": "<h3>Potential issues</h3>\n\n<ul>\n<li><p><code>intDatabaseType</code> should be promoted to an instance variable instead of being supplied in every call to <code>AssignParameterValues</code> - the way you have it, <strong>you can build an 5-items array with 2 parameters for SQL Server and 3 paramete... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T19:44:09.920",
"Id": "31502",
"Score": "3",
"Tags": [
"design-patterns",
"vb.net"
],
"Title": "Encapsulation with a dbParameter class"
} | 31502 |
<p>In C# I can use </p>
<pre><code>DateTime dt = DateTime.Now.Date;
</code></pre>
<p>This will give the current date, without the TimeSpan value (<strong><em>'00:00:00'</em></strong>). In JavaScript I did this:</p>
<pre><code>var dt = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate());
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T20:47:06.377",
"Id": "50232",
"Score": "1",
"body": "That is ugly, why would you call `new Date(...)` 4 times?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T21:04:39.397",
"Id": "50233",
"Sc... | [
{
"body": "<p><a href=\"http://www.w3schools.com/js/js_obj_date.asp\" rel=\"nofollow noreferrer\">JavaScript Date Object</a></p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString\" rel=\"nofollow noreferrer\">Mozilla Documentation on <code>toL... | {
"AcceptedAnswerId": "31516",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T19:59:18.950",
"Id": "31503",
"Score": "4",
"Tags": [
"javascript",
"datetime"
],
"Title": "How could I do DateTime.Now.Date (from C#) in JavaScript?"
} | 31503 |
<h2>Abstract</h2>
<p>I'd like to have advice on how to :</p>
<ul>
<li>implement <strong>methods that rely on a state</strong>, </li>
<li>when the <strong>instance is mutable and may be in an inconsistent state</strong>, </li>
<li>in such a way that the methods <strong>either silently fail or return nil</strong>,</li>... | [] | [
{
"body": "<p>Looks like your class has two separate responsibilities:</p>\n\n<ul>\n<li>validating a set of fields (fields can be in an inconsistent state)</li>\n<li>performing calculations on these fields (fields must be valid)</li>\n</ul>\n\n<p>Therefore I would split it up into two classes:</p>\n\n<ul>\n<li>... | {
"AcceptedAnswerId": "31530",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T20:17:09.193",
"Id": "31505",
"Score": "0",
"Tags": [
"ruby",
"state",
"active-record"
],
"Title": "Ruby OO design : how to handle inconsistent state in a mutable class?"
} | 31505 |
<p>I recently decided to make a <code>LinkedList</code> and binary search tree using JavaScript. I wanted to reach out to a wider audience and see how I did, and where could I improve.</p>
<p><a href="https://gist.github.com/TheIronDeveloper/6604756" rel="nofollow"><strong>Linked List:</strong></a></p>
<pre><code>var... | [] | [
{
"body": "<p>Most of your code looks like textbook code.</p>\n\n<p>Your <code>size</code> function shouldn't have to take a second argument.</p>\n\n<pre><code>LinkedList.prototype.size = function(currentNode /* optional */) {\n // var currentNode, shadowing the currentNode param, is weird\n var node = cu... | {
"AcceptedAnswerId": "31522",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-18T23:16:00.187",
"Id": "31513",
"Score": "9",
"Tags": [
"javascript",
"linked-list",
"tree"
],
"Title": "LinkedList and binary search tree in JavaScript"
} | 31513 |
<p>I'm pretty new to coding and I want to get an opinion on my coding. I am learning Python and I made a really simple heads and tails guessing game.</p>
<pre><code>import random
import time
import easygui
import sys
while True:
rand = random.choice(["Heads", "Tails"])
firstguess = raw_input("Guess Heads or Ta... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-05-06T08:12:45.827",
"Id": "238721",
"Score": "0",
"body": "You are doing fine. My first program ever was a guessing game like this. Keep it up."
}
] | [
{
"body": "<p>Why are you mixing <code>raw_input()</code> with <code>easygui</code>? That's a suboptimal user experience.</p>\n\n<p><code>sys.exit(0)</code> at the end is superfluous, but harmless.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-09T23:33:12.043",
"Id": "31514",
"Score": "5",
"Tags": [
"python",
"beginner",
"game",
"python-2.x"
],
"Title": "\"Heads or Tails?\" guessing game in Python"
} | 31514 |
<p>I am new to the OOP world I have been reading as much as I can about it and have never been more confused. I understand that its great for organizing code and making it more maintainable, etc. I have written some OOP code but I am unsure if its proper, it works fine though.</p>
<p>I am confused about public private... | [] | [
{
"body": "<p>What you're really doing here, is using a class as a container for bunch of functions. It's a perfectly fine thing to do, but it's not really object-oriented programming. Even the name of your class <code>userFunctions</code> confirms it.</p>\n\n<p>An object should be something that binds together... | {
"AcceptedAnswerId": "31531",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T02:03:06.807",
"Id": "31520",
"Score": "1",
"Tags": [
"php",
"object-oriented"
],
"Title": "Proper usage of OOP PHP"
} | 31520 |
<p>According to shootout.alioth.debian.org, Racket is not much slower than C#, at least in the same order of magnitude due to its JIT compiler.</p>
<p>However, I'm seeing at least <strong>two degrees of magnitude</strong> slowdown in my implementation of the RC4 cipher in C# vs. Racket. </p>
<p>(Disclaimer: I am not ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T02:48:45.217",
"Id": "50262",
"Score": "3",
"body": "As per the FAQ, please embed the code you'd like to have reviewed. You may keep the link as well."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T... | [
{
"body": "<p>I was looking at the C# code in your link and found something that made me stop for a minute\nthis may be a dumb question, I couldn't put it into a comment</p>\n\n<pre><code>while(true)\n {\n int ky = 0;\n restart:\n if (ky % 256 == 0) \n {\n Console.Error.WriteLine(\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T02:27:49.713",
"Id": "31521",
"Score": "4",
"Tags": [
"c#",
"scheme",
"racket"
],
"Title": "Why is this RC4 code in Racket so slow?"
} | 31521 |
<p>I am working on an HTML document to which I need to add certain classes to some elements. In the following code, I am adding class <code>img-responsive</code>.</p>
<pre><code>def add_img_class1(img_tag):
try:
img_tag['class'] = img_tag['class']+' img-responsive'
except KeyError:
img_tag['... | [] | [
{
"body": "<p>The second option is better, because the possible error is explicit. However, in lots of case in Python, you should follow <a href=\"http://docs.python.org/2/glossary.html#term-eafp\" rel=\"noreferrer\">EAFP</a> and go for the <code>try</code> statement. However, we can do better.</p>\n\n<h2>get(v... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T07:01:33.673",
"Id": "31523",
"Score": "12",
"Tags": [
"python",
"html",
"html5",
"beautifulsoup"
],
"Title": "Adding a new class to HTML tag and writing it back with Beautifu... | 31523 |
<p>Each row in the table has a delete and duplicate operation. The input values are passed to the new section based on the <code>id</code>s of each input on the row which changes dynamically based on the user's actions. The function for recreating the id's of the rows is not so good. I am not to sure how change it.</p>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T12:22:23.353",
"Id": "50276",
"Score": "0",
"body": "Can you create a fiddle and also try to explain precisely what you are trying to do? Sorry, I couldn't understand your question very well."
}
] | [
{
"body": "<p>Probably the most important thing you should be focusing on is the idea that ID's are unique. There can't be more than one element with the same ID. If you're trying to select several elements, jQuery will stop looking as soon as it hits the first element that mathces the ID. You should use classe... | {
"AcceptedAnswerId": "31554",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T08:27:42.993",
"Id": "31525",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Table recreation function"
} | 31525 |
<p>Here's an absolutely essential piece of C++ lore, a stack allocator, that will allow you to, say, allocate strings and vectors on the stack. There are 2 stack allocators I know of, <a href="https://stackoverflow.com/questions/783944/how-do-i-allocate-a-stdstring-on-the-stack-using-glibcs-string-implementation">here<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T17:11:54.173",
"Id": "50309",
"Score": "0",
"body": "Why do you use global namespacing operator `::` in example usage?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T18:56:40.357",
"Id": "50332",... | [
{
"body": "<h2>Fixes required for a conforming Standard Library</h2>\n\n<p>There is one big issue that will make custom allocators fragile to work with: incomplete C++11 library support. Since C++11, containers are required to go through <code>std::allocator_traits<Allocator></code> to access <code>constr... | {
"AcceptedAnswerId": null,
"CommentCount": "16",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T09:10:25.623",
"Id": "31528",
"Score": "10",
"Tags": [
"c++",
"c++11",
"memory-management",
"stack"
],
"Title": "A working stack allocator"
} | 31528 |
<p><strong>NOTE</strong>: I'm not perfectly sure of some of the parsed data, so any corrections are more than welcome.</p>
<p>Parser (cpuid.c):</p>
<pre><code>#include <stdint.h>
#include <string.h>
#include "cpuid.h"
enum {
CPU_PROC_BRAND_STRING_INTERNAL0 = 0x80000003,
CPU_PROC_BRAND_ST... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-26T17:21:54.787",
"Id": "50801",
"Score": "1",
"body": "\"GeniuneTMx86\" is probably a typo -> \"GenuineTMx86\""
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-24T19:39:27.787",
"Id": "58794",
"Scor... | [
{
"body": "<p>Here are some comments on your code.</p>\n\n<p>I think your types <code>cpufeature_t</code> and <code>cpuextfeature_t</code> are probably\nunnecessary as they are just <code>uint32_t</code>. They might be better expressed as\nenums.</p>\n\n<p>Functions that are purely for local use (ie. not part ... | {
"AcceptedAnswerId": "36100",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T11:45:18.370",
"Id": "31532",
"Score": "5",
"Tags": [
"c",
"parsing",
"linux",
"assembly"
],
"Title": "Is this CPUID parser ideal for any usage?"
} | 31532 |
<p>I need suggestions.</p>
<pre><code>var textarea = document.getElementById("textarea"),
filename = prompt("Name this note:", "untitled");
if (filename == null) {
window.close();
} else if (filename == "") {
filename = "untitled";
};
document.title = filename + ".txt";
function Rename() { // Rename note... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T13:25:49.393",
"Id": "50279",
"Score": "0",
"body": "https://dl.dropboxusercontent.com/u/92126558/projects/ntpd/js/main.js is the link to the code btw (had to retrieve it from the page's source...)"
}
] | [
{
"body": "<h1>Usability</h1>\n\n<ul>\n<li>Horrible user experience. Nobody wants to see a modal prompt popping up right when opening a site.</li>\n<li><code>window.close()</code> when not entering something in that prompt. Not only do most browsers rightfully reject this unless it's a popup window, it's also a... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T13:01:06.167",
"Id": "31533",
"Score": "1",
"Tags": [
"javascript"
],
"Title": "text editing app"
} | 31533 |
<p>I'd like your thoughts on this basic implementation of MVC. The view outputs a form, and when the page is loaded, the controller checks for a form submission and then updates the model accordingly. Finally, the view outputs the form again, grabbing the new values from the model.</p>
<p>One problem with this is that... | [] | [
{
"body": "<h2>Templates</h2>\n\n<p>Your HTML code should be separated out into a template file. You should do your best to avoid mixing HTML into your PHP, as your HTML will inevitably grow, and your PHP will get messier as a result. </p>\n\n<h2>Post/Get/Redirect</h2>\n\n<p>The pattern you are looking for is <... | {
"AcceptedAnswerId": "31541",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T14:35:50.293",
"Id": "31538",
"Score": "3",
"Tags": [
"php",
"mvc"
],
"Title": "Basic PHP MVC setup for form submissions"
} | 31538 |
<p><strong>The background</strong></p>
<p>Two beginners without access to an experienced mentor write an ASP .NET MVC application, mostly simple CRUD, using Linq to SQL for the data access layer. Beginner number 1 writes the model part. I, beginner number 2, start writing controllers and views. When using the web and ... | [] | [
{
"body": "<p>First of all, your code doesn't compile, you have a poor lonely extra closing bracket in your <code>Update</code> method.</p>\n\n<p>Next, your <code>Update</code> method shouldn't <code>Insert</code> if <code>Update</code> doesn't work. If the entity doesn't exist, you should return false. Otherwi... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T16:41:48.227",
"Id": "31543",
"Score": "8",
"Tags": [
"c#",
"beginner",
"linq-to-sql"
],
"Title": "Does this unusual data access pattern create any problems?"
} | 31543 |
<p>I've been trying to take image pixel data and write it out into printer code and my results are rather slow.</p>
<p>Here is a simplified version of what I have so far (image is a PIL Image object of 1200 x 1800 pixels):</p>
<pre><code># ~36 seconds on beaglebone
f.write(pclhead)
pix = image.getdata()
for y in xran... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T17:06:01.780",
"Id": "50305",
"Score": "0",
"body": "instead of all that string manipulation why not just write it out."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T17:56:51.423",
"Id": "50322"... | [
{
"body": "<p>Start with storing the <code>'\\xff' * 72</code> string as a constant; Python strings are immutable, recreating that string each time is not necessary.</p>\n\n<p>Next, use a list to collect all strings, then join at the end; this is cheaper than constant string concatenation.</p>\n\n<p>Last, avoid... | {
"AcceptedAnswerId": "31775",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T17:01:47.077",
"Id": "31545",
"Score": "7",
"Tags": [
"python",
"performance",
"strings",
"image",
"lookup"
],
"Title": "Writing image pixel data to printer code"
} | 31545 |
<pre><code>/**
* Upload has a limit of 10 mb
* @param string $dir $_SERVER['DOCUMENT_ROOT']
* @param string $path Path do you want to upload the file
* @param string $filetype jpg|jpeg|gif|png|doc|docx|txt|rtf|pdf|xls|xlsx|ppt|pptx
* @param array $_FILES An associative array of items uploaded to the current script... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T17:50:44.267",
"Id": "50318",
"Score": "0",
"body": "You should post this to StackOverflow instead."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T18:00:44.167",
"Id": "50324",
"Score": "1",
... | [
{
"body": "<p>I have two minor comments.</p>\n\n<p>First, I prefer having my variables defined in all branches, to avoid the <code>PHP Notice: Undefined variable:...</code> error in logs. So, an initialization</p>\n\n<pre><code>$isMove = false;\n</code></pre>\n\n<p>would be nice. Btw, maybe <code>$isMoved</cod... | {
"AcceptedAnswerId": "31579",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T17:29:24.420",
"Id": "31550",
"Score": "1",
"Tags": [
"php"
],
"Title": "how can I improve the check name file part"
} | 31550 |
<p>The <strong>Game of Life</strong>, also known simply as <strong>Life</strong>, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.</p>
<p>The "game" is a zero-player game, meaning that its evolution is determined by its initial state, requiring no further input. One interacts wi... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T18:13:51.293",
"Id": "31552",
"Score": "0",
"Tags": null,
"Title": null
} | 31552 |
A cellular automaton simulation following rules devised by mathematician John Conway. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T18:13:51.293",
"Id": "31553",
"Score": "0",
"Tags": null,
"Title": null
} | 31553 |
<p>Review this code, which should return <code>true</code> if a port is in use or <code>false</code> if the port is not in use.</p>
<p>Clarification: "In use" means that the port is already open (and used by another application). I'm trying to find a port number between (49152 and 65535) to open that is available.</p>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-20T11:06:12.617",
"Id": "50399",
"Score": "2",
"body": "Catching `Exception` is not a good practice try to catch the known subclass which you expect..."
}
] | [
{
"body": "<p>The code can be simplified somewhat:</p>\n\n<pre><code>private boolean isPortInUse(String host, int port) {\n // Assume no connection is possible.\n boolean result = false;\n\n try {\n (new Socket(host, port)).close();\n result = true;\n }\n catch(SocketException e) {\n // Could not ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T19:18:29.837",
"Id": "31557",
"Score": "14",
"Tags": [
"java",
"error-handling",
"socket"
],
"Title": "Checking if a port is in use"
} | 31557 |
<p>The objective is to increment the page visits by one. The user should not be able to do this by refreshing. The number of visits can be incremented only if the user's last visit was later than 10 minutes or none at all. This should work regardless of multiple users behind the same IP or router.</p>
<p>Does this ne... | [] | [
{
"body": "<p>My 2 cents:</p>\n\n<ul>\n<li><p>I would not use an array of objects to represent the pages, I would use an object where each <code>$scope.ad.id</code> is a property and where the value is the last time visited. This would take out your loop and dupe management</p></li>\n<li><p>Any enterprising ind... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T20:37:15.663",
"Id": "31560",
"Score": "4",
"Tags": [
"javascript",
"angular.js"
],
"Title": "\"Stack Exchange page visits\" alike implementation"
} | 31560 |
<p>I have this jQuery click handler function that has three jobs:</p>
<ol>
<li>Set the time interval for the refresh rate</li>
<li>Change the color on the clicked refresh rate selection</li>
<li>Callback the tablesort functions to resort the newly loaded data</li>
</ol>
<p>I'd like to pull out the separate functional... | [] | [
{
"body": "<p>Add the <code>refresh-rates</code> map to <code>#refresh-buttons</code> element ( use <code>.data()</code> function ), optimize amount of <code>$()</code> calls:</p>\n\n<pre><code>$(document).ready(function() {\n var refresh_btns$;\n\n // you can store id map where ever you prefer to\n //... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T21:31:37.373",
"Id": "31563",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"sorting",
"user-interface"
],
"Title": "Extracting Javascript functions"
} | 31563 |
<p>I don't intend on implementing this into an application yet as I'm going to test it first. As such, it doesn't do much beyond rolling. It also overloads some "typical" operators such as <code>==</code> and <code>!=</code>.</p>
<p>Most of all, I'm still very unsure about my random number generator. I've read abou... | [] | [
{
"body": "<p>Just based on the code, and in no particular order:</p>\n\n<ul>\n<li>Bikeshedding: as <code>Dice</code> represents a single die, I would call it such.</li>\n<li>You're passing <code>Dice</code> by reference to const everywhere. In your current design it is just an <code>int</code>, and I don't se... | {
"AcceptedAnswerId": "31714",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-20T05:35:10.053",
"Id": "31571",
"Score": "7",
"Tags": [
"c++",
"c++11",
"random",
"dice"
],
"Title": "Random number generation in Dice class"
} | 31571 |
<p>I have one programming question:</p>
<blockquote>
<p>The sine and cosine of \$x\$ can be computed as follows:</p>
<blockquote>
<p>\$\sin(x) = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \frac{x^9}{9!} - \dots\$</p>
<p>\$\cos(x) = 1 - \frac{x^2}{2!} + \frac{x^4}{4!} - \frac{x^6}{6!} + ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-20T10:00:41.217",
"Id": "50382",
"Score": "2",
"body": "What a lot of languages, looks a lot like Java to me. Where is the class Trigonometric_Ratios? Does this compile? How do the results look? Homework? I wouldn't worry too much abou... | [
{
"body": "<pre><code>cos(X) = sum (Cn) where Cn=x^2n/2n!\n\nsin(X) = sum (Sn) where Sn=x^(2+1)n/(2n+1)!\n</code></pre>\n\n<p>So, <code>Sn=Cn*x/(2n+1)</code></p>\n\n<pre><code>Cn=S(n-1)*x/2n\n</code></pre>\n\n<p>Start from <code>C0=1</code> and compute <code>S0=C0*x, C1=S0*x/2, S1=C1*x/3</code> etc.</p>\n",
... | {
"AcceptedAnswerId": null,
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-20T09:51:25.437",
"Id": "31577",
"Score": "3",
"Tags": [
"java",
"performance",
"algorithm",
"homework",
"numerical-methods"
],
"Title": "Approximating sines and cosines usi... | 31577 |
<p>I've played with jQuery for some time now but have never written my own plugin.</p>
<p>A question was asked: "can I blur an image using jQuery?" and I thought this to be a decent candidate to play with.</p>
<p>Here's my code so far:</p>
<pre><code>(function ($) {
$.fn.blurStuff = function (options) {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T18:18:19.533",
"Id": "72345",
"Score": "0",
"body": "http://coding.smashingmagazine.com/2011/10/11/essential-jquery-plugin-patterns/ Look at using native css blur if the browser supports it. http://caniuse.com/#feat=css-filters And ... | [
{
"body": "<p>In the code I only would modify the variable declarations:</p>\n\n<pre><code>var defaults = {blurRadius:2, deblurOnHover:false},\nsettings = $.extend(defaults, options),\nimg, blurContainers, clone;\n</code></pre>\n\n<p>Personal preference, but you can read a discusion about it <a href=\"https://s... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-20T10:26:39.153",
"Id": "31578",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"plugin"
],
"Title": "My first jQuery plugin - blurStuff()"
} | 31578 |
<p>I have the following oops code, I am also monitoring user activity to see if it is idle for more than 5 seconds. I am very new to oops, so just want to understand if there are better way to implement it.</p>
<pre><code>#!/usr/bin/python
import Tkinter
import time
class simpleapp_tk(Tkinter.Tk):
def __init__(s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-22T05:06:33.027",
"Id": "50487",
"Score": "0",
"body": "What is oops? Oops! Did you mean OOP? See also http://programmers.stackexchange.com/questions/92174/what-does-s-stands-for-in-oops"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>Tkinter is not just OOP, it's about <a href=\"http://en.wikipedia.org/wiki/Event-driven_programming\" rel=\"nofollow noreferrer\">http://en.wikipedia.org/wiki/Event-driven_programming</a> . The code you posted does not yet show enough to be judged, because it's too small and the application purpos... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-20T13:29:35.117",
"Id": "31582",
"Score": "4",
"Tags": [
"python",
"tkinter"
],
"Title": "Python Tkinter OOPS code optimization"
} | 31582 |
<p>This is a plugin I wrote a while ago and I'm trying to improve it. Is this the best practice for jQuery plugins? Should I use options for flexibility?</p>
<p>The initial aim was to replicate the syntax for <code>.fadeIn()</code> in jQuery.</p>
<p>Any pointers would be appreciated.</p>
<pre><code>/* AnimateCSS - C... | [] | [
{
"body": "<p>Awesome code,</p>\n\n<ul>\n<li>Well named variables, commented and easy tor read</li>\n<li>JsHint.com has nothing on this code</li>\n<li>Use <code>'use strict'</code></li>\n</ul>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"Cr... | {
"AcceptedAnswerId": "47786",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-20T14:28:45.293",
"Id": "31584",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"plugin"
],
"Title": "jQuery plugin best practice"
} | 31584 |
<p>The code takes in nodes with different start time as input and assigns the position such that they will not overlap. As I have coded with too many loops and conditions. Can anyone review the code and help me to make it efficient? Please do review the algorithm to assign positions to the rectangular blocks.</p>
<pre... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li><code>console.log()</code> <- Performance killer, at the very least call a custom function that you can uncomment</li>\n<li><code>//updated_pos_mat[j].push(nodes[temp_ival[0]].id);</code> <- Remove dead code for easier reading</li>\n<li><code>temp_arr.reduc... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-20T15:13:21.860",
"Id": "31585",
"Score": "3",
"Tags": [
"javascript",
"algorithm",
"svg",
"d3.js"
],
"Title": "Displaying overlapping blocks using d3.js"
} | 31585 |
<p>I wrote this partly as a learning exercise in TDD. Could I please have feedback on both how to improve the quality of the code and the completeness of the tests?</p>
<p>I used LinqPad as my IDE for this, the code has no external dependencies (the test framework is included).</p>
<pre><code>void Main()
{
var te... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-20T17:41:38.423",
"Id": "50419",
"Score": "0",
"body": "“I used LinqPad as my IDE for this” I don't think that's a good idea. LinqPad is great for small amounts of code, but I would never use it for anything this big. If you can't affo... | [
{
"body": "<p>Not sure I should be answering my own question, but having slept on it and reviewed the code my perspective has moved on.</p>\n\n<p>I've reviewed my use cases, and it turns out that I only need the three two-argument overloads, which I wrote last, and can ditch the four other, supposedly simpler, ... | {
"AcceptedAnswerId": "31630",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-20T15:49:05.977",
"Id": "31587",
"Score": "2",
"Tags": [
"c#",
"json",
"tdd"
],
"Title": "A C# class to check if one JSON tree (de-serialised as ExpandoObject / Array etc) contain... | 31587 |
<p>For the sake of knowledge, I wanted to convert a SQL query to a LINQ query expression. Here is the original SQL:</p>
<pre><code>SELECT CT.COURSE_NODE_ID AS CNID, CT.NODE_TEXT
FROM COURSE_RELATED_VERSIONS AS CRV INNER JOIN
COURSE_TREE AS CT ON CRV.COURSE_NODE_ID = CT.COURSE_NODE_ID
WHERE (CRV.COURSE_ID = ... | [] | [
{
"body": "<ol>\n<li>LINQ isn't as rigid about the order of clauses as SQL is (this applies to both syntaxes). This means that if you switch your <code>Join</code> around, you can put your <code>Where</code> before your <code>Join</code>.</li>\n<li>If you have <code>Select</code> right after <code>Join</code>, ... | {
"AcceptedAnswerId": "31595",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-20T17:12:36.307",
"Id": "31592",
"Score": "3",
"Tags": [
"c#",
"linq"
],
"Title": "Can this LINQ lambda expression be written any better?"
} | 31592 |
<pre><code>var _ = require("underscore");
var checkSettingsUndefined = function(settings){
if(_.isEmpty(settings)){
throw new Error("settings are empty");
}
}
var Class = function(settings){
checkSettingsUndefined(settings);
this.settings = settings;
}
Class.prototype.settings = function()... | [] | [
{
"body": "<p>The abstraction is good but the tight coupling is bad. The only real use case for <code>checkSettingsUndefined</code> is for your <code>Class</code> object.</p>\n\n<p>Here is an example of a more generic method, it just takes an array of validation objects that will be run on their associated cal... | {
"AcceptedAnswerId": "31602",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-20T17:35:42.760",
"Id": "31593",
"Score": "1",
"Tags": [
"javascript",
"object-oriented",
"classes",
"unit-testing",
"node.js"
],
"Title": "Throwing error if settings / ar... | 31593 |
<p>This is code from a grappling hook implementation. This is specifically code that, after a block is detected between two way points, it tries to find a path around.</p>
<p>This particular piece of the function considers the blocks that are in the way and decides which corners are appropriate to wrap around.</p>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-20T19:47:55.477",
"Id": "50431",
"Score": "0",
"body": "I must confess that I don't really understand the problem nor the drawing but my feeling is that you might want to have a look at http://en.wikipedia.org/wiki/Convex_hull_algorith... | [
{
"body": "<p>I can't follow your code at all, mainly because I don't understand your terminology. What'a a <code>GrapplingHookPathPoint</code>? <code>anchoredBlock</code>? <code>anchorPoint</code>? <code>problem</code>?</p>\n\n<p>Anyway, I'll describe how I would approach the problem instead.</p>\n\n<p>Let's... | {
"AcceptedAnswerId": "31645",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-20T18:56:06.063",
"Id": "31597",
"Score": "5",
"Tags": [
"c++",
"computational-geometry"
],
"Title": "Complex logic that I'm certain can be simplified"
} | 31597 |
<p>A program I wrote isn't performing quite to where I had hoped so I went looking to find where the majority of the time of the program was being spent and it was in the function below so I would like to get some eyes on it to help tune it up and make it run a little quicker. Please note I realize it isn't the most re... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-20T21:02:11.257",
"Id": "50434",
"Score": "0",
"body": "\"//assume this is always true for now\" so you can ditch the else."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-20T21:29:17.533",
"Id": "50435... | [
{
"body": "<p>My advice:</p>\n\n<ol>\n<li><p><strong>Precompute whatever is possible to precompute</strong>. I would say: all those vol*vol, x*x (especially before the double division /x/x). Your compiler may be smart enough to make some optimization itself, but it's better not to risk and to check if some perf... | {
"AcceptedAnswerId": "31721",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-20T20:37:52.870",
"Id": "31600",
"Score": "2",
"Tags": [
"c++",
"performance"
],
"Title": "Performance issues with Trinomial Tree to calculate price of option"
} | 31600 |
<p>Is there is better way to do that more efficiently?</p>
<p><strong><code>onCreate()</code>:</strong></p>
<pre><code>@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
layout = new Layout();
Event event = new Eve... | [] | [
{
"body": "<p><strong>Naming conventions</strong></p>\n\n<p>Several of your classes and variables defies <a href=\"http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-135099.html#367\" rel=\"nofollow\">Java naming conventions</a>. A class should start with an uppercase letter and a varia... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-20T22:19:53.470",
"Id": "31603",
"Score": "6",
"Tags": [
"java",
"android",
"search"
],
"Title": "Search Android contacts more efficiently"
} | 31603 |
<p>I use this <code>Timer</code> function quite a bit lately for all sorts of stuff,
and would appreciate if someone could review/analyze/criticize/verify
and, of course, suggest things I can do to optimize it for high
frequency execution (mainly animation).</p>
<p>My goal was to replicate ActionScript's counterpart (... | [] | [
{
"body": "<p>What's with the variable names? len, un, i, fn, t, f?\nUse the full meaningful names. This is the StopWatch class I use for performance, time measuring.</p>\n\n<pre><code>var StopWatch = function (performance) {\n this.startTime = 0;\n this.stopTime = 0;\n this.running = false;\n this.... | {
"AcceptedAnswerId": "31759",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-21T00:15:17.107",
"Id": "31604",
"Score": "2",
"Tags": [
"javascript",
"asynchronous",
"timer"
],
"Title": "Timer factory function"
} | 31604 |
<p>I been learning web development for 1.5 month now, and I am trying to improve my code. I can achieve what I want, but I think my code is really bad.</p>
<p>For example, I have a bunch of jQuery animations and a bunch of function to 'stop' those animations when another animation is starting. The code seems very inel... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-21T01:15:00.127",
"Id": "50442",
"Score": "0",
"body": "The first step to improve your code is to get rid of id's and use common classes."
}
] | [
{
"body": "<p>You could certainly use classes in many places to decrease code duplication. For instance, you could add a <code>top</code> class to all of your \"top\" elements. In that way, you could <code>stop</code> and <code>fadeOut</code> all in one line:</p>\n\n<pre><code>$(\".top\").fadeOut().stop();\n<... | {
"AcceptedAnswerId": "31608",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-21T00:40:58.987",
"Id": "31605",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"animation"
],
"Title": "Various animation functions"
} | 31605 |
<p>The following function takes two numbers that are linked with a "user" and calculates an ID number based on that. I have been trying to make this as clean as possible, and would like some advice on how to make this more efficient. an example of the input would be "12195491" for the num and "3120" for the ts, which ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-21T01:10:11.147",
"Id": "50439",
"Score": "1",
"body": "Could you provide more background? Maybe an example of input and output? Why `\"3452\"`? Why as a string not a number? What is `ts`?"
},
{
"ContentLicense": "CC BY-SA 3.0"... | [
{
"body": "<p>I think this is a little simpler. These are the changes I'd recommend:</p>\n\n<p>1) Always use a for loop if you have an initialization, test, and increment.</p>\n\n<p>2) I'd prefer variable names that have meaning like _nextDigit</p>\n\n<p>3) Take advantage of the fact that strings can be accesse... | {
"AcceptedAnswerId": "31612",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-21T01:07:34.517",
"Id": "31607",
"Score": "3",
"Tags": [
"javascript"
],
"Title": "More efficient version of an ID calculator in JavaScript"
} | 31607 |
<p>First of all, I am a beginner in Python trying to learn optimizations and proper coding standards.</p>
<p>Here is a snippet of code that checks if a number follows the rule: first AND last <code>N</code> digits contain all unique numbers from <code>1</code> to <code>N</code>, but in any order. This also means that ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-21T10:13:30.827",
"Id": "50450",
"Score": "0",
"body": "Pandigital numbers have a [somewhat different definition](http://en.wikipedia.org/wiki/Pandigital_number)."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "201... | [
{
"body": "<p>You can rewrite your asserts without comparing to <code>True</code> and <code>False</code>:</p>\n\n<pre><code>assert is_pandigital(1423, 4)\nassert not is_pandigital(1423, 5)\nassert is_pandigital(14235554123, 4)\nassert not is_pandigital(14235552222, 4) # !important\nassert not is_pandigital(1444... | {
"AcceptedAnswerId": "31615",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-21T08:44:10.237",
"Id": "31614",
"Score": "3",
"Tags": [
"python",
"optimization",
"beginner"
],
"Title": "Improve pandigital algorithm"
} | 31614 |
<p>The below code is still far from feature complete, but am looking to have some of the sections critiqued to learn better idioms or adjustments (e.g. - yet to be implemented: handling of csv files with headers, exception handling, more robust color labeling for matplotlib graphs, etc.):</p>
<pre><code>"""
Quantile n... | [] | [
{
"body": "<p>Ì am not sure <code>file_list = [args for args in sys.argv[1:]]</code> calls for list comprehension. I might be wrong but <code>file_list = sys.argv[1:]</code> should do the trick.\nSame applies to other of your list comprehension. If you do want to create a new list out of the previous, <code>lis... | {
"AcceptedAnswerId": "31639",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-21T11:14:16.090",
"Id": "31617",
"Score": "4",
"Tags": [
"python",
"csv",
"statistics"
],
"Title": "Code correctness and refinement for quantile normalization"
} | 31617 |
<p>I have this <code>authenticate!</code> method where I am trying to retrieve their account based on the subdomain, then find the user. if user is found & their password is matched, we return <code>success</code>, else <code>fail</code> in all other cases. here is the code:</p>
<pre><code>def authenticate!
ac... | [] | [
{
"body": "<p>Some programmers don't like the pattern <code>if (var = value)</code> (for understandable reasons), unfortunately, by avoiding it at all costs, you end up writing verbose code like yours. If you have no problems with it:</p>\n\n<pre><code>def authenticate!\n if (account = Account.find_by(subdomai... | {
"AcceptedAnswerId": "31649",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-21T13:41:05.627",
"Id": "31619",
"Score": "4",
"Tags": [
"ruby",
"ruby-on-rails",
"authentication"
],
"Title": "Rails authentication checks"
} | 31619 |
<p>I have the following function to collect quota information for the given user and return the information on a "ready to use" array:</p>
<pre><code>/* Get User Quota Information
*
* Prepare and array with the user's account disk space information
* by ascertaining the amount of space available on its quota,
* th... | [] | [
{
"body": "<p>I think you should use <a href=\"http://php.net/manual/en/function.escapeshellarg.php\" rel=\"nofollow\"><code>escapeshellarg</code></a> to secure that <code>$user</code> does not do damage through your <code>exec</code> call. Also, you should check if your <code>$arr</code> actually has the requi... | {
"AcceptedAnswerId": "31631",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-21T16:38:41.780",
"Id": "31626",
"Score": "4",
"Tags": [
"php"
],
"Title": "Getting user quota stats"
} | 31626 |
<p>I am reading hadoop source code , Here I have a doubt "org.apache.hadoop.util.StringUtils" they reassigned a list which is already intiailized.</p>
<pre><code> public static Collection<String> getStringCollection(String str){
List<String> values = new ArrayList<String>();
if (str == null)... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-27T01:09:15.660",
"Id": "67441",
"Score": "0",
"body": "This question appears to be off-topic because it is not your own written code."
}
] | [
{
"body": "<p>It looks like a useless reassignment. It must be some refactoring gone wrong. At worst, it will cause a tiny performance hit.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-21T18:18:47.257",
"... | {
"AcceptedAnswerId": "31629",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-21T16:56:26.583",
"Id": "31627",
"Score": "3",
"Tags": [
"java"
],
"Title": "Is this correct to reassign already intialized variable?"
} | 31627 |
<p>As an exercise in learning Scala, I implemented a square root function like this:</p>
<pre><code> def sqrt(x: Double): Double = {
if (x < 0) throw new IllegalArgumentException("negative numbers not allowed")
val threshold = if (x < 1) x / 1e15 else 1e-12
def sqrt(x: Double, p: Double): Double = {... | [] | [
{
"body": "<p>I'm going to concentrate on the Scala rather than the maths side, because that's my area.</p>\n\n<p>The internal helper function doesn't need two parameters, since the value of x never changes; pushing x repeatedly onto the stack is a waste of time. Also, better to use a case statement than a cha... | {
"AcceptedAnswerId": "31648",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-21T16:59:02.013",
"Id": "31628",
"Score": "11",
"Tags": [
"algorithm",
"unit-testing",
"scala",
"numerical-methods"
],
"Title": "Sqrt (square root) function"
} | 31628 |
<p>I'm working on my personal project and have recently had a bit of trouble with a method I wrote during the week.</p>
<p>This method compares user input from the same <code>JComboBox</code>. A before and after, if you will. It then makes an appropriate adjustment to a 2nd <code>ComboBox</code> depending on the user... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-22T12:47:21.513",
"Id": "50497",
"Score": "0",
"body": "So you problem is that this method sometimes has to keep it's count in `oldPac3`, but sometimes in other variables such as `oldGemT` or `oldGemC`? Is that it? If it's the case we ... | [
{
"body": "<h1>TL;DR</h1>\n\n<ol>\n<li>Name your variables more descriptively.</li>\n<li>Never copy-and-paste logic; if you find yourself doing so, make a new method or analyze <em>why</em> you're repeating it.</li>\n<li>Don't pass around components if you don't have to (like <code>JComboBox</code>es). In gen... | {
"AcceptedAnswerId": "31863",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-21T20:54:31.580",
"Id": "31633",
"Score": "5",
"Tags": [
"java",
"object-oriented"
],
"Title": "Writing an effective method that reflects good OO design and fixes this broke method"
} | 31633 |
<p>My class <code>Person</code> has a number of boolean values: <code>isMoving</code>, <code>hasEyesOpen</code>, <code>isTired</code> etc. They are all independent and eight in total. These values are updated from elsewhere every second. The Person stores the last hundred historical values. My code seems to contain a l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-12T07:12:30.970",
"Id": "50471",
"Score": "0",
"body": "@NarendraPathai I'm not really asking how my code is, but how this kind of problem should be solved. I just supplied my code in order to show some research effort and motivate the... | [
{
"body": "<p>Well one way to do it is to create a class 'PersonProperty'. You could make it a generic class if you intend to have non-boolean properties in the Person. </p>\n\n<p>The PersonProperty class could have methods getValue(), setValue(), getHistory() and a way of being identified - e.g. getName() that... | {
"AcceptedAnswerId": "31635",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-12T07:07:21.760",
"Id": "31634",
"Score": "-1",
"Tags": [
"java"
],
"Title": "How to organize these several lists of booleans to avoid code duplication?"
} | 31634 |
<p>When a user clicks the "Move Up" button, I grab the current elements <code>procedureid</code> and <code>sortOrder</code>. I then need for "Move Up" to grab the element above it and navigate down to a link inside the <code><p id="btncontainer"></code> element and grab that <code>procedureid</code> and <code>so... | [] | [
{
"body": "<p>Don't rely on <code>prev()</code> to traverse <code><br></code> tags and other strange code that isn't valid, as a <code><br></code> tag can't be a direct child of an UL.</p>\n\n<p>If you remove the <code><br></code> tag you can use <code>prev('li')</code> to get the previous li ... | {
"AcceptedAnswerId": "31638",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-11T20:47:08.187",
"Id": "31636",
"Score": "-1",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Grabbing elements with a \"Move Up\" button"
} | 31636 |
<p>I've just started learning Java and went to compare my finished product to some others on Stack Overflow. Is there a reason why mine is "simple" and the others seem ridiculously hard to even understand (for me)? <a href="https://stackoverflow.com/questions/4138827/check-string-for-palindrome">Link to the other pali... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-22T04:17:57.883",
"Id": "50485",
"Score": "0",
"body": "Can you just break it down for me. The good/bad/ugly of my code? Constructive criticism would be great as I'm very good at memorizing the books I use to learn java I just have a h... | [
{
"body": "<p>The most misleading part of the code is this: <code>String reversed = original;</code> — <code>reversed</code> is not reversed at all! Let's get rid of that confusion right away. Also note a few minor points…</p>\n\n<pre><code>public class Checker\n{\n public static void main(String[] args) {... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-22T03:27:58.383",
"Id": "31641",
"Score": "3",
"Tags": [
"java",
"beginner",
"palindrome"
],
"Title": "Palindrome Checker"
} | 31641 |
<p>Failing to get a solution to my problem from other people, I got tired of waiting and wrote this (rather rushed) Text class to deal with the text problems I've been having in Pygame. I wanted the text to update itself, so that it would be unnecessary to keep track of its original position. After playing a lot with i... | [] | [
{
"body": "<p>This is copied from <a href=\"https://codereview.stackexchange.com/a/31539/11728\">my answer</a> to your question \"<a href=\"https://codereview.stackexchange.com/q/31408/11728\">What about my Pong game?</a>\".</p>\n\n<ol>\n<li><p>The <code>Text._size</code> member is only used to create the font,... | {
"AcceptedAnswerId": "31796",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-22T07:31:12.177",
"Id": "31642",
"Score": "1",
"Tags": [
"python",
"pygame"
],
"Title": "Text class for Pygame"
} | 31642 |
<p>This is a simple program that can tell you your zodiac sign (Chinese or Western) and the year in which you were born. I made this using very basic beginning knowledge with C++ as practice.</p>
<p>I'm looking for some quick reviews on my code to see if there is anything I'm doing wrong or could be done better, makin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-24T13:54:34.290",
"Id": "50643",
"Score": "0",
"body": "Thank you everyone for all your help. This has given me a good bit to study, some of which I need to become more knowledgeable on, (such as functions & loops) others I need to lea... | [
{
"body": "<ul>\n<li><p>Since this is C++, prefer <a href=\"http://en.cppreference.com/w/cpp/types/size_t\" rel=\"nofollow noreferrer\"><code>std::size_t</code></a> over C-like <code>size_t</code>. With <code><ctime></code>, <code>time_t</code> should also be <code>std::time_t</code>. Keep the <code>std... | {
"AcceptedAnswerId": "31655",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-22T15:41:30.133",
"Id": "31652",
"Score": "9",
"Tags": [
"c++",
"beginner",
"datetime"
],
"Title": "Simple zodiac sign program"
} | 31652 |
<p>I have the following code below and I am trying to improve it.
How can I know if there is any limitations/drawbacks writing this way and why? Any possible error conditions? </p>
<p>What can be improved on this code? Thoughts? Suggestions?</p>
<pre><code><!DOCTYPE html >
<html>
<head>... | [] | [
{
"body": "<p>Adding in a timeout to the JSONP request is a good idea as suggested by <a href=\"https://codereview.stackexchange.com/a/31663/22816\">Noval Agung Prayogo</a>.</p>\n\n<p>Other than that, there's not a lot to change...</p>\n\n<ul>\n<li><code>$(document).ready(function () { ... });</code> can be wri... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-22T16:29:38.410",
"Id": "31654",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"html",
"image",
"ajax"
],
"Title": "Flickr tag search"
} | 31654 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.