body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I am writing an audio engine that must be multi-platform (win/linux). Basically, a <code>CSound</code> represents a sound file, and <code>CSoundInstance</code> represents <em>one playing</em> of a <code>CSound</code>. Obviously, playing sound is very different on Windows than it is on linux.</p> <p>A <code>CSoundIn...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-03T21:41:39.977", "Id": "34115", "Score": "1", "body": "to me this sounds like a job for inheritance. You're asking for 2 different ways to do the same thing. So you would still use CSound, and CSoundImpl but those would be your parent...
[ { "body": "<p>As you said, if you need something in a pimpl class from another class, then something is wrong. If you can't abstract away the differences, then you can't hide the differences and shouldn't use this idiom.</p>\n\n<p>Don't you think it would be simpler to put <code>Play()</code> in <code>CSound</c...
{ "AcceptedAnswerId": "21346", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-03T21:26:09.067", "Id": "21257", "Score": "2", "Tags": [ "c++", "design-patterns" ], "Title": "Access to a pimpl's members from another pimpl" }
21257
<p>To delete a key from a trie, there are four cases:</p> <p>For the explanation of trie data structure, please check the following link: <a href="http://www.geeksforgeeks.org/trie-insert-and-search/" rel="nofollow">http://www.geeksforgeeks.org/trie-insert-and-search/</a></p> <p>(1) Key is not in the trie. </p> <p>(...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T15:47:17.827", "Id": "34168", "Score": "2", "body": "What is the question?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T18:07:15.880", "Id": "34190", "Score": "0", "body": "@tb-, I've e...
[ { "body": "<ol>\n<li><p>Check your indentation, mostly for comments. While there are a lots of <a href=\"http://en.wikipedia.org/wiki/Indent_style\" rel=\"nofollow\">indent styles for C</a>, none of them recommends removing the spaces after <code>if</code> and <code>for</code>.</p></li>\n<li><p>Using recursive ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T01:29:12.343", "Id": "21259", "Score": "3", "Tags": [ "c", "trie" ], "Title": "delete a key in a trie" }
21259
<p>This is a simple program that gets a number from a user and calculates the number of primes between 3 and the user's number. I'm just curious if I'm using too many variables. I'm only asking since I'm used to not needing to initialize iterator variables before a loop.</p> <pre><code>#include &lt;iostream&gt; using ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T02:35:02.747", "Id": "34120", "Score": "1", "body": "You didn't ask for this but you could test if an integer is a prime in a much more efficient way." } ]
[ { "body": "<p>No, I wouldn't say you're using too many variables (except for <code>c</code>, which doesn't appear to be used anywhere). Not enough functions, though. And perhaps too many spurious assignments. Specifically, I'd suggest something like:</p>\n\n<pre><code>#include &lt;iostream&gt;\nusing namespa...
{ "AcceptedAnswerId": "21262", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T02:06:49.590", "Id": "21261", "Score": "2", "Tags": [ "c++", "primes" ], "Title": "Calculating the number of primes between 3 and another number" }
21261
<p>I am learning OOP using PHP5 and I wrote two simple classes for receiving data from a database using the dependency injection pattern and rendering a grid with Twig.</p> <p>Does this code have sense for OOP logic?</p> <p><strong>index.php</strong></p> <pre><code>&lt;?php /* * Remplazar con autoload */ requi...
[]
[ { "body": "<p>There is one major issue with your code: <strong>It's not English</strong></p>\n\n<p>You can easily guess that I'm also no native English speaker, but you can't write methods and variables in your native language. At some place, either in your company, your open source project or finally if you as...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T02:37:45.973", "Id": "21263", "Score": "2", "Tags": [ "php", "object-oriented", "php5", "dependency-injection", "twig" ], "Title": "Receiving data from a database" }
21263
<p>My HTML has three divs, each id tagged with the logic behind my object (ma/shadow/traps) which contain 10 div each (every icons), also ID-tagged according to the object. On click, I'm gathering the ID and the parent ID to traverse the object and find the value.</p> <p>It's only possible to raise the value if the pr...
[]
[ { "body": "<p>I'm not quite sure I've followed your logic, but it sounds like you have two pre-requisites (either of which might not be present), and you want to return <code>false</code> in any case where a prerequisite is present but is not met.</p>\n\n<p>Can't you break out the testing of one prerequisite in...
{ "AcceptedAnswerId": "21267", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-03T22:11:17.023", "Id": "21264", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Gathering IDs to find values from objects" }
21264
<p>I want to define a matrix of values with a very simple pattern. I've achieved it with the code below but it's ugly - very difficult to read (I find) and surely not as optimal, in terms of performance, as it could be. The former is really what I'm trying to address here. I feel this can be done much more elegantly an...
[]
[ { "body": "<p>It's called Cartesian product and you can do that easily:</p>\n\n<p>Here's one way:</p>\n\n<pre><code>y = [10 30 50 70]\n\nx = [10 30 50]\n\n[X,Y] = meshgrid(y,x);\nresult = [Y(:) X(:)];\n</code></pre>\n\n<p>Result:</p>\n\n<pre><code>10 10\n30 10\n50 10\n10 30\n30 30\n50 30\n10 50\n3...
{ "AcceptedAnswerId": "21273", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-01T14:20:13.903", "Id": "21272", "Score": "3", "Tags": [ "matrix", "matlab" ], "Title": "Build a combinatorial matrix from two vectors" }
21272
<p>Looking for feedback on how to better improve the code below to simplify the code below.</p> <pre><code>var animateTop = $('body'); if ($('html').hasClass('lt-ie9')) { animateTop = $('html'); } $('.var').on('click', function() { animateTop.animate({ scrollTop: $('footer').offset().top }, { q...
[]
[ { "body": "<p>Can't really tell what your code does in real life, thus the following optimization/organization might not work. However, following generic tips, here's what I got:</p>\n\n<pre><code>//we can reduce DOM fetching by fetching html first\n//caching it as well as other frequently used elements\n//assu...
{ "AcceptedAnswerId": "21288", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T05:57:13.323", "Id": "21275", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Simplify jQuery animation with callback" }
21275
<p>I am in two minds about function calls as parameters for other functions. The doctrine that readability is king makes me want to write like this:</p> <pre><code>br = mechanize.Browser() raw_html = br.open(__URL) soup = BeautifulSoup(raw_html) </code></pre> <p>But in the back of my mind I feel childish doing so, wh...
[]
[ { "body": "<p>If it's only one parameter, then sure, why not.</p>\n\n<p>I personally hate the way JQuery syntax (and recently C# and Scala) is usually written with lots of inline function calls (and even inline functions complete with bodies!).</p>\n\n<p>Readability is key. But if you can't make your code reada...
{ "AcceptedAnswerId": "21282", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T06:37:42.507", "Id": "21278", "Score": "3", "Tags": [ "python" ], "Title": "Function calls as parameters for other functions" }
21278
<p>I am using this static method in my class <code>IconManager</code> to read an image from jar file. <code>imagepath</code> is a relative path to the image.</p> <p>This code works perfect. But I was told it is error-prone, because does not handle Exceptions correctly.</p> <pre><code>private static BufferedImage read...
[]
[ { "body": "<p>Before the <code>return null;</code> you have to had add an error message to your Logger (or print to console an error) with \n<code>e.getMessage()</code> , so you will know where is the problem.<br><br>\n Otherwise, when your code is published, nobody can know why or where your code hang.</p>\n",...
{ "AcceptedAnswerId": "21284", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T07:13:14.203", "Id": "21279", "Score": "3", "Tags": [ "java", "exception-handling" ], "Title": "Reading image from jar" }
21279
<p>since in my website I have a lot of <code>&lt;HEADER&gt;</code>, <code>&lt;FOOTER&gt;</code> AND <code>&lt;SECTION&gt;</code> do you think is appropriate if i use a <code>.main</code> class for the main HEADER, main FOOTER AND main SECTION?</p> <p>In the CSS I will never style the <code>.main</code> class like this...
[]
[ { "body": "<p>As a general rule, if you want your markup to be semantic, you should be using classes, IDs and document structure <strong>to describe the content as clearly as possible,</strong> to whatever level is required to achieve the styling you need. Don't just add classes and IDs with the motivation \"I ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T10:00:43.210", "Id": "21285", "Score": "1", "Tags": [ "html5" ], "Title": "HTML5 TAG using a .main class" }
21285
<p>I get a lot done with Python scripts but always feel like I'm working with a messy desk when I'm using it. I assume this is because I am not coding in Python correctly. Coming from a C# and Ruby background, I've used Python mainly as a utility language writing together things that I need quickly - never really try...
[]
[ { "body": "<pre><code>import json\nimport re\nimport urllib2\nfrom scraper_tools import soupify, getHtml, buildJsonPostRequest\n\n__author__ = 'ecnalyr'\n\n\ndef getImageLinkFromDiv(div):\n</code></pre>\n\n<p>The python style guide recommends lowercase_with_underscores for function names</p>\n\n<pre><code> \...
{ "AcceptedAnswerId": "21296", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T13:26:42.897", "Id": "21290", "Score": "8", "Tags": [ "python", "web-scraping" ], "Title": "Scraping new product data from an online store" }
21290
<p><strong>Question from Skiena's Programming Challenges.</strong> Getting WA (wrong answer) in Online Judge even though it's working for sample test cases. Can somebody find a case where it fails?</p> <p>I tried the tricky case from this link and it gave the right answer-</p> <p><a href="https://codereview.stackexc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T16:07:34.670", "Id": "34177", "Score": "0", "body": "Code Review is for improving code that your think works, not finding errors in your code. See the [FAQ]." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-...
[ { "body": "<p>I did not run it (and I do not like to read it, too much abbreviations, wrong variable names, too less formatting), but what about this case:</p>\n\n<blockquote>\n <p>3<br>\n 1.01<br>\n 0.99<br>\n 0.99 </p>\n</blockquote>\n\n<p><code>sum</code> will be <code>2.99 / 3 = 0.9966666...</code> \n<...
{ "AcceptedAnswerId": "21312", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T14:54:22.727", "Id": "21294", "Score": "1", "Tags": [ "c++", "algorithm", "strings", "programming-challenge" ], "Title": "Skiena's Programming Challenge [UVa ID 10137]- Get...
21294
<p>I'm new to TDD, never used it ever. I understand the basic concepts but I'm now working on a small project which will be the first time I've ever actually used TDD.</p> <p>The code is pretty self explanatory, it's a simple user data storage class. I've written an interface, a UserData class, and then implemented th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T15:39:38.973", "Id": "34164", "Score": "2", "body": "One thing I notice off hand is you might find it easier to use the [ExpectedExceptionAttribute](http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittestin...
[ { "body": "<p>imho you are using return values in the wrong way.</p>\n\n<p>For instance, the <code>AddUser</code> returns false for two different reasons which will make it harder to maintain the application. imho both cases are exceptional (the developer should make sure that the user do not exist before calli...
{ "AcceptedAnswerId": "21303", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T15:32:04.480", "Id": "21297", "Score": "3", "Tags": [ "c#", ".net" ], "Title": "New to TDD, am I doing everything right? How could I improve?" }
21297
<p>Ok, so I started to build my own CMS. You can see <a href="http://cms.golubovic.info" rel="nofollow" title="Aleksandar Golubovic's Blog">Aleksandar Golubovic's Blog</a>,and I need your help. Please, look at my code, and tell me is that safe? You can download current version from <a href="http://cms.golubovic.info/tb...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T15:49:45.303", "Id": "34170", "Score": "0", "body": "This site is for code review only. IE: You post a piece of code and a question concerning the posted code and we review it and offer help on what you should do. This is not a webs...
[ { "body": "<p>Well looking at this as a code review of the code you posted i can recommend a couple of things;</p>\n\n<h2>Security</h2>\n\n<p>The major flaw at the moment is the possibility for SQL injection. You put the $_GET values directly into the query without validation or escaping. </p>\n\n<p>PHP.net has...
{ "AcceptedAnswerId": "21310", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T15:44:47.760", "Id": "21301", "Score": "2", "Tags": [ "php" ], "Title": "Twitter Bootstrap CMS" }
21301
<p>I wanted to implemented an algorithm in Python 2.4 (so the odd construction for the conditional assignment) where given a list of ranges, the function returns another list with all ranges that overlap in the same entry.</p> <p>I would appreciate other options (more elegant or efficient) than the one I took. </p> <...
[]
[ { "body": "<p>Firstly, modify or return, don't do both. </p>\n\n<p>Your <code>process</code> method returns lists as well as modify them. Either you should construct a new list and return that, or modify the existing list and return nothing.</p>\n\n<p>Your <code>remove_overlap</code> function does the same thin...
{ "AcceptedAnswerId": "21309", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T17:04:46.913", "Id": "21307", "Score": "9", "Tags": [ "python", "performance", "algorithm", "python-2.x", "interval" ], "Title": "Consolidate list of ranges that overla...
21307
<p>As the title says, I'm looking for a better way of writing the following PHP function as it's a very very long one. It's part of a bigger class and I'm trying to keep the amount of code as little as possible. </p> <p>The reason why I needed so many cases is because the function can accept all kinds of arguments in ...
[]
[ { "body": "<p>If there's anything in this answer - concepts, words, principles, etc. - that you find confusing, please don't hesitate to ask for a clarification.</p>\n\n<blockquote>\n <p>It might not make any sense just by looking at it</p>\n</blockquote>\n\n<p>It's good that you can detect and acknowledge thi...
{ "AcceptedAnswerId": "21320", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T17:11:04.710", "Id": "21308", "Score": "1", "Tags": [ "php" ], "Title": "A better way of writing a PHP function" }
21308
<p>My task was:</p> <p>Write a function that takes three arguments: a character and two integers. The character is to be printed. The first integer specifies the number of times that the character is to be printed on a line, and the second integer specifies the number of lines that are to be printed. Write a program t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T05:09:29.417", "Id": "34208", "Score": "1", "body": "`printf(\"%c\", ch);` have you considered `putchar(ch);`?" } ]
[ { "body": "<p>Only a couple of things:</p>\n\n<ul>\n<li><p><code>int lines,times;</code> - one declaration per line, please!</p></li>\n<li><p><code>scanf(\"%c%d%d\", &amp;userChar, &amp;times, &amp;lines)</code> - where does one number end and the next start?. You need to include some terminating characters, su...
{ "AcceptedAnswerId": "21313", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T19:53:28.327", "Id": "21311", "Score": "1", "Tags": [ "c" ], "Title": "A function to print a character number of times and in number of lines" }
21311
<p>I am a newcomer to design patterns. I read some articles about the <a href="https://en.wikipedia.org/wiki/Abstract_factory" rel="nofollow">abstract factory</a> pattern, and wrote the following simple example:</p> <pre><code>public interface ParserFactory { List&lt;ITransport&gt; getBusList(); List&lt;ITranspo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T13:19:36.140", "Id": "34225", "Score": "0", "body": "\"Abstract Factory\" is not a pattern but an abomination. I'd strongly recommend to look at Dependency Injection instead (using Guice, Spring, CDI...), which solves the same probl...
[ { "body": "<p>This isn't really an Abstract Factory. Going on the theme of what you've got above (although I'm not sure what trains, planes and buses have to do with parsing!), an Abstract Factory would look something like the following:</p>\n\n<pre><code>public interface Parser\n{\n List&lt;ITransport&gt; g...
{ "AcceptedAnswerId": "21325", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T20:56:37.773", "Id": "21314", "Score": "2", "Tags": [ "java", "design-patterns" ], "Title": "Using AbstractFactory" }
21314
<p>I'm writing a WPF application and I have several <code>ReadOnlyObservableCollection</code> fields in my models.</p> <p>Suppose that I wanted to create a <code>FooViewModel</code> instance for each <code>FooModel</code> instance. <code>FooModel</code> has an observable collection of <code>BarModel</code>, and <code>...
[]
[ { "body": "<p><strong>Raising Events</strong> </p>\n\n<p>The default pattern for rasing events is to create a <code>protected void OnNameOfTheEvent(EventArguments)</code> method (without the sender parameter). Like </p>\n\n<pre><code>protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArg...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T22:09:24.313", "Id": "21317", "Score": "6", "Tags": [ "c#" ], "Title": "Mapping ReadOnlyObservableCollection to another collection" }
21317
<p>You can see the JavaScript at the end of this post in action <a href="http://andrew-oh.com/portfolio/timeline/" rel="nofollow">here</a>.</p> <p>I've recently picked up JavaScript/jQuery and would love some feedback on how I'm implementing this functionality. As you can see, the <code>li</code> items in the navbar c...
[]
[ { "body": "<blockquote>\n <p>Is there anything else I should do to improve my JS/Jquery skills?</p>\n</blockquote>\n\n<p><strong>Self-invoking Anonymous Function</strong></p>\n\n<pre><code>(function ( $, window, undefined ) {\n doStuff();\n})( jQuery, window );\n</code></pre>\n\n<p>The extra <code>()</code>...
{ "AcceptedAnswerId": "21433", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T00:38:49.167", "Id": "21323", "Score": "4", "Tags": [ "javascript", "jquery", "performance", "beginner", "html" ], "Title": "Highlighting a nav list item based on the u...
21323
<p>I've been experimenting with the Express Node.js framework. On the face of it, the approach of passing functions to <code>app.VERB</code> methods seems unusual. In other frameworks I've used (in languages other than javascript), you create a single handler class for each url pattern, with methods representing differ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-09T16:26:39.043", "Id": "75900", "Score": "0", "body": "You might want to take a look at express.js version 4. There is a function called `route` in the router. http://expressjs.com/4x/api.html#router.route" } ]
[ { "body": "<p>This looks good to me,</p>\n\n<ul>\n<li>As you mentioned, <code>as_view</code> stands out a bit, but I see where you are coming from</li>\n<li>I am not sure why you do not declare <code>GET</code> and <code>POST</code>, then you do not need to use <code>toLowerCase()</code>, are you worried the ca...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T01:02:43.160", "Id": "21324", "Score": "3", "Tags": [ "javascript", "node.js" ], "Title": "Node.js object-oriented controllers" }
21324
<p>I need to get from an array of booleans to a Flags enum.</p> <p>Here's what my enum looks like:</p> <pre><code>[Flags] public enum UserContactPreferences { None = 0, SMS = 1, Email = 2, Phone = 4 } </code></pre> <p>Here's what my parsing code looks like currently.</p> <pre><code>private UserContactPreferences Ge...
[]
[ { "body": "<p>Well, you need some sort of mapping between the parameters and the <code>enum</code> values, so you can't actually avoid having three almost same pieces of code. But you can make your code shorter by using <code>if</code>s and <code>|=</code> instead of ternary operators:</p>\n\n<pre><code>private...
{ "AcceptedAnswerId": "21332", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T09:27:58.387", "Id": "21331", "Score": "4", "Tags": [ "c#", "enum" ], "Title": "Parse Flags enum from array of booleans" }
21331
<p>Im currently working on a system that will communicate with other systems via webservice (or some sort of communication). I have a system that stores all user data already and don't want to duplicate data in this new system so I have come up with a way of accessing the data when needed. </p> <p>In my current system...
[]
[ { "body": "<p>As a matter of opinion without knowing exactly what you would like to achieve, I can see some potential issues.</p>\n<ul>\n<li><p>Name doesn't need a set option (except if you are populating back to the source which is not shown here), otherwise it would just cause confusion.</p>\n</li>\n<li><p>Yo...
{ "AcceptedAnswerId": "21370", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T11:37:43.597", "Id": "21334", "Score": "1", "Tags": [ "c#", "design-patterns" ], "Title": "Populating a class whose data is stored in an external application" }
21334
<p>I needed a task scheduler that could be used somehow like this:</p> <pre><code>#include &lt;iostream&gt; // To compile and run this example, include here the code listed in the second code block void Task2() { std::cout &lt;&lt; "OK2 ! now is " &lt;&lt; std::chrono::system_clock::now().time_since_epoch().co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-05-21T19:02:27.367", "Id": "241230", "Score": "1", "body": "A few notes:\n*(1) You can use std::thread directly (no pointer), especially since your class is not copyable. *(2) std::function allows to capture context, that can potentially ...
[ { "body": "<p>So a couple of minor issues first:</p>\n<pre><code>void main()\n</code></pre>\n<p>Argh, bad. Someone who can write this should know better!</p>\n<p>There's a problem with your <code>ScheduleAt</code> function. You're passing in an rvalue reference to time, and trying to bind this to a non-const lv...
{ "AcceptedAnswerId": "21378", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T12:39:44.577", "Id": "21336", "Score": "20", "Tags": [ "c++", "c++11", "scheduled-tasks" ], "Title": "C++ Task Scheduler" }
21336
<p>I implemented this Agent class for a project recently and was wondering if I could get some other eyes to look at it -- I'm currently the only developer where I work so I can't exactly ask someone here to do it.</p> <p>I'm pretty sure it's correct, but then I'm too close to it.</p> <pre><code>public abstract class...
[]
[ { "body": "<p>Few minor points:</p>\n\n<ul>\n<li>Generic type parameter should be called <code>&lt;T&gt;</code> as per <a href=\"http://msdn.microsoft.com/en-us/library/aa479858.aspx#bestpractices_topic2\" rel=\"nofollow\">convention</a>.</li>\n<li><code>public</code> constructors in <code>abstract</code> class...
{ "AcceptedAnswerId": "23243", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T14:25:09.737", "Id": "21337", "Score": "4", "Tags": [ "c#", "thread-safety", "actor" ], "Title": "Is this Agent/Actor implementation issue free?" }
21337
<p>Posted my question <a href="https://stackoverflow.com/questions/14710039/vbscript-poker-game-what-hand-do-i-have">here</a>.</p> <p>Here is the full code:</p> <pre><code>'buy a blank deck of cards 'declare variables dim defaultDeck(51) dim trueDeck(51) dim isUsed(51) numPlayers = 1 numCards = 12 intMyHand = 0 '0 t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T14:29:12.700", "Id": "34396", "Score": "0", "body": "As fun as this was, I'm switching to Python." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-18T22:20:49.717", "Id": "57873", "Score": "0", ...
[ { "body": "<p>You're creating your cards with a nested <code>For</code> loop; one over <code>suit</code>, another over <code>faceValue</code> - I'd do the same (or quite similar). However I'm not buying the <code>Select Case</code> part:</p>\n\n<pre><code>for suit=0 to 3\n for faceValue=0 to 12\n sele...
{ "AcceptedAnswerId": "37185", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T14:39:41.030", "Id": "21338", "Score": "5", "Tags": [ "playing-cards", "vbscript" ], "Title": "How to tell the NPC what hand it has?" }
21338
<p>I my class hierarchy looks like this:</p> <ul> <li><code>P</code></li> <li><code>I : P</code></li> <li><code>O : P</code></li> </ul> <p>I have this method. The goal of this method is to return a new object of type <code>I</code> or <code>O</code> depending on a certain condition. </p> <pre><code> public P GetP() ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T16:12:16.963", "Id": "34240", "Score": "1", "body": "Is this something that could fall under a [factory pattern](http://en.wikipedia.org/wiki/Factory_method_pattern)? Change the factory based on the value of `pDetail.Code`, then cal...
[ { "body": "<ol>\n<li><p>I think it would be better if <code>Session.Begin()</code> returned an <code>IDisposable</code>, which would call <code>Session.Close()</code> in its <code>Dispose()</code>. That way, you can enclose the whole method inside <code>using</code> and you don't have to worry about calling it ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T15:55:35.897", "Id": "21342", "Score": "6", "Tags": [ "c#" ], "Title": "Need help with my code using a base class?" }
21342
<p>I'm trying to make a sprite cache for SFML sprites. The basic idea I got was to use a map of an <code>enum</code> and a sprite pointer. Then when I would ask for a certain sprite I'd have a manager that would check if the pointer for that sprite is null. If it is, then it would create a new sprite object and clip it...
[]
[ { "body": "<p>The code looks good, and your question is well written: thanks.</p>\n\n<ol>\n<li><p>I would call the <code>Sprites</code> enum <code>SpriteId</code> since at any given point it only store one sprite id.</p></li>\n<li><p>Returning a pointer could be quite problematic here: as you say, if SpriteMana...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T16:52:22.540", "Id": "21345", "Score": "3", "Tags": [ "c++", "cache", "sfml" ], "Title": "Sprite cache for SFML sprites" }
21345
<p>Checklist from FAQ for proper posting.</p> <pre><code>Does my question contain code? - YES Did I write that code? - YES Is it actual code from a project rather than pseudo-code or example code? - Strait from actual code, minus a few functions that do not apply to the Q To the best of my knowledge, does th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T22:40:12.710", "Id": "34262", "Score": "0", "body": "Please define 'reliably set', as it's probably setting the copied value _eventually_. Your first major problem is that you're limited by the fact that you're using a global varia...
[ { "body": "<p>This code is quite confusing. Do you know about parallel threads mechanisms?</p>\n\n<pre><code>CLUtilCompact.waitForMe = true;\nset.start();\n</code></pre>\n\n<p>A new thread is started now and executes the run method from the interface. It is not defined when the thread is run, how fast and when ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T19:43:53.737", "Id": "21348", "Score": "1", "Tags": [ "java" ], "Title": "Reliably setting the system clipboard in a spawned thread and having the spawner wait" }
21348
<p>I did this program and I need to make sure I did it right. The answers come out to be right but I want to make sure nothing is wrong with the coding.</p> <pre><code>class RecursiveMethods { RecursiveMethods() //default constructor { } public int fOf(int x) { if (x &lt;= 10) ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T20:18:03.650", "Id": "34256", "Score": "2", "body": "Could you add an explanation of what is the code supposed to do?" } ]
[ { "body": "<p>It is fine. The code could use the following improvements:</p>\n\n<ul>\n<li>some additional comments, to describe in particular what the recursive function does. Recursive functions are by nature harder to read.</li>\n<li>\"fOf\" is not a particularly good method name. Try to use longer, explicit ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T19:48:48.197", "Id": "21349", "Score": "1", "Tags": [ "java", "recursion" ], "Title": "Recursively printing equations" }
21349
<p>I just started Java programming yesterday (so don't expect too much), and I've written some code. My code works the way I want it to work, but there are obviously things wrong with it.</p> <p>I was wondering how it could be improved. I think I've added unnecessary things. I'm practicing using classes and other stuf...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T20:54:08.560", "Id": "34258", "Score": "0", "body": "You've added a \"Performance\" tag. Is the program too slow for you? Just how fast do you need it to be?" } ]
[ { "body": "<h3>Styling:</h3>\n\n<p>You have to fix the case of your identifiers to be more idiomatic. It means:</p>\n\n<ul>\n<li>Class names should be Capitalized (\"Testing\", \"Funcs\", ...)</li>\n<li>Class members and variables should use camel case (\"firstName\", \"inputSn\", ...)</li>\n</ul>\n\n<p>Also:</...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T20:38:56.993", "Id": "21350", "Score": "5", "Tags": [ "java", "beginner" ], "Title": "Beginner's exercise to ask for first names and surnames" }
21350
<p>As a fairly new C# programmer I am a unsure about when and how to best make use of LINQ (and also when to choose the expression method syntax vs. the query syntax). This question often comes up for me at work, because I heavily lean toward making full use of new language features and a functional style, while my col...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T01:09:24.610", "Id": "34270", "Score": "0", "body": "Tomato solution #1 (s1) - tomatoes solution #2 (s2). S1 results in cleaner code and easier to spot logical errors in since it contains less \"manual code\". However, say that any ...
[ { "body": "<p>Some notes:</p>\n\n<ol>\n<li><p>I think the LINQ version would be more readable if you extracted a variable for the collection. Something like:</p>\n\n<pre><code>var serials = /* the whole LINQ query here */\n\nItems.Clear();\nItems.AddRange(serials);\n</code></pre></li>\n<li><p>The LINQ version m...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T00:42:12.450", "Id": "21359", "Score": "3", "Tags": [ "c#", "linq" ], "Title": "To LINQ or not to LINQ" }
21359
<p>I have some code that uses a multidimensional look-up table (LUT) to do interpolation. The typical application is a color space conversion, where 3D inputs (RGB) are converted to 4D (CMYK), but the code is rather general. The look-up table is a numpy array, which will generally have a shape like <code>(4, 17, 17, 17...
[]
[ { "body": "<p>Firstly, you could use some tests. Here are a few I cooked up:</p>\n\n<pre><code>assert_equals( process_lut_shape( (4, 17, 17, 17) ) , (0, 3, 4, 17) )\nassert_equals( process_lut_shape( (14, 16, 16) ) , (0, 2, 14, 16) )\nassert_raises( ValueError, process_lut_shape, (14, 15, 15) )\nassert_equals( ...
{ "AcceptedAnswerId": "21363", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T01:20:00.097", "Id": "21360", "Score": "1", "Tags": [ "python", "numpy" ], "Title": "Figuring out the structure of a shape tuple" }
21360
<p>I am looking for a memory efficient python script for the following script. The following script works well for smaller dimension but the dimension of the matrix is 5000X5000 in my actual calculation. Therefore, it takes very long time to finish it. Can anyone help me how can I do that?</p> <pre><code>def check(v1,...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T12:27:08.100", "Id": "34309", "Score": "0", "body": "\"... memory efficient ... very long time ...\" Do you want to optimize memory usage or runtime?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T18...
[ { "body": "<p>I noticed one of your issues is that you are calculating the same thing over and over again when it is possible to pre-calculate the values before looping. First of all:</p>\n<pre><code>x = sqrt(d0(m[i], m[i]))\n</code></pre>\n<p>and:</p>\n<pre><code>y = sqrt(d0(m[j], m[j]))\n</code></pre>\n<p>are...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T02:19:53.197", "Id": "21362", "Score": "1", "Tags": [ "python" ], "Title": "Looking for efficient python program for this following python script" }
21362
<p>Here's my attempt at Project Euler Problem #5, which is looking quite clumsy when seen the first time. Is there any better way to solve this? Or any built-in library that already does some part of the problem?</p> <pre><code>''' Problem 5: 2520 is the smallest number that can be divided by each of the numb...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T12:07:04.760", "Id": "34279", "Score": "0", "body": "I think you can adapt [Erathosthenes' prime sieve](http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) to compute is_prime plus the amount of factors in one go." } ]
[ { "body": "<p>You are recomputing the list of prime numbers for each iteration. Do it just once and reuse it. There are also better ways of computing them other than trial division, the <a href=\"http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes\" rel=\"nofollow\">sieve of Eratosthenes</a> is very simple yet e...
{ "AcceptedAnswerId": "21375", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T10:09:49.247", "Id": "21367", "Score": "5", "Tags": [ "python", "project-euler", "primes" ], "Title": "Any better way to solve Project Euler Problem #5?" }
21367
<p>I am having a few issues about a session class that I found after reading it a lots of times,</p> <p><strong>Here is the class :</strong></p> <pre><code>class SessionManager{ static function sessionStart($name, $limit = 0, $path = '/', $domain = null, $secure = null) { $https = isset($secure) ? $secure : isset($_S...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T12:13:14.833", "Id": "34280", "Score": "0", "body": "Someone please?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T12:21:44.943", "Id": "34308", "Score": "0", "body": "Please add a link ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T10:21:00.670", "Id": "21368", "Score": "1", "Tags": [ "php", "security", "session" ], "Title": "Few concerns about specific session class" }
21368
<p>OK, I've been playing with D for a while (and been <em>in love</em> with its expressive power and simplicity, to be honest). However, since I'm still new to D, I'm facing a few issues.</p> <p>Let's take the following example. All the following program does is to take numbers in the 0..10000000 (fairly big one, for ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T08:34:06.507", "Id": "34281", "Score": "3", "body": "What further optimisations? What about... `-O3`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T08:34:45.197", "Id": "34282", "Score": "3"...
[ { "body": "<p>How about: using <code>res.length = 64;</code> and then in your loop replace </p>\n\n<pre><code>res ~= cast(int)log2(bitboard &amp; ~(bitboard-1));\n</code></pre>\n\n<p>by:</p>\n\n<pre><code>res[n] = cast(int)log2(bitboard &amp; ~(bitboard-1));\n</code></pre>\n\n<p>But to be honest this type of co...
{ "AcceptedAnswerId": "21372", "CommentCount": "24", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T08:30:01.563", "Id": "21371", "Score": "10", "Tags": [ "c++", "optimization", "d" ], "Title": "C++ vs D - Algorithm Optimization/Conversion (Using vectors/arrays)" }
21371
<p>I've written a program that calculates the best rational approximation for e with a 1, 2, 3, 4, 5, and 6 digit denominator respectively (on Matlab). For a 5-digit denominator it takes about a minute. For a 6-digit denominator it takes 2 hours. I've tried to improve the code, but I am a beginner. Suggestions are kind...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T16:39:51.360", "Id": "34321", "Score": "1", "body": "I think this question may be better off at codereview or math. Two pointers: working with strings is usually quite slow, and it can be a lot faster if you think more about the pro...
[ { "body": "<p>In the evening I thought a bit about the question, and though it is a bit more radical than giving pointers on the code, I have created an example on how to approach this problem the matlab way.</p>\n\n<p>Judging from your code the value of <code>e</code> can be considered known. With this I have ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-05T16:30:36.957", "Id": "21379", "Score": "3", "Tags": [ "matlab" ], "Title": "Rational Approximation for e with Matlab" }
21379
<p>I have a situation where I would like to use a single <code>QThread</code> to run two (or more) separate methods at different times. For example, I would like the <code>QThread</code>to run <code>play()</code> sometimes, and when I am done playing, I want to disconnect the <code>QThread.started()</code> signal from ...
[]
[ { "body": "<p>Use a Queue, python has a threadsafe Queue class.</p>\n\n<p>Push the function you want to run on the background thread onto the queue.</p>\n\n<p>Have the thread wait on the queue executing functions as they are put into it.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", ...
{ "AcceptedAnswerId": "21385", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T15:51:06.187", "Id": "21382", "Score": "1", "Tags": [ "python", "multithreading", "pyqt" ], "Title": "Alternative to using sleep() to avoid a race condition in PyQt" }
21382
<p>I'm writing a program which takes individual int inputs from the user and then outputs some details on the numbers (average, min, max and how many). <code>Input.readInt()</code> is a method I made which simply reads an integer from the command line and returns it.</p> <p>There are a few things I'd like to improve -...
[]
[ { "body": "<p>Please tell me this is for your personal benefit and that you aren't asking me to do your homework!</p>\n\n<pre><code>average = total / count;\n</code></pre>\n\n<p><code>total</code> and <code>count</code> are both integers, so <code>/</code> performs integer division. The result is then converte...
{ "AcceptedAnswerId": "21388", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T15:59:43.003", "Id": "21383", "Score": "4", "Tags": [ "java", "array", "statistics" ], "Title": "Calculating and displaying number statistics" }
21383
<p>I do a single select in one radgrid, and based upon that selection I want to select multiple rows in a different radgrid:</p> <pre><code>&lt;telerik:RadGrid ID="rgPaymentLines"&gt; &lt;ClientEvents OnRowSelected="RowPaymentSelected"/&gt; ... &lt;/telerik:RadGrid&gt; &lt;telerik:RadCodeBlock ID="RadCodeBlock1" runa...
[]
[ { "body": "<p>welcome to Code Review and thank you for your question. You need to profile the code to see for yourself where it is slow. Firebug and Chrome can do this. Only then will you be able to optimize your code.</p>\n\n<p>Side note: Be careful about variable names, some of them seem to be in French (doss...
{ "AcceptedAnswerId": "22787", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T16:16:51.907", "Id": "21384", "Score": "4", "Tags": [ "javascript", "jquery", "optimization" ], "Title": "Looping through Radgrid in JS is slow, can this be faster?" }
21384
<p>I am working on a way to quickly build JSON strings in Java. To this end, I have created the following two files. Assuming that I do not need to parse JSON strings for Java, is this an efficient implementation? Furthermore, are there any cases where it would output an invalid JSON string?</p> <p><strong>JSONList.ja...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T18:02:49.483", "Id": "34327", "Score": "1", "body": "Is there a reason you are not using an existing library to do this? For instance [Gson](http://code.google.com/p/google-gson/)." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>First of all, <code>this.items</code> is redundant in most cases - just <code>items</code> would be enough.</p>\n\n<hr>\n\n<pre><code>if(value != null)\n{\n this.items.add(value);\n}\nelse\n{\n throw new IllegalArgumentException(\"Value must be JSON, was \" + (value == null ? \"null\" : valu...
{ "AcceptedAnswerId": "21393", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T17:57:21.790", "Id": "21387", "Score": "1", "Tags": [ "java", "json" ], "Title": "Simple JSON writer" }
21387
<p>I have the following code, but it somehow looks a bit redundant. As I am new to ColdFusion, I am not sure how to optimize it. Can someone suggest an alternative?</p> <pre><code>&lt;cfparam name="url.idInfopage" default="0"&gt; &lt;cfif not isNumeric(url.idInfopage)&gt;&lt;cfset url.idInfopage= 0&gt;&lt;/cfif&gt; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T16:20:37.063", "Id": "34331", "Score": "1", "body": "What version of CF are you running?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T16:21:31.027", "Id": "34332", "Score": "0", "body":...
[ { "body": "<p>You could re-write it something like this:</p>\n\n<pre><code>&lt;cfif StructKeyExists(stElement,'idInfoPage') AND isNumeric(stElement.idInfopage)&gt;\n &lt;cfset idInfopage = stElement.idInfopage /&gt;\n\n&lt;cfelseif StructKeyExists(Url,'idInfoPage') AND isNumeric(Url.idInfopage)&gt;\n &lt;...
{ "AcceptedAnswerId": "21390", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-04T16:13:07.703", "Id": "21389", "Score": "3", "Tags": [ "performance", "beginner", "url", "coldfusion", "cfml" ], "Title": "Setting a page number from the URL, with fallb...
21389
<p>I have created this simple code:</p> <blockquote> <p>For the size of an array with 2 values (<code>n</code> and <code>m</code>), verify if <code>n</code> and <code>m</code> are >= 1. <code>m</code> = width and <code>n</code> = height.</p> </blockquote> <p>The code works but I'm sure it isn't optimized.</p> <pre...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T19:51:47.750", "Id": "34336", "Score": "0", "body": "The big question is not whether it is optimized. The big question is \"Does it matter\"? Do you find it too slow? How fast would you like it to be?" }, { "ContentLicense":...
[ { "body": "<p>You should provide a compiling code. I'll assume that <code>n</code> and <code>m</code> are <code>int</code>, but you should have added their declaration.</p>\n\n<ul>\n<li>You should use explicit names for variables. <code>n</code> is a line count, so call it <code>line_count</code>. <code>m</code...
{ "AcceptedAnswerId": "21395", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T19:38:47.037", "Id": "21392", "Score": "1", "Tags": [ "c", "validation", "io" ], "Title": "Verifying column and line counts" }
21392
<p>This is the first time I've written JavaScript in this way (previously all I've done mostly is DOM manipulation and form validation in vanilla and jQuery).</p> <p>I've begun working on a basic Pong game. It's currently unfinished, but before I continue, I'd like to get some feedback from experienced JS developers:<...
[]
[ { "body": "<p>I don't see anything wrong with your code as it stands but there are at least two things you may need to think about as it develops:</p>\n\n<ol>\n<li><p>can objects drawn on the canvas interfere with each other, and if so, how can the programme deal with that?</p></li>\n<li><p>are you likely to wa...
{ "AcceptedAnswerId": "21518", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T22:25:52.217", "Id": "21398", "Score": "5", "Tags": [ "javascript", "game", "html5", "canvas" ], "Title": "JavaScript/Canvas Pong game" }
21398
<p>This is my first attempt at reading the contents of a file consisting of strings separated by a null character.</p> <pre><code>vector&lt;string&gt; CReadFileTest::ReadFile( const char * filename ) { ifstream ifs(filename, ifstream::in); if (ifs) { vector&lt;string&gt; list ; while (ifs....
[]
[ { "body": "<p>A couple of issues:</p>\n\n<pre><code>while (ifs.good())\n</code></pre>\n\n<p>Don't loop on <code>good()</code> (or <code>eof()</code>). This is one of the more annoying parts of the C++ <code>iostream</code> library. This should be:</p>\n\n<pre><code>while(std::getline(ifs, s, '\\0'))\n</code></p...
{ "AcceptedAnswerId": "21403", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-06T23:34:47.330", "Id": "21400", "Score": "4", "Tags": [ "c++", "file", "stream", "vectors" ], "Title": "Reading contents of a file consisting of strings separated by a null c...
21400
<p>I started taking a look at a programming challenge I had read about earlier today on <a href="http://webcache.googleusercontent.com/search?q=cache%3aAb2gQz9h2zMJ%3ablog.8thlight.com/eric-koslow/archive.html%20&amp;cd=5&amp;hl=en&amp;ct=clnk&amp;gl=us" rel="nofollow">8thlight</a>. Unfortunately, it seems to have been...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T11:18:01.963", "Id": "34363", "Score": "3", "body": "If you want us to review the tests, you should include those too." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T15:01:43.407", "Id": "34402",...
[ { "body": "<p>A couple of very simple tests that would fail would be to call your method with a parameter of <code>null</code> or <code>new int[0]</code>. Also, I'm not a big fan of using arrays so I did a tiny bit of rework on it to use a simple enumerable as well as guard against those edge cases.</p>\n\n<p><...
{ "AcceptedAnswerId": "21429", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T03:17:14.557", "Id": "21405", "Score": "5", "Tags": [ "c#", "algorithm", "unit-testing", "tdd" ], "Title": "Maximum Sub-array Problem" }
21405
<p>I'm looking for a general review of a generalized linear interpolation table. Design decisions, anything that's missing, anything that could be clearer or simplified, any style considerations. Keep in mind that I've tried to keep this C++03 compatible, so no recommendations for using C++11 features please.</p> <p><...
[]
[ { "body": "<pre><code>//Lower constraint; upper_bound is less than the\n//min table value\n</code></pre>\n\n<p>You probably mean \"upper_bound is the min table value\". This also applies to the next comment.</p>\n\n<pre><code> //Higher constraint check; upper bound (may)\n //be greater than max table valu...
{ "AcceptedAnswerId": "21418", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T05:26:01.383", "Id": "21407", "Score": "2", "Tags": [ "c++", "lookup", "c++03" ], "Title": "Standard library-like linear interpolation table" }
21407
<p>I am writing a program which calculates the scores for participants of a small "Football Score Prediction" game.</p> <p>Rules are:</p> <ol> <li>if the match result(win/loss/draw) is predicted correctly: 1 point</li> <li>if the match score is predicted correctly(exact score): 3 points (and +1 point because 1st rule...
[]
[ { "body": "<p>I'd change something in the style of your application in order to decrease the coupling.</p>\n\n<p>Why do you use global variables?\nI'd change the design to have the following functions:</p>\n\n<ul>\n<li><code>takeFixtures(fileName)</code> returning the fixtures;</li>\n<li><code>takePredictions(n...
{ "AcceptedAnswerId": "21416", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T05:51:57.967", "Id": "21408", "Score": "4", "Tags": [ "python", "optimization", "game" ], "Title": "Calculating scores for predictions of football scores" }
21408
<p>I need some advice off the back of a question I posted on StackOverflow. I'm a procedural PHP programmer and I'm looking to make the move into object oriented PHP. I have started a small project that basically acts as a small CMS that allows me to separate my website content from the actual structure of the page. Th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T09:47:13.243", "Id": "34351", "Score": "0", "body": "possible duplicate of [Object Orientated PHP, what's wrong with this setup?](http://codereview.stackexchange.com/questions/21413/object-orientated-php-whats-wrong-with-this-setup)...
[ { "body": "<p>What I see at first glance.</p>\n\n<p><code>Page</code> and <code>Connection</code> are extending <code>Mysqli</code></p>\n\n<p>Why is a Page a special Mysqli? (Page extends Mysqli)</p>\n\n<p>Why is a Connection a special Mysqli? (Connection extends Mysqli)</p>\n\n<p>A page can use a Mysqli to sav...
{ "AcceptedAnswerId": "21415", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T09:24:45.540", "Id": "21414", "Score": "0", "Tags": [ "php", "object-oriented" ], "Title": "Object Orientated PHP, what's wrong with this implementation of OOPHP and how might it b...
21414
<p>I am creating an application which will be testable(unit + integration). In this application I have a FileHelper static class,</p> <pre><code>public static class FileHelper { public static void ExtractZipFile(Stream zipStream, string location) { .................................. } public s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T11:40:39.180", "Id": "34368", "Score": "1", "body": "Why would you want this class to be static at all? If you want testable code, avoid them. I'd change the API slightly. so you use Zip = new Zip('file.zip'); Zip.extractTo('/path/)...
[ { "body": "<p>If you want to write tests for this helper class only - they would be <em>integration tests</em> since they touch the file system. </p>\n\n<p>In order to make the code <em>unit testable</em> you need to make it independent from hardware and physical interaction with network or disk.</p>\n\n<p>If y...
{ "AcceptedAnswerId": "21419", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T10:28:08.167", "Id": "21417", "Score": "5", "Tags": [ "c#", "unit-testing", "static" ], "Title": "How to make static methods testable?" }
21417
<p>I was hoping someone could give me some feedback on my code. I am still new to php and I'm sure I have messed up somewhere. The code pasted is for a registration page where users will submit their information which will then be posted to the database.</p> <pre><code>&lt;?php&gt; include 'PasswordHash.php'; $sql =...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T14:00:27.243", "Id": "34394", "Score": "0", "body": "`<?php>` is wrong. It should be just `<?php`." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T14:31:32.673", "Id": "34397", "Score": "0", ...
[ { "body": "<p>Well, here are my notes from looking through the code:</p>\n\n<ol>\n<li><p>You create a connection to the database, and include <code>PasswordHash.php</code>, when it is not yet needed. Database connections are not \"free of charge\" and should be used conservatively.</p></li>\n<li><p>You use two ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T12:51:56.853", "Id": "21420", "Score": "2", "Tags": [ "php", "mysql", "mysqli" ], "Title": "Could really use some feedback on this registration code in php" }
21420
<p>I am trying to create a multiway tree with the following code in C++. As of now, it is more like a sample piece of code.</p> <p>I wish to do the following with this piece of code(and I am able to get the desired result):</p> <ol> <li>Create a struct Node of two members : value(of the node) and array of children of...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T01:22:48.550", "Id": "34375", "Score": "0", "body": "I've fixed the indentation on this code. There was some non-standard indentation that could confuse readers." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2...
[ { "body": "<p>This is correct enough. </p>\n\n<p>You could improve it in a couple of ways,</p>\n\n<ul>\n<li>if you do <code>new Node()</code>, note the additional <code>()</code>, <a href=\"https://stackoverflow.com/a/620402/1520364\">its members will be zero initialized</a>, so you can skip the <code>null</cod...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T01:11:04.943", "Id": "21421", "Score": "2", "Tags": [ "c++" ], "Title": "Making grandchild of root null , the right way in C++" }
21421
<p>I have made a function which calculates the index of a point to which an arbitrary point on a polygon made of XY points belong.</p> <p>This is a visual representation:</p> <p><img src="https://i.stack.imgur.com/d13dZ.png" alt="enter image description here"></p> <p>And this is the function I made:</p> <pre><code>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T14:32:47.727", "Id": "34398", "Score": "2", "body": "I personally don't understand the explanation. Why 3 in the first red circle for example?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T16:15:52....
[ { "body": "<p>First, I do not know anything about PAWN.</p>\n\n<p>Does it have a profiler? Can any profiler be used? If yes, probably use it.<br>\nIf no, write at least some test units to measure execution time.</p>\n\n<p>I will assume typical language elements. I will assume <code>polygonid &gt; 0</code> and <...
{ "AcceptedAnswerId": "21449", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T13:03:24.067", "Id": "21424", "Score": "1", "Tags": [ "optimization", "computational-geometry", "pawn" ], "Title": "Optimizing mathematical index calculation function" }
21424
<p>My overall challenge and why this code was written was to compare two strings. One string being a description of a item in inventory and one string being a description of a item, but possibly truncated/missing some characters. I am trying to match up the items I have posted on Craigslist and the items I think I have...
[]
[ { "body": "<p>It sounds from your problem description that the strings can only differ if one is a substring of the other. Maybe even the one will only be truncated at the end? When I look at your code I see that CraigsList may add hyphens and spaces. I think this is a much simpler problem than the more gene...
{ "AcceptedAnswerId": "21439", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-02-07T13:39:23.613", "Id": "21425", "Score": "3", "Tags": [ "java", "performance", "edit-distance" ], "Title": "Using Levenshtein distance to compare strings" }
21425
<p>I'm new to Lisp and I'm yet to wrap my head around the lisp way of writing programs. Any comments regarding approach, style, missed opportunities appreciated:</p> <p><em>In particular</em>, please advice if I build results list correctly (<code>(setf merged-list (append merged-list (list a)))</code>).</p> <pre><co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T16:26:39.737", "Id": "34416", "Score": "0", "body": "@RTOSkit, As I said, I need advice on how to make my lisp better. The program does what it needs to do, however there is certainly ways to make it more concise, efficient, elegant...
[ { "body": "<ol>\n<li><p>Use <a href=\"http://www.lispworks.com/documentation/HyperSpec/Body/f_nconc.htm\" rel=\"nofollow\"><code>nconc</code></a> instead of <code>append</code> for speed in</p>\n\n<p>(setf merged-list (append merged-list (list a)))</p>\n\n<p>Note that you need <code>setf</code> with <code>nconc...
{ "AcceptedAnswerId": "21438", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T15:16:37.903", "Id": "21431", "Score": "4", "Tags": [ "beginner", "mergesort", "lisp", "common-lisp" ], "Title": "Mergesort with an inversion counter" }
21431
<p>I have a simple form validation script. Could you tell me how I can improve this script (mainly regarding security)?</p> <p><strong>HTML page</strong></p> <pre><code>&lt;form name="input_form" action="process_form.php" method="post"&gt; &lt;p&gt; &lt;label for="name"&gt;Name&lt;/label&gt; &lt;input ty...
[]
[ { "body": "<pre><code>${$key}\n</code></pre>\n\n<p>This makes me somewhat nervous, but I guess it's acceptable in this context since it's whitelisted.</p>\n\n<hr>\n\n<pre><code>foreach($check_empty_vars as $var_name)\n{\n if(${$var_name} == \"\") \n {\n $error .= ucfirst($var_name) . \" cannot ...
{ "AcceptedAnswerId": "21437", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T17:17:00.597", "Id": "21434", "Score": "1", "Tags": [ "php", "validation", "form" ], "Title": "Form validation script" }
21434
<p>I have this piece of code to replace current text inside an array of html divs with values coming from a JSON file:</p> <pre><code> $.each($('.something'), function(){ if($(this).text()=="1"){ $(this).html(jsondata.CameraTypeLabel1); }else if($(this).text()=="2"){ $(this)....
[]
[ { "body": "<p>jQuery's <a href=\"http://api.jquery.com/html/\" rel=\"nofollow\"><code>.html()</code></a> method can take a callback function - it'll be called for every element in the collection - and will use the returned value to set the element's html.</p>\n\n<p>You can use bracket notation to access the key...
{ "AcceptedAnswerId": "21444", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T19:33:10.363", "Id": "21440", "Score": "3", "Tags": [ "javascript", "jquery" ], "Title": "Replacing text in an array" }
21440
<p>I'm just trying to learn how to write jQuery better so I wanted some smart peoples opinions.</p> <p>The code is checking the billing and shipping address fields to see if it contains a PO Box address by looking for variations of "PO" and then displays a warning message after the input if it does contain it.</p> <p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T05:35:23.750", "Id": "34443", "Score": "0", "body": "Just so you know, there is a stack overflow question with a more complete PO box matching expression. It may help you out: http://stackoverflow.com/questions/5680050/po-box-regula...
[ { "body": "<p>There's 2 obvious places to clean this up a bit. The first is the duplicated keyup handler and the second is the check for PO.</p>\n\n<p>Most jQuery functions can be called on a collection of elements. Since you are calling the same code on both your shipping address and billing address, we can ...
{ "AcceptedAnswerId": "21448", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T21:26:11.450", "Id": "21445", "Score": "1", "Tags": [ "javascript", "jquery", "validation", "form", "e-commerce" ], "Title": "Checking address fields for presence of a ...
21445
<p>Suppose User and Item are two models, and User has many Item. Both models are derived from the parent Model class. In order to retrieve the list of all items a particular user has:</p> <pre><code> $user = new User(100); // User with ID = 100 $items = $user-&gt;getItems(); </code></pre> <p>Now suppose that ...
[]
[ { "body": "<p>I have the feeling that there is something wrong with your database structure. According your query, user will have exactly one item?</p>\n\n<p>If one user can have many items and the items belongs only to this user, your schema should look like:</p>\n\n<pre><code>User:\nID Name ...\n\nItem\nID Na...
{ "AcceptedAnswerId": "21456", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T04:47:33.563", "Id": "21450", "Score": "1", "Tags": [ "php", "mvc" ], "Title": "How to implement HasMany() relationship with PHP?" }
21450
<p>I am creating a simple template engine that uses Regex to find special expressions, which are parsed and processed. They are enclosed in Ruby-style opening tags and have the format:</p> <pre><code> &lt;% label %&gt; OR: &lt;% function(arg1, arg2, arg3) %&gt; </code></pre> <p>However the problem is that I c...
[]
[ { "body": "<p>Your current regex is too greedy.</p>\n\n<p>When running against your single line input, I get this result:</p>\n\n<pre><code>/^(.*)\\&lt;\\%\\s*(.+)\\s*\\%\\&gt;(.*)$/\n\n[0] =&gt; &lt;p&gt;&lt;% name %&gt; - &lt;% age %&gt; - &lt;% gender %&gt;&lt;/p&gt;\n[1] =&gt; &lt;p&gt;&lt;% name %&gt; - &l...
{ "AcceptedAnswerId": "21454", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T04:59:24.863", "Id": "21451", "Score": "1", "Tags": [ "php", "regex" ], "Title": "How to make this Regex more flexible?" }
21451
<p>I have two classes, Database and Logger. Database is responsible for handling SQL queries, and Logger logs messages to an external file. Whenever the database executes an SQL query, I want Logger to log it. Right now my implementation looks something like this:</p> <pre><code> class Database { public fun...
[]
[ { "body": "<p>There is nothing wrong with having the loggers everywhere. If you clutter all your classes with some kind of event notification it would look worst :)</p>\n\n<p><strong>But</strong>, Logger should not be called with a static method. You can create a pool of Loggers and your call will look like:</p...
{ "AcceptedAnswerId": "21458", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T05:11:42.560", "Id": "21452", "Score": "3", "Tags": [ "php", "design-patterns" ], "Title": "How to implement Publish-subscribe pattern in PHP?" }
21452
<p>I've started learning .NET with MVC 4 in C# and I built a basic application to display records from a MySQL database. It's incredibly basic, but it's the best I could come up with being a complete beginner to C# and all.</p> <p>Most of the programming I do is with Ruby on Rails and I tried to carry over some of the...
[]
[ { "body": "<h2>Dependency injection</h2>\n\n<p>Use dependency injection everywhere you can</p>\n\n<pre><code>public class AuthorsController : Controller\n{\n private readonly bookisticsEntities _booksEntities;\n\n public AuthorsController(bookisticsEntities entities)\n {\n _booksEntities = entit...
{ "AcceptedAnswerId": "21459", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T05:19:12.250", "Id": "21453", "Score": "1", "Tags": [ "c#", "asp.net", "asp.net-mvc-4" ], "Title": "Displaying records from a MySQL database" }
21453
<p>I have decided to create a <a href="https://github.com/Patryczek/OptionType/blob/master/OptionType/Option.cs" rel="nofollow">simple <code>Option</code> type for C#</a>. I have essentially based it on the <a href="https://github.com/scala/scala/blob/master/src/library/scala/Option.scala" rel="nofollow">Scala's <code>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T13:35:02.007", "Id": "34458", "Score": "1", "body": "Also, I think you should consider that C# already has idiomatic way to do this: `null` for reference types and `Nullable<T>` for value types. What's worse a variable of type `Opti...
[ { "body": "<p>What you have done is usually called a <a href=\"http://en.wikipedia.org/wiki/Monad_%28functional_programming%29#The_Maybe_monad\" rel=\"nofollow\"><strong>Maybe</strong> Monad</a>. There are several implementations of those for .NET (<a href=\"https://github.com/phlik/Monads.net/blob/master/Monad...
{ "AcceptedAnswerId": "21506", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T10:13:03.687", "Id": "21461", "Score": "6", "Tags": [ "c#", "functional-programming", "scala" ], "Title": "Option type in C# and implicit conversions" }
21461
<p>Is there a better way of creating this terminal animation without having a series of conditional statements (i.e. <code>if ... elif ... elif...)</code>?</p> <pre><code>import sys, time count = 100 i = 0 num = 0 def animation(): global num if num == 0: num += 1 return '[= ]' elif nu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T14:06:17.480", "Id": "34488", "Score": "0", "body": "I guess that a progress bar, shouldn't you write \\b 9 times?" } ]
[ { "body": "<p>You can build up the string like this:</p>\n\n<pre><code>def animation(counter, length):\n stage = counter % (length * 2 + 2)\n if stage &lt; length + 1:\n left_spaces = stage\n else:\n left_spaces = length * 2 - 1 - stage\n return '[' + ' ' * left_spaces + '=' + ' ' * (l...
{ "AcceptedAnswerId": "21464", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T11:13:04.773", "Id": "21462", "Score": "9", "Tags": [ "python" ], "Title": "Python terminal animation" }
21462
<p>I know i have some real problems with the following code (as others said). can you please help me to optimize it a little bit? Maybe some example of how to do it.</p> <p>(find the longest repeating substring with length between x and y)</p> <pre><code> public static String longestDuplicate(String text, int x, i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T11:29:42.337", "Id": "34449", "Score": "1", "body": "What do you want to optimize? The number of line breaks? What problems do you have?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T11:42:12.043", ...
[ { "body": "<p>You may want to roll your own comparison method to compare two pieces of a string in-place, instead of using substring(), which as I understand creates an unnecessary temporary copy. It may look like this:</p>\n\n<pre><code>bool CompareInPlace(String text, int from1, int len1, int from2, int len2)...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T11:17:12.310", "Id": "21463", "Score": "1", "Tags": [ "java", "optimization" ], "Title": "Optimizing code: longest repeating substring" }
21463
<p>For the sake of learning JavaScript better and getting used to the Google Chrome Extension API, I'm currently writing a little Chrome extension.</p> <p>To keep things simple and being able to make use of prototypal inheritance, I decided to write a little instantiation/inheritance helper before I get started.</p> ...
[]
[ { "body": "<blockquote>\n <p>Did I miss some important aspects regarding inheritance itself</p>\n</blockquote>\n\n<p>JavaScript uses prototypal inheritance, which is already quite simple. Here's an example:</p>\n\n<pre class=\"lang-js prettyprint-override\"><code>function Animal() {\n this.name = 'Animal';\...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T13:45:37.820", "Id": "21469", "Score": "4", "Tags": [ "javascript", "inheritance", "google-chrome" ], "Title": "Instantiation/Inheritance Helper" }
21469
<p>I'm trying to optimise my implementation of a static kd tree to perform orthogonal range searches in C++.</p> <p>My problem: The code performs slowly even for a small number of queries when the number of points is around 10<sup>5</sup>.</p> <p>I've constructed the tree based on <a href="http://en.wikipedia.org/wik...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T04:24:45.843", "Id": "34466", "Score": "0", "body": "That's a lot of code to have us look at. Might I consider using a profiler? http://www.cs.utah.edu/dept/old/texinfo/as/gprof_toc.html" }, { "ContentLicense": "CC BY-SA 3.0...
[ { "body": "<p>You could make the <code>return_subtree</code> function non-recursive by using a <code>stack</code> object by yourself:</p>\n\n<pre><code>void return_subtree(int node, vector&lt;T&gt; &amp;query_list)\n{\n if (node &gt; N) { return; }\n\n std::stack&lt;int&gt; st;\n st.push(node);\n\n ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T04:13:41.700", "Id": "21470", "Score": "5", "Tags": [ "c++", "optimization", "c++11", "tree", "interval" ], "Title": "Orthogonal range search for a static kd tree" }
21470
<p>Can anyone please tell which one is the more effective way to write C# code, among the two options below?</p> <p>Option A:</p> <pre><code>internal static string GetLast3Years() { return (DateTime.Now.Year - 2).ToString() + "," + (DateTime.Now.Year - 1).ToString() + "," + DateTime.Now.Year.ToString(); } </code>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T17:07:46.227", "Id": "34470", "Score": "0", "body": "Neither is particularly good..." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T17:08:04.793", "Id": "34471", "Score": "0", "body": "Op...
[ { "body": "<p>I will do it the following way</p>\n\n<pre><code> internal static string GetLast3Years()\n {\n int currentYear = DateTime.Now.Year; \n\n return String.Format(\"{0},{1},{2}\", currentYear - 2, currentYear - 1, currentYear);\n }\n</code></pre>\n", "comm...
{ "AcceptedAnswerId": null, "CommentCount": "12", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-07T17:02:48.287", "Id": "21472", "Score": "2", "Tags": [ "c#" ], "Title": "Should I use an intermediate variable in a complex C# expression?" }
21472
<p>I'd like to find a way to do what this method does in a cleaner, less hacky looking way </p> <pre><code> def self.create_from_person!(person) spi = new(:person =&gt; person, :provider =&gt; person.provider) spi.age_eligible_code = participant.age_eligible?(person) ? 1 : 2 spi.county_of_residence_code = ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T16:21:50.143", "Id": "34498", "Score": "0", "body": "where does `participant` come from?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T16:26:07.027", "Id": "34499", "Score": "0", "body":...
[ { "body": "<p>Notes:</p>\n\n<ul>\n<li>Any reason not to set the attributes in a single <code>create</code> step? </li>\n<li>DRY by using procs for short-lived functions.</li>\n<li>Methods should return meaningful values. Here it makes sense to return the newly created object.</li>\n<li>(As Mark pointed out) The...
{ "AcceptedAnswerId": "21479", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T14:45:11.067", "Id": "21475", "Score": "1", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "An abundance of ternary operators" }
21475
<p>I'm working on a javascript intensive user-interface application. (At least it's intensive for me, it's my first serious javascript project).</p> <p>I have a few jquery functions going whenever a div is rolled over or mouseout. For example there are some divs which are draggable objects, and so when they are mouseo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T13:44:38.413", "Id": "34560", "Score": "0", "body": "Can't help with the timing, but a small refactoring suggestion: replace the body of the first if with: $this.removeClass('activated').addClass('ready'). Depending on what you need...
[ { "body": "<p>Without actual code, we cannot review it if it actually contains significant issues. Thus, I've set forth guidelines instead.</p>\n<h1>Compression</h1>\n<p>The real help that compression does is actually speeding up loading times. Unless you are actually loading scripts on demand on mouseover, the...
{ "AcceptedAnswerId": "21513", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T16:12:43.463", "Id": "21480", "Score": "0", "Tags": [ "javascript", "jquery", "optimization", "user-interface" ], "Title": "Optimizing a jquery user interface application" ...
21480
<p>I'm currently changing some legacy code over to PDO. The below code works, but not 100%. I would like to know if it's best practice or if anything can be done better.</p> <pre><code>//Database Array $config['db'] = array( 'host' =&gt; 'localhost', 'username' =&gt; 'root', 'password' =&gt; 'root', ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-12T14:15:37.603", "Id": "34742", "Score": "0", "body": "Please declare cross-posting, to reduce duplication of effort (from [here](http://stackoverflow.com/q/14809804/472495)). Normally not declaring is a downvoteable offence, but I'll...
[ { "body": "<p>Here are a few things I noticed.</p>\n\n<ol>\n<li><p>If you are going to catch a possible exception when you connect to your MySQL DB you want to include the PDO instantiation in the try block.</p>\n\n<pre><code>try { \n $db = new PDO('mysql:host=' . $config['db']['host'] . ';dbname=' . $confi...
{ "AcceptedAnswerId": "21493", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T16:52:30.007", "Id": "21481", "Score": "0", "Tags": [ "php", "pdo" ], "Title": "PDO connection / prep and execute in their own functions" }
21481
<p>I've began to read the book <em>Clean Code</em> by Robert Martin. I've had a strong desire to learn how to write clear, easy-to-understand from other people. The <code>ColorViewer</code> application allows you to view the color in different formats.</p> <p><a href="https://github.com/SemenovLeonid/ColorViewer" re...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T03:08:41.033", "Id": "34535", "Score": "3", "body": "one thing that Uncle Bob was clear about in that book was Unit Tests... :) I don't see any on your GitHub site either :) as for the rest it isn't horrible. Since there is a bunch ...
[ { "body": "<p>I'm not an Android developer, so just some notes from a Java developer's perspective.</p>\n\n<ol>\n<li><pre><code>List&lt;String&gt; namesOfColorComponents = new ArrayList&lt;String&gt;(colorComponents.length);\nfor (String component : colorComponents) {\n namesOfColorComponents.add(component);...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T17:56:56.330", "Id": "21484", "Score": "6", "Tags": [ "java", "android" ], "Title": "ColorViewer mini-app for viewing colors in different formats" }
21484
<p>I just put together the skeletons for a priority queue using a binary heap in racket/scheme. Using racket/scheme is all about the educational experience and I was wondering if anyone wants to critique and improve the code. Bug reports are welcome</p> <pre><code>;; priority queues operations on integer values (def...
[]
[ { "body": "<p>Here are some general points before I start on more specific points:</p>\n\n<ul>\n<li>I don't see any unit tests. Racket programmers often write many unit tests for each function. You can use the <a href=\"http://docs.racket-lang.org/guide/Module_Syntax.html\"><code>module+</code></a> construct an...
{ "AcceptedAnswerId": "23549", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T19:16:46.093", "Id": "21485", "Score": "6", "Tags": [ "algorithm", "scheme", "racket" ], "Title": "Improving a priority queue sketch in Racket/Scheme" }
21485
<p>In PHP, I have a parent/child class and am using dependency container to load them. I am trying to use the same database connection on all of them without duplicating the object.</p> <p>I used <code>$this-&gt;_db</code> to pull data from the database in a child class method (and my class stores that in the propert...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T22:30:08.830", "Id": "34526", "Score": "0", "body": "Why have you overloaded `setDatabase` in `myChild`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T22:39:20.127", "Id": "34527", "Score": ...
[ { "body": "<p>Why should an object know about a database (in an OOP sense)? I'm definitely no friend of the <a href=\"http://en.wikipedia.org/wiki/Singleton_pattern\" rel=\"nofollow\">Singleton</a> pattern, but a database is in most projects a valid use case.</p>\n\n<hr>\n\n<p>Your code might not be OO but <a h...
{ "AcceptedAnswerId": "21517", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T21:21:26.990", "Id": "21486", "Score": "1", "Tags": [ "php", "object-oriented", "database", "scope", "inheritance" ], "Title": "Using a dependency container to load a p...
21486
<p>I decided to write an STL-style class as an exercise. I followed a tutorial of sorts that I found online, but I also made some modifications. I'd like to hear any criticisms you folks might have. Be harsh; I can take it.</p> <pre><code>#ifndef CIRCULARDEQUE_HPP_ #define CIRCULARDEQUE_HPP_ #include &lt;iterator&gt;...
[]
[ { "body": "<p>Your code on the whole looks good, there's very little I can pick at. I can only offer a few minor suggestions for improvement.</p>\n\n<p>Firstly, your <code>operator=</code> can be made slightly shorter and cleaner:</p>\n\n<pre><code>circular_deque&amp; operator=(self_type other)\n{\n swap(*th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T21:52:04.803", "Id": "21487", "Score": "7", "Tags": [ "c++", "beginner", "c++11", "queue", "stl" ], "Title": "STL-style deque class" }
21487
<p>I've built a small <code>hooks</code> class for adding some capabilities of basic plug-in functionality.</p> <p>Is there room for improvement? I am just beginning to learn OOP. I have two ways to manually add execution points and delete them:</p> <ul> <li>autoloading method for plugins in a specific folder</li> <...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-10T02:09:04.407", "Id": "34583", "Score": "0", "body": "Two suggestions immediately comes to my mind: don't use Singletons (they are just disguised globals) and always write in English both comments and code." } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T22:56:19.127", "Id": "21489", "Score": "3", "Tags": [ "php", "beginner", "object-oriented" ], "Title": "Hooks class for basic plugin functionality" }
21489
<p>I'm writing a card game (Dominion) as a pet project. I'm new to C++ but not programming.</p> <p>A player has a deck, containing the hand and cards in play (tableau). Outside the player, there are piles of cards to buy from (supply piles). I want to display these objects (the hand, tableau and supply piles) on the sc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T04:56:15.050", "Id": "34537", "Score": "0", "body": "Your question isn't fully clear to me. If you create a `std::vector<IInfo*> x;` then you can do `push_back(new Card(...)`, `push_back(new SupplyPile(...))`. Templates aren't covar...
[ { "body": "<p>Is there any reason why <code>View</code> itself can't be a template?</p>\n\n<pre><code>template &lt;typename T&gt; class View {\npublic:\n View(const std::vector&lt;T&gt;&amp; items, int window_starty, int window_startx);\n virtual ~View() { }\n\n const T&amp; CurrentItem() const;\n // ...\n ...
{ "AcceptedAnswerId": "22772", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-08T22:58:50.373", "Id": "21490", "Score": "3", "Tags": [ "c++", "beginner", "game", "playing-cards" ], "Title": "Dominion card game - how can I take advantage of interfaces?" ...
21490
<p>After I found the Change Tracking feature in SQL Server, I thought that I would love to have this information in a stream. That lead me to RX, and Hot Observables. I did some reading and came up with this. I'm wondering if it could be improved.</p> <p>First is how I would use it, followed by the class that impleme...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T00:43:10.087", "Id": "34532", "Score": "0", "body": "Also found this which may be way more efficient .. http://bit.ly/WWEdp0" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-31T09:13:54.463", "Id": "9...
[ { "body": "<pre><code>ConfigurationManager.ConnectionStrings[\"MonitorDB.Properties.Settings.db\"].ToString()\n</code></pre>\n\n<p>I wouldn't rely on <code>ToString()</code> here. <code>ToString()</code> is useful for getting human-readable representation of an object, but I think you shouldn't use it like this...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T00:34:22.890", "Id": "21491", "Score": "2", "Tags": [ "c#", "system.reactive" ], "Title": "Hot Observable of Change Tracking Events from SQL Server 2008 R2" }
21491
<pre><code> #include&lt;stdio.h&gt; #include&lt;stdlib.h&gt; #include&lt;string.h&gt; #include&lt;ctype.h&gt; #define MAX_FILE_LENGTH 500 // Gets the next line from the text file, returns the pointer to that line char* getLine(char* loc, FILE* fileStream); // Returns whether the given s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T08:25:23.467", "Id": "34547", "Score": "2", "body": "Do you want to ask a question or just show your code?" } ]
[ { "body": "<h2>Use of Malloc:</h2>\n\n<p>Where you do:</p>\n\n<pre><code>char* line = (char*)malloc(MAX_FILE_LENGTH*sizeof(char));\n</code></pre>\n\n<p><code>MAX_FILE_LENGTH</code> is known at compile time, and the scope of <code>line</code> doesn't\noutlive the function, thus there is no reason to utilize <cod...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T03:34:31.407", "Id": "21492", "Score": "-2", "Tags": [ "c" ], "Title": "c code emulating grep" }
21492
<p>I am trying to understand how genetic algorithms work. As with everything, I learn by attempting to write something on my own;however, my knowledge is very limited and I am not sure if I am doing this right.</p> <p>The purpose of this algorithm is to see how long it will take half of a herd to be infected by a dise...
[]
[ { "body": "<p>Extract methods <code>initHerd</code>, <code>processGeneration</code> and <code>infect</code>.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T08:12:27.293", "Id": "21501", "ParentId": ...
{ "AcceptedAnswerId": "21511", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T05:14:55.343", "Id": "21495", "Score": "1", "Tags": [ "python", "algorithm", "random" ], "Title": "What is wrong with my Genetic Algorithm?" }
21495
<p>I'm trying to learn Python by working my way through problems on the Project Euler website. I managed to solve problem #3, which is </p> <blockquote> <p>What is the largest prime factor of the number 600851475143 ?</p> </blockquote> <p>However, my code looks horrible. I'd really appreciate some advice from exper...
[]
[ { "body": "<p>Some thoughts:</p>\n\n<p><code>Divide</code> function has been implemented recursively. In general, recursive implementations provide clarity of thought despite being inefficient. But in this case, it just makes the code cumbersome.</p>\n\n<pre><code>while m % factor == 0:\n m /= factor\nreturn...
{ "AcceptedAnswerId": "21507", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T06:35:13.020", "Id": "21497", "Score": "4", "Tags": [ "python", "project-euler", "primes" ], "Title": "Largest Prime Factor" }
21497
<p>I am trying to insert into a database using JDBC and each thread will be inserting into the database. I need to insert around 30-35 columns. I wrote a stored procedure that will UPSERT into those columns. </p> <p>The problem I am facing is that in the <code>run()</code> method, I have around 30 columns written over...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T07:55:28.153", "Id": "34542", "Score": "3", "body": "I have the felling that your Constants are not constant." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T08:09:11.997", "Id": "34544", "Sco...
[ { "body": "<p><strong>Extract a method.</strong></p>\n\n<pre><code>class Task implements Runnable {\n\n ... \n private completeStatement (CallableStatement stmt, Strung userId)\n {\n callableStatement.setString(1, String.valueOf(userId));\n ...\n } \n\n @Override\n public void r...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T07:51:19.410", "Id": "21498", "Score": "2", "Tags": [ "java", "database", "jdbc" ], "Title": "Inserting into a database using JDBC" }
21498
<p>My program calculates the determinant of a matrix of any degree. If you really can't understand my comments or indentifiers please let me know.</p> <pre><code>//;;MakeShift make element number 'ind' the head of list: (defun MakeShift (ind L buf) (if (= ind 1) (cons (car L) (append buf (cdr L))) (makeRepl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T11:50:32.597", "Id": "34554", "Score": "1", "body": "You may want to document the data structures used and provide an example how the code is supposed to be used." } ]
[ { "body": "<p><strong>The first thing is to learn proper indentation.</strong></p>\n\n<pre><code>//;;PushForEach put element elem into a heads of all lists of L:\n(defun PushForEach (elem L)\n (if (null L) nil (cons (cons elem (car L)) (PushForEach elem (cdr L)))\n )\n)\n</code></pre>\n\n<p>What's wrong w...
{ "AcceptedAnswerId": "21510", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T08:58:35.680", "Id": "21503", "Score": "2", "Tags": [ "matrix", "common-lisp" ], "Title": "Determinant calculation of a matrix of any degree" }
21503
<p>I'm writing a dependency injection plugin for the <a href="http://backbonejs.org/" rel="nofollow">Backbone</a> javascript framework, and I'm not sure what the API for constructor argument injection should look like. </p> <p>Just for reference, Backbone objects are defined as follows:</p> <pre><code>var LoginView =...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-02T03:55:37.817", "Id": "60209", "Score": "0", "body": "There is a good article http://www.merrickchristensen.com/articles/javascript-dependency-injection.html that could help you out." } ]
[ { "body": "<p>If I had to pick, I would pick the second option. It's the clearest to me and aligns well with how the plugin injects properties. I don't think it's \"lying\" to the user because it's obvious that the needs.args function is doing something with the arguments before passing back control to the act...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T13:29:09.370", "Id": "21514", "Score": "4", "Tags": [ "javascript", "api", "backbone.js" ], "Title": "Backbone.js Dependency Injection API Design" }
21514
<p>I was thinking about a solution to store preferences and access to them in a most natural way. I came up with the solution below. My questions are: what do you think about the solution? Can it be improved (except maybe using macros)? Is it too complicated (to use)? </p> <p>And most important: <strong>does anyone kn...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T20:43:53.143", "Id": "34570", "Score": "0", "body": "Could you describe your design goals and requirements? To _store and access preferences in a natural way_ is too vague. For example, why not just use Scala's case classes to repre...
[ { "body": "<p>You had asked if anyone has solved this. Take a look at, <a href=\"https://github.com/paradigmatic/Configrity\" rel=\"nofollow\">Configrity</a>. It has the same functionality, however it doesn't use <code>java.util.prefs.Preferences</code>, to store preferences in. Does have interoperability with ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T20:10:51.330", "Id": "21521", "Score": "2", "Tags": [ "scala" ], "Title": "Type-safe user preferences in scala" }
21521
<p>This is the first program (that is not doing much basically), and I know usually you define classes in separate files. I just wanted to see if I got the syntax right, and the concept of using objects from the first chapter of the book. </p> <pre><code>#import &lt;Foundation/Foundation.h&gt; //interface section @i...
[]
[ { "body": "<p>You should definitely check out how <a href=\"http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html#//apple_ref/doc/uid/TP40011210-CH5-SW5\" rel=\"nofollow\">properties</a> can make your code shorter, by adding some...
{ "AcceptedAnswerId": "21648", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-10T00:50:11.517", "Id": "21527", "Score": "1", "Tags": [ "objective-c", "datetime" ], "Title": "Defining a 'Watch' class" }
21527
<p>I'm attempting to write a piece of code that is supposed to remove consecutive appearances of a <code>string</code> (not a single character) in a <code>StringBuilder</code>.<br> It's <strong>extremely</strong> important that the method works well and does not remove or change anything that it shouldn't. Solid perfor...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-10T02:22:08.047", "Id": "34585", "Score": "0", "body": "If it's so important, have you written unit tests for it?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-10T03:39:16.720", "Id": "34586", "Sc...
[ { "body": "<p>Your code looks like it does exactly what you want to me.</p>\n\n<p>Some notes:</p>\n\n<ol>\n<li><code>StringBuilder</code> methods (which you're emulating by using an extension method) return the modified <code>StringBuilder</code>, so they can be used in a <a href=\"http://en.wikipedia.org/wiki/...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-10T02:01:12.587", "Id": "21528", "Score": "4", "Tags": [ "c#", "strings" ], "Title": "A reliable way to remove consecutive appearances of a substring" }
21528
<p>I am trying to create an invert index structure in C++. An invert index, in this case, refers to image retrieval system, where each invert index refers to a numbers of "Patch ID". (simply called "ID" in the code) These IDs are basically for describing many kind of pixel gradient patches from all images in the databa...
[]
[ { "body": "<p>You are taking a copy of the inner map, modifying it, then putting it back. That could well be inefficient. You could take the inner map by reference then modify it.</p>\n\n<p>However you can actually make use of the fact that <code>map operator[]</code> inserts if it does not find the element. As...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-10T02:14:22.703", "Id": "21529", "Score": "3", "Tags": [ "c++", "algorithm", "image", "container" ], "Title": "Inverting index structure in C++" }
21529
<p>I have an MVC framework I've written. I'm trying to abstract out ASP.NET specific bits as well as make it more testable. Previously, I relied on <code>HttpContext.Current</code> in many places, which proves to be very unfriendly to unit testing. So, I started designing my own minimalistic interface for everything I'...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-10T08:30:21.303", "Id": "34591", "Score": "1", "body": "I would try and keep my controllers as skinny as possible and then unit testing them is not really necessary. Hopefully this way you might be able to keep your interface smaller ...
[ { "body": "<p>You have to keep in mind that the earlier version of the .NET framework suffered in applying the interface segregation principle. In this case, the HTTP context includes methods associated with the request (ex. URL), the response (ex. HTTP status) and server utility functions (ex. map path).</p>\n...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-10T04:14:04.393", "Id": "21530", "Score": "7", "Tags": [ "c#", "interface", "server" ], "Title": "Interface for server requests and responses" }
21530
<p>I am working on a project in which I need to pass multiple arguments from the command line-</p> <p>Below is the use case I have-</p> <ol> <li><p>From the command line, I will be passing atleast four paramaters- <code>noOfThreads</code>, <code>noOfTasks</code>, <code>startRange</code> and <code>tableName1</code>, s...
[]
[ { "body": "<ol>\n<li><p>Extract out the common logic before the <code>if</code>. The following is more or less the same:</p>\n\n<pre><code>noOfThreads = Integer.parseInt(args[0]);\nnoOfTasks = Integer.parseInt(args[1]);\nstartRange = Integer.parseInt(args[2]);\ntableName1 = args[3];\ndatabaseNames.add(tableName...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-10T05:47:51.827", "Id": "21531", "Score": "3", "Tags": [ "java" ], "Title": "Passing multiple parameters from the command line in Java" }
21531
<p>I have written a piece of code that finds common patterns in two strings. These patterns have to be in the same order, so for example "I am a person" and "A person I am" would only match "person". The code is crude, all characters, including whitespace and punctuation marks, receive the same treatment. The longest p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-26T21:33:10.350", "Id": "73955", "Score": "1", "body": "stdlib solution: if `a, b = \"same order words\", \"not same but order words matched\"` then `[a[i:i+n] for i, _, n in difflib.SequenceMatcher(None, a, b).get_matching_blocks()\ni...
[ { "body": "<p>You can simplify the two functions quite a bit. For <code>find_raw_patterns</code> you can use <code>partition</code> instead of manually splitting the strings up, and simplify the formation of the list.</p>\n\n<pre><code>def find_raw_patterns(s1, s2): # used recursively\n if s1 == '' or s2 == ...
{ "AcceptedAnswerId": "21535", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-10T06:16:47.460", "Id": "21532", "Score": "4", "Tags": [ "python", "strings" ], "Title": "Python 3: Finding common patterns in pairs of strings" }
21532
<p>I've developed a code for a Hangman game and what I need help in is basically simplifying, correcting and removing parts of the code that are not needed (or there is an easier way to do it). I think there are parts where I could have done it easier but I do not know where they are. I would appreciate any/ all help a...
[]
[ { "body": "<p>Thank you for sharing your code. Quite frankly, it's a bit of a mess, so let's try to clean it up. </p>\n\n<h1>General Code Issues</h1>\n\n<p>Here are a few examples of issues with your code that can easily be corrected. All these issues can be automatically detected by a good IDE such as the free...
{ "AcceptedAnswerId": "21573", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-10T09:27:07.587", "Id": "21534", "Score": "4", "Tags": [ "java", "hangman" ], "Title": "Hangman game code" }
21534
<p>I've written this <code>module</code> (using a tutorial on the web I can't find now to stop unusual requests from clients. It's working as I've tested it on a local system. </p> <ol> <li><p>Is the logic fine enough?</p></li> <li><p>Another problem is that it counts requests for non-aspx resources (images, css, .....
[]
[ { "body": "<p>There definitely are not enough of these tools in the .NET world, but I've found that there are a lot in the WordPress/php world. My recommendation would be to review the code in those modules to determine if the logic is good enough. Certainly, \"good enough\" depends on your needs though. </p>\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-10T12:31:12.277", "Id": "21537", "Score": "1", "Tags": [ "c#", "asp.net" ], "Title": "Optimizing this AntiDos HttpModule" }
21537
<p>My data is in this format:</p> <blockquote> <p>龍舟 龙舟 [long2 zhou1] /dragon boat/imperial boat/\n</p> </blockquote> <p>And I want to return:</p> <pre><code>('龍舟', '龙舟', 'long2 zhou1', '/dragon boat/imperial boat/') </code></pre> <p>In C I could do this in one line with <code>sscanf</code>, but I seem to be f̶a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-10T13:04:27.373", "Id": "34604", "Score": "0", "body": "This is a little hard to parse because the logical field separator, the space character, is also a valid character inside the last two fields. This is disambiguated with brackets ...
[ { "body": "<p>My goal here is clarity above all else. I think a first step is to use the <code>maxsplit</code> argument of <a href=\"http://docs.python.org/2/library/stdtypes.html#str.split\" rel=\"nofollow\"><code>split</code></a> to get the first two pieces and the remainder:</p>\n\n<pre><code>trad, simp, rem...
{ "AcceptedAnswerId": "21543", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-10T12:37:25.733", "Id": "21539", "Score": "3", "Tags": [ "python", "strings", "parsing", "unicode" ], "Title": "String parsing with multiple delimeters" }
21539
<p>I have two loops which I am using to create a file, if the clientID in the client loop is the same as the id in the valuation loop then create a row. Then if the month value is the same as the previous month value we need to add up the values.</p> <p>This all works fine but i was wondering if anyone can think of a ...
[]
[ { "body": "<p>If you add a <code>toString()</code> method inside the client class you could, replace this code:</p>\n\n<pre><code>//in loop so use stringbuilder\n StringBuilder sb = new StringBuilder();\n sb.append(cl.getId());\n sb.append(\",\");\n sb.append(cl.getFi...
{ "AcceptedAnswerId": "21553", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-10T17:24:28.407", "Id": "21548", "Score": "1", "Tags": [ "java" ], "Title": "Calculating sum of certain values in a list" }
21548
<p>I'm on a high school robotics team and I'm trying to code a Xbox 360 controller so that it'll controller the motors with variable speed. So far it works alright, but where I'm quite the novice coder I'd like to have more experienced eyes peer at my code and see if they can find a better way, or more effective way to...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T00:45:18.077", "Id": "34620", "Score": "2", "body": "As the code is working without issue, this would be more appropriate on codereview.SE" } ]
[ { "body": "<p>Just on the if statements. Could you do something like:</p>\n\n<pre><code> Dim LY As Integer = GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y * 100\n Dim LX As Integer = GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X * 100\n\n HScrollLX.Value = LX\n VScrollLY.Value = LY\n\...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-09T00:32:55.870", "Id": "21551", "Score": "3", "Tags": [ "vb.net", "xna" ], "Title": "I was wondering if there was a better way to improve my XNA joystick code? (Vb. Net)" }
21551
<p>So, my question is more of a 'best practices' question rather than a question with a particular aim. This is my current understanding of PHP factories and how to incorporate them into a project using PDOs and dependency injection. I'm pretty new at this and I still don't understand a lot about this subject. As such,...
[]
[ { "body": "<p><code>demo</code> should be <code>Demo</code> and in new classes you might want to use namespaces instead of underscores in your class names. See <a href=\"https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md\" rel=\"nofollow\">PSR-0</a></p>\n\n<p>As non of your <code>$args</code...
{ "AcceptedAnswerId": "21564", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-10T22:14:56.477", "Id": "21555", "Score": "4", "Tags": [ "php", "pdo" ], "Title": "PHP PDO Factory Classes" }
21555
<p>I'm wondering if there is anything i'm overlooking in the code below. I've taken the <a href="http://doc.akka.io/docs/akka/2.0.2/intro/getting-started-first-scala.html#Bootstrap_the_calculation" rel="nofollow">Pi calculation</a> example, simplified it and converted it to Akka 2.1. </p> <p>More specifically, i use t...
[]
[ { "body": "<p>I'm not an akka expert but I did used akka in a project so these are just some of my observations:</p>\n\n<ol>\n<li><p><code>result</code> is blocking.</p>\n\n<pre><code>val result = Await.result(master ? Run, timeout.duration)\n</code></pre>\n\n<p>On case the master takes longer due to load or wh...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-11T00:22:15.037", "Id": "21557", "Score": "3", "Tags": [ "scala", "akka" ], "Title": "Is this Scala/Akka idiomatic and correct for Akka 2.1?" }
21557
<p>I was trying to explain the mediator pattern to a new developer, and ended up writing a simple event mediator. Thoughts?</p> <p><strong>EventMediator</strong></p> <pre><code>class EventMediator { private $events = array(); public function attach($event, Closure $callback) { if(!is_string($event)) ...
[]
[ { "body": "<p>I think this is a very clean looking code base, so congrats getting that down. I also think that the the way you implemented the pattern worked out very well.</p>\n\n<p>I don't have much to say, it's mostly just formatting.</p>\n\n<ul>\n<li>Throughout, you insist on keeping block sections condense...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-11T00:35:56.697", "Id": "21558", "Score": "3", "Tags": [ "php", "php5", "mediator" ], "Title": "Simple event mediator" }
21558