body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>Can you please review the following code and give any suggestions for improvment?</p> <p>Class ContactList.java</p> <pre><code>import java.io.*; import java.util.*; public class ContactList { public static void main(String args[]) throws IOException { Contact contact; contact = new Contact(); int act...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-12T15:30:20.873", "Id": "36684", "Score": "0", "body": "A first glance : in this case I replace the `switch` by a `Observable/Observer` patten, loosely coupled and evolutive" }, { "ContentLicense": "CC BY-SA 3.0", "Creation...
[ { "body": "<p>The first thing I would suggest is to replace your magic numbers with meaningful constants:</p>\n\n<pre><code>private static final int NEW_PERSON_ACTION = 1;\nprivate static final int PRINT_PERSON_ACTION = 2;\nprivate static final int SEARCH_LAST_NAME_ACTION = 3;\n//etc...\n</code></pre>\n", "...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-12T15:23:16.917", "Id": "23793", "Score": "5", "Tags": [ "java" ], "Title": "Command line Contact Management" }
23793
<p>For my simple Android application, I don't want to use an ORM. I'd like to have a db-communcation layer easy to user, to read and efficient.</p> <p>This is my solution: every entity (ex: Person) as an helper that do the CRUD functions (ex: PersonHelper). The helper extends another class (EntityHelper), that contai...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-04T16:12:11.207", "Id": "80802", "Score": "0", "body": "avoid using enums in Android, use static final fields." } ]
[ { "body": "<p>I'm not familiar with Android development nor SQLite, so just a few minor generic notes:</p>\n\n<ol>\n<li><p>You have the following method in the <code>EntityHelper</code>:</p>\n\n<blockquote>\n<pre><code>/**\n * Bind a record to an entity for insert.\n * Remember to not bind the entity id!\n * \n...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-12T22:38:19.770", "Id": "23807", "Score": "4", "Tags": [ "java", "android", "database" ], "Title": "Android database access" }
23807
<p>I've started writing a game and I need help, because I know there are many ways to improve what I am doing. I am doing it the basic way I know I can but I know there is more complex ways of doing it.</p> <pre><code>import time print"Created on 3/12/2013" print"ver 1.2" print"Created by: Daniel Vargas" print'At any ...
[]
[ { "body": "<p>Here are some small fixes:</p>\n\n<ul>\n<li><strong>Make the input lowercase.</strong> By replacing <code>Choice2 = raw_input('You...\\n')</code> with <code>Choice2 = raw_input('You...\\n').lower()</code> you can replace <code>Choice1 in ('East', 'east')</code> by <code>Choice1 == 'east'</code>.</...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-12T23:02:53.713", "Id": "23808", "Score": "4", "Tags": [ "python", "adventure-game" ], "Title": "Adventure game in a forest" }
23808
<p>I'm currently writing a WebGL HTML5 game, and large part of the game initialization involved loading assets streamed over a websocket, and saving them to disk using the FileSystem API.</p> <p>As part of optimizing the code, we're trying to eliminate as many memory allocations as we can, which means cutting down on ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-12T15:21:24.063", "Id": "36706", "Score": "0", "body": "I'm going to migrate it in a few minutes, but would you like to award the bounty first so it doesn't get lost on the way?" } ]
[ { "body": "<p>I think the best approach here would be</p>\n\n<ul>\n<li><p>Create a FileWriter wrapper which exposes the functionality through a (jQuery?) Deferred pattern <a href=\"http://api.jquery.com/category/deferred-object/\" rel=\"nofollow\">http://api.jquery.com/category/deferred-object/</a></p></li>\n<l...
{ "AcceptedAnswerId": "23812", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-11T15:35:45.707", "Id": "23809", "Score": "6", "Tags": [ "javascript", "html5", "optimization" ], "Title": "Using Javascript FileWriter with minimal use of closures" }
23809
<p>I have a table full of URLs, some of which will occasionally become invalid. As part of a system I'm writing to go through the links periodically, and test if they are valid (or redirect to valid sites), I wrote the following class. The feedback I'm looking for is primarily related to clean code and best practices--...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T12:15:46.520", "Id": "36742", "Score": "0", "body": "'I kept the one line functions, because I want someone who does not know exactly how curl works to still be able to read the code.' That, is what comments are for." }, { "...
[ { "body": "<p>one line functions make your logic hard to follow, I would advise strongly against them.\n<em>Especially</em> if you only call that function only once, which is the case in most of your code.</p>\n\n<p>As a very minor comment, I would put </p>\n\n<pre><code>curl_setopt($this-&gt;curl, CURLOPT_NOBO...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T01:26:35.760", "Id": "23816", "Score": "3", "Tags": [ "php" ], "Title": "How can this this URL Checker be made cleaner?" }
23816
<p>See the examples below:</p> <pre><code>function map_cloning(obj,fn){ result = {}; for (var key in obj) result[key] = fn(obj[key]); return result; }; function map_modifying(obj,fn){ for (var key in obj) obj[key] = fn(obj[key]); return obj; }; function sum_cloning(vector1,vector2...
[]
[ { "body": "<p>I suggest cloning. If it was possible (like in Java), I'd even suggest making your objects immutable...</p>\n\n<p>Why do I suggest cloning? Consider being after a busy Friday, with business users ranting all day on some totally unimportant feature, and you see this code fragment all of a sudden, h...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T03:09:30.413", "Id": "23819", "Score": "1", "Tags": [ "javascript" ], "Title": "Modify or not modify your objects when creating computing functions?" }
23819
<p>I'm new to JS/jQuery and wrote some JavaScript/jQuery lines to create a <a href="http://jsfiddle.net/drkthng/RJWS2/9/" rel="nofollow">"pulsating" object</a>.</p> <p>I get the "pulse" effect by increasing/resizing the object and then bringing it back to its original state periodically. I was uncomfortable with calc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T11:44:45.780", "Id": "36740", "Score": "2", "body": "The short answer is to write a plugin. See http://docs.jquery.com/Plugins/Authoring for style advice." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-...
[ { "body": "<p>Ok, so after some (more!) search on the net, I will propose one thing that I was already pondering about (having a little experience mostly with OOP languages Java and C#).<br><br>\ncreating a <strong>class/datastructure</strong> to hold the values<br><br>\nI was inspired by these sources:<br></p>...
{ "AcceptedAnswerId": "23877", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T03:18:06.857", "Id": "23820", "Score": "5", "Tags": [ "javascript", "jquery", "beginner" ], "Title": "Providing one-time calculations to frequently used methods" }
23820
<p>This is completely optimization question, I have a pagination query like this:</p> <pre><code>$this-&gt;paginate = array( 'fields' =&gt; array( 'DISTINCT Contact.contact_id', 'Contact.first_name', 'Contact.last_name', ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-01T17:11:41.290", "Id": "85491", "Score": "0", "body": "you can half the cost of that code by calling paginate only once =)" } ]
[ { "body": "<p>Perhaps you could wrap it all in a function:</p>\n\n<pre><code>function pagination($this,$viewList,$keywordQuery)\n{\n $this-&gt;paginate = array(\n 'fields' =&gt; array(\n 'DISTINCT Contact.contact_id',\n 'Contact.first_name',\n ...
{ "AcceptedAnswerId": "23930", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T06:03:12.783", "Id": "23821", "Score": "2", "Tags": [ "performance", "php", "php5", "pagination", "cakephp" ], "Title": "How to optimize the pagination query?" }
23821
<p>Is this a good CSS? </p> <pre><code> .table1 thead tr td, .table1 tbody tr td, .table2 thead tr td, .table3 tbody tr td:first-child, .table4 tbody tr td:first-child, .table7 tbody tr td:first-child ,.table7 tbody tr td:nth-child(2), .table8 tbody tr td:first-child, .table9 tbody tr td{background-co...
[]
[ { "body": "<p>Well, I suggest to use some more whitespace and use a CSS minifier to strip the whitespace in production, this doesn't look that nice... Some things:</p>\n\n<hr>\n\n<pre><code>border-top: 4px solid #a3c6cd; border-bottom:4px solid #a3c6cd\n</code></pre>\n\n<p>This can be easier done by using the <...
{ "AcceptedAnswerId": "23824", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T07:16:13.247", "Id": "23823", "Score": "2", "Tags": [ "css" ], "Title": "CSS Code Quality" }
23823
<p>Is it possible to write the two following lines of code in a more compact one?</p> <pre><code>IEnumerable&lt;int&gt; collection = from partnerNumbers in contract.Contact.PartnerNumbers select partnerNumbers.Pnr; var response = this.otherClass.SomeMethod(collection, DateTime.Now.Date); </code></pre> <p>Additional i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T08:37:26.257", "Id": "36730", "Score": "0", "body": "`DateTime.Today`" } ]
[ { "body": "<p>Idon't see why you would want to shorten that piece of code but here's the same result in one line and using a LinQ method-chain instead of query-syntax:</p>\n\n<pre><code>var response = otherClass.SomeMethod(contract.Contact.PartnerNumbers.Select(p =&gt; p.Pnr), DateTime.Now.Date);\n</code></pre>...
{ "AcceptedAnswerId": "23837", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T07:44:16.930", "Id": "23825", "Score": "3", "Tags": [ "c#", "linq", "entity-framework" ], "Title": "Refactoring from .. in .. select to more compact one" }
23825
<p>I have created a simple DBLayer class. But I am not sure whether this class have any bug/issue using in production. </p> <pre><code>public class DBLayer { private static string connectionString = ConfigurationManager.AppSettings["ConnectionString"]; public static DataTable GetDataTable(string strSQL, Comma...
[]
[ { "body": "<p>Looks good. You may also want some other things like <code>getScalar</code> (A single object, or string, as in 1 cell), <code>getDataRow</code>, just the top row, <code>getDataRowCollection</code>, i frequently only use datatable to get the rows, and forget about the columns, so I can iterate over...
{ "AcceptedAnswerId": "23829", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T09:10:12.743", "Id": "23828", "Score": "3", "Tags": [ "c#", "sql-server" ], "Title": "Simple DBLayer class review" }
23828
<p>I am learning C# from a book, and there is an exercise as follows:</p> <blockquote> <p>Write a program that has a person enter full name, age, and phone number. Display this information with formatting. Also display the person's initials.</p> </blockquote> <p>I wrote some code and I feel that it could be imp...
[]
[ { "body": "<p>In designing classes we should try and confirm to the <a href=\"http://en.wikipedia.org/wiki/Single_responsibility_principle\">Single Responsibility Principle</a>. Each class should only do one thing. Sometimes defining what makes a single responsibility is hard, but your <code>Person</code> class...
{ "AcceptedAnswerId": "23836", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T11:51:06.903", "Id": "23835", "Score": "6", "Tags": [ "c#", "console", "formatting" ], "Title": "Displaying a person's personal information with formatting" }
23835
<p>This program use random number generator to create sentences. It prints 20 sentences randomly. Here is the code:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;time.h&gt; #include &lt;ctype.h&gt; #define STR_LEN 80 #define MAX_SEN 20 int main(void) { char *article[] = {"the", "...
[]
[ { "body": "<p>Sorry for no explanation. Not really sure why I wrote this. Just saw your post, got in the zone, and suddenly I have a chunk of code! Hope it is insightful.</p>\n\n<pre><code>#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\n#include &lt;stdlib.h&gt;\n#include &lt;time.h&gt;\n#include &lt;ctype...
{ "AcceptedAnswerId": "23887", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T14:06:04.993", "Id": "23845", "Score": "2", "Tags": [ "c", "array" ], "Title": "Random Sentences generator" }
23845
<p>Below is the code of a custom C# class I have called UniversalTextBoxTextBinder. I'm interested to hear the code review comments to find out the limitations of this 'universal' solution as well as to get posted here the references on similar solutions. Obviously the solution posted here can be generalized on other t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T13:57:53.980", "Id": "36751", "Score": "1", "body": "By the way, WPF doesn't need that, because it has a `real` binding engine where you can achieve a two-way binding with only doing `<TextBox Text=\"{Binding FirstName}\"/>`." }, ...
[ { "body": "<p>I think this code, while fairly impressive, is reinventing a wheel that WinForms wasn't designed to use. Trying to implement the <em>Model-View-ViewModel</em> pattern with WinForms will cause you more trouble than you can possibly imagine, if your application is just a little bit more complex than...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T13:42:59.797", "Id": "23847", "Score": "4", "Tags": [ "c#", "winforms" ], "Title": "'Universal' WinForms TextBox Text 'Two-Way' Binder" }
23847
<p>I have no idea if I'm doing this efficiently, or ideally, but I've written what I think is a factory. Please help me understand if this is good practice, or if there is another direction I should take this. There's no particular project in mind with this, I'm just farting around. (Written in PHP)</p> <pre><code>cla...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-21T12:43:51.360", "Id": "37318", "Score": "0", "body": "Is Wouter J the only one with any input on this?" } ]
[ { "body": "<p>In my opinion, a factory should create a specific class, global ones like this one shouldn't be used. For instance, having a PizzaFactory is something like this:</p>\n\n<pre><code>class PizzaFactory\n{\n public static function createPizza($type)\n {\n switch ($type) {\n cas...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T14:15:39.207", "Id": "23848", "Score": "1", "Tags": [ "php", "object-oriented" ], "Title": "Getting familiar with OOP - Factories" }
23848
<p>The following script should get links which are stored in a text file (line by line), then put them into an array and finally scan each links' source code for a certain line. If this line is found, it will be pasted into a CSV file.</p> <p>It works fine so far, but it takes ages to finish, since each link is 'opene...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T14:57:27.857", "Id": "36758", "Score": "0", "body": "Can you time how long it takes to finish? What you consider \"ages\" to complete might be perfectly acceptable for this type of task. I have a scraper that grabs booking informati...
[ { "body": "<p>Performing this task in parallel would help greatly although PHP is not the best language to do so in.</p>\n\n<p>I would do so by spawning PHP processes by POSTing to other PHP scripts (<a href=\"https://stackoverflow.com/questions/962915/how-do-i-make-an-asynchronous-get-request-in-php/962920#962...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T14:26:49.587", "Id": "23849", "Score": "3", "Tags": [ "php", "performance", "html", "curl" ], "Title": "Optimizing PHP script fetching entire HTML pages" }
23849
<p>I'm writing a function that takes between one and three arguments <code>(function callback [, number limit] [, regexp pattern])</code>. Since the second two are both optional, I need to determine which argument is being passed when the function is supplied with only two. Below is my solution, but it seems overly ver...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T14:33:18.627", "Id": "36755", "Score": "0", "body": "Can the order of which they are passed in change? Ie. if there is a second one, will it always be a number etc. Or could the order change possibly? Being were the regexp gets pass...
[ { "body": "<pre><code>function(cb,limit,pattern) {\n limit = typeof(limit) === \"undefined\" ? 1 : limit;\n //do stuff\n}\n</code></pre>\n\n<p>Calling a function with less arguments than declared will just fill them with undefined. You can then check if that is the value, if so fill in your default ones.<...
{ "AcceptedAnswerId": "23853", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T14:28:09.867", "Id": "23850", "Score": "1", "Tags": [ "javascript", "node.js" ], "Title": "Handling an unknown number of arguments" }
23850
<p>I'm wondering if the way I wrote our TextHelper class is a really a proper way to do it.<br> We have products that are interlinked in different ways and every product has multiple text fields that might be empty.</p> <p>Now depending on where the text is supposed to show up, we want different texts.<br> A simple ex...
[]
[ { "body": "<p>My answer to your main question is you gotta do what you gotta do. Just so you feel more comfortable; this pattern has a name <strong>strategy enum</strong>. It is even in <em>Effective Java</em>.</p>\n\n<p>But I have a criticism for this bit:</p>\n\n<pre><code> public static final TextType[] u...
{ "AcceptedAnswerId": "23860", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T14:39:30.963", "Id": "23851", "Score": "3", "Tags": [ "java", "enum" ], "Title": "Enums with different methods, useful or abuse?" }
23851
<p>I'm trying to establish a concurrency violation verification in my SQL updates using C# and raw SQL.</p> <p>What I'm doing now is storing the <code>TimeStamp</code> value in a <code>byte[]</code> upon selection and before updating I'm checking if the stored value is equal to the current value. here's the code:</p> ...
[]
[ { "body": "<blockquote>\n<pre><code> using (SqlConnection connection = new SqlConnection(\"\"))\n {\n try\n {\n //open connection\n if (connection.State != System.Data.ConnectionState.Open)\n</code></pre>\n \n <p>Why check connection state for just created connection?...
{ "AcceptedAnswerId": "23864", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T14:41:06.363", "Id": "23852", "Score": "4", "Tags": [ "c#", "sql", "exception-handling" ], "Title": "Handling optimistic concurrency violations" }
23852
<p>I have done a lot of research on OOP and I keep seeming to read different opinions on several items, especially the scope resolution operator (<code>::</code>) and handling class containing private functions.</p> <p>When calling a private function from within the <code>class</code> it seems that a majority of progr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T15:09:39.143", "Id": "36760", "Score": "1", "body": "the `::` operator, or `T_PAAMAYIM_NEKUDOTAYIM` if you like that, is an operator for static methods and class constants, to call a method use `$this->method()`." }, { "Cont...
[ { "body": "<ol>\n<li>Never ever use <code>var</code>. That's a deprecated form of <code>public</code>;</li>\n<li>Avoid using <code>public</code> on your properties, you want to have controll about the value of every property in your class;</li>\n<li><p>If you use <code>protected</code> or <code>private</code> d...
{ "AcceptedAnswerId": "23857", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T14:45:28.453", "Id": "23854", "Score": "2", "Tags": [ "php", "object-oriented", "timer" ], "Title": "Timer class in PHP OOP" }
23854
<p>I wrote a basic Clojure single-threaded socket server, mostly following Java examples; in particular I'd appreciate feedback on three things, </p> <ul> <li>how I handle mutable state (I/O, managing connections).</li> <li>how I pass the server around among the create-server/run/app functions. </li> <li>my setup to e...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T15:26:54.230", "Id": "23859", "Score": "3", "Tags": [ "clojure" ], "Title": "single-threaded socket server" }
23859
<p>I am working on the following problem (<a href="http://www.enigmagroup.org/missions/programming/9/" rel="nofollow">http://www.enigmagroup.org/missions/programming/9/</a>).</p> <p>You have a 6x6 table where the first 5 columns and rows are comprised of different types of shapes, 5 total. The sixth row contains the s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T09:45:55.363", "Id": "36819", "Score": "2", "body": "You could use [Gaussian Elimination](http://en.wikipedia.org/wiki/Gaussian_elimination) to do the solution of your equations, just put your linear equations in a 5x6 matrix first....
[ { "body": "<ol>\n<li><p>I'm not a JavaScript developer but two things which could help: <a href=\"https://codereview.stackexchange.com/questions/23867/solving-systems-of-linear-equations#comment36819_23867\">another algorithm, as <em>RobH</em> mentioned in his comment</a> or running the calculations in a backgr...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T16:35:28.973", "Id": "23867", "Score": "7", "Tags": [ "javascript", "optimization", "algorithm", "json", "programming-challenge" ], "Title": "Solving systems of linear equ...
23867
<p>I have a small function which I regularly use to check if a variable contains only [a-z][0-9] and the special chars '-' and '_'. Currently I'm using the following:</p> <pre><code>function is_clean($string){ $pattern = "/([a-z]|[A-Z]|[0-9]|-|_)*/"; preg_match($pattern, $string, $return); $pass = (($strin...
[]
[ { "body": "<p>No need for all that. Just use one bracket group, negate it (be prepending a <code>^</code>), and use the return value directly:</p>\n\n<pre><code>function is_clean ($string) {\n return ! preg_match(\"/[^a-z\\d_-]/i\", $string);\n}\n</code></pre>\n\n<hr>\n\n<p>Here's a quote from <a href=\"http...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T17:37:44.967", "Id": "23872", "Score": "1", "Tags": [ "php", "regex" ], "Title": "php most efficient way to check if a variable contains only certain chars" }
23872
<p>I want to get a better feeling for how JavaScript works and how to use it well. I coded up this Tetris game, and have iterated over the code base and improved it a couple of times now.</p> <p>I hope the state of the code is fairly good at this point, but also that someone more familiar with the language can suggest...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T18:27:38.437", "Id": "36776", "Score": "2", "body": "Don't you think there's a little too much code in one file?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T18:32:13.287", "Id": "36777", "...
[ { "body": "<p>From a one-time reading:</p>\n\n<ul>\n<li><p>Functions <code>left</code>, <code>right</code>, <code>up</code> and <code>down</code> do model changes and deal with the view. Ideally, you would have a controller functionality that calls those functions when required, and afterwards the controller ca...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T18:07:15.050", "Id": "23873", "Score": "10", "Tags": [ "javascript", "beginner", "game", "tetris" ], "Title": "Learning the basics of JavaScript with a Tetris game" }
23873
<p>I'm trying to change the background color of each <code>.achievement</code> div. The content is being generated dynamically so I can't add a class easily to each one.</p> <p>I have it working with selectors like <code>.achievements .grid-row:nth-child(odd) .col-1-2:nth-child(even) .achievement</code> but they seem ...
[]
[ { "body": "<p>You should probably take out the class selectors (<code>.grid-row</code> and <code>.col-1-2</code>) because <code>nth-child</code> <a href=\"https://stackoverflow.com/questions/5428676/nth-child-doesnt-respond-to-class\">doesn't respond to them</a> (i.e. they're not doing anything):</p>\n\n<pre><c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T21:23:46.370", "Id": "23880", "Score": "3", "Tags": [ "html", "css" ], "Title": "CSS3 Selectors for achievements" }
23880
<p>I am new with <code>SignalR</code> and still a newbie with <code>IoC Container</code> <code>SimpleInjector</code> and I am wondering if there are any side effects and/or if I'm save with my chosen approach.</p> <p>In my web app I have a <code>SetupHub</code> that invokes a method on an object resolved with <code>Si...
[]
[ { "body": "<p>Currently, your setup doesn't allow for any cancellation or error handling. The latter is an implementation detail, so I guess you've handled that in the actual code. I would consider the following:</p>\n\n<ul>\n<li>Return the started task out of <code>Start</code></li>\n<li>Will you ever need to ...
{ "AcceptedAnswerId": "48365", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T21:55:43.597", "Id": "23881", "Score": "10", "Tags": [ "c#", "dependency-injection", "signalr" ], "Title": "Send message with SignalR to client(s) from injected (IoC) method" }
23881
ASP.NET SignalR is a new library for ASP.NET developers that makes it incredibly simple to add real-time web functionality to your applications. What is "real-time web" functionality? It's the ability to have your server-side code push content to the connected clients as it happens, in real-time.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T22:22:54.870", "Id": "23883", "Score": "0", "Tags": null, "Title": null }
23883
Apache Subversion is an open-source centralized version control system.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T22:26:56.253", "Id": "23886", "Score": "0", "Tags": null, "Title": null }
23886
<p>I started feeling like my code was becoming a little cluttered in the graphics:</p> <pre><code>void render() { BufferStrategy bs = getBufferStrategy(); if (bs == null) { createBufferStrategy(3); return; } Graphics2D g = (Graphics2D) bs.getDrawGraphics(); g.setColor(Color.BLACK);...
[]
[ { "body": "<p>To answer real fast about your switch, you can do the following :</p>\n\n<pre class=\"lang-java prettyprint-override\"><code>function whatEverName(State state){\n\n switch(state){\n case START_MENU:\n drawStartMenu();\n //..\n break;\n case PL...
{ "AcceptedAnswerId": "23959", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T23:45:03.420", "Id": "23888", "Score": "1", "Tags": [ "java", "graphics", "hangman" ], "Title": "Set visible interface from method/class" }
23888
<p>I point to my problem in the comments of my code.</p> <p>I have a class RomanNumeral:</p> <pre><code>public class RomanNumeral { private String romaNumera; private String romans = "IVXLCDM"; public RomanNumeral(String rn) { //sets rn to romaNumera and checks if rn is a valid roman numeral ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T04:56:02.140", "Id": "36813", "Score": "1", "body": "Why are you using `float`s when roman numerals represent integers?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-16T12:23:38.603", "Id": "36976"...
[ { "body": "<p>First thing you can do is put them in <code>else if</code> statements. It doesn't reduce the code but it do at least reduce the number of case the program has to check each time.</p>\n\n<p>Because right now if the first match is good, it'll still check all the other statements.</p>\n\n<hr>\n\n<p><...
{ "AcceptedAnswerId": "23892", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T00:51:18.857", "Id": "23891", "Score": "7", "Tags": [ "java", "classes", "roman-numerals" ], "Title": "Reducing verbosity of RomanNumeral class" }
23891
<p>I have developed a system whereby I use an attribute to state which <code>SelectList</code> to use for an 'FK' property. I would appreciate some feedback mainly on by good practice, and also on any ways to do this better. Let me start my exposition with a demo view model:</p> <pre><code>public class DemoModel { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-12-31T20:21:30.377", "Id": "350397", "Score": "0", "body": "I stumbled across this post and noticed that in your DropDownListAttribute class, OnMetadataCreated(), you are assigning a value to local variable listProp, but not assigning tha...
[ { "body": "<p>I'm assuming this code hasn't been reviewed yet because it's... <strong>beautiful</strong> - and I'm still searching for a better word. I mean, <em>wow that's clever, I want that!!</em></p>\n\n<p>The only thing I can see here, is in the <code>View</code> method:</p>\n\n<blockquote>\n<pre><code>pro...
{ "AcceptedAnswerId": "37747", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T06:23:13.340", "Id": "23897", "Score": "11", "Tags": [ "c#", ".net", "asp.net", "asp.net-mvc-4" ], "Title": "Injecting SelectList objects into ViewData to enable using Edit...
23897
<p>I'm using the following function to fuzzy match strings:</p> <pre><code>function fuzzy_match(str,pattern){ pattern = pattern.split("").reduce(function(a,b){ return a+".*"+b; }); return (new RegExp(pattern)).test(str); }; </code></pre> <p>Example:</p> <pre><code>fuzzy_match("fogo","foo") //true fuzzy_match...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T09:02:03.457", "Id": "36816", "Score": "2", "body": "Why is [360k operations per second](http://jsperf.com/fuzzy-match) slow? If your application is slow, I think the problem is not there." }, { "ContentLicense": "CC BY-SA 3...
[ { "body": "<pre><code>function fuzzy_match(str,pattern){\n pattern = pattern.split(&quot;&quot;).reduce(function(a,b){ return a+&quot;.*&quot;+b; });\n return (new RegExp(pattern)).test(str);\n};\n</code></pre>\n<ol>\n<li><p>String concatenation is slow. The reason is that you need to allocate new memory ...
{ "AcceptedAnswerId": "23905", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T06:38:25.573", "Id": "23899", "Score": "16", "Tags": [ "javascript", "strings", "regex" ], "Title": "Faster JavaScript fuzzy string matching function?" }
23899
<p><strong>Note:</strong> This ended up being much longer than I was expecting. I have a number of side questions that relate to specific parts of the code for if you don't want to slog through all this mess.</p> <h2>Background</h2> <p>I have had some experience in Java, but recently decided to learn C#. I would like...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T15:16:01.663", "Id": "36937", "Score": "1", "body": "You should look into automatic properties. You can write things like `public string Command { get; private set; }` and not need backing fields." }, { "ContentLicense": "C...
[ { "body": "<p>First off, for somebody who is just learning C# you use it better than some of the people I work with.</p>\n\n<p>Now to answer your questions:</p>\n\n<ol>\n<li><p>You are correct, there is no native way to read numbers from the <code>Console</code> in C#. You could look at <code>decimal.TryParse<...
{ "AcceptedAnswerId": "23958", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T06:52:53.837", "Id": "23900", "Score": "13", "Tags": [ "c#" ], "Title": "Am I coding Java in C#?" }
23900
<p>I'm mostly looking for performance suggestions. Feel free to include more than just that.</p> <p>Since Google Code Jam is coming around, I thought I would look at some of the previous questions. <a href="https://code.google.com/codejam/contest/90101/dashboard#s=p0" rel="nofollow">Alien Language</a> is the one I pic...
[]
[ { "body": "<p>You need a clever data structure in order to avoid to check all possible combinations. I would suggest Trie structure with some additional statistic for every char position. Using Trie you can pretty quick find which letter is possible in which position and which isn't possible.</p>\n\n<p>One more...
{ "AcceptedAnswerId": "23914", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T07:31:15.460", "Id": "23901", "Score": "4", "Tags": [ "c#", "programming-challenge" ], "Title": "Another iteration of Alien Language" }
23901
<p>I wrote two functions for determining leap years. ("Kabisat" means "leap year" in Indonesia.)</p> <pre><code>def kabisat? y return false if y%4!=0 return true if y%100!=0 y%400==0 end def kabisat_2? y return true if y%400==0 return false if y%100==0 y%4==0 ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T10:06:20.757", "Id": "36820", "Score": "4", "body": "Why not use the built-in [`Date#leap?`](http://ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#method-i-leap-3F) method?\n\nIn any event, your `kabisat_1` function is broken....
[ { "body": "<p>Some notes:</p>\n\n<ul>\n<li>I assume that, for some reason, you want to write your own function/method instead of the existing <a href=\"http://ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#method-i-leap-3F\" rel=\"nofollow\">Date#leap?</a> that @Flambino linked above.</li>\n<li><code>kabi...
{ "AcceptedAnswerId": "23903", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T07:48:16.810", "Id": "23902", "Score": "2", "Tags": [ "algorithm", "ruby", "datetime" ], "Title": "Leap year algorithm?" }
23902
<p>Please check my code below. I don't have any problems but I'm not aware how far the code will work, release and kill excel instances..</p> <pre><code>try { wBook = xCel.Workbooks.Open(excelfilepath); xCel.Visible = false; this.xCel.DisplayAlerts = false; wSheet = (Excel.Worksheet)...
[]
[ { "body": "<p>Since Excel runs via COM, it won't be released from memory until you remove all references to it. Your example (above) does a pretty good job, but after you say wBook.Close(), you should say wBook = null. Likewise Excel won't gracefully close-down while your xCel object refers to an instance of ...
{ "AcceptedAnswerId": "23908", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T13:35:49.643", "Id": "23907", "Score": "1", "Tags": [ "c#", "exception-handling", "excel" ], "Title": "Excel instances: release and kill" }
23907
<p>Is this code correct?</p> <p>This code was adapted from <a href="http://chessprogramming.wikispaces.com/Alpha-Beta#Implementation-Negamax%20Framework" rel="nofollow">this</a> alphabeta pseudocode. AlphaBeta search is often mentioned but getting the code 100% correct is tricky.</p> <p><code>IGame</code> is an inte...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T15:56:17.927", "Id": "36840", "Score": "3", "body": "Even if the algorithm is know as \"alphabeta\", \"minimax\", etc, you should find better variable names that \"alpha\" and \"beta\"." }, { "ContentLicense": "CC BY-SA 3.0"...
[ { "body": "<p>My last AI course was too long time ago so just some generic notes and some modifications for easier testing.</p>\n\n<ol>\n<li><p>Fields should be <code>private</code>. (<em>Item 13</em> of <em>Effective Java 2nd Edition</em>: <em>Minimize the accessibility of classes and members</em>)</p></li>\n<...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T15:01:45.857", "Id": "23911", "Score": "5", "Tags": [ "java", "search", "ai" ], "Title": "Java alphabeta search" }
23911
<p>I'm not entirely sure on how to handle errors on this:</p> <ul> <li>Is returning a <code>nullptr</code> in case of bad parameters okay, or is it better to return a <code>ENFMPCodegenData.Empty</code>, like there is <code>Rectangle.Empty</code> or Point.Empty in the .NET Framework?</li> <li>What about handling error...
[]
[ { "body": "<blockquote>\n <p>Is returning a <code>nullptr</code> in case of bad parameters okay?</p>\n</blockquote>\n\n<p>No, you should instead throw an <code>ArgumentException</code> (or possibly one of its derived types). This way, if an user of your code makes a mistake, they will get an exception clearly ...
{ "AcceptedAnswerId": "24014", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T16:33:49.060", "Id": "23916", "Score": "4", "Tags": [ "c#", "c++", "c++11", "c++-cli" ], "Title": "Implementation of a managed wrapper DLL" }
23916
<p>I'm trying to find a good pattern for new applications (and for refactoring old ones).</p> <p>Maybe it's just me, but I dislike spawning my main logic thread from inside my main form thread (so far I always have 2+ threads in my apps and beefy hardware, also .NET 4.5). I feel it conflicts with the separation of co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T13:39:46.500", "Id": "36927", "Score": "1", "body": "Are you planning on having the `MainTask` method actually do any work? If not, why have it? If so, how will it interact with the UI if it has no reference to the UI and the UI h...
[ { "body": "<p>I would second Steven Doggart's comment about it being pointless to spawn a thread that does nothing.</p>\n\n<p>To address your separation of concerns issue, though: If you are using one of a number of design patterns for your UI (e.g., MVC, MVVM, MVP, etc.), your MainForm class will merely be bin...
{ "AcceptedAnswerId": "23967", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T16:58:26.353", "Id": "23917", "Score": "2", "Tags": [ "c#", "multithreading" ], "Title": "Multi-threaded Winforms Conventions for Main()" }
23917
<p>This is K.I.S.S, but how about some error and misuse control? I am wishing it were .NET.</p> <pre><code>&lt;?php function array_group_by($arr, $key_selector) { $result = array(); foreach($arr as $i){ $key = $key_selector($i); if(!array_key_exists($key, $result)) { $result[$key] ...
[]
[ { "body": "<ol>\n<li>Using the <code>[]</code> syntax for adding array items, allows PHP to create the array as necessary. Thus you can scrap the <code>if</code> statement for a modest performance increase off 10 to 15% in my own testing. (Unlike if you used <a href=\"http://php.net/manual/en/function.array-pus...
{ "AcceptedAnswerId": "23926", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T17:33:41.113", "Id": "23919", "Score": "3", "Tags": [ "php", "array" ], "Title": "Generic array group by using lambda" }
23919
<p>I made this class to handle any min max integer value and return a random number in the entered parameter range. I tested it to work with all combinations(I think). But is this totally wrong or written with unnecessary amounts of code? Are there obvious Java convention violations or obvious redundancy in this?</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T22:00:04.820", "Id": "36845", "Score": "1", "body": "The `rand()` is for a different programming language, C++." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T22:03:23.723", "Id": "36846", "S...
[ { "body": "<p>That does look a little confusing. The example you looked at is for C, not Java. I would do this:</p>\n\n<pre><code>int random = (int) Math.floor(Math.random() * (max - min + 1) ) + min;\n</code></pre>\n\n<p>It works like this: <code>Math.random()</code> returns a <code>double</code> between 0 ...
{ "AcceptedAnswerId": "23921", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-13T21:52:15.650", "Id": "23920", "Score": "1", "Tags": [ "java", "performance", "random" ], "Title": "Random number wrapper class" }
23920
<p>I have a function that searches the shortest vector in a vector of vectors of pointers.</p> <p>Which is a better way?</p> <pre><code>std::vector&lt;std::vector&lt;void*&gt;&gt; const&amp; ways { size_t i = SIZE_MAX; for(auto&amp; it : ways) { if(i &gt; it.size()) i = it.size(); } } </co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T01:59:21.390", "Id": "36889", "Score": "0", "body": "This is the wrong site for this type of question. You are going to get a lot more responses on SO." } ]
[ { "body": "<p>Calling <code>size()</code> twice, like you are, almost definitely get's optimized out in any modern compiler. How you are doing it is perfectly fine. You could also do it with <code>std::max_element</code>...</p>\n\n<pre><code>auto max = std::max_element(ways.begin(), ways.end(), \n [](const s...
{ "AcceptedAnswerId": "23934", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T19:09:22.223", "Id": "23927", "Score": "1", "Tags": [ "c++", "vectors" ], "Title": "Should I call a method (i.e. size()) multiple times or store it (if I know the value will not ch...
23927
<p>I am learning about the class and methods in Python.</p> <p>The class Accuracy is a class of several (13 in total) statistic values between a reference polygon and one or more segmented polygons based on shapely module.</p> <p><img src="https://i.stack.imgur.com/sg0ar.jpg" alt="enter image description here"></p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T19:33:06.900", "Id": "36862", "Score": "0", "body": "Will you ever be calling the four functions `ra_or`, `ra_os`, etc. outside of `Accuracy`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T19:34:11....
[ { "body": "<p>If you plan on calling the four functions <code>ra_or</code>, <code>ra_os</code>, <code>sim_size</code> and <code>AFI</code> outside of <code>Accuracy</code> then it is good to keep them as functions. If they never get called except through <code>Accuracy</code>, then they should be made methods.<...
{ "AcceptedAnswerId": "23932", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-14T19:27:14.750", "Id": "23929", "Score": "4", "Tags": [ "python", "classes", "extension-methods" ], "Title": "improve the design of class “accuracy” in Python" }
23929
<p>Is there a better, more elegant solution to the following method?</p> <pre><code>Boolean[] spades = new Boolean[10]; // 40 cards deck foreach (Card card in m_Cards.Where(card =&gt; (card.Suit == Suit.Spades))) spades[(Int32)card.Rank] = true; // Rank goes from Ace (0) to King (10) if (spades[0] &amp;&amp; spa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-24T00:28:15.753", "Id": "63223", "Score": "1", "body": "What is your `m_cards` variable? What kind of game is this?" } ]
[ { "body": "<p>We can use the fact that in the ordered sequence of cards the cards that match your requirement will be located at the beginning of sequence, and their rank will match their position:</p>\n\n<pre><code>var count = _cards.Where(card =&gt; card.Suit == Suit.Spades)\n .Select(card =&gt; (int)card....
{ "AcceptedAnswerId": "23945", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T04:59:37.613", "Id": "23940", "Score": "7", "Tags": [ "c#", "algorithm", ".net", "game", "playing-cards" ], "Title": "Playing card game method" }
23940
<p>I know I should be using vectors, but I want to learn something.</p> <p>Please review it and point out any mistakes. Thank you. Here it is:</p> <pre><code>template&lt; typename T &gt; class Table2D { public: Table2D( unsigned int sizeX, unsigned int sizeY ) : m_sizeX( sizeX ) ...
[]
[ { "body": "<p>Firstly, I assume you have something like <code>#define __in</code> up the top. This is sort of a Microsoft-ism, and really isn't needed in most of these parameter sets. When you're passing types that are neither pointers nor references, it's pretty obvious that they're input values. To me, it's s...
{ "AcceptedAnswerId": "23943", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T06:07:44.630", "Id": "23941", "Score": "2", "Tags": [ "c++" ], "Title": "C++ Simple 2D Array Wrapper" }
23941
<p>Recently I needed to manipulate with cookies using JavaScript, so I wrote a class:</p> <pre><code>function Cookies() { var cookieLifeTime = null; this.setCookie = setCookie; this.getCookie = getCookie; this.deleteCookie = deleteCookie; this.setLifeTime = setLifeTime; function setLifeTime(l...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T11:31:34.580", "Id": "36913", "Score": "0", "body": "As far as I'm aware, there is already a plugin for it in the wild. Why not use it instead?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T12:47:25...
[ { "body": "<p>The only thing I'd suggest is that there is no real need for it being a class, since it's basically a singleton. So I'd use:</p>\n\n<pre><code>var Cookies = {\n // The same as your function\n};\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "Creatio...
{ "AcceptedAnswerId": "23957", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T10:20:12.747", "Id": "23949", "Score": "4", "Tags": [ "javascript" ], "Title": "Class to interact with cookies" }
23949
<p>I wrote a simple JSON schema validator. The full code is over <a href="https://gist.github.com/pramodliv1/5168625" rel="nofollow noreferrer">here</a> on gist.github.com However, the code without comment is...</p> <pre><code>validate = function(schema, instance) { var i; var errors = 0; var getType =...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T11:30:49.887", "Id": "36912", "Score": "0", "body": "Edited your question putting the code from the link into it." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T12:23:39.833", "Id": "36915", ...
[ { "body": "<p>I'd definitely change:</p>\n\n<pre><code>if(instance[i] == undefined) {\n addError(\"Property Not found\", i);\n}\n</code></pre>\n\n<p>to something more robust, e.g.</p>\n\n<pre><code>if (!instance.hasOwnProperty(i)) {\n addError(\"Property Not found\", i);\n}\n</code></pre>\n\n<p>Stylistica...
{ "AcceptedAnswerId": "23952", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T10:35:56.720", "Id": "23950", "Score": "3", "Tags": [ "javascript", "json" ], "Title": "JSON schema validator" }
23950
<p>How can I verify that <code>ohterClassMock.MethodToTest()</code> was called with <code>contracts</code>?</p> <p>That it was called with <code>contract</code>, that have <code>Id = 1</code> and <code>Param2 = 34</code> and also with <code>contract2</code>, which has <code>Id = 2</code> and <code>Param2 = 56</code>.<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T10:22:12.720", "Id": "36906", "Score": "2", "body": "Not very clear. What do you want to test exactly? That the contracts were not modified?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T10:24:56.96...
[ { "body": "<p>Strictly to answer the question at hand, you have local variables for the individual contracts already, so you can just re-use them:</p>\n\n<pre><code>ohterClassMock.Verify(mock =&gt; mock.MethodToTest(It.Is&lt;Contract&gt;(c =&gt; contract.Equals(c))));\nohterClassMock.Verify(mock =&gt; mock.Meth...
{ "AcceptedAnswerId": "23964", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T10:19:33.750", "Id": "23951", "Score": "1", "Tags": [ "c#", "unit-testing", "moq" ], "Title": "Verify collection as a method parameter" }
23951
<p>I often have method like this one with two or more render to do due to catching the error for example. I currently do something like this:</p> <pre><code>def update @user = current_user if params[:user][:camera_type].present? &amp;&amp; params[:user][:lens_type].present? &amp;&amp; params[:user][:photo].present...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T22:27:50.263", "Id": "36965", "Score": "0", "body": "can you fix the indentation?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T23:37:42.857", "Id": "36966", "Score": "1", "body": "@tokl...
[ { "body": "<p>Some notes:</p>\n\n<ul>\n<li>Keep your controllers lean, this is too much code for an action. </li>\n<li>The photo upload should be done as a part of the object's save chain (after validation), so create a <code>before_save</code> callback in the <code>User</code> model that returns <code>false</c...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T14:09:22.763", "Id": "23954", "Score": "2", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "two or more render/redirect in the same method" }
23954
<p>Just trying to work out some simple graceful connection handling code in Haskell to get my head around some of the IO/Networking/Threading stuff, some tips where I'm doing things poorly would be appreciated! I'm sure I could just use a module like network pipes that would handle all the graceful stuff for me out of ...
[]
[ { "body": "<p>Just one remark: When handling <code>IO</code> resources, I'd strongly suggest using <a href=\"http://hackage.haskell.org/package/base-4.8.0.0/docs/Control-Exception-Base.html#v:bracket\" rel=\"nofollow\"><code>bracket</code></a> for resources that are obtained at some point and later released. No...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T17:05:43.190", "Id": "23963", "Score": "4", "Tags": [ "multithreading", "haskell", "networking", "server" ], "Title": "Haskell network connection graceful handler" }
23963
<p>I have implemented the DBSCAN algorithm for clustering image keypoints. I have been following the pseudocode on the <a href="http://en.wikipedia.org/wiki/DBSCAN" rel="noreferrer">wiki</a> page pretty strictly, and it's working, but I get the feeling its a very naive implementation and could be improved in terms of ...
[]
[ { "body": "<p>Your implementation is fine. There's a few little things that could change but overall wouldn't do much for efficiency. For instance, having the <code>noise</code> vector doesn't really do anything and <code>sqrt()</code> is computationally-demanding, so squaring <code>eps</code> before the loop ...
{ "AcceptedAnswerId": "36129", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T17:47:14.777", "Id": "23966", "Score": "12", "Tags": [ "c++", "performance", "algorithm", "clustering", "opencv" ], "Title": "Density-based clustering of image keypoint...
23966
<p>OpenCV is the most popular and advanced code library for Computer Vision related applications today, spanning from many very basic tasks (capture and pre-processing of image data) to high-level algorithms (feature extraction, motion tracking, machine learning). It is free software and provides a rich API in C, C++, ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T18:34:16.707", "Id": "23971", "Score": "0", "Tags": null, "Title": null }
23971
OpenCV (Open Source Computer Vision) is a cross-platform library of programming functions for real time computer vision.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T18:34:16.707", "Id": "23972", "Score": "0", "Tags": null, "Title": null }
23972
<p>In effort to streamline applicable PHP file <code>include</code> or <code>require</code> functions I thought that making a class to handle this might be a good idea.</p> <p>Originally I had an <code>includes/init.php</code> file that included everything, I wanted to make this more dynamic to the specific page the u...
[]
[ { "body": "<h2>Mixing</h2>\n\n<p>You are mixing 2 things:</p>\n\n<ul>\n<li>class loading</li>\n<li>\"template\" loading</li>\n</ul>\n\n<p>You aren't over complicating things - you try to over simplify them.</p>\n\n<h2>Class loading</h2>\n\n<p>In your solution you are loading all classes if only (for example) 2 ...
{ "AcceptedAnswerId": "23977", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-15T20:46:24.727", "Id": "23976", "Score": "1", "Tags": [ "php", "object-oriented" ], "Title": "PHP Class that handles all includes / required files" }
23976
<p>I initialized a tree using a nested hash as input, but when I recursively call <code>Tree.new</code> on the children, it doesn't seem to pass each child as a hash. As a pretty ugly, but working, alternative, I translated everything to arrays.</p> <p>Is there a way to preserve the hash?</p> <p>I'm doing this exerci...
[]
[ { "body": "<p>Some notes:</p>\n\n<ul>\n<li>The <code>initialize</code> method of a class should be its most basic and fundamental constructor, don't use it as a \"helper\". A tree has a name and some children, so these should be the arguments. You want to construct a Tree from a hash to make things easier for t...
{ "AcceptedAnswerId": "23986", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-16T04:49:51.960", "Id": "23979", "Score": "1", "Tags": [ "ruby", "tree" ], "Title": "Making a tree with hash input" }
23979
<p>Here is a solution to the <a href="http://pl.spoj.com/problems/JPESEL/" rel="nofollow">SPOJ's JPESEL problem</a>. Basically the problem was to calculate cross product of 2 vectors modulo 10. If there is a positive remainder, it's not a valid <a href="http://en.wikipedia.org/wiki/PESEL" rel="nofollow">PESEL number</a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-16T17:58:26.517", "Id": "36992", "Score": "0", "body": "Why do you need to read from STDIN? I guess it will be faster with a file." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-16T18:02:45.890", "Id":...
[ { "body": "<p>Likely what is taking up extra time is the line:</p>\n\n<pre><code> p = map(int, re.findall('.',sys.stdin.readline()))\n</code></pre>\n\n<p>There are a few things here. Firstly, regular expressions are relatively expensive. Underneath, it likely needs to compile the regular expression (which in th...
{ "AcceptedAnswerId": "23993", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-16T09:30:44.913", "Id": "23981", "Score": "1", "Tags": [ "python", "optimization", "programming-challenge", "python-2.x" ], "Title": "SPOJ \"Pesel\" challemge" }
23981
<p>I am searching a recursive solution space and would like to return the first match I find. (I am using this to solve sudoku, but I guess this would apply to any recursively defined problem or datastructure).</p> <p>So, in pseudocode, I need to call a function repeatedly with a set of possible input values, and retu...
[]
[ { "body": "<p>You can use <code>drop-while</code> instead of mapping over the given sequence.</p>\n\n<pre><code>(defn find-first-3 [do-something range]\n (first (drop-while #(nil? (do-something %)) range)))\n</code></pre>\n\n<p>This should be minimally lazy (since you don't need laziness here), won't traverse ...
{ "AcceptedAnswerId": "24100", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-16T10:47:53.203", "Id": "23983", "Score": "2", "Tags": [ "clojure", "recursion" ], "Title": "Finding first match in recursive search" }
23983
<p>I would like to know if this is being done correctly.</p> <pre><code>using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Linq; using System.Text; public class InnerJoinTables { public List&lt;InnerJoinTable&gt; Items = new List&lt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-16T14:15:47.803", "Id": "36978", "Score": "1", "body": "Does it seem to work? What exactly are you worried about? Why do you think it might not be the correct way?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "20...
[ { "body": "<p>The code will work, so from that point of view, it is correct.</p>\n\n<p>But there are also some issues with it:</p>\n\n<ol>\n<li>I don't see any reason for the <code>InnerJoinTables</code> class to exist. You should just use <code>List&lt;InnerJoinTable&gt;</code> directly in the calling code. Th...
{ "AcceptedAnswerId": "23989", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-16T14:01:23.667", "Id": "23987", "Score": "0", "Tags": [ "c#", "object-oriented", "generics" ], "Title": "Creating and populating a generic list" }
23987
<p>I received the following feedback for my code:</p> <hr> <p>"I still do not see a design here that will work.</p> <p>It is a very bad idea to have the big switch and loop at this point. All you need in your <code>main()</code> method is to create one object of each class and call the methods on them.</p> <h3>In c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-16T15:59:17.923", "Id": "36983", "Score": "3", "body": "Explaining what the code is supposed to be doing would be nice. A bit hard to review without any context. Also, could you perhaps give the question a real title?" }, { "Co...
[ { "body": "<p>If I understand the requirements correctly, then you were tasked to <em>design</em> not to <em>implement</em> such a system. So you were asked to specify the interface, or API.</p>\n<h2>Example in English:</h2>\n<h3>Class Contact:</h3>\n<p>represents a contact. Has getters/setters for name, email,...
{ "AcceptedAnswerId": "23992", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-16T15:43:28.663", "Id": "23990", "Score": "1", "Tags": [ "java", "array" ], "Title": "Help creating a workable design?" }
23990
<p>Say I have a data structure like this:</p> <pre><code>array(3) { ["id"]=&gt; int(1) ["name"]=&gt; string(3) "foo" ["message"]=&gt; array(1) { ["action"]=&gt; string(3) "PUT" } } </code></pre> <p>Where 'message' and 'action' are both optional. To check if they're present my first attempt woul...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T00:40:26.233", "Id": "125246", "Score": "0", "body": "See also: http://stackoverflow.com/questions/2948948/array-key-exists-is-not-working You can write an array_key_exists utility function which works recursively." } ]
[ { "body": "<p>No, this is just the way of doing it.</p>\n\n<blockquote>\n <p>Even when I'm not limited to a certain script language, I can't think of an cleaner solution?</p>\n</blockquote>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "Crea...
{ "AcceptedAnswerId": "23994", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-16T18:02:38.540", "Id": "23991", "Score": "8", "Tags": [ "php", "array" ], "Title": "Checking for existing key in multi-dimensional array" }
23991
<p>At the "if(a==2)" part of my code below, the android emulator takes 8 seconds to process and display some data in a list. I need to reduce this time to 1 second or less. I am accessing a 50 KB .txt file with 3200 lines, comparing each line with a string passed by another function, and whichever line matches the stri...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-17T04:09:00.407", "Id": "37013", "Score": "1", "body": "onCreate could really do with some splitting up into separate methods." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-17T09:00:56.430", "Id": "37...
[ { "body": "<ol>\n<li><p>These streams are never closed:</p>\n\n<blockquote>\n<pre><code>InputStream is = getAssets().open(\"USSTATES.txt\");\nInputStreamReader iz = new InputStreamReader(is);\nBufferedReader bis = new BufferedReader(iz);\n</code></pre>\n</blockquote>\n\n<p>You should close them in a <code>final...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-16T21:58:44.457", "Id": "23995", "Score": "3", "Tags": [ "java", "optimization", "android" ], "Title": "Optimization of Android code suggestions? Iteration based" }
23995
<p>Looking for optimizations and cleaner, more pythonic ways of implementing the following code.</p> <pre><code>#Given an array find any three numbers which sum to zero. import unittest def sum_to_zero(a): a.sort(reverse=True) len_a = len(a) if len_a &lt; 3: return [] for i in xrange(0, len...
[]
[ { "body": "<p>Your code fails this test case:</p>\n\n<pre><code>def test_winston1(self):\n res = sum_to_zero([125, 124, -100, -25])\n self.assertEqual(res, [125,-100,-25])\n</code></pre>\n\n<p>As for the code</p>\n\n<pre><code>def sum_to_zero(a):\n a.sort(reverse=True)\n</code></pre>\n\n<p>Why sort?</p...
{ "AcceptedAnswerId": "23998", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-16T22:10:11.573", "Id": "23996", "Score": "9", "Tags": [ "python", "algorithm" ], "Title": "Given an array find any three numbers which sum to zero" }
23996
<p>I am creating a multiple choice quiz game with PHP and Javascript. Questions can have 2 to 6 answers. I have been using the PHP queries in the code below to get arrays of the questions of a quiz, and the answers for each questions.</p> <p>I now want to use this data in Javascript, and want to make it so each time a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-16T23:58:26.000", "Id": "37008", "Score": "1", "body": "JSON - JavaScript Object Notation, is a better way to pass information to/from PHP and JS. PHP has built in functions to encode and decode to JSON. http://php.net/manual/en/book.j...
[ { "body": "<p>Running a SQL statement in a loop is in general a bad idea. Depending on your <code>$questionsrow</code> you might send a lot of not needed requests.</p>\n\n<p>In relation to MECUs hint you could use something like:</p>\n\n<pre><code>$questions=array();\n//add constrains to select only some questi...
{ "AcceptedAnswerId": "24000", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-16T22:47:09.217", "Id": "23997", "Score": "1", "Tags": [ "javascript", "php", "array" ], "Title": "Turning multiple PHP arrays into one array ready for conversion to Javascript" }
23997
<p>I am trying to implement a stable radix sort in place with O(1) space. I've seen Wikipedia, and I notice the C implementation is using a temporary variable to hold the sorted value for each pass, and the section of "in-place" MSD radix sort implementation is quite confusing. </p> <p>I took the C code and tried to i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-17T02:15:51.647", "Id": "37009", "Score": "0", "body": "What is the question, whether your implementation of the algorithm is correct? whether the asymptotic costs are the ones of algorithm?" }, { "ContentLicense": "CC BY-SA 3....
[ { "body": "<p>Yes, your radix sort appears to be correct, and runs in O(<em>k n</em>) time.</p>\n\n<p><code>bucket_max_index</code> is written to, but otherwise never used. You can eliminate it completely.</p>\n\n<p>Before the creation of the <code>temp</code> vector, you set <code>index = 0</code>. It would ...
{ "AcceptedAnswerId": "45074", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-17T01:55:01.933", "Id": "23999", "Score": "6", "Tags": [ "c++", "sorting", "complexity", "radix-sort" ], "Title": "Stable radix sort in-place using O(1) space" }
23999
<p>I'm using the <code>BigRational</code> beta off the BCL CodePlex (<a href="http://bcl.codeplex.com" rel="nofollow">bcl.codeplex.com</a>), and I realized it had no parsing method, so I tried to write one. However, it's quite inefficient (5.5ms for a 254 character number). That's over 45x slower than the BigInteger im...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-17T17:25:04.023", "Id": "37049", "Score": "0", "body": "I think that before worrying about performance, you should make sure that your code actually works correctly (hint: try parsing numbers like `0.1`, or even just `1`). And you shou...
[ { "body": "<p>The answer, I found out now, was that if I moved the <code>Regex</code>es to private fields, and then used those, after the first use it will radically drop down to .4ms, and that's including a <code>WriteLine</code> call. So the real hotspot in this method was the <code>Regex</code>. Thanks every...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-17T08:45:53.343", "Id": "24002", "Score": "6", "Tags": [ "c#", "performance", "parsing", "rational-numbers" ], "Title": "Parsing a BigRational efficiently" }
24002
<p>I am developing a web-application and I am encountering some trouble : I have some tabs and each one contains input forms with different values. I need to switch beetween these tabs and see the different contents of each one. So I thought I could create objects for every tab , but I have to name them , I use somet...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-17T11:48:38.587", "Id": "37024", "Score": "0", "body": "If you are using jQuery and jQueryUI why don't you use the tab control in that library: http://api.jqueryui.com/tabs/" } ]
[ { "body": "<pre><code>var step = function(params){\n this.id = randID();\n this.titolo = params.titolo;\n this.descrizione = params.descrizione;\n this.dmax = null;\n}\n\n$(\"#btn\").on('click',function(){\n stepA = new step({\n \"titolo\" : $(\"#titolo\").val(),\n \"descrizione\" :...
{ "AcceptedAnswerId": "27444", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T09:34:27.030", "Id": "24003", "Score": "1", "Tags": [ "javascript", "jquery", "object-oriented" ], "Title": "Dynamically create object" }
24003
<p>I don't know what this problem is named, so I can't Google for a solution about it. Here's the image:</p> <p><img src="https://i.stack.imgur.com/RcOcA.jpg" alt="3 Pitcher Problem"></p> <p>There are three pitchers with capacities of 10, 7 and 3 quarts.</p> <p>We need to move the water from a pitcher (or jar) to an...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T12:01:59.780", "Id": "37088", "Score": "1", "body": "See [this answer](http://stackoverflow.com/a/15089256/68063) over on Stack Overflow. (It's in Python, not Ruby, but it shouldn't be too difficult for you to follow.)" } ]
[ { "body": "<p>Some comments on your code:</p>\n\n<ul>\n<li><p><code>def initialize max, current, target</code>. The community consensus seems to be to put always parenthesis on method definitions. I'd definitely do it.</p></li>\n<li><p><code>return @current == @max</code>. It's not idiomatic to put explicits <c...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-17T12:42:25.680", "Id": "24007", "Score": "2", "Tags": [ "algorithm", "ruby", "recursion" ], "Title": "\"Three pitchers with water\" problem" }
24007
<p>I'm very new to Angular, and trying to get my head around whether or not I'm doing it the Right Way (tm).</p> <p>I want to filter a set of results by their properties, where if none of the filters are checked, all the results are displayed, but if one or more filters are checked, all results which match the checked...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-17T23:28:06.740", "Id": "37057", "Score": "0", "body": "I don't have the rep to create an 'Angular' tag unfortunately." } ]
[ { "body": "<p>You're attempting to handle the data binding yourself by creating arrays to store objects based on the click event. Angular does the two way binding for you. </p>\n\n<p>Basically, I assign a new property named \"included\" by assigning it as the model to the input checkbox. Then I use that proper...
{ "AcceptedAnswerId": "30713", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-17T20:15:56.963", "Id": "24017", "Score": "0", "Tags": [ "javascript", "angular.js" ], "Title": "Angular Checkbox Filtering" }
24017
<p>I've discovered (and written) a way to object oriented programming in lua in a functional fashion instead of the standard metatable method. It carries much more functionality (no pun intended) but I'm afraid it might dent performance. My goal is to experiment with servers written in lua and I wanted to use this OOP ...
[]
[ { "body": "<p>Even though this kind of inheritance is perfectly valid example of OOP designing in language like Lua; it is considered a bad practice of programming.</p>\n<p>According to <a href=\"http://www.lua.org/pil/16.html\" rel=\"nofollow noreferrer\">Programming in Lua</a> on <strong>Object-Oriented Progr...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-17T21:22:24.777", "Id": "24020", "Score": "10", "Tags": [ "object-oriented", "lua" ], "Title": "Object Oriented programming in lua in a functional fashion" }
24020
<p>I have a function that takes an XML document and parses out specific XML elements and appends those to a list for use by an Oracle executemany call. The placement of the elements matters as the executemany string uses positional binds, though I could easily use a dictionary to use named binds instead. I feel that wh...
[]
[ { "body": "<p>I was able to simplify this by using BeautifulSoup4 to replace the block of code that searches for typePattern if: statements with one that matches against a simplified list and appends in one go. This still has to iterate through the section of code, but it is very fast. The slowest part is loadi...
{ "AcceptedAnswerId": "24063", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-17T22:42:10.663", "Id": "24022", "Score": "3", "Tags": [ "python" ], "Title": "How can I make my XML parser more pythonic?" }
24022
<p>i wish to improve my Progressbar in Python</p> <pre><code>from __future__ import division import sys import time class Progress(object): def __init__(self, maxval): self._seen = 0.0 self._pct = 0 self.maxval = maxval def update(self, value): self._seen = value pct =...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T02:05:07.600", "Id": "37061", "Score": "1", "body": "CodeReview is to get review on code which is working, not to get some help to add a feature." } ]
[ { "body": "<p>As per my comments, I've not sure SE.CodeReview is the right place to get the help you are looking for.</p>\n\n<p>However, as I didn't read your question properly at first, I had a look at your code and changed a few things (please note that it's not exactly the same behavior as it used to be):</p...
{ "AcceptedAnswerId": "24024", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-17T23:05:03.840", "Id": "24023", "Score": "0", "Tags": [ "python", "optimization" ], "Title": "Progressbar in Python" }
24023
<p>The following <a href="/questions/tagged/batch" class="post-tag" title="show questions tagged 'batch'" rel="tag">batch</a> script runs on a Scheduled Task on Windows 7 with a quad core 2.5GHz and 16GB of DDR3.</p> <p>It makes the <a href="/questions/tagged/svn" class="post-tag" title="show questions tagged 'svn'" r...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T06:41:37.677", "Id": "37068", "Score": "0", "body": "For starters you could remove ***all*** unnecessary code." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T06:41:58.237", "Id": "37069", "Sc...
[ { "body": "<p>This isn't a great answer but I've found <em>some</em> tips to hopefully (not guaranteed) increase the speed of your batch files.</p>\n\n<blockquote>\n <p>Load Batch Files on to a RAM Drive. Use a small-size RAM drive with\n small cluster sizes to preserve memory. Then place the RAM Drive batc...
{ "AcceptedAnswerId": null, "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T02:29:20.060", "Id": "24025", "Score": "0", "Tags": [ "windows", "batch", "svn" ], "Title": "Speed up SVN backup" }
24025
<p>I have a pack of cards and I am doing a 'deal' action. I am dealing <code>n</code> number of cards, for now to one player.</p> <p>How can I DRY up the <code>while</code> and <code>unless</code> loops to have fewer lines?</p> <pre><code>def deal(number_of_players, number_of_cards_each) # 1..number_of_players p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T05:27:24.437", "Id": "37064", "Score": "1", "body": "You are not using `number_of_players` parameter, returning cards for one player only. You should get your algorithm straight first." }, { "ContentLicense": "CC BY-SA 3.0",...
[ { "body": "<p>If I get your code right you are creating random cards while dealing. I would move this at the beginning to make your dealing cleaner. I'm no ruby guy, so I have to offer some pseudo code:</p>\n\n<pre><code>// List/Array of 52/32... Cards (just a trivial loop over the ranks and suits)\nall_cards=g...
{ "AcceptedAnswerId": "24035", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T02:37:36.570", "Id": "24026", "Score": "1", "Tags": [ "ruby", "playing-cards" ], "Title": "Deal action with a pack of cards" }
24026
<p>I have an abstract class which implements the <code>IDataCreator</code> interface:</p> <pre><code>public interface IDataCreator { public String getDataString(); } public abstract class AbstractCreator implements IDataCreator { protected IProject p; public AbstractCreator(IProject p) { this.p = ...
[]
[ { "body": "<p>Note that there isn't a so called factory pattern, there is factory method and there is abstract factory.</p>\n\n<p>I would create a separate factory class for ProjectDateCreator.CREATION and ProjectDateCreation.UPDATED. To answer your original question, never be afraid of interfaces and abstract ...
{ "AcceptedAnswerId": "24037", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T08:05:42.860", "Id": "24031", "Score": "6", "Tags": [ "java", "design-patterns", "factory-method" ], "Title": "Is this a correct way to use Factory Pattern?" }
24031
<p>I haven't spent too much time with CoffeeScript and am trying to have a simple counter:</p> <pre><code>casper.on('step.complete', ( -&gt; i = 0 return (step) -&gt; i += 1 @echo "Step#{ i }" )()) </code></pre> <p>Which works fine but seems to have a bit too many parenthes...
[]
[ { "body": "<p>I would certainly distangle the code and create a named function instead of an anonymous one.</p>\n\n<pre><code>step_creator = -&gt;\n i = 0\n return (step) -&gt;\n i += 1\n @echo \"Step#{ i }\"\n\ncasper.on 'step.complete', step_creator()\n</code></pre>\n", "comments": [ ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T14:51:22.243", "Id": "24038", "Score": "1", "Tags": [ "coffeescript", "closure" ], "Title": "Cleanest way to close over a counter in CoffeeScript" }
24038
<p>I need the most efficient way to get the value of the searchName, or if null return searchName. I am returning just a single string, so maybe I should search itemRepository.Item instead of Items</p> <pre><code>return itemRepository.Items() .Where(i =&gt; i.Name.Contains(searchName)) ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T15:56:46.863", "Id": "37100", "Score": "0", "body": "Why is `Items` a method rather than a property (as evidenced by the `()`)? Other than that question, this seems exactly the canonical way I'd do what you're looking for." }, {...
[ { "body": "<p>As long as <code>Items()</code> returns an <code>IQueryable&lt;Item&gt;</code> directly from the database, then this code is just about as fast as you can get it. If not, I think your <code>Items()</code> method will be the main bottleneck in this code. </p>\n\n<p>From your comment it sounds like ...
{ "AcceptedAnswerId": "24047", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T15:39:36.797", "Id": "24042", "Score": "-1", "Tags": [ "c#", "linq" ], "Title": "making this linq query faster" }
24042
<p><a href="http://en.wikipedia.org/wiki/Transact-SQL" rel="nofollow">Transact-SQL</a> (TSQL) is a proprietary SQL dialect used by Microsoft and Sybase in their relational database products. Since Microsoft's SQL Server originated from a Sybase codebase, the general syntax and some system functions are very similar on ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T15:43:30.327", "Id": "24043", "Score": "0", "Tags": null, "Title": null }
24043
Transact-SQL (TSQL) is the extended SQL dialect used in Microsoft SQL Server and Sybase. Please also tag with either [sql-server] or [sybase].
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T15:43:30.327", "Id": "24044", "Score": "0", "Tags": null, "Title": null }
24044
<p>A general question: For using matlabpool, I write the line</p> <pre><code>matlabpool open local 12; </code></pre> <p>as the first line in my code and the line:</p> <pre><code>matlabpool close; </code></pre> <p>as the last. Is this correct?</p>
[]
[ { "body": "<p>Seems to be fine according to <a href=\"http://www.mathworks.nl/help/distcomp/matlabpool.html\" rel=\"nofollow\">the documentation</a>.</p>\n\n<p>The only things you need to try are whether 12 is the best number for you, and whether it makes sense to close the matlabpool earlier (you might not gai...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T15:59:22.620", "Id": "24045", "Score": "1", "Tags": [ "matlab" ], "Title": "Using matlabpool: Is my embedding correct?" }
24045
<p>Below is attempt to catch potential deadlocks at runtime in C#. Basically this class allows user to acquire locks in a pre-defined order only. I ran some basic tests and it appears to work. Please review and let me know if you find something wrong with implementation.</p> <pre><code>public class OrderedLock { [...
[]
[ { "body": "<p>I haven't extensively tested it, but there are a few things I've noted:</p>\n\n<ul>\n<li>The class has two members which hold on to <code>IDisposable</code> resources. Therefore, the class <strong>must</strong> implement <code>IDisposable</code> as well and <code>Dispose()</code> of those members....
{ "AcceptedAnswerId": "24050", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T16:06:31.623", "Id": "24046", "Score": "3", "Tags": [ "c#", "multithreading" ], "Title": "Implementation of ordered lock pattern" }
24046
<p>In the project I work on there are several places where a switch statement is used on a type enum. (I know, better to use virtual functions or a visitor pattern or something, but sometimes switching on type codes is unavoidable - e.g., deserializing XML.) All of our type enums are of the simple form <code>enum { Typ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T01:53:46.537", "Id": "37158", "Score": "0", "body": "You might want to edit your code so that it compiles in something other than MSVC. MSVC in non-compliant in this situation, specifically, explicit specializations must be at names...
[ { "body": "<p>That seems like an awful lot of boilerplate code to replace a single diagnostic that already exists in a lot of compilers. You're replacing</p>\n\n<pre><code>switch (fruit) {\n case APPLE: return \"apple\"; break;\n case PEAR: return \"pear\"; break;\n case PLUM: return \"plum\"; break;\n}\n</c...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T16:38:14.617", "Id": "24048", "Score": "6", "Tags": [ "c++", "template", "template-meta-programming" ], "Title": "C++ compile-time checked switch 'statement'" }
24048
<p>So I'm making a program that is a serial port wedge. In other words I want it to listen to a serial port. If data comes in, wait a given amount of time, then play a sound and finally send the data out.</p> <p>All of those things have a abstract class associated with it. I'm thinking that I might eventually want to ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-26T15:37:39.577", "Id": "37642", "Score": "3", "body": "Have your class implement `IDisposable` and follow the disposable pattern for it: http://stackoverflow.com/a/898867/3312" } ]
[ { "body": "<p>As Jesse C. Slicer mentioned, because your class <em>seems</em> to encapsulate an <code>IDisposable</code> object (assuming <code>serialPort</code> would be a private field - this would be clearer if you named it <code>_serialPort</code>), it's <em>asking</em> to implement the <code>IDisposable</c...
{ "AcceptedAnswerId": "35804", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T17:18:48.870", "Id": "24051", "Score": "3", "Tags": [ "c#", "polymorphism" ], "Title": "Hardware resource Open/Close methods" }
24051
<p>This plugin displays a tooltip popup with the data obtained via Ajax. I am sure there are better ones out there, but my objective is to learn how to correctly build a plugin, not find the best one available. I would appreciate any comments, suggestions, criticism from a best practices and design pattern usage persp...
[]
[ { "body": "<p>Here's the code mostly the same with some changes to style and comments:</p>\n\n<pre><code>(function($){\n var defaults = {\n 'url' : 'getAjaxTip.php', // The url used to get the tooltip data.\n 'class' : '', // Css class(es) to add to tooltip (along with standardAjaxTip)....
{ "AcceptedAnswerId": "24096", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T17:25:42.323", "Id": "24053", "Score": "2", "Tags": [ "javascript", "jquery", "ajax", "plugin" ], "Title": "Tooltip popup plugin" }
24053
<p>This is inside a method (basically its just this), I try to get the neededValue otherwise I pass back what was passed in...</p> <pre><code>private static string GetNeededValue(string param) { string tValue = ""; if (!string.IsNullOrEmpty(param)) { var map = repo.Item(string....
[]
[ { "body": "<p>Yes it's efficient. However, your code appears to be very vulnerable to <a href=\"http://en.wikipedia.org/wiki/SQL_injection\" rel=\"nofollow\">SQL Injection</a> attacks. For example, imagine what the result would be if a user ran this code:</p>\n\n<pre><code>var result = MyModule.GetNeededValue(\...
{ "AcceptedAnswerId": "24057", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T18:27:22.243", "Id": "24055", "Score": "4", "Tags": [ "c#" ], "Title": "just making sure this is efficient, for the null checks" }
24055
<p>I have implemented a global <code>appIncluder</code> function which is imported as includeme with the <strong>init</strong>.py of the package to be included.</p> <p><code>includeme</code> (<code>ApplicationIncluder</code>) receives the config object, so it is then easy to use config.package and its variables/method...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T20:03:59.663", "Id": "24058", "Score": "4", "Tags": [ "python", "pyramid" ], "Title": "Global appIncluder function to include sub-applications dynamically" }
24058
<p>Please have a look at the code below:</p> <p>ClassLibrary1 has a structure as follows:</p> <pre><code>Namespace com.app.test Public Class Class1 End Class End Namespace </code></pre> <p>ClassLibrary2 has a structure as follows:</p> <pre><code>Namespace com.app.test Public Class Class2 End Class End Nam...
[]
[ { "body": "<p>Yes it is poor practice, there is no reason really to deviate from best practice which is to have the last part of your namespace match the project name like this:</p>\n\n<pre><code>CompanyName.SolutionName.ProjectName\n</code></pre>\n\n<p>Say there is a company called \"ABC Solutions\" and they h...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-18T21:12:52.983", "Id": "24061", "Score": "2", "Tags": [ "design-patterns", "vb.net" ], "Title": ".NET - multiple DLLs and one namespace" }
24061
<p>I'm new to programming and even more new to Haskell. Below is a little tid-bit I wrote that operates on a bunch of lists. I am wondering if someone would be kind enough to walk through the function <code>margProbs</code> line-by-line, and enumerate their respective space/time complexities and/or just possibly sugge...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T14:45:55.073", "Id": "37184", "Score": "0", "body": "What do you expect as an answer: suggestions to improve performance or just analysis of space&time complexity?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate":...
[ { "body": "<p><strong><code>scaleV</code></strong></p>\n\n<p><code>scaleV</code> is very similar to <code>fmap</code>, it just has different precedence in its arguments, the following definition is simpler and highlights this similarity:</p>\n\n<pre><code>scaleV = (fmap .)\n</code></pre>\n\n<p><strong>Guards</s...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T01:17:18.707", "Id": "24067", "Score": "3", "Tags": [ "optimization", "beginner", "haskell", "functional-programming", "complexity" ], "Title": "Space and time complexity ...
24067
<p>I have a website that keeps track of 'changes' that users make. These changes come in all shapes and sizes and each shape and size has a different MySQL table to store them in. In total there are 8 different tables. Each table has completely different columns, so I don't <em>think</em> a simple <code>JOIN</code> wou...
[]
[ { "body": "<p>Yes, there is: create a stored procedure and UNION the result sets then sort the records and return them to PHP.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T19:37:45.677", "Id": "37208", "Score": "0", "body...
{ "AcceptedAnswerId": "24070", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T03:39:17.347", "Id": "24068", "Score": "1", "Tags": [ "php", "mysql" ], "Title": "MySQL limit across multiple tables in multiple queries" }
24068
<p>I would like to refactor this block, it looks clunky:</p> <pre><code># refactor me receive_payment_on = false config[:sections].each do |section| if section[:applicants] section[:applicants][:sections].each do |app_sec| if app_sec[:employment] &amp;&amp; app_sec[:employment][:receive_payment_on] ...
[]
[ { "body": "<p>Put your code into a method. So you get rid of the temporary variable, its cleaner and you can leave your method with a return as soon as you find the first true. (A break to leave the loop will have the same effect.)</p>\n\n<p>In addition to that I'm a big friend of guard conditions. Invert <code...
{ "AcceptedAnswerId": "24072", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T05:56:53.813", "Id": "24071", "Score": "0", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Setting receive_payment_on flag for employment applicants" }
24071
<p><a href="https://pypi.python.org/pypi/pyramid/" rel="nofollow">Pyramid</a> is a small, fast, down-to-earth, open source Python web application development framework. It makes real-world web application development and deployment more fun, more predictable, and more productive.</p> <p>Pyramid is produced by the <a h...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T09:53:25.423", "Id": "24076", "Score": "0", "Tags": null, "Title": null }
24076
A Python-based web framework provided by the Pylons Project *Note: Don't use this for pyramid output (e.g. of numbers)
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-03-19T09:53:25.423", "Id": "24077", "Score": "0", "Tags": null, "Title": null }
24077
<h2>Definition from Wikipedia:</h2> <blockquote> <p>Microsoft Excel is a spreadsheet application developed by Microsoft.</p> </blockquote> <h2>Basic functionality:</h2> <ul> <li>Calculation</li> <li>Graphing and charting tools</li> <li>Pivot tables</li> <li>A macro programming language called Visual Basic for Appl...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T10:56:59.527", "Id": "24080", "Score": "0", "Tags": null, "Title": null }
24080
Microsoft Excel is a commercial spreadsheet application written and distributed by Microsoft.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T10:56:59.527", "Id": "24081", "Score": "0", "Tags": null, "Title": null }
24081
Serialization is the process by which an object is converted into a format that can be stored and later retrieved.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T11:00:36.280", "Id": "24083", "Score": "0", "Tags": null, "Title": null }
24083
<p>The binary search algorithm begins by comparing the target value to value of the middle element of the sorted array. If the target value is equal to the middle element's value, the position is returned. If the target value is smaller, the search continues on the lower half of the array, or if the target value is lar...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T11:11:04.857", "Id": "24086", "Score": "0", "Tags": null, "Title": null }
24086
Binary search is an efficient algorithm for finding a key in sorted data. It runs in O(log n) time.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T11:11:04.857", "Id": "24087", "Score": "0", "Tags": null, "Title": null }
24087
<p><a href="http://www.asp.net/mvc/mvc4" rel="nofollow">ASP.NET MVC 4</a> is the fourth major version of the ASP.NET Model-View-Controller platform for web applications.</p> <h3>New Features</h3> <p>Among the new features of the fourth release are:</p> <ul> <li>Refreshed and modernized default project templates</li>...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T11:11:55.370", "Id": "24088", "Score": "0", "Tags": null, "Title": null }
24088
ASP.NET MVC 4 is the fourth major version of the ASP.NET Model-View-Controller platform for web applications.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T11:11:55.370", "Id": "24089", "Score": "0", "Tags": null, "Title": null }
24089
<h1> Representation in different languages</h1> <ul> <li><p>DateTime is a type in <a href="/questions/tagged/sql" class="post-tag" title="show questions tagged &#39;sql&#39;" rel="tag">sql</a> that represents the date with the time of day with fractional seconds (accuracy: rounded to increments of .000, .003 or .007 s...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-03-19T11:13:55.370", "Id": "24090", "Score": "0", "Tags": null, "Title": null }
24090
DateTime objects in many programming languages describe an instant in time, expressed as a date and time of day. Use on questions about reviewing code involving date/time logic.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-19T11:13:55.370", "Id": "24091", "Score": "0", "Tags": null, "Title": null }
24091