body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I have a rather clunky function that returns a number based on certain values:</p> <pre><code>local = {'abs154': '4'} w12,sv2,sv4,sv6,sv8,sv10,sv12=75,95,110,104,101,110,116 supers = [["5", w12], ["6", w12], ["7", w12], ["8", w12], ["16", w12], ["17", w12], ["18", w12], ["9", sv2], ["11", sv2], ["12", sv2], ["13"...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T00:52:22.807", "Id": "48801", "Score": "0", "body": "sorry about the lack of code blocks. seems a bit different than stack" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T01:00:41.310", "Id": "488...
[ { "body": "<ul>\n<li>Extract two functions from the except clause: one that extracts <code>num</code> from <code>group</code>, and one that looks up <code>sn</code> from <code>super</code></li>\n<li>Precomputing <code>cumfreq</code> into <code>super</code> would allow easy lookup with help from the <code>bisect...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T00:49:50.157", "Id": "30710", "Score": "1", "Tags": [ "python", "mathematics" ], "Title": "Cleaning and simplifying function that returns a number based on certain values" }
30710
<p>I am using <code>ExcelDataReader</code> to import an Excel file to a dataset.</p> <p>Example Excel table:</p> <blockquote> <pre><code>//ID Name Display Order Active //1 John 1 1 </code></pre> </blockquote> <p><code>ID</code>, <code>DisplayOrder</code> and <code>Active</code> c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T04:52:12.010", "Id": "48812", "Score": "2", "body": "I'd probably rewrite that last line as `IsActive= dr.Field<double>(\"Active\") > 0` (your ternary is unnecessary as the comparison already evaluates to `true` or `false`) because ...
[ { "body": "<p>I created an extension method for <code>DataTable</code> to convert them into a <code>List&lt;T&gt;</code></p>\n\n<pre><code>public static class Helper\n{\n /// &lt;summary&gt;\n /// Converts a DataTable to a list with generic objects\n /// &lt;/summary&gt;\n /// &lt;typeparam name=\"T...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T03:49:58.153", "Id": "30714", "Score": "47", "Tags": [ "c#", "performance", "linq", "converting", ".net-datatable" ], "Title": "Converting DataTable to List of class" }
30714
<p>My code looks ugly. What can you recommend? I already know about <code>Enum</code>; maybe it's a good variant for this situation. Anything else?</p> <pre><code> private void writerContent(Integer firstRow, List&lt;Record&gt; records){ int firstColumn=0; int lastColumn=7; XSSFSheet sheet =...
[]
[ { "body": "<p>Why don't you unroll the inner loop? So the final method will be like</p>\n\n<pre><code>private void writerContent(Integer firstRow, List&lt;Record&gt; records) {\n XSSFSheet sheet = workBook.getSheetAt(0);\n for (int lineId=firstRow; lineId&lt;records.size(); lineId++) {\n Record re...
{ "AcceptedAnswerId": "30735", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T06:34:50.870", "Id": "30717", "Score": "7", "Tags": [ "java" ], "Title": "Refactor code to populate a spreadsheet" }
30717
<p>I am developing a webapp using Spring MVC + Hibernate. I created a GenericDao class that implements basic data access methods, to be extended by all my concrete daos in the app. What I want advice or review about is the exception handling of the data access layer exceptions. Let me post a shortened version of my gen...
[]
[ { "body": "<p>I would say don't set rules like \"I will catch exceptions in this layer.\" \nWith exceptions you have two options catch them or throw them. If you know what to do with exception then catch it and proccess it in the catch section. If you dont know what to do at the current level(layer) throw it. O...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T07:20:05.473", "Id": "30719", "Score": "3", "Tags": [ "java", "error-handling", "spring", "hibernate" ], "Title": "Managing data access layer exceptions" }
30719
<p>A few days ago, I posted my version of a wildcard search algorithm, which you can see here: <a href="https://codereview.stackexchange.com/questions/30456/wildcard-search-in-c">Wildcard search in C</a></p> <p>Today I'm showing version 2. I didn't want to make it in the same post because the code is quite different.<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T12:24:48.873", "Id": "48829", "Score": "0", "body": "I'm assuming you'd also like this to be shortened? It's considerably longer than the first version." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-0...
[ { "body": "<p>I’m afraid your approach to matching multiple characters looks fundamentally misguided to me. Consider cases like:</p>\n\n<pre><code>abcbcd ab*cd\n</code></pre>\n\n<p>One approach that works is a recursive matcher, i.e. when encountering <code>*</code>, try <code>wildcard(value+1, wcard)</code>...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T08:53:14.077", "Id": "30724", "Score": "1", "Tags": [ "c", "strings", "search" ], "Title": "Wildcard search in C version 2" }
30724
<p>I am using <code>db_dataobject</code> and have provided two examples of an insert and a select query below.</p> <p>Can you please help me rewrite them in a more secure way using PDO? Is there any other way to improve them?</p> <p><strong>INSERT</strong> </p> <pre><code> $user= new DataObjects_user; ...
[]
[ { "body": "<p>I come back to this at the end, but if this answer is <em>tltr</em>, basically, I end up suggesting not to write your own DB abstraction layer, <a href=\"https://codereview.stackexchange.com/questions/29362/very-simple-php-pdo-class/29394#29394\">It's been done before</a>, way better than you're d...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T08:59:41.910", "Id": "30725", "Score": "0", "Tags": [ "php", "mysql", "security", "pdo" ], "Title": "How can I make this piece of code more secure?" }
30725
<p>Any suggestions how to make this code better? I'm novice in coding...)) In this code I'm want to show some hint depending of browser type on semi-transparent overlay. I'm detecting browser type (I'm need - Firefox, Chrome, IE 9 and higher), create all nessesary elements, append this elements to a document.body, and ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T11:59:58.063", "Id": "48827", "Score": "4", "body": "Why re-invent hot water? http://www.browser-update.org/ ... And then ofcourse, browser sniffing is bad. http://css-tricks.com/browser-detection-is-bad/ And what about Opera? and a...
[ { "body": "<p>\"Browser-sniffing\" is bad, usually because the methods used to detect them are usually \"spoofable\" and unreliable</p>\n\n<p>User Agent string can be spoofed (changed) and can't be relied on. In fact, vendors change UAs to tell websites they are another browser, some for valid purposes. I think...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T09:59:35.543", "Id": "30729", "Score": "0", "Tags": [ "javascript" ], "Title": "Improve my browser-detecting JavaScript" }
30729
<p>Moved from Programmers.SE.</p> <p>I have written a new version of the PBKDF2 algorithm in Haskell. It passes all of the HMAC-SHA-1 test vectors listed in <a href="http://www.ietf.org/rfc/rfc6070.txt" rel="nofollow">RFC 6070</a>, but it is not very efficient. How can I improve the code? I plan to upload it to Github...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T09:54:21.833", "Id": "49503", "Score": "0", "body": "Do you have a test suite that measures the algorithm's performance? It'd be much easier to test ideas for improvements." }, { "ContentLicense": "CC BY-SA 3.0", "Creati...
[ { "body": "<p>The <a href=\"https://stackoverflow.com/q/18718103/1333025\">comments on SO</a> give some good hints. The most critical part is obviously <code>blockIterator</code>, so let's make it a separate function:</p>\n\n<pre><code>blockIterator\n :: ([Octet] -&gt; [Octet] -&gt; [Octet]) -- ^ pseudo ran...
{ "AcceptedAnswerId": "31111", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T13:13:21.650", "Id": "30733", "Score": "3", "Tags": [ "haskell", "cryptography" ], "Title": "Code Review of Haskell PBKDF2" }
30733
<p>I have working code to show in <code>index.php</code> and <code>content-gallery.php</code> of WordPress with Bootstrap 3.0 Carousel.</p> <p>But, I know it's not clean code. Could anyone help me clean/improve it?</p> <p>This is the code we need to generate Bootstrap Carousel: </p> <pre><code>&lt;div id="carousel-...
[]
[ { "body": "<p>IMO, clean wp code is hard, if not impossible to acchieve. I can tell you, however, that the first thing I'd remove from your functions is the <code>echo $html;</code> statements.</p>\n\n<p>A function is a block of code that does something, and <em>returns that data</em>, to be used anywhere. Your...
{ "AcceptedAnswerId": "30758", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T14:02:54.960", "Id": "30736", "Score": "1", "Tags": [ "php", "optimization" ], "Title": "Bootstrap 3.0 Carousel gallery post WordPress" }
30736
<p>I wrote this program which takes all the bits in a number and shifts them to the left end (for example: 01010110 --> 11110000). It's and exercise from a book. It works, but it seems to be very wasteful to use integers (I only need 8 bits). </p> <p>Can you tell me if the code is proper or not? Is the algorithm good?...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T02:54:27.483", "Id": "48879", "Score": "2", "body": "It's a good algorithm. The code is not bad. I agree with most of what Jamal says, but I don't like combining the `if` with its body on a single line. The standard puts a space bet...
[ { "body": "<p>It appears the correct results are given, which is good. I do see some miscellaneous things, though.</p>\n\n<ul>\n<li><p>The naming and execution in <code>main()</code> seem confusing. Try something like this:</p>\n\n<pre><code>int main()\n{\n // the name \"bit\" is misleading; you're using a...
{ "AcceptedAnswerId": "30744", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T15:37:06.687", "Id": "30740", "Score": "3", "Tags": [ "c++", "algorithm", "bitwise" ], "Title": "Take all the bits in a number and shift them to the left end" }
30740
<p>I have a <code>defaultdict</code> being written to file like this:</p> <pre><code>writer = csv.writer(open(locationToSaveFile, 'wb+')) for k,v in dict.iteritems(): writer.writerow([k ,v]) </code></pre> <p>I then have this horribly convoluted text to read it back in:</p> <pre><code>myDict = defaultdict(lis...
[]
[ { "body": "<p><code>csv</code> is meant to store rows of data, not a simple dictionary. You can use <a href=\"http://docs.python.org/2/library/json.html\" rel=\"nofollow\"><code>json</code></a> for that:</p>\n\n<pre><code>import json\n\n# writing\njson.dump(yourdict, open(filename, 'w'))\n\n# reading\nyourdict ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T16:38:08.830", "Id": "30741", "Score": "2", "Tags": [ "python", "csv" ], "Title": "Writing defaultdict to CSV file" }
30741
<p>Consider the query given below:</p> <pre><code>SELECT * FROM ((SELECT c.cust_id , c.username , REPLACE(qs.seg_type_ref_key_02, 'N/A', 'Non Vip') casino_group, REPLACE(qs.seg_type_ref_key_03, 'N/A', 'Non Vip') bingo_group, REPLACE(qs.seg_type_r...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T18:43:23.783", "Id": "48860", "Score": "0", "body": "Consider also: http://dba.stackexchange.com/" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T18:51:27.513", "Id": "48862", "Score": "0", ...
[ { "body": "<p>From some research, I have found the <code>&lt;&gt;</code> or <code>does not equal</code> takes longer to run than <code>=</code> operations</p>\n\n<p>In <a href=\"https://stackoverflow.com/a/7419299/1214743\">this answer to <code>SQL Server “&lt;&gt;” operator is very slow compared to “=” on tabl...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-03T18:27:44.103", "Id": "30745", "Score": "3", "Tags": [ "optimization", "performance", "sql", "sql-server" ], "Title": "Querying a warehouse database" }
30745
<p>Today I decided to get into F#. I watched <a href="http://channel9.msdn.com/Blogs/pdc2008/TL11" rel="nofollow noreferrer">this video</a> and had a bit of fun doing some coding examples, I can see that it will be very useful for certain programs that I write. </p> <p>One thing that I was interested in are the explic...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T05:58:44.197", "Id": "48886", "Score": "0", "body": "I don't understand why this is a problem, i.e. I think you're making this more complicated than it really is... Just pass a function." }, { "ContentLicense": "CC BY-SA 3.0...
[ { "body": "<p>If you're trying to work around the inability to pass a constructor as a first-class function, here's a simpler approach:</p>\n\n<pre><code>let inline New x = (^T : (new : ^U -&gt; ^T) x)\n\n// a function that takes a 'constructor' function\nlet f (g: int -&gt; 'T) = g 0\n\ntype T(i:int) = class e...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T03:03:11.957", "Id": "30752", "Score": "1", "Tags": [ "f#" ], "Title": "F# solution to generic new() constraint limitation" }
30752
<p>To execute tasks sequentially with a timeout I use <code>ExecutorService.submit()</code> and <code>Future.get()</code>. As I don't want to block calling clients, I implement producer–consumer pattern with a queue into a Thread while(true) loop:</p> <pre><code>import java.util.concurrent.ExecutionException; import j...
[]
[ { "body": "<p><strong>TaskProcessor</strong></p>\n\n<ul>\n<li>I see little reason why this should extend <code>Thread</code>, rather than simply implement <code>Runnable</code></li>\n<li>as a thread it <em>is</em> responsive to interruption, yet there is no way a client can interrupt this thread, through API no...
{ "AcceptedAnswerId": "30782", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T07:59:31.453", "Id": "30756", "Score": "4", "Tags": [ "java", "unit-testing", "concurrency", "multithreading" ], "Title": "Unit test an ExecutorService in a deamon" }
30756
<p>I needed to perform network communications in my Linux C++ project. I thought that it was a good idea to operate on a higher level of abstraction than raw system calls. Also I love OO design. So I'm implementing an <a href="https://github.com/Kolyunya/Unet/tree/master/src" rel="nofollow">object-oriented high-level U...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T19:17:12.377", "Id": "48970", "Score": "2", "body": "There are already a million of these. Writting your own is a bad idea as you have to fix all the same mistakes that have been fixed before. Don't re-invent the wheel find one that...
[ { "body": "<p>As Loki stated: don't re-invent the wheel. In the interest of learning and sharing, here are some ideas to consider:</p>\n\n<pre><code>if ( argc != 3 )\n</code></pre>\n\n<p>Use an API already designed for parsing the command line. There must be dozens.</p>\n\n<pre><code>socket.setOption(SO_REUSEAD...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T10:06:54.457", "Id": "30761", "Score": "3", "Tags": [ "c++", "object-oriented", "linux", "networking" ], "Title": "Object-oriented Linux networking library" }
30761
<p>The code below gets value from a column in an Excel sheet. The values I get are B1, B2, B3, B4...., B100, ...Bn. All I need to do is strip out the char 'B' and convert the numeric string to integer and count how many times a particular integer has repeated.</p> <p>The snippet below shows the string stripping the c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T11:17:29.763", "Id": "48896", "Score": "0", "body": "I'm confused about the code, I think the end result of it is that it will do nothing. Also, have a look at the `Substring()` method." }, { "ContentLicense": "CC BY-SA 3.0"...
[ { "body": "<p>you have this line</p>\n\n<pre><code>range = null;\n</code></pre>\n\n<p>and this line</p>\n\n<pre><code>range = readSheet.get_Range(cell, Missing.Value);\n</code></pre>\n\n<p>both inside and outside of your <code>While</code> Statement. this seems Odd to me?\nfrom the code that you have given it l...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T10:21:52.697", "Id": "30762", "Score": "4", "Tags": [ "c#", "strings", ".net", "excel", "interval" ], "Title": "Getting a value from an Excel sheet column" }
30762
<p>My current task is to extend some JavaScript of a framework we are using. A pop-up should slide in, instead of just appear in the middle of the window. So I have overridden one of the framework's methods, and do at the end this:</p> <pre><code>AdfDhtmlPage.prototype.showMessages = function (componentId) { // Some ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T11:14:00.790", "Id": "48895", "Score": "0", "body": "Why would you assume that your element should be bound inside the AdfDhtmlSimpleFloat object? (is popupElement an AdfDhtmlSimpleFloat?). I notice from the ADF docs that they warn ...
[ { "body": "<p>The problem is that <code>this._slideIn</code> refers to a function, not a method invocation. In your third code sample, changing your last line to</p>\n\n<pre><code>var self = this;\nsetTimeout(function() { self._slideIn(componentId) }, 20);\n</code></pre>\n\n<p>should be sufficient. You have t...
{ "AcceptedAnswerId": "30809", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T10:36:50.720", "Id": "30763", "Score": "1", "Tags": [ "javascript", "closure" ], "Title": "JavaScript binding loss with setTimeout" }
30763
<p>I've been studying <a href="http://en.wikipedia.org/wiki/Reservoir_sampling" rel="nofollow noreferrer">Reservoir sampling</a> for a couple of days. What I've tried here is draw a uniformly random sample of size 3 from bigger data (the 26 characters of the English alphabet) via reservoir sampling. Below is what I've...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-14T02:57:21.597", "Id": "49772", "Score": "0", "body": "Nice R plots. R is really powerful for statistics like this. Good language choice for the use case." } ]
[ { "body": "<p>The algorithm itself looks solid, and your code looks good! I just wanted to provide some general style tips for Java.</p>\n\n<p>First, why are you performing the core of your logic in the <code>test1</code> constructor? That's highly irregular for Java. A constructor in general should only per...
{ "AcceptedAnswerId": "30808", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T11:33:56.553", "Id": "30764", "Score": "4", "Tags": [ "java", "shuffle" ], "Title": "Review of reservoir sampling" }
30764
<p>I have a bunch of IP addresses. I want one IP network that has them all. <code>ipaddr.collapse_address_list</code> already exists, but that gives you a <em>list</em> of all the IP networks that identify your IP addresses, no more, no less, whereas I only need <em>one</em> IP network.</p> <p>I tried at first using X...
[]
[ { "body": "<p>You don't have to look at all the IPs to catch 'em all. Just looking at the lowest and highest does the trick. This realisation comes in handy when you consider that ipaddr does have a (private) function that gives you the common prefix length between two IP addresses. The code can then be simplif...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T12:00:52.867", "Id": "30765", "Score": "2", "Tags": [ "python", "networking" ], "Title": "Find the single smallest IP network with the given IP addresses" }
30765
<p>Below is how I'm solving the problem of <a href="https://softwareengineering.stackexchange.com/questions/210260/converting-between-data-and-presentation-types">converting between data and presentation types</a>, I'd like to know if that's a good way to go about it, and if not, what would be a better way to go about ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T13:44:24.137", "Id": "48920", "Score": "0", "body": "I realize the actual code does not actually have a `SomeEntity` class and that CR guidelines are against such \"placeholders\", however the review I'm requesting is more about the...
[ { "body": "<pre><code>T ToEntity();\n</code></pre>\n\n<p>To me, <code>ToEntity()</code> implies some sort of conversion action. A better option might be <code>T GetEntity()</code> or even a property called <code>Entity</code>.</p>\n\n<pre><code>protected readonly T EntityType;\n</code></pre>\n\n<p><code>EntityT...
{ "AcceptedAnswerId": "30773", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T13:18:26.127", "Id": "30769", "Score": "10", "Tags": [ "c#", "reflection", "mvvm", "lambda" ], "Title": "Converting between data and presentation types" }
30769
<p>I am having an issue where I am doing a query and it is coming back with about 100 pages, I was hoping to have it come back with 1,2,3...30,31...99,100 instead of 1,2,3,4,5,6,7,8,etc. please see below for working code that returns back results as unwanted format, I am new here so if this question is written wrong pl...
[]
[ { "body": "<p>Do you just mean the links at the bottom of your page? If so you have this code:</p>\n\n<pre><code>// Display page links.\n$numOfPages = ceil($rowsReturned/$rowsPerPage);\nfor($i = 1; $i&lt;=$numOfPages; $i++)\n{\n $pageLink = \"?pageNum=$i\";\n print(\"&lt;a href=$pageLink&gt;$i&lt;/a&gt;&a...
{ "AcceptedAnswerId": "30772", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T13:34:36.460", "Id": "30770", "Score": "2", "Tags": [ "php", "sql", "pagination" ], "Title": "PHP Pagination for 1,2,3... vs 1,2,3,4,5,etc" }
30770
<p>What's a concise way of returning <code>true</code> or <code>false</code> along with an error message?</p> <p>Here's a concrete example - I'm building a parser that takes in a file. <code>ParseReplayData</code> does some validation before proceeding with the actual parsing:</p> <pre><code>public class Parser { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T14:12:31.850", "Id": "48926", "Score": "7", "body": "What about throwing an exception instead of returning `false`? You could also define a `Result` class which contains the return-value and the reason." } ]
[ { "body": "<p>An alternative as MrSmith42 suggested could be to use exceptions.</p>\n\n<pre><code>public class ReplayDataParser\n{\n private const string SupportedFileExtension = \"w3g\";\n private const string ErrorFileDoesNotExist = \"Replay file does not exist: {0}\";\n private const string ErrorFil...
{ "AcceptedAnswerId": "30792", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T14:01:50.297", "Id": "30774", "Score": "10", "Tags": [ "c#", "error-handling" ], "Title": "Cleaner way of returning true/false with error message" }
30774
<p>This is my first C++ program with classes, and I don't want to develop bad skills. It's very simple and consists of 3 files. This is an exercise from a book, hence the name of the driver file.</p> <p>Please tell me whether it's proper or not!</p> <p><strong>parity.cpp:</strong></p> <pre><code>#include &lt;iostre...
[]
[ { "body": "<p><a href=\"http://www.cplusplus.com/forum/articles/10627/\" rel=\"nofollow\">Some general guidelines regarding <code>#include</code>s</a>:</p>\n\n<ul>\n<li>only <code>#include</code> in the header when necessary (this reduces potentially unwanted dependencies)</li>\n<li>whenever possible, forward d...
{ "AcceptedAnswerId": "30781", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T16:04:44.130", "Id": "30779", "Score": "6", "Tags": [ "c++", "beginner", "classes" ], "Title": "Testing parity of number of items" }
30779
<p>I want to ensure that, as much as possible given my skill level, that I'm using relevant patterns correctly and following naming conventions. This is a controller for a poor-mans <a href="http://en.wikipedia.org/wiki/Mud_client" rel="nofollow">MUD client</a> using Apache <code>TelnetClient</code>. The <a href="htt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-08T07:20:59.633", "Id": "49253", "Score": "0", "body": "By the way... Don't you think, that a comment \"This question came from our site for professional and enthusiast programmers\" visible, when a question has been moved from SO, sug...
[ { "body": "<p>Member Variables: You define two of them as <code>final</code>, yet never a assign a new value to any of them. Might as well just make them all <code>final</code>.</p>\n\n<hr>\n\n<p><code>sendCommands()</code>:</p>\n\n<ul>\n<li><code>commandString</code> is never being used.</li>\n<li><code>comman...
{ "AcceptedAnswerId": "30786", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T10:02:59.457", "Id": "30784", "Score": "2", "Tags": [ "java", "design-patterns", "multithreading", "controller", "producer-consumer" ], "Title": "Controller for a MUD c...
30784
<p>I choose to use a dictionary to store the variables for fast <code>GET</code> and <code>SET</code> commands. In my code, I have saved all of the open transactional blocks in memory. I can't see any way around this since it is always possible to have enough <code>ROLLBACK</code> commands to access all open blocks. ...
[]
[ { "body": "<p>Python has a built in dictionary method for <code>numequalto</code>:</p>\n\n<pre><code>print dict.values().count(value)\n</code></pre>\n\n<p>I don't know exactly how fast this is, but am sure it is faster than implementing your own O(N) function. Unfortunately it isn't compatible with your impleme...
{ "AcceptedAnswerId": "30788", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T18:23:46.983", "Id": "30785", "Score": "2", "Tags": [ "python", "database" ], "Title": "Building a simple database in Python" }
30785
<p>The object is to be able to pass some dates (start date, holiday) and the number of days you want to skip. We only want to skip working days, not weekends and holidays. </p> <p>Just let me know what you'd do different than what I have. The code works, but I was told there are issues with it, but not told what issue...
[]
[ { "body": "<p>Here is another way of doing the same thing</p>\n\n<pre><code>&lt;?php\n\nfunction getWDays($startDate,$holiday,$wDays) {\n\n // using + weekdays excludes weekends\n $new_date = date('Y-m-d', strtotime(\"{$startDate} +{$wDays} weekdays\"));\n\n $holiday_ts = strtotime($holiday);\n\n //...
{ "AcceptedAnswerId": "30813", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T20:26:11.867", "Id": "30791", "Score": "2", "Tags": [ "php", "datetime" ], "Title": "Get Next Working Date, skip weekends and holidays" }
30791
<p>I have created a linked list in C++, I suspect there is a good chance I have made some larger errors in this code as I am working with a few concepts new to me. Please be very hard on me as I want to eventually be good at this.</p> <pre><code>#include &lt;iostream&gt; // basic linked list implimentation in C++ usi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-25T12:00:41.027", "Id": "63354", "Score": "0", "body": "Your code still doesn’t follow the Rule of Three Anton mentioned. In particular, you should either provide copy-assignment and and copy-constructor or explicitly disable them (C++...
[ { "body": "<p>I'll cover the C++-specific issues first, and then move on to the design decisions you make.</p>\n\n<p>First of all, note that C++ has the <a href=\"http://en.wikipedia.org/wiki/Rule_of_three_%28C%2B%2B_programming%29\" rel=\"nofollow\">Rule of Three</a>. It states that if you have a custom destr...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T21:42:47.567", "Id": "30794", "Score": "2", "Tags": [ "c++", "linked-list" ], "Title": "Basic linked list in C++" }
30794
<p>I'm fairly new to MVC concepts and PHP input validation.</p> <p>I'm open to all input, but I'm largely wanting to know if the following:</p> <ol> <li><p>Follows the MVC pattern correctly - if not, how can I change it to better follow that? </p></li> <li><p>Has any huge apparent security flaws with the validation p...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T22:06:04.100", "Id": "30799", "Score": "3", "Tags": [ "php", "mvc", "validation" ], "Title": "Tiny MVC - Handling validation / sanitization in a model" }
30799
<p>I am working on a project in which I will be having different Bundles. Let's take an example, Suppose I have 5 Bundles and each of those bundles will have a method name <code>process</code>.</p> <p>Below are the things, I am supposed to do-</p> <ol> <li>I need to call all those 5 Bundles <code>process</code> metho...
[]
[ { "body": "<blockquote>\n <p>I need to call all those 5 Bundles process method in parallel using\n multithreaded code and then write to the database. I am not sure what\n is the right way to do that? Should I have five thread? One thread for\n each bundle? But what will happen in that scenario, suppose if I...
{ "AcceptedAnswerId": "30840", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-05T01:29:49.123", "Id": "30801", "Score": "1", "Tags": [ "java", "multithreading", "thread-safety" ], "Title": "Calling different bundles in parallel using ExecutorService" }
30801
<pre><code>package utils; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import com.google.gson.Gson; public class JSONUtils { public static final Gson gson = new Gson(); public static String toJSON(Object o, String... fields) { HashMap&...
[]
[ { "body": "<p>Are you changing the fields that you expose from your objects depending on certain conditions? </p>\n\n<p>On the whole it would be best to use reflection only as a last gasp. Gson works fine with collections in general see the documentation over at <a href=\"https://sites.google.com/site/gson/gson...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-05T03:48:02.067", "Id": "30804", "Score": "2", "Tags": [ "java", "json" ], "Title": "Is it a good choice to define my own JSON util class like this?" }
30804
<p>I have spent about 2 weeks reading about hashing passwords and website security. As there seems to be many different ways to achieve this, I'm a bit confused as to whether my code is secure.</p> <p>Can anyone please have a look through and let me know what they think and what needs to be changed?</p> <p>I have not...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-05T13:59:24.763", "Id": "49030", "Score": "0", "body": "`RNGCryptoServiceProvider`, `SHA256Managed` and `Rfc2898DeriveBytes` all implement the `IDisposable` interface and therefore should be wrapped in `using` statements." }, { ...
[ { "body": "<p>As CodesInChaos pointed out in the comments, a far more secure way to hash passwords is to use a deliberately expensive hash. This will all but eliminate any hope of a successful brute-force attack.</p>\n\n<p>The \"best\" algorithm I know of for this purpose would be <a href=\"https://en.wikipedia...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-05T10:58:41.920", "Id": "30814", "Score": "4", "Tags": [ "c#", "security", "cryptography" ], "Title": "Hashing passwords for a website" }
30814
<p>Consider the following:</p> <pre><code>If myString = "abc" Or myString = "def" [...] Or myString = "xyz" Then </code></pre> <p>In C# when <code>myString == "abc"</code> the rest of the conditions aren't evaluated. But because of how VB works, <em>the entire expression needs to be evaluated</em>, even if a match is...
[]
[ { "body": "<p>My 2 cents,</p>\n\n<p>the first function seems fine, you could make it a little DRYer by just setting the compareMethod in your if statement and then have only 1 complicated line of logic. And if you are doing that, you might as well put the Cstr's there.</p>\n\n<pre><code>Public Function StringCo...
{ "AcceptedAnswerId": "30844", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-05T12:12:34.683", "Id": "30816", "Score": "10", "Tags": [ "strings", "vba", "vb6" ], "Title": "A more readable InStr: StringContains" }
30816
<p>A while ago I implemented .net's <code>string.Format()</code> method in VB6; it works amazingly well, but I'm sure there has to be a way to make it more efficient.</p> <p>I'll start by listing a simple class called <code>EscapeSequence</code>:</p> <pre><code>Private Type tEscapeSequence EscapeString As String ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T00:11:27.193", "Id": "49096", "Score": "0", "body": "I'm thinking of moving parts of this into a class, but I want to stick to a `Public Function` in a simple code module, to avoid breaking existing code (and still be able to call i...
[ { "body": "<h1><strong>Key Points</strong></h1>\n\n<ul>\n<li>Each <code>Case</code> block implements formatting functionality for a specific format specifier.</li>\n<li><code>Goto</code> statements indicate the function <em>wants</em> to be broken down into several smaller functions.</li>\n<li>Local variables s...
{ "AcceptedAnswerId": "31000", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-05T12:43:12.027", "Id": "30817", "Score": "19", "Tags": [ "strings", "vba", "formatting", "vb6" ], "Title": "A CSharpish String.Format formatting helper" }
30817
<p>I need to make sure the correct menu item is highlighted according to which URL is currently being viewed. </p> <p>Now the problem with our site is that each menu item can represent several pages. So the Client menu will show the client list - but should still be highlighted when you go to the edit client page. So ...
[]
[ { "body": "<p>I'm not sure if my solution is relevant to your problem, but I had a similar problem with keeping the correct page selected on page refresh as refresh was resetting defaults and home would be selected on what ever page you refreshed from.</p>\n\n<p>This is how I solved it:</p>\n\n<p><strong>page c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-05T14:16:28.570", "Id": "30823", "Score": "2", "Tags": [ "javascript", "angular.js" ], "Title": "Adding a custom field to Routes - clever solution or terrible hack?" }
30823
<p>I am trying to evaluate if someone has read and seen all the questions of a book.</p> <p>I am using PHP to average everything out after I get the data. I know MySQL can avg, but I can't seem to wrap my head around how I can average the box number of the questions (similar to spaced repetition learning) if they have...
[]
[ { "body": "<p>What you have written is essentially six independent queries. Let's drop the pretense that these are correlated subqueries. Let's also reorder the output columns. We can also simplify <code>col = A || col = B</code> as <code>col in (A, B)</code>.</p>\n\n<pre><code>SELECT (SELECT COUNT(s.id)\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T04:52:57.833", "Id": "30824", "Score": "1", "Tags": [ "performance", "sql", "mysql", "mysqli" ], "Title": "Determining if someone has read and seen all the questions of a book...
30824
<p>Every coder knows that if you give six developers an assignment to write a bit of code that will perform some specific task, you will end up with at least six different ways of doing it.</p> <p>I recently realized/discovered a radical example of this. I wrote some code to calculate check digits for barcodes. I then...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-05T16:36:26.643", "Id": "49040", "Score": "1", "body": "I'm happy everyone kept the CzechSum." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-05T17:35:50.520", "Id": "49047", "Score": "0", "body...
[ { "body": "<p><strong>Caveat: I've never written a line of C#, nor do I know anything about its compiler.</strong></p>\n\n<p>I think that the approach taken in your code could be considered the more modern approach. It is definitely more suitable for human consumption, and it makes it more easy to test individu...
{ "AcceptedAnswerId": "30836", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-05T16:28:10.560", "Id": "30829", "Score": "3", "Tags": [ "c#", "comparative-review", "checksum" ], "Title": "Calculating Czechsum digits for barcodes" }
30829
<p>I'm not a great JS coder so I need your expertises to look into my code (although nothing very special and it works fine) to see if it is good practise or not because I heard that dodgy JS coding might slow down the site especially when it comes to reading mouse or user events.</p> <p><div class="snippet" data-lang...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T09:45:11.693", "Id": "49120", "Score": "2", "body": "In modern browsers you can simply use `<input placeholder=\"Site Search\">`. For older browsers you might be able to use a [polyfill](https://github.com/Modernizr/Modernizr/wiki/H...
[ { "body": "<p>This is the way I would approach it. Live demo here: <a href=\"http://jsbin.com/iHEgalU/3/edit\" rel=\"nofollow\">http://jsbin.com/iHEgalU/3/edit</a>\nSure, bad js can slow your site down. Something like this is going to be pretty fast no matter what you do (unless you go out of your way to make i...
{ "AcceptedAnswerId": "30834", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-05T16:53:05.297", "Id": "30832", "Score": "2", "Tags": [ "javascript", "html", "form", "event-handling" ], "Title": "Placeholder text for HTML search field" }
30832
<p>I am trying to implement strings tokenizer in Excel via UDF using C# and Excel-Dna. Personally I found the mIRC's function <a href="http://www.mirchelp.net/helpfile/token_identifiers.htm" rel="nofollow"><code>$gettok</code></a> pretty useful due to the lack of string functions in Excel.</p> <p><strong>Examples</str...
[]
[ { "body": "<p>In this statement:</p>\n\n<pre><code>for (int i = from; i &lt;= to; i++)\n {\n sb.Append(tokens[i - 1] + ((char)delimiter));\n }\n</code></pre>\n\n<p>The way that you have it written, I don't think that <code>i</code> will ever hit <code>to</code>.</p>\n\n<p>Also, I would change some ...
{ "AcceptedAnswerId": "30841", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-05T19:48:04.490", "Id": "30837", "Score": "7", "Tags": [ "c#", ".net", "excel" ], "Title": "String tokenizer via UDF" }
30837
<h2>The Problem</h2> <p>As an ASP.NET MVC4 developper, I'm using Entity Framework a lot. Considering performance I often use lazy loading for my models.</p> <pre><code>public class Result { public int Id { get; set; } public decimal Grade { get; set; } public virtual Skill Skill { get; set; } public i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-05T20:42:16.627", "Id": "49072", "Score": "0", "body": "Could you perhaps use AutoMapper or some other existing mapping service to do what you are wanting? I haven't used AutoMapper but sounds like what you might be looking for." },...
[ { "body": "<p>A simple option would be to use reflection to check for properties that are virtual and has the Id-suffix. This is where I came up with, working for me;</p>\n\n<pre><code>public static IQueryable&lt;T&gt; IncludeAll&lt;T&gt;(this IQueryable&lt;T&gt; queryable) where T : class\n{\n var type = typ...
{ "AcceptedAnswerId": "30867", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-05T20:36:33.053", "Id": "30839", "Score": "11", "Tags": [ "c#", "entity-framework", "asp.net-mvc-4" ], "Title": "DbSet<T> IncludeAll method" }
30839
<p>We are starting a new web project using C# / MVC4 and Entity Framework 5 for data access. I've decided to go with an n-layered approach for the structure of the project and I would like some feedback on my design decisions.</p> <p>This is how the solution is structured:</p> <ul> <li>Project.Model (Class Library): ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2018-08-28T11:19:02.193", "Id": "390518", "Score": "0", "body": "Related post - [ASP.NET MVC (Domain Model, Repository, Fluent, Services - Structure for my Project)](https://stackoverflow.com/q/1349640/465053) & [Best Structure for ASP.NET MVC...
[ { "body": "<p>It looks like you have dependencies hard coded into each layer.</p>\n\n<p>Service layer:\nHow do you plan to inject a mocked repository into your Logic Layer when unit testing it?\nWouldn't it make sense to inject these dependencies in via the constructor into your services once you've registered ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-05T20:52:45.087", "Id": "30843", "Score": "20", "Tags": [ "c#", "design-patterns", "entity-framework", "asp.net-mvc-4" ], "Title": "MVC Layered Project Structure" }
30843
<p>I am very new to Scala. I have done an exercise using Scala to solve the maximum path problem. </p> <p>Basically, I have a triangle of integers, I want to find the path from the top to bottom which the numbers on the route produces the largest sum. For example:</p> <pre><code> 5 12 3 2 4 9 ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T06:57:35.713", "Id": "49228", "Score": "0", "body": "I also used a similar approach to the one above, but added dynamic programming to speed up the algorithm so that you can use it to solve Problem 67 where the data set is pretty la...
[ { "body": "<p>In terms of algorithm, I think it is best to focus on the answer you are after. In This case you want the sum, but I notice your result returns the path and the sum.</p>\n\n<p>If you want to focus on the sum think about starting from the bottom, and accessing the best path in terms of the bottom ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-05T22:00:15.293", "Id": "30845", "Score": "6", "Tags": [ "scala" ], "Title": "Maximum path problem using Scala" }
30845
<p>My goal was to get the following code to work:</p> <pre><code>#include&lt;iostream&gt; #include&lt;vector&gt; #include&lt;list&gt; #include&lt;algorithm&gt; #include&lt;array&gt; #include"functional.hpp" int main( ) { std::vector&lt;double&gt; a{1.0, 2.0, 3.0, 4.0}; std::list&lt;char&gt; b; b.push_back...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2018-02-23T16:21:22.310", "Id": "359370", "Score": "0", "body": "I like the `special_decay` trick." }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2018-09-28T08:23:26.117", "Id": "394422", "Score": "0", "body":...
[ { "body": "<p>I have not much to say. Your code reads quite good, which is rather pleasant. Here are a few tidbits though:</p>\n\n<h2><code>typedef</code></h2>\n\n<p>If you are willing to write modern code, you should consider dropping <code>typedef</code> and using <code>using</code> everywhere instead. It hel...
{ "AcceptedAnswerId": "35429", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-05T22:26:56.717", "Id": "30846", "Score": "29", "Tags": [ "c++", "functional-programming", "c++11", "iterator" ], "Title": "\"Zip-like\" functionality with C++11's range-based...
30846
<p>Can someone improve this for me? It seems ugly. </p> <p>The method should test whether an incoming number is a palindrome and return a Boolean result.</p> <pre><code>private static bool IsPalindrome(int value) { var inverseValue = string.Concat(value.ToString().Reverse()); return inverseValue == value.ToSt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T00:03:37.303", "Id": "49094", "Score": "5", "body": "What's ugly? Looks pretty succinct to me." } ]
[ { "body": "<p>Looks o.k. and clear to me.\nBut you can reduce it to one line, if you want.</p>\n\n<pre><code>private static bool IsPalindrome(int value){\n return string.Concat(value.ToString().Reverse()) == value.ToString();\n}\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-S...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-05T23:27:09.467", "Id": "30847", "Score": "6", "Tags": [ "c#", "palindrome" ], "Title": "Determining whether a number is a palindrome" }
30847
<h3>Background</h3> <ul> <li>Python (version 2.7.2)</li> </ul> <h3>Problem</h3> <ul> <li>You want to specify an array in your code.</li> <li>You want to use the 'syntax sugar' available in Ruby and Perl.</li> <li>You are a fanatic about readable code but also saving keystrokes.</li> </ul> <h3>Solution</h3> <ul> <l...
[]
[ { "body": "<p>This will work as written. You could shorten it slightly by replacing </p>\n\n<pre><code>if(not item.strip()=='')\n</code></pre>\n\n<p>with </p>\n\n<pre><code> if item.strip()\n</code></pre>\n\n<p>You're also calling strip twice, you could skip that with:</p>\n\n<pre><code>array_names = [i for i i...
{ "AcceptedAnswerId": "30861", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T02:05:52.430", "Id": "30849", "Score": "1", "Tags": [ "python", "python-2.x" ], "Title": "Python array literal syntax sugar similar to Perl and Ruby" }
30849
<p>I recently had to write a function to return characters missing from an input string. Here is the snippet</p> <pre><code>#include &lt;bitset&gt; #include &lt;string&gt; template&lt;class Iterator&gt; std::string getMissingLetters(Iterator begin, Iterator end) { std::bitset&lt;26&gt; letters; for (auto i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T03:44:58.213", "Id": "49105", "Score": "0", "body": "I'd use `std::size_t` specifically, especially in the second `for`-loop." } ]
[ { "body": "<p>Bug, should be:</p>\n\n<pre><code>if (c &gt;= 26) continue;\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T05:03:48.783", "Id": "49107", "Score": "0", "body": "Not sure why this was down voted. It c...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T03:09:13.693", "Id": "30851", "Score": "4", "Tags": [ "c++" ], "Title": "Review of a C++ missing characters snippet" }
30851
<p>I have the following HTTP reply saved in a local file called <code>source.txt</code>:</p> <blockquote> <pre class="lang-none prettyprint-override"><code>HTTP/1.1 301 Moved Connection: close Content-length: 111 Location: https://11.12.13.14:81/ Content-type: text/html; charset="utf-8" &lt;html&gt;&lt;head&gt;&lt;...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T16:15:44.173", "Id": "49214", "Score": "0", "body": "What about at least a minimal description on what this functions should do?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-08T12:35:42.600", "Id"...
[ { "body": "<p>Your <code>getLocation</code> can be improved a little:</p>\n\n<p>For a start, the call parameter should be <code>const</code> (although if you were happy\nmodifying the string you could avoid the memory allocation).</p>\n\n<p>Moving on:</p>\n\n<pre><code>const char *p1 = strstr(source, \"Location...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T03:42:08.850", "Id": "30852", "Score": "2", "Tags": [ "c", "strings", "http", "socket" ], "Title": "Extract location from HTTP socket" }
30852
<p>I know that the <code>DBContext</code> represents a session (Unit-Of-Work and Repository) with the database, however I an unsure as to when I should have a different <code>DBContext</code>. Currently, I have a separate <code>DBContext</code> for each table with a single <code>DBSet</code> for each <code>DBContext</c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T06:56:35.307", "Id": "49110", "Score": "0", "body": "I suppose one option is to use the Repository and Unit of Work Patterns to manage this across a single repository, but that starts to look like quite a lot of work for a simple si...
[ { "body": "<p>As you have already mentioned, DbContext <em>is</em> a UoW, and DbSet <em>is</em> a repository -- there is no need to reimplement those patterns, unless you're into ridiculously useless complexity.</p>\n\n<p>Entity Framework wraps all pending changes in a transaction for you already, so each DbCon...
{ "AcceptedAnswerId": "31165", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T04:36:23.720", "Id": "30856", "Score": "17", "Tags": [ "c#", "asp.net", "entity-framework", "asp.net-mvc-3", "asp.net-mvc-4" ], "Title": "Using separate DBContext class...
30856
<p>I have this piece of code:</p> <pre><code>List&lt;myItem&gt; items = (from x in db.myItems join y in db.tblParents on x.item_parent equals y.id where !y.hidden orderby x.name select x).ToList(); </code></pre> <p>And it ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T15:48:12.430", "Id": "49145", "Score": "2", "body": "Does the equivalent TSQL join run any faster in SSMS?" } ]
[ { "body": "<p>I honestly don't see anything particularly wrong with that Linq query, but there are a number of other things you should consider:</p>\n\n<ul>\n<li>Converting the query to a <code>List&lt;T&gt;</code> forces immediate evaluation of the query and requires the allocation of an single, contiguous por...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T06:19:11.630", "Id": "30862", "Score": "4", "Tags": [ "c#", "linq", "database", "join" ], "Title": "Optimizing join statement" }
30862
<h1><code>static</code> in OO context</h1> <p><code>static</code> methods, are methods defined in the context of a type, or class, that can be invoked without having to create an instance of that type. As a result, the method has access to hidden (<code>protected</code> or <code>private</code>) properties and methods....
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T06:56:20.883", "Id": "30864", "Score": "0", "Tags": null, "Title": null }
30864
The static keyword, in object-oriented programming languages, is used to define a function/method or field/property as bound to the context of a type/class, but not to any specific instance. Unlike constants, static properties can usually be changed at runtime. static also refers to the storage class in languages like...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T06:56:20.883", "Id": "30865", "Score": "0", "Tags": null, "Title": null }
30865
<p>I'm developing and app that communicates via Bluetooth with another PCB. It consists of 3 seekbars that regulates the value of 3 parameters of the PCB.</p> <p>The structure is this:</p> <ol> <li>Send petition string for read the first value</li> <li>Receive the first value</li> <li>Send petition string for read th...
[]
[ { "body": "<p>It is quite hard to see what you are trying to achieve from your code. I think that you have two separate applications communicating over Bluetooth and that is working. However the way that you are coding the read/write methods is never going to work. Whoever said not to code the 1 second wait is ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T07:25:11.227", "Id": "30866", "Score": "2", "Tags": [ "java", "android", "bluetooth" ], "Title": "App for communicating with another PCB via Bluetooth" }
30866
<p>The program listens to the Altera FPGA DE2 board's keys that can start and stop and reset a counter:</p> <pre><code>#include &lt;stdio.h&gt; #include "system.h" #include "altera_avalon_pio_regs.h" extern void puttime(int* timeloc); extern void puthex(int time); extern void tick(int* timeloc); extern void delay(int ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T13:02:35.140", "Id": "49134", "Score": "3", "body": "Too many magic numbers, it's hard to understand the purpose of the program." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T15:11:14.633", "Id"...
[ { "body": "<p>You need to change the naming convention. Obviousy you can't do that for the API provided for the FPGA but for the function's name as well as variable names you need to change that a bit.</p>\n\n<p>Like <code>hex7seg</code> should be changed <code>hex7seg_lower</code> and <code>hex7seg2</code> sho...
{ "AcceptedAnswerId": "30915", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T10:25:03.153", "Id": "30870", "Score": "3", "Tags": [ "c", "assembly", "fpga" ], "Title": "Polling for Nios 2" }
30870
<p>I have a solution in which I instantiate a class with various types inside of it. I feel it is becoming to cumbersome to instantiate and then create variables for each of the types I want to access in the class (Option 2 in the code), so I've come up with a custom return type so I only have to return data once for...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T12:51:42.757", "Id": "49133", "Score": "1", "body": "For immutable types its mostly a performance choice depending on the size of the class/struct. For mutable types, go with the class." } ]
[ { "body": "<p>This <a href=\"http://msdn.microsoft.com/en-us/library/ms229017.aspx\" rel=\"nofollow\"><code>MSDN Page</code></a> states:</p>\n\n<blockquote>\n <p><strong>CONSIDER</strong> defining a struct instead of a class</p>\n \n <ul>\n <li>if instances of the type are small and commonly short-lived or ...
{ "AcceptedAnswerId": "30873", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T11:58:36.667", "Id": "30872", "Score": "3", "Tags": [ "c#", "design-patterns", "classes" ], "Title": "Is the use of Struct or Class personal preference?" }
30872
<p>I need to inject same variables into settings.py for multiple django apps.hence i wrote a module which takes in output of local() and modifies. This works but is it the right way to do things?</p> <pre><code>def enable_theme(theme_name, container): """ Enable the settings for a custom theme, whose files should be s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T13:15:29.060", "Id": "49135", "Score": "0", "body": "The code you posted doesn't use `local()`. Also, you need to format your code so that it shows up correctly." } ]
[ { "body": "<p>You're not trying to modify a local environment, you're trying to modify the module's dictionary, which you can access by calling <a href=\"http://docs.python.org/2/library/functions.html#globals\" rel=\"nofollow\"><code>globals()</code></a>.</p>\n\n<p>Note: the dictionary returned by <a href=\"ht...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T13:00:16.247", "Id": "30875", "Score": "1", "Tags": [ "python", "django" ], "Title": "modifying local environment in python" }
30875
<p>I am using VBA to manipulate the global address book in Outlook. My method takes a contact and returns a complete list of everyone who reports through that person based on the Outlook org structure.</p> <p>Unfortunately it takes quite some time to run, even for a single manager. I'm not really sure what is the be...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T16:09:34.097", "Id": "49149", "Score": "1", "body": "See the remarks section here : http://msdn.microsoft.com/en-us/library/office/ff866704.aspx I dont think your code is the problem." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>not sure that this will help with the Speed/Performance of the script but I am thinking that you should change your <code>do while</code> like this</p>\n\n<pre><code>Dim keepLooping as boolean \nkeepLooping = True\nDo While keepLooping = True\n keepLooping = False\n</code></pre>\n\n<p>and then ...
{ "AcceptedAnswerId": "33484", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T13:54:03.897", "Id": "30876", "Score": "6", "Tags": [ "performance", "vba", "outlook" ], "Title": "Manipulating the global address book in Outlook" }
30876
<p>I need to optimize this code so it can execute faster, even if that means using more memory:</p> <pre><code>for (int t = 0; t &lt; Clientes[0].ChildNodes.Count; t++) { for (int i = 0; i &lt; Clientes[0].ChildNodes.Item(t).ChildNodes.Count; i++) { if (Clientes[0].ChildNodes.Item(t).ChildNodes.Item(i)...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T15:50:55.273", "Id": "49146", "Score": "1", "body": "“let me know if you think that my approach will improve the speed” You need to measure that yourself. Guessing about speed is night impossible." }, { "ContentLicense": "CC...
[ { "body": "<ul>\n<li><p>Make <code>Queues[t].Send(QueueMessage);</code> asynchronous if it is not. This will be the best means to speed up your looping. Then have it handle the exception rather than this loop.</p></li>\n<li><p>If you're not expecting exceptions when calling Send, then having the <code>Try/Cat...
{ "AcceptedAnswerId": "30894", "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T14:45:05.193", "Id": "30881", "Score": "7", "Tags": [ "c#", "performance", "linq" ], "Title": "How to optimize these nested loops for better performance?" }
30881
<p>The array is dynamic, can be with 7 or more keys, except the first key never changes.</p> <pre><code>Array ( [0] =&gt; Array ( [ProviderID] =&gt; 1010 [ProviderName] =&gt; HAMZEPOUR, SHOKOUFEH ...
[]
[ { "body": "<p>The answer depends on what you want when you say 'efficient'. In my opinion, you should be using either a stdClass object with an array of Contacts, an array of Algorithms, etc. This will be more memory-intensive, but unless you are running in crazy looping structures then you will not notice any ...
{ "AcceptedAnswerId": "31567", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T16:21:53.317", "Id": "30884", "Score": "0", "Tags": [ "php", "array", "php5" ], "Title": "Is this an efficient way of organize an array?" }
30884
<p>I previously posted a <a href="https://codereview.stackexchange.com/questions/30764/review-of-reservoir-sampling">Reservoir-Sampling program</a>, which was basically a test version of this one. This is an assignment. In the code below, I use <code>RunTimeException</code> to control when scanner finishes reading dat...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T19:16:37.863", "Id": "49162", "Score": "0", "body": "Well possibly the task is bananas. Could you edit the post with what you are trying to achieve and the exact limitations of the question. If `stdin` is nothing to do with your sol...
[ { "body": "<p>Finished in the comments, can you post the part of the assignment question pertinent to your limited library usage and main method only code? Anyway, if you have been told that a RTE will signify the end of the reading (rather than the null) then this seems marginally better as it makes it clear w...
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T18:38:21.857", "Id": "30888", "Score": "2", "Tags": [ "java", "homework", "error-handling" ], "Title": "Exceptions to control data read flow" }
30888
<p>I'm trying to design a <code>Shader</code> class. For now, I'm just trying to get basic outline for handling uniforms. Some design goals I aimed for is to avoid passing a string to a function as this is error prone and has no type checking. There's really only one place this can go wrong: if you mistype the name o...
[]
[ { "body": "<blockquote>\n <p>What are you thoughts on this implementation?</p>\n</blockquote>\n\n<p>It is simply awful. Besides code bloat, just look how you declare such objects, and how you call methods on such objects.</p>\n\n<blockquote>\n <p>Do you have suggestions for improvements or perhaps an entirely...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T20:02:58.757", "Id": "30893", "Score": "4", "Tags": [ "c++", "classes", "opengl" ], "Title": "Shader class implementation" }
30893
<p>I wrote this class to make cookie management easier.</p> <p>I know it makes use of <code>serialize()</code>, but I have no intention of storing very much data in the cookie, and it seemed a cleaner solution than, say, the JSON functions (like, even if a class implements the <code>JSONSerializable</code> interface, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T16:51:56.357", "Id": "49219", "Score": "0", "body": "Don't use the closing `?>` in definition files (PHP recommends not using the closing tag!). If a file is called `something.class.php`, I'd expect it to contain _only_ a class defi...
[ { "body": "<p>First off, I've posted a fairly length answer on the subject of request classes, which can be found <a href=\"https://codereview.stackexchange.com/questions/29469/critique-request-php-request-method-class/29485#29485\">here</a>. Because you state you're thinking of writing a <code>Session</code> c...
{ "AcceptedAnswerId": "30975", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T20:30:35.363", "Id": "30895", "Score": "4", "Tags": [ "php", "object-oriented", "classes", "recursion", "php5" ], "Title": "Cookie Management Class" }
30895
<p>Please review the following Clojure tokenizer. The goal is to study Clojure, so sometimes I re-implement functions (it will be nice to see standard functions for this). Beyond of this, code seems quite cumbersome.</p> <pre><code>(defn space? [^Character c] (Character/isWhitespace c)) (defn digit? [^Character c] ...
[]
[ { "body": "<p>I don't know if you're still at it (given it's been a few months) ; in any case, here's my answer (it could be useful to someone, who knows).</p>\n\n<ul>\n<li><p>speaking of standard functions, maybe you could leverage the Clojure reader e.g.:</p>\n\n<pre><code>(def to-int (comp read-string #(appl...
{ "AcceptedAnswerId": "36396", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T00:38:51.070", "Id": "30899", "Score": "10", "Tags": [ "parsing", "clojure" ], "Title": "Clojure tokenizer" }
30899
<p>Aspects of combinatorics include:</p> <ul> <li><strong>enumerative combinatorics</strong>: counting the structures of a given kind and size</li> <li><strong>combinatorial designs</strong> and <strong>matroid theory</strong>: deciding when certain criteria can be met, and constructing and analyzing objects meeting t...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T02:35:26.243", "Id": "30902", "Score": "0", "Tags": null, "Title": null }
30902
Combinatorics is a branch of mathematics concerning the study of finite or countable discrete structures.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T02:35:26.243", "Id": "30903", "Score": "0", "Tags": null, "Title": null }
30903
<pre><code>module A def methodInA # do stuff methodInB # do stuff end end module B def methodInB puts "this is a B method!" end end class C extend A extend B def initialize methodInA end end c = new C </code></pre> <p>I'm not feeling good about this. Is this a good idea in gene...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T16:24:34.640", "Id": "49450", "Score": "2", "body": "Not a real answer, but a lot of people use [`ActiveSupport::Concern`](http://api.rubyonrails.org/classes/ActiveSupport/Concern.html) to manage module dependencies. The linked page...
[ { "body": "<p>Since inheritance and interface both has some problems of their own, high level languages like ruby, python supports a different way for organizing code- Mixin. </p>\n\n<p>The code you have written involves mixin, you can see this as interface with implemented methods.When a class can inherit feat...
{ "AcceptedAnswerId": "31509", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T09:30:45.877", "Id": "30909", "Score": "3", "Tags": [ "ruby" ], "Title": "Calling methods of another module from a module, from a class extending both?" }
30909
<p>We have two log files in which one is generated from a process. We compare one file(golden file) to another file to check if file correct or not. It should have same value. We generally use diff utility to compare two files. I have got enhancement to add machine information into process generated File. So I want to ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T14:11:18.030", "Id": "49206", "Score": "2", "body": "Just to be sure, you want to compare the 2 files after deleting the last line from `Process File`. Correct? If correct then why are you deleting the last line in data. Wouldn't th...
[ { "body": "<p>There is no need for python here, you can use the <code>head</code> command to filter out the last line of a file:</p>\n\n<pre><code>diff &lt;(head -n -1 \"Golden_File\") &lt;(head -n -1 \"cp.log\")\n</code></pre>\n", "comments": [], "meta_data": { "CommentCount": "0", "Content...
{ "AcceptedAnswerId": "30920", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T13:10:29.767", "Id": "30912", "Score": "2", "Tags": [ "python" ], "Title": "Compare File with ignore some line/last line" }
30912
<p>I have a class that stores the data related to all employees in a particular department. In this class, I am having a list of employees and other fields. Also, I am having a property which returns a <code>bool</code>, indicating whether an employee exists or not. I am a bit confused regarding the naming of this pro...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T18:47:04.377", "Id": "49227", "Score": "5", "body": "`DoesEmployeeExists` is grammatically incorrect. At least use `DoesEmployeeExist`. But +1 to `Has*`/`Is*`, guitar_freak beat me to it." }, { "ContentLicense": "CC BY-SA 3....
[ { "body": "<pre><code>class Employee_Details\n</code></pre>\n\n<p>This class is badly named. First, .Net naming conventions say you shouldn't use underscore for this, the class should be called <code>EmployeeDetails</code>. Second, the name seems to imply it contains details about a single employee. Better name...
{ "AcceptedAnswerId": "30923", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T14:57:44.847", "Id": "30914", "Score": "10", "Tags": [ "c#" ], "Title": "Boolean naming convention" }
30914
A field-programmable gate array (FPGA) is an integrated circuit designed to be configured by a customer or a designer after manufacturing.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T15:48:21.940", "Id": "30919", "Score": "0", "Tags": null, "Title": null }
30919
<p>I am creating a small app working on file system. The user can choose a directory and than, application get one of the possible result (examples):</p> <ul> <li>return number of lines in all *.java files</li> <li>return number of lines in all *.java files without comments</li> <li>return number of all classes</li> <...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T17:43:34.033", "Id": "49223", "Score": "0", "body": "The fact, that classes behave similarly doesn't mean they need to implement the same interface. You need an interface, if some code will have to work with any of those classes. Ho...
[ { "body": "<p><strong>Normally when you need \"different return types\"</strong>, you can use <a href=\"http://docs.oracle.com/javase/tutorial/java/generics/\" rel=\"nofollow\">generics</a>. However, since you want these <code>Counter</code>s to be in a List of some sort, using generics goes out the window sinc...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T16:46:55.570", "Id": "30922", "Score": "1", "Tags": [ "java", "interface" ], "Title": "Common interface with different return types" }
30922
<p>I have this function which is associated with a timer that I'm creating in AngualarJS. Should I be concerned about the function being able to execute quickly enough for the timer to be accurate.</p> <pre><code>$scope.start = function() { if($scope.counting === true) return false; $scope.counting = true; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T17:25:50.670", "Id": "49221", "Score": "1", "body": "Already creating one closure costs more than 10000 math functions and kills 13 kittens" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T17:31:17.077...
[ { "body": "<p>After digging around a bit, it seems the most appropriate approach for this is to create a kind of \"fix\" for latency resulting from CPU time that will quickly cause inaccuracies in a javascript timer. I wrote the below to demonstrate. As you can see, the <code>setTimeout</code> named <code>timer...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T17:24:02.527", "Id": "30924", "Score": "1", "Tags": [ "javascript", "performance", "angular.js" ], "Title": "Is it reasonable to expect this AngularJS function to perform well?" }
30924
<p>Very easy question for these who spend some time on analyzing code written by co-workers. </p> <p>When I write my code, I do my best to write it in a very, extremely readable way. But sometimes I have an impression, that I write it too easy... Simple example:</p> <p>When I see such a code:</p> <pre><code>public C...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-08T15:05:33.210", "Id": "49265", "Score": "0", "body": "I like your idea of formatting every condition on a new line, but the automatic formatter (yours, or your co-workers') will probably destroy that at some point." }, { "Con...
[ { "body": "<p>Does the method <code>getCategoryType</code> need to know everything about a <code>Component</code>? Maybe its logic can be satisfied (and tested) with only this:</p>\n\n<pre><code>public Category getComponentCategoryType(boolean hasSensor, \n boolean hasInp...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-07T18:56:37.870", "Id": "30926", "Score": "6", "Tags": [ "java" ], "Title": "Long conditionals in ifs" }
30926
<p>For a simple project, I represent a two-dimensional grid as a one-dimensional array, with both row and column indices between <code>1</code> and <code>gridHeight</code>. When retrieving a cell from the grid, I first need to check if both row and column IDs are within allowed bounds.</p> <pre><code>public void check...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T08:45:31.397", "Id": "49293", "Score": "1", "body": "throw out all your checkIfAllowed stuff - you'll still get IndexOutOfBoundsException, though without message (which is not informative anyway)" }, { "ContentLicense": "CC ...
[ { "body": "<p>Not sure if I've understood yout question correctly, but I assume, that your grid is a square grid (you test both, maximal high and width, as a lower than grid's height).</p>\n\n<p>Referring to your first question:\nThere are many options. You can make a method which takes two parameters at a time...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-08T02:59:21.310", "Id": "30937", "Score": "2", "Tags": [ "java", "array", "exception-handling" ], "Title": "Checking if an index is out of bounds" }
30937
<p>This is a question about whether my coding style follows AngularJS best practices. </p> <p>One of the selling points to Angular is directives. Directives allow you to create custom DOM with elements or attributes you create. I've found myself creating lots of directives, thinking of each one as little controls to b...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-11-13T10:17:24.720", "Id": "203899", "Score": "0", "body": "Old question, however.. avoid `ng-controller` (its not reusable), use custom directives and TDD those directives. You should use HTML as your vehicle of user state instead of rel...
[ { "body": "<p>AngularJS encourages <strong>slim controllers</strong>. They'd rather you have fat directives and services than controllers.</p>\n\n<p>I think you are absolutely correct to have many directives.</p>\n\n<p>In my angular apps, I have some directives without <code>link</code> to make my templates cle...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-08T03:01:31.257", "Id": "30938", "Score": "7", "Tags": [ "javascript", "angular.js" ], "Title": "In AngularJS, create lots of directives or use ng-controller?" }
30938
<p>I'm not sure if this implementation is good enough. The function takes a vector of 1 million chars and creates a table of the sequences that pass before the next occurrence of itself.</p> <p>Some questions I have, though feel free to point other things out as well:</p> <ul> <li>Is the initialization of the hash-m...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-08T08:32:52.817", "Id": "30945", "Score": "1", "Tags": [ "lisp", "scheme", "vectors", "hash-map", "racket" ], "Title": "Creating an updating hash table" }
30945
<p>I've been learning Java for about 3 weeks now, and I was hoping someone could check over my code for me, and let me know how to improve.</p> <p>I am aware that the maths class could be removed (I could've typed <code>answer = inputA * inputB</code> etc. within the switch statement) but this is just because I wanted...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T11:58:53.817", "Id": "49421", "Score": "0", "body": "rhetorical question: why does java use: `public static double sqrt(double a)` ? see the API http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#sqrt%28double%29. hint...
[ { "body": "<ul>\n<li><p><code>power</code> should probably be using <code>Math.pow()</code>. I'm picturing how slow your code would be at calculating 1.0000001<sup>5000000</sup>. Or how inaccurate it'll be when someone wants to raise to a non-integer power. If those are not intended to be allowed, then passi...
{ "AcceptedAnswerId": "30953", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-08T11:02:31.660", "Id": "30950", "Score": "11", "Tags": [ "java", "beginner", "calculator" ], "Title": "Simple calculator in Java" }
30950
<p>------edit---------</p> <p>note: this is for a <a href="http://en.wikipedia.org/wiki/Mud_client" rel="nofollow">MUD client</a>, so the commands are issued to the MUD game server</p> <p>-----end edit--------</p> <p>For an overview, here's the structure of the project:</p> <pre><code>NetBeansProjects/TelnetConsol...
[]
[ { "body": "<p>1) (Minor Detail) Don't make PlayerCharacter a singleton. I understand it only occurs once, but it seems overkill to make it a singleton, and making it an enum is even more confusing.</p>\n\n<p>2) PlayerFlags should instead be an <code>EnumMap&lt;Flag, Boolean&gt;</code> where Flag is a simple en...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-08T11:15:57.107", "Id": "30951", "Score": "2", "Tags": [ "java", "design-patterns", "singleton" ], "Title": "Singleton has logic and state, and logic has state" }
30951
<p>I really need a review on the structure, and how things are done. I want to improve.</p> <p>Command.class:</p> <pre><code>&lt;?php /** * Command * Processing commands to the server, acting, receiving response. * * @author Jony &lt;driptonethemes@gmail.com&gt; */ class Command ex...
[]
[ { "body": "<ol>\n<li>Stop using underscore to indicate private/protected parts of a class.</li>\n<li>Do not put logic in the constructors</li>\n<li>It is pointless to have <code>... ? true : false;</code> in <code>isUsingCommand()</code>.</li>\n<li>Use <a href=\"http://uk3.php.net/manual/en/function.implode.ph...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-08T12:25:54.790", "Id": "30954", "Score": "2", "Tags": [ "php", "object-oriented" ], "Title": "Object-oriented command processor" }
30954
<p>I just finished a widget clock that displays the actual seconds and changes an <code>ImageView</code> each 15 minutes. I have used a <code>BroadcastReceiver</code> with <code>AlarmManager;</code>. I also have setup a click on an <code>ImageView</code> to change it for another image and play a sound, and this image...
[]
[ { "body": "<p>Well, after doing some research and testing, I think the BroadcastReceiver is the best way to create a clock, however the update each second can drain the battery, in some phones is not noticeable, but I prefered to update it each minute, I personally do not recommend using services or handler sin...
{ "AcceptedAnswerId": "30959", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-01T21:06:14.300", "Id": "30958", "Score": "2", "Tags": [ "java", "android", "datetime" ], "Title": "A Widget Clock with seconds" }
30958
<p>I've been doing a lot of searching on PHP, logins, forms, cookies, sessions, etc. And so, I've tried to gather all the info that I got from all over the place. But, I didn't find a place with all the info, and tried to do the best secure login I could do.</p> <p>This is what I have. If this ends up being good, o...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-08T19:19:26.860", "Id": "49273", "Score": "0", "body": "You might want to read this article: http://phpsec.org/projects/guide/4.html and place a session_destroy / session_regenerate_id in your Check.php code." }, { "ContentLice...
[ { "body": "<p>Some comments:</p>\n\n<pre><code>if($_SERVER[\"HTTPS\"] != \"on\")\n</code></pre>\n\n<p>See: <a href=\"https://stackoverflow.com/a/2886224/59087\">https://stackoverflow.com/a/2886224/59087</a></p>\n\n<p>Avoid calling <code>exit()</code> from more than one location.</p>\n\n<p>The following code is ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-08T18:59:27.573", "Id": "30962", "Score": "4", "Tags": [ "php", "security", "session" ], "Title": "Is this a safe Login?" }
30962
<p>I am trying to learn events and delegates in C#. To do that I am trying to create a hypothetical console project where when some user submits the orders in his/her shopping cart, I need the Billing department and mailing department to handle that event. Can someone please critique this code for doing the same?</p> ...
[]
[ { "body": "<p>The standard signature for an event-handler delegate is</p>\n\n<pre><code>void HandlerName(object sender, HandlerArgs args)\n</code></pre>\n\n<p>Where <code>HandlerArgs</code> inherits from <code>System.EventArgs</code></p>\n\n<p>So to follow this convention, you should create a new class:</p>\n\n...
{ "AcceptedAnswerId": "30966", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-08T23:46:53.153", "Id": "30965", "Score": "6", "Tags": [ "c#", "event-handling", "delegates", "e-commerce" ], "Title": "Shopping cart using events and delegates" }
30965
Vectors are sequence containers representing arrays that can change in size. For questions about geometric or algebraic vectors, use [coordinate-system] instead.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T00:43:53.157", "Id": "30969", "Score": "0", "Tags": null, "Title": null }
30969
<ul> <li>the asterisk (*) typically represents zero or more characters in a string of characters</li> <li>the question mark (?) typically represents any one character</li> </ul>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T01:00:16.100", "Id": "30970", "Score": "0", "Tags": null, "Title": null }
30970
A wildcard character is a special character that represents one or more other characters.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T01:00:16.100", "Id": "30971", "Score": "0", "Tags": null, "Title": null }
30971
<p>This is a simple jQuery script that I use to vertically center elements on pages. It's quite simple, but I would love to know if there is room for improvement.</p> <pre><code>(function( $ ){ $.fn.flexVerticalCenter = function( onAttribute, verticalOffset, parentSelector ) { return this.each(function()...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T02:38:34.857", "Id": "49283", "Score": "1", "body": "This is well written code, I don't think you will find any improvements here, congrats :)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T02:44:41....
[ { "body": "<p>From the comments above, I think the code is ok :)</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T15:49:40.183", "Id": "31110", "ParentId": "30972", "Score": "1" } } ]
{ "AcceptedAnswerId": "31110", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T02:13:39.347", "Id": "30972", "Score": "5", "Tags": [ "javascript", "jquery", "optimization" ], "Title": "Optimising this simple jQuery script that vertically centers elements ...
30972
<p>Currently, the code below looks awful because of all the callbacks involved. How can I reduce the amount of nesting? Also, would you recommend the use of q or Async.js?</p> <pre><code>var mongoose = require('mongoose'); var User = require('../models/user.js'); var Genre = require('../models/genre.js'); var Album =...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T14:11:33.957", "Id": "49307", "Score": "0", "body": "Just to be clear: all those `create` methods take a callback because they create the item on the server and they execute the callback when it is done?" } ]
[ { "body": "<ol>\n<li>The code does not look awful. It is normal async JavaScript.</li>\n<li>No, in this case I would not recommend to to use Async, step or sth. else.</li>\n<li>When you have got used to async programming, you will understand 1. and 2.</li>\n</ol>\n", "comments": [ { "ContentLi...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T04:09:04.163", "Id": "30973", "Score": "6", "Tags": [ "javascript", "node.js" ], "Title": "Avoiding callback hell" }
30973
<p>I append the DOM elements dynamically, and when the data gets changed i use to hide and show lots of DOM elements. How do I improve my code?</p> <pre><code>str_user_details += '&lt;tr &gt;&lt;td class="td_edu td_pad" colspan="2"&gt;&lt;div class="div_edu"&gt;&lt;span class="headings"&gt;Education &lt;/span&gt; &lt;...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T09:19:32.147", "Id": "49295", "Score": "6", "body": "There's not enough info here to really answer the question. A decently sized sample of the actual code would probably help." } ]
[ { "body": "<p>Well for one thing I know you can replace this...</p>\n\n<pre><code>$jq('#create_account').css('display','none');\n$jq('#wrong_user').css('display','none'); \n</code></pre>\n\n<p>With...</p>\n\n<pre><code>$jq('#create_account').hide();\n$jq('#wrong_user').hide()\n</code></pre>\n\n<p>Same with...<...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T08:51:16.573", "Id": "30976", "Score": "-1", "Tags": [ "javascript", "jquery" ], "Title": "Hiding and showing DOM elements dynamically" }
30976
<p>I'd really appreciate if any of you could do a code review of my Sopping cart demo. I was wondering whether this could be improved? I'm honestly trying to improve myself too!</p> <p>There's a small problem on the product list! looks like doest work if has more than 1 product. Demo: <a href="http://plnkr.co/edit/jLk...
[]
[ { "body": "<p>This code style is not very good, becouse u declare functions inside a function. The problem with this is that you recreate all this functions every time u run \"shoppingCart\" function.</p>\n\n<p>Instead try using this pattern;</p>\n\n<pre><code>(function(){\n\n //my private functions delare\n...
{ "AcceptedAnswerId": "30986", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T12:51:20.220", "Id": "30982", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Jquery shopping cart code review" }
30982
<p>I use two lists of objects invoices, original list and a new modified list. I would insert in db invoices presents in the new modified list but not presents in the original list.</p> <p>For delete, I would remove from db invoices presents in the original list but absent in the new modified list.</p> <p>This is wha...
[]
[ { "body": "<p>1) In your <code>for</code>-loop, when the <code>if</code> is true, you should not only set <code>coupleFind = true</code>, but also add a <code>break</code> since you keep looping for nothing otherwise.</p>\n\n<p>2) I'm not sure why the customerId is not already part of the invoice.</p>\n\n<p>3) ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T13:20:00.703", "Id": "30984", "Score": "1", "Tags": [ "java", "algorithm" ], "Title": "Algorithm for comparing two lists of objects, to insert added items, and delete removed items" }
30984
<p>I've written a vocabulary trainer which does a lot of passing state around, as I have an ACID-database and a temporary state.</p> <p>In my experience with Haskell I've learnt that overusing <code>IO ()</code> is a code smell, I think that this is also true for state.</p> <p>Please have a look at the following <cod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T12:28:05.377", "Id": "49428", "Score": "1", "body": "I believe the _prompt_ monad would be an answer to your problem. See [this post](https://groups.google.com/forum/#!topic/fa.haskell/XfX6LKlpheA) and [this paper](http://web.mit.ed...
[ { "body": "<p>I have a few suggestions:</p>\n\n<ol>\n<li>Instead of functions recursively call each other, have a single master dispatching function that calls <code>command</code>, <code>control</code>, <code>guess</code> etc. This will give a central overview how the whole process works. Otherwise it's very d...
{ "AcceptedAnswerId": "31083", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T14:32:32.047", "Id": "30989", "Score": "2", "Tags": [ "haskell", "io", "quiz", "state" ], "Title": "Vocabulary trainer passing around too much IO/State" }
30989
<p>Yesterday I found some nice video from some IT conference about removing if statements from code. I saw a very nice example of refactoring. I am curious what do you think about it, especially what weak points do you see in such approach.</p> <p>1) We have a class with very "nice" method:</p> <pre><code>public int ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T12:25:05.980", "Id": "49426", "Score": "0", "body": "is the code for `Component` available? I think there-in lies your problem. Shouldn't this logic be right in that class?" }, { "ContentLicense": "CC BY-SA 3.0", "Crea...
[ { "body": "<p>Personally, I wouldn't use that approach, because of the amount of boilerplate code and complexity it introduces. Adding N+1 classes, where N is the number of conditions, just seems like overkill to me.</p>\n\n<p>First off, I don't think that the method at hand must necessarily be refactored. I ag...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T14:52:54.087", "Id": "30990", "Score": "9", "Tags": [ "java" ], "Title": "Many if statements - refactoring" }
30990
<p>Is there a way to simplify the code below? I want to simplify it, but I don't know if it is possible.</p> <p>In the table below, I insert data which will end up in a MySQL table.</p> <p>HTML</p> <pre><code>&lt;table border="0"&gt; &lt;tr&gt; &lt;td align="center"&gt;Dată / Interval orar&lt;/td&gt; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T18:51:52.750", "Id": "58052", "Score": "0", "body": "The mysql extension has been deprecated; no longer in active development, and no longer supported in php5.5x. Using the old mysql extension will make your code less future proof. ...
[ { "body": "<h2>Use indexing in HTML name attributes</h2>\n\n<pre><code>&lt;table&gt;\n &lt;tr&gt;\n &lt;td&gt;Dată / Interval orar&lt;/td&gt;\n &lt;td&gt;Denumire&lt;/td&gt;\n &lt;td&gt;Moderatori&lt;/td&gt;\n &lt;td&gt;Detalii&lt;/td&gt;\n &lt;/tr&gt;\n &lt;tr&gt;\n ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T14:58:28.987", "Id": "30991", "Score": "1", "Tags": [ "php", "mysql" ], "Title": "Simplify MySQL INSERT query" }
30991
<p>I have written a script using Beautiful Soup to scrape some HTML and do some stuff and produce HTML back. However, I am not convinced with my code and I am looking for some improvements.</p> <p>Structure of my source HTML file:</p> <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt; &lt;html&...
[]
[ { "body": "<p>regarding 1 you can:</p>\n\n<pre><code>new_content = [c for c in old_content if c != '\\n']\n</code></pre>\n\n<p>or simply</p>\n\n<pre><code>new_content = old_content.replace('\\n', '')\n</code></pre>\n\n<p>Regarding 5, if your are generating anything that is nontrivial, then it will pay off to le...
{ "AcceptedAnswerId": "30993", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T12:05:18.880", "Id": "30992", "Score": "4", "Tags": [ "python", "html", "web-scraping", "beautifulsoup" ], "Title": "Scraping HTML using Beautiful Soup" }
30992
<p>I've just started looking at Zend Framework 2 and Doctrine ORM, with a view to possibly using it in one of my future products. So far I have a very simple application which allows the user to select data from a 'configuration' table. This table has just one row and several columns with settings that the application ...
[]
[ { "body": "<p>Quick answers:</p>\n\n<ul>\n<li>Is it easy to test? AFAICT, with the code provided it's quite easy to test. If you follow the docs (and it looks like you did follow them rather closely) then it should be easy to test.</li>\n<li>Could I use magic-methods: In theory, you can, but I wouldn't. More on...
{ "AcceptedAnswerId": "31088", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T15:35:08.670", "Id": "30994", "Score": "2", "Tags": [ "php", "unit-testing", "zend-framework", "doctrine" ], "Title": "Advice on Zend Framework 2 and Doctrine" }
30994
<pre><code>char* Migrated[]={"026","109"}; int isMigrated(char* codeB) { int i; int n=sizeof(Migrated)/sizeof(*Migrated); for(i=0;i&lt;n;i++) { if(strcmp(Migrated[i],codeB)==0) return 0; } return -1; } </code></pre> <p>is this function optimised from execution time p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T15:40:30.067", "Id": "49316", "Score": "0", "body": "You should use a hash table." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T15:40:52.423", "Id": "49317", "Score": "4", "body": "If th...
[ { "body": "<p>You could assert that any code has to come from the <code>Migrated</code> array and thus only compare the addresses, i.e. omit the <code>strcmp</code> call and just test for <code>Migrated[i] == codeB</code>.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "Cre...
{ "AcceptedAnswerId": null, "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T15:37:39.320", "Id": "30995", "Score": "1", "Tags": [ "c", "performance" ], "Title": "Optimization for C isMigrated function" }
30995
<p>I'm running this code with the FastMD5 library. Could it lead to memory leaks, or does it seem OK?</p> <pre><code>File[] directory = new File("/PATH/TO/FOLDER/WITH/LOTS/OF/FILES").listFiles(); for(int i = 0; i &lt; directory.length;i++){ System.out.println(MD5.asHex(MD5.getHash(directory[i]))); } </c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T18:38:54.130", "Id": "49339", "Score": "1", "body": "Do you have a reason to suspect a memory leak? There are many tools in Java that interact with the virtual machine and can show you a graph of memory usage in real-time." }, ...
[ { "body": "<p>In Java you have to do so much hard work to leak memory (someone will say not closing stream, but that's another story). </p>\n\n<p>I think you have a C programming background. So you are thinking of <code>memory leak</code>. Forget it there is JVM for you.</p>\n\n<p>And use enhanced for loop in J...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T16:08:19.010", "Id": "30999", "Score": "1", "Tags": [ "java" ], "Title": "Can MD5ing all the files in a table cause a memory leak?" }
30999
<p>I'm working on a project for an Intro to C/Python class and am looking to improve the efficiency of the program. The program is a lottery simulation where the user inputs the number of tickets they want to buy, then generates tickets, and finally outputs the total winnings and net gain (usually loss). </p> <p>This ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T19:36:47.437", "Id": "49342", "Score": "4", "body": "Remove the `print(i,\" \",winnings)` and see if the performance improves. Or you could print every 10000 by `if i % 10000 == 0:`" }, { "ContentLicense": "CC BY-SA 3.0"...
[ { "body": "<p>Doing this in a loop means <code>O(N)</code> time, where <code>N = # of tickets</code>.</p>\n\n<p>If tickets are independent of each other, you can break this into chunks and process them in parallel. But threading is an advanced topic that you aren't likely to deal with in an intro class.</p>\n"...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T19:24:12.003", "Id": "31007", "Score": "1", "Tags": [ "python", "performance", "simulation" ], "Title": "Improving Lottery Simulation" }
31007
<p>I was tasked with writing a method which would take in an <code>int</code> (for amount in coins) and then convert the coins, accordingly, by counting how many quarters, dimes, nickels, and pennies were located in the amount. Afterwards, it would return a <code>String</code> which stated each count of individual coin...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T21:08:29.600", "Id": "49363", "Score": "0", "body": "Hmm the unit names could be abbreviated to something like `nickelUnit = nickels==1 ? \" nickel\" : (nickels==0||nickels>1 ? \" nickels\" : \"ERROR - negative amount of nickels!\")...
[ { "body": "<p>Highlighting what a few helper classes can do : </p>\n\n<p>Imagine this enum </p>\n\n<pre><code>private enum Coin {\n QUARTER(25, \"quarter\"), DIME(10, \"dime\"), NICKEL(5, \"nickel\"), PENNY(1, \"penny\", \"pennies\");\n ...\n</code></pre>\n\n<p>and a tuple of quotient and remainder :</p>\...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T20:40:47.603", "Id": "31014", "Score": "3", "Tags": [ "java" ], "Title": "Converting Java int-based amount to Coin metrics" }
31014
<p>Long story short, I would like to use OOP for my new PHP project. It has a "login" requirement (i.e. user will first need to enter the username and password (login.php), if it's correct, it will be redirected to index.php and then fetch some products information). Also there will be a settings page that allows user ...
[]
[ { "body": "<p>The <strong>Single Responsibility Principle</strong> is a good thing to aim for, for many classes. It doesn't always mean that each class only does one thing (though it can), but that it is responsible for a small amount of tightly-related functionality.</p>\n\n<p>That said, the job of some classe...
{ "AcceptedAnswerId": "31020", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T20:57:32.977", "Id": "31015", "Score": "7", "Tags": [ "php", "object-oriented", "authentication" ], "Title": "Determining what functions should be implemented in this user-auth...
31015
<pre><code>def fib_m_through_n(m, n): """(number, number) -&gt; list A function which returns a list containing the mth through the nth fibonacci numbers. SHOULD BE MODIFIED IN THE FUTURE so it will remember values already computed, so when it is called again it reuses that information """ ...
[]
[ { "body": "<p>Of course not.</p>\n\n<p>If you do <code>c, a, b = a + b, b, c</code>, this is what you get</p>\n\n<pre><code>a, b, c = a0, b0, c0\nc, a, b = a + b, b, c \n## c become a0 + b0\n## a becomes b0\n## b becomes c0\n</code></pre>\n\n<p>I'm pretty sure this is not your intention.</p>\n\n<p>In tuple assi...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-09T22:56:01.340", "Id": "31024", "Score": "2", "Tags": [ "python", "fibonacci-sequence" ], "Title": "Returning a Fibonacci list" }
31024
<p>You guess heads or tails by clicking one of the buttons on easyGUI. If it's right, you will get a "good job" message. If it's wrong, you will get a "wrong" message! After that, there is an option to play again.</p> <p>Please give me some feedback on how I can make my code better, if there is room for improvement....
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T01:06:46.203", "Id": "49384", "Score": "2", "body": "please, correct your indentation" } ]
[ { "body": "<p>Top-level code in a module should generally be definitions only, not \"executable\" code. In other words, you should be able to import your module without running your program. This makes it easier to read and easier to debug. My preferred style for a script (as opposed to library) module is somet...
{ "AcceptedAnswerId": "31033", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T01:02:42.953", "Id": "31027", "Score": "2", "Tags": [ "python", "beginner", "game" ], "Title": "Guessing Game (Heads or Tails)" }
31027
<p>I have a <code>move</code> function in this game that I'm making. It works fine, but I'd like to reduce its size a bit.</p> <pre><code>function move(moveTo, direction) { switch (direction) { case "right": $('#player').animate({ left: "+=" + scale }, "slow", function () { $(...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T00:54:02.900", "Id": "49660", "Score": "0", "body": "what do you mean by backwards coding?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T01:01:34.477", "Id": "49661", "Score": "0", "body...
[ { "body": "<p>I would abstract the animation logic into a high order function and the possible directions in an object, then just lookup the corresponding function for each direction, in other words:</p>\n\n<pre><code>function move(to, dir) {\n\n function animate(props) {\n return function() {\n $('#pl...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T01:02:44.970", "Id": "31028", "Score": "5", "Tags": [ "javascript", "jquery" ], "Title": "Move function for a game" }
31028