body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I have </p> <pre><code>public static class TupleExtensions { public static IEnumerable&lt;T&gt; SelectMany&lt;T&gt;(this IEnumerable&lt;Tuple&lt;T, T&gt;&gt; te) { foreach (var t in te) { yield return t.Item1; yield return t.Item2; } } public static ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-20T09:58:48.080", "Id": "42989", "Score": "0", "body": "I'd rather use collections (perhaps immutable, perhaps simple arrays)." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-20T10:00:59.283", "Id": "42...
[ { "body": "<p>In general, I think this pattern makes sense, because it clearly expresses what the method returns and lets you easily do the computation you want to do with the result.</p>\n\n<p>Some thoughts:</p>\n\n<ol>\n<li><p>I don't see any reason why your extension methods should only work on a collection ...
{ "AcceptedAnswerId": "27589", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-20T09:10:55.433", "Id": "27586", "Score": "3", "Tags": [ "c#", "linq" ], "Title": "I've started Tuples to LINQ and I'm not sure if it's an anti pattern" }
27586
<p>This service object allows users without a session to create a comment, and register OR login at the same time.</p> <p>If a user is signed out he must enter an email and a password along with the comment.</p> <p>The service checks if a user exists using the email, then attempts to authenticate the user. Otherwise,...
[]
[ { "body": "<p>My opinions:</p>\n\n<ol>\n<li>The class methods <code>by</code> and others are unnecessary.</li>\n<li>The service object should be initialized by feeding objects instead of params.</li>\n<li>Build a guest user is not job of CommentService.</li>\n</ol>\n\n<p>Then code like these:</p>\n\n<pre><code>...
{ "AcceptedAnswerId": "27597", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-20T13:50:39.080", "Id": "27592", "Score": "1", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Registering or logging in when creating a new comment object" }
27592
<p>I have come across the following piece of code</p> <pre><code> if (Region.Current == Region.EU) { return RegionalPriceLN; } else if (Region.Current == Region.NY) { return RegionalPriceNY; } else if (Region.Current == Region.HK) { return RegionalPriceHK; } else i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-21T09:34:42.030", "Id": "43064", "Score": "0", "body": "What is the rationale for storing anonymous functions rather than the objects themselves?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-21T18:46:10....
[ { "body": "<p>Second option is definitely a preferred way over first one. Also you may consider a <code>switch</code> statement.</p>\n\n<p><strong>UPDATE</strong>. Since Region is a class then the only good way to avoid long <code>if...else</code> is the mapping like in your second variant</p>\n\n<p>First optio...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-20T14:06:19.547", "Id": "27594", "Score": "1", "Tags": [ "c#" ], "Title": "Refactoring from if-else-if to Dictionary" }
27594
<p>I am new to learning Repository Pattern. I am developing a site in MVC 4 (I'm new to it as well).</p> <p>The way I am using Repository pattern as follows:</p> <ol> <li><p>I created <code>IRepository&lt;T&gt;</code> interface as follows:</p> <pre><code>public interface IRepository&lt;T&gt; { void I...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-02-22T19:49:33.403", "Id": "148044", "Score": "0", "body": "Implementation seem fine to me but if you like you could drop the `IRepository<T>` and have only `abstract BaseRepository<T>`." } ]
[ { "body": "<ol>\n<li><p>You can make <code>DbContext</code> protected property in your base implementation, so you don't have to declare it in every single derived class.</p></li>\n<li><p>You might want to consider extracting <code>Insert</code> and <code>Delete</code> methods to separate interface, because oft...
{ "AcceptedAnswerId": "27618", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-20T14:53:13.667", "Id": "27598", "Score": "18", "Tags": [ "c#", "design-patterns", "asp.net-mvc-4" ], "Title": "Following Repository Pattern properly" }
27598
<p>I wrote the following code to take the heading of an object, and determine which direction <code>(x,y)</code> it needs to move to be heading forward in a 2D plane. I have debugged the code and know that it functions as expected, but as far as readability/maintainability is concerned, I feel like it could be better. ...
[]
[ { "body": "<p>I'll separate this into two sections: readability and maintainability. I'm not exactly sure of the usage, so I don't feel I can comment on that.</p>\n<h2>Readability</h2>\n<p>Personally, I think the largest burden on the cleanliness of this code, is the comments. I think they're too large and ther...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-20T16:13:00.217", "Id": "27600", "Score": "7", "Tags": [ "php", "optimization" ], "Title": "Remapping Heading Angle to Coordinates to Move By" }
27600
<p>The rules for this script are simple:</p> <ul> <li>If geocode is hit, then just geocode</li> <li>If geocode and submit is hit, then geocode and then submit</li> <li>If an autosuggest link is hit, then geocode instantly</li> <li>In this case, do not re-geocode later when the button is hit</li> </ul> <p>This is my c...
[]
[ { "body": "<p>Just a few things in no particular order:</p>\n\n<ul>\n<li>Don't use <code>long</code> as a variable name. It's a reserved word in Javascript and can cause confusion.</li>\n<li>If you're going to disable the country input in your form, you should probably just put the US keyword straight in your c...
{ "AcceptedAnswerId": "27648", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-20T16:21:35.363", "Id": "27601", "Score": "1", "Tags": [ "javascript", "jquery", "optimization", "performance", "functional-programming" ], "Title": "Jquery Geocoding Scri...
27601
<p>In the case that Type is not an option, data must exist so I just use an assert to clarify and throw an exception if data is missing. Is there a better way to do this? I think in Java this would be acceptable but I know the scala crowd tends to have a different idea of what idiomatic use of the language is.</p> <pr...
[]
[ { "body": "<p>In short: yes, assertions make perfect sense outside testing and can raise the confidence that the code is actually correct.</p>\n\n<h2>Design by contract</h2>\n\n<p>What you like to assert, namely, that <em>\"<code>dataOption</code> must be defined if <code>tpe</code> does not represent a subtype...
{ "AcceptedAnswerId": "27619", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-20T17:02:02.393", "Id": "27602", "Score": "0", "Tags": [ "scala" ], "Title": "Scala: Are assertions acceptable outside of test context?" }
27602
<p>For my classes, I had to finish this task:</p> <blockquote> <p><strong>Directory's disk usage list</strong></p> <p>For indicated directory print a list of files and subdirectories in descending order according to their total disk usage. Disk usage of a simple file is equivalent to its size, for a subdire...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-20T19:24:38.167", "Id": "43025", "Score": "0", "body": "I guess they want you to use recursion? \"CAUTION: during recursive directories listing do not dereference symbolic links.\" : your solution is iterative" }, { "ContentLic...
[ { "body": "<p>I just copied your code, pasted it in to a terminal, ran it, and it did exactly what it is supposed to do. Now, how to make it better?</p>\n<p>You don't mention it in the question, but using <code>ls</code>, <code>awk</code>, <code>find</code>, and <code>sort</code> together somehow seems unlikely...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-20T17:40:07.467", "Id": "27603", "Score": "5", "Tags": [ "bash", "linux", "file-system", "awk" ], "Title": "Directory's disk usage list" }
27603
<p>We are beginning to learn Node.js and we are not always sure if we do it the right way. We have a strong object oriented background so the adoption is not always easy. Right now we implemented a factory method, but we are not completely sure if our approach is good. </p> <p>Factory Method:</p> <pre><code>var fs = ...
[]
[ { "body": "<p>When using callbacks, the first parameter is the error. So instead of throwing the error, you should pass it as the first argument. The signature of the callback should look like this <code>function(err, all, other, arguments)</code>.</p>\n\n<p>So instead of this</p>\n\n<pre><code>var fs = require...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-20T17:44:58.140", "Id": "27604", "Score": "1", "Tags": [ "javascript", "design-patterns", "unit-testing", "node.js", "asynchronous" ], "Title": "Is this factory method a good...
27604
<p>I have these classes that have a boilerplate way of initialization. So, instead of writing it each time, I wrote a class called <code>MockUtil.java</code>, and I put the boilerplate mocks in there.</p> <p><code>MockUtil</code> has static variables and methods which can be called to do the mocking for the test class...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-21T07:44:46.983", "Id": "43059", "Score": "0", "body": "If you are telling a mocked object to return another mocked object you are doing it wrong. Also all this code does not seem to do anything useful." }, { "ContentLicense": ...
[ { "body": "<p>You are right about the problem with static variables and methods possibly causing problems in a multithreaded environment. I recommend turning your MockUtil into an abstract class with no static methods and then have your test classes extend that. That way you are guaranteed to have fresh mocks f...
{ "AcceptedAnswerId": "27681", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-20T20:38:18.980", "Id": "27608", "Score": "3", "Tags": [ "java", "design-patterns", "unit-testing", "junit" ], "Title": "Mocking utility class for database testing" }
27608
<p>I'm going to implement something like the Unity3D component model for my C++ game engine. Please, review my draft of the <code>Component</code> base class:</p> <pre><code>class Component { public: template&lt;class T&gt; static T* create(void) { if (Type&lt;T&gt;::id == 0) Type&lt;T&...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-20T22:28:38.357", "Id": "43043", "Score": "2", "body": "Any particular reason why you’re rolling your own RTTI, when C++ has a perfectly good built in facility for that?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate...
[ { "body": "<p>Sorry, but this is simply not a good design.</p>\n\n<p>Your reliance on memory-owning raw pointers means that the library is easy to use wrongly, and that the user will leak memory. This is a big no-no in modern C++. First, because it’s harmful and makes user code brittle and complex; and second, ...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-20T22:13:42.793", "Id": "27612", "Score": "4", "Tags": [ "c++" ], "Title": "Component implementation" }
27612
<p>This is the console program that I've written in C++. It's a game where you have to guess a randomly picked number within the range 0-200. I just took a look at syntax and how to get started with C++ and VS and I was able to write this game almost immediately, but tweaking and improving it took me some time. I have ...
[]
[ { "body": "<ul>\n<li><p>There's no need for <code>printf()</code> and <code>scanf()</code> in C++. Instead, use:</p>\n\n<ul>\n<li><code>std::cout &lt;&lt; \"Some text...\" &lt;&lt; aVariable;</code> for outputting, or</li>\n<li><code>std::cin &gt;&gt; aVariable;</code> for inputting</li>\n</ul></li>\n<li><p>In...
{ "AcceptedAnswerId": "27614", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-21T01:13:12.033", "Id": "27613", "Score": "7", "Tags": [ "c++", "game", "number-guessing-game" ], "Title": "Console guess game" }
27613
<p>It works and does what is supposed what to do btw.</p> <pre><code>&lt;?php ob_start(); session_start(); include("php/connect.php"); ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml...
[]
[ { "body": "<p>It was not easy, but the first step for improving your code is to split the layout from the logic:</p>\n\n<p>layout.php</p>\n\n<pre><code>&lt;!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"&gt;\n&lt;html xmlns=\"http://www.w3.org/1999...
{ "AcceptedAnswerId": "27627", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-21T05:12:01.453", "Id": "27615", "Score": "1", "Tags": [ "php", "sql", "authentication", "session" ], "Title": "Social football site with authentication and user statistics" }
27615
<p>I am trying to make a textbox which filters user input to match specified type, so I can discard some of my validation logic.</p> <p>For example, if I specify <code>ushort</code> I want my textbox to only accept text changes which result in a valid <code>ushort</code> value and nothing else.</p> <p>This is what I'...
[]
[ { "body": "<p>I think what your code is missing the most is documentation and some better naming. The constructor takes a regex string (with a very generic name <code>regexPattern</code>) and you <em>also</em> have to override <code>TryParse()</code>. There is absolutely no indication of why both are needed, wi...
{ "AcceptedAnswerId": "27816", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-21T08:23:14.993", "Id": "27620", "Score": "5", "Tags": [ "c#", "wpf" ], "Title": "Filtered WPF textbox" }
27620
<p>I am working on a project that needs algebra operations. I have coded a <code>Matrix</code> class (only needed 4x4 matrix), and a <code>Vector4</code> class. The classes working fine, but I would know if there are some bad practices that I use, and want you to help me improve this classes. Last time I encountered so...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2018-08-05T04:17:51.583", "Id": "387120", "Score": "1", "body": "How come `w` is `1.0f` by default instead of `0.0f` like the other components?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2018-08-05T19:38:31.253", ...
[ { "body": "<p>For the <code>Matrix</code>, I’d consider replacing the 16 <code>float</code> constructor with an <code>initializer_list</code> constructor, and adding a copy constructor.</p>\n\n<p>I agree that your <code>Vector4</code> class is rather ugly. Two ways of accomplishing what you want:</p>\n\n<ol>\n<...
{ "AcceptedAnswerId": "27672", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-21T11:12:10.640", "Id": "27625", "Score": "2", "Tags": [ "c++", "matrix" ], "Title": "Matrix and Vector4 classes" }
27625
<p>This Lua code runs in redis. It iterates over some JSON docs, and applies some logic based on the user (if any) making the request. I'm sure there's a lot I can improve here.</p> <pre><code>local function iterAll(limit) local start = 0 local stop = limit-1 local ids = redis.call('zrevrange', 'questions-by-lat...
[]
[ { "body": "<p>Firstly, you've hard-coded all of your key names instead of using the <code>KEYS</code> table for passing them to the script - this is both hard to maintain as well as incompatible with clustering.</p>\n\n<p>Next, consider using MessagePack (<code>cmsgpack</code> in Redis' Lua) instead of JSON whe...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-21T13:23:38.323", "Id": "27632", "Score": "6", "Tags": [ "beginner", "lua", "redis" ], "Title": "Iterating over JSON docs" }
27632
<p>I have this code:</p> <pre><code>if(listObj.Any(x =&gt; x.id &lt; 0)) { foreach(ModelClass item in listObj) { if(item.id &lt; 0) { // code to create a new Obj in the database } } } </code></pre> <p>But, should I use like this?</p> <pre><code>foreach(ModelClass item in ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-01-06T10:16:59.033", "Id": "501676", "Score": "0", "body": "us a simple for loop and not a foreach and remove any linq code if you need performance\nand if you need to do it really fast use an unmanaged for loop" } ]
[ { "body": "<p>Use <code>.Where</code> extension method to filter the records you need:</p>\n\n<pre><code>foreach(ModelClass item in listObj.Where(x =&gt; x.id &lt; 0))\n{\n // code to create a new Obj in the database\n}\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", ...
{ "AcceptedAnswerId": "27635", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-06-21T14:14:06.610", "Id": "27633", "Score": "1", "Tags": [ "c#", "performance", ".net", "linq" ], "Title": "Should I use and loop, or just a loop?" }
27633
<p>This is one of my first steps with GUI. I've tried an implementation of <a href="http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" rel="nofollow">Conway's Game of Life</a> with TkInter. I would appreciate any opinions about my code, especially about the separation of GUI and logic.</p> <pre><code>import Tkinte...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-21T15:49:11.673", "Id": "43083", "Score": "0", "body": "I'd advice you to have a look at http://www.youtube.com/watch?v=o9pEzgHorH0 from the 17th minute." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-21T1...
[ { "body": "<p>In terms of your specific question, I think you have done a good job of separating out the simulation and the presentation. However, you have a few slightly awkward bits of code:</p>\n\n<pre><code>def change(self):\n \"\"\" Changes from dead to alive and vice-versa. \"\"\"\n if self.is_alive...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-21T15:26:46.153", "Id": "27638", "Score": "6", "Tags": [ "python", "game-of-life", "tkinter" ], "Title": "Game of Life, separation of logic / GUI" }
27638
<p>I am currently trying to improve on a query that is being used to build a view. The query is in PL/SQL, in an Oracle database. There are 3 different types of reports (100,200, and 300) that are generated at each building. We track the consecutive years that each report is generated, and based on the combination of (...
[]
[ { "body": "<p><code>cte1</code>, besides needing a better name, needs to just be a fully-fledged table. With 63 combinations, it takes a while to process how to get all these in correctly. Putting this in a view doesn't speed up that CTE at all. So, just create a permanent table in the database preloaded wit...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-21T16:03:50.503", "Id": "27640", "Score": "5", "Tags": [ "performance", "sql", "oracle", "plsql" ], "Title": "Query for building a view" }
27640
<blockquote> <p>A company sells iPods online. There are 100 stocks maintained at Argentina and Brazil. A single iPod costs $100 in Brazil and $50 in Argentina. The cost of exporting stocks from one country to the other will cost $400 per 10 blocks. The transportation is always done in the multiples of 10. C...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-10-20T06:37:17.327", "Id": "122618", "Score": "1", "body": "[Apparent source of the challenge](http://permalink.gmane.org/gmane.comp.programming.algogeeks/18046)" } ]
[ { "body": "<p>You can write</p>\n\n<pre><code>if raw_input(\"Enter the country from which you order from\") == \"Brazil\":\n c = 1\nelse:\n c = 2\n</code></pre>\n\n<p>instead of</p>\n\n<pre><code>print \"Enter the country from which you order from\"\nx=raw_input()\nif x==\"Brazil\":\n c=1\nelse:\n c...
{ "AcceptedAnswerId": "27645", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-21T17:23:18.953", "Id": "27642", "Score": "1", "Tags": [ "python", "programming-challenge" ], "Title": "Stocks of iPods for various countries" }
27642
<p>I'm still learning jQuery and am wondering if there are other ways to put <code>.each()</code> inside another <code>.each()</code> function:</p> <p>JavaScript:</p> <pre><code>$("ul").each(function(index){ $("#uid" + index + " li").each(function(listItemIndex){ var listItemWidth = $(this).width(); ...
[]
[ { "body": "<pre><code>$(\"ul\").each(function() {\n var ul = this;\n $(ul).children('li').each(function(listItemIndex) {\n if (listItemIndex &gt; 0) {\n var listItemWidth = $(this).width();\n var listItemPosition = listItemIndex * (listItemWidth + 10);\n $(this).css...
{ "AcceptedAnswerId": "27647", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-21T17:35:22.377", "Id": "27643", "Score": "-2", "Tags": [ "javascript", "jquery", "html" ], "Title": ".each() inside another .each() function" }
27643
<p>I was doing this particular problem <a href="http://www.spoj.com/problems/AIBOHP/">AIBOHP</a> and used a dp approach based on checking the ends of a substring of length i starting from 1. Although my time complexity is fine at O(n^2) but space is taking too much because of which I am getting RTE if I am declaring it...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-08T02:30:46.110", "Id": "46698", "Score": "0", "body": "Maybe you can reduce the memory consumption by a constant factor, but I'm not sure about reducing the space complexity. A simple hint could be: use `short int` instead of `int`, b...
[ { "body": "<h1>Things you did well:</h1>\n\n<ul>\n<li><p>Usage of <code>static</code>.</p></li>\n<li><p>Using <code>memset()</code> instead of some <code>for</code> loops for initialization of your <code>int[][]</code>.</p></li>\n</ul>\n\n<h1>Things you could improve:</h1>\n\n<h3>User Experience:</h3>\n\n<ul>\n...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-21T18:28:34.710", "Id": "27644", "Score": "7", "Tags": [ "optimization", "c", "algorithm", "strings", "palindrome" ], "Title": "Checking ends of a substring" }
27644
<p>I have written a Custom Log4J Appender which is responsible for sending the log message to a third party service asynchronously. It is expected to be called every millisecond.</p> <p>I ran FindBugs on this code, it didn't report anything unusual. But before releasing this code to production, how can I know if this ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-22T05:06:59.537", "Id": "43097", "Score": "0", "body": "If you want a very simple check if whether your code has any issues then test it against this very simple checklist http://www.codinghorror.com/blog/2006/05/code-smells.html Code ...
[ { "body": "<p>Add source code comments. Why does the class exist? What does it do? What do each of the methods do? What are their pre- and post-conditions?</p>\n\n<p>This code:</p>\n\n<pre><code>ArrayList&lt;LoggingEvent&gt; buffer = new ArrayList&lt;LoggingEvent&gt;();\n</code></pre>\n\n<p>Should be:</p>\n\n<p...
{ "AcceptedAnswerId": "27663", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-21T22:27:06.407", "Id": "27650", "Score": "0", "Tags": [ "java" ], "Title": "Custom Log4J Appender" }
27650
<p>Write a program that lets users keep track of the last time they talked to each of their friends. Users should be able to add new friends (as many as they want!) and store the number of days ago that they last talked to each friend. Let users update this value (but don't let them put in bogus numbers like negative v...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-22T16:33:00.657", "Id": "43115", "Score": "1", "body": "Why are you writing your own primitive version of `vector`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-22T19:37:49.373", "Id": "43136", "...
[ { "body": "<p>First of all the \"growArray\" function will never be called since you put it inside an if block that runs only once. when the if statement is evaluated your size is 10 and your next_element+1 is 1 and you never check for (size == next_element+1) again.</p>\n", "comments": [], "meta_data":...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-21T23:22:00.013", "Id": "27651", "Score": "0", "Tags": [ "c++" ], "Title": "keep track of friends and number of days not spoken to, dynamic memory location" }
27651
<p>I'm a photographer doing many backups. Over the years I found myself with a lot of hard drives. Now I bought a NAS and copied all my pictures on one 3TB RAID 1 using rsync. According to my script, about 1TB of those files are duplicates. That comes from doing multiple backups before deleting files on my laptop and b...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T18:25:49.593", "Id": "43217", "Score": "0", "body": "Python 2.7.5 right?" } ]
[ { "body": "<p>Your code is very risky because you use a weak checksum (md5 - see <a href=\"http://en.wikipedia.org/wiki/Cryptographic_hash_function#Cryptographic_hash_algorithms\" rel=\"nofollow noreferrer\">wikipedia for own study</a>), but since an error would be devastating please use sha256.</p>\n<p>Let me ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-22T00:07:19.347", "Id": "27652", "Score": "5", "Tags": [ "python", "linux", "file-system" ], "Title": "Replacing duplicate files with hard links" }
27652
<p>The code works but I want to split it into functions and make it more reusable. The way it is now, the code is not reusable. I want the parts which replaces the query string and the part that populates with the number of items to be reusable for other classes, so ideally I want to make'em functions but then I suppos...
[]
[ { "body": "<p>Start with making a dictionary for the regionId-to-name part:</p>\n\n<pre><code>region_id_to_name = {'4694186': 'Andhra Pradesh', ... } #very long\n</code></pre>\n\n<p>And put it, along the <code>form.w.choices</code> list (which is actually exactly the same dictionary) outside the class, or as an...
{ "AcceptedAnswerId": "27675", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-22T09:31:07.527", "Id": "27657", "Score": "6", "Tags": [ "python", "search", "google-app-engine" ], "Title": "Handling regional search requests" }
27657
<p>I'm using JPA 2.0, Mojarra 2.1.9 and its component library Primefaces 3.5. I have a table in MySQL database named <code>state_table</code> with three columns.</p> <ul> <li>state_id (BigInt)</li> <li>state_name (Varchar)</li> <li>country_id (BigInt)</li> </ul> <p><code>state_id</code> is a auto-generated primary ke...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-08T14:39:14.253", "Id": "46715", "Score": "0", "body": "You probably have to use introspection (or Commons BeanUtils), to get rid of the if-else-if's. Something like: \"if the key does not contain a dot, get the property with this name...
[ { "body": "<p>I believe, you should not mix your architecture layers. \n<code>SortMeta</code> is a GUI class. If you want to change your GUI-Framework, or use another one, you have to refactor your Finder. Therefore you should not use <code>SortMeta</code> (GUI-Class) in your business layer. </p>\n", "comme...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-22T10:50:19.320", "Id": "27659", "Score": "3", "Tags": [ "java", "jpa", "jsf-2" ], "Title": "Efficient way of handling multiple sorting and filtering using JPA" }
27659
<p>I was asking if the following code has a correct semantically markup, or can it better, and so yes, how:</p> <pre><code> &lt;!-- Start container website --&gt; &lt;header id="header"&gt; &lt;div class="container_12"&gt; &lt;div class="grid_12"&gt; &lt;a href="#" id="logo"&...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-22T14:04:35.417", "Id": "43107", "Score": "0", "body": "Your HTML is not valid. You should [validate](http://validator.w3.org/check) it and correct the errors first (e.g. your `div` with the ID `image-loop` contains `li` elements, whic...
[ { "body": "<p>First of all: You have a lot of meaningless div elements nested in eachother. I'm sure you can remove most of them and just add those classes to their parent or child element.</p>\n\n<p>Then some semantical tips. Please note that semantic is somewhat an opinion, so I'm just posting my thoughts:</p...
{ "AcceptedAnswerId": "27687", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-22T11:32:05.293", "Id": "27660", "Score": "2", "Tags": [ "html5" ], "Title": "Is the HTML5 markup right implemented and semantically correct?" }
27660
<p>I recently created the following code, which is supposed to implement a Pong variation for one player. How can I improve or optimize my code?</p> <p><code>Pong</code> class:</p> <pre><code>import javax.swing.JFrame; public class Pong extends JFrame { private static final int HEIGHT = 500, WIDTH = 900; pu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-22T21:50:55.583", "Id": "43145", "Score": "0", "body": "I reviewed another Pong program just a couple of weeks ago, you might want to check that out: http://codereview.stackexchange.com/questions/27197/code-review-for-pong-in-java/2721...
[ { "body": "<p>A few observations</p>\n\n<p>In the <code>PongPanel</code> class, I had to change the following line</p>\n\n<pre><code>ball = new Ball(game);\n</code></pre>\n\n<p>to </p>\n\n<pre><code>ball = new Ball();\n</code></pre>\n\n<p>to remove the error. I'm not sure whether the error was in the construct...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-22T16:54:29.107", "Id": "27665", "Score": "0", "Tags": [ "java", "object-oriented", "game", "swing" ], "Title": "Single-player Pong game in Java" }
27665
<p>I'm looking for some opinions on this bit of code that I wrote and if there are any ways it can be improved.</p> <p>The scripts aim is to run the function runme() every 60 seconds with a random interval anywhere between -20 seconds to +40 seconds so it could run randomly anywhere between 40 seconds and 100 seconds....
[]
[ { "body": "<p>I don't think you do need the scheduler for that, at least not for how you use it.\nYour loop schedules 1 event and just afterwards waits until it's finished, since run() waits until the scheduled event(s) are completed.</p>\n\n<p>You can achieve the same by just sleeping for <code>runtime</code> ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-22T19:13:31.650", "Id": "27673", "Score": "2", "Tags": [ "python", "random", "timer", "python-2.x" ], "Title": "Opinions/Improvements on a run periodically/timer function in Pyth...
27673
<p>I implemented a strongly connected graph code in C++.</p> <p><strong>matrix_graph.h</strong></p> <pre><code>#pragma once #include "stdafx.h" class matrix_graph { private: int** v; int vertexes; public: matrix_graph(int**, int); ~matrix_graph(void); void reverse(); int get_max_vertexes(); ...
[]
[ { "body": "<p>Firstly, I think you class name can be improved somewhat. Sure, it tells you the underlying data structure that the graph will use (sort of, anyway), but it doesn't tell you anything about what <strong>kind</strong> of graph it is. Unless you read the source, you won't know that this is supposed t...
{ "AcceptedAnswerId": "27695", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-22T20:34:44.313", "Id": "27677", "Score": "2", "Tags": [ "c++", "graph" ], "Title": "Strongly-connected component for a graph" }
27677
<p>First of all, I'm really new to SFML and making GUIs. This is my first real program using this.</p> <p>Right now, when I click outside the window when the program is first run, the first piece is placed in the top left corner without clicking that square. It works as I want it to every time after that, with an er...
[]
[ { "body": "<p><strong>Click Event</strong></p>\n\n<p>I apologize, the computer I'm on doesn't have SFML installed but I'll try to get to this later(probably tomorrow). One thing I noticed, though, is in isClickInBounds you do:</p>\n\n<pre><code> event.mouseButton.x &gt;= square[boardPos].left \n&amp;&amp; ev...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-22T20:55:27.040", "Id": "27679", "Score": "3", "Tags": [ "c++", "game", "gui", "tic-tac-toe", "sfml" ], "Title": "Graphical Tic-Tac-Toe game using SFML" }
27679
<pre><code> trait Comonad[M[_]] { // map def &gt;&gt;[A,B](a: M[A])(f: A =&gt; B): M[B] // extract | coeta def counit[A](a:M[A]): A // coflatten | comu def cojoin[A](a: M[A]): M[M[A]] } object Comonad { implicit def listComonad[A]: Comonad[List] = new Comonad[List] { def counit[A](...
[]
[ { "body": "<p>I believe, what's bothering you is a non-total definition of <code>counit</code>, right? (for <code>cojoin</code> one possible variation is <code>lsa.tails</code>) Indeed, a <code>List</code> does not have a valid comonad instance specifically bacause of that. It does have a valid <a href=\"http:/...
{ "AcceptedAnswerId": "27691", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-23T02:57:33.950", "Id": "27685", "Score": "3", "Tags": [ "functional-programming", "scala" ], "Title": "Simple Comonads in Scala?" }
27685
<p>I was wondering about on how to organise the code on my site, to make it clearer as possible and clearly readable. </p> <p>I'm organising it with <code>namespace</code>, separating every single section of the page. </p> <p>For example:</p> <pre><code>var Header = { //code relative to the header } var CentralBody...
[]
[ { "body": "<p>A conceptual question, those are always tricky.</p>\n\n<p>Organizing by namespace is not a bad idea, though I would lowercase your namespace ( <code>Header</code> -> <code>header</code> etc. )</p>\n\n<p>Furthermore, I would suggest to look into <a href=\"http://en.wikipedia.org/wiki/Model%E2%80%93...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-23T10:36:01.400", "Id": "27688", "Score": "2", "Tags": [ "javascript", "jquery", "object-oriented" ], "Title": "Organise site's module" }
27688
<p>I am writing a <a href="http://en.wikipedia.org/wiki/Nonogram" rel="nofollow">Nonogram</a> game in JavaScript.</p> <p>I would like to know your opinions on the code and suggestions on how to improve it.</p> <p>I'm using a MVC approach.</p> <ul> <li>the Model has two matrices (represented as linear arrays): one wi...
[]
[ { "body": "<p>In general, it looks good to me.</p>\n\n<p>My 2 cents:</p>\n\n<ul>\n<li><p>I am not sure why you have event related things in your model</p></li>\n<li><p><code>iterateOverDraggedCells</code> looked like it could use some refactoring.</p>\n\n<ul>\n<li>Whenever you start with x1,y1,x2,y2, I think it...
{ "AcceptedAnswerId": "30789", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-23T10:47:16.950", "Id": "27689", "Score": "10", "Tags": [ "javascript", "jquery", "html", "css", "game" ], "Title": "Nonogram game in JavaScript" }
27689
<p>I'm taking a sentence and determining whether or not it is a palindrome. I'm doing this while learning about stacks.</p> <ol> <li><p>Is there a way I can use pointers instead of <code>char</code> array 'sent' so that the number of input characters need not be constrained to 20 in the following code?</p></li> <li><p...
[]
[ { "body": "<p>Where to start ;) Some hints:</p>\n\n<ol>\n<li>Was is part of the task to use a stack for this? You could easily check for the palindrome just on the char array by looping over it from left to right.</li>\n<li>Why using two different data structures for the same content: an char array for data ent...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-23T11:03:56.730", "Id": "27690", "Score": "2", "Tags": [ "c", "stack", "palindrome" ], "Title": "Using pointers for string manipulation" }
27690
<p>I present a bunch of grids of data to the user, and want to sum certain columns in some of the grids.</p> <pre><code>// for one such grid: rows = [{id: 0, name: "Alice", age: "23"}, {id: 1, name: "Bob", age: "25"} /* ... */] sum_aggregator = { init: function() { return 0 }, step: function(l, r) { ...
[]
[ { "body": "<p>This is the first time I have heard \"vtabels\", the more known term is <a href=\"http://en.wikipedia.org/wiki/Decision_table\" rel=\"nofollow\">decision table</a>. Also, on the contrary, using decision tables is <em>very</em> idiomatic JavaScript and is used often, just rarely with lambdas and mo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-23T12:42:11.787", "Id": "27693", "Score": "1", "Tags": [ "javascript" ], "Title": "Data and vtables vs. objects and methods" }
27693
<p>I have solved one <a href="http://codeforces.com/problemset/problem/317/B" rel="nofollow">problem</a> on Codeforces and I guess the output is quite correct. However, it is slow for input in range of thousands. Since, I am learning Python now, it would be great help if one could help me optimise this code. Any notes,...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T14:51:53.307", "Id": "43207", "Score": "0", "body": "I've added an answer. I don't have the right version of python handy but it should again make your script orders of magnitude faster. I'd be interested in the results if you were ...
[ { "body": "<p>A few things:</p>\n\n<ul>\n<li><p>You should probably put the <code>start = time.time()</code> as early as possible if you want it to make sense.</p></li>\n<li><p>As your class consists on a simple dict, there is no or little value in defining it. (In a \"real life\" scenario, it would be consider...
{ "AcceptedAnswerId": "27731", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-23T15:50:17.277", "Id": "27699", "Score": "2", "Tags": [ "python", "optimization", "algorithm" ], "Title": "Codeforces problem python code optimization" }
27699
<p>I've written a simple program to test out the capabilities of <a href="http://hackage.haskell.org/package/netwire" rel="nofollow">netwire</a> (or rather, how to write programs using netwire). The goal is to have an application that shows a window, starting out as completely filled with red. Pressing space should swi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-25T04:36:48.463", "Id": "43250", "Score": "0", "body": "Wow, that does really look like a heck of a lot of haskell for what it does, and it's also kind of hard to penetrate... Normally I find haskell a bit more readable, I wonder if th...
[ { "body": "<p>Your iff function would be better expressed with <code>&lt;|&gt;</code> or <code>msum</code>. They're for making a choice, so one of them ought be used in place of <code>iff</code>, I'm not sure where the <code>True</code>/<code>False</code> values are feeding out into <code>iff</code>, but I woul...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-23T16:24:37.533", "Id": "27701", "Score": "3", "Tags": [ "haskell" ], "Title": "Simple netwire program" }
27701
<p>I am trying to solve <a href="http://www.spoj.com/problems/PRIME1/" rel="nofollow">this</a> problem on Sphere Online Judge. I keep getting a timeout error. Any comments or suggestions are welcome and appreciated.</p> <pre><code>package info.danforbes.sphere; import java.io.BufferedReader; import java.io.BufferedWr...
[]
[ { "body": "<p>I'll make general statements not addressing (or not limited to) performance.</p>\n\n<hr>\n\n<p>Your overall design is not very Object-Oriented. Usage of static/global variables is discouraged for a reason, it is very hard to follow the flow the program. Consider rewriting it with proper classes/en...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-23T17:45:23.233", "Id": "27702", "Score": "1", "Tags": [ "java", "optimization", "primes" ], "Title": "Sphere Online Judge, Problem 2: Prime Number Generator" }
27702
<p>I made an android app which utilizes SSDP for automatic device discovery.</p> <p>Because I didn't need the whole UPnP functionality, I wrote my own independent SSDP component.</p> <p>It works well, but I feel like I might've made the implementation way more complex than it needs to by adding too much indirection/a...
[]
[ { "body": "<p>The <code>SSDPMainComponent</code> is doing <em>four</em> different jobs (the code for <code>StartPeriodicNotify()</code> seems to be missing though). Yet on closer inspection those jobs have very little in common. Some share the same socket, but that's it.</p>\n\n<p>We can simply refactor SSDMain...
{ "AcceptedAnswerId": "27775", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-23T18:07:49.647", "Id": "27704", "Score": "4", "Tags": [ "java", "android", "networking" ], "Title": "Using SSDP for automatic device discovery" }
27704
<p>Right now I'm creating a community. You can register and create your own profile and post on a forum etc. I'm just doing this for fun and learning. I'm not planning on becoming a professional programmer this is just a hobby of mine.</p> <p>Anyway, I want do it right though. Please review my script and tell me if it...
[]
[ { "body": "<p>I can't say it is plain wrong, but the <code>LEFT JOIN</code> against groups makes me twitch when I read it, because it is so crucial that this password check works. I'd split it off into a separate query that you run after the user has been authorized.</p>\n\n<p>Then, in <code>$_SESSION['user'] =...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-23T20:01:51.920", "Id": "27707", "Score": "5", "Tags": [ "php", "pdo", "authentication" ], "Title": "Registration and login" }
27707
<p>It's a standalone HTML file on <a href="https://github.com/mike-joyce/Mastermind/blob/master/Mastermind.html" rel="nofollow">GitHub</a></p> <p>I included the CSS and JavaScript with the HTML so it would be easier to e-mail the game.</p> <p>I'm most interested in comments about the solution-checking functions. This...
[]
[ { "body": "<p>The first thing I notice is that you're \"manually\" handling both color and position. This isn't actually necessary if you set everything up using simple arrays.</p>\n\n<p>An array is, by definition, an indexed list of values. So if you use a simple array for your code and the pegs, then position...
{ "AcceptedAnswerId": "37456", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-23T21:42:55.007", "Id": "27710", "Score": "4", "Tags": [ "javascript", "game" ], "Title": "How can I improve this version of the board game Mastermind?" }
27710
<p>I'm currently doing my first internship and had to create an application that will check through the first row of a CSV for valid or invalid input. Is there a more elegant way to code or to refactor my FileValidator class? This is my first time programming in a professional environment, so I'm still trying to learn ...
[]
[ { "body": "<ul>\n<li>Declare your <code>BUSINESS</code> constant as final</li>\n<li><code>readFile</code> will currently always return 'true', barring some unforeseen exception. Seems like you could make it a void method as well.</li>\n<li><code>validateFile</code> is a bit bad method name. Imagine it being use...
{ "AcceptedAnswerId": "27712", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-23T21:56:56.513", "Id": "27711", "Score": "3", "Tags": [ "java", "csv", "excel" ], "Title": "Is there a better or more elegant way to code this CSV cell-parser (using CSVReader)?"...
27711
<p>I wrote <a href="https://github.com/jrenner/libgdx-updater/blob/master/libgdx_update.py" rel="nofollow">a script</a> that updates some library files for the game framework libgdx by grabbing the latest nightly build .zip file from a server and extracting the contents to the appropriate locations.</p> <pre><code>#!/...
[]
[ { "body": "<p>Your code looks pretty good. Some notes:</p>\n\n<ul>\n<li><p>According to <a href=\"http://www.python.org/dev/peps/pep-0008/#imports\" rel=\"nofollow\">PEP8</a>, imports should be written in separate lines.</p></li>\n<li><p><code>fatal_error</code>: I'd probably write the signature this way: <code...
{ "AcceptedAnswerId": "27719", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T04:14:25.943", "Id": "27715", "Score": "3", "Tags": [ "python", "library", "libgdx" ], "Title": "Updating libgdx game framework library files" }
27715
<p>You can place the script where you want the content to be checked and loaded in your design.</p> <ul> <li><p><code>urlCheck</code> is the name given to the function. You can change it, and if you do, change all <code>urlCheck</code> references within the code.</p></li> <li><p><code>window.location.href</code> retu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T07:58:27.920", "Id": "43183", "Score": "6", "body": "I'd probably fix the indentation." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T08:11:18.713", "Id": "43185", "Score": "0", "body": "...
[ { "body": "<pre><code>&lt;script language=\"JavaScript\"&gt;\n</code></pre>\n\n<p>The <a href=\"http://www.w3.org/TR/html401/interact/scripts.html\" rel=\"nofollow noreferrer\"><code>script</code> tag</a> does not have a property <code>language</code> anymore, that property is deprecated. You should use the pro...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T07:44:47.787", "Id": "27717", "Score": "0", "Tags": [ "javascript", "url" ], "Title": "Using if/else by checking page URL" }
27717
<p>Is there any way I can refactor this expression tree?</p> <pre><code> public static IOrderedQueryable&lt;T_PO&gt; SortedPO(this IQueryable&lt;T_PO&gt; query, ExtjsGridPagingParameter.SortingParameter sortingParameter) { IOrderedQueryable&lt;T_PO&gt; result = null; if (String.IsNullOrEmpty(...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-10-05T13:32:55.800", "Id": "195370", "Score": "1", "body": "As we all want to make our code more efficient or improve it in one way or another, try to write a title that summarizes what your code does, not what you want to get out of a re...
[ { "body": "<p>Note that your code will return <code>null</code> in case if the sort order is not defined. I've preserved this logic, but you may want to change it to return original query (and thus change return type to <code>IQueryable&lt;T_PO&gt;</code>).</p>\n\n<p>You are doing 2 separate actions in this met...
{ "AcceptedAnswerId": "27726", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T11:09:15.827", "Id": "27723", "Score": "-1", "Tags": [ "c#", "linq", "expression-trees" ], "Title": "Refactor Linq Expression" }
27723
<p>Let's say I have a List contains numbers: </p> <p>1,2,3,4,5,6,7,8,9</p> <p>and I would like to split this to two lists:</p> <ul> <li>odd numbers</li> <li>even numbers</li> </ul> <p>So I can do this two ways: </p> <p><strong>Solution 1:</strong></p> <p>Create two methods:</p> <pre><code>List&lt;Integer&gt; fil...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T12:51:35.580", "Id": "43199", "Score": "2", "body": "\"Disadvantage: I hear that assign results for parameters is a bad practice.\" <-- where did you read that? If it is the most practical for you, just use it..." }, { "Cont...
[ { "body": "<p>Here is a solution which replicates Guava's <code>Predicate</code> interface. Since this interface is really easy, here is how it is done:</p>\n\n<pre><code>public interface Predicate&lt;T&gt;\n{\n // returns true if input obeys the predicate\n boolean apply(T input);\n}\n</code></pre>\n\n<p...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-06-24T12:49:49.607", "Id": "27724", "Score": "14", "Tags": [ "java", "comparative-review" ], "Title": "Split Collection to two list depend on criteria" }
27724
<p>I'm trying to determine whether an element which has been clicked has a specific tagname. The trick is, that sometimes when you click an element you want any parent to be that specific tag.</p> <p>My approach:</p> <pre><code>var ignore = 'a input textarea body'.split(' '); var isClickable = function(elem) { v...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-29T13:29:04.727", "Id": "45917", "Score": "0", "body": "You shouldn't use `for ... in` on arrays. It loops over all properties, including `length`." } ]
[ { "body": "<p>I see two big problems with the code:</p>\n\n<ul>\n<li><p>You are doing the recursive call inside the loop, so you will do each level four times. That will quickly escalade to a lot of calls. You should do the call after the loop, where you have determined that the node is not one in the array.</p...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T14:17:13.337", "Id": "27729", "Score": "2", "Tags": [ "javascript" ], "Title": "Check if clicked element has specific tagname" }
27729
<p>I have some custom tables in a Wordpress database that I need to export to CSV. I created a dashboard widget to help with this based on some assistance given to me on on one of my SO questions. It basically consists of a single button that posts back and does some output buffering to render the CSV.</p> <p>I've had...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T18:46:02.370", "Id": "43222", "Score": "0", "body": "I suspect is has something to do with the content-length header being ignored..." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T18:50:47.033", ...
[ { "body": "<p>Normally, Output Buffer functions are not needed in a WordPress context, here neither. We'll just hook on <code>admin_init</code> to intercept our <code>$_POST</code> action, output the export file and <code>exit</code>. The browser doesn't even reloads the page.</p>\n\n<p>The form needs a securit...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T16:06:47.947", "Id": "27734", "Score": "3", "Tags": [ "php", "wordpress" ], "Title": "Exporting data in a WordPress widget" }
27734
<p>I created my first jQuery plugin over this weekend. I would like a code review so that I can improve my code in the future and learn from any mistakes I make. Any tips for Github would also be greatly appreciated since I am also new to GitHub :). </p> <p>Demo: <a href="https://rawgithub.com/Shivambh28/ezToggle/mast...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T17:12:59.990", "Id": "43215", "Score": "0", "body": "\"Uncaught ReferenceError: jQuery is not defined \" <- on your Demopage. Reason: \"[blocked] The page at https://rawgithub.com/Shivambh28/ezToggle/master/demo.html ran insecure co...
[ { "body": "<p>Props to you on your first plugin! Well here are a few pointers in no particular order:</p>\n\n<p><strong>- Double Wrapping:</strong> When you cache <code>yDiv=$(this);</code>, you're wrapping the element with the jQuery object. And then you do: <code>$(yDiv).not(...</code> What this does is wrap ...
{ "AcceptedAnswerId": "27749", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T16:10:32.683", "Id": "27735", "Score": "1", "Tags": [ "javascript", "jquery", "plugin" ], "Title": "First jQuery Plugin, Would like a code review" }
27735
<p>I have some duplicate code using LINQ &amp; XML. I'm sure there is a way to refactor it, but I'm not sure how to go about doing it. Would someone help, please?</p> <pre><code>var fileInfo = dataXL.Worksheet("data") .Where(t =&gt; t["F2"].Equals(company)) .Select(t =&gt; new ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T18:37:05.810", "Id": "43219", "Score": "0", "body": "Both of those XML schemas seem to be badly designed. Is there any possibility of changing them?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T18:...
[ { "body": "<p>This is what you could do:</p>\n\n<ul>\n<li>Try to bring order to the chaos of field numbers. For instance, associate 'F12' to 'Year 2010, Quarter 1'. This is essential to reduce code duplication.</li>\n<li>Fortunately, the field names of each year are sequential (that is, F12 is 2010Q1, F13 is 20...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T17:39:58.420", "Id": "27736", "Score": "-1", "Tags": [ "c#", "linq" ], "Title": "Refactor LINQ & XML code" }
27736
<p>I have created a personal password storage program that takes the user's username, password, and for what account it is for, and stores it in a text file and can also read from them (assuming you type the right name in). What I'm looking to do, is either trim it down (take out none needed code) or finding more effec...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T19:37:21.080", "Id": "43231", "Score": "0", "body": "is this java 7 your targeting?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-25T12:42:11.637", "Id": "43265", "Score": "0", "body": "If ...
[ { "body": "<p>Couple of Points.</p>\n\n<p><strong>Most Important:</strong> If your looking for secure password storage do not write your own library. Password storage is a very complex at best pratice. So I you care about the contents of the plain text password file being accessed don't do this. </p>\n\n<p>If t...
{ "AcceptedAnswerId": "27747", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T18:51:29.203", "Id": "27738", "Score": "5", "Tags": [ "java", "authentication" ], "Title": "Password storage slim/trim it down?" }
27738
<p>I've been teaching myself Python - my first programming language - for about two years now.</p> <p>I recently discovered the <code>concurrent.futures</code> module and wanted to do something with it. What do you think about this script?</p> <pre><code>import re import shutil import string from collections import ...
[]
[ { "body": "<p>PEP8 mentions that top-level constructs like functions should be separated by two lines. Hanging indents should have only one level of indentation (lines 43 and 61). Be careful about trailing whitespaces (lines 61 and 89).</p>\n\n<p>I love functional style myself but it is often frowned upon in Py...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T19:03:58.827", "Id": "27739", "Score": "4", "Tags": [ "python", "concurrency" ], "Title": "Self-taught Pythonista: Any criticism welcome for this concurrent word count script!" }
27739
<pre><code>def alist(x): if x == 1: return 1 return [alist(x - 1), x, alist(x - 1)] l = '%r' % alist(int(raw_input('Maximum Number Of Asterisks: '))) f = l.replace("[", "").replace("]", "").replace(",", "").replace(" ", "") for i in f: print "*" * int(i) </code></pre> <p>So, basically, I just forma...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T20:14:03.873", "Id": "43232", "Score": "0", "body": "You should clarify what exactly you want.Give us an example of the multidimensional list." } ]
[ { "body": "<p>Without many details, maybe the following can help you:</p>\n\n<pre><code>&gt;&gt;&gt; import itertools\n&gt;&gt;&gt; list_of_lists = [['item_1'], ['item_2', 'item_3'], ['item_4', 'item_5', 'item_6']]\n&gt;&gt;&gt; chain = list(itertools.chain(*list_of_lists))\n&gt;&gt;&gt; print chain\n['item_1',...
{ "AcceptedAnswerId": "27944", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-24T19:08:02.273", "Id": "27740", "Score": "1", "Tags": [ "python" ], "Title": "Is there a better way to flatten out a multidimensional list?" }
27740
<p>As suggested on my <a href="https://codereview.stackexchange.com/questions/27573/c-simple-matrix-class-improve-coding">previous question</a>, I am posting my revised code for feedback.</p> <p>One thing that caught my attention is that my program actually runs slower after adding the modifications. It was previousl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-25T01:13:15.290", "Id": "43236", "Score": "0", "body": "Are you compiling with optimization on? This is probably important, as with optimization off, compute_index will not be inlined (for example)." }, { "ContentLicense": "CC ...
[ { "body": "<p>Most likely the performance degradation is caused because in your previous version, <code>operator&lt;&lt;</code> took a <code>Grid3d&amp;</code>, and in this version it takes a <code>Grid3d</code>. Your <code>operator&lt;&lt;</code> signature should be</p>\n\n<pre><code>std::ostream&amp; operator...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-25T00:43:50.413", "Id": "27752", "Score": "3", "Tags": [ "c++", "performance", "matrix" ], "Title": "Simple matrix class - version 2" }
27752
<p>I'm using a payment gateway and am trying to implement the post and response handling with CURL so that it all happens on one page.</p> <p>The following is tested and works but I want to double check it's secure. I'm not storing the card details but I'm essentially posting them to myself (via AJAX) and then curling...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-25T13:53:34.237", "Id": "43267", "Score": "0", "body": "Is the Gateway_Fingerprint unique? or is it the same over all requests?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-25T22:00:22.423", "Id": "4...
[ { "body": "<p>Well, security from what type of threat? You need to figure out what you want to protect against before you can protect against it! Since I'm unsure of what you're protecting against, I'll point out relevant <code>setopt</code> flags.</p>\n\n<ul>\n<li><code>CURLOPT_VERBOSE</code> - This is fine fo...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-25T02:56:07.510", "Id": "27755", "Score": "5", "Tags": [ "php", "security", "curl", "ssl" ], "Title": "Secure CURL to & handle response from Payment Gateway" }
27755
<p>This method takes a string and parses the syllables. I've broken much of the logic into helper methods. Without getting into the helper methods, it's pretty easy to tell what this is doing. But there are a lot of conditionals. I tried handling the conditions that handle adding to the <code>syllables</code> variable ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-25T10:49:01.120", "Id": "43262", "Score": "0", "body": "> This method takes a string and parses the syllables. Well, the method takes no arguments, you mean you are storing it in the class with a reader?" } ]
[ { "body": "<p>Not really elegant, but you could merge the lines by using the <a href=\"http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Control_Structures#short-if_expression_.28aka_ternary_operator.29\" rel=\"nofollow\"><code>?:</code> operator</a>:</p>\n\n<pre><code>syllables = count_vowels + (count_ys_in...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-25T03:56:25.800", "Id": "27756", "Score": "2", "Tags": [ "strings", "ruby" ], "Title": "Parsing syllables from a string" }
27756
<p>I've done a LOT of reading about creating a Unit Of Work and Repository based implementation for my Entity Framework based application. I have come up with the following - what problems can you find?</p> <p>The theory of making the actual SQL Server unit of work, context, and repository coupled to entity framework ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-03T19:07:28.773", "Id": "43836", "Score": "0", "body": "This may be of interest to you: [MSDN: The Unit Of Work Pattern And Persistence Ignorance](http://msdn.microsoft.com/en-us/magazine/dd882510.aspx)" } ]
[ { "body": "<p>In your <code>Repository&lt;T&gt;</code>, you might want to check the <code>EntityState</code> of your <code>entity</code> before manipulating them in your <code>DbSet</code> like this:</p>\n\n<pre><code> public void Add(T entity)\n {\n DbEntityEntry dbEntityEntry = DbContext.Entry(enti...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-25T15:01:41.227", "Id": "27766", "Score": "3", "Tags": [ "c#", "design-patterns", "entity-framework" ], "Title": "Review Repository and UnitOfWork implementation" }
27766
<p>I've worked hard on this code and it functions exactly as I wanted, but I've been told it is a little bit unreadable. My focus is to get the code as clean as possible, and have things as efficient as possible.</p> <p>This is the code I am working with: <a href="http://jsfiddle.net/xT5X5/6/" rel="nofollow">http://js...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-25T15:22:42.510", "Id": "43268", "Score": "1", "body": "You are storing your application state in the HTML instead of keeping a JavaScript object and separating concerns (\"requirements\" for example is conceptually an array, not a lis...
[ { "body": "<p>First of all there is a great article on <a href=\"http://javascriptplayground.com/blog/2013/06/refactoring-js/?utm_source=javascriptweekly&amp;utm_medium=email\" rel=\"nofollow\">refactoring jQuery</a> by Jack Franklin.</p>\n\n<p>Second is my solution that i came up with in last 2 hours(ocd kicke...
{ "AcceptedAnswerId": null, "CommentCount": "13", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-25T15:08:53.113", "Id": "27767", "Score": "1", "Tags": [ "javascript", "jquery", "performance" ], "Title": "Jquery field add code - Improvements in readability, compactness or effic...
27767
<p>I'm working on my site, and need help knowing what I need to do to improve the security of my login system.</p> <p>If you feel so inclined, I would love some help to tell me what the exact changes that I need to make, but if you could just tell me what other security measures I need to add, that would be amazing.</...
[]
[ { "body": "<p>The first thing I will tell you to do is to look into SQL injections. Your scripts are providing a pretty easy way of potentially exposing security holes. using <code>mysqli_real_escape_string</code> to escape any data going into your database is one of the better sanity checks. </p>\n\n<p>In your...
{ "AcceptedAnswerId": "28062", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-25T15:55:03.643", "Id": "27768", "Score": "3", "Tags": [ "php", "security", "mysqli", "authentication" ], "Title": "User Data Security" }
27768
<p>I am trying to turn this function:</p> <pre><code>collection = ['hey', 5, 'd'] for x in collection: print(x) </code></pre> <p>Into this one:</p> <pre><code>def printElement(inputlist): newlist=inputlist if len(newlist)==0: Element=newlist[:] return Element ...
[]
[ { "body": "<blockquote>\n <p>but I wonder if it's okay there's no \"return\" line under \"else:\"</p>\n</blockquote>\n\n<p>Yes, that's OK. You don't need to return anything from your function if you don't want to. In fact, in the interest of consistency, you may as well remove the thing returned in the if bloc...
{ "AcceptedAnswerId": "27777", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-25T19:27:19.883", "Id": "27773", "Score": "2", "Tags": [ "python", "recursion" ], "Title": "I'm practicing turning for loops into recursive functions. what do you think?" }
27773
<p>I wrote this tiny script to pull the JSON feed from the <a href="http://citibikenyc.com/stations/json" rel="nofollow">CitiBike website</a>:</p> <pre><code>import requests import time def executeCiti(): r = requests.get("http://citibikenyc.com/stations/json") print r.json() time.sleep(62) while True:...
[]
[ { "body": "<p>While this is a good start, there are several things that should be noted.</p>\n\n<blockquote>\n <p>r = requests.get(\"<a href=\"http://citibikenyc.com/stations/json\">http://citibikenyc.com/stations/json</a>\")</p>\n</blockquote>\n\n<p>This is code snippet is network-based, and so errors may occ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-25T19:38:57.170", "Id": "27774", "Score": "8", "Tags": [ "python", "json", "timer" ], "Title": "Timed requests and parsing JSON in Python" }
27774
<p>I am doing interview studies and can't find a simple DFS for a cycle-finding algorithm. I want someone to tell me if my DFS algorithm works and how it can be improved.</p> <p>Where can you get a typical DFS cycle finding algorthm for Java? I assume you have to "mark" the nodes and edges in order to find a cycle? ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-18T07:44:58.337", "Id": "44971", "Score": "1", "body": "Why would `A -> B -> A` not be a cycle? Can different nodes have the same name? If so, how do you distinguish nodes?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationD...
[ { "body": "<p>There are a couple of suggestions I have here.</p>\n\n<p>The first is a major performance one... you have the code:</p>\n\n<pre><code>boolean isCycle = false;\nfor(Node node : nodes){ \n isCycle = isCycle || isCycled(node, getEdgeNum(n,node)); \n}\nreturn isCycle;\n</code></pre>\n\n<p>T...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-25T19:55:14.687", "Id": "27776", "Score": "4", "Tags": [ "java", "depth-first-search" ], "Title": "Java cycle detection using DFS in an undirected graph" }
27776
<p>I figure that someone here probably knows a much better way to do this. I'm still figuring out AJAX and jQuery, so I consider that I still need to master quite a bit of knowledge. </p> <p>My function extends Foundation 4 Reveal's functionality in a few ways:</p> <ul> <li>Uses WordPress AJAX to dynamically pull in ...
[]
[ { "body": "<ul>\n<li><p><strong>L15</strong>, <strong>L26</strong>, <strong>L31-60</strong>: Inconsistent indentation levels.</p></li>\n<li><p><strong>L4-43</strong>: Consider indenting this block.</p></li>\n<li><p><strong>L04</strong>: I don't see the point in storing the ID rather than the jQuery object itsel...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-25T20:07:39.037", "Id": "27779", "Score": "3", "Tags": [ "javascript", "jquery", "ajax", "plugin", "wordpress" ], "Title": "Plugin for WordPress and Foundation Reveal" }
27779
<p>This little program is self-explanatory. I count letters in a string (can be any string), using a <code>for</code> loop to iterate through each letter. The problem is that this method is very slow and I want to avoid loops.</p> <p>Any ideas? I thought that maybe if I remove checked letters from the string after eac...
[]
[ { "body": "<p>Use the built in <code>Counter</code> in the <code>collections</code> module:</p>\n\n<pre><code>&gt;&gt;&gt; from collections import Counter\n&gt;&gt;&gt; Counter('qwertyqweryyyy')\nCounter({'y': 5, 'e': 2, 'q': 2, 'r': 2, 'w': 2, 't': 1})\n</code></pre>\n", "comments": [], "meta_data": { ...
{ "AcceptedAnswerId": "27784", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-06-25T21:43:08.603", "Id": "27781", "Score": "11", "Tags": [ "python", "strings" ], "Title": "Counting letters in a string" }
27781
<p>I'm working on a communications layer for a system that reads data from a TCPIP client that is formatted as fixed-width ASCII (yeah, old school). I was quite surprised that there seemed to be no built in way to do this, and ended up using the following simple StreamReader subclass:</p> <pre><code>/// &lt;summary&gt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-19T08:03:46.760", "Id": "43287", "Score": "0", "body": "I considered posting there as well, but thought since the primary question was really \"is there a better way to do this?\" here would be more appropriate." }, { "ContentL...
[ { "body": "<p>I don't know if something does that already, but you could mimic <a href=\"http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.structlayoutattribute.aspx\" rel=\"nofollow\">StructLayout</a> if you need to read multiple types of 'objects' or need reusability.</p>\n\n<p>Basically ...
{ "AcceptedAnswerId": "27793", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-18T09:25:22.707", "Id": "27782", "Score": "3", "Tags": [ "c#", "stream" ], "Title": "Reading fixed-width data fields in .NET" }
27782
<p>We have a lot of phone numbers that contain dashes and start with a zero which are from another country.</p> <p>I am trying to strip the dashes and the one leading zero and select the country code from a drop-down box.</p> <p>I'm using "raw" JS with DOM here (for the sake of not having to pull in a framework):</p>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T01:35:19.567", "Id": "43302", "Score": "0", "body": "You're only cutting off 'a' leading zero (and not all of them), (all that needs fixing is changing that if to a while). You're also not caching your selectors (not a big deal if t...
[ { "body": "<p>Just a few points</p>\n\n<ul>\n<li><p>You're missing a <code>&amp;</code> in your <code>if</code> conditional. Right now you're doing a bitwise AND, rather than a logical AND (which would be <code>&amp;&amp;</code>).</p></li>\n<li><p>I'd say you should always use curly braces, even for one-liners....
{ "AcceptedAnswerId": "27815", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T01:07:26.613", "Id": "27787", "Score": "3", "Tags": [ "javascript", "strings", "dom" ], "Title": "String processing in JavaScript" }
27787
<p>I have this ExpressJS route for saving and listing <code>Category</code> model.</p> <pre><code>exports.save = function(req, res, next){ //validate here&gt;&gt;&gt; var name = req.body.name; var description = req.body.description; new Category({ name: name, description: description, }).save(functi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-05T17:23:00.240", "Id": "127954", "Score": "0", "body": "Instead of the [`console.log`](http://nodejs.org/api/stdio.html#stdio_console_error_data) you could use `console.error` to print errors. It's the same as `console.log` but it pri...
[ { "body": "<p>I assume you have a typo there, <code>error</code> is nowhere defined but you do have <code>err</code>.</p>\n\n<p>To jackdbernier's point, you should read the docs:\n<a href=\"http://expressjs.com/guide.html#users-online\" rel=\"nofollow\">http://expressjs.com/guide.html#users-online</a></p>\n\n<p...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T02:03:01.103", "Id": "27788", "Score": "2", "Tags": [ "javascript", "error-handling", "mongodb", "express.js" ], "Title": "Saving and listing Category model" }
27788
<p>This code doesn't look too good. Could anyone help me format it?</p> <pre><code>private void initComparisonDatatable() { List&lt;BrandProfitAndLoss&gt; brandProfitAndLossComparisonDatatable = new ArrayList&lt;BrandProfitAndLoss&gt;(); BrandProfitAndLoss brandProfitAndLossCurrentYear = new BrandProfitAndLos...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T07:41:15.270", "Id": "43325", "Score": "2", "body": "What is this method supposed to do in plain English? Method name doesn't help." } ]
[ { "body": "<p>Some problems that could be seen without actually understanding code:</p>\n\n<ul>\n<li>Unhelpful and possibly misleading comments: <code>// the selected year is not null</code></li>\n<li>Repeating type in variable name : <code>brandProfitAndLossCurrentYear</code></li>\n<li>Using ad hoc code instea...
{ "AcceptedAnswerId": "27794", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T06:41:52.227", "Id": "27791", "Score": "1", "Tags": [ "java" ], "Title": "Initialize comparison datatable" }
27791
<p>I finally got my upload form and code that uploads to db. I used tutorial from <a href="http://www.icraftzone.com/2012/06/file-upload-and-download-script-using.html" rel="nofollow">this site</a>.</p> <p>As I am php newbie, I want to know how secure this code is and if it is not secure at all (which I am almost sure...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T05:05:35.747", "Id": "43391", "Score": "1", "body": "You haven't validated the file type. That seems to be most important thing to do." } ]
[ { "body": "<ol>\n<li><p><strong>Restrict file types</strong>:\nAs your concern is security, you should make sure that the file type is one of those you allow.\nFor that you must implement a file type checker, that validates file type is allowed, then you let the user upload the file. Learn how to do that <a hre...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T09:01:31.657", "Id": "27796", "Score": "1", "Tags": [ "php", "mysql" ], "Title": "PHP upload to database" }
27796
<p>The function <code>arg_to_uint64</code> takes a 0-terminated string and returns an <code>unsigned int</code>. The <code>unsigned int</code> is the integer presentation of <code>arg</code> in decimal or in hex (if prefixed with 0x) as defined in the C language standard.</p> <pre><code>constexpr char hexprefix[]="0x"...
[]
[ { "body": "<p>Just use <code>strtoll</code> with a base of 0 </p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T16:05:57.473", "Id": "27810", "ParentId": "27797", "Score": "6" } } ]
{ "AcceptedAnswerId": "27810", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T09:16:36.573", "Id": "27797", "Score": "3", "Tags": [ "c++", "parsing", "c++11", "linux" ], "Title": "Parsing hex and decimal numbers in C++11" }
27797
<p>I am currently working on a project which uses the MVVM pattern. I have a POCO which I want to present in an editor and, because the object is composed from a number of smaller, reusable POCOs, I thought it would be appropriate to show it in a <code>TabControl</code>.</p> <p>The result looks like this:</p> <p><img...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T10:24:04.140", "Id": "43333", "Score": "0", "body": "I guess you're going to have to show a bit of code how your ViewModels or POCOs are structured." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T12:...
[ { "body": "<p>Looks pretty good. Just a few little things:</p>\n\n<ul>\n<li>Command-related methods <code>CanDoXXXX</code> and <code>DoXXXX</code> would be better off named <code>CanExecuteXXXX</code> and <code>ExecuteXXXX</code> or <code>OnExecuteXXXX</code>.</li>\n<li>I would put the ViewModel properties <cod...
{ "AcceptedAnswerId": "36014", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T10:10:52.503", "Id": "27798", "Score": "2", "Tags": [ "c#", "wpf", "mvvm" ], "Title": "Implementing a POCO editor split over a number of TabItems" }
27798
<p>I wrote something that has probably done thousands of times: a function that takes a parsed http query as input and return a linq query. </p> <p>Any input is appreciated.</p> <pre><code>public IList&lt;Lead&gt; GetLeads(NameValueCollection nvc) { IQueryable&lt;MyContext&gt; queryBase = QueryBase(); foreac...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T12:10:03.593", "Id": "43336", "Score": "2", "body": "Why is your DB returning everything as `string`s? This is especially problematic for the `double`s, since the `Replace()` indicates there is some culture mismatch." } ]
[ { "body": "<p>Here's a stab at making it a tad more performant while simplifying the syntax a bit:</p>\n\n<pre><code>//case where an array of possible values is sent\nprivate const string MyRegex = \"\\\\[.*\\\\]\";\n\nprivate static readonly Regex replacer = new Regex(MyRegex, RegexOptions.Compiled);\n\npublic...
{ "AcceptedAnswerId": "27805", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T11:37:07.697", "Id": "27800", "Score": "3", "Tags": [ "c#", ".net", "linq" ], "Title": "Transforming http request into linq query" }
27800
<p>I am trying to make a text-based RPG in Python and Pygame. I need a way to manage my inventory slots. Currently, I have no way to find out what is currently equipped. I can only overwrite it, even though I can display the current armor value and what it would be.</p> <p>Here is the code for the only item I have "...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2018-11-15T01:20:25.917", "Id": "400917", "Score": "2", "body": "The code that you have posted makes no sense. If `leatherTunicItem = False`, then none of the rest of the code can possibly have any effect, because both the `if` and the `elif` ...
[ { "body": "<p>Some considerations on your current code:</p>\n\n<ol>\n<li>Don't use <code>== True</code>. You either want to check the truth value of the object, in which case simply drop the <code>== True</code>, or you want to check for identity, in which case you should use <code>is True</code>(even though it...
{ "AcceptedAnswerId": "27807", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T14:57:06.330", "Id": "27806", "Score": "3", "Tags": [ "python", "pygame" ], "Title": "Text-based adventure RPG inventory code" }
27806
<p>I have been working on improving my javascript skills, mainly "namespacing" and the best practices used by js developers. I would like to know how I can improve this code and any tips that may help me along the way. Below is the specific code I am working with and there is a working fiddler also. </p> <p>Just to...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T16:47:12.433", "Id": "43362", "Score": "1", "body": "Just a little comment on the UX. When you are at the first or last question, you should disable the back/next button. It looks weird that the button has an hover and can be clicke...
[ { "body": "<p>I tend to use a lot of Java best practices in my JavaScript code. The biggest issue I see is the lack of extensible classes/methods. The methods are procedural and only seem to be broken into new methods because they are repeatable. The class as a whole violates the single responsibility principle...
{ "AcceptedAnswerId": "28257", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T14:38:21.320", "Id": "27808", "Score": "5", "Tags": [ "javascript", "quiz" ], "Title": "Multiple-choice quiz" }
27808
<p>Is there a smarter way to write this code? I used to add all the elements in the collection constructor, something like this:</p> <pre><code>new OrderWizardStateCollection([new OrderWizardState(..), new OrderWizardState(..)..]) </code></pre> <p>but now, since I have this one conditional addition, I'm writing it t...
[]
[ { "body": "<p>You could do a loop over the elements that you are always adding:</p>\n\n<pre><code>for (var info in [\"basket\", \"account\", \"delivery\", \"payment\", \"placeorder\"] {\n this.state_collection.add (new OrderWizardState ({ state: info, phase: this.phase_collection.findWhere ({ phase: info }) ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T17:36:23.210", "Id": "27812", "Score": "3", "Tags": [ "javascript" ], "Title": "Add elements to collection conditionally" }
27812
<p>Could it be written better?</p> <pre><code>package main import ( "code.google.com/p/go-tour/wc" "fmt" ) func WordCount(s string) map[string]int { dict := make(map[string]int) splited := Split(s) for _, string := range splited { _, present := dict[string] if present { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T18:54:47.083", "Id": "43374", "Score": "0", "body": "\"for _, string := range splited {\"\nAre you using \"string\" as a variable Name?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T09:25:55.363", ...
[ { "body": "<p>For example,</p>\n\n<pre><code>package main\n\nimport (\n \"code.google.com/p/go-tour/wc\"\n \"strings\"\n)\n\n// WordCount returns a map of the counts of each “word” in the string s.\nfunc WordCount(s string) map[string]int {\n words := strings.Fields(s)\n counts := make(map[string]in...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T17:38:18.803", "Id": "27813", "Score": "4", "Tags": [ "strings", "go" ], "Title": "Split and word count in go" }
27813
<p>I recently came across the <a href="https://en.wikipedia.org/wiki/Sleeping_barber_problem" rel="nofollow">Sleeping Barber</a> problem and found out that it is a good place to start learning how to use threads properly. </p> <p>I don't have <em>too</em> much experience with threads and want to learn more, so I figu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T21:17:23.220", "Id": "43377", "Score": "0", "body": "Please add a description of the problem in your question." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T21:47:46.230", "Id": "43381", "Sc...
[ { "body": "<p>I have no idea what you are trying to achieve here so here are a full general comments :</p>\n\n<p>The pythonic way to check <code>not self.waiting_customers.empty()</code> is <code>self.waiting_customers</code> (if <code>waiting_customers</code> is known to be a container).</p>\n\n<p>Also</p>\n\n...
{ "AcceptedAnswerId": "27819", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T20:50:07.707", "Id": "27817", "Score": "1", "Tags": [ "python", "algorithm", "multithreading" ], "Title": "Feedback on a Python 'sleeping barber' program" }
27817
<p>As a follow-up to my previous <a href="https://codereview.stackexchange.com/questions/26071/computation-of-prefix-free-codes-with-many-repeated-weight-values-in-reduced-spa">question</a> about prefix free code, I learned about the module unittest and wrote the following set of functions, to be used in order to semi-...
[]
[ { "body": "<p>Most Python I read these days prefers list comprehensions over <code>map</code> or <code>filter</code>. For example, I'd change</p>\n\n<pre><code>terms = map( lambda x: x[1] * math.pow(2,-x[0]), L)\nreturn sum(terms)\n</code></pre>\n\n<p>to</p>\n\n<pre><code>return sum(x[1] * math.pow(2, -x[0]) fo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-26T21:45:48.927", "Id": "27821", "Score": "1", "Tags": [ "python" ], "Title": "Code to check for the optimality of a minimal prefix free code" }
27821
<p>I applied for a job and they asked me to write code with the following requirements:</p> <blockquote> <p>Get a "toolbar offer" description from http..update.utorrent.com/installoffer.php?offer=conduit. Parse the bencoded (see <a href="http://en.wikipedia.org/wiki/Bencode">http://en.wikipedia.org/wiki/Bencode...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T17:25:54.403", "Id": "43422", "Score": "58", "body": "A fairly simple problem with your code: Comments should explain why, not how." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T23:44:24.430", "...
[ { "body": "<p>Run your code through <a href=\"https://pypi.python.org/pypi/pep8\">pep8</a> and possibly a more pedantic static analyzer like <a href=\"http://www.logilab.org/857#projectinfo_tab\">pylint</a>.</p>\n\n<p>You will find these tools don't like some of your formatting and variable names. They will lik...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T03:55:04.517", "Id": "27824", "Score": "213", "Tags": [ "python", "algorithm", "interview-questions" ], "Title": "Calculate SHA1 hash from binary and verify with a provided hash" ...
27824
<p>This is Tic-Tac-Toe using negamax for AI. Help me make it better!</p> <p>Some sore points are:</p> <pre><code>def get_mark good_mark = false until good_mark mark = gets.chomp if mark =~ /x/i chose_x good_mark = true elsif mark =~ /o/i chose_y good_mark = tr...
[]
[ { "body": "<p>Some suggestions:</p>\n\n<ol>\n<li>Avoid flags. Oftentimes there are a hint that you can structure your code better</li>\n<li>Learn the available language constructs and methods (e.g. <code>case/when</code> or <code>#any?</code>)</li>\n<li>Avoid methods with side effects when you can better use a ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T04:56:21.927", "Id": "27826", "Score": "1", "Tags": [ "beginner", "ruby", "game", "tic-tac-toe", "ai" ], "Title": "Ruby Tic-Tac-Toe using classes" }
27826
<p>I'm a JavaScript developer. I'm pretty sure that will be immediately apparent in the below code if for no other reason than the level/depth of chaining that I'm comfortable with. However, I'm learning Ruby, and so I'd love to write beautiful Ruby code too. My simple first project is a Craigslist search-across-region...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-28T23:33:11.313", "Id": "43550", "Score": "0", "body": "my goodness i had totally forgotten that ruby even had a `for` statement" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-29T01:22:53.417", "Id": "...
[ { "body": "<p>Long, long question. I'll take your first snippet and leave others to tackle the rest. First some comments about your code:</p>\n\n<ul>\n<li><p><code>def get_us_regions()</code>: It's not idiomatic to puts those <code>()</code> on methods without arguments.</p></li>\n<li><p><code>first()</code>: I...
{ "AcceptedAnswerId": "27863", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T06:35:18.253", "Id": "27832", "Score": "5", "Tags": [ "object-oriented", "ruby", "multithreading", "http", "web-scraping" ], "Title": "Craigslist search-across-regions ...
27832
<p>Background: I was making a chrome extension that injects movie ratings into theatres' showtimes pages. The problem I was duplicating a lot of code calling similar but just slightly different functions. Sometimes I wanted to do an <code>$(el).prepend</code>, sometimes <code>$(el).append</code>, or <code>$(el).after</...
[]
[ { "body": "<p>Firstly, I wouldn't say it's evil. From JS's point of view, <code>obj[\"foo\"]()</code> is identical to <code>obj.foo()</code>. The dot-syntax and bracket-syntax are completely interchangeable. Of course, if you call your variable \"abomination\" then, yeah, it's going to <em>sound</em> evil.</p>\...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T06:48:46.900", "Id": "27833", "Score": "4", "Tags": [ "javascript" ], "Title": "Is this use of an array of function names and bracket-notation function calling a hacky/evil solution?" }
27833
<p>Thanks for the Reply. </p> <p>Here is the actual Scenario My application received the data from a backend in the form of a class object ie. </p> <pre><code>public class FlowObject { private String id; private List&lt;FlowStep&gt; flowlSteps; private List&lt;String&gt; audRefs; } </code></pre> <p>Now FlowSt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T09:18:49.937", "Id": "43405", "Score": "2", "body": "The first problem I see is that your FlowStep is mutable; as such, if an element of a list in FlowObject is still referenced by another method and it modifies it, the list in Flow...
[ { "body": "<p>One thing I guess you can consider is to add a constructor for class FlowCopy that handles (or encapsulates) the copy task to release this burden from function getFlow():</p>\n\n<pre><code>public class FlowCopy {\n public FlowCopy(FlowObject obj) {\n setId(obj.getId()); \n setAud...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T09:06:16.383", "Id": "27837", "Score": "1", "Tags": [ "java" ], "Title": "Review the code to copy List of custom class to another list of Custom class" }
27837
<p>T_PROJECT is the class that will be retrieve data from linq to sql and ProjectOwnerDataFields is the class that will be used to show data in view. in edit mode i have to get value from model and send it back like this. is there anyway to refactor this and remove the reverse duplication on ProjectOwnerDataFields and ...
[]
[ { "body": "<p>Anyone may correct me if I'm wrong but honestly: I don't think so. </p>\n\n<p>(Offtopic)</p>\n\n<p>This can be rewritten:</p>\n\n<pre><code>if (String.IsNullOrEmpty(this.CountryIsoLetter) == false)\n{\n return new RegionInfo(this.CountryIsoLetter).EnglishName;\n}\nreturn \"\";\n</code></pre>\n\...
{ "AcceptedAnswerId": "27848", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T11:57:38.793", "Id": "27844", "Score": "1", "Tags": [ "c#" ], "Title": "Refactor data tranfer object and model" }
27844
<p>I should be able to figure this out on my own, but I can't seem to wrap my head around how to optimize this set of logic for interpreting the existence of URL parameters.</p> <pre><code>&lt;cfif ParameterExists(start) and not ParameterExists(end) and not ParameterExists(after)&gt; &lt;cfquery name="STUDENT" datasou...
[]
[ { "body": "<p>Yeah, you're not doing yourself any favours by having the elements of the IF conditions in differing orders. It took a bit for me to re-sort everything so I could understand what the heck was going on. I <em>think</em> it distills down to this:</p>\n\n<pre><code>&lt;cfscript&gt;\n if (structKey...
{ "AcceptedAnswerId": "27856", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T16:52:57.447", "Id": "27852", "Score": "0", "Tags": [ "bitwise", "coldfusion", "cfml" ], "Title": "Bitwise Logic optimization" }
27852
<p>I'm working on some exercises Scala by Example and I've implemented an excl() method on sets which removes an element from a set, and a toString method that converts a set to a string.</p> <p>I'm practicing use pattern matching here. A bit concerned about shadowing my instance variables on the line</p> <p><code>ca...
[]
[ { "body": "<p>Some ideas:</p>\n\n<ul>\n<li>Make the trait <code>sealed</code>.</li>\n<li><p><code>combine</code> doesn't need to be a nested function, this only makes it harder to read and causes problems with shadowed variables. Instead you could move it to an accompanying object, or make it a separate method ...
{ "AcceptedAnswerId": "28872", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T16:57:32.943", "Id": "27853", "Score": "3", "Tags": [ "scala" ], "Title": "Printing out a tree set using pattern matching in Scala" }
27853
<p>I'd like some comments and any suggestions that you have for where to go next with this.</p> <p>I've been working on developing a JavaScript library that allows for dynamic forms by simply adding some extra HTML tags and attributes to your form. It's brand new, so it doesn't have a lot of features, but it's based ...
[]
[ { "body": "<p><strong>On the whole</strong></p>\n\n<p>Interesting, from a philosophy perspective, you are now moving from code with potential JavaScript bugs to code with potential HTML 'configuration' bugs. Debugging configuration bugs is annoying since there is no dedicated tooling for it.</p>\n\n<p>Furthermo...
{ "AcceptedAnswerId": "48008", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T17:38:46.123", "Id": "27854", "Score": "3", "Tags": [ "javascript", "jquery", "html", "form", "dom" ], "Title": "eDomForm - dynamic forms without writing any JavaScript...
27854
<p>I have code for a class that will manage an OAuth authentication key, included below. Because this class's functionality means it needs to be considered with regards to security, I wanted to check to make sure that all is as it should be (or figure out what ought to be changed), and there aren't any extra risks any...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T19:18:48.527", "Id": "43430", "Score": "1", "body": "It seems crazy that you would need to call the Desktop browser to get the \"code\". But then again, I'm not sure what the \"code\" is." } ]
[ { "body": "<p>If this is running as a daemon - my understanding is that you mean as some kind of cron job or a background task, then who will be logging into your Box.com account to get the 'code' for the first time in the <code>getCode</code>?</p>\n<p>Are you aware of the OAuth2 framework/protocol, if not, <a ...
{ "AcceptedAnswerId": "28422", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T17:59:47.907", "Id": "27857", "Score": "1", "Tags": [ "java", "security" ], "Title": "Authentication Program" }
27857
<p>I'm just starting to learn C++ and have been experimenting with various functions. Here is one that computes the number of permutations of <em>n</em> consecutive numbers as well as all possible permutations provided <em>n</em>. I'd love to receive any form of tips and criticisms on improving this function.</p> <pre...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T19:04:12.357", "Id": "43428", "Score": "3", "body": "You know there's an `std::permutations()` function in the standard library?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T19:05:15.240", "Id"...
[ { "body": "<ul>\n<li><p>Do not use <code>using namespace std</code>. Learn more about this <a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\">here</a>.</p></li>\n<li><p>It looks nicer to put the <code>int n</code> above the user input code. You could als...
{ "AcceptedAnswerId": "27865", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T19:02:05.847", "Id": "27859", "Score": "3", "Tags": [ "c++", "beginner", "combinatorics" ], "Title": "Computing the number of permutations of n consecutive numbers" }
27859
<p>This will later be be posted on my website to explain quick sort so I would like how I could improve the readability and simplicity of this demo class. I do not like my use of the stack (meaning this recursion cannot process a list with millions of values).</p> <p>How could I reduce the stack impact? I think the be...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T22:34:26.747", "Id": "43439", "Score": "0", "body": "sidenote: instantiate arraylists as ``List<Integer> list = new ArrayList<>()`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-07-01T15:22:20.363", "I...
[ { "body": "<p>Rather than creating new <code>List</code>s, your method could sort the list in place. The method you call recursively could take the list and index values; the methods would look something like this:</p>\n\n<pre><code>/**\n * sorts the {@code list} in place\n */\npublic static void sort(ArrayList...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T19:27:31.650", "Id": "27861", "Score": "2", "Tags": [ "java", "recursion", "sorting", "quick-sort" ], "Title": "Simplest quick sort using one 19-line function" }
27861
<p>For my first not-just-a-few-days-long Python project, I needed something to handle basic set theory operations (union, intersection etc.) for one dimensional integer intervals, so I came up with this module.</p> <p>It would be cool if you could tell me if the code is OK or something you would frown upon if you had ...
[]
[ { "body": "<p>First off, <code>Intervals</code> should be a new style class. There's no real reason to ever use old style classes nowadays. If you want to be fancy, you could throw in a set-like ABC, but you should at least inherit from <code>object</code>.</p>\n\n<p>The default argument <code>interval_list</co...
{ "AcceptedAnswerId": "27886", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T20:27:03.453", "Id": "27862", "Score": "6", "Tags": [ "python" ], "Title": "Set theory operations (union, intersection etc.) for one dimensional integer intervals" }
27862
<p>For work, my colleague and I sketched this method up as a brain dump of how we want this method to work. What I am trying to figure out is how can we break this method into smaller components so that it is easier to test to write tests for this. I am trying to avoid putting this into methods where they are coupled b...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-28T16:22:52.857", "Id": "43509", "Score": "0", "body": "What's SlaveDB? why are you doing sql by hand instead of using AR?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-29T22:57:22.020", "Id": "43588"...
[ { "body": "<p>Even if you don't want to load your data into ActiveRecord, you can use AR to prepare your SQL statement using <code>to_sql</code>:</p>\n\n<pre><code>def self.for_venue(venue, options = {})\n\n filter = options[:filter]\n\n date_conditions = case options[:date]\n when 'upcoming' then \"datetim...
{ "AcceptedAnswerId": "28043", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-27T22:07:36.907", "Id": "27866", "Score": "1", "Tags": [ "ruby", "sql", "mysql", "ruby-on-rails", "active-record" ], "Title": "ActiveRecord SQL search with a filter based ...
27866
<p>I need to build a application which sends a lot of emails. These emails are based on a table. Basic idea is, I grab a bunch of records from database. Create <code>MailMessage</code> (<code>System.Net.Mail</code>) and send it. Since there are a lot of mails to be sent, I am thinking about developing a multi-threaded ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-28T02:06:30.580", "Id": "43446", "Score": "0", "body": "Why do you need to send so many emails?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-28T03:36:39.473", "Id": "43451", "Score": "0", "bo...
[ { "body": "<p>Instead of rolling your own version of a parallel for each loop, you should use <a href=\"http://msdn.microsoft.com/en-us/library/system.threading.tasks.parallel.foreach.aspx\" rel=\"nofollow\"><code>Parallel.ForEach()</code></a>. It will make your code simpler, avoid the possibility of bugs in yo...
{ "AcceptedAnswerId": "27897", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-28T02:02:26.207", "Id": "27871", "Score": "0", "Tags": [ "c#", "multithreading", "email" ], "Title": "Multi threaded application to send large no of emails" }
27871
<p>This is a program that I made for encrypting text files, it uses a one time pad cipher to encrypt the files, but I do not know if there are any holes in my program that could be a vulnerability. </p> <pre><code>import os q = 1 while q == 1: e = raw_input("file to encypt: ") #This will open a file for encryp...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-28T02:45:12.380", "Id": "43449", "Score": "7", "body": "Crypto is a very specialized topic. General programers will be able to critique your code style not your crypto strength. Go to a specialized group for that: http://crypto.stackex...
[ { "body": "<p>I am not going to comment on possible vulnarabilities (that question does not belong here). But your Python code has several issues.</p>\n\n<p>In the code:</p>\n\n<pre><code>f1 = file(path2, \"w\")\nf1 = open(path2, \"w\")\nf1.write(decrypt)\nf1.close()\n</code></pre>\n\n<p>the first two lines do ...
{ "AcceptedAnswerId": "27938", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-28T02:32:42.093", "Id": "27872", "Score": "2", "Tags": [ "python", "cryptography" ], "Title": "Is my cipher secure?" }
27872
<p>I am writing a TCP based client that need to send and receive data. I have used the <code>Asynchronous Programming Model (APM)</code> provided for Socket class by the .NET Framework.</p> <p>After being connected to the socket, I start waiting for data on the socket using <code>BeginReceive</code>.</p> <p>Now, whil...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-28T13:40:31.463", "Id": "43498", "Score": "0", "body": "Why are you using the asynchronous method `BeginSend()` when you immediately synchronously wait for it to complete? Why don't you just use `Send()`? Also, can you use C# 5.0?" }...
[ { "body": "<p>Instead of using the <code>ToArray()</code> method of the <code>MemoryStream</code> you could use <code>GetBuffer()</code> instead because this isn't creating a new array. </p>\n\n<p>Edit based on <a href=\"https://codereview.stackexchange.com/users/27497/iridium\">@Iridium</a>'s <a href=\"https:/...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-28T02:56:54.093", "Id": "27873", "Score": "2", "Tags": [ "c#", ".net", "socket", "tcp" ], "Title": "Transmitting/Sending big packet safely using TcpClient/Socket" }
27873
<p>I've been learning Python like for a year and started learning a little about pandas <code>DataFrame</code>. I made this little program to practice all the concepts and would like to hear your suggestions for improvement.</p> <p><strong>GOAL</strong></p> <p>This program should plot how the inventory levels behave ...
[]
[ { "body": "<p>Nice piece of code. Are you calculating <a href=\"https://en.wikipedia.org/wiki/Safety_stock#Methods_for_calculating_safety_stocks\" rel=\"nofollow noreferrer\">safety stock</a> based on the std dev of the demand distribution? Couldn't find in the code - sorry if it is there.</p>\n\n<p>If not not,...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-28T03:16:12.087", "Id": "27874", "Score": "3", "Tags": [ "python", "simulation", "pandas" ], "Title": "Inventory simulation using Pandas DataFrame" }
27874
<p>Here is an exercise I completed today from Bjarne Stroustrup's <em>Programming Principles and Practice in C++</em> book. Any tips about coding style, simplification, or perhaps modularization by means of using functions for some of the data processing would be sincerely appreciated. FYI I have only been programming...
[]
[ { "body": "<ul>\n<li><p>It's best not to use <code>using namespace std</code>. Read <a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\">here</a> for more information.</p></li>\n<li><p>Initialize all of your variables on separate lines. When I tried to run...
{ "AcceptedAnswerId": "27919", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-28T03:44:45.383", "Id": "27875", "Score": "7", "Tags": [ "c++", "beginner", "converting" ], "Title": "Style, simplification and modularization for unit converter" }
27875
<p>I am looping through an object and finding whether or not the object has the "key," along with some further stuff.</p> <p>I feel that there is some other correct way to do this apart from this:</p> <pre><code>var initialLocalesGen = function(data){ var status; if(!$.isEmptyObject(data)){ consol...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-28T06:24:51.057", "Id": "43457", "Score": "0", "body": "Why do your objects always have different attributes? What is `data`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-28T06:26:06.670", "Id": "434...
[ { "body": "<p>You could merge the last three ifs. (I assume there are no other states.) </p>\n\n<pre><code>if(data.hasOwnProperty(\"status\")){\n currentStatus = parseInt(data[\"status\"]);\n switch(currentStatus ) {\n case 0:\n var object1 = {\"status\" : data[\"st...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-28T05:48:39.167", "Id": "27880", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "How to check minimize or make if-condition on object loop more correct?" }
27880