body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>For the purpose of this problem, the BST is defined to allow duplicates, and the duplicate values will always follow to the right-side of the parent nodes with the same value. For example, with the data:</p> <pre><code> 1, 2, 2, 2, 2 </code></pre> <p>if the root node has the value 2 (as opposed to 1) then the tree...
[]
[ { "body": "<h2>General</h2>\n\n<p>Your code style here is good, the variable names are nice and descriptive, and the algorithm you implement is easy to identify and follow. This is good-looking code. There are a few of nit-picks:</p>\n\n<ul>\n<li>the <code>TreeNode</code> class should be a 'static' class ... <c...
{ "AcceptedAnswerId": "42832", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T23:30:22.967", "Id": "31960", "Score": "5", "Tags": [ "java", "algorithm", "tree", "binary-search" ], "Title": "Duplicate detection and reporting in a BST" }
31960
<p>This is a Python script that I use on my Android tablet. It moves the files in the <code>Download</code> folder to a folder on the external SD card. The files are sorted based on their extensions and are moved to folders (for each different type of extension). If it encounters a new file type, it will create a ne...
[]
[ { "body": "<p><code>File</code>, <code>FileList</code>, and <code>Data</code> are neither class names nor constants; variable names should be lower_case in Python. I'd call it <code>filename</code> instead of <code>file</code> to avoid clashing with Python's built-in <code>file()</code> constructor.</p>\n\n<p>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-28T23:52:25.453", "Id": "31961", "Score": "5", "Tags": [ "python", "android", "linux", "file-system" ], "Title": "Moving and organizing files in download folder" }
31961
<p>I want you to pick my code apart and give me some feedback on how I could make it better or simpler.</p> <pre><code>public int heightHelper(TreeNode node) { int height = -1; if (node == null) return height; final Queue&lt;TreeNode&gt; queue = new LinkedList&lt;TreeNode&gt;(); queue.add(node); ...
[]
[ { "body": "<p>The code is basically sound.</p>\n\n<p>It's not a helper function, so don't name it as such. (Helper functions would usually be <code>private</code>.)</p>\n\n<p>Comments would be good. In particular, a JavaDoc explaining how to interpret the height of a degenerate tree would be helpful.</p>\n\n<...
{ "AcceptedAnswerId": "31967", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T00:41:28.120", "Id": "31963", "Score": "5", "Tags": [ "java", "algorithm", "tree" ], "Title": "Find height of a tree without using recursion" }
31963
<p>This essentially checks if any of these <code>if</code> statements are true, then echos a statement.</p> <p>Unfortunately, wrapping the error message with a <code>div</code> tag is impossible since I set error to 1 after I would have the div tag show up. I assume I could use a function for this but I don't understa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T01:21:01.280", "Id": "51052", "Score": "0", "body": "http://stackoverflow.com/questions/4731810/if-else-embedding-inside-html\r\n\r\nHere's a solution to problem here on stackflow" }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>Like so:\nHere you can see that is easier to have errors as an array, use alternative control statments to separate php from html:</p>\n\n<pre><code> &lt;?php\n $messages = array();\n if(strlen($display)&lt;4)\n {\n $messages[] = 'Display name is too short';\n }\n if (empty($...
{ "AcceptedAnswerId": "31968", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T01:08:08.417", "Id": "31965", "Score": "2", "Tags": [ "php", "html", "validation", "email" ], "Title": "Redundant email checking in PHP" }
31965
<p>Ok, code reviewers, I want you to pick my code apart and give me some feedback on how I could make it better or more simple. Also its really hard to make this code work if <code>preorder array contains duplicate</code>. Any code/psuedocode is useful.</p> <pre><code>public class PreOrderTraversalBST { private T...
[]
[ { "body": "<p>Your binary tree setup does not appear to be well balanced.... and no, the counter is unnecessary. I think you have perhaps over-thought the process...</p>\n\n<p>If the data is pre-sorted, you can simply bifurcate your data in a recursive process.</p>\n\n<p>Your method is very close to what I woul...
{ "AcceptedAnswerId": "36376", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T06:54:18.970", "Id": "31972", "Score": "1", "Tags": [ "java", "algorithm", "tree" ], "Title": "Given preorder array construct a BST" }
31972
<p>I've started my first application using backbone and have something basic up and running, backbone seems to give a lot of freedom to application design and I don't know what I'm doing right and wrong in that regard. I'm just after some tips and criticism.</p> <p>The first view is for the details which should be vis...
[]
[ { "body": "<h3>DetailsView</h3>\n\n<p>You should pass jquery selector to the <code>el</code> — <a href=\"http://backbonejs.org/docs/backbone.html#section-140\" rel=\"nofollow\">Backbone will handle it</a>. Also, note that you should pass DOM element to the <code>el</code> property.</p>\n\n<hr>\n\n<p>Injecting o...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T09:35:46.427", "Id": "31974", "Score": "3", "Tags": [ "javascript", "backbone.js", "d3.js" ], "Title": "Basic Backbone application using d3" }
31974
<p>I ask if the following code need some refactoring :</p> <pre><code>public static int InsertBonus(DataTable dt, int month, int year) { int affectedRow = -1; using (IfxConnection con = new IfxConnection(ConfigurationManager.ConnectionStrings["xxx"].ToString())) { using (IfxTransaction tran = con....
[]
[ { "body": "<p>Yes:</p>\n\n<ul>\n<li>You don't need to use a <code>StringBuilder</code> when you are not building a string. Just use the string.</li>\n<li>Don't check the state of the connection for every query. Just open the connection before the first query, and it stays open.</li>\n<li>The check for null for ...
{ "AcceptedAnswerId": "32004", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T09:53:49.803", "Id": "31975", "Score": "1", "Tags": [ "c#", "asp.net" ], "Title": "simple transaction process" }
31975
<p>Implement data structure overflow queue. Overflow queue is a normal queue with one extra property. It never throw Stack overflow exception. So whenever queue becomes full, it replaces the oldest element present in the queue and front pointer simply shifted one step ahead. Constraint:- it should have public void enQu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T21:49:48.060", "Id": "51107", "Score": "2", "body": "See [EvictingQueue](http://code.google.com/p/guava-libraries/source/browse/guava/src/com/google/common/collect/EvictingQueue.java)." } ]
[ { "body": "<p>With this implementation, it would not throw a stackoverflow exception but there could be an unusual behavior. Maybe there could be some better exception message to handle this case.</p>\n\n<pre><code>OverflowQueue q = new OverflowQueue(n);\n</code></pre>\n\n<p>Now, let's say I want to enqueue n+1...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T12:07:59.510", "Id": "31978", "Score": "5", "Tags": [ "java", "algorithm", "queue" ], "Title": "Implement data structure overflow queue" }
31978
<p>Is there a more efficient algorithm to generate random numbers in C++?</p> <p>(This code is working on Dev-C++, but I'm not sure if it works on a Borland compiler.)</p> <pre><code>/* Author: Arpit Agrawal Email: arpitagrawal294@gmail.com Description: Dice Roll Algorithm. Project Name: e-Roll. */ #includ...
[]
[ { "body": "<p>Only call <code>srand()</code> once in an application:</p>\n\n<pre><code> srand (time(NULL));\n</code></pre>\n\n<p>Should be just after <code>main()</code> starts.</p>\n\n<p>This does not generate an evenly distributed the random numbers.</p>\n\n<pre><code> n= rand();\n n = 1 + n % 6;\n</...
{ "AcceptedAnswerId": "31992", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T13:47:23.910", "Id": "31980", "Score": "11", "Tags": [ "c++", "beginner", "game", "random", "dice" ], "Title": "Simple Dice Roll game" }
31980
<p>I have tested all the cases of how a line could be</p> <ol> <li>vertically</li> <li>horizontally </li> <li>has a slope that's positive or less than 1</li> </ol> <p>The function works, but I would like it reviewed, such as if there are overflows, etc.</p> <pre><code>// Draw line using DDA Algorithm void Graphics::...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-16T15:15:03.177", "Id": "102135", "Score": "0", "body": "https://en.wikipedia.org/wiki/Bresenham's_line_algorithm" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-16T20:50:28.490", "Id": "102231", "S...
[ { "body": "<p>This makes no sense. The <code>slope</code> must be an <code>int</code> such as 0, 1, 2, 3, 4, … but a vertical line is treated as a line of slope 2? How is that accurate at all?</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-13T10:04...
{ "AcceptedAnswerId": "57213", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T14:18:09.263", "Id": "31982", "Score": "2", "Tags": [ "c++", "algorithm", "graphics" ], "Title": "Implementation of DDA Line Algorithm" }
31982
<p>I'm changing an HTML datepicker value (<code>#date</code>) into 3 separate values in order to post them to a booking engine. I've managed to get it to work but there is a lot of repetition and the original <code>#date</code> value is also submitted unnecessarily.</p> <p>The engine takes these parameters: </p> <pre...
[]
[ { "body": "<p>The tought process to make your code <a href=\"http://en.wikipedia.org/wiki/Don%27t_repeat_yourself\" rel=\"nofollow\">DRY</a> is almost always the same:</p>\n\n<ol>\n<li>Find the commonalities between blocks of code.</li>\n<li>Extract these into an iterable structure.</li>\n<li>Loop.</li>\n</ol>\...
{ "AcceptedAnswerId": "32011", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T18:28:58.800", "Id": "31990", "Score": "3", "Tags": [ "javascript", "jquery", "datetime", "form" ], "Title": "jQuery date split into day month year" }
31990
<p>I want you to pick my code apart and give me some feedback on how I could make it better or simpler. Although, agree that generics should be used, instead of integers, let's punt on generics as a review for now.</p> <pre><code>public class CreateBinarySearchTree { private TreeNode root; public CreateBinar...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-18T18:00:06.080", "Id": "57817", "Score": "0", "body": "Have you tested this code properly to make sure that it works correctly? There's just something about your `right` and `left` fields in the `TreeNode` that doesn't feel right to m...
[ { "body": "<p><code>root</code> is created if and only if you add an element. From the BST I know, the <code>root</code> always exists, even if the tree contains no elements.</p>\n\n<p>Also, the name is confusing. Is it a 'BST creator'? \nThen the name is ok, but some 'BST' itself should be accessible.</p>\n\n<...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T20:07:21.430", "Id": "31994", "Score": "10", "Tags": [ "java", "algorithm", "tree" ], "Title": "Creating a binary search tree" }
31994
<p>I have written a small wrapper class for using PHP Mcrypt for encrypting and decrypting text data. This class generates a salt for hashing the key and encrypts the given data with the generated key hash. The encrypted data get stored with the initialization vector and the key salt into a container class. The contain...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T14:59:52.767", "Id": "51234", "Score": "1", "body": "If you `trim` the data prior to encrypting it, don't trim the decrypted data. It should be excactly the same, and require no additional processing. If that's not the case, the dat...
[ { "body": "<p>I have been wanting to answer this for a while now, and I think I can give an answer today! So...</p>\n\n<blockquote>\n <p>Am I using PHP Mcrypt the right way?</p>\n</blockquote>\n\n<p>Well, what is <em>right</em>? Hows about, <em>what is wrong</em>? There's a blog I know of, which is written by ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T20:30:14.877", "Id": "31996", "Score": "7", "Tags": [ "php", "security", "php5", "cryptography" ], "Title": "Am I using PHP Mcrypt the right way?" }
31996
<p>I am writing PHP code to update a database, but this code is extremely repetitive and thus error prone. I am effectively typing the variable names six times each! Can this be improved without loosing functionality? I am certain there must be better way!</p> <p>First, the definition of the demandArrayValue function:...
[]
[ { "body": "<p>If I were you, I'd create a function that looked like this:</p>\n\n<pre><code>function getArrayValues( array $array, array $keys)\n{\n $result = array();\n foreach($keys as $key)\n {\n if (!isset($array[$key]))\n {\n throw new RuntimeException($key.' is not set');...
{ "AcceptedAnswerId": "32018", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T20:57:46.273", "Id": "31997", "Score": "1", "Tags": [ "php" ], "Title": "Modifying database using POSTed variables in PHP" }
31997
<p>Ok, code reviewers, I want you to pick my code apart and give me some feedback on how I could make it better or more simple. ( Generics would be added a bit later). </p> <pre><code>public class CreateABinaryTree { private TreeNode root; public CreateABinaryTree() { } /** * Constructs a binary...
[]
[ { "body": "<p>I only see one really questionable thing in your code. Why do you call <code>this()</code> in your constructor? Your parameter-less constructor does absolutely nothing, so this line is irrelevant. If anything, I would actually even remove that constructor entirely so that your API can only be u...
{ "AcceptedAnswerId": "32005", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T21:04:42.237", "Id": "31998", "Score": "3", "Tags": [ "java", "algorithm", "tree" ], "Title": "Create a binary tree, code review request" }
31998
<p>I'm reading <em>TDD By Example</em> by Kent Beck (which I highly recommend, if you haven't read it!) In <em>The xUnit Example</em>, he discusses how to collect the results of multiple tests in a single <code>TestResult</code>. His code looks like this:</p> <pre><code># in TestCase def run(self, result): result....
[]
[ { "body": "<p>One benefit of a collecting parameter is writers can add multiple items to the list. The collecting parameter can descend deeper into the stack and each method is free to add as many items to the list as necessary.</p>\n\n<p>If what was added to the list was restricted to the return value of the ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T22:52:02.670", "Id": "32002", "Score": "2", "Tags": [ "python", "design-patterns" ], "Title": "Collecting Parameter vs overloading addition" }
32002
<p>I am trying to clean up and make the following code more efficient -</p> <p><a href="https://gist.github.com/eWizardII/6757364" rel="nofollow">https://gist.github.com/eWizardII/6757364</a></p> <pre><code>from PIL import Image import numpy as np from PIL import ImageChops import subprocess import math import dateti...
[]
[ { "body": "<p>I don't know about \"more efficient\", but here are some hints and tips that will help you clean up the code and make it more readable:</p>\n\n<h2>Style remarks</h2>\n\n<ul>\n<li>My style checker asks for at least 2 spaces before an inline comment (lines 20-21). I don't think it's a bad idea.</li>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-29T23:06:21.127", "Id": "32003", "Score": "2", "Tags": [ "python", "optimization" ], "Title": "Python Code Cleanup/Optimization" }
32003
<p>The following script is being used to generate the status line in <a href="https://code.google.com/p/wmii/" rel="nofollow">wmii</a>. I'm curious if there are faster/more efficient ways to find the various info I'm grabbing. I'm also a relative newbie when it comes to zsh (and shell scripting in general) so I'd also ...
[]
[ { "body": "<h3>Extracting a column</h3>\n\n<p>It's a lot easier to extract columns from text using awk.\nInstead of this:</p>\n\n<blockquote>\n<pre><code>grep \"cpu MHz\" /proc/cpuinfo | sed 's/[\\t ]*//g; s/cpuMHz://g'\n</code></pre>\n</blockquote>\n\n<p>This is shorter, and uses a single awk process instead o...
{ "AcceptedAnswerId": "115256", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T02:02:16.003", "Id": "32008", "Score": "3", "Tags": [ "beginner", "linux", "shell", "zsh" ], "Title": "zsh system status script" }
32008
<p>Ok, code reviewers, I want you to pick my code apart and give me some feedback on how I could make it better or more simple.</p> <pre><code>public class Trie { private static final int ASCII = 256; private TrieNode root; public Trie () { root = new TrieNode(); } private static class ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T05:32:18.773", "Id": "51117", "Score": "0", "body": "What is the code doing??" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T07:06:48.157", "Id": "51126", "Score": "3", "body": "It is hop...
[ { "body": "<p>The <code>TrieNode[] alphabets</code> can probably be changed to a <code>Map&lt;Character, TrieNode&gt;</code>.</p>\n\n<p>This would have some important advantages: </p>\n\n<ul>\n<li>First, you would not consume all characters domain space (256 in your sample code) unless you actually have nodes d...
{ "AcceptedAnswerId": "32030", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T04:08:30.757", "Id": "32010", "Score": "0", "Tags": [ "java", "algorithm", "tree", "trie" ], "Title": "Trie - code review request for improvement" }
32010
<p>I'm wondering what would be the best way to calculate the hashcode when the order of a sequence doesn't matter. Here's the custom <code>IEqualityComparer&lt;T&gt;</code> i've implemented for an <a href="https://stackoverflow.com/a/19089162/284240">answer</a> on Stackoverflow.</p> <pre><code>public class AccDocument...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T10:25:47.683", "Id": "51141", "Score": "0", "body": "Why don't you simply assign a unique ID upon creation of an object and redefine 'equality' of two objects instead? Using the ID when the `GetHashCode` is called is efficient and i...
[ { "body": "<p>If the order does not matter, use an kommutative operator to combine the hashCodes of the elements.</p>\n\n<p>Possible candidates are:<br>\n<code>^</code> binary <code>xor</code> // <em>THIS WOULD BE MY CHOICE</em><br>\n<code>+</code> addition // problem may be the overflow<br>\n<code>*</c...
{ "AcceptedAnswerId": "32025", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T09:12:20.233", "Id": "32024", "Score": "6", "Tags": [ "c#", "linq" ], "Title": "Calculating GetHashCode efficiently with unordered list" }
32024
<p>Here I want to lock when populating a particular cache object, without blocking other calls to the same method requesting <code>Foo</code>s for other <code>barId</code>s. I realise the <code>MemoryCache</code> will be thread safe, but if two or more concurrent calls come in it seems like it would be better if only o...
[]
[ { "body": "<p>What I don't like about your approach is that the lock objects are never removed from <code>FooServiceCacheLocks</code>, even when the object is removed from the cache.</p>\n\n<p>One way to simplify your code would be to combine <code>MemoryCache</code> with <a href=\"http://msdn.microsoft.com/en-...
{ "AcceptedAnswerId": "32091", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T10:04:09.050", "Id": "32026", "Score": "7", "Tags": [ "c#", "locking", "cache" ], "Title": "Locking during cache population" }
32026
<p>I have a data structure composed of several <code>std::lists</code>, each sorted by a specific criterion. When a new item is inserted into this data structure, there is a need for a reference item already in this data structure. Also all the items between the reference and insertee need to be collected into sets.</p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T16:45:56.710", "Id": "51177", "Score": "0", "body": "Ending your identifiers with `_` makes very unreadable `->` expressions..." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T17:03:40.157", "Id":...
[ { "body": "<p>I haven't tested this solution, but I believe that your code could be simplified by using a <code>reverse_iterator</code>.</p>\n\n<pre><code>upperReferenceSet_.clear();\nlowerReferenceSet_.clear();\nfor (int objective = 0; objective &lt; nObjectives_; ++objective)\n{\n const Real referenceValu...
{ "AcceptedAnswerId": null, "CommentCount": "13", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T11:16:10.607", "Id": "32027", "Score": "8", "Tags": [ "c++", "performance", "c++11", "linked-list", "iteration" ], "Title": "Optimizing iteration through linked lists" }
32027
<p>I am a beginner in Digital Signal Processing and I was trying to compute and plot an autocorrelation.</p> <p>I've wrote this piece of code:</p> <pre><code>r = [zeros(2,1); y(1:98,1)]; r = r.*y; </code></pre> <p>and I wished to know if this is a valid way of computing an autocorrelation.</p>
[]
[ { "body": "<p>How about <code>xcorr(y)</code>? The <a href=\"http://www.mathworks.com/help/signal/ref/xcorr.html\" rel=\"nofollow\"><code>xcorr()</code></a> function is part of the Signal Processing Toolbox.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "20...
{ "AcceptedAnswerId": "36539", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T13:57:53.333", "Id": "32031", "Score": "2", "Tags": [ "matlab" ], "Title": "Is this a valid way of computing autocorrelation?" }
32031
<p>This is my simple Fibonacci implementation in CoffeeScript. What do you think? Using cache (<code>fibResults</code>), it's very very fast. </p> <pre><code>fibResults = [] defaultMax = 1000 nrMax = defaultMax fibonacci = (n) -&gt; return fibResults[n] if fibResults[n] if n &lt; 2 fibResults[n] = n else ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T16:29:53.913", "Id": "51175", "Score": "0", "body": "what is the max number that you are wanting to go to? i remember when we did this in C# and it got pretty intense, but i think we were just doing it in VIsual Studio Debug. and i...
[ { "body": "<p>Something I noticed in your algorithm is that despite using memoization, you are still reassigning the Fibonnacci number into the array every time you calculate it. </p>\n\n<p>You could avoid reassigning by having a function like <code>computeIfAbsent</code> that determines if the Fibonacci for a ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T14:54:39.310", "Id": "32032", "Score": "3", "Tags": [ "javascript", "node.js", "coffeescript", "fibonacci-sequence" ], "Title": "Fibonacci using cache" }
32032
<p>By having two model classes <code>Conversation</code> and <code>Message</code>, what are the best practices to handle the next situation: A conversation listening for its messages <code>PropertyChanged</code> events and so being able to update itself.</p> <ol> <li>What are the best practices? </li> <li>How can I i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T06:58:59.743", "Id": "51212", "Score": "0", "body": "Looks fine to me" } ]
[ { "body": "<p>First of all, the Conversation class does not provide any events for chances, so nobody has a chance to get to know if something changes. This is already be implemented within an (Sorted)Observable collection, but unfortunately you publish this private field as <code>IList&lt;Message&gt;</code> by...
{ "AcceptedAnswerId": "32059", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-09-30T17:50:47.850", "Id": "32035", "Score": "3", "Tags": [ "c#", "event-handling", "collections" ], "Title": "How to observe nested objects" }
32035
<p>I'm a C++ programmer using <a href="http://www.spoj.com/" rel="nofollow">SPOJ</a> problems to learn C(99). This is my solution to the problem <a href="http://www.spoj.com/problems/CMEXPR/" rel="nofollow">CMEXPR</a>, where the goal is to read a valid expression (<code>+</code>, <code>-</code>, <code>*</code>, <code>/...
[]
[ { "body": "<p>These comments are not really related to writing \"idiomatic C\", merely things I noticed in your code.</p>\n\n<ul>\n<li><p>Your handling of commas in lists is odd:</p>\n\n<pre><code>enum ParsingContext {\n CONTEXT_FIRST_TERM\n , CONTEXT_ADDITIVE_EXPRESSION\n , CONTEXT_NONFIRST_TERM\n};\n...
{ "AcceptedAnswerId": "32075", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T19:10:40.957", "Id": "32040", "Score": "4", "Tags": [ "c", "parsing" ], "Title": "Parsing expressions using idiomatic C" }
32040
<p>This is pretty much an OOP version of <a href="https://codereview.stackexchange.com/questions/31817/python-game-of-life">this question</a>, with the improvements:</p> <pre><code>import copy import shelve class GameOfLife(object): def __init__(self, board, generations = 10): self.__board = board ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T21:57:10.390", "Id": "51193", "Score": "0", "body": "To create a board… `import shelve; b = [[False] * 15] * 15 ; b[7][7] = True ; shelve.open('boardfile.dat')['board'] = b`" }, { "ContentLicense": "CC BY-SA 3.0", "Creat...
[ { "body": "<p>This looks good. Here are a few (untested) comments.</p>\n\n<ul>\n<li>Your <code>__str__</code> method could take advantage of ternary operator, list comprehension and the join method :</li>\n</ul>\n\n<p>This :</p>\n\n<pre><code>def __str__(self):\n string = \"\"\n for row in self.__board:\n...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T21:24:24.487", "Id": "32044", "Score": "4", "Tags": [ "python", "object-oriented", "game-of-life" ], "Title": "Game Of Life OOP Python" }
32044
<p>I have a <code>ByteArray</code> value as <code>avroBinaryValue</code> , <code>Schema Id</code> value as <code>short</code> <code>schemaId</code> and <code>Last Modified Date</code> value as <code>lastModifiedDate</code> in <code>long</code>.</p> <pre><code>short schemaId = 32767; long lastModifiedDate = "1379811105...
[]
[ { "body": "<p>The way you are doing it is fine, however it seems like a better idea to just put all of the data you want to serialize into a <code>Serializable</code> object and then just serialize that automatically. For example you could do something like : </p>\n\n<pre><code>public static void main(String[] ...
{ "AcceptedAnswerId": "32074", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T01:06:42.437", "Id": "32048", "Score": "1", "Tags": [ "java" ], "Title": "Merge three ByteArrays together and then split resulting ByteArrays" }
32048
<p>I have been working a number pyramid program. This is a question from Y. Daniel Laing's <em>Introduction to programming using Python</em> (which is based on Python 3.2). The question is from chapter 5, and it is number 5.19 in programming exercises portion of the chapter. The question is stated as follows:</p> <bl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T06:44:58.160", "Id": "51210", "Score": "2", "body": "But that's not a working code at all. It will just get infinitely stuck at the first loop." } ]
[ { "body": "<p>This feels like a C program. Python can be a lot more compact, and more importantly, expressive. The key is to think at a higher level than a few characters at a time. List comprehensions help a lot.</p>\n\n<p>Each row consists of a countdown, a \"1\" in the middle, then an ascending count. Le...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T01:30:08.340", "Id": "32050", "Score": "5", "Tags": [ "python", "python-3.x", "ascii-art" ], "Title": "Building a number pyramid" }
32050
<p>I am working on a bigger project and want to separate game updates from rendering and not end up with a super complicated game loop. So I came up with the idea of isolating the problem and writing a controller for this. My game loop looks like:</p> <pre><code>public class Game { public bool Running; public...
[]
[ { "body": "<p>I think sourcing the game-loop out is basically a good idea to improve separation of concerns. But I would go farther: I would implement a <a href=\"http://en.wikipedia.org/wiki/Strategy_pattern\" rel=\"nofollow\">strategy pattern</a> which makes the behavior of the game loop exchangeable. Futherm...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T07:04:56.660", "Id": "32054", "Score": "3", "Tags": [ "c#", "game" ], "Title": "Control game ticks/frames of updates and rendering separately" }
32054
<p>Can someone please find out why this store procedure is timing out?</p> <pre><code>ALTER PROCEDURE [dbo].[Insertorupdatedevicecatalog] (@OS NVARCHAR(50) ,@UniqueID VARCHAR(500) ,@Longitude FLOAT ,@Latitude FL...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-13T14:42:40.253", "Id": "57144", "Score": "1", "body": "why do you use double `'` around things?" } ]
[ { "body": "<p>It's impossible to say what the problem is without knowing how the data is structured, how many rows are in each table, what the indexes are, and other information. Even then, the problem may not even be with this query but with some other query that causes problems for the database as a whole. Ba...
{ "AcceptedAnswerId": "32200", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T10:12:12.053", "Id": "32060", "Score": "1", "Tags": [ "sql", "sql-server", "t-sql", "time-limit-exceeded", "geospatial" ], "Title": "Store procedure timing out sometime...
32060
<p>I was trying to solve the final puzzle at the end of the classes chapter (Chapter 8) in "Python Programming for the Absolute Beginner" which is stated as:</p> <blockquote> <p>Create a Critter Farm program by instantiating several <code>Critter</code> objects and keeping track of them through a list. Mimic the <co...
[]
[ { "body": "<p>Not much to say:</p>\n\n<p><strong>Variable naming</strong></p>\n\n<p>I find that <code>happiness</code> is not very well chosen; <code>sadness</code> would probably be a better name.</p>\n\n<p><strong>Conciseness</strong></p>\n\n<p><code>self.__hunger = max(self.__hunger - 3, 0)</code> is a bit s...
{ "AcceptedAnswerId": "32072", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T11:21:31.650", "Id": "32063", "Score": "1", "Tags": [ "python", "object-oriented" ], "Title": "OOP Challenge in Python" }
32063
<p>I'm messing around with JavaScript and am trying out objects, functions &amp; arrays. I'd like to know if someone has tips about making it better, shorter, or has a better solution for what I have thought about for now. What I've tried to do is just do simple math (+ and -) using arrays as input for numbers. It al...
[]
[ { "body": "<pre><code>function doMath(options) {\n var defaults = {\n method: 'add'\n };\n var options = $.extend({}, defaults, options);\n\n var n = 0;\n\n for(var i=0; i&lt;options.numbers.length; i++) {\n if(isNumber(options.numbers[i])) {\n if(options.method == 'add' ...
{ "AcceptedAnswerId": "32070", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T11:35:42.943", "Id": "32064", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Simple math using arrays" }
32064
<p>Using a combination provided from <a href="http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application" rel="nofollow noreferrer">this example</a> and <a href="https://codereview.stackexchange.com/questions/11785/ef-code-first...
[]
[ { "body": "<p>While I'm not sure of the safety of <code>PerRequestLifetimeManager</code>, one thing I'd recommend changing in your repository is to avoid inheritance from <code>Repository&lt;T&gt;</code>.</p>\n\n<p>Instead of </p>\n\n<pre><code>public class EmployeeRepository : Repository&lt;Employee&gt;\n{\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T13:59:57.187", "Id": "32071", "Score": "6", "Tags": [ "c#", "design-patterns", "entity-framework", "asp.net-mvc-4" ], "Title": "Entity Framework using Repository Pattern, Unit...
32071
<p>I need to provide a service (either a Windows Service or an Azure Worker Role) which will handle the parallel execution of jobs. These jobs could be anything from importing data to compiling of reports, or to sending out mass notifications, etc. </p> <p><strong>Database Design:</strong></p> <p>The whole process of...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T23:45:47.613", "Id": "51266", "Score": "0", "body": "I think you don't have ReSharper installed and screaming at your private field naming convention! Prefixing them with an underscore really helps readability I find - I was WTF-loo...
[ { "body": "<p>Only some few minor things:</p>\n\n<ol>\n<li>In <code>StartPopulatingQueue</code> to me as the reader it's unclear in what unit <code>pollingDelay</code> is in. Two classic solutions:\n\n<ul>\n<li>Change it to be a <code>TimeSpan</code> - I usually prefer this since it provides the most flexibilit...
{ "AcceptedAnswerId": "109919", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T14:36:16.253", "Id": "32073", "Score": "6", "Tags": [ "c#", "design-patterns", "serialization" ], "Title": "Parallel Job Consumer using TPL" }
32073
<p>This is my very first Bash script that does something real. I'm here to learn, so please tell me if and how this can be done better.</p> <pre><code>#!/bin/sh # Daniele Brugnara # October - 2013 if [ -k $1 ]; then echo "Error! You must pass a repository name!" exit 1 fi SVN_PATH="/var/lib/svn" cur...
[]
[ { "body": "<ol>\n<li><p>If the first argument to your script contains a space, then you get an error message:</p>\n\n<pre><code>$ ./cr32076.sh \"my repository\"\n./cr32076.sh: line 6: [: my: binary operator expected\n</code></pre>\n\n<p>To avoid this, put quotes around the variable <code>$1</code>, like this:</...
{ "AcceptedAnswerId": "32084", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T16:06:42.553", "Id": "32076", "Score": "4", "Tags": [ "bash" ], "Title": "New svn repository script" }
32076
<p>I'm trying to create a custom div scroller. I got it working, but it's still a little rough around the edges. Please take a look..</p> <p><a href="http://jsfiddle.net/5t3Ju/134/" rel="nofollow">DEMO</a></p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" ...
[]
[ { "body": "<p>Just focusing on the Javascript:</p>\n\n<ul>\n<li><p>I feel a urge to to reference a <a href=\"http://thecodelesscode.com/case/34?topic=naming\" rel=\"nofollow\">story about a monk</a>. Instead I'll just say that descriptive names will help when you come back to your code or when others try to rea...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T16:55:15.113", "Id": "32077", "Score": "5", "Tags": [ "javascript", "html", "css" ], "Title": "Custom scrollable div" }
32077
<p>Is there a more efficient way of achieving the same result besides setting up a database?</p> <pre><code># In reality, contains 4 million tuples. stuff_tuple = ( ('hello', 241, 1), ('hi', 243, 3), ('hey', 242, 2) ) # Convert tuple to set for faster searching? stuff_set = set(stuff_tuple) # Only first ...
[]
[ { "body": "<p><a href=\"https://stackoverflow.com/questions/513882/python-list-vs-dict-for-look-up-table\">This question</a> suggests that dictionaries and sets - which are both based on hashtables internally -- are the fastest for random retrieval of hashable data (which your sample seems to b). It's always a ...
{ "AcceptedAnswerId": "32111", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T17:19:24.890", "Id": "32078", "Score": "1", "Tags": [ "python" ], "Title": "Search set, return item" }
32078
<p>I wrote some code using meteor, which is working, but I don't know if I did it the best way. I'm asking for opinions on other ways to perform this task.</p> <p>It's just a list of places. You can fill the textfield with a place and it'll appear on the list. You have an option to remove the place by clicking on t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T21:46:35.700", "Id": "51248", "Score": "1", "body": "Would you prefer a new tag for meteor.js?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T22:01:17.573", "Id": "51249", "Score": "0", "...
[ { "body": "<p>Great start! You're very close. I changed things around a little bit, and added an extra template and a separate event map for that template. This should make it easier to understand, and it means you don't have to store the place's id in a data attribute. Check it out:</p>\n\n<pre><code>Places = ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T21:26:49.900", "Id": "32086", "Score": "3", "Tags": [ "javascript", "beginner", "meteor" ], "Title": "Better way to write list of places program" }
32086
<p>Meteor is an Open-Source JavaScript web framework that provides a modular platform for developing client/server applications in pure JavaScript.<br> Meteor's core consists of the DDP (Distributed Data Protocol), which is merely a client-server protocol for querying/updating a server-side database, as well as for syn...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T22:07:02.137", "Id": "32087", "Score": "0", "Tags": null, "Title": null }
32087
This tag is for questions written using the Meteor open-source web framework. These questions should also be tagged with [javascript].
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T22:07:02.137", "Id": "32088", "Score": "0", "Tags": null, "Title": null }
32088
<p>Originally my wireframe was </p> <p><img src="https://i.stack.imgur.com/c5sIz.png" alt="original wireframe"></p> <p>But I ended up going with this in testing. The image is the result of my new code. </p> <p><img src="https://i.stack.imgur.com/3mrlJ.png" alt="prototype 1"></p> <p>Keep in mind that the actual cont...
[]
[ { "body": "<p>this looks really good so far, </p>\n\n<p>I don't see anything that I would change about this. you are using <code>span</code> tags correctly and efficiently for what you are doing with them, your <code>div</code> tags are also used to the best of their abilities.</p>\n\n<p>your CSS also looks g...
{ "AcceptedAnswerId": "33610", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T23:13:55.677", "Id": "32092", "Score": "1", "Tags": [ "html", "css" ], "Title": "Review of HTML and CSS for a newsfeed of posts" }
32092
<p>I am pretty new to Python but I'm learning from classes.</p> <p>I am working on a project for class and this is my code. Anyone got a better idea of a way to organize the code or put it differently so there aren't so many conditional statements?</p> <pre><code>def cm(centimeter): """Centimeter to Meters Conver...
[]
[ { "body": "<p>Instead of trying to determine if the input is a number and then looking for a special value (<code>\"false\"</code>), let Python determine if the input is a number:</p>\n\n<pre><code>def cm(centimeter):\n \"\"\"Centimeter to Meters Converter!\"\"\"\n result = round(centimeter / 100)\n pr...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-01T23:31:07.203", "Id": "32093", "Score": "5", "Tags": [ "python", "beginner", "converting" ], "Title": "Organization of measurements converter" }
32093
<p>I am currently writing an app that converts musical keys. In a nutshell the conversion part of the script, is one giant if / then statement (if the user selected A then display B, etc etc.).</p> <p>While this works perfectly fine, I definitely feel like this is fairly crude, and extremely lengthy, with all of the k...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T16:35:39.707", "Id": "51252", "Score": "0", "body": "you could use a switch statement instead. http://www.w3schools.com/js/js_switch.asp That way your script stops when it finds a match and doesn't have to check the other conditions...
[ { "body": "<p>This is just a nebulous thought, but you could make each key an array ie Cmaj=(c,d,e,...), Dmaj=(d,e,f#,...) then take the position in the original key's array of the note to be transposed and find the note at that position in the target key's array. So for example if the keys were Cmaj and Dmaj a...
{ "AcceptedAnswerId": "32098", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T16:29:46.023", "Id": "32095", "Score": "4", "Tags": [ "javascript", "jquery", "music" ], "Title": "Transposing notes by one whole step" }
32095
<p>I have the following, quite ugly statement - is there a better way to write something of this nature?</p> <pre><code>if (!item["Created By"].ToString().Contains("System Account") &amp;&amp; !item.Url.Contains("_catalogs") &amp;&amp; !item.Url.Contains("Style Library") &amp;&amp; !item.Url.Contains("Cach...
[]
[ { "body": "<p>As well as some standard indenting, a quick thought could be reversing the item being compared and using some temporary variables for readability. </p>\n\n<p><strong>EDIT</strong>:<br>\nOk, so svick pointed out that the original code was fundamentally flawed. So how about creating an extension m...
{ "AcceptedAnswerId": "32107", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T01:44:51.113", "Id": "32103", "Score": "2", "Tags": [ "c#", "optimization", "sharepoint" ], "Title": "Surely there's a better way to write this statement?" }
32103
<p>I am trying not to pick up any bad habits while improving the way I write programs. Any suggestions on the following lines of code?</p> <pre><code>package guessGame; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Random; // Main C...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T04:07:51.103", "Id": "51277", "Score": "0", "body": "you can minimize that long if-else block by having a separate method" } ]
[ { "body": "<p>Problems I see:</p>\n\n<ol>\n<li><p><code>comment</code> and <code>comment2</code> are initialised twice, once in the class definition and again in the constructor.</p></li>\n<li><p>If you click the <code>New Game</code> button, you'll get a new window but the old one will still be there. (see als...
{ "AcceptedAnswerId": "32110", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T01:58:44.320", "Id": "32104", "Score": "3", "Tags": [ "java", "game", "swing", "number-guessing-game" ], "Title": "Number-guessing game in Java with Swing UI" }
32104
<p>I am writing a byte array value into a file, consisting of up to three of these arrays, using Java with big Endian byte order format. Now I need to read that file from a C++ program.</p> <pre><code>short employeeId = 32767; long lastModifiedDate = "1379811105109L"; byte[] attributeValue = os.toByteArray(); </code><...
[]
[ { "body": "<p>Obviously the code isn't portable to big-endian machines. I'll use C syntax, since I'm more familiar with that than C++.</p>\n\n<p>If you have <code>endian.h</code>, you can use the functions in there; if not, you should have <code>arpa/inet.h</code> which defines functions for swapping network by...
{ "AcceptedAnswerId": "32115", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T03:34:42.043", "Id": "32106", "Score": "3", "Tags": [ "java", "c++", "serialization" ], "Title": "Deserializing a byte array from Java in C++" }
32106
<p>I am writing a simple event handling class in C++, to avoid having delegate registration and calls cluttering the rest of the code. I have a design that seems to do the job, but it has a couple of drawbacks.</p> <p>So far it looks like this:</p> <pre><code>template&lt;typename T&gt; struct IDelegate { virtual void...
[]
[ { "body": "<p>Been a while since I've done much in the way of heavy C++ &amp; I'm sure others will weigh in with their own suggestions, but my two cents:</p>\n\n<ol>\n<li><p>I think the best solution is the first one you rejected: add Foo::{Add,Remove}Listener. Yep, it's more code but (a) it solves both the iss...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T04:04:28.150", "Id": "32108", "Score": "2", "Tags": [ "c++", "delegates", "event-handling" ], "Title": "Designing an EventHandler in C++" }
32108
<p>Ok, code reviewers, I want you to pick my code apart and give me some feedback on how I could make it better or more simple. </p> <pre><code>public final class StringValueOf { private StringValueOf () {} // note that int max value is 10 digits final static int [] sizeTable = { 9, 99, 999, 9999, 99999,...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T17:08:02.210", "Id": "51353", "Score": "0", "body": "The `buf.toString()` doesn't do anything. Also, don't you mean to test for `Integer.MIN_VALUE` and return `-2147483648`?" } ]
[ { "body": "<p>Since it's easy to convert integer digits to their character values ('0' = 0x30..'9' = 0x39), why not:</p>\n\n<pre><code>public static String stringValueOf(int value) {\n if (value == 0) return \"0\";\n if (value == Integer.MIN_VALUE) return \"-2147483648\";\n\n final boolean negative = value &...
{ "AcceptedAnswerId": "32125", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T04:24:04.060", "Id": "32109", "Score": "3", "Tags": [ "java" ], "Title": "Implement String's valueOf function, code review request" }
32109
<p>I am currently working on an app and have some issues with the date handling. Found a simple solution, and want your opinion. First thing, that I want to achieve:</p> <ol> <li>I have 2 date format inputs, one is like 2013-09-30 14:20:00 and the other is 30/09/2013 1420</li> <li>Time stamp is given with no day light...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T08:15:54.350", "Id": "51295", "Score": "1", "body": "You should take a look at [`DateTime::createFromFormat`](http://www.php.net/manual/en/datetime.createfromformat.php) and [`DateTime::format`](http://www.php.net/manual/en/datetime...
[ { "body": "<p>Use <a href=\"http://www.php.net/manual/en/datetime.createfromformat.php\" rel=\"nofollow\">DateTime::createFromFormat</a> method to convert datetime strings to DateTime object:</p>\n\n<pre><code>$date1 = DateTime::createFromFormat('Y-m-d H:i', '2013-09-30 14:20');\n$date2 = DateTime::createFromFo...
{ "AcceptedAnswerId": "32124", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T08:12:19.037", "Id": "32120", "Score": "1", "Tags": [ "php" ], "Title": "PHP date reformat function" }
32120
<p>I have written the following Executor:</p> <pre><code>/** * &lt;p&gt;This executor guarantees that there is never more than one element waiting to be executed. If an element is * submitted for execution and another element is still in queue, the newly submitted element replaces the previously * queued element in...
[]
[ { "body": "<p>Here is an alternative that you could use that works single threaded and thus completely without timing issues. However it assumes knowledge of internal logic (Name of the class \"Sleeper\", the way that the executor performs sleeping (by adding a sleeper into the queue) etc.). So neither pretty, ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T10:48:45.647", "Id": "32127", "Score": "4", "Tags": [ "java", "unit-testing", "concurrency" ], "Title": "Testing an Executor" }
32127
<p>The processing is the same, but the response type differs based on whether it's an AJAX request or not.</p> <p>One way I can think of is to store all the response calls inside closure functions, and return once at the end (twice in the function overall because of the first return). That would only make it look a te...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T12:12:45.330", "Id": "51317", "Score": "0", "body": "looks to me like your controller method is actually being used for 3 distinct requests... consider creating an ajax-only controller, a form controller, and a regular controller, t...
[ { "body": "<p><em>Seeing I was asked to post my comment as an answer, I've set about typing this little thing up. It's, essentially, a slightly more verbose version of my initial comment.</em></p>\n\n<p>Well, all in all, a controller action is a method, so the same <em>\"rules\"</em> should apply: 1 type of req...
{ "AcceptedAnswerId": "36181", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T11:08:06.703", "Id": "32128", "Score": "2", "Tags": [ "php", "object-oriented", "laravel" ], "Title": "How do I reduce the if..else soup in this Controller function?" }
32128
<p>I'm using Pygame to create a small game with few rectangle shapes. However, I want to learn more about classes, and I'm trying to use them. I'm very new to classes and inheritance, but I want to learn the best habits possible. I'm using Python 3.3.2.</p> <pre><code>import pygame class Screen(object): ''' Cre...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T06:39:08.417", "Id": "51379", "Score": "1", "body": "See [Prefer composition over inheritance?](http://stackoverflow.com/q/49002/222914)" } ]
[ { "body": "<p>First off, you don't need to explicitly inherit from <code>object</code> when creating classes. In Python 3.x, you can just type <code>class MyClass:</code>, and leave it as that if you aren't inheriting from any other classes.</p>\n\n<p>Secondly, I think your current design is fine, as long as th...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T11:33:31.857", "Id": "32129", "Score": "4", "Tags": [ "python", "object-oriented", "python-3.x", "game", "inheritance" ], "Title": "Creating a game with rectangular shapes...
32129
<p>I just wrote this tiny library called <a href="https://github.com/dhilipsiva/isRTL.coffee" rel="nofollow">isRTL.coffee</a> to determine the direction of the text. Is there any better way of doing this?</p> <pre><code>rtlChars = '\u0600-\u06FF' # Arabic - Range rtlChars += '\u0750-\u077F' # Arabic Supplement - Rang...
[]
[ { "body": "<p>Yep, it's possible to improve. You can simply do:</p>\n\n<pre><code>window.isRTL = (value) -&gt;\n reRTL.test value\n</code></pre>\n\n<p>Another way to improve is the way you declare your special characters. Right now, it's confusing between the <code>=</code> and <code>+=</code>. Here is anoth...
{ "AcceptedAnswerId": "32132", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T12:28:09.447", "Id": "32131", "Score": "5", "Tags": [ "javascript", "performance", "coffeescript", "i18n", "unicode" ], "Title": "isRTL.coffee library to determine if a...
32131
<p><strong>HTML</strong></p> <pre><code>&lt;!Doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Welcome To DPS Raipur&lt;/title&gt; &lt;link rel="icon" type="image/png" href="logo.gif" /&gt; &lt;link rel="stylesheet" type="text/css" href="index.css"&gt; &lt;/head&gt; &lt;body&g...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T13:50:23.340", "Id": "51333", "Score": "0", "body": "have you done any searching for what you are asking here? this Question smells of \"Off-Topic\" for Code Review." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate...
[ { "body": "<p>Yes </p>\n\n<p>the code will auto align to the user's browser window, as long as the browser window is greater than <code>1200px</code></p>\n\n<p><strong>Second Question</strong></p>\n\n<p>if you keep the files on your computer they will not be online, you have to host the pages on a web server an...
{ "AcceptedAnswerId": "32137", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T13:25:14.893", "Id": "32135", "Score": "3", "Tags": [ "html", "beginner", "css" ], "Title": "Will this code adjust its alignments automatically with respect to the user's scree...
32135
<p>I wrote <a href="https://github.com/dhilipsiva/dssudokusolver">DSSudokuSolver</a> - a sudoku solving algorithm a while back. Is there any possibility that this algorithm can be improved?</p> <p><strong>Original Algorithm:</strong></p> <pre><code>CleanElements = function(comp_ary, Qsudoku){ for(i=0; i&lt;9; i++...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T15:20:38.540", "Id": "51344", "Score": "0", "body": "You should generally avoid adding properties to `window`." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T23:45:59.327", "Id": "63730", "Sc...
[ { "body": "<p>It's not a huge improvement, just taking a stab at a few slight tweaks:</p>\n\n<pre><code>var sudoku = {\n CleanElements:function(comp_ary, Qsudoku){\n var i_factor,\n j_factor,\n i_min,\n i_max,\n i_index,\n j_index,\n in...
{ "AcceptedAnswerId": "38273", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T14:49:02.187", "Id": "32138", "Score": "7", "Tags": [ "javascript", "optimization", "algorithm", "sudoku" ], "Title": "DSSudokuSolver - A JavaScript Sudoku solving algorith...
32138
<p>After recently getting a bulk of work done on my WebAPI service layer, I thought I'd post some of my working on here for you guys to tear apart, generally, most of it 'feels' mostly okay, but I know there are areas for improvement. Hopefully no screaming issues with it:</p> <p>Someone is going to quote me Ayende, n...
[]
[ { "body": "<p>I do mostly Windows development so I might not be the experienced eye you're looking for in terms of ASP.NET MVC, but I'll share a couple thoughts anyway:</p>\n\n<ul>\n<li><strong>Your default/parameterless constructor for the <code>AuthHandler</code> class is redundant</strong> and can be removed...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T14:51:08.590", "Id": "32139", "Score": "6", "Tags": [ "c#", "design-patterns", "asp.net-mvc-4" ], "Title": "Unit of work, Ninject, Repository and WebAPI implementation" }
32139
<p>This is a simple script that I use for wrapping a selected word in a textarea field. I'm looking to:</p> <ol> <li><p>make sure my logic is valid/see what others have done in a relative context.</p></li> <li><p>request improvements to the OO approach I'm going for.</p></li> </ol> <pre><code>Formatter = {}; Form...
[]
[ { "body": "<p>One comment I might suggest is your hard reference to mass_message, consider passing that in as part of your event data, as it makes the code more re-usable (Several instances of your editor on a page?)</p>\n\n<p>A thought to consider is to swap your hard b and i tags to instead define css classes...
{ "AcceptedAnswerId": "32151", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T15:26:49.193", "Id": "32140", "Score": "6", "Tags": [ "javascript", "jquery", "object-oriented" ], "Title": "Object Oriented JavaScript optimization" }
32140
<p>I'm learning DB design. How would you change the following schema which tries to replicate Stack Overflow's functionality:</p> <pre><code>create_table "questions", :force =&gt; true do |t| t.text "question", :null =&gt; false t.text "description", :null =&gt; false t.integer "u...
[]
[ { "body": "<p>Your answers table doesn't actually have an answerID, which is later referenced in your answer comments.</p>\n\n<p>Your link tables for comments, I would have a primary key assigned that is separate from the answerid, since you don't want a composite key between answerID and comment (Think about u...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T15:28:16.340", "Id": "32141", "Score": "4", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Critique my Stack Overflow schema" }
32141
<p>I've asked <a href="https://codeclimate.com/" rel="nofollow noreferrer">Code Climate</a> to <a href="https://codeclimate.com/github/wconrad/ftpd" rel="nofollow noreferrer">generate metrics</a> for the <a href="https://github.com/wconrad/ftpd/tree/94beb23d544e8d8d5a6e1c0d6731ae7f5fa3a62f" rel="nofollow noreferrer">ft...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T19:33:20.523", "Id": "51360", "Score": "1", "body": "what about using a \"real\" state machine instead of a switch implementation ? If you don't want to use a gem like [state_machine](https://github.com/pluginaweek/state_machine) yo...
[ { "body": "<h3>EDIT</h3>\n\n<p>the more I think about it, the more it seems obvious that a parser would be more adapted to this problem than a state machine. Unfortunately, I don't know much about writing parsers...</p>\n\n<h3>ORIGINAL ANSWER</h3>\n\n<p>Maybe you could try to create one class per state :</p>\n\...
{ "AcceptedAnswerId": "32157", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-10-02T16:08:51.040", "Id": "32144", "Score": "6", "Tags": [ "ruby", "server", "state-machine", "cyclomatic-complexity", "ftp" ], "Title": "State machine for handling Telnet s...
32144
<p>I'm doing a infix to postfix conversion. The code works, but here are some points I want to improve</p> <p>1) In the line of </p> <pre><code>while ((!operators.empty())&amp;&amp;(order(operators.top()) &gt;= order(token[0]))) </code></pre> <p>If the condition order changes ( check the stack empty later), there'll...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T15:57:22.683", "Id": "51404", "Score": "0", "body": "To improve it I would write it in a language designed for parsing. Have a look at flex and yacc(bison)." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-1...
[ { "body": "<blockquote>\n <p>If the condition order changes ( check the stack empty later), there'll be a segmentation fault (because I'm calling operators.top() which is NULL)</p>\n</blockquote>\n\n<p>Calling top() on an empty queue is even worse then returning <code>NULL</code>. It is actually <strong>undefi...
{ "AcceptedAnswerId": "32193", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T19:25:33.877", "Id": "32155", "Score": "2", "Tags": [ "c++", "parsing", "tree" ], "Title": "Arithmetic expression parsing, and converting infix to postfix notation" }
32155
<p>This code review request is <em>tightly coupled</em> with <a href="https://stackoverflow.com/questions/19129232/lifespan-of-dbcontext-in-a-wpf-application">this SO question</a>, this is the solution I implemented to solve the problem being asked about there.</p> <p>All my ViewModels get constructor-injected with a ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T07:46:20.370", "Id": "51381", "Score": "0", "body": "AFAICT you don't need to throw away the context? http://code.msdn.microsoft.com/How-to-undo-the-changes-in-00aed3c4" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
[ { "body": "<p>Somewhat similar but still a bit different approach is to encapsulate your context into some container class and put this wrapper into IoC container instead of context itself. Might look like this:</p>\n\n<pre><code>interface IContextManager&lt;TContext&gt; : IDisposable\n{\n TContext Context ...
{ "AcceptedAnswerId": "32163", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-02T20:03:29.787", "Id": "32156", "Score": "4", "Tags": [ "c#", "entity-framework", "wpf", "dependency-injection" ], "Title": "Enabling discard pending changes on DbContext" }
32156
<p>I'm trying to do something like this:</p> <pre><code>var loudDogs = dogs.Where(async d =&gt; await d.IsYappyAsync); </code></pre> <p>The "IsYappyAsync" property would return a <code>Task&lt;bool&gt;</code>.</p> <p>Obviously this isn't supported, so instead I've built an extension method called WhereAsync.</p> <p...
[]
[ { "body": "<p>There are several ways to achieve what you're after and it depends on whether you want the results drip fed to you as they're available or whether you're happy to have them all in one bang.\nThe way you've implemented your method gives it all in one bang - which is fine.</p>\n\n<p>A shorter implem...
{ "AcceptedAnswerId": "32162", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T01:55:28.600", "Id": "32160", "Score": "13", "Tags": [ "c#", "linq", "task-parallel-library", "async-await" ], "Title": "Filtering a collection by an async result" }
32160
<p>Since Entity Set does not support asqueryable, I have to do this. How can I reduce the amount of redundant code between the two methods?</p> <pre><code>public static IQueryable&lt;T&gt; WhereCreateWithin&lt;T&gt;(this IQueryable&lt;T&gt; query, DateManager.TimeRange timeRange, DateTime? beginDayParam = null) where...
[]
[ { "body": "<p>Given that the logic is exactly the same (i did not do a line by line comparision), one of the possible solutions whould be:</p>\n\n<pre><code>private static TCollection WhereCreateWithin&lt;T, TCollection&gt;(TCollection query,\n DateManager.TimeRange timeRange, \n DateTim...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T04:23:23.887", "Id": "32161", "Score": "4", "Tags": [ "c#", "linq" ], "Title": "Code duplication where impliment extension method for IEnumerable and IQueryable on entity set" }
32161
<p>Within a function, I want to grab a set of parameters from a named array. What is the most efficient way of testing if the parameter exists in the array, and if it does, use it as a variable? I came up with a few alternatives.</p> <pre><code>target = $('#page_links') if ( functionobject.target ) { target = func...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T08:36:10.633", "Id": "51384", "Score": "0", "body": "I think the terminology in your question might be bad. Instead of \"parameters from a named array\", you probably mean \"attributes in an object\". Arrays are supposed to sequence...
[ { "body": "<p>I would say</p>\n\n<pre><code>var target = functionobject.target || $('#page_links');\n</code></pre>\n\n<p>How did I arrive at that? The important point to get across is that no matter what happens, you want to assign <em>something</em> to <code>target</code>. One first attempt to express that w...
{ "AcceptedAnswerId": "32168", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T08:09:05.353", "Id": "32166", "Score": "1", "Tags": [ "javascript" ], "Title": "Best way to retrieve parameters from associative array in javascript?" }
32166
<p>I want a second copy of an <code>std::vector</code> in which all elements are inverted, e.g. <code>0x01</code> in the first vector should be <code>0xFE</code> in the second. </p> <p>Is this a good solution?</p> <pre><code>std::vector&lt;uint8_t&gt; first_list = {0x01, 0x10, 0x32, 0x1A }; std::vector&lt;uint8_t&gt;...
[]
[ { "body": "<p>You can utilize <code>std::transform</code> here (I'll assume C++11 for the lambda):</p>\n\n<pre><code>int main()\n{\n std::vector&lt;uint8_t&gt; first_list = {0x01, 0x10, 0x32, 0x1A};\n std::vector&lt;uint8_t&gt; second; \n std::transform(first_list.begin(), first_list.end(), std::back_i...
{ "AcceptedAnswerId": "32190", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T08:22:42.563", "Id": "32167", "Score": "2", "Tags": [ "c++", "c++11", "bitwise" ], "Title": "Copy and bit-invert ints in an std::vector" }
32167
<p>I have three types alert dialogue. Each alert dialogue behave differently but I don't like to write three types of alert dialogue in same class because it extends the class size drastically. Here are the three alert dialogue given below:</p> <pre><code>public boolean onJsAlert(WebView view, String url, String messa...
[]
[ { "body": "<p>I also like to keep classes short, but I don't think it should influence your design. You can put the alert building code in another class file if you really want to. </p>\n\n<p>I would not try to coerce the geolocation alert with onJsAlert/onJsConfirm since it is quite different. But you could...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T09:51:31.180", "Id": "32175", "Score": "1", "Tags": [ "java", "android" ], "Title": "How to reduce code from different alert-dialogue?" }
32175
<p>I am using Codeigniter and it's ActiveRecord.</p> <p>I had this idea for a base class that provided a generic getter/setter for doing simple queries on a database. I have a lot of database objects that could benefit from not having to duplicate the basic query patterns.</p> <p>Instead of writing functions whose so...
[]
[ { "body": "<p>Well, for a kickoff, you're concerned about your code's reusability can trump its undeniable downsides. But, if you look at one or two things more closely, your code <em>isn't</em> as reusable as perhaps you think it is:</p>\n\n<pre><code>// Parsing arguments\n$params = (isset($args[0])) ? $args[0...
{ "AcceptedAnswerId": "32182", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T10:43:09.983", "Id": "32176", "Score": "2", "Tags": [ "php", "design-patterns", "mvc", "database", "codeigniter" ], "Title": "Builder pattern for Codeigniter ActiveReco...
32176
<p>I've got the following query builder. Some of the cases have the same piece of code (those that have a parameter).</p> <p>I know it's not good to duplicate code that much if at all.</p> <p>How would you suggest I improve this loop?</p> <pre><code>for ($i = 0; $i &lt; $len; ++$i) { switch ($conditions[$i]['con...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T17:43:17.370", "Id": "53979", "Score": "1", "body": "Get rid of it, and use an existing querybuilder, that has been proven to work. Doctrine, for example. It'll save you a whole lot of time... clone its repo and edit the code, if yo...
[ { "body": "<p>I just separated out the cases with no count increase. I am sure somebody more experienced could come up with a better solution.</p>\n\n<pre><code>for ($i = 0; $i &lt; $len; ++$i) {\nif 'version' = 'no_credits':\n $sql .= ' AND `musers`.`credits` = 0';\n\nelse if 'version' = 'never_ta...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T12:20:21.900", "Id": "32179", "Score": "3", "Tags": [ "php", "mysql" ], "Title": "Query builder improvment" }
32179
<p>How can I refactor this?</p> <pre><code>public static IQueryable&lt;T_COMPANY&gt; WhereTotalTransactionOrShowCaseAtLeast(this IQueryable&lt;T_COMPANY&gt; query, int minimum, DateTime? date = null) { if (date == null) { query = query.Where(company =&gt; (company.Products.Count + company.References.Co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T14:28:46.703", "Id": "51395", "Score": "1", "body": "You have a lot of repetition in your 'let' statements, why not separate the building of the initial 'result' object out, without the final comparison, so you aren't re-writing tho...
[ { "body": "<p>From what I can understand you are looking for a way to consolidate this code into one function and specify that the comparrison with minimum can either be less than or greater than or equal to. You could try something like this</p>\n\n<pre><code>public static IQueryable&lt;T_COMPANY&gt; WhereTota...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T13:35:50.510", "Id": "32183", "Score": "1", "Tags": [ "c#", "linq" ], "Title": "Refactor similar queries but reverse side of inequality operator" }
32183
<p>Be as harsh as you can! I'm trying to improve my coding style and would like to know if there is anything I could improve.</p> <p>EDIT: To make this fair, The person who provides the most helpful tips (both in quantity and quality) will get marked as the answer</p> <p>The code below is the JavaScript file for a CM...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T14:54:50.670", "Id": "51398", "Score": "1", "body": "At first glance I'd cache `$(\"#dashBody\")` and `$(\"#topDash\")`, rather than keep searching the DOM every time you want to reference them." }, { "ContentLicense": "CC B...
[ { "body": "<p>I'd cache the following jQuery objects...</p>\n\n<pre><code>var $dashBody = $(\"#dashBody\");\nvar $topDash = $(\"#topDash\");\nvar $loadProgress = $(\".loadProgress\");\nvar $loadingText = $(\".loadingText\");\n</code></pre>\n\n<p>In function <code>clearEditSection()</code> you do a second search...
{ "AcceptedAnswerId": "32187", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T14:40:18.577", "Id": "32184", "Score": "6", "Tags": [ "javascript", "jquery", "ajax" ], "Title": "JavaScript file for a CMS application" }
32184
<p>I have a grid which allows a user to enter a new Grid item. If the grid item exists or the <code>tb</code> is empty it displays the error. Here's the code I came up with.</p> <p>Can anybody think of a cleaner or more efficient way of doing so? Thinking about it now, I guess I could have done it all in one function...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T15:14:42.907", "Id": "51400", "Score": "0", "body": "Malachi, I used your edit, but how can I had that code block when I post" } ]
[ { "body": "<p>Some people say that adding private functions which are only called in one place in a class clutter the \"private interface\" of the class. However I actually do prefer it in some cases. In your case I think it makes sense as it makes <code>InsertTrack</code> easier to read so I would not merge th...
{ "AcceptedAnswerId": "32203", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T15:07:35.027", "Id": "32185", "Score": "2", "Tags": [ "c#", "linq", "asp.net" ], "Title": "Check if Item exists in Grid using Linq" }
32185
<p>Here's some code that I ran through jsperf to assess its performance. The first test (named <strong>EvalLengthBefore++</strong> in the images below) is the way I would consider normally looping through the elements of an array:</p> <pre><code>var arr = []; for (var x = 0; x &lt; 1000; x++) { arr.push(Math.random(...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T15:20:37.043", "Id": "51401", "Score": "8", "body": "Not sure if this belongs to codereview.SE but it does look like a pretty interesting question." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T15:2...
[ { "body": "<p>Since you asked this question here rather than on Stack Overflow, I'm going to propose this <a href=\"http://jsperf.com/elementloop/2\" rel=\"nofollow\">countdown iteration</a>:</p>\n\n<pre><code>for (var y = arr.length - 1; y &gt;= 0; --y) {\n //do some maths\n var el = arr[y];\n el++;\n...
{ "AcceptedAnswerId": "32233", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T15:15:13.347", "Id": "32186", "Score": "11", "Tags": [ "javascript", "performance", "array" ], "Title": "Why is this code so much faster (relatively) in IE7?" }
32186
<p>I have a large C# Dictionary of string keys and boolean values. Background on the reason for it is this: my program builds up a bunch of the same objects from two different sources, and then compares all the properties to see if there are any disparates. But I want to ignore the differences where I know one source h...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T17:57:46.353", "Id": "51412", "Score": "2", "body": "We need some more context to know how best to help. What is this dictionary used for? Where/how is it modified? My gut reaction seeing the dictionary defined like that is that ...
[ { "body": "<p>Dictionaries don't preserve the order of their entries, so list all keys with <code>false</code> values first, then all keys with <code>true</code> values. I would also sort the keys alphabetically within each group.</p>\n\n<pre><code>// Represents fields that are actually retrieved from TP data\...
{ "AcceptedAnswerId": "32221", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T15:22:13.670", "Id": "32188", "Score": "6", "Tags": [ "c#", "hash-map" ], "Title": "How best to differentiate boolean values in a long list?" }
32188
<p>Is this query acceptable in terms of performance (I get the correct data) or can it be optimized?</p> <pre><code>SELECT bankInstitution.name, person.firstName, person.surname, offer.offerId, bank.personId, bank.bankOtherName, bank.sortCode, bank.number, loan.loanId offer.camp...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T20:32:47.167", "Id": "51420", "Score": "0", "body": "this might be a dumb question but what is `:campaignId` referring to?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T21:05:21.060", "Id": "514...
[ { "body": "<p>There is an illegal comma before <code>FROM</code>.</p>\n\n<p>I would put <code>bank.isCurrent = 1</code> in the <code>WHERE</code>-clause instead of as a join condition.</p>\n\n<p>For consistency, I would reverse the equalities in the join conditions:</p>\n\n<ul>\n<li><code>JOIN loan ON loan.pers...
{ "AcceptedAnswerId": "33486", "CommentCount": "15", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T18:35:15.840", "Id": "32197", "Score": "1", "Tags": [ "optimization", "performance", "sql", "sql-server" ], "Title": "SQL with several joins" }
32197
<p>I have a server-client environment, where the client connects and synchronizes data with the server every 5 second.</p> <p>For synchronizing I use a background thread on the client which works fine, but on one specific hardware the method GetNetworkAvailable throws out of memory exceptions occasionaly. The errors o...
[]
[ { "body": "<ol>\n<li><p>I would do the waiting for interval at the end also with an event - I find it cleaner. Something like this:</p>\n\n<pre><code>AutoResetEvent _syncWaitEvent = new AutoResetEvent(false);\n\n....\n\n// I assume there is a way for external callers to stop sync\npublic void StopSync()\n{\n ...
{ "AcceptedAnswerId": "32201", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T19:17:09.363", "Id": "32198", "Score": "3", "Tags": [ "c#", "multithreading", "web-services" ], "Title": "Synchronization-Thread with Server every 5 secs" }
32198
<p>I have made this program to find out the first and following sets of the productions:</p> <pre><code>E-&gt;TA A-&gt;+TA A-&gt;0 T-&gt;FB B-&gt;*FB B-&gt;0 F-&gt;(E) F-&gt;# </code></pre> <p>Here epsilon(NULL) is taken as 0: </p> <pre><code> #include&lt;stdio.h&gt; #include&lt;ctype.h&gt; char a[8][8]; stru...
[]
[ { "body": "<p>To start at the top, your two structures <code>firTab</code> and <code>folTab</code> could probably be\ncombined. And given a name than means something.</p>\n\n<p>Your embedded constants 8 and 5 throughout should be replaced by #defined\nconstants to make changing them easier.</p>\n\n<p>You would ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T19:25:04.913", "Id": "32199", "Score": "4", "Tags": [ "c", "parsing" ], "Title": "Computing first and following sets (compiler design)" }
32199
<p><strong>This question is the first draft, my new revised code is here: <a href="https://codereview.stackexchange.com/questions/32246/anagrams-for-a-given-input-2-0">Anagrams for a given input 2.0</a></strong></p> <p>Here is my code that I wrote, which basically lists the anagrams for a given input.</p> <p>I did t...
[]
[ { "body": "<p>The organisation of the code is not the best as some methods are probably doing more than they should.</p>\n\n<p>You should write a method to check whether two words are anagrams or not.</p>\n\n<p>There is not point in storing the number of anagrams in k as it corresponds to the length of the list...
{ "AcceptedAnswerId": "32215", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T22:13:04.470", "Id": "32204", "Score": "6", "Tags": [ "java", "optimization", "array" ], "Title": "Anagrams for a given input" }
32204
<p>This is a simple console menu that just holds a main menu and a few menu "buttons" (numbers and titles which the user has to enter for the button to do its action). It does not need submenus or more complicated input handling.</p> <p>I went with an object-oriented approach and defined three classes: <code>Menu</cod...
[]
[ { "body": "<p>I think display() and userInput() would be clearer if you did it like this:</p>\n\n<pre><code>def display(self):\n \"\"\"\n Display the menu alongside the navigation elements\n \"\"\"\n response = None\n while response is None:\n # Display menu buttons\n for button in ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T23:45:35.043", "Id": "32207", "Score": "3", "Tags": [ "python", "console" ], "Title": "Console user main menu" }
32207
<p>Please feel free to be as harsh as possible.</p> <p><strong>Implementation file:</strong></p> <pre><code>#include "Stack.h" #include &lt;iostream&gt; using namespace std; // Initializes an empty Stack. Stack::Stack() { this-&gt;head = new node(); this-&gt;num_elements = 0; // set default values for h...
[]
[ { "body": "<ul>\n<li><p><a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\">Do not use <code>using namespace std</code></a>.</p></li>\n<li><p>In the constructor and <code>push()</code>, it looks like you're calling <code>new</code> on a function. It should...
{ "AcceptedAnswerId": "32211", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T00:28:55.017", "Id": "32210", "Score": "7", "Tags": [ "c++", "linked-list", "stack" ], "Title": "Linked stack implementation in C++" }
32210
<p>I would like to do these actions step by step:</p> <ol> <li>first DB update</li> <li>copy file</li> <li>unlink file</li> <li>second DB update</li> </ol> <p>It is working, but I don't know if my code is correct/valid:</p> <pre><code>$update1 = $DB-&gt;query("UPDATE..."); if ($update1) { if (copy("...")) ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T07:17:49.643", "Id": "51452", "Score": "0", "body": "What class is `$DB` an instance of..." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T12:23:19.027", "Id": "51478", "Score": "0", "body...
[ { "body": "<blockquote>\n <p>Is it possible to use if statement this way?</p>\n</blockquote>\n\n<p>Yes.</p>\n\n<p>Whether it is a good style depends on other factors.</p>\n\n<p>Let us look at a few alternatives. First, your code (with cuddled braces):</p>\n\n<pre><code>if ( $update1 ) {\n if ( copy( \"...\"...
{ "AcceptedAnswerId": "32332", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T01:01:17.917", "Id": "32212", "Score": "3", "Tags": [ "php" ], "Title": "Using if statement in PHP" }
32212
<p>So I have this Pygame 3.3.2 code of 2 classes. I tried to make it as simpler as possible, but ofcourse to show the problems I have with thedesign.</p> <pre><code>import pygame import sys class MainWindow(object): ''' Handles main surface ''' def __init__(self, width, height): self.WIDTH = width ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T23:03:43.953", "Id": "51552", "Score": "0", "body": "I suspect I'm doing a wrong object composition." } ]
[ { "body": "<p>When you're composing, think about how you want to access the components you're putting together. In this example, you are asking the window to include a DrawRect that always draws to a 50 x 50 pixsel square. Does the window really need to include that rect? The DrawRect has all the info it needs...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T01:50:53.747", "Id": "32213", "Score": "3", "Tags": [ "python", "python-3.x", "pygame" ], "Title": "Object Composition" }
32213
<p>I was trying to solve a challenge. The execution time should not exceed 5s, but for some value my code took longer. I want to know if I can optimize my code for performance.</p> <pre><code>public class Solution { int n;long k;int count=0; public static void main(String[] args) { new Solution().readI...
[]
[ { "body": "<p>What exactly your code does? It is not obvious, maybe you should name your variables better. Specially <code>count = (a&gt;b ? a-b : b-a) == k ? count+1 : count;</code>\nWhat <code>a</code> anb <code>b</code> is? <code>count</code> of what?</p>\n\n<p>Instead of splitting line twice. Split it once ...
{ "AcceptedAnswerId": "32229", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T03:32:56.890", "Id": "32217", "Score": "1", "Tags": [ "java", "optimization", "performance", "multithreading", "programming-challenge" ], "Title": "Optimize calculation...
32217
<p>I have the following method that's in a common library. I want to know how to write it better, but mostly, I want to know how to think about this better so I don't end up with code like this.</p> <pre><code>public virtual void PrintConsoleAndLog(string verboseMessage = null, Exception e = null, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T05:28:12.550", "Id": "51440", "Score": "5", "body": "Which logger are you using? Instead of doing logging everything twice (once with your logger and once to console) can't you just reconfigure your logger to also write to the conso...
[ { "body": "<p>In the comments it was already mentioned to configure the logger to determine the logging target which avoids logging everything twice.</p>\n\n<p>Another thing to improve: Eliminate duplicate code (statements and expressions).\nFrom looking at the code there are many things which are repeated over...
{ "AcceptedAnswerId": "32228", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T04:48:49.710", "Id": "32218", "Score": "3", "Tags": [ "c#", "console", "error-handling" ], "Title": "Console printing and logging method for a common library" }
32218
<p>I have a implementation of following code block,</p> <pre><code>public class FileFormatConversion { public static enum File_TYPES { PDF, PNG, OTHERS, ALL } public static void processOtherFileType(String arg1) { System.out.println("Other file output -- " + arg1 + " file"); } public static void processPNGPD...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T05:33:55.413", "Id": "51441", "Score": "1", "body": "Please provide a more concrete use case, with real working code, not pseudocode, so that we can better understand your problem." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>To avoid the <a href=\"http://c2.com/cgi/wiki?SwitchStatementsSmell\">messy <code>switch</code> block</a>, you should probably create an interface or abstract class called <code>FileConversionHandler</code>:</p>\n\n<pre><code>public abstract class FileConversionHandler {\n public abstract void ...
{ "AcceptedAnswerId": "32227", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T05:09:10.357", "Id": "32219", "Score": "3", "Tags": [ "java", "optimization" ], "Title": "Optimizing code block using Switch Case" }
32219
<p>Here is my code. Is there anyway to make it more efficient?</p> <pre><code>/* IN: string to have characters reversed OUT: string containing characters in reversed order */ char* reverStr(const char *str) { char* revStr = (char*)malloc(strlen(str)); int i; for(i = strlen(str)-1; i &gt;= 0; i-...
[]
[ { "body": "<p>What about this:</p>\n\n<pre><code>/*\nIN: string to have characters reversed\nOUT: string containing characters in reversed order\n*/\nchar* reverStr(const char *str)\n{\n int index=strlen(str);\n char* revStr = (char*)malloc(index--);\n int destIndex=0;\n while (0&lt;...
{ "AcceptedAnswerId": "32237", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T09:31:15.827", "Id": "32234", "Score": "4", "Tags": [ "c", "strings" ], "Title": "Is this the best way to reverse a string in C (not in place)?" }
32234
<p>I wonder if there is a more "functional" way of implementing something like this:</p> <pre><code>@months.zipWithIndex.foreach { case (month, index) =&gt; if (index%3 == 0) { &lt;tr&gt; } &lt;td&gt;@month&lt;/td&gt; if (index%3 == 0) { &lt;/tr&gt; } } </code></pre> <p>Can these t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-08T13:45:24.253", "Id": "51776", "Score": "0", "body": "There are many ways, of which my answer is one example, but the key is to structure your code around rows rather than months. Unless the list of months is empty, you will always ...
[ { "body": "<p>I don't believe there's any kind of functional looping structure that will allow you to obtain this behavior without the 'if' statements. The fact is, you have to include something conditionally, and so you have to check that condition somehow. This is a bit more idiomatic way to do it, I believe,...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T13:15:47.827", "Id": "32239", "Score": "1", "Tags": [ "scala", "functional-programming" ], "Title": "More functional approach" }
32239
<p>This is very simple: the user inputs his/her name, the program then truncates it on a consonant at a specified position, if possible if not it will truncate it on a vowel. It then adds an extension from a list of extensions to make the complete nickname and displays it.</p> <pre><code> /** * @author :...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T14:33:54.017", "Id": "51483", "Score": "0", "body": "Why is this used? `nickExtension.size() - 0`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T14:36:46.703", "Id": "51484", "Score": "0", ...
[ { "body": "<pre><code>private static String getName(String prompt){\n String input=JOptionPane.showInputDialog(null,prompt);\n return input;\n}\n</code></pre>\n\n<p>I like what you've done here. But I would rename the method to <code>getInput(String prompt)</code> since you've made it reusable. You can ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T13:48:41.960", "Id": "32240", "Score": "3", "Tags": [ "java", "strings" ], "Title": "Simple Nick Namer" }
32240
<p>A few years ago I started building a tiny (~300 SLOC) JavaScript framework for scalable and maintainable Single-Page-Applications written in CoffeeScript.</p> <ul> <li><a href="https://github.com/flosse/scaleApp" rel="nofollow">GitHub</a></li> <li><a href="http://www.scaleapp.org/" rel="nofollow">www.scaleapp.org</...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T14:09:08.947", "Id": "32241", "Score": "4", "Tags": [ "node.js", "api", "coffeescript" ], "Title": "Core class of a JavaScript framework for Single-Page-Applications" }
32241
<p>Just got done implementing a shortest path algo of a unit cost DAG BFS in Hadoop and wanting to get anyone's opinion on how I could have done it better. The main issue I see is that I lose the parallel nature of hadoop by forcing the mappers to wait for the output of the previous mapper before beginning.</p> <p>The...
[]
[ { "body": "<p>I'm not familiar with Hadoop, take my advice with care.</p>\n\n<ol>\n<li><p>Are you sure that you want to use the default charset?</p>\n\n<blockquote>\n<pre><code>try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, Charset.defaultCharset()))) {\n</code></pre>\n</blockquote>\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T14:21:48.490", "Id": "32243", "Score": "6", "Tags": [ "java", "algorithm", "graph", "breadth-first-search", "hadoop" ], "Title": "Shortest Path in a Unit Cost DAG BFS in H...
32243
<p><strong>This question follows on from :<a href="https://codereview.stackexchange.com/questions/32204/anagrams-for-a-given-input">Previous Question</a></strong></p> <p>Here is what my reworked code looks like. I neatened it up as much as I could. Changed some of the semantics of it. I also tried to add some faster e...
[]
[ { "body": "<p>Four issues with <code>private static boolean checkMatch(String word, String candidate)</code>:</p>\n\n<ul>\n<li><code>checkMatch</code> is not as descriptive as a name could be. I think <code>private static boolean isAnagram(String a, String b)</code> would be better. I would also rename the pa...
{ "AcceptedAnswerId": "32259", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T15:03:07.863", "Id": "32246", "Score": "2", "Tags": [ "java", "optimization", "array" ], "Title": "Anagrams for a given input 2.0" }
32246
<p>I'm new to using fragments in Android. I'm working on an app using a sliding panel layout and I just came up with an idea for changing my fragments. I decided to create the following method:</p> <pre><code> private void changeFrag(Object newFrag){ // Insert the fragment by replacing any existing fragment...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T17:20:51.823", "Id": "51516", "Score": "0", "body": "have you tested this? does it work?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T18:20:10.527", "Id": "51529", "Score": "1", "body"...
[ { "body": "<p>You could make it more dynamic. Because this method adds the Fragment only to the <code>R.id.fragment_secondpane</code> layout. If this is all what you desire, it's ok. Otherwise add a parameter for the layout. This way you can use your method to add a Fragment to different layouts.</p>\n\n<p>Beca...
{ "AcceptedAnswerId": "32328", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T15:07:58.033", "Id": "32247", "Score": "1", "Tags": [ "java", "android", "casting" ], "Title": "Can casting to fragment be more efficient than using a variable?" }
32247
<p>Considering the following Makefile:</p> <pre><code>%.o: %.cpp $(C) $(CF) -c $&lt; -o $@ Audio/%.o: Audio/%.cpp $(C) $(CF) -c $&lt; -o $@ Game/%.o: Game/%.cpp $(C) $(CF) -c $&lt; -o $@ Generation/%.o: Generation/%.cpp $(C) $(CF) -c $&lt; -o $@ Input/%.o: Input/%.cpp $(C) $(CF) -c $&lt; -o $@ ...
[]
[ { "body": "<p>All of these rules</p>\n\n<pre><code>Audio/%.o: Audio/%.cpp\n $(C) $(CF) -c $&lt; -o $@\n\n# etc.\n</code></pre>\n\n<p>are redundant! Your first pattern rule</p>\n\n<pre><code>%.o: %.cpp\n $(C) $(CF) -c $&lt; -o $@\n</code></pre>\n\n<p>already covers them all.</p>\n", "comments"...
{ "AcceptedAnswerId": "32252", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T15:21:25.113", "Id": "32249", "Score": "4", "Tags": [ "makefile" ], "Title": "How do I simplify the following slice of a Makefile?" }
32249
<pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; void getUserNum(int &amp;); int rFib(int n); void dispSeq(std::vector&lt;int&gt; &amp;vRef); int main() { int userNum; getUserNum(userNum); rFib(userNum); return 0; } void getUserNum(int &amp;refVal) { std::cout &lt;&lt; "Enter a posi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T16:58:19.000", "Id": "51511", "Score": "2", "body": "Asking how to do something is best done on SO. Though a good code review here will definitely push you in the correct direction." } ]
[ { "body": "<p>Its normal to put parameter names even in the declarations:</p>\n\n<pre><code>void getUserNum(int &amp;);\n</code></pre>\n\n<p>We use this to help us identify what the function is doing.</p>\n\n<p>In C++ the <code>'*'</code> and the <code>'&amp;'</code> are part of the type information. So it is u...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T16:44:33.237", "Id": "32251", "Score": "1", "Tags": [ "c++", "recursion", "beginner", "vectors" ], "Title": "How can I store the fibonacci sequence in a vector during each rec...
32251
<p>I'm working my way through <em>The Java Programming Language, Fourth Edition - The Java Series</em>. This is Exercise 7.3:</p> <blockquote> <p>Write a program that calculates Pascal's triangle to a depth of 12, storing each row of the triangle in an array of the appropriate length and putting each of the row arr...
[]
[ { "body": "<p>There are 2½ things wrong with your code, otherwise it's fine.</p>\n\n<ol>\n<li><p>Use exception handling with <code>try</code>/<code>catch</code> for exceptional circumstances, not for trivial bounds checking which you can do! The snippet</p>\n\n<pre><code>try {\n upperLeft = triangle[i - 1]...
{ "AcceptedAnswerId": "32260", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T18:20:17.320", "Id": "32255", "Score": "4", "Tags": [ "java", "classes" ], "Title": "Critique of Pascal's Triangle Class" }
32255
<p><strong>Reason for script:</strong></p> <p><a href="http://www.w3.org/International/tests/html5/the-dir-attribute/results-dir-auto" rel="nofollow"><code>dir="auto"</code> is an attribute value from the HTML 5 spec with current poor support in IE and Opera browsers</a>. The project I am working on only cares about ...
[]
[ { "body": "<p>My 2 cents:</p>\n\n<ul>\n<li>Code looks really good overall</li>\n<li>In <code>prependOverride</code>, the naming is unfortunate\n<ul>\n<li>The parameter isLTR is really what you request, not what it is</li>\n<li>The var direction really is a boolean, not the direction of the element</li>\n<li>If ...
{ "AcceptedAnswerId": "37593", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T18:32:06.223", "Id": "32256", "Score": "8", "Tags": [ "javascript", "regex", "i18n", "unicode", "dojo" ], "Title": "dir=\"auto\" JavaScript shim for IE" }
32256
<pre><code>public class ArrayList&lt;E&gt; implements List&lt;E&gt; { private static final int defaultMaxSize = 10; private int maxSize; private int size; private int currentPosition; private E[] array; /** * Create a new ArrayList object. * * @param maxSize */ @Suppress...
[]
[ { "body": "<ul>\n<li>First and foremost : why are you writing this class? It doesn't look like an improvement or a specialized version of <code>java.util.ArrayList</code>.</li>\n<li>the <code>insert()</code> contract states : \"Must check that the linked list's capacity is not exceeded.\" (wait, linked list?). ...
{ "AcceptedAnswerId": "32264", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T20:58:42.620", "Id": "32262", "Score": "2", "Tags": [ "java", "array" ], "Title": "Can someone review my implementation of an ArrayList?" }
32262
<p>I wrote a <a href="https://bitbucket.org/bigstones/automatica" rel="nofollow noreferrer">small library</a> to learn Haskell while studying Automata theory. I have <a href="https://softwareengineering.stackexchange.com/q/213441/50398">some concerns</a> on my algorithm to evaluate state reachability. That is, I think ...
[]
[ { "body": "<p>This is neat, methinks. </p>\n\n<p>A couple of questions/points:</p>\n\n<ol>\n<li>Is the <code>|| any (== s') rs</code> part of <code>canReachExcluding</code> necessary?</li>\n<li>In the same definition, the part <code>rs = reach1From s au \\\\ ex</code> takes time linear in the size of <code>ex</...
{ "AcceptedAnswerId": "43812", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T23:37:35.637", "Id": "32266", "Score": "6", "Tags": [ "algorithm", "haskell", "state-machine" ], "Title": "Automata theory, state reachability in Haskell" }
32266
<pre><code>public class KeyValuePair implements Comparable { private Comparable key; private Object value; public KeyValuePair(Comparable key, Object value) { this.key = key; this.value = value; } @Override public int compareTo(Object item) throws ClassCastException { if (!(item i...
[]
[ { "body": "<p>You shouldn't need to throw <code>ClassCastException</code> explicitly; it would be thrown automatically by the JVM if the cast actually fails.</p>\n\n<p>However, you shouldn't have to deal with casting at all if you use Java Generics properly.</p>\n\n<pre><code>public class KeyValuePair&lt;K exte...
{ "AcceptedAnswerId": "32274", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-05T01:31:27.547", "Id": "32267", "Score": "3", "Tags": [ "java" ], "Title": "Can someone review my implementation of a KeyValuePair?" }
32267
<p>So here is my Queue interface:</p> <pre><code>public interface Queue&lt;E&gt; { /** * Add an item to the rear of the queue. * * @param item * Item to be added. */ public void enqueue(E item); /** * Remove and return the item at the front of the queue. * ...
[]
[ { "body": "<p>You should <strong>not</strong> name your interface <code>Queue</code>, since <code>java.util.Queue</code> already exits.</p>\n\n<p>Also it would be helpful if you post the source of <code>SingleLinkedListNode</code>. </p>\n\n<p>The source looks fine to me, you could however add two methods like (...
{ "AcceptedAnswerId": "32293", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-05T01:39:01.847", "Id": "32268", "Score": "1", "Tags": [ "java", "queue" ], "Title": "Can someone review my implementation of a Queue?" }
32268