body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>From times to times I stumble over the following situation:</p> <p>I have got a class with a property that's only used if another property has a particular value, for instance:</p> <pre><code>public enum enum_ConnectionType { Local, Server } public class Session { private enum_ConnectionType _connecti...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-08T17:33:21.877", "Id": "32438", "Score": "0", "body": "What language are you using?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-08T17:35:13.393", "Id": "32439", "Score": "0", "body": "C#, I...
[ { "body": "<p>I would do this using an interface and polymorphism to represent this:</p>\n\n<pre><code>public interface ISession\n{\n void DoSomething();\n\n // Add your properties / method definitions\n}\n\npublic class ServerSession : ISession\n{\n private readonly string _serverName;\n\n public...
{ "AcceptedAnswerId": "20286", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-08T17:01:30.727", "Id": "20280", "Score": "8", "Tags": [ "c#", "object-oriented", "classes", "properties" ], "Title": "Class with a sometimes unused property" }
20280
<p>I have been working on a php driven template engine. This is fairly light weight, and fast from all of my testing, but I was hoping to get some feed back on it. First I would like to show you an example usages before I show the actual library. For full documentation and more examples: <a href="http://plater.phpsnips...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T01:38:05.373", "Id": "32482", "Score": "0", "body": "Have you compared your template engine with Smarty (which is licensed under the LGPL)? http://www.smarty.net/" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "...
[ { "body": "<p><strong>Disclaimer:</strong></p>\n\n<p>If you are just doing this for experience that's fine, but there are already many popular templating engines out there. Trying to compete with them isn't going to be easy or even probable. Sorry to be so blunt about it, but its the truth. Don't expect this to...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-08T17:09:49.160", "Id": "20281", "Score": "4", "Tags": [ "php", "html", "template" ], "Title": "PHP Template Engine" }
20281
<p>It currently takes about 10 minutes to process ~16k teams and ~81k games. I could soon have ~17k teams with ~160k, and multiple sports. I run this as a cron job overnight and store the results in a serialized gzipped array which is processed upon each pageload to sort teams by states for displaying and actually calc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T22:04:45.150", "Id": "32598", "Score": "0", "body": "Sorry if this is a stupid question, I haven't read over your question fully yet, but why are you checking all this data every time? Does it change? If, once its stored, its static...
[ { "body": "<p>Not quite a lot that can be done performance-wise...you have a lot of data to pour over (<code>16,000 * 81,000 = 1,296,000,000 records</code> and with the new data <code>17,000 * 160,000 = 2,720,000,000 records)</code>. You could possibly think of moving over to a faster database (Redis? Cassandra...
{ "AcceptedAnswerId": "27849", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-08T17:14:32.600", "Id": "20282", "Score": "4", "Tags": [ "php", "mysqli" ], "Title": "Improve Speed of RPI Calculation" }
20282
<p>Just a small PHP exercise to write some simple reports, I thought I'd do it without a framework for fun and profit. I'm particularly concerned about the potential for SQL injection, since the user could pass their own values to <code>$_GET['status']</code>.</p> <p>I also understand that <code>mysql_connect()</code>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-08T17:37:04.140", "Id": "32440", "Score": "2", "body": "\"Better equivalents\" do not work the same way, they are better. Using a PDO system will help prevent SQL injection." }, { "ContentLicense": "CC BY-SA 3.0", "Creation...
[ { "body": "<blockquote>\n <p>I also understand that mysql_connect() et. al are deprecated in PHP since 5.5, but I assume better equivalents work the same way.</p>\n</blockquote>\n\n<p>Sort of. MySQLi can work a lot like the the mysql extension, but personally I prefer PDO. Whereas MySQLi has both an OO and a p...
{ "AcceptedAnswerId": "20306", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-08T17:16:43.770", "Id": "20283", "Score": "3", "Tags": [ "php", "mysql", "form" ], "Title": "Database report in PHP" }
20283
<p><strong>Introduction</strong></p> <p>In my Java application, I need to represent the result of an operation. This can either be OK or ERROR + an error message.</p> <hr> <p><strong>Background</strong></p> <p>I have a class to verify the integrity of a directory (e.g. to check that a few conditions hold). If it fi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-08T22:30:51.817", "Id": "32472", "Score": "2", "body": "Are you sure you even need such a class? Why not stick with exceptions?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T09:33:33.807", "Id": "3...
[ { "body": "<p>I do not know the exact requirements, but two simple approaches would be:</p>\n\n<ul>\n<li><p>Just return a String as result. This can either be null or empty (if everything is ok) or the error message (if something is wrong).</p></li>\n<li><p>Throw an exception</p></li>\n</ul>\n\n<p>(Other then t...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-08T17:39:55.217", "Id": "20285", "Score": "7", "Tags": [ "java" ], "Title": "Java - How to represent the result of an operation" }
20285
<p>I'm just wondering if you see any ways I could simplify the following code without making it too difficult for a newbie to understand what I'm trying to do:</p> <pre><code> if (trim($this-&gt;uri-&gt;segment(5)) == 1) { if ( $this-&gt;my_model-&gt;functionA($this-&gt;uri-&gt;segment(8),$this-&gt;uri-&gt;se...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-08-04T23:33:25.367", "Id": "181558", "Score": "1", "body": "The title of your post should be the function/purpose of your code." } ]
[ { "body": "<p>Don't call the same function over and over with the same parameters, you won't get different results so why call it again and again? Also I would use a switch.</p>\n\n<pre><code>&lt;?php\n\n$seg5 = trim($this-&gt;uri-&gt;segment(5));\n$seg8 = $this-&gt;uri-&gt;segment(8);\n$seg4 = $this-&gt;uri-&...
{ "AcceptedAnswerId": "20299", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-08T21:35:26.850", "Id": "20297", "Score": "0", "Tags": [ "php" ], "Title": "how to simplify this code" }
20297
<p>This is my code to partition a list into two parts according to a value. I.e. nodes smaller than value <code>x</code> should precede nodes larger than the value <code>x</code>.<br> It seems correct. Any corner cases I am overseeing or corrections are highly appreciated. </p> <pre><code>public Node partition(Node h...
[]
[ { "body": "<p>I just have a point on naming of your function. You named it <code>partition</code> but you're just rearranging the elements and returning the head pointer! If you want to partition, you may want to return pointers to heads of partitions (the <code>head</code> you already return and another pointe...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-08T21:52:02.797", "Id": "20300", "Score": "1", "Tags": [ "java", "algorithm", "linked-list" ], "Title": "Partition a linked list arround an element" }
20300
<p>I have a system that needs to be able to reboot a different piece of hardware partway through a script that programs it. It used to wait for me to come and reboot the hardware halfway through, but I've since automated that. I use <a href="http://code.google.com/p/usbnetpower8800/source/browse/trunk/usbnetpower8800.p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-22T22:37:27.413", "Id": "41046", "Score": "1", "body": "Personally I gradually abandon all set-uid things in my system. I primarily use daemons listening UNIX sockets which nonprivileged programs can connect to and ask commands. That w...
[ { "body": "<p>Both of your programs are insecure. The problem is that I can set <code>PYTHONPATH</code> to anything I like before executing the program. I can set it to something so that it loads my own <code>usb</code> module which can execute whatever code I like. At that point, I'm executing code as the root...
{ "AcceptedAnswerId": "20307", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-08T23:16:59.930", "Id": "20304", "Score": "2", "Tags": [ "python", "c", "security", "linux" ], "Title": "Are these set-uid scripts/binaries secure?" }
20304
<p>I wrote a JavaScript that takes 2 fractions and finds the common denominator for both. If the user inputs 2/6 and 1/2 --- the script outputs 2/6 + 3/6. I'm interested in feedback on possibly simplifying it or improving it. Thanks.</p> <p>JS Bin: <a href="http://jsbin.com/omelen/1/edit" rel="nofollow">http://jsbin.c...
[]
[ { "body": "<p>Here's my attempt to help you.</p>\n\n<ul>\n<li>As a general rule, keep everything as general as you can and don't split your code into different cases unless you have to. From the <code>if (factor &gt;1)</code> part, I knew things could be improved</li>\n<li>At the end, the denominators will be t...
{ "AcceptedAnswerId": "20309", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T01:25:38.240", "Id": "20308", "Score": "2", "Tags": [ "javascript" ], "Title": "Find Common Denominator for 2 Fractions with JavaScript - Simplify & Improve" }
20308
<p>I've developed program, which may work with graphs and its edges (connections between vertices):</p> <p><a href="http://ideone.com/FDCtT0" rel="nofollow">http://ideone.com/FDCtT0</a></p> <pre><code>/* Oleg Orlov, 2012(c), generating randomly adjacency matrix and graph connections */ using System; using System.C...
[]
[ { "body": "<pre><code>class Graph\n</code></pre>\n\n<p>What this class represents is not a whole <a href=\"http://en.wikipedia.org/wiki/Graph_%28mathematics%29\" rel=\"nofollow\">graph</a>, it's a single <a href=\"http://en.wikipedia.org/wiki/Vertex_%28graph_theory%29\" rel=\"nofollow\">vertex</a> (or node). Be...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T02:43:35.617", "Id": "20310", "Score": "1", "Tags": [ "c#", "matrix", "graph" ], "Title": "Generating adjacency matrix on random cout of graphs with output the matrix" }
20310
<p>I'm writing a WCF service for validating password and getting company ID for the clients that requests the services. The service runs on a server locally as a windows service, which sends queries to the database and returns the appropriate info back to the client.</p> <p>I'd first like some comments on how the over...
[]
[ { "body": "<p>You should never generate dynamic SQL by concatenating incoming values into an SQL string that is executed later. This type of code leads to <a href=\"http://en.wikipedia.org/wiki/SQL_injection\" rel=\"nofollow\">SQL injection</a> vulnerability, and by using your service as it is now it's very eas...
{ "AcceptedAnswerId": "20359", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T05:19:33.367", "Id": "20312", "Score": "1", "Tags": [ "sql", "database", "wcf" ], "Title": "How to write a stable WCF service" }
20312
<p>I'd like this reviewed.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #define SWITCH(S) char *_S = S; if (0) #define CASE(S) } else if (strcmp(_S, S) == 0) {switch(1) { case 1 #define BREAK } #define DEFAULT } else {switch(1) { case 1 int main() { char buf[256]; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T15:56:28.143", "Id": "32534", "Score": "8", "body": "If you want a different syntax, use a different language. Don't try to bend C to your taste by misusing the preprocessor. It will just cause problems." } ]
[ { "body": "<p>I do like the idea but I'm not sure to really get the benefit of your code compared to (my C is a bit rusty so the code might not be correct) : </p>\n\n<pre><code> if (strcmp(buf,\"abcdef\") == 0) {\n printf (\"B1!\\n\");\n if (strcmp(buf,\"ghijkl\") == 0) {\n printf (\"C1!\\n\...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T08:34:42.363", "Id": "20314", "Score": "6", "Tags": [ "c", "strings" ], "Title": "Using case and switch macros for strings" }
20314
<p>For example I have 2 dates (year and month) like :</p> <pre><code>2013-03 2013-01 &lt;-- Jan. current month. 2012-10 </code></pre> <p>So my code is :</p> <pre><code>// Get current month and year $m = date('m'); $y = date('Y'); // So I do something to get highest date so result is.. $highest = "2013-03"; // Cu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T09:24:20.187", "Id": "32515", "Score": "0", "body": "I'm confused. What's your end goal? Are you trying to list, in descending order, all dates between two given dates?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
[ { "body": "<p>There's not really much to review here since it's such a short snippet, but a few things:</p>\n\n<hr>\n\n<p>I tend to avoid manipulating dates as strings. With just a year-month format it's actually fine since there's no odd rules. It's generally a lot safer to use DateTime though (or even strtot...
{ "AcceptedAnswerId": "20316", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T09:09:07.067", "Id": "20315", "Score": "1", "Tags": [ "php", "datetime" ], "Title": "Between dates : from highest -> current -> lowest" }
20315
<p>The below code does Read csv files and process it to do some sort of cacluations.This is more of small picture code , to introduce big picture. The csv file contains information of seeds of crop which have some information in number depending upon the numbers the calcuation have to be done.There are different types ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T19:01:15.223", "Id": "32562", "Score": "0", "body": "Don't reinvent the wheel. http://opencsv.sourceforge.net/" } ]
[ { "body": "<ul>\n<li>The path to the CSV file can be a parameter, it should not be hard coded, the path separator is available.</li>\n<li>Depending on the file size there are more modern options to read files. (Guava &amp; File NIO )</li>\n<li>Checking for null values before parsing. </li>\n<li>Method names are...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T11:26:35.980", "Id": "20321", "Score": "1", "Tags": [ "java", "optimization", "design-patterns" ], "Title": "Review code for optimization and implementation" }
20321
<p>This is a script to access the Stack Exchange API for the genealogy site and create a list of user dictionaries. It contains a snippet at end to validate. The data obtained is stored in YAML format in a file for use by other programs to analyze the data.</p> <pre><code>''' This is a script to access the stackexch...
[]
[ { "body": "<pre><code>'''\nThis is a script to access the stackexchange api\n for the genealogy site \n and create a list of user dictionaries\n'''\n\n# use requests module - see http://docs.python-requests.org/en/latest/user/install/#install\nimport requests\n\n# use pretty print for output\n</code></pre...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T12:43:43.470", "Id": "20323", "Score": "0", "Tags": [ "python", "stackexchange" ], "Title": "Script to access genealogy API for list of users and attributes" }
20323
<p>I designed this object for a "bread formula". They use a concept known as <a href="http://en.wikipedia.org/wiki/Baker_percentage" rel="nofollow noreferrer">baker's percentages</a>, but you don't need to understand the math to help with the object design.</p> <p>I designed it as an object (of type <code>Formula</cod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T18:08:52.350", "Id": "32554", "Score": "1", "body": "If you are always setting a field in the constructor, it doesn't need to be nullable. If you're never setting it to a useful value, it shouldn't be a parameter to the constructor...
[ { "body": "<p>Here's my humble opinion, it generally looks OK, here are some basic tips:</p>\n\n<ol>\n<li>Use generic collections if you can, <code>List&lt;Ingredient&gt;</code> instead of <code>ArrayList</code>, you won't have to cast it later on</li>\n<li>You can use LINQ for summing/counting/filtering/projec...
{ "AcceptedAnswerId": "20347", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T15:58:29.523", "Id": "20328", "Score": "14", "Tags": [ "c#", "object-oriented" ], "Title": "Bread formula object" }
20328
<p>I've designed an algorithm to find the longest common subsequence.</p> <p>These are steps: </p> <ul> <li><p>Pick the first letter in the first string.</p></li> <li><p>Look for it in the second string and if its found, Add that letter to <code>common_subsequence</code> and store its position in <code>index</code>,...
[]
[ { "body": "<p>Firstly, your algorithm is incorrect try:</p>\n\n<p><code>lcs(\"AAAABCC\",\"AAAACCB\")</code>, the LCS should be <code>\"AAAACC\"</code>, but your algorithm finds <code>\"AAAAB\"</code>.</p>\n\n<p>Secondly your algorithm is <code>O(n^2*m)</code> not <code>O(n*m)</code>. Since you don't elaborate a...
{ "AcceptedAnswerId": "20352", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T17:13:23.143", "Id": "20337", "Score": "3", "Tags": [ "python", "algorithm" ], "Title": "Find the longest common subsequence algorithm - low speed" }
20337
<p>I want to ask whether my following implementation is good in the view of good practice and performance. I have an app where I have to show another page or template html in an iframe. I get that template html via ajax and render it in the iframe. Iframe must be used because the template must be isolated.I am now stor...
[]
[ { "body": "<p>I don't think this will cause you any problems; it may offer superior performance in many scenarios, especially over re-rendering the template. The only other option that comes to mind is to keep this invisibly in the DOM somewhere and use JQuery's <code>clone()</code> to re-render it as needed. I...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T18:31:53.350", "Id": "20340", "Score": "4", "Tags": [ "javascript", "jquery", "ajax", "template", "mustache" ], "Title": "Rendering and re-rendering a Mustache template" }
20340
<p>I have designed couple of aspects using PostSharp for different projects, but there is a design flaw in many of them: <strong>dependency management</strong>.</p> <p><strong>This is a question about injection of dependencies into aspects, not about dependency injection using aspects</strong></p> <p>Due to nature of...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T05:43:37.737", "Id": "49112", "Score": "0", "body": "The PostSharp documentation proposes several strategies to cope with the issue of consuming dependencies from an aspect: http://doc.postsharp.net/postsharp-3.0/Content.aspx/PostSh...
[ { "body": "<p>I've not used PostSharp in a number of years, but have often used the following pattern to get around life-cycle issues with DI on attributes. It's a little manual, so should be seen as the exception rather than the rule, but it's easy to follow.</p>\n\n<p>In your aspect, define a static factory m...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T18:36:12.040", "Id": "20341", "Score": "13", "Tags": [ "c#", "reflection", "dependency-injection", "postsharp", "aspect-oriented" ], "Title": "Inject dependency into PostS...
20341
<p>From the <a href="https://www.postsharp.net/product" rel="nofollow">PostSharp product page</a>:</p> <blockquote> <p>PostSharp automates the implementation of patterns so they don't turn into boilerplate.</p> <p>It allows developers to eradicate boilerplate by offloading repeating work from humans to mach...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T18:37:14.427", "Id": "20342", "Score": "0", "Tags": null, "Title": null }
20342
PostSharp is aspect oriented programming for .NET using attributes that encapsulate aspects
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T18:37:14.427", "Id": "20343", "Score": "0", "Tags": null, "Title": null }
20343
Aspect oriented refers to the expression of event-driven programming through the use of callback functions or other means to respond to a local event that has global consequences without going through repetitive conditional checks or creating unnecessary dependencies between objects or subroutines.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-01-09T18:37:57.390", "Id": "20345", "Score": "0", "Tags": null, "Title": null }
20345
<p>I'm trying to think of ways to separate things out. I'm open to ideas, or if you see anything blatantly wrong, I'd like to know that too.</p> <p>Generally, I'm happy with this, but the sheer size of the class seems like a code smell.</p> <p><a href="https://bitbucket.org/jgrigonis/baseball_simulator/src" rel="nof...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-15T04:17:34.890", "Id": "32890", "Score": "0", "body": "don't use names like `__foo`. it doesn't do anything useful, and it certainly doesn't keep anyone else from mucking around in your class; it's just annoying magic." }, { ...
[ { "body": "<p>Don't pass in the name of your database file. You should pass in a database connection object. As it stands you reopen the database in many different places across your code. You should really only open the database once and pass the connection around. If you do this:</p>\n\n<ol>\n<li>Your code wi...
{ "AcceptedAnswerId": "20364", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T22:11:17.277", "Id": "20358", "Score": "4", "Tags": [ "python" ], "Title": "Gigantic class to model a baseball game" }
20358
<p>I am trying to factor integers using the trial division algorithm (Wikipedia: <a href="http://en.wikipedia.org/wiki/Trial_division" rel="nofollow">http://en.wikipedia.org/wiki/Trial_division</a>).</p> <p>I reviewed the Wikipedia entry for trial division and multiple other sources but I don't completely understand t...
[]
[ { "body": "<p>A few comments :</p>\n\n<ol>\n<li><p>Before writing any code, perform the computation manually. How would you do it for 20? You'd do something along the lines like :</p>\n\n<ul>\n<li>let's try the first prime number : 2</li>\n<li>is 2 a divisor of 20 ? yes, it is. 20 is 2*10 so let's add 2 to the ...
{ "AcceptedAnswerId": "20366", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-10T01:19:27.150", "Id": "20362", "Score": "0", "Tags": [ "javascript" ], "Title": "Integer Factorization using the Trial Division Algorithm" }
20362
<p>I'm not sure if there's a standard view where the placement of a success result should be in a conditional that can return multiple statuses. The success condition of this function is in the middle of the conditional block:</p> <pre><code>def redeem(pin) success = false message = nil if !self.date_claimed.nil...
[]
[ { "body": "<p>Some notes:</p>\n\n<ul>\n<li><p>Imperative programming has its use cases (or so I've heard :-)) but implementing logic is definitely not one of them. <a href=\"https://code.google.com/p/tokland/wiki/RubyFunctionalProgramming\" rel=\"nofollow\">Some thoughts</a> on the matter. Use always expression...
{ "AcceptedAnswerId": "20372", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-10T04:16:32.790", "Id": "20367", "Score": "2", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Placement of success code in a conditional" }
20367
<p>Here is an algorithm to evaluate best matching <code>System.Type</code> for two types in hierarhy. This is one of answers for <a href="https://stackoverflow.com/q/14107683/443366">this StackOverflow question</a> by Ken Kin:</p> <blockquote> <p>Evaluate the maximum possible type to fit both of types</p> </blockquo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-15T11:40:07.767", "Id": "32903", "Score": "2", "body": "Seems SE is a quiet and peaceful place." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-17T08:58:36.487", "Id": "33069", "Score": "0", "bo...
[ { "body": "<p>Your code does not take in account interface covariance and contravariance issues.</p>\n\n<p>Here is the sample code that demonstrates it:</p>\n\n<pre><code>class ObservableOfString : IObservable&lt;string&gt; { /*...*/ }\nclass ObservableOfObject : IObservable&lt;object&gt; { /*...*/ }\nclass Obs...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-10T06:27:59.767", "Id": "20369", "Score": "8", "Tags": [ "c#", "reflection" ], "Title": "Evaluate the best common type to fit both of types" }
20369
<p>I'm finally "done" with my small prototype for an element inside my website. I'm just a learner in the jQuery code and that reflects in my code. It's bloated, a lot of functions do the same thing, but for a red or green button which results in this kind of code.</p> <pre><code>$('.submenu').on('click','.rood',funct...
[]
[ { "body": "<p>Make a function.</p>\n\n<pre><code>function doStuff(obj, c) {\n obj.css({overflow: 'hidden', color: c}).fadeIn(400);\n}\n</code></pre>\n\n<p>Then call it</p>\n\n<pre><code>$('#submenu').click(function () {\n doStuff($('#geregeld'), 'green');\n});\n</code></pre>\n\n<p>(simplified example) </p>\n\...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-10T09:23:30.197", "Id": "20373", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Element inside a website" }
20373
<p>I have this method that basically takes a string and does different things depending on what the string starts with. Is there a cleaner way to write this method?</p> <pre><code>public String analyze(BotMessage message) { String lcmsg = message.message().toLowerCase(); //Not a command if(!lcmsg.startsWi...
[]
[ { "body": "<p>You can use Observer/Observable pattern for the <code>if(message.skipe(){..}</code> area.</p>\n\n<p>So each each observer evaluate the <code>if</code> and run the method (the methods are wrote inside the Observer).</p>\n\n<p>If a new test is needed, you have just to had a new Observer with no impa...
{ "AcceptedAnswerId": "20383", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-10T10:55:14.297", "Id": "20375", "Score": "5", "Tags": [ "java", "strings" ], "Title": "Conditional execution based on input string's prefix" }
20375
<p>I have inherited a node-js project, and I am completely new to it. Fortunately, it is already covered by unit tests.</p> <p>The class under test, <code>FmsRescuers</code>, has the responsibility of sending HTTP requests to a remote server. </p> <p>My first refactoring was to extract the HTTP behavior into the <cod...
[]
[ { "body": "<p>You could use sinon.js to have the power of spies, stubs and mocks. <a href=\"http://sinonjs.org/\" rel=\"nofollow\">http://sinonjs.org/</a></p>\n\n<p>That way you could create a stub of <code>httpRequest</code>.</p>\n\n<p>Look for <code>stub.yield([arg1, arg2, ...])</code>.</p>\n\n<p><strong>Edit...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-10T13:59:09.320", "Id": "20379", "Score": "4", "Tags": [ "javascript", "unit-testing", "node.js" ], "Title": "Does this nodeunit test conform to best practices?" }
20379
<p>I have a DataSet with only two tables in it. The first table is a list of models (of products) with default parameters (settings), and the second table is a list of modules. A module is a product based on a given model but with some parameters that have been changed. A sample DataSet in XML format could be something...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T03:01:14.767", "Id": "32623", "Score": "1", "body": "Side note: do your really need to call `ToString()` on `string` property: `pair.Value.ToString()`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T...
[ { "body": "<p>Really, all I did was refactor your code into smaller methods.</p>\n\n<p>I'm loading the <code>Module</code> properties and values into a dictionary. I then get the corresponding <code>Model</code> and load it's properties into the same dictionary. During the filling of the dictionary, it ignores ...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-09T02:57:16.490", "Id": "20380", "Score": "1", "Tags": [ "c#", "sql", "xml", "linq" ], "Title": "(More) efficient and elegant way to retrieve data from a dataset?" }
20380
<p>Before, I had this code, sometimes it is longer:</p> <pre><code>String dbEntry = "idBldgInfo = '" + currentBldgID + "',scenario = '305',installCost='" + installCost + "',annualSave='" + annualSave + "',simplePayback='" + simplePayback + "',kwhPre='" + preKWH + "',kwhPost='" + postKWH + "',co2Pre='" + preCO2e + "',...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-10T15:39:10.433", "Id": "32635", "Score": "1", "body": "What are you going to do with that `dbEntry`?\n\nBe sure you are not going to concatenate it with other strings to build a SQL query, it is extremely risky and will lead to [SQL I...
[ { "body": "<p>Your first implemenattion also uses <code>StringBuilder</code> under the hood.\nSee javadoc of <code>java.lang.String</code>:</p>\n\n<blockquote>\n <p>The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings. String con...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-10T15:31:25.227", "Id": "20385", "Score": "3", "Tags": [ "java", "strings" ], "Title": "String Building" }
20385
<p><a href="http://projecteuler.net/problem=3" rel="nofollow">Project Euler problem 3</a> asks:</p> <blockquote> <p>What is the largest prime factor of the number 600851475143?</p> </blockquote> <p>The first step I took is to determine the highest value number I should be looking at as a possibility (600851475143 /...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-10T19:07:38.430", "Id": "32655", "Score": "0", "body": "Use `sieve of eratosthenes` to find the primes then go through all the primes from largest down to find the largest factor." }, { "ContentLicense": "CC BY-SA 3.0", "Cr...
[ { "body": "<p>You can use other techniques to find primes <code>sieve of Eratosthenes</code>:<br>\nBut since this is a code review I will review the code you have:</p>\n\n<p>The easiest optimization is to record primes as you go.<br>\nA number is prime if it is not divisible by any of the primes you have alread...
{ "AcceptedAnswerId": "20414", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-10T19:01:11.173", "Id": "20389", "Score": "2", "Tags": [ "java", "performance", "algorithm", "programming-challenge", "primes" ], "Title": "Faster way to determine largest...
20389
<p>I am still trying to wrap my head around good programming practice and just wrote this routine to read in an Excel file and return all the sheets into a dataset:</p> <pre><code>Public Shared Function ReadExcelIntoDataSet(ByVal FileName As String, Optional ByVal TopRowHeaders As Boolean = False) As DataSet Try ...
[]
[ { "body": "<ol>\n<li><p>The <code>Using</code> is good practice and not overkill. Trying to dispose the resources in the <code>Finally</code> part has the disadvantage, that you don't know when the exception happened and which resources have been assigned by that time. The Using statement does this automaticall...
{ "AcceptedAnswerId": "20395", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-10T19:25:16.137", "Id": "20393", "Score": "2", "Tags": [ "vb.net" ], "Title": "Using Statement for OleDB - Is this overkill?" }
20393
<p>I've written a small utility for monkey-patching native JavaScript constructor functions. For example, you can use it to modify input arguments before returning an instance (this can be useful for unit tests).</p> <p>There is much more detail about the utility <a href="https://github.com/jamesallardice/patchwork.js...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-10T23:52:51.803", "Id": "32682", "Score": "1", "body": "Why not use [Object.create()](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/create)? Also what JS engine or environment will your scripts be ...
[ { "body": "<p>I don't see any good reason why you're using some of these hacks. It took me a while to understand what you were doing and I was pretty much forced to step through it in debugger. Going to review this line by line and point out simplifications and patterns as I see fit. I'll be batching together a...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-10T22:18:56.237", "Id": "20400", "Score": "16", "Tags": [ "javascript" ], "Title": "Monkey-patching native JavaScript constructors" }
20400
<p>I came up with a solution for the <a href="https://www.interviewstreet.com/challenges/dashboard/#problem/50bff669014b8" rel="nofollow">InterviewStreet problem "Triplet"</a></p> <p>In short, there is an integer array <em>d</em> which does not contain more than two elements of the same value. How many distinct ascend...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-10T11:36:42.230", "Id": "32680", "Score": "1", "body": "You didn't exactly go out of your way to help us understand your variable names." } ]
[ { "body": "<ol>\n<li>The problem looks like it would have a solution of complexity \\$O(n log n)\\$. Yours has \\$O(n^2)\\$. google \"number of increasing subsequences\". </li>\n<li>The site says input size can be \\$10^5\\$. A \\$O(n^2)\\$ algorithm with hash look-ups, hash inserts, and virtual function calls ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-10T11:13:58.017", "Id": "20401", "Score": "1", "Tags": [ "java", "algorithm" ], "Title": "InterviewStreet Triplet optimization" }
20401
<p>I'm just starting with Ruby and decided to do two different implementations of Conway's Game of Life. In this first one I'm not using <code>cells</code> as a separate class and instead just track everything as a location on the board, using a state pattern I guess. </p> <p>Anyway, I want this code to display good ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-30T18:10:38.367", "Id": "33846", "Score": "0", "body": "Small detail, but important: Never `x-y`, always `x - y`. Conversly, `x = -y`, never `x = - y`." } ]
[ { "body": "<p>Your code looks pretty good to me. I specially like how you don't update inplace a <code>Board</code> but create new ones on each iteration. And the OOP aspects of it seem also ok, I wouldn't write a <code>Cell</code> class when a pair <code>[x, y]</code> does just fine and there are not many meth...
{ "AcceptedAnswerId": "20441", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-10T23:52:09.867", "Id": "20402", "Score": "4", "Tags": [ "ruby", "game-of-life", "rspec" ], "Title": "Ruby implementation of Conway's Game of Life" }
20402
<p>I'm wondering if you see anything terribly wrong with this code, or if you see any areas for improvement. My objective is to make sure its simple enough for someone else taking over my job to be able to pick up fairly quickly. </p> <p>My basic question has to do with the fact that in my model, I'm trying to disting...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-12T14:11:09.987", "Id": "32745", "Score": "0", "body": "Does anything else in the try block throw an exception other than the one shown? If not, it can be massively simplified" } ]
[ { "body": "<p>I don't really like the method of exception pseudo-typing you're doing, I'd use different objects to represent the type of exception rather than the content, like so:</p>\n\n<pre><code>function macaddresses($ip, $name)\n{\n try\n {\n //some code....\n if($obj-&gt;connect())\n ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-11T00:24:46.797", "Id": "20403", "Score": "3", "Tags": [ "php", "error-handling" ], "Title": "error handling logic in php" }
20403
<p>I have a situation where depending on what the value of a uri segment is, my controller will load a different view. Here's what the code looks like in part:</p> <pre><code> //which view do we load? if (strpos(strtoupper($data['hardwaremodel']),"HP") !== false) { //hp view shou...
[]
[ { "body": "<p>I think I've come up with something cleaner: </p>\n\n<p>code in controller methods simplified to this:</p>\n\n<pre><code> //which view do we load?\n $viewnamePrefix = $this-&gt;checkhardwarename($data['hardwaremodel']);\n $data['main_content']=$viewnamePrefix.'ad';\n $this-&gt;load-&gt...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-11T00:46:54.337", "Id": "20404", "Score": "1", "Tags": [ "php" ], "Title": "Ideas for simplificaton - Logic to choose which view to load" }
20404
<p>The exercise is the bunny linked list exercise; the last beginner exercise from <a href="http://www.cplusplus.com/forum/articles/12974/" rel="nofollow">here</a>.</p> <p>I'm looking for feedback on absolutely everything that could make me a better programmer: </p> <ul> <li>Syntax</li> <li>Optimization</li> <li>Form...
[]
[ { "body": "<p>Not a full review, but just some general comments on style and other C++ idioms. Note that I only looked at some of the code and wasn't looking at correctness.</p>\n\n<h2>Style</h2>\n\n<ul>\n<li>You should name your files with the same name as the class (eg. <code>class RabbitNode</code> would be ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-11T03:51:49.713", "Id": "20407", "Score": "10", "Tags": [ "c++", "beginner", "linked-list" ], "Title": "Linked list of bunny objects" }
20407
<p>I want to filter the options of a large select group based on text input in a textbox. I am currently using this code to filter from a <code>SELECT</code> group based on the text of a input box.</p> <p>Can you please tell me whether there is a more efficient way of doing this? My <code>SELECT</code> group is very l...
[]
[ { "body": "<p>Your jQuery could be somewhat more efficient if you minimize <code>$(...)</code> element look-ups by storing them as variables or chaining them.</p>\n\n<p>Also, I think you will see some benefit to replacing some jQuery constructs with their pure JS alternatives (<code>$.each</code> -> <code>for</...
{ "AcceptedAnswerId": "20421", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-11T12:08:00.297", "Id": "20415", "Score": "4", "Tags": [ "javascript", "jquery" ], "Title": "Filtering a SELECT group using jQuery" }
20415
<p>I frequently run a script similar to the one below to analyze an arbitrary number of files in parallel on a computer with 8 cores. </p> <p>I use Popen to control each thread, but sometimes run into problems when there is much stdout or stderr, as the buffer fills up. I solve this by frequently reading from the stre...
[]
[ { "body": "<p>Python has what you want built into the standard library: see the <a href=\"http://docs.python.org/2/library/multiprocessing.html\" rel=\"noreferrer\"><code>multiprocessing</code> module</a>, and in particular the <a href=\"http://docs.python.org/2/library/multiprocessing.html#multiprocessing.pool...
{ "AcceptedAnswerId": "20514", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-11T12:47:40.057", "Id": "20416", "Score": "4", "Tags": [ "python", "multithreading" ], "Title": "Python parallelization using Popen" }
20416
<p>I often need to return empty collections.<br> One of those days I wrote the following to return a cached instance:</p> <pre><code>public static class Array&lt;T&gt; { // As a static field, it gets created only once for every type. public static readonly T[] Empty = new T[0]; } </code></pre> <p>I didn't kno...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-11T14:27:53.627", "Id": "32698", "Score": "0", "body": "I wasn't aware of this little gem. Thanks!" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-11T14:46:37.013", "Id": "32701", "Score": "0", ...
[ { "body": "<p>I think it entirely depends on context.</p>\n\n<p><code>Enumerable&lt;T&gt;.Empty()</code> was clearly introduced for syntactic sugar in Linq. I see no reason to use it over a plain old new-statement.</p>\n\n<p>The wider question about caching and efficiency depends on the code-base. Calling a lis...
{ "AcceptedAnswerId": "20435", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-11T12:55:29.047", "Id": "20417", "Score": "7", "Tags": [ "c#", ".net", "array", "collections" ], "Title": "Cached empty collections" }
20417
<p>I've just created a teeny little script to count the seconds until I get auto-logged off. I already solved my issue with my ssh client settings, but I'd still like any help making the bash script nicer to read, or just tips in general.</p> <pre><code>#!/bin/bash count=0 while ( [ : ] ) do count=$(($count+1)) ...
[]
[ { "body": "<p>If the answer is what you care for,</p>\n\n<p>in your .bash_profile :</p>\n\n<pre><code>touch \"~/.loggued_in\"\n</code></pre>\n\n<p>in your .bash_logout:</p>\n\n<pre><code>date -r ~/.loggued_in ; date\n</code></pre>\n\n<p>and check if there is a timeout setup:</p>\n\n<pre><code>{ set ; env ; } | ...
{ "AcceptedAnswerId": "20433", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-11T13:04:13.333", "Id": "20418", "Score": "7", "Tags": [ "bash" ], "Title": "Counting seconds until auto-log-off" }
20418
<p>This morning I was trying to find a good way of using <code>os.path</code> to load the content of a text file into memory, which exists in the root directory of my current project.</p> <p><a href="http://halfcooked.com/blog/2012/06/01/python-path-relative-to-application-root/" rel="noreferrer">This approach</a> str...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-17T15:41:47.363", "Id": "33095", "Score": "0", "body": "You should choose an answer or provide more information." } ]
[ { "body": "<p>your approach seems ok, but as it is not a common problem/solution, you should document what your <code>__root__.py</code> file is doing.</p>\n\n<p>One thing: you should not use double leading and trailing underscores, see <a href=\"http://www.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">pep8<...
{ "AcceptedAnswerId": "20449", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-11T15:09:55.653", "Id": "20428", "Score": "6", "Tags": [ "python" ], "Title": "Accessing the contents of a project's root directory in Python" }
20428
<p>I'm trying to track down what I suppose to be memory/thread leak in one of my programs.</p> <p>My program uses a function to upload a file to a <a href="http://www.windowsazure.com/en-us/develop/net/how-to-guides/blob-storage/" rel="nofollow noreferrer">Windows Azure Storage Blob</a>. In order to make this function...
[]
[ { "body": "<p>There are several issues in your code that make it error-prone:</p>\n\n<ul>\n<li>you are using a single byte array to feed all memory streams, thus the same data may be sent in different chunks. Same stands for <code>count</code>.</li>\n<li>the order of chunks in <code>blockids</code> can be diffe...
{ "AcceptedAnswerId": "20434", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-11T15:16:34.520", "Id": "20429", "Score": "1", "Tags": [ "c#", "asynchronous", "task-parallel-library" ], "Title": "TPL Thread Leak and Memory Leak" }
20429
<p>I am in the process of writing a simple Node.JS webserver. I am about halfway there in terms of functionality. Please see the full code in <a href="http://pastebin.com/h2KBWDTH" rel="nofollow noreferrer">this Pastebin</a> (the client-side code is not shown as I want to focus on server-side).</p> <p>Before I impleme...
[]
[ { "body": "<p>First of all you need to separate your code into multiple files.\nUsually its something like models/controllers etc.\nI know it is very useful for copy pasting it to places like this but it will not do for the long run.</p>\n\n<p>Even without testing your code I am pretty sure that this is not cor...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-11T17:01:17.970", "Id": "20436", "Score": "1", "Tags": [ "javascript", "security", "node.js", "server" ], "Title": "Simple Node.JS webserver" }
20436
<p>I am using Bootstrap for a front-end project. I would like feedback concerning my HTML markup. I have spent quite some time polishing it, and I feel it is somewhat "mature". I have run the W3C HTML validator on it, and it only complains about three things:</p> <ol> <li>My use of <code>center</code> tags (consider t...
[]
[ { "body": "<p>Other items to consider:</p>\n\n<ul>\n<li>Place JavaScript at the bottom (before the closing body tag).</li>\n<li>Find other ways to avoid the flash of <a href=\"http://www.learningjquery.com/2008/10/1-way-to-avoid-the-flash-of-unstyled-content\" rel=\"nofollow noreferrer\">unstyled content</a>.</...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-11T18:59:27.537", "Id": "20439", "Score": "3", "Tags": [ "html" ], "Title": "Bootstrap: HTML markup review" }
20439
<p>I currently have code that looks like this</p> <pre><code>private string _stringField; protected string StringField { get { if (_stringField == null) _stringField = GetStringField(); return _stringField; } } </code></pre> <p>ReSharper is suggesting I change the property to:...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-11T19:52:15.160", "Id": "32722", "Score": "4", "body": "That and using Lazy<> is how I tend to do my properties when wanting something like this. Just seems more consise to me. As for confusing others? Possibly but it might also tea...
[ { "body": "<p><a href=\"http://msdn.microsoft.com/en-us/library/ms173224.aspx\">??</a> is well known operator in C#. It doesn't confuse but reduce coding. </p>\n\n<p>Both snippets have same meaning.</p>\n\n<p>But if it is .NET 4.0 onwards, i would rather use <a href=\"http://msdn.microsoft.com/en-us/library/dd...
{ "AcceptedAnswerId": "20442", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-11T19:41:26.213", "Id": "20440", "Score": "16", "Tags": [ "c#", "lazy" ], "Title": "Lazy loaded property readability" }
20440
<p>I'm working on an A* search algorithm implemention and this is what I came up with for the open list:</p> <pre><code>from heapq import heappush, heappop class OpenList(set): ''' This uses a heap for fast retrieval of the node with the lowest path score. It also uses a set for efficiently checking if a ...
[]
[ { "body": "<h3>1. Bug</h3>\n\n<ol>\n<li><p>You don't properly synchronize the set and the heap in all cases. For example, when taking a union:</p>\n\n<pre><code>&gt;&gt;&gt; a = OpenList()\n&gt;&gt;&gt; a |= set([1,2,3])\n&gt;&gt;&gt; a\nOpenList([1, 2, 3])\n&gt;&gt;&gt; a._heap\n[]\n</code></pre>\n\n<p>If you ...
{ "AcceptedAnswerId": "20509", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-11T22:23:15.693", "Id": "20451", "Score": "5", "Tags": [ "python", "algorithm", "heap", "a-star" ], "Title": "A* search algorithm: open set and heap" }
20451
<p>I'm a Scala beginner and looking at the <code>trim()</code> method of the Java API. I noticed side effects, so I attempted to implement a functional version in Scala.</p> <p>Here is the Java version: </p> <pre><code>public String trim() { int len = count; int st = 0; int off = offset; /* avoid getfield opcod...
[]
[ { "body": "<p>No good idea about the concern of reversing the list twice. But you may</p>\n\n<ol>\n<li><p>Let you inner function return a List instead of a string thus having less conversions from list to string and string to list.</p></li>\n<li><p>Change your match to the following pattern (not tested):</p>\n\...
{ "AcceptedAnswerId": "20503", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-12T00:09:55.710", "Id": "20452", "Score": "6", "Tags": [ "java", "beginner", "strings", "scala" ], "Title": "A scala implementation of the Java trim method" }
20452
<p>I'm developing an iPhone app that is heavily Calendar-based, and it requires a good amount of (what I'm calling) "date boundaries." </p> <p>I use these "date boundaries" to fetch EKEvents from specific calendars and display data for specific years, months, and quarters.</p> <p><em><strong>SPECIAL NOTE:</em></stron...
[]
[ { "body": "<p>you could maintain one array with the starts of the quarters and one withe the ends. as only the months changes, you need just those.<br>\nThan you iterate over them and generate the dates</p>\n\n<pre><code>NSArray *startsOfQuarters = @[@10, @1, @4 , @7];\nNSArray *endOfQuarters = @[@12, @3, @6 , ...
{ "AcceptedAnswerId": "20464", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-12T03:52:43.690", "Id": "20456", "Score": "2", "Tags": [ "optimization", "performance", "objective-c", "ios" ], "Title": "Initialize a bunch of NSDateComponents objects at onc...
20456
<p>Following snippet reads CSV Line count using BinaryReader. </p> <p>Currently it checks <code>\r</code> and <code>\n</code> for line delimiters.</p> <pre><code> private static int GetLineCount(string fileName) { BinaryReader reader = new BinaryReader(File.OpenRead(fileName)); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-12T17:10:05.567", "Id": "32747", "Score": "1", "body": "Both `BinaryReader` and `File.OpenRead()` are `IDisposable` resources - wrap them in a `using` statement for deterministic disposal." }, { "ContentLicense": "CC BY-SA 3.0"...
[ { "body": "<p><code>Environment.NewLine</code> always returns <code>\\r\\n</code> so it won't help you in parsing different line endings.</p>\n\n<p>If your task is to count the number of lines then it would be much easier just to do smth. like:</p>\n\n<pre><code> private static int GetLineCount(string fileNa...
{ "AcceptedAnswerId": "20459", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-12T04:18:11.863", "Id": "20457", "Score": "1", "Tags": [ "c#" ], "Title": "Clean code for array comparison" }
20457
<p>Today I solved a question from Google Code Jam: mimicking a cell phone keypad messaging.</p> <p>Here is the program, with <code>goto</code> statements. I know it is an unstructured style to use <code>goto</code>, but I still did because it improved speed.</p> <pre><code>#include &lt;stdio.h&gt; int main() { ...
[]
[ { "body": "<p>I didn't write any C in the last few years but I think you could use <a href=\"http://www.acm.uiuc.edu/webmonkeys/book/c_guide/1.6.html#continue\" rel=\"nofollow\"><code>continue</code></a> instead of <code>goto</code> in the first version.</p>\n", "comments": [ { "ContentLicense...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-12T14:38:56.323", "Id": "20462", "Score": "3", "Tags": [ "c", "programming-challenge", "comparative-review" ], "Title": "Mimicking T9 cell messaging" }
20462
<p>I'm sure this can be done in less lines and in a more clean way?</p> <pre><code>function BaseClass() { BaseClass.prototype.talk = function () { alert("I'm BaseClass"); } } function MyClass() { BaseClass.call(this); } MyClass.prototype = new BaseClass(); MyClass.base = {}; MyClass.base.talk = MyClass.prot...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-13T06:51:00.757", "Id": "32767", "Score": "0", "body": "Why are you declaring `BaseClass.prototype.talk` inside the constructor?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-13T06:52:40.713", "Id": "...
[ { "body": "<pre><code>function BaseClass () {}\n\nBaseClass.prototype.talk = function () {\n alert(\"I'm BaseClass\");\n}\n\nfunction MyClass() {\n BaseClass.call(this);\n}\n\nMyClass.prototype = new BaseClass();\nMyClass.base = BaseClass.prototype;\n\nMyClass.prototype.talk = function () {\n alert(\"I...
{ "AcceptedAnswerId": "20478", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-12T19:47:26.917", "Id": "20465", "Score": "1", "Tags": [ "javascript" ], "Title": "Javascript class+call base class?" }
20465
<p>I am running a simulation with 250 interacting agents and have a few functions that are called over and over again. Even with precomputing all distances between agents before the N<sup>2</sup> (250x250) interaction loop, my simulation is still very slow. Are there any C++ optimization tricks that I could use to spee...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-12T20:12:16.023", "Id": "32791", "Score": "2", "body": "Use a space partitioning algorithm to avoid the N^2 loop." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-12T20:16:49.410", "Id": "32792", "Sc...
[ { "body": "<p>It looks good to me. I would change </p>\n\n<pre><code> if (!preyDead[i])\n {\n</code></pre>\n\n<p>To</p>\n\n<pre><code> if (preyDead[i])\n continue;\n</code></pre>\n\n<p>Just so its less nested. Same with preyDead[j]. But everything looks fine to me.\nA tip I once saw on SO is...
{ "AcceptedAnswerId": null, "CommentCount": "14", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-12T20:22:21.990", "Id": "20466", "Score": "10", "Tags": [ "c++", "performance", "computational-geometry" ], "Title": "Calculating angles and distances" }
20466
<p>In my library <a href="http://androidtransfuse.org" rel="nofollow">Transfuse</a> I use a code generator to build a handful of classes that look up resources. Each of these look up classes are proxied by a static utility class so they may be referenced before the generated class is built. For instance, the <code>Pa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-24T09:30:32.297", "Id": "33436", "Score": "0", "body": "Is there a reason why  `Parcels` and `Transfuse$Parcels` can not be in the same `jar`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-24T16:16:16.193...
[ { "body": "<p>I ended up taking a bit of a different route with this problem. It seems I was not adding additional proxied resources if they were not contained within the current compiled package... as in, they were included in included libraries. So, my proxy utility looks like the following:</p>\n\n<pre><co...
{ "AcceptedAnswerId": "23711", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-13T00:09:59.923", "Id": "20470", "Score": "2", "Tags": [ "java", "performance", "proxy", "dynamic-loading" ], "Title": "Generated code proxy" }
20470
<p>The full code is located here: <a href="https://gist.github.com/4521540" rel="nofollow noreferrer">https://gist.github.com/4521540</a></p> <p>It's a dummy <code>List</code> in C++. My concern is with freeing up memory. It doesn't crash when I run my code. It looks like my <code>if/else</code> covers everything.</p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2018-01-05T14:53:59.873", "Id": "351322", "Score": "0", "body": "You also might want to read up on smart pointers. You can protect against memory leaks and double deletes by using `std::unique_ptr`." }, { "ContentLicense": "CC BY-SA 3....
[ { "body": "<p>A cleaner way would be to go iteratively through the list. </p>\n\n<p>I would do something like:</p>\n\n<pre><code>~List()\n{ \n if(startNode == NULL)\n return;\n\n if(startNode-&gt;Next != 0)\n { \n delete this-&gt;startNode-&gt;Next;\n }\n delete this-&gt;startNo...
{ "AcceptedAnswerId": "20480", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-13T01:14:11.720", "Id": "20472", "Score": "5", "Tags": [ "c++", "linked-list", "memory-management" ], "Title": "Destructor for a linked list" }
20472
<p>This is my code and I would like to get it code reviewed. It is functional and behaves as expected.</p> <p>I pass some basic types to the <code>Serialize()</code> function and then deserialize the output to get back the original value.</p> <pre><code>size_t returnSize(const char* s) { string string(s); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-13T08:33:28.297", "Id": "32775", "Score": "0", "body": "You're duplicating a string on the heap only to take its size?" } ]
[ { "body": "<p>First of all, fundamentally: <code>std::string</code> is a data type to hold <em>text</em>. Exclusively. It should <strong>not</strong> be used to hold binary data. Use a <code>std::vector&lt;(unsigned) char&gt;</code> for that.</p>\n\n<p>Secondly, you are using heap allocation without needing to:...
{ "AcceptedAnswerId": "20490", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-13T01:24:02.557", "Id": "20474", "Score": "6", "Tags": [ "c++", "strings", "serialization" ], "Title": "std::vector memory manipulation with serialization and deserialization" }
20474
<p>I am new to web apps and I am having a difficult time structuring my apps. I put together a very simple math web app which I wish to expand on. The app has the following pages/screens:</p> <ul> <li>Home screen</li> <li>About screen</li> <li>Math question screen</li> <li>Answer check screen</li> <li>Results screen.<...
[]
[ { "body": "<p>If you organize the app into several pages/folders, then response will be slower, passing values around more complicated, and you will have several scripts instead of one to manage. So I would not do this until it becomes really too big to manage in a single page. Remember one of the key advantage...
{ "AcceptedAnswerId": "20500", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-13T01:24:52.337", "Id": "20475", "Score": "3", "Tags": [ "javascript", "css", "html5" ], "Title": "Structuring Simple HTML5 / CSS3 / JavaScript Math Web App" }
20475
<p>I am curious to know if there is a faster, better, and more efficient way to accomplish this program that acquires employee information:</p> <pre><code> &lt;?php session_start(); //require 'functions.php'; //require 'DB.php'; $employeeID = $_SESSION['employeeID']; $clockIn = $_GET['clockIn']; $clockOut = $_GET['...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-13T17:56:12.260", "Id": "32812", "Score": "4", "body": "Why make the db connection so many times? Why not only once?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T07:59:29.347", "Id": "32971", ...
[ { "body": "<p>Defining the same connection multiple times can be avoided, and also, putting everything in <code>try/catch</code> serves no purpose if the only thing you do in the catch is displaying the message which would be displayed anyway with the error reporting mode you set on the <code>$conn</code></p>\n...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-13T04:13:30.887", "Id": "20476", "Score": "2", "Tags": [ "php", "mysql", "pdo" ], "Title": "Acquiring employee information" }
20476
<p>I'm particularly concerned about where I have declared the functions, can I move them around to clean up the code without breaking anything? The "conjugate" function contains a lot of stuff that has nothing to do with actually conjugating verbs and rather handles output strings and html DOM objects. I really want to...
[]
[ { "body": "<p>I didn't really have a chance to really take this apart but your first foreach loop binding the mouseover events can actually be written like in this jsfiddle <a href=\"http://jsfiddle.net/KSzFy/\" rel=\"nofollow\">http://jsfiddle.net/KSzFy/</a></p>\n\n<p>When you call a event binding function on ...
{ "AcceptedAnswerId": "20971", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-13T16:17:03.650", "Id": "20495", "Score": "4", "Tags": [ "javascript", "jquery", "html", "html5" ], "Title": "This blueprint has already become a mess, please suggest some res...
20495
<p>I want to remove my goto's in this code but I'm not sure how. There must be a cleaner way to write my code. Perhaps move the "if" statement to the end of each loop then use break?</p> <p>Sorry if this is a stupid question, I'm self-taught, and I'm finishing up my first sizable program. Any suggestions as to how I c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-13T21:41:13.317", "Id": "32825", "Score": "2", "body": "In this particular case, when labels are directly after the loops, each of the `goto`s can be replaced by a regular `break` from the `foreach` loop. I'm not posting this as an ans...
[ { "body": "<p>As a first pass here is what I got. It is nowhere close to what it should be, but it is a start. If you gave more code, I could perfect it further but right now I do not know where the variables are coming from. </p>\n\n<pre><code>public void Sort()\n{\n //Begin the sorting method\n if (load...
{ "AcceptedAnswerId": "20538", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-13T21:20:40.933", "Id": "20497", "Score": "3", "Tags": [ "c#", "beginner", "csv", "gui" ], "Title": "Prompting a user to save and regenerate some entries in a file" }
20497
<p>I've discovered that using hashed passwords with salts is a much better idea than MD5/SHA256, so I'm not hashing them with PBKDF2. However, I'm wondering if this is a correct approach to authorizing my user. I also have logic for logging authorizations. When the same IP has entered an incorrect login/pass, it become...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-23T03:47:46.320", "Id": "88931", "Score": "0", "body": "I think code like `_db.Administrators.Where(...)` should be put in a repository to aid Unit Testing." } ]
[ { "body": "<p>I really think that you should merge all of these if statements, make them an if/elseif/else statement. just move all the variable declarations to the top.</p>\n\n<p>then it turns into this</p>\n\n<pre><code>[HttpPost]\n[ValidateAntiForgeryToken]\npublic ActionResult Authorize(Administrator a)\n{...
{ "AcceptedAnswerId": "87105", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-14T13:54:30.683", "Id": "20507", "Score": "6", "Tags": [ "c#", "logging", "asp.net-mvc-4", "authorization" ], "Title": "PBKDF2 authorization" }
20507
<p>I have following code for doing custom paging from an asp.net web application. </p> <p><strong>Points of interest</strong></p> <ol> <li>It uses Link Buttons as suggested in <a href="https://stackoverflow.com/questions/14335067/passing-search-parameters-to-same-page-when-hyperlink-clicked">https://stackoverflow.co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-21T15:06:30.487", "Id": "33278", "Score": "1", "body": "@Knownasilya. Thanks. I have accepted possible answers. 75% acceptance now" } ]
[ { "body": "<p>I have come across a scenario that will fail: Suppose there is an image button control in the same page along with our button. Our code for pre-adding links will be called in all postbacks. </p>\n\n<p>Assume that the value in textbox is supposed to be an integer. We have added a validation that wi...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-14T14:30:32.940", "Id": "20510", "Score": "3", "Tags": [ "c#", "asp.net", "sql-server" ], "Title": "Custom Paging in ASP.Net Web Application" }
20510
<p>On an IRC channel I'm a member of, one particular person mocks every piece of code I post, even if it's a rough draft or if I haven't coded in months. I am pretty well versed with computer theory and knowledge, but my skills with programming lack due to little practice. This particular code was from a project I wa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-14T16:59:47.070", "Id": "32854", "Score": "9", "body": "http://www.codinghorror.com/blog/2006/01/flattening-arrow-code.html" } ]
[ { "body": "<p>Your code looks perfectly reasonable and the indentation is very standard. The only issue I can see is that C arrays are zero based so the loop </p>\n\n<pre><code>for(currentArg = 1; currentArg &lt;= count; currentArg++){\n</code></pre>\n\n<p>should possibly be</p>\n\n<pre><code>for(currentArg = ...
{ "AcceptedAnswerId": "20513", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-14T16:47:03.953", "Id": "20511", "Score": "4", "Tags": [ "c", "parsing" ], "Title": "Criticize C argument parsing method" }
20511
<p>I am trying to create a randomly generated array of x numbers with no duplicates. I am choosing numbers, one at a time, then comparing each new number to the numbers already in the array. </p> <p>Here is my code. At the end I should have an array of seven numbers, none that match, but sometimes I get a nil:</p> <p...
[]
[ { "body": "<p>I don't understand what you really want, but this simple one-liner generates an array of ten elements (from 1 to 10) with a random order. Tweak it to meet your needs:</p>\n\n<pre><code>(1..10).to_a.shuffle\n#=&gt; [4, 10, 1, 7, 3, 5, 8, 2, 9, 6]\n</code></pre>\n", "comments": [ { ...
{ "AcceptedAnswerId": "20521", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-14T19:29:56.047", "Id": "20520", "Score": "4", "Tags": [ "ruby" ], "Title": "How do I generate a list of n unique random numbers in Ruby?" }
20520
<p>I'm very new both to programming and to R so please bear with me :-) I've written the following bit of code, which works perfectly well and runs through a data file with 17446 rows in about 35 seconds. I don't really have a problem with this but am sure that this could be a lot more elegant with probably the use of ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-11T18:23:03.283", "Id": "32873", "Score": "0", "body": "Can you confirm that `NEE2` in `mean(Dspke$NEE2[(i-2):i-1])` is really meant to be `NEE2` and not `NEE`? `NEE2` seems like an odd choice, and this has a bearing on the complexity ...
[ { "body": "<p>The <code>embed</code> function is well-suited for constructing trailing vectors by row:</p>\n\n<pre><code> Dspke[ , paste0(\"E3\", 1:3)] &lt;- NA # create columns to hold the trailing values\n Dspke[4:nrow(Dspke), 5:7] &lt;- embed(Dspke$NEE, 3)\n Dspke$NEE3 &lt;- ifelse( apply(Dspke[,5:7], 1,...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-11T17:52:38.097", "Id": "20523", "Score": "3", "Tags": [ "r" ], "Title": "More elegant filter script in R" }
20523
<p>I am building a web service that gets data via Stored Procedures from a db and provides the result as JSON. The solution is built as a MVC 4 Web API project. I have to retrieve the data via Stored Procedures for several reasons (security, SQLAnywhere db, etc).</p> <p>It is a relatively small scale project so I have...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-31T14:26:44.287", "Id": "79972", "Score": "0", "body": "I believe `taTemp` and `dsTemp` are both objects of classes which implement `IDisposable` and therefore should be wrapped in `using` statements to ensure proper deterministic disp...
[ { "body": "<p>General approach to build Web API without models, doesn't give the full web API capabilities.</p>\n\n<p>E.g: </p>\n\n<ol>\n<li>Help: You cannot have Web API help generated automatically.</li>\n<li>You cannot return error handling scenarios: status, message</li>\n</ol>\n\n<p>If you don't want to cr...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-15T01:05:50.553", "Id": "20526", "Score": "6", "Tags": [ "c#", "asp.net", "web-services" ], "Title": "Web API and Stored Procedures" }
20526
<p>I was wondering if there was a way to rewrite this to be a bit more clean. It seems a bit odd to have a <code>mouseenter</code> and a <code>mouseleave</code> for this. Surely there's a toggle of some kind?</p> <pre><code>$(document).ready(function() { // Post header animation $('h1.post').mouseenter(function() { ...
[]
[ { "body": "<p>You can condense this a bit by using jQuery's <a href=\"http://api.jquery.com/hover/\" rel=\"nofollow\"><code>hover</code></a> method:</p>\n\n<pre><code>$('h1.post').hover(function() {\n $(this).animate({ paddingLeft: 10 }, 300);\n}, function() {\n $(this).animate({ paddingLeft: 0 }, 300);\n...
{ "AcceptedAnswerId": "20528", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-15T01:13:54.917", "Id": "20527", "Score": "1", "Tags": [ "javascript", "beginner", "jquery" ], "Title": "Header and navbar animations on a website" }
20527
<p>I have created some code in Java that slices up an image into rows and columns and then saves each image to the file system. This works but there are some improvements I would like to make</p> <p>I would like it to automatically know the original file name and extension using the StringTokenizer class so I do not h...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-15T07:44:59.947", "Id": "32894", "Score": "0", "body": "First step in changing some behavior: put it in a separate place. You should write a `getFileName( ... )` method." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate...
[ { "body": "<p>Not sure I understand your problem but what about changing the signature of you constructor to:</p>\n\n<pre><code>GridImage(String path, String filename, int rows, int columns)\n</code></pre>\n\n<p>And have path and filename be attributes of your object.</p>\n\n<p>I don't know why you implemented ...
{ "AcceptedAnswerId": "20536", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-15T02:30:25.357", "Id": "20529", "Score": "2", "Tags": [ "java" ], "Title": "Slicing up an image into rows and columns in Java" }
20529
<p>For a quiz web app, I decided the best way to store quiz questions, answers, and other user data related to the question was to use an array of objects for the quiz. I'm not sure if this is the best way to go about it since static information such as the questions and answers will be mixed with user data.</p> <p>Ea...
[]
[ { "body": "<p>How you're making the questions really looks ugly. How about this way?</p>\n\n<pre><code>var quiz = [{\n question: \"Montgomery\",\n answer: \"Alabama\",\n enabled: false,\n asked: 0\n},{\n question: \"Juneau\",\n answer: \"Alaska\",\n enabled: true,\n asked: 0\n}, {} /* .....
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-15T06:31:04.903", "Id": "20532", "Score": "1", "Tags": [ "javascript" ], "Title": "Using an Array of Objects to Store Quiz Questions/Answers" }
20532
<p>I define in the Settings Tab of a VB.Net class library some user scoped settings. I want to expose these settings to other projects that reference the class library. I chose to do this using a public Module. This works, but it requires exposing each and every setting manually. Is there a better way?</p> <pre><code>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-15T10:09:51.100", "Id": "32898", "Score": "2", "body": "You *could* expose the `Settings` module wholesale." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-15T10:28:08.830", "Id": "32901", "Score": ...
[ { "body": "<p>I think it's a fairly verbose way of exposing app settings. How about this?</p>\n\n<p><img src=\"https://i.stack.imgur.com/Ukvaw.png\" alt=\"enter image description here\"></p>\n\n<p><sub>(taken from an answer on <a href=\"https://stackoverflow.com/questions/11873656/how-to-make-application-proper...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-15T09:48:34.590", "Id": "20537", "Score": "3", "Tags": [ "vb.net" ], "Title": "Is this the correct way to expose a setting for a vb.net class library?" }
20537
<p>I have developed a new router after having learnt a lot from my previous attempts and I will be using this in sites I make from now on.</p> <p>In a previous question, the issue of <code>REQUEST_URI</code> being too inflexible made me wonder if I could make adjustments to allow it to route <code>$_POST</code> and <c...
[]
[ { "body": "<p>Where you have:</p>\n\n<blockquote>\n<pre><code>$class = ucfirst($this-&gt;autoMap($command[0]), $this-&gt;classAliases);\n</code></pre>\n</blockquote>\n\n<p>I think it should be:</p>\n\n<pre><code>$class = ucfirst($this-&gt;autoMap($command[0], $this-&gt;classAliases));\n</code></pre>\n\n<p>The c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-15T12:16:22.610", "Id": "20539", "Score": "2", "Tags": [ "php", "object-oriented", "mvc", "url-routing" ], "Title": "Good, flexible and secure MVC router PHP" }
20539
<p>I recently created an extension which detects the type of credit card based on the numbers entered in and formats it. I am using Luhn Algorithm for validating credit card numbers and I am using jQuery masking for formatting the credit card numbers (for reference: jquery.maskedinput-1.3.min).</p> <p>You can play wit...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-15T14:08:07.750", "Id": "32906", "Score": "6", "body": "Why re-invent the wheel? http://paweldecowski.github.com/jQuery-CreditCardValidator/" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-15T14:33:06.023",...
[ { "body": "<p>One thing that comes to mind is you could remove many lines of code by using <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\" rel=\"nofollow\">regular expressions</a>:</p>\n\n<pre><code>name: 'Visa',\n className: 'visa',\n checkPattern: /^4\\d{12}...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-15T13:44:39.977", "Id": "20543", "Score": "8", "Tags": [ "javascript", "beginner", "jquery", "validation", "finance" ], "Title": "Validating a credit card" }
20543
<p>I have moved all my web-server code dealing with user management into a single Node.js module that I pasted below. I have spent time polishing it, and churned it through JSHint. I am generally happy with the code, except for the error handling. I find it clunky at best.</p> <p>How can I improve error handling in th...
[]
[ { "body": "<p>From a once over </p>\n\n<ul>\n<li><p>Not everybody in CR agrees, but I find tabular data best presented in an aligned format:<br></p>\n\n<pre><code>var API = { \n list: [list , 'private'], \n login: [login , 'public' ], \n logout: [logout, 'private'], ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-15T15:47:17.820", "Id": "20547", "Score": "4", "Tags": [ "javascript", "node.js" ], "Title": "User management in Node.js" }
20547
<p>I'm tasked with getting emails from a .csv file and using them to submit a form. I am using the csv and mechanize Python libraries to achieve this.</p> <pre><code>import re import mechanize import csv def auto_email(email): br = mechanize.Browser() br.open("URL") br.select_form(name="vote_session") ...
[]
[ { "body": "<p>I would suggest to use</p>\n\n<pre><code>with open('emails.csv', \"rb\") as ifile\n</code></pre>\n\n<p>see here for details: <a href=\"http://www.python.org/dev/peps/pep-0343/\">http://www.python.org/dev/peps/pep-0343/</a>\nin this case you don't need to do <code>ifile.close</code> at the end</p>\...
{ "AcceptedAnswerId": "20549", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-15T16:16:16.327", "Id": "20548", "Score": "3", "Tags": [ "python", "beginner", "python-2.x", "csv", "email" ], "Title": "CSV email script efficiency" }
20548
<p>Below are some of the classes I have written for a small space invaders game. It's not finished but it's at the bare bones stage. I am still learning how to properly use the Slick2D library. I know where there are some problems but that is due to my lack of full knowledge of how Slick2D works, so I had to think of a...
[]
[ { "body": "<p>Caveat: I am not a Java programmer. I am an ActionScript programmer. The two languages are somewhat related, and basic design principles should carry across.</p>\n\n<p>At first glance, I don't see anything that would scare me away from hiring you if it were my decision. I would say that most of th...
{ "AcceptedAnswerId": "20565", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-15T19:30:00.457", "Id": "20551", "Score": "3", "Tags": [ "java", "game" ], "Title": "Classes for a small space invaders game" }
20551
<p><strong>User specification</strong></p> <ul> <li>"<code>var_dump($GLOBALS)</code> is ugly as <code>...</code> without wamp"</li> </ul> <p><strong>General specification</strong></p> <ul> <li>Produce a PHP function to display the contents of <code>$GLOABLS</code> in a user-friendly manner</li> <li>Must produce prop...
[]
[ { "body": "<p>Have a look at <a href=\"http://krumo.sourceforge.net/\" rel=\"nofollow\">http://krumo.sourceforge.net/</a>, maybe reinventing the wheel is not necessary :)</p>\n\n<p>Even if you don't want to use it directly, reviewing the code might help you.</p>\n", "comments": [], "meta_data": { ...
{ "AcceptedAnswerId": "20620", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-15T21:35:42.650", "Id": "20557", "Score": "1", "Tags": [ "php", "html", "php5" ], "Title": "Suggestions for improvement of HTML table building function" }
20557
<p>I have written a function to handle post data received from a web page. The Emphasis is on making getting post data easy: using the function allows the coder to specify the required data, type, and default value all in one line.</p> <p>I'm using django and it provides a nice dict of post data. this will be passed t...
[]
[ { "body": "<p>I think the code is great.</p>\n\n<p>Some comments:</p>\n\n<ol>\n<li>Transform is a tuple of 4 elements (key, type, is_default, default_value). I think is too many, it is hard to remember which means what.</li>\n<li>Since it is a tuple - if you want to provide a \"default_value\" - you need to pro...
{ "AcceptedAnswerId": "20618", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T01:47:25.057", "Id": "20564", "Score": "1", "Tags": [ "python", "django" ], "Title": "POST data handler" }
20564
<p>I have the following method that will take the car parts I searched for and match them to my car object in array. Then it tells me the percent match.</p> <p>Example:</p> <p>Car.h has NSSet toCarParts. toCarParts has may car parts.</p> <p>My array contains 5,000 or so matches.</p> <p>I will go through each one an...
[]
[ { "body": "<p>Currently you are comparing all part against all parts, so you have a squared complexity which causes trouble for bigger numbers.</p>\n\n<p>In the case that you can create your part list as <strong>sorted list</strong> (i.e. TreeSet in Java, not sure what is available in your language ) you can do...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T03:53:50.977", "Id": "20567", "Score": "1", "Tags": [ "optimization", "objective-c", "ios" ], "Title": "Optimization of percent match code" }
20567
<p>I am working on projecteuler # 14, <a href="http://projecteuler.net/problem=14" rel="nofollow">http://projecteuler.net/problem=14</a> and my code takes too long to run. Any tips, or hints for a beginner?</p> <p>Code:</p> <pre><code>//////////////////////// /// ProjectEuler # 14/// //////////////////////// #inclu...
[]
[ { "body": "<p><strong>Hint</strong></p>\n\n<p>Taking the example from the Project Euler page, if you have computed the Collatz number for 5 in the past and you know it's 6, then when computing Collatz number for 10, you probably don't need to go through the whole chain. You can stop when you reach 5.</p>\n\n<p>...
{ "AcceptedAnswerId": "20578", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T04:12:09.220", "Id": "20568", "Score": "1", "Tags": [ "c++", "project-euler" ], "Title": "Tips on projecteuler code optimization" }
20568
<p>I wrote a solution to the <a href="http://en.wikipedia.org/wiki/Knapsack_problem">Knapsack problem</a> in Python, using a bottom-up dynamic programming algorithm. It correctly computes the optimal value, given a list of items with values and weights, and a maximum allowed weight.</p> <p>Any critique on code style, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T00:18:33.647", "Id": "52860", "Score": "5", "body": "An old post, I know, but if you haven't run into it already `enumerate` allows you to specify the starting index (e.g. `for i,item in enumerate(items,1):` would have `i` begin at ...
[ { "body": "<h3>1. Review</h3>\n\n<ol>\n<li><p>The function <code>knapsack</code> lacks a docstring that would explain what arguments the function takes (what kind of things are in <code>items</code>? must <code>items</code> be a sequence, or can it be an iterable?) and what it returns.</p></li>\n<li><p>This kin...
{ "AcceptedAnswerId": "20581", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-01-16T05:52:50.383", "Id": "20569", "Score": "56", "Tags": [ "python", "algorithm", "dynamic-programming", "knapsack-problem" ], "Title": "Dynamic programming knapsack solution" ...
20569
<p>My script finds all factors of an integer. First it finds all prime integers using trial division then it uses the prime factors to find all other factors of the integer.</p> <p>I would like to know how I can improve and simplify it. I think the code that prevents duplicate factors such as 4 x 5 and 5 x 4 probably...
[]
[ { "body": "<p>Have you considered using Pollard's Rho algorithm? It's insanely fast on small integers, and really easy to implement: <a href=\"http://en.wikipedia.org/wiki/Pollard%27s_rho_algorithm#Algorithm\" rel=\"nofollow\">http://en.wikipedia.org/wiki/Pollard%27s_rho_algorithm#Algorithm</a></p>\n", "com...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T08:03:41.890", "Id": "20571", "Score": "2", "Tags": [ "javascript", "primes" ], "Title": "Find all factors of an integer" }
20571
<p>I have a program that calculates some values and saves them to an array. Before save a value, program checks if there is already an identical value in array:</p> <pre><code> string someData = GetData(); bool newItem = true; int arrayDataLength = arrayData.Length; for (int x = 0; x &lt; arrayDataLength; x++) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T14:00:50.917", "Id": "32986", "Score": "1", "body": "I would strongly suggest waiting at least a day before accepting an answer (even if it is *very* helpful), as you are likely to get more feedback." }, { "ContentLicense": ...
[ { "body": "<p><strong>1. Resizing.</strong> </p>\n\n<pre><code>Array.Resize(ref arrayData, (arrayData.Length+1);\n</code></pre>\n\n<p>It's not a good way to resize an array. You copy the whole array every time you need add just one value. You might want to consider the approach which is used in .NET collections...
{ "AcceptedAnswerId": "20585", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T10:34:51.923", "Id": "20574", "Score": "3", "Tags": [ "c#", "performance", "array" ], "Title": "Searching item in array" }
20574
<p>I have to display some set of:</p> <ul> <li>Data in serpentine order. In an experiment there are replication, range, and plot.</li> <li>Replications contains range a plot. A range contains a plot.</li> <li>If there are 2 replication, 4 ranges, and 8 plots, then each replication contains 2 ranges. Each range has 2 p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T13:52:55.247", "Id": "32985", "Score": "0", "body": "Are the two last lines in the correct order in your example ? Same question for lines 3 & 4 ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T17:16...
[ { "body": "<p>This is not a typical codereview question. It is not about reviewing code for code quality, it is asking for an algorithm improvement.</p>\n\n<p>But anyway, here we go:</p>\n\n<blockquote>\n <p>serpentine order</p>\n</blockquote>\n\n<p>I did not found any explanation on google what this is exactl...
{ "AcceptedAnswerId": "20910", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T11:57:04.043", "Id": "20580", "Score": "1", "Tags": [ "java", "algorithm", "sorting", "collections", "iteration" ], "Title": "Displaying plotted data in serpentine orde...
20580
<p>I have created a drop-down to populate a list of cities. Everything works fine, but I would like to know better ways of doing this. Also, please let me know if it is possible to create the same drop down using <code>&lt;Select&gt;</code> instead of HTML helpers.</p> <pre><code>//ViewModel public class LocationDTO ...
[]
[ { "body": "<p><strong>View Model</strong></p>\n\n<p>Looks fine to me, although I'd recommend that if all your DTO classes are to be appended with 'DTO' you instead put them inside a namespace named 'DTO' and leave the 'DTO' characters off the class names entirely.</p>\n\n<p><strong>Controller</strong></p>\n\n<p...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T14:54:08.387", "Id": "20586", "Score": "4", "Tags": [ "c#", "asp.net-mvc-3" ], "Title": "Drop-down for populating a list of cities" }
20586
<p>I am trying to create a class to queue up a series of commands. (Not really a queue as events happen based on time). Each command has a callback (Action) that get's called. However, each Action has a different set of parameters (signature), so I am using an object[] to pass them and then have to do lots of casting.<...
[]
[ { "body": "<p>Starting from minor issues - please follow naming conventions (variables should be camelCased and methods PascalCased, do add access modifiers, give variables meaningful names).</p>\n\n<p>Your design breaks <a href=\"http://en.wikipedia.org/wiki/Open/closed_principle\">Open-Closed principle</a>: Q...
{ "AcceptedAnswerId": "20588", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T15:03:50.933", "Id": "20587", "Score": "4", "Tags": [ "c#", "casting", "callback" ], "Title": "Collection of Actions" }
20587
<p>In order to create loose coupling architecture on my web applications, I have created my own implementation for ORM, in this case, NHibernate.</p> <p>I want you please to review the code and tell me if you think it can work in a real world on high traffic app.</p> <p>I have divided the API to transaction and sessi...
[]
[ { "body": "<p>I've seen many attempts to abstract particular ORM from application, and all of them at a certain stage of maturity had to break this abstraction. One of the reasons for that is when you need to optimize certain use cases (like eager-loading related entities, or combining several round trips to se...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T17:30:17.087", "Id": "20592", "Score": "2", "Tags": [ "c#", "database", "http", "session", "hibernate" ], "Title": "NHibernate session and transaction implementation" }
20592
<p>I have this code in a class that gets a string, parses it, and makes some adjustments to get a valid <code>datetime</code> format from the string.</p> <p>An input string for this function could be = "A0X031716506774"</p> <pre><code>import datetime def _eventdatetime(self, string): base_date = datetime.datetime...
[]
[ { "body": "<pre><code>import datetime\ndef _eventdatetime(self, string):\n base_date = datetime.datetime.strptime(\"1980-1-6 0:0\", \"%Y-%m-%d %H:%M\")\n</code></pre>\n\n<p>Why are you specifying the date as a string only to parse it? Just do: <code>base_date = datetime.datetime(1980,1,6,0,0)</code>. You sho...
{ "AcceptedAnswerId": "20595", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T17:45:56.693", "Id": "20593", "Score": "1", "Tags": [ "python", "performance", "datetime", "formatting" ], "Title": "Getting a valid datetime format from a string" }
20593
<p>We have a rule that all of our validation messages must be in a summary, and thus the default "this field is required" doesn't cut it because the messages lose their context in a summary and therefore need specific field indicators.</p> <p>I have a solution that I like rather well, but it soon became clear that the...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-10-03T16:26:23.240", "Id": "118404", "Score": "0", "body": "In general, you should provide a wrapping element to run your selectors on, rather than traversing the entire DOM. Also, why are you adding an empty object literal to `customMess...
[ { "body": "<p>This looks fine to me.</p>\n\n<p>I only have 2 minor points:</p>\n\n<ol>\n<li>You could assign the <code>.text()</code> once in the <code>var</code> statements so that your string concats look like <code>customMessages.email = \"'\" + label + \"' has an invalid email address.\";</code> This way yo...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T18:21:11.047", "Id": "20594", "Score": "4", "Tags": [ "javascript", "jquery", "validation" ], "Title": "Custom jQuery validation error messages" }
20594
<p>I've inherited a class which has a bunch of properties defined as:</p> <pre><code>public int ID { get { return m_nOID; } set { m_nOID = value; } } public int ConxnDetail { get { LoadDetails(); return m_nConxnDetail; } set { m_nConxnDetail = value; } } public bool ConxnConstraints { get { LoadD...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T18:44:20.433", "Id": "33011", "Score": "0", "body": "Is there a reason the data isn't loaded when the object is constructed?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T18:55:01.363", "Id": "3...
[ { "body": "<p>There is the <a href=\"http://msdn.microsoft.com/en-us/library/ms743695.aspx\" rel=\"nofollow\">INotifyPropertyChanged</a> event handler, but I'm not sure why you would need that in this case? Instead why not just load the details when the ID changes as that seems to be the only value that will c...
{ "AcceptedAnswerId": "20602", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T18:25:53.477", "Id": "20596", "Score": "1", "Tags": [ "c#", "design-patterns" ], "Title": "Calling tries to lazy load in every properties getter" }
20596
<p>I have a model <code>section</code> with a column <code>parent_id</code> - the only thing identifying a parent/child relationship. I wrote a helper method to output all sections, all their possible subsections and include their "depth".</p> <p>This is the helper method:</p> <pre><code># Calls itself for each secti...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T19:38:29.840", "Id": "33019", "Score": "0", "body": "Derp. The syntax is `all_sections.push([section.sortlabel, section.title, depth])`. I'll leave the question open to see if anyone comes up with something better." }, { "Co...
[ { "body": "<p>What I needed was the pipe operator! It was of course just doing what I was telling it to - pushing the results of itself onto the current element in the array. Only when the rootsections loop completes does it start a new array element.</p>\n\n<p>The 'pipe' (<code>|</code>) is a different array m...
{ "AcceptedAnswerId": "20651", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T19:21:16.550", "Id": "20597", "Score": "3", "Tags": [ "ruby", "array", "ruby-on-rails" ], "Title": "Retrieve all parents, all possible children, sorted and with their \"depth\"...
20597
<p>I'm trying to work with forms, and just getting a grasp on JavaScript. Basically I'm unsure if there is a more reusable way to handle forms with Meteor/jQuery.</p> <pre><code>// Creating a new prayer, including the preview Template.newPrayer.events({ 'click input.save' : function() { var tit...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-09T16:37:03.687", "Id": "70855", "Score": "0", "body": "I think you'll want to take a look at https://github.com/awatson1978/forms-kitchen-sink" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-01-12T09:49:54.52...
[ { "body": "<p>As far as I know, Meteor's reactivity is one-way: changes in data are reflected in the DOM. To go the other way (DOM to data) there's two common methods: 1) grabbing data directly from the DOM when it's needed (i.e. to save it) as you've done above and 2) binding DOM elements to data models, and u...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T21:11:37.613", "Id": "20598", "Score": "4", "Tags": [ "javascript", "template", "meteor" ], "Title": "Working with forms in Meteor, using selectors for every input" }
20598
<p>I have a model class that contains 3 <code>ArrayList</code> which are in order by parallel of the same size. <code>&lt;Object&gt;&lt;Calendar&gt;&lt;Long&gt;</code> I want to sort it by the <code>&lt;Long&gt;</code> Is this the most clean? is there a better way? This doesn't seem memory efficient.</p> <pre><code> ...
[]
[ { "body": "<p><strong>1. Correctnes.</strong></p>\n\n<p>compareTo() method of the WinningSet class is not correct. As of now Integer.MAX_VALUE &lt; System.currentTimeMillis(). Consider the following example:</p>\n\n<pre><code> long time1 = System.currentTimeMillis();\n System.out.println(time1 &gt; 3*Inte...
{ "AcceptedAnswerId": "20617", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T21:38:56.990", "Id": "20599", "Score": "2", "Tags": [ "java", "optimization", "android", "sorting" ], "Title": "Sorting parallel ArrayList" }
20599
<p>This code allows calling a method while redirecting the IO to strings. This is useful for unit testing where you have to direct something to the console or examine output that comes from it. I assume these have been written a lot, but I couldn't find examples.</p> <p>I'd like advice on how to make them generally ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-17T12:13:36.337", "Id": "33082", "Score": "0", "body": "I think the code you try to test with these methods would also benefit from a review. If you have a method that prints some output that needs to be tested than pass in the System....
[ { "body": "<p>In any case you should add the resetting of the <em>in</em> and <em>out</em> in the finally block, otherwise you will have problem in case an exception is thrown.</p>\n\n<hr>\n\n<p>Nevertheless, did you ever thought of using <a href=\"http://logging.apache.org/log4j\" rel=\"nofollow\">Log4J</a> or...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T22:07:09.143", "Id": "20600", "Score": "3", "Tags": [ "java", "unit-testing" ], "Title": "Code to redirect console IO to strings" }
20600
<p>I'm a beginner Python coder and this is the first program that I have ever programmed. Please suggest improvements/bugs. <a href="http://paste2.org/p/2756692" rel="nofollow">Here's</a> the link to the code.</p> <pre><code>global hp hp = 20 global dice import random dice = random.randint(3,5) global beardamage impo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T23:54:12.767", "Id": "33038", "Score": "1", "body": "For a start, please put all the import at the beginning of your file." } ]
[ { "body": "<pre><code>global hp\nhp = 20\n</code></pre>\n\n<p>Global only has an effect inside a function. It does absolutely nothing here. At any rate you should avoid using global.</p>\n\n<pre><code>global dice\nimport random\ndice = random.randint(3,5)\nglobal beardamage\nimport random\nbeardamage = random.r...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T22:30:52.453", "Id": "20601", "Score": "7", "Tags": [ "python", "beginner", "game", "dice", "adventure-game" ], "Title": "Python Adventure game" }
20601
<p><strong>Code Review</strong> is a question and answer site for seeking peer review of your code. It's built and run <em>by you</em> as part of the <a href="https://stackexchange.com">Stack Exchange</a> network of Q&amp;A sites. We're working together to improve the skills of programmers worldwide by taking working ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-01-17T00:19:54.120", "Id": "20605", "Score": "0", "Tags": null, "Title": null }
20605
<p>The quality of your working code with regards to:</p> <ul> <li>Best practices and design pattern usage</li> <li>Security issues</li> <li>Performance</li> <li>Correctness in unanticipated cases</li> </ul>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-17T00:20:31.763", "Id": "20606", "Score": "0", "Tags": null, "Title": null }
20606
<ul> <li>Troubleshooting, debugging, or understanding code snippets</li> <li>How to add a feature</li> <li>How to fix compile-time errors, runtime errors, or incorrect results</li> <li>Best practices in general (that is, it's okay to ask "Does this code follow common best practices?", but not "What is the best practice...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-17T00:20:56.520", "Id": "20607", "Score": "0", "Tags": null, "Title": null }
20607
<p>I found an example of <a href="http://www.obviex.com/samples/Encryption.aspx" rel="nofollow">how to implement Rijndael</a>.</p> <p>This class uses a symmetric key algorithm (Rijndael/AES) to encrypt and decrypt data. As long as encryption and decryption routines use the same parameters to generate the keys, the key...
[]
[ { "body": "<p>This code uses obsolete <code>PasswordDeriveBytes</code> class, use <code>Rfc2898DeriveBytes</code> class instead (Thanks @tom for highlighting this issue):</p>\n\n<pre><code>Rfc2898DeriveBytes password = new Rfc2898DeriveBytes(\n passPhrase,\n saltValueBytes,\n passwordIterations);\n</co...
{ "AcceptedAnswerId": "20641", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-17T00:26:19.773", "Id": "20608", "Score": "3", "Tags": [ "c#", "security", "aes" ], "Title": "Rijndael for use in production systems" }
20608