body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I came up with this function <code>rangedReplace</code> as an exercice to use recursion and try different ways to make it work (I made at least 3 completely different versions). I think this version is the best but I have a feeling I can improve the way the functions/arguments are handled especially in the <code>cen...
[]
[ { "body": "<h2>Parameter design</h2>\n\n<p>To facilitate currying, you should arrange a function's parameters starting with the one that is the least likely to vary. In this case, I would consider the fill character the parameter that is most likely to be fixed.</p>\n\n<p>The next parameter, I think, should be...
{ "AcceptedAnswerId": "56052", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T03:21:53.080", "Id": "55953", "Score": "6", "Tags": [ "strings", "haskell" ], "Title": "Replacing part of a string with filler characters" }
55953
<p>I'm trying to write the most efficient query I can to pull the relevant data I need for retrieving the latest conversations for a user, ordering groupings of conversations by most recent message in that conversation.</p> <p>I don't like the idea of using a subselect to match the max timestamp. Is there a better or ...
[]
[ { "body": "<p>This SQL of yours has three issues I want to address before looking at the performance...</p>\n<h3>Formatting:</h3>\n<pre><code>SELECT c.id,\n c.fromUserId,\n c.toUserId,\n m.userId,\n m.message,\n m.timestamp,\n pm.filename AS thumbnail,\n u.username\nFRO...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T03:36:14.980", "Id": "55955", "Score": "2", "Tags": [ "sql", "mysql" ], "Title": "Query the Max Nth per group" }
55955
<p>I have a WCF service in which I am reading and adding some records to a .xml file. I load the .xml document in the constructor and use it in all the methods and save when it's updated.</p> <p>I want to know if this is the correct way of using it. I have seen code around where people load the <code>xDocument</code...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T05:23:54.803", "Id": "98370", "Score": "0", "body": "Well I think that really comes down to your requirements. If the propability of chaning the document are high, I would load it in the beginning. There is nothing wrong with that. ...
[ { "body": "<p>As you are using a singleton which loads the document once, I would say \"Yes you will probably see some degradation in performance to service calls if you only load it on demand\".</p>\n\n<p>If your service is the one and only program which modifies the document then your approach is probably via...
{ "AcceptedAnswerId": "55968", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T03:57:33.383", "Id": "55956", "Score": "4", "Tags": [ "c#", "xml", "wcf" ], "Title": "Using XDocument properly" }
55956
<p>Given a Binary Search Tree (where all nodes on the left child branch are less than the node), and all nodes to the right are greater/equal to the node), transform it into a Greater Sum Tree where each node contains sum of it together with all nodes greater than that node. Example <a href="http://d2o58evtke57tz.cloud...
[]
[ { "body": "<h1>Compiler Warnings</h1>\n\n<blockquote>\n <p>Iterable is a raw type. References to generic type Iterable should be parameterized</p>\n</blockquote>\n\n<p>This is very easy to fix. It's horrible that you haven't fixed it already. I'm sure that you know what generics is by now so I don't need to ex...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T06:28:05.900", "Id": "55966", "Score": "4", "Tags": [ "java", "algorithm", "tree" ], "Title": "Transform a Binary Search Tree into a Greater Sum Tree" }
55966
<pre><code>$roleId = pg_escape_string($_POST['role']); $grantValue = pg_escape_string($_POST['grant']); $feature = pg_escape_string($_POST['feature']); $permission = pg_escape_string($_POST['permission']); $permissionsModel = new Permissions(); $record = $permissionsModel-&gt;getPermission($roleId); ...
[]
[ { "body": "<h1>Yes, this is bad practice, sometimes</h1>\n\n<p>You are giving the user the option to dynamically change object properties. What if the property doesn't exist? What if a boogie monster passes by?</p>\n\n<p>Sometimes, generating the property could be usefull, but only do this when you trust the th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T06:35:56.073", "Id": "55967", "Score": "3", "Tags": [ "php", "postgresql", "properties", "yii" ], "Title": "Generating the property name of an object" }
55967
<p>If I have to loop results of a query echoing first all fields of a column, then echoing something not to loop, then fields of another column.</p> <pre><code>&lt;?php $con = mysqli_connect(); echo 'Latest users who tried our test&lt;br&gt;'; //select the fields of the first column $query1 = mysqli_query($con,"SELECT...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T08:37:17.383", "Id": "98395", "Score": "3", "body": "You are aware that `LIMIT` without `ORDER BY` rarely makes good sense?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T08:54:14.793", "Id": "98...
[ { "body": "<p>You want to access both columns in the same loop?</p>\n\n<pre><code>query = mysqli_query($con, \"SELECT user, score FROM ris_universita\");\nwhile ($assoc = mysqli_fetch_assoc($query) {\n echo $assoc['user'];\n echo $assoc['score'];\n}\n</code></pre>\n\n<p>You could also use <code>\"SELECT *...
{ "AcceptedAnswerId": "55998", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T08:08:15.453", "Id": "55973", "Score": "5", "Tags": [ "php", "sql", "mysql", "mysqli" ], "Title": "Two while for the same query" }
55973
<p>I've written some jQuery code that works, but I'm a novice in jQuery and I want to know how to improve my code if possible.</p> <p>I know I have 3 near identical blocks of code. If I create a function, the code will be the same. I'm looking for more accurate code and am trying to reduce my code into fewer lines.</p...
[]
[ { "body": "<p>I've written in my way. You can see it with this link <a href=\"http://jsfiddle.net/968pA/8/\" rel=\"nofollow\">http://jsfiddle.net/968pA/8/</a> .</p>\n\n<p>HTML :</p>\n\n<pre><code>&lt;header id=\"masthead\" class=\"container site-header\" role=\"banner\"&gt;\n &lt;nav role=\"navigation\"&gt;\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T09:16:01.393", "Id": "55977", "Score": "5", "Tags": [ "javascript", "beginner", "jquery" ], "Title": "jQuery Dropdown Navigation" }
55977
<p>I have written some jQuery which validates a group of drop downs. It checks the text value selected in all the drop downs (first three characters), and if there is a duplicate, it warns the user.</p> <p>This code seems quite messy, I was wondering if anyone would like to attempt to refactor this. Tips for improve...
[]
[ { "body": "<p>You didn't incude it in your post, but I'm comment on it anyway: The way you assign the validator function to your select elements isn't very optimal:</p>\n\n<pre><code> $('#MainContent_ddOpenBrd1').change(function () {\n validateTeam('openSelect');\n });\n $('#MainContent_...
{ "AcceptedAnswerId": "55985", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T09:46:32.240", "Id": "55978", "Score": "5", "Tags": [ "javascript", "jquery", "html", "validation" ], "Title": "Multiple drop down validation" }
55978
<h3>Why this plugin:</h3> <p>I am developing a mobile app - at some point, I felt like this would be a good idea to give the users the possibility to control everything in the app with touch gestures, hence the need for a plugin able to recognize more than the basic swipe events.</p> <h3>What it does:</h3> <p>When t...
[]
[ { "body": "<p>Interesting plugin,</p>\n\n<p>some observations:</p>\n\n<ul>\n<li>Use JsHint, there are a ton of minor issues with this code that you should clean up</li>\n<li>Use JsBeautifier, there is quite a bit of inconsistent formatting</li>\n<li><code>'unicorn'</code> sounds like fun, <code>'typezor'</code>...
{ "AcceptedAnswerId": "56566", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T09:51:02.597", "Id": "55979", "Score": "6", "Tags": [ "javascript", "jquery", "event-handling", "plugin", "touch" ], "Title": "Small jQuery mobile plugin to handle touc...
55979
<p>I have very quickly mocked this up as an example model in Angular JS:</p> <pre><code>.factory('car', function() { function car(serial, name, type, manufacturer) //intended to be private var serial = serial; var name = name; var type = type; var manufacturer = manufacturer; this.getSerial ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T10:08:30.897", "Id": "98428", "Score": "1", "body": "The convention is to not worry about encapsulation, it's preferable to use prototypes and monkey-patching, than attempting to hide everything. Prefixing \"private\" variables with...
[ { "body": "<p>JavaScript provides a analogy to private properties, but you should think of them as hidden as they do not behave as private properties. Protoptyped methods do not have access to hidden properties. </p>\n\n<p>Properties defined with the \"this\" token are public and can be accessed anywhere the ob...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T09:51:20.857", "Id": "55980", "Score": "1", "Tags": [ "javascript", "design-patterns", "angular.js" ], "Title": "Use of getters and setters with a car information example" }
55980
<p>I am doing a date validation. I have no. of pages, which have the date field. User can input the date like "220875" or "22AUG75" - I need to test both and check the length as well.</p> <pre><code>function isValidDate(newDate) { newDate[1] = newDate[1]-1; newDate[2] = (parseInt(newDate[2]) &lt; 50) ? 2000 +...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T16:27:43.013", "Id": "98530", "Score": "0", "body": "After a quick glance it's not immediately obvious what `this.mode` represents. I assume it's a toggle between validating `220875` and `22AUG75`. You should probably rename the var...
[ { "body": "<p>Can this be simplified ? Most certainly.</p>\n\n<ul>\n<li>You can take advantage of the fact that <code>new Date( 'APR 04 1977' )</code> and <code>new Date( '04 04 1977' )</code> both work, so you don't need <code>getMonthFromString</code></li>\n<li>You can take more out of regexes with capturing ...
{ "AcceptedAnswerId": "56385", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T10:49:06.773", "Id": "55981", "Score": "3", "Tags": [ "javascript", "jquery", "datetime", "validation" ], "Title": "Can this date-validation function can be simplified furt...
55981
<p>I've written an asynchronous retry method as an answer for <a href="https://stackoverflow.com/questions/24462525/parallel-foreach-using-thread-sleep-equivalent">this question</a>. I'd like to get your opinion of the implementation and whether there are better ways to implement this. You could also implement this wit...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T11:38:00.113", "Id": "98447", "Score": "5", "body": "Hello and Welcome to [codereview.se]! Unknowingly you became the second contestant in our new CR-Game. For more information see [tag:rags-to-riches]. Feel free to drop by in [chat...
[ { "body": "<blockquote>\n <p>You could also implement this with <code>async-await</code> but I thought this would be a more efficient implementation.</p>\n</blockquote>\n\n<ol>\n<li>When performance matters, don't guess, <em>measure</em>. When it doesn't matter (which is 97 % of the time <a href=\"http://c2.co...
{ "AcceptedAnswerId": "56212", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T10:56:09.807", "Id": "55983", "Score": "11", "Tags": [ "c#", "task-parallel-library", "async-await", "rags-to-riches" ], "Title": "Asynchronous retry method" }
55983
<p>With Tornado 3.2 they made some updates to auth module and have updated the code. Earlier I was using open id for Google login, since it will be deprecated in the future I am switching the code to Oauth 2.0 login. Also I was using <code>tornado.web.asynchronous</code>, now I have updated the code to use <code>tornad...
[]
[ { "body": "<p>There are a few small improvements I can see:</p>\n\n<ol>\n<li><p>Your <code>get_current_user()</code> function is slightly misleading. Currently, you return <code>None</code> if there is no current user, or <code>True</code> if there is. This function isn't returning the current user, its returni...
{ "AcceptedAnswerId": "55994", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T12:12:21.610", "Id": "55988", "Score": "5", "Tags": [ "python", "asynchronous", "authentication", "tornado" ], "Title": "Oauth 2.0 handler functions for Tornado" }
55988
<p>This function adds a number of hours to a 24 hour clock:</p> <pre><code>/** * @param {Integer} now The current hours * @param {Integer} add The number of hours to add */ function addHours(now, add){ var h = (now + add) % 24; return h &lt; 0 ? 24 + h : h; }; </code></pre> <ul> <li><code>addHours(2, 5) /...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T13:02:05.317", "Id": "98457", "Score": "0", "body": "Other that the inappropriate parameter name `now`, there is not much you could say about it code-wise. However what I'd like to question its usefulness, which seems very limited."...
[ { "body": "<p>Tiny question ;)</p>\n\n<ul>\n<li><p>As @Rotora mentioned, <code>now</code> is not a fantastic parameter name, it conveys that I need to only pass who late it is 'now', <code>add</code> is a verb, also not brilliant as parameter naming goes</p></li>\n<li><p><code>addHours( -500 , -100 )</code> ret...
{ "AcceptedAnswerId": "55996", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T12:19:51.940", "Id": "55989", "Score": "6", "Tags": [ "javascript", "datetime" ], "Title": "Add number of hours to 24 hour clock" }
55989
<p>Here is simple repository pattern that I use to access data in my database. I would like some advice on how to improve this code. Commenting on my code quality is also welcome too! </p> <pre><code>public static class ProdRepository { private static Entities context = null; public static Entities Context ...
[]
[ { "body": "<p>Two questions.</p>\n\n<ol>\n<li>Do you really need to specifically return a <code>List&lt;OutboundModel&gt;</code> or would an <code>IList&lt;OutboundModel&gt;</code> or even <code>IEnumerable&lt;OutboundModel&gt;</code> do?</li>\n<li>Since <code>context</code> starts out as <code>null</code> and ...
{ "AcceptedAnswerId": "56001", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T12:33:02.917", "Id": "55991", "Score": "7", "Tags": [ "c#", "beginner", "entity-framework" ], "Title": "Basic Entity Framework Repository implementation" }
55991
<p>I am kind of new to programming. Picked up some Perl about a year ago and now learning some Python. I am pretty confident in Perl, but Python seems un-natural to me. </p> <p>I wrote a little script that parses log files and indexes them into Solr in JSON. This is for some reporting. </p> <p>I wanted to see if the...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T14:32:08.120", "Id": "98479", "Score": "1", "body": "I think your indentation got borked when you copied the code over. There are a few isolated sections that, if run as is, would error out due to an unexpected indentation block." ...
[ { "body": "<p>Since this you posted quite a lot of code, I'll keep my comments higher-level and more general in nature.</p>\n\n<p>There is one document titled <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP8</a> that covers Python's style conventions. Take a look at it as it gives v...
{ "AcceptedAnswerId": "56020", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T12:53:04.660", "Id": "55992", "Score": "2", "Tags": [ "python", "beginner", "parsing" ], "Title": "Parsing Solr log files" }
55992
<p>I built a very basic image slider, but I'm still having trouble refactoring. </p> <p>I caught myself reusing same code for clicking the previous/next buttons, selecting a slider dot, and the automated sliding. The difference between these actions is how the index of images changes. I'm not sure how to break out t...
[]
[ { "body": "<p>You are basically doing 3 things in both functions:</p>\n\n<ol>\n<li>Make every dot inactive</li>\n<li>Determine which dot is now active</li>\n<li>Activate the determined dot</li>\n</ol>\n\n<p>You could easily make 1) a part of 3) and create a function that activates a dot:</p>\n\n<pre><code>funct...
{ "AcceptedAnswerId": "56046", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T13:03:27.123", "Id": "55993", "Score": "5", "Tags": [ "javascript", "jquery", "beginner" ], "Title": "DRYing out a basic image slider" }
55993
<p>I'm an upstart, been only <strong>professionally</strong> programming for a bit less than 2 years, mainly in Java as I am currently working as an Android developer.</p> <p>I often find myself thinking about how to improve the readability and maintainability of my code, and establish some style guidelines, for the p...
[]
[ { "body": "<p>Code style guidelines are available from a number of places. The 'old faithful' official Java ones have been pulled down, for some reason. Oh, they have been restored and <a href=\"http://www.oracle.com/technetwork/java/javase/documentation/codeconvtoc-136057.html\" rel=\"nofollow noreferrer\">are...
{ "AcceptedAnswerId": "56008", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T13:16:52.223", "Id": "55995", "Score": "6", "Tags": [ "java", "formatting", "event-handling" ], "Title": "Scroll listener - about code style guidelines and standards" }
55995
<p>I wrote an algorithm which should cut a companies name into 3 strings.</p> <blockquote> <p><strong>Input:</strong> 1 String</p> <p><strong>Output:</strong> 3 String.</p> <p><strong>Conditions:</strong></p> <p>String 1 2 and 3 shall not be longer then 35 signs. If the Input string is longer then it ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T15:13:38.213", "Id": "98498", "Score": "0", "body": "Your solution attempts to split at whitespace. This is a nice idea, but not explicit in the requirement (and causes many problematic special cases). (Actually, the requirement tha...
[ { "body": "<p>You don't need to loop. The function <a href=\"http://msdn.microsoft.com/en-us/library/aka44szs%28v=vs.110%29.aspx%E2%80%8ECachedSimilar\">SubString</a> and the property <a href=\"http://msdn.microsoft.com/en-us/library/system.string.length.aspx\">Length</a> is enought to handle what you want.</p>...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T13:42:35.663", "Id": "56002", "Score": "10", "Tags": [ "algorithm", "beginner", "strings", "vb.net" ], "Title": "Splitting company name into 3 strings" }
56002
<p>I cannot edit the <code>QueryPermissions</code> class because it is an external .dll that was given to me to use. Yes, I realize it's a bad practice to use an out variables, but I am pushing for a rewrite of that service.</p> <p>As you can see below the two methods do the almost the EXACT same thing only one uses a...
[]
[ { "body": "<p>What about using a delegate?</p>\n\n<pre><code>private delegate void Query(int value, int key, ref List&lt;WebQuery&gt;, bool b);\n\npublic void SomeCallingMethod()\n{\n IEnumerable&lt;OnlineReport&gt; reports;\n // one way\n int myUserKey;\n Query q = _QueryPermissions.GetQueriesForTaskAndUse...
{ "AcceptedAnswerId": "56011", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T14:05:38.663", "Id": "56003", "Score": "1", "Tags": [ "c#" ], "Title": "Refactoring two node-accessing methods" }
56003
<p>I have set up a <code>Dictionary</code> that calls on a class to fill a <code>DataGridView</code> via SQL statements. The problem is in two (out of 5) instances the value passed HAS to be an integer, but the value comes from a textbox so it is being passed as string. Before I set these Dictionaries up I was just u...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T15:06:02.827", "Id": "98491", "Score": "0", "body": "Clarification on the text box: Does it have to be a text box? Or can you make it a different type of input?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "20...
[ { "body": "<p>In your data structure include a validator (this should probably be a <code>Predicate&lt;String&gt;</code>); most of the predicates will just return true, but the two that require integers will have a nontrivial validator that checks for integer.</p>\n\n<p>So I guess the type should be <code>Dicti...
{ "AcceptedAnswerId": "56043", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T14:34:09.367", "Id": "56009", "Score": "2", "Tags": [ "c#", "beginner", "winforms", "hash-map", "error-handling" ], "Title": "Error Handling When Using Dictionary" }
56009
<p>We have a base interface:</p> <pre><code> public interface IMessage { //Some properties } </code></pre> <p>then we have derived messages that implement this interface such as:</p> <pre><code> public class AlarmEventMessage: IMessage { //Some properties } </co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T15:29:32.130", "Id": "98506", "Score": "1", "body": "Welcome to Code Review! Your current question touches on a typical gray area of Code Review. We're not very fond of \"example code\" around here, the only question then is what \"...
[ { "body": "<p>You are correct when you say that the <code>MessageHandler</code> class violates the Single Responsibility Principle. </p>\n\n<p>What you're looking for here is generics. First of all, you need to define a contract for messages and their respective handlers. This can be done with the following:</p...
{ "AcceptedAnswerId": "56018", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T14:55:51.893", "Id": "56014", "Score": "0", "Tags": [ "c#" ], "Title": "Multiple overloads for message handling" }
56014
<p>I am trying to find if a subwebsite exists in sharepoint, and if it does, then add +1.</p> <p>I think the loop can be improved.</p> <pre><code>// subsiteName will be like "FruitCrateOfCompanyX" public static string FormatMyHomieURL(string subsiteName, string mainSite) { if (!mainSite.EndsWith("/")) ma...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T04:31:33.207", "Id": "98839", "Score": "0", "body": "What is the problem you're trying to solve here? Specifically: Why is incrementing the final number of the subsitename the way to solve it? Is this the only means you have of chec...
[ { "body": "<p>You asked about the loop.</p>\n\n<blockquote>\n<pre><code>while (SubwebExists(temp))\n{\n i++;\n temp = mainSite + subsiteName + i;\n\n}\n</code></pre>\n</blockquote>\n\n<p>Is this loop guaranteed to execute at least once? I suspect so, because if it doesn't, you return <code>subsiteName + 0...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T15:23:40.667", "Id": "56019", "Score": "9", "Tags": [ "c#", "sharepoint" ], "Title": "Checking if website exists and adding +1" }
56019
<p>I've replaced the following horrendous Excel formula (values and names have been replaced):</p> <pre><code>=IF(AND(SourceTable[@Field1]="Value1",SourceTable[@Field2]="Value2"),"Result1", IF(SourceTable[@Field2]="Value3","Result2", IF(AND(SourceTable[@Field1]="Value4",SourceTable[@Field3]="Value5"),"Resu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T16:59:21.040", "Id": "98534", "Score": "4", "body": "Why replace the names? It takes away meaning, which makes the code pretty hard to read and ultimately to review." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate"...
[ { "body": "<p>I'm assuming that names have been changed to protect the innocent, but just in case they've not been...</p>\n\n<h3>These are terrible names. All of them.</h3>\n\n<ul>\n<li>Function names should have verb-noun names and be <code>PascalCased</code>. So instead of <code>CUSTOMFUNCTION</code> should b...
{ "AcceptedAnswerId": "56463", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T15:47:59.423", "Id": "56023", "Score": "7", "Tags": [ "vba", "excel" ], "Title": "VBA Function slower than Excel Formula" }
56023
<p>I have a working SQL statement which shows the following:</p> <ul> <li>Player</li> <li>Champion</li> <li>Role</li> <li>Total Kill/Death Ratio</li> <li>Total Kill+Assist/Death Ratio</li> <li>Total Win %</li> <li>Difference between Ratio from one month ago</li> <li>Difference between KA Ratio from one month ago</li> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-07T23:19:13.347", "Id": "99270", "Score": "2", "body": "I'll hazard a guess that this hasn't received attention because of how it is asked. I have a few suggestions. First, cut down the stuff you don't need in the SQL. Selecting pla...
[ { "body": "<h1><strong>Naming conventions</strong></h1>\n\n<p>I think your aliases are pretty cryptic.</p>\n\n<p>This:</p>\n\n<blockquote>\n<pre><code>from schema.records tt\n</code></pre>\n</blockquote>\n\n<p>That:</p>\n\n<blockquote>\n<pre><code>from CTERatio c, hist h\n</code></pre>\n</blockquote>\n\n<p>It's...
{ "AcceptedAnswerId": "56593", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T16:00:03.540", "Id": "56024", "Score": "6", "Tags": [ "game", "sql", "postgresql" ], "Title": "Is there a way to optimize this aggregate postgreSQL statement by using CASE?" }
56024
<p>I have a function that takes a <code>Dictionary&lt;String, Object&gt;</code> as an argument. It uses this <code>Dictionary</code> to create parameters for a query string.</p> <pre><code>private static TableAdapters dataSource = new TableAdapters(); private void findScriptsQueryButton_Click(object sender, EventArgs...
[]
[ { "body": "<p>The code isn't bad, I think you just need to properly wrap it and expose a better API. For instance, <code>GetDataSource</code> can stay, but it should be private and have a better-named and typed function that calls into it. Something like:</p>\n\n<pre><code>DataTable FindBy(String findBy)\n</c...
{ "AcceptedAnswerId": "56077", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T16:09:32.267", "Id": "56025", "Score": "5", "Tags": [ "c#", "beginner", ".net", "hash-map" ], "Title": "Passing parameters to a query" }
56025
<p>This is the successor of my <a href="https://codereview.stackexchange.com/questions/55939">previous</a> CSV reader. I implemented quite some useful suggestions.</p> <p>I will give explanation on a few parts:</p> <ul> <li><p>Prefixing constant identifiers with <code>Sym_</code> (abbreviation for symbol) is a practi...
[]
[ { "body": "<p>A few minors for now:</p>\n\n<ol>\n<li><p>When throwing an exception because the argument violated a constraint then you should consider mentioning that in the message. Simply \"Invalid foobar\" is quite useless to anyone using it. A message like \"Buffer size must be 128 or larger\" would be infi...
{ "AcceptedAnswerId": "56048", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T16:56:49.063", "Id": "56031", "Score": "3", "Tags": [ "c#", "parsing", "csv" ], "Title": "CSV reader (revised)" }
56031
<p>I read effective Java by Joshua Bloch. And it said use enums over int constant. So I was thinking instead of using hard coded strings I could also use enums. The <strong>forgotpassword.txt</strong> and <strong>confirmation.txt</strong> are plain text resource files.</p> <p>When the class is loaded, I get the conten...
[]
[ { "body": "<p>Your code looks overly complicated. If the number of templates is low, why don't you initialize them manually, and if it's high why don't you just put them in a collection? Are you sure you really need lots of singletons here?</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3...
{ "AcceptedAnswerId": "56110", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T17:13:07.507", "Id": "56034", "Score": "5", "Tags": [ "java", "singleton", "enum" ], "Title": "Is this good design for custom email template?" }
56034
<p>I'm new to ui.router in Angular and have to build an app, which contains a header, sidebar (off-canvas), feedback area (save successful and warnings area) and a content area.</p> <p>I thought it would be best if I split up all things and create different (nested) <code>ui-view</code>s:</p> <p><strong>index.html</s...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T18:08:37.113", "Id": "56041", "Score": "4", "Tags": [ "javascript", "beginner", "angular.js" ], "Title": "Angular ui.route" }
56041
<blockquote> <p>Given a linked list and two integers <em>M</em> and <em>N</em>. Traverse the linked list such that you retain <em>M</em> nodes then delete next <em>N</em> nodes, <strong>continue the same until end of the linked list.</strong></p> <ul> <li><p>Input:</p> <p><em>M</em> = 2, <em>N</em> = ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T23:02:07.170", "Id": "98598", "Score": "1", "body": "You should probably just use Java's [LinkedList](http://docs.oracle.com/javase/8/docs/api/java/util/LinkedList.html). If you were working in some company, it would not be well se...
[ { "body": "<p>Bugs galore....</p>\n\n<h1>Bug 1</h1>\n\n<p>The user should always be able to call:</p>\n\n<pre><code>list.deleteNAfterM(0, list.size());\n</code></pre>\n\n<p>This should always be safe.... but, your code throws <code>IllegalArgumentException</code> if the list is empty.</p>\n\n<p>Also, why call i...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T19:27:19.583", "Id": "56045", "Score": "4", "Tags": [ "java", "linked-list" ], "Title": "Repeatedly skip M nodes then delete N nodes then skip M nodes and so on" }
56045
<p>I'm having trouble figuring out the best approach with DI. After doing more research, Mark Seeman recommends using the <a href="https://stackoverflow.com/questions/9501604/ioc-di-why-do-i-have-to-reference-all-layers-assemblies-in-entry-application/9503612#9503612" title="stack overflow">Composition Root</a> approac...
[]
[ { "body": "<p>The <em>composition root</em> is just the place in your code where you'll <em>compose</em> the application and resolve the entire dependency graph at once. You'll want that as close as possible to the application's entry point - the <code>Main</code> method is perfect for this in a console applica...
{ "AcceptedAnswerId": "56066", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T20:11:07.023", "Id": "56049", "Score": "0", "Tags": [ "c#", "design-patterns", "dependency-injection" ], "Title": "Unity DI Composition Root vs XML" }
56049
<p>I have a class that implements Queue and draws values from other queues which may still be referenced outwith it. I want my method to draw values from the contained queues, using synchronized locks on them to ensure thread safety with other code that uses synchronized locks on the queues.</p> <p>The way I've tried ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T23:25:24.567", "Id": "98600", "Score": "1", "body": "Could you please clarify what you mean when you say: *I want the method to draw values from the queues by checking over all values indefinitely and after a value is checked twice....
[ { "body": "<h1>Code Style</h1>\n\n<p>Java Code Style puts the open-brace at the end of the line, not the start of the next line. For example, you have:</p>\n\n<blockquote>\n<pre><code> if(i == nextQueue)\n {\n</code></pre>\n</blockquote>\n\n<p>but that should be:</p>\n\n<pre><code> ...
{ "AcceptedAnswerId": "56058", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T22:23:44.697", "Id": "56054", "Score": "3", "Tags": [ "java", "multithreading", "queue" ], "Title": "Threadsafe get method on queue that draws values from other queues?" }
56054
<p>I have a script that is standardizing a large amount of data in the database. The standardization involves applying over 500 regular expressions to the data.</p> <p>Here is some quick pseudocode:</p> <pre><code>Load the records from the database for each record for each regular expression ##predefined list of 5...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T01:45:41.503", "Id": "98609", "Score": "0", "body": "`$accountKey = @row[0]` and similar lines assign a list to a scalar variable. Does this code work?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T...
[ { "body": "<p>Nested loops can be problematic, but you can build regex which can be applied once instead of running <code>foreach</code></p>\n\n<pre><code>my %replace = (\n str =&gt; { re =&gt; '\\bstr\\b', output =&gt; \"street\" },\n rd =&gt; { re =&gt; '\\brd\\b', output =&gt; \"road\" },\n);\nmy ($reComb...
{ "AcceptedAnswerId": "56086", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T01:02:24.420", "Id": "56059", "Score": "6", "Tags": [ "performance", "algorithm", "regex", "perl" ], "Title": "Canonicalizing a large set of addresses using many regex subs...
56059
<p>This Connect 4 game will be used for implementing game-playing AI. Sample players are supplied. One takes user input, and the other plays randomly. Right now it's set for a human player to play against a randomly playing agent, but in the future I plan to try out algorithms such as Minimax and have AI agents play ag...
[]
[ { "body": "<p>I would advise using slightly longer names (<code>rind</code> should be <code>row_ind</code>, etc.), adding comments (while you are writing the code, not after) and avoiding counterintuitive variable names such as <code>four</code>. It is quite confusing when you are writing statements such as <co...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T01:13:30.047", "Id": "56061", "Score": "4", "Tags": [ "python", "python-3.x", "numpy", "connect-four" ], "Title": "Connect 4 game for AI agents" }
56061
<blockquote> <p>Given two arrays <code>A</code> and <code>B</code>, of length <code>N</code> and length <code>k</code> respectively, if we move <code>B</code> over <code>A</code> and take the sum of product of corresponding elements of <code>A</code> and <code>B</code>, then find the minimum of those sum of products....
[]
[ { "body": "<p>This is effectively a convolution problem. Theoretically, this can (potentially) be done faster by a conversion to the frequency domain, that is, using a <a href=\"http://en.wikipedia.org/wiki/Fast_Fourier_transform\" rel=\"nofollow noreferrer\">fast Fourier transform</a> (FFT) convolution.</p>\n\...
{ "AcceptedAnswerId": "56065", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T01:19:09.237", "Id": "56062", "Score": "4", "Tags": [ "python", "algorithm", "array" ], "Title": "Product of corresponding elements in 2 arrays" }
56062
<p>As a small exercise I have written some string formatting and printing functions in C++11. I would like a bit of code review, not so much on the merits of using this over something like <code>std::stringstream</code> or <code>boost::format</code>, but simply whether or not my implementation makes sense. I realize th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T10:14:12.597", "Id": "98672", "Score": "0", "body": "Is there any particular reason why you have overloads for `const T&` and `T&&` all over the place? `T&&` implicitly allows `T&` and `const T&` due to reference collapsing." }, ...
[ { "body": "<p>As you mention, the simple replacing is susceptible to problems if a replacement string includes a format specifier. But setting that aside, there are still a few things I would rather do differently.</p>\n\n<p><strong>Document</strong>. You should be sure to document your formatting language in c...
{ "AcceptedAnswerId": "56195", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T02:16:29.133", "Id": "56067", "Score": "10", "Tags": [ "c++", "strings", "c++11", "formatting", "boost" ], "Title": "String-formatting and printing functions" }
56067
<p>I have two identical objects on the page, so I get more of the same lines of code. Can anything be made simpler, perhaps with merging?</p> <pre><code>for(var i=0;i&lt;ticks.length,i&lt;ticks2.length;i++) { var tick = ticks[i]; var tick2 = ticks2[i]; var tickCenter = tick.offsetWidth / 2 var offset = (i - ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T03:53:11.687", "Id": "98621", "Score": "0", "body": "Extract the redundant code into a function." } ]
[ { "body": "<p>You can combine the two identical assignments at the end into the same line rather than recalculating the same value again:</p>\n\n<pre><code>for (var i = 0; i &lt; ticks.length &amp;&amp; i &lt; ticks2.length; i++) {\n\n var tick = ticks[i];\n var tick2 = ticks2[i];\n var tickCenter = ti...
{ "AcceptedAnswerId": "56072", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T03:38:42.250", "Id": "56070", "Score": "5", "Tags": [ "javascript" ], "Title": "Reducing code with two identical objects" }
56070
<p>I decided to setup a generic makefile to compile SFML programs, as I'm going to be making a bunch of small apps over the next few weeks playing around with it. I'm still new to writing makefiles (still weaning off of using IDEs), but I'm pretty happy with how it turned out.</p> <pre><code>##########################...
[]
[ { "body": "<ul>\n<li><p><code>CFLAGS</code> traditionally refer to compiling <code>.c</code> files. The <code>c++</code> compiler is traditionally invoked with <code>CXXFLAGS</code>.</p></li>\n<li><p>I must advise against automatic collection of <code>SOURCES</code> (line 54). Usually you need to build more tha...
{ "AcceptedAnswerId": "56075", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T03:48:00.237", "Id": "56071", "Score": "5", "Tags": [ "bash", "linux", "makefile" ], "Title": "Generic Makefile" }
56071
<h2>case 1</h2> <p><code>self.read_codec_info(fname)</code> repeat 2 times, how to make it better ?</p> <pre><code> codec_infos = [fname, resp] if len(self.read_codec_info(fname)) &gt; 0: codec_infos += self.read_codec_info(fname) </code></pre> <h2>case 2</h2> <p>There are many variables and strings ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T07:02:22.520", "Id": "98636", "Score": "3", "body": "Can you post the entire class to give more context? Also, why do you have code after `continue`?" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2018-08-14T12...
[ { "body": "<p><strong>Case 1</strong></p>\n\n<p>To avoid calling twice, simply assign the returned value:</p>\n\n<pre><code>codec_infos = [fname, resp]\ninfo = read_codec_info(fname)\nif len(info) &gt; 0: # or just 'if info:'\n codec_infos.extend(info)\n</code></pre>\n\n<p>If <code>read_codec_info</code> alw...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T06:22:04.477", "Id": "56079", "Score": "-6", "Tags": [ "python" ], "Title": "Refactor repeated statements and lengthy conditional statements" }
56079
<pre><code>[TestCase(new[] { 1, 2 }, 1, Result = 2)] [TestCase(new[] { 1, 2 }, 2, Result = 1)] [TestCase(new[] { 1, 2, 3 }, 2, Result = 2)] [TestCase(new[] { 1, 2, 3, 4 }, 2, Result = 2)] [TestCase(new[] { 1, 2, 3, 4 }, 10, Result = 1)] public int TotalPageCountIsAccurate(int[] testSequence, int pageSize) { var pag...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T06:54:53.577", "Id": "98634", "Score": "0", "body": "What isn't feasible about using named arguments?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T06:57:53.557", "Id": "98635", "Score": "0"...
[ { "body": "<p>If I'm right you could do at least two things:</p>\n\n<ol>\n<li><p>Generate the array and pass only the number of items to the test method.</p></li>\n<li><p>Rename <code>testSequence</code> to something more descriptive, like <code>items</code>, <code>elements</code> etc.</p></li>\n</ol>\n\n\n\n<p...
{ "AcceptedAnswerId": "56084", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T06:42:20.430", "Id": "56080", "Score": "6", "Tags": [ "c#", "unit-testing", "nunit" ], "Title": "How can I better the readability of inline test data?" }
56080
<p>The following code works but is a mess. But being totally new to Ruby I have had big problems trying to refactor it into something resembling clean OOP code. Could you help with this and explain what you are doing?</p> <pre><code>require 'nokogiri' require 'open-uri' require_relative 'db.rb' # Not used requi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T17:15:13.623", "Id": "98732", "Score": "1", "body": "Spacing immediately comes to mind. Start a new indentation level after each `each do`." } ]
[ { "body": "<p>I can't speak to Ruby but I see an improvement that could be done to your MySQL code. Since this operation loops multiple times and passes a query to MySQL each time, you would considerably improve your database execution by using a stored <code>PROCEDURE</code> and passing parameters to it. The p...
{ "AcceptedAnswerId": "56180", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T06:45:03.643", "Id": "56081", "Score": "14", "Tags": [ "beginner", "object-oriented", "ruby", "sql", "web-scraping" ], "Title": "Nokogiri crawler" }
56081
<p>I have two tables in the database:</p> <ol> <li><p>Credentials (<code>userid</code>, <code>password</code>, <code>usertype</code>)</p></li> <li><p>Customer (<code>customername</code>, <code>userid</code>(foreign key))</p></li> </ol> <p>I need to validate username,password and usertype and create a session variable...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T07:43:32.240", "Id": "98680", "Score": "5", "body": "Are you save your password as a **plain text**? Use parameterized queries. Use using statement to dispose your database connections." }, { "ContentLicense": "CC BY-SA 3.0"...
[ { "body": "<p>Well, you can start by removing obvious copy-paste:</p>\n\n<pre><code>dr.Close();\ncmd = new SqlCommand(\"select Password from Credentials where UserId='\" + objLogOnUserInformation.UserId + \"'\", con);\ndr = cmd.ExecuteReader();\n</code></pre>\n\n<p>and</p>\n\n<pre><code>dr.Close();\ncmdOne = n...
{ "AcceptedAnswerId": "56089", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T07:49:43.647", "Id": "56087", "Score": "6", "Tags": [ "c#", "sql", "mysql", "asp.net", "authentication" ], "Title": "Username, Password and UserType Validation" }
56087
<p>I decided to port my favorite unit testing framework, <a href="https://github.com/philsquared/Catch" rel="nofollow noreferrer">Catch</a>, to JavaScript. So far I'm focusing on <a href="https://github.com/philsquared/Catch/blob/master/docs/tutorial.md#test-cases-and-sections" rel="nofollow noreferrer">test cases and ...
[]
[ { "body": "<h3>Overall Design</h3>\n\n<p>For such a small amount of code, I find the logic extremely difficult to follow. I understand what is happening at a high level, but it seems every function is responsible for managing everything, and program control bounces around a lot.</p>\n\n<p>As an example, the fin...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T08:12:18.473", "Id": "56090", "Score": "7", "Tags": [ "javascript", "unit-testing" ], "Title": "Catch-style unit testing in JavaScript (phase 1)" }
56090
<p>I've started writing a piece of code to help me search for an object in all the objects found in the diagonals of an M x M 2D array. </p> <p>Though the code works, I'd like to know if there is a way I can improve on it or there exists a different technique I could use to achieve the same result with fewer lines of ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T08:32:03.197", "Id": "98651", "Score": "1", "body": "from a performance standpoint this can be improved (`s.Contains(strToFind)`) - by using the usual techniques from lexing (basically you can look for `strToFind` while looking thro...
[ { "body": "<p>This reminds me of what I wrote a while ago for my <a href=\"https://codereview.stackexchange.com/questions/45086/recursive-and-flexible-approach-to-tic-tac-toe\">Tic Tac Toe Ultimate game</a>.</p>\n\n<p>In case I get anything wrong, here is a relevant part of my original code:</p>\n\n<pre><code>/...
{ "AcceptedAnswerId": "56096", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T08:21:12.940", "Id": "56092", "Score": "7", "Tags": [ "c#", "algorithm", "linq", "matrix" ], "Title": "Searching all diagonals of a 2D M x M array" }
56092
<p><a href="http://htmleditor.gitlab.io/" rel="nofollow noreferrer"><strong>HTML Editor</strong></a> is an online HTML editor with a minimalist approach. Edit your HTML, CSS, and JavaScript code and monitor the instant live preview.</p> <p>Please review the source code and provide feedback:</p> <pre><code>&lt;!DOCTYP...
[]
[ { "body": "<p>In all, quite impressive code, here are some pointers:</p>\n\n<ul>\n<li>Besides the suggestion to compare with 0 via <code>===</code>, JsHint could not find anything</li>\n<li>Consider using <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EventTarget.addEventListener\">addEventListener<...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T13:23:01.153", "Id": "56106", "Score": "22", "Tags": [ "javascript", "html", "css", "text-editor" ], "Title": "HTML Editor: online HTML editor with real-time preview" }
56106
<p>Recently I have been learning Python programming, for about a week. I have covered all basic stuff - loops, strings, input masks - and have challenged myself by making a little game. It isn't much, that I know, but I was just wandering whether or not I have done everything correctly.</p> <p>Any feedback regarding f...
[]
[ { "body": "<p>Here is an alternative implementation, with explanatory comments below. This introduces quite a few additional Python concepts:</p>\n\n<pre><code>from operator import ge, le, ne\nimport random\n\ndef get_valid_input(choices=set(\"hls\")):\n while True:\n ui = input(\"Higher (H), Lower (L...
{ "AcceptedAnswerId": "56142", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T18:33:24.187", "Id": "56126", "Score": "6", "Tags": [ "python", "beginner", "game", "random", "playing-cards" ], "Title": "First text game with Python - Higher or Lower...
56126
<p>This question is a cross between career question and a code review. I was uncertain where to ask, but since there is code involved I went with CodeReview.</p> <p>I’m going through the process of technical interviews, and it hasn’t been a positive experience but I’m trying to make sense of the feedback I’ve gotten t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T20:32:38.277", "Id": "98768", "Score": "7", "body": "The first thing I noticed was that you had [a class whose name ended with `Manager`](http://blog.codinghorror.com/i-shall-call-it-somethingmanager/)." }, { "ContentLicense...
[ { "body": "<p>Your regex removes anything that's not 0-9 or a '.', then you replace the '.'. You could have removed the '.' from the regex to do it all in one shot:</p>\n\n<p>\"[^0-9]\" instead of \"[^0-9.]\"</p>\n\n<p>Remember to make sure to answer the question that was asked. You've simplified the number, b...
{ "AcceptedAnswerId": "56136", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T20:10:36.807", "Id": "56130", "Score": "32", "Tags": [ "c#", "unit-testing", "regex", "interview-questions" ], "Title": "What are some indicators that I was over-thinking m...
56130
<p>I created this library just for fun. Since I was a bit tired to write 10 lines of code to execute a simple select query in Android, I created a way make it simple.</p> <p>It's not so advanced and some Android query features are not ported, such as <code>beginTransaction</code>.</p> <p><code>BananaQuery</code> is ...
[]
[ { "body": "<h1>Pattern Matching</h1>\n<p>Let's focus on just this one method, for a moment:</p>\n<blockquote>\n<pre><code>static Pair&lt;String, List&lt;String&gt;&gt; parseNamedArguments(String condition, Map&lt;String, Object&gt; bindParams) {\n List&lt;String&gt; argumentsPair = new LinkedList&lt;String&g...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T20:46:44.230", "Id": "56135", "Score": "7", "Tags": [ "java", "android", "sqlite" ], "Title": "BananaQuery - Android one-line query" }
56135
<p>Out of a challenge for myself, I created this little program in which you can create "variables", test those "variable" values, test regular values, or clear all the "variables".</p> <pre><code>from operator import * oper = { "==": eq, "&gt;": gt, "&lt;": lt, "&lt;=": le, "&gt;=": ge, "!=":...
[]
[ { "body": "<p>The code is sufficiently trivial that it's hard to see where improvements could be made. The only element that isn't already compatible with Python 3 is <code>println</code> (<code>print</code> is a function in 3.x), which seems useless anyway - why would you do:</p>\n\n<pre><code>pcl.println(pcl....
{ "AcceptedAnswerId": "56147", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T21:03:06.060", "Id": "56138", "Score": "0", "Tags": [ "python", "python-2.x" ], "Title": "Variable creation and returning Boolean values" }
56138
<p>I started a project to build my own invoicing and management system to take the place of prohibitively expensive QuickBooks software. This will be broken down in 5 steps, with the current step in bold font, and previous steps linked. </p> <ol> <li><strong>Design the DB schema and table relationships, and insert dat...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T21:55:05.143", "Id": "98789", "Score": "0", "body": "Note, I will also post it to DBA after CR has been done to see if they find anything that I could do better." } ]
[ { "body": "<ul>\n<li><p><code>ProductType</code> should be normalized a bit further with a <code>ProductCategory</code> table. Alternatively, you could add a description column to product type, but I think the category table makes more sense. </p></li>\n<li><p>Instead of <code>Taxable</code> being a Boolean, yo...
{ "AcceptedAnswerId": "56184", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T21:53:13.770", "Id": "56145", "Score": "15", "Tags": [ "sql", "mysql" ], "Title": "Revision 1 - Step 1: PsychoProductions management tool project" }
56145
<p>I am currently doing a project for school, and I am completely stumped. We are only on Chapter 8 of <em>C# Development 1</em> and I have a question about the code.</p> <p>The project is:</p> <blockquote> <p><strong>Use a one-dimensional array to solve the following problem:</strong></p> <p>Write an app that the user...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T22:21:04.960", "Id": "98794", "Score": "0", "body": "First off you're right that Hashset is what you want in a normal situation. Basically you're trying to create a collection that has an idempotent Add()" }, { "ContentLicen...
[ { "body": "<p>Not sure whether there's some trickery here... But a simple solution could be:</p>\n\n<p>Simplest way would be an array of boolean for all possible numbers. When you enter 50, check position 50 and if it's false, it was the first time, now set that position to true so it can't be true the next tim...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T21:57:27.307", "Id": "56146", "Score": "2", "Tags": [ "c#", "array" ], "Title": "Duplication Elimination Project" }
56146
<p>I want to check if the structure that I use contains an object. To do so I wrote the following contains method:</p> <pre><code>boolean contains(Topic t){ if (t == null) return false; if (t.equals(root)) return true; else return false; } </code></pre> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T22:51:24.870", "Id": "98800", "Score": "1", "body": "Welcome to Code Review. We may be able to provide better advice if you include more context about what you are trying to accomplish." }, { "ContentLicense": "CC BY-SA 3.0"...
[ { "body": "<p>Neither is best. The best would be:</p>\n<pre><code>boolean contains(Topic t){\n return t != null &amp;&amp; t.equals(root);\n}\n</code></pre>\n<p>Using <code>equals</code> is better than using the properties of <code>Topic</code>, because of <strong>Single Responsibility Principle</strong></p>...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T22:33:43.150", "Id": "56151", "Score": "2", "Tags": [ "java" ], "Title": "Is this a good way of writing contains method in Java?" }
56151
<p>All I want is a simple "yes/possible" or "no/and that's bad coding".</p> <p>I have a card game I'm making and looking through your discard pile is a big part of it, so it's going to be constantly growing.</p> <p>Can I make a <code>for</code> loop to create new touch event so I don't have to make an <code>if</code>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T23:41:08.537", "Id": "98815", "Score": "1", "body": "Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving the cleanliness of existing, working code. This question se...
[ { "body": "<p>Your code indicates that you have a serious problem with your object oriented design. Objects are supposed to be 'opaque', and you should not be able to see the structure of the data in your object. Instead, you have this code, which is somehow able to access:</p>\n\n<ul>\n<li><code>board.turn.han...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-04T23:22:35.087", "Id": "56157", "Score": "-1", "Tags": [ "java", "android", "playing-cards", "event-handling" ], "Title": "Touched events created in a for loop" }
56157
<p>So, whether you're still in the development stages or your app is already on the app store, you always hope your app isn't crashing. But if it is, you want to be sure you've got good crash reports, right? Moreover, if your app is on the appstore, it may not be sufficient to wait around for Apple to upload crash re...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-18T02:37:36.117", "Id": "102482", "Score": "0", "body": "If you do this, be sure to include in your privacy policy, and preferably up-front to users who won't read the privacy policy, the information that you may be taking a screenshot...
[ { "body": "<pre><code>+ (instancetype)screenshot;\n</code></pre>\n\n<p>While it is good to use the <code>instancetype</code> as your return type to allow for subclass, there are two problems using it here.</p>\n\n<p>First, this is a class category, not a class, and the only way for a category to be included in ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T00:03:55.050", "Id": "56162", "Score": "10", "Tags": [ "objective-c", "ios", "exception", "category" ], "Title": "Unhandled Exception handler that captures a screenshot" }
56162
<p>Is my Application.php class secure for continuing development?</p> <p>The Application.php acts as a registry for the whole application. I tried not to rewrite already working code that is being pulled from Zend Framework and PhalconPHP, but allow myself to have freedom with using frameworks within my web applicatio...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-22T03:43:47.737", "Id": "103130", "Score": "0", "body": "\"Is my... class secure?\" - What exactly are the threats you're afraid of?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-22T21:01:00.863", "Id...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T02:51:06.783", "Id": "56166", "Score": "2", "Tags": [ "php", "object-oriented", "security", "classes", "php5" ], "Title": "Application Class Security" }
56166
<p>How can I improve this method that adds data to three tables in the database?</p> <p>The tables are:</p> <ul> <li><code>UserTable</code></li> <li><code>UserInfoTable</code></li> <li><code>ContactTable</code></li> </ul> <p><code>UserInfoTable</code> and <code>ContactTable</code> have a one-to-many relationship, wi...
[]
[ { "body": "<p>I think you want to use transactions. Within a transaction, you can certainly do INSERT + INSERT + SELECT the UserInfoID + the final INSERT. Commit the transaction at the end, after all successful, rollback on any exception.</p>\n\n<p>Rather than using the low level database APIs like managing <co...
{ "AcceptedAnswerId": "56177", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T04:15:55.633", "Id": "56167", "Score": "6", "Tags": [ "java", "sql", "jdbc" ], "Title": "Inserting tables with foreign key" }
56167
<p>I have one complex method with 1890 paths. I don't know how can be this refactored. Can somebody add some tips about it? Maybe the MySQL table structure is wrong.</p> <pre><code>public function fetchClubChallengeState() { $c = $this-&gt;caller-&gt;in_club; $o = $this-&gt;opponent-&gt;in_club; if (!$c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T08:07:06.387", "Id": "98845", "Score": "1", "body": "I'we extracted the bottom part to other method, but I think, it can be refactored further." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T10:28:03...
[ { "body": "<p>Don't know what happens in your db, but <code>LIMIT 1</code> suggests that result of your query will return exactly what you ask or nothing. In this case no need to compare caller and opponent in if statement - just return (false) from method when <code>$last</code> is empty/false.</p>\n\n<p>Other...
{ "AcceptedAnswerId": "56210", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T07:33:47.960", "Id": "56172", "Score": "4", "Tags": [ "php", "mysql" ], "Title": "Refactoring of this complex PHP method" }
56172
<p>I have a huge list of song objects in my program and I need those objects in almost all activities. Well, at least a part of it up to everything.</p> <p>So I created a class which looks pretty much like this :</p> <pre><code>class DataStore { private static ArrayList&lt;Song&gt; songList; private static Arr...
[]
[ { "body": "<blockquote>\n <p>I have a huge list of song objects in my program and I need those objects in almost all activities.</p>\n</blockquote>\n\n<p>Your description is an excellent fit for <a href=\"http://developer.android.com/guide/topics/providers/content-providers.html\">Content Providers</a>.</p>\n\...
{ "AcceptedAnswerId": "56178", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T10:43:37.787", "Id": "56175", "Score": "5", "Tags": [ "java", "android", "singleton" ], "Title": "Android global data" }
56175
<p>I want to implement KD tree. I have defined class <code>Node</code> as follows:</p> <pre><code>public static class Node{ int id; public double x; public double y; public Node leftChild; public Node rightChild; Node(int id, double x, double y){ this.id = id; this.x = x; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T10:54:34.343", "Id": "98856", "Score": "0", "body": "Can you give some more context about what you are using this for and what `Node` and `KDTree` are intended for?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate":...
[ { "body": "<p>Usually you would use generics in a classes like <code>KDTree</code> if you need to parametrize them at some point. What I mean here is, that you would construct a <code>KDTree</code> containing objects of type <code>Node</code> but also another <code>KDTree</code> but containing objects of type.....
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T10:45:07.287", "Id": "56176", "Score": "10", "Tags": [ "java", "tree", "generics" ], "Title": "Do I need Generics for these node and tree classes?" }
56176
<p>I have class point that represents point in 2D and I want to sort these points once based on their x-coordinate and second based on their y coordinate. Since x and y are double values my code looks like this:</p> <pre><code>public static class Point{ int id; public double x; public double y; Point(i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T13:59:30.743", "Id": "98870", "Score": "3", "body": "How do you call this method? How do you actually perform the compare, because, as it stands you can only sort with either the x or the y point, but not both." } ]
[ { "body": "<p>(First of all: Your code does not compile, unless I take the assumption that <code>Point</code> is an inner class)</p>\n\n<p>This seems like an <em>almost</em> proper way to handle it.<br>\nThe improvement I can think about though is to provide a <code>getXComparator()</code> method, and hence hid...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T13:40:35.437", "Id": "56185", "Score": "7", "Tags": [ "java", "sorting" ], "Title": "Comparator based on Double values in Java" }
56185
<p>I wrote this implementation using templates. It works fine and as expected. Just want to know if this can be improved. I have some specific questions too at the end. Please feel free to critique to your heart's content.</p> <pre><code>#include &lt;iostream&gt; template &lt;class T&gt; class Tree { // Internal ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-07T19:17:26.733", "Id": "99225", "Score": "1", "body": "Just as a note: `std::set<T>` is probably implemented as a tree (Its access characteristics defined in the standard would be the equivalent as if it was implemented by a balanced ...
[ { "body": "<blockquote>\n <p>Should I handle possible exceptions that can be thrown from <code>new</code>?</p>\n</blockquote>\n\n<p>Yes, if <code>new</code> fails, it'll throw <code>std::bad_alloc</code>, which should be caught and handled. Ideally, the tree should remain unchanged, but you may not be able to...
{ "AcceptedAnswerId": "56199", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T14:13:25.970", "Id": "56188", "Score": "6", "Tags": [ "c++", "c++11", "interview-questions", "tree", "template" ], "Title": "Binary Search Tree implementation using tem...
56188
<p>I study data structures on coursera's <a href="https://www.coursera.org/course/algs4partI" rel="nofollow">course</a>, and there is an extra exercise to create a Queue data structure.</p> <p>I created it:</p> <pre><code>class Queue { Integer[] data; int head, tail; public Queue() { data = new Integer[2]...
[]
[ { "body": "<h2>Imports:</h2>\n<blockquote>\n<pre><code>import java.util.*;\n</code></pre>\n</blockquote>\n<p><em><strong>NEVER</strong></em> do this. <a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/package-summary.html\" rel=\"nofollow noreferrer\">Look how many classes you got now.</a> This is ine...
{ "AcceptedAnswerId": "56213", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T14:40:03.797", "Id": "56193", "Score": "5", "Tags": [ "java", "queue" ], "Title": "Queue over resizable array implementation" }
56193
<p>I have a script which dynamically loads data onto a restaurant menu for printing. Could the following code could be shortened at all?</p> <pre><code> &lt;script&gt; $(document).ready(function(){ $('#prestarters').load('prestarters.php', '', function(response, status, xhr) { ...
[]
[ { "body": "<p>Piece iterates over <code>list</code>, calling same <code>$.ajax()</code>, <code>err</code> or, other functions, etc., for each item within <code>list</code>. Save <code>list</code> items to <code>_list</code> , poll until <code>_list.length === list.length</code> - all <code>list</code> items pro...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T14:42:27.637", "Id": "56194", "Score": "4", "Tags": [ "javascript", "optimization", "ajax" ], "Title": "Script for dynamically-loading data onto a restaurant menu for printing" }
56194
<p>I want to construct KD-Tree from unsorted List of points in the plane (i.e. 2-KD-Tree). To do so I used the method from Wikipedia: <a href="http://en.wikipedia.org/wiki/Kd-tree#Construction" rel="nofollow">http://en.wikipedia.org/wiki/Kd-tree#Construction</a> This is my code:</p> <pre><code>public static Node buil...
[]
[ { "body": "<pre><code>List.subList(low, high)\n</code></pre>\n\n<p>Is probably the easiest approach to take to the list management without requiring the copying of a lot of nodes. It does make a lot of <code>Lists</code> though, which are very short lived. This should be fine. If you really needed to keep th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T14:58:09.000", "Id": "56196", "Score": "3", "Tags": [ "java", "tree", "collections", "complexity", "clustering" ], "Title": "Construct KD-Tree in Java" }
56196
<p>Just used DI containers in MVC projects, via constructor injection, and I'd need to now inject a service into a console app. I'm using Autofac so I followed what I found <a href="https://code.google.com/p/autofac/wiki/GettingStarted">here</a>.</p> <p>The code would be something like this:</p> <p>The service the co...
[]
[ { "body": "<p>Your <code>Main</code> method has too many responsibilities: it's your application's <em>composition root</em>, <strong>and</strong> it's executing the program's logic... if printing to <code>Console</code> can be considered <em>logic</em>.</p>\n\n<p>There's not enough meat in this project to even...
{ "AcceptedAnswerId": "56207", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T15:00:02.353", "Id": "56197", "Score": "20", "Tags": [ "c#", "dependency-injection", "autofac" ], "Title": "Autofac DI container in console app" }
56197
<p>I have a node.js/express.js based REST application. In one GET service I am querying data based on different set of request parameters. I am looking for a better way to implement it.</p> <pre><code>function handleGet(connection,req,res) { var sql = 'SELECT id, name, age, rent, marks FROM student WHERE class = 10';...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T09:19:02.147", "Id": "98882", "Score": "1", "body": "Maybe this helps: http://stackoverflow.com/questions/16182652/javascript-query-selectors-dsl-as-an-independent-library" }, { "ContentLicense": "CC BY-SA 3.0", "Creatio...
[ { "body": "<p>I think it's counterintuitive that <em>both</em> <code>minAge</code> and <code>maxAge</code> have to be specified to have any effect. Why shouldn't the criteria work independently? Simplifying your code would also make your API less surprising. Don't bother with <code>BETWEEN ? AND ?</code>; go...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T02:05:39.623", "Id": "56202", "Score": "4", "Tags": [ "javascript", "sql", "node.js", "api" ], "Title": "Building SQL from multiple combinations of query parameters" }
56202
<p>I wrote these methods to encode data as array of <a href="http://en.wikipedia.org/wiki/Type-length-value" rel="noreferrer">TLV</a> objects, and also to serialize and deserialize them. Any feedback on improvements, etc. would be appreciated.</p> <p>Please note that I ignored endianness issues so far, as they are not...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T20:21:30.133", "Id": "98926", "Score": "3", "body": "\"Created by macbook air\"? ([See here if you want to fix it.](http://stackoverflow.com/a/6983301/68063))" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014...
[ { "body": "<h3>Typedef your structs:</h3>\n\n<p>Personally, I don't like having to write <code>struct</code> every time when using a user defined type:</p>\n\n<pre><code>struct tlv xyz;\n</code></pre>\n\n<p>I would suggest that you use a <code>typedef</code> for your structured types:</p>\n\n<pre><code>typedef ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T15:35:50.640", "Id": "56203", "Score": "10", "Tags": [ "c", "serialization" ], "Title": "Type-length-value (TLV) encode/decode" }
56203
<p>In following query I'm use both Common Table Expression and Outer queries. Apparently both looks same to me.</p> <p><em>If I summarize my requirement, I have employees in <code>SalaryTrans</code> table and I want to find out amounts to be recovered from their salaries monthly. Table <code>Rcovery</code> contains al...
[]
[ { "body": "<p>I find the query rather difficult to read due to your indentation style. For your benefit and for the benefit of other reviewers, I've reformatted your query, changing only the whitespace:</p>\n\n<pre><code>WITH CTE (employee_id, RID, instalment, reference, recovered_amount, total_amount) AS (\n ...
{ "AcceptedAnswerId": "56235", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T15:49:57.787", "Id": "56205", "Score": "2", "Tags": [ "sql", "sql-server", "null" ], "Title": "Using Common Table Expression and Outer queries" }
56205
<p>I've been implementing a function for calculating the <em>n</em><sup>th</sup> Fibonacci number in F#. So far the best implementation I could come up with is this:</p> <pre><code>let fib n = let rec fib = function | 0 -&gt; 0I, 1I | n -&gt; let f1, f2 = fib (n / 2) ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T17:12:25.037", "Id": "98897", "Score": "0", "body": "The question regarding tail-recursion is off-topic as we do not assist in adding additional implementation. As long as everything else works, it can still be reviewed." }, { ...
[ { "body": "<p>A concise and idiomatic (I think) implementation (which happens to be tail recursive) but without your <code>/ 2</code> optimisation would be:</p>\n\n<pre><code>let fib n =\n let rec tail n1 n2 = function\n | 0 -&gt; n1\n | n -&gt; tail n2 (n2 + n1) (n - 1)\n tail 0I 1I n\n</code></pre...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T16:40:02.097", "Id": "56209", "Score": "5", "Tags": [ "algorithm", "recursion", "f#", "fibonacci-sequence" ], "Title": "Fibonacci number function: convert to tail-recursion?" ...
56209
<p>I wrote the following short test code to test the performance of C++AMP and the PPL libraries against the sequential STL implementation of <code>std::transform</code>. To my surprise, both C++AMP and PPL implementations were significantly worse than the sequential implementation (C++AMP: 128ms, PPL: 51ms, Sequential...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T17:15:01.053", "Id": "98898", "Score": "0", "body": "Why are you using a macro? Just do `const int size = 30737418;`." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T17:18:55.037", "Id": "98903",...
[ { "body": "<p>I think in this case parallel execution (at least off the CPU) is unlikely to give a speedup. The problem is fairly simple: the operation you're carrying out (addition) is so simple that the bandwidth to memory is the controlling factor in the overall speed.</p>\n\n<p>With the operation happening ...
{ "AcceptedAnswerId": "56218", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T17:10:40.413", "Id": "56211", "Score": "2", "Tags": [ "c++", "optimization", "c++11", "concurrency", "amp" ], "Title": "PPL and AMP performing worse than sequential tra...
56211
<p>This post is in reference to: <a href="https://codereview.stackexchange.com/questions/55992/parsing-solr-log-files">Parsing Solr log files</a></p> <p>I re-wrote most of the code and split it up into a couple of classes. Currently, the class functionality is pretty limited, but I can see that I would need to reuse t...
[]
[ { "body": "<p>Here is my 2c. Please note this is constructive criticism, and goal is to help you get better. Please take any useful advice below, and disregard anything you don't agree with. I hope this helps. Some of this is extremely anal, but you will meet a lot of anal python developers who are religiously ...
{ "AcceptedAnswerId": "56897", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T18:29:30.253", "Id": "56214", "Score": "3", "Tags": [ "python", "parsing", "json" ], "Title": "Parsing Solr log files - version 2" }
56214
<p>I wanted to practice using sockets and multithreading. This is simple code where I start a <code>Server</code> and connect to it via <code>Client</code> and chat between them.</p> <p><code>Server</code> class:</p> <pre><code>public class Server { public static void main(String[] args) throws Exception{ ...
[]
[ { "body": "<pre><code>SocketEnhancer socketEnhancer = new SocketEnhancer(serverSocket.accept());\n</code></pre>\n\n<p>Currently, this is a not very advanced chat application as you can only have one client. It'll be a 1-1 conversation. It will just be one server and one client talking to each other. You can run...
{ "AcceptedAnswerId": "56220", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T18:49:25.710", "Id": "56217", "Score": "8", "Tags": [ "java", "multithreading", "console", "socket", "chat" ], "Title": "Simple chat console app" }
56217
<p>This is my first attempt at splitting the download buffer into several threads by the number provided. I want to improve on performance and better implementation approach.</p> <pre><code>import os import requests import threading import urllib2 import time url = "http://www.nasa.gov/images/content/607800main_kepl...
[]
[ { "body": "<h2>Utilizing Threads:</h2>\n\n<p>You are doing a number of things to slow down and serialize your code while the point of threads is to do things in parallel.</p>\n\n<pre><code>for idx in range(splitBy):\n byteRange = buildRange(int(sizeInBytes), splitBy)[idx]\n bufTh = SplitBufferThreads(url,...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T19:21:19.217", "Id": "56222", "Score": "1", "Tags": [ "python", "multithreading", "http", "concurrency", "url" ], "Title": "Split download file buffer by any number of thr...
56222
<p>I'm trying to get a better understanding of decoupling methods. Right now, I have this method:</p> <pre><code>private bool ContainsLegalFirstName(DataRow row, string legalFirstNameColumn) { return row.Table.Columns.Contains(legalFirstNameColumn) &amp;&amp; !String.IsNullOrEmpty(row[legalFirstNameColumn]...
[]
[ { "body": "<p>As <code>DataRow</code> does not implement <code>IDataRecord</code>, you would have to pass an adapter that wraps the row and implements the interface. Also, passing an <code>IListSource</code> would only help if it always returned a <code>ITypedList</code> (which is not guaranteed) which you coul...
{ "AcceptedAnswerId": "56259", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T19:34:15.607", "Id": "56225", "Score": "3", "Tags": [ "c#", "interface", ".net-datatable" ], "Title": "Loose coupling, accessing class properties" }
56225
<p>I feel like this maybe to much for one method... This method lives inside of a service class which is called by an interface. It dumps data into three different tables within a database.</p> <pre><code>public UserAccount CreateAccount(NewAccount newAccount) { if (!AccountAlreadyExists(newAccount.UserName)) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T00:34:00.897", "Id": "98948", "Score": "1", "body": "Why is there a class `NewAccount` and also a class `UserAccount`? I think you should remove `NewAccount` and use `UserAccount` instead. you then can save almost the whole block af...
[ { "body": "<p>I personally think this is fine if the concept of creating a <code>UserContact</code>, <code>User</code> is directly tied to creating a <code>UserAccount</code>, i.e. one cannot live without the other. </p>\n\n<p>That is because the abstraction of the method CreateAccount() hides away the impleme...
{ "AcceptedAnswerId": "56231", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T20:03:34.003", "Id": "56226", "Score": "2", "Tags": [ "c#", "beginner", ".net", "authentication" ], "Title": "Creating a New User Account" }
56226
<p>In my application I need to search for some songs on my external storage card every now and then. On startup I read everything, however when it comes to new activities I thought I could just pass the file paths and read the songs I need again.</p> <p>I've created this function:</p> <pre><code>public static Song ge...
[]
[ { "body": "<p>In general the code seems fine and it is not horrible or anything, but I think you could surely have improvements.</p>\n\n<h1>High level</h1>\n\n<p>Currently your code returns <code>null</code> if <code>audioCursor == null</code>, I think this should be an exception, possibly an existing one, or a...
{ "AcceptedAnswerId": "56348", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T20:09:47.720", "Id": "56228", "Score": "6", "Tags": [ "java", "performance", "android", "singleton" ], "Title": "Searching for songs on an Android application" }
56228
<p>I have a Visual Studio Solution which has a bunch of Projects in it. One of these projects is called "Services" and is basically the junction point between all remaining projects. When I built it originally I made it as generic as possible so I can expand on it. At the time I only had to work with Entity Framework b...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T21:54:00.163", "Id": "98934", "Score": "3", "body": "Rather than inheritance could you use composition instead, so nothing inherits from DbService, but instead they all contain private variables of type DbService??" }, { "Co...
[ { "body": "<h3>Zealous nitpicking...</h3>\n<blockquote>\n<p><em>am I being too zealous in trying to reduce the base class and interface inheritances</em></p>\n</blockquote>\n<p>Careful with wording here: a type <em>inherits</em> from a base class, and <em>implements</em> an interface. Interfaces aren't <em>inhe...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T20:29:26.107", "Id": "56230", "Score": "2", "Tags": [ "c#", "generics", "inheritance", "interface" ], "Title": "Many interfaces and lots of inheritance vs few interfaces and l...
56230
<p>I have an image upload script that uploads images to the server:</p> <pre><code>&lt;?php define("UPLOAD_DIR", "uploads/"); $fileType = exif_imagetype($_FILES["myFile"]["tmp_name"]); $allowed = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG); if (!in_array($fileType, $allowed)) { header('Location: edit.php'...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T23:44:49.897", "Id": "98942", "Score": "0", "body": "I would check for !empty && in_array just to be safe, otherwise, it looks pretty good" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T23:48:28.507"...
[ { "body": "<h2>The Security Aspect</h2>\n<p>Good to see that you're not just checking for a file extension in the name!!</p>\n<p><strong>Basically, yes</strong>, it's the minimal security needed. There aren't too many steps needed to make an image uploading script safe, however, doing it wrong could present som...
{ "AcceptedAnswerId": "56250", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T22:01:43.913", "Id": "56234", "Score": "4", "Tags": [ "php", "html", "image" ], "Title": "Does my image upload look safe enough?" }
56234
<p>I am writing a utility method which can check for empty and null string, or collection or an object or any general types -</p> <pre><code>public static boolean isEmpty(Object obj) { if (obj == null) return true; if (obj instanceof Collection) return ((Collection&lt;?&gt;) obj).size() == 0; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T17:07:40.367", "Id": "99030", "Score": "0", "body": "Why would you need to do this? This shouldn't be necessary under most circumstances. Additional information about the use case could help us give you a more appropriate solution."...
[ { "body": "<h1>Don't.</h1>\n<p>I mean. Don't use the same method for all kinds of objects.</p>\n<p>This method does not make much sense to me.</p>\n<p>This line smells. A lot.</p>\n<pre><code>if (obj instanceof Collection)\n return ((Collection&lt;?&gt;) obj).size() == 0;\n</code></pre>\n<p><a href=\"http://...
{ "AcceptedAnswerId": "56238", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-05T22:21:04.000", "Id": "56236", "Score": "8", "Tags": [ "java", "optimization", "null" ], "Title": "Writing a generic performance efficient isEmpty method which can check for nul...
56236
<blockquote> <p>Find all nodes, which are at a distance of <em>k</em> from the input node.</p> <p><a href="http://d2o58evtke57tz.cloudfront.net/wp-content/uploads/BinaryTree4.png" rel="nofollow noreferrer">http://d2o58evtke57tz.cloudfront.net/wp-content/uploads/BinaryTree4.png</a></p> <p><strong>Input:</strong></p> <p>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T01:07:25.430", "Id": "98952", "Score": "0", "body": "Please include the diagrams with your question... there's a button on the edit box to do that." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T01:1...
[ { "body": "<pre><code> int x;\n // if x &gt; 0, means the desired node was found in leftsubtree.\n if ((x = search(currNode.getLeft(), node, list, kthLevel)) &gt; 0) {\n</code></pre>\n\n<p>Why make this so complicated?</p>\n\n<p>Go for readability instead:</p>\n\n<pre><code> int x;\n x = search(c...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T00:18:52.650", "Id": "56239", "Score": "1", "Tags": [ "java", "algorithm", "tree" ], "Title": "Find K distant nodes" }
56239
<p>I wrote a user authentication program(s) for an MVC application. Before you ask part of the project specs are I have to store user information in company databases on servers that aren't the web server so the default membership classes are out of the question (as far as I am aware membership creates its own database...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T07:39:48.287", "Id": "98981", "Score": "0", "body": "Is there any particular reason why do you have Username on all tables: User, UserAccount and UserContact?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014...
[ { "body": "<ol>\n<li><p><code>UserName</code> as PK/CK of the <code>User</code> table and thus FK on all tables like <code>UserContact</code> may be a bad design choice. Especially if you have a lot of records, it may lead to index fragmentation.</p>\n\n<p>Suggestion: Add a <code>[Key] public int UserId { get; ...
{ "AcceptedAnswerId": "56264", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T01:35:44.293", "Id": "56241", "Score": "4", "Tags": [ "c#", "beginner", ".net", "authentication", "interface" ], "Title": "User Authentication Bundle" }
56241
<blockquote> <p><em>Continued from <a href="https://codereview.stackexchange.com/questions/56090">phase 1</a>; please read it first for background.</em></p> </blockquote> <h1>Overview</h1> <p>This phase focuses on assertions. Here's where things get ugly. <a href="https://github.com/philsquared/Catch" rel="nofollow...
[]
[ { "body": "<p>From a design perspective, I think this is overkill, I assume you know what you're doing.</p>\n\n<p>I looked at this code a fair bit, and it is well written, the only point is that</p>\n\n<pre><code>function decompose(assertion) {\n return '(' + assertion.replace(operatorPattern, quoteOperators...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T01:40:40.397", "Id": "56244", "Score": "4", "Tags": [ "javascript", "unit-testing" ], "Title": "Catch-style unit testing in JavaScript (phase 2)" }
56244
<p>I've authored a couple of plugins which show popovers on a given element. One of the objectives for both was no specification of plugin direction. So instead of the implementing dev having to specify <code>direction: left</code> the direction would automatically gravitate towards the center of the page while staying...
[]
[ { "body": "<p>Okay, I think I got it. Yay! This one has haunted me for awhile. The new gravity function is completely fluid, way more concise, and accurate.</p>\n\n<p>Instead of identifying specific points (top-left, bottom-right, middle-left, etc...) the new code pushes every possible point in steps (set to 20...
{ "AcceptedAnswerId": "57154", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T02:30:39.527", "Id": "56246", "Score": "3", "Tags": [ "algorithm", "coffeescript" ], "Title": "Automatically gravitate popover towards page center" }
56246
<p>I've implemented a binary heap in F#. It's pure and uses zippers for tree modification. To test it out I have implemented heap sort using it but it takes 10 seconds to sort a list of 100 000. Regular List.sort is instant and since heap sort should have the same complexity I'm wondering what I can do to improve my im...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T23:31:33.053", "Id": "99059", "Score": "0", "body": "Hi, your GitHub repo is missing some files (PriorityQueue.fs, PriorityQueue.fsi, Heap.fsi) and won't build." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "20...
[ { "body": "<p>First of all I'm not surprised that your algorithm is significantly slower than <code>List.sort</code>:</p>\n\n<ol>\n<li><code>List.sort</code> is implemented using <code>Array.Sort</code>, which uses <a href=\"https://en.wikipedia.org/wiki/Introsort\" rel=\"nofollow\">introsort</a>. Normal (array...
{ "AcceptedAnswerId": "57117", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T08:40:15.373", "Id": "56255", "Score": "4", "Tags": [ "optimization", "f#", "heap" ], "Title": "A functional binary heap implementation" }
56255
<p>I have some code that calculates the "sentiment" of a Tweet.</p> <p>The task starts with an <a href="http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6010">AFINN</a> file, that is a tab-separated list of around 2500 key-value pairs. I read this into a <code>dict</code> using the following function:</p>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T13:48:03.713", "Id": "99005", "Score": "2", "body": "Planning a [tender to the Secret Service?](http://www.bbc.com/news/technology-27711109) ;-)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T18:27:3...
[ { "body": "<p>As you may have probably suspected, the list comprehension in <code>processTweets</code> makes this non-streaming and eat a lot of memory, as it has to contain the entire result dictionary in memory before returning to the caller. Which might be fine, as it's just a list of integers.</p>\n\n<p>You...
{ "AcceptedAnswerId": "56257", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T08:43:07.710", "Id": "56256", "Score": "6", "Tags": [ "python", "performance", "python-2.x", "io" ], "Title": "Processing large file in Python" }
56256
<pre><code>import sys x=int(sys.stdin.readline()) lst = [int(sys.stdin.readline()) for i in xrange(x)] lst.sort() print lst </code></pre> <p>How can I make this code faster for large input?</p>
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T13:32:59.470", "Id": "99001", "Score": "0", "body": "You probably can't; Python's built-in sort is Timsort, which is [pretty good](http://stackoverflow.com/q/7770230/3001761)." }, { "ContentLicense": "CC BY-SA 3.0", "Cre...
[ { "body": "<p>You might be able to get a mild speed-up by simply running the above code in python 3 instead of 2 (use range instead of xrange, as xrange was depreciated in v3 and turned into range). Another possible speed up is running the code under <a href=\"http://pypy.org\" rel=\"nofollow\">http://pypy.org<...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T12:44:30.223", "Id": "56263", "Score": "-1", "Tags": [ "python", "performance", "sorting", "python-2.x" ], "Title": "Better sorting speed" }
56263
<p>I want to make a menu-item which:</p> <ul> <li>Reveals a drop-down submenu, when the item is hovered (using a mouse) or touched (using a touch-screen).</li> <li>Lets you click on a link in the submenu, while the submenu is visible</li> <li>Closes the submenu (without clicking on a link), if you move the mouse outsi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-07T08:09:24.217", "Id": "99106", "Score": "0", "body": "First, using -999em paints a very large and taxing element, use -100% or the exact width of the element instead. Second, a hover state is two part, which is why you may need to to...
[ { "body": "<p>Interesting question,</p>\n\n<p>as I noted, the provided code does not work, but you can do accomplish what you tried by using <a href=\"https://stackoverflow.com/a/13080306/7602\"><code>:active</code></a> note that this will not work without also setting <code>&lt;body ontouchstart=\"\"&gt;</code...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T13:50:56.563", "Id": "56267", "Score": "12", "Tags": [ "html", "css", "mobile", "touch" ], "Title": "Mobile touch menu" }
56267
<p>I have to solve the following problem: Given an array of integers and given an integer value, list all possible numbers frm the array that sums up to the given value. </p> <p>Example:</p> <p>Input: array = {1, 2, 2, 3, 4, 5}, int N = 5<br> Output: {1, 2, 2}, {1, 4}, {5} {2, 3}.</p> <p>This is my solution:</p> <p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T16:06:30.107", "Id": "99022", "Score": "5", "body": "This appears to be a variant of the subset sum problem, which is known to be NP-complete. Difficulty finding good solutions is to be expected. You can use dynamic programming to s...
[ { "body": "<ul>\n<li><p>It's a bit odd that you mix arrays and <code>ArrayList</code>'s.</p></li>\n<li><p>Stick to <code>List</code> (the interface) in the variable declarations instead of <code>ArrayList</code> (the implementation).</p></li>\n<li><p>You might get a stack overflow with all your recursive calls....
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T15:41:08.947", "Id": "56270", "Score": "12", "Tags": [ "java", "recursion", "interview-questions" ], "Title": "List all possible numbers from a given array that sums up to a given...
56270
<p>Is it possible to rewrite this piece of code any better when it comes to efficiency and/or readability?</p> <pre><code>public function dispatch() { $key = array_search($this-&gt;reqUri, $this-&gt;routes); if ($key !== false) { if (isset($this-&gt;methods[$key])) { if ($this-&gt;methods[...
[]
[ { "body": "<p>The <code>array_search</code> will iterate over every element in <code>$this-&gt;routes</code>. That's not scalable. It would be better to reorganize <code>$this-&gt;routes</code> so that you can lookup keys more directly, so that your code will work like this:</p>\n\n<pre><code>if (isset($this-&g...
{ "AcceptedAnswerId": "56274", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T15:50:53.307", "Id": "56272", "Score": "4", "Tags": [ "php", "optimization" ], "Title": "Rewriting dispatch method" }
56272
<p>The parser below is not designed for every single US address. I am parsing through a file where each line may or may not be an address. I am more focused on speed rather than robustness.</p> <ul> <li><p><code>state-abbreviation-lookup</code> and <code>street-suffix-lookup</code> are booth used for consistency (ad...
[]
[ { "body": "<h2><code>split-string</code> can be simplified</h2>\n\n<p>You're defining a function that takes an argument <code>s</code> and applies the <code>comp</code>osite of 3 different <code>clojure.string</code> functions to <code>s</code> within the body of the function. You could simplify this in 2 ways:...
{ "AcceptedAnswerId": "56375", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T16:22:33.013", "Id": "56275", "Score": "4", "Tags": [ "beginner", "parsing", "clojure" ], "Title": "Parsing US address with Clojure" }
56275
<p>I'm using Python to find fixed points of a given function and then draw a <a href="https://en.wikipedia.org/wiki/Cobweb_plot" rel="nofollow noreferrer">cobweb plot</a> to visualize it. Thanks to <a href="https://stackoverflow.com/questions/5571457/fixed-point-iteration-and-plotting-in-python">this question</a>, I ha...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T19:50:11.933", "Id": "99048", "Score": "1", "body": "The answer to questions 1, 2 and 4 is to make the things you want to change into *arguments to the functions/methods*. And yes, there's no real reason for the class - `search` and...
[ { "body": "<h2>Your questions</h2>\n\n<ol>\n<li>Functions can be function arguments, too.</li>\n<li>You can add a parameter for that.</li>\n<li>See additional comments. I think it's fine that you use a class.</li>\n<li>That is usually not in the range of codereview. That should be asked in StackOverflow (but I ...
{ "AcceptedAnswerId": "60752", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T18:19:53.563", "Id": "56281", "Score": "5", "Tags": [ "python", "beginner", "classes", "numpy", "numerical-methods" ], "Title": "Fixed point iteration and cobweb plot" ...
56281
<p>I use Lazarus 1.2.4 and Freepascal 2.6.4. </p> <p>I have created a program that reads a disk in buffers of 64Kb (tried various buffer sizes) using a repeat...until loop. Each buffer is hashed using the SHA1 unit, specifically, SHA1Init, SHA1Update and SHA1Final.</p> <p>The trouble is, is that although it works and...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-07T04:50:08.533", "Id": "99090", "Score": "0", "body": "There is a frequently run code in SHA1Transform() which you did not show (it maybe the assembly rewrite candidate). Do you use this https://github.com/graemeg/freepascal/blob/mast...
[ { "body": "<p>If you're processing 1.8Gb per minute using 64Kb buffers, that's (1800000 / 64 =) 28000 buffers per minute i.e. (28000 / 60 =) 470 buffers / second.</p>\n\n<p>I don't know what you're doing elsewhere with these statements ...</p>\n\n<pre><code>ProgressCounter := ProgressCounter + 1; // We use this...
{ "AcceptedAnswerId": "56289", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T19:28:30.247", "Id": "56284", "Score": "8", "Tags": [ "performance", "hashcode", "pascal" ], "Title": "Enhancing speed of looping cycle using Freepascal" }
56284
<p><a href="http://learnyouahaskell.com/functionally-solving-problems#heathrow-to-london" rel="nofollow noreferrer">Working on Functionally Solving Problems</a> from <em>Learn You a Haskell</em>, I worked on the "Heahtrow to London" shortest path problem.</p> <p>I'm working on a reduced set of this problem in order to...
[]
[ { "body": "<h2>Data representation</h2>\n\n<p>My critique starts here:</p>\n\n<pre><code>data Tree a = EmptyTree | Node a (Tree a) (Tree a)\n</code></pre>\n\n<p>Why is a node forced to have 2 sub-trees? Given a graph like this:</p>\n\n<pre><code> B1 - C1\n | |\nA - B2 - C2\n | |\n B3 - C3\n<...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T20:20:27.627", "Id": "56286", "Score": "4", "Tags": [ "haskell", "pathfinding" ], "Title": "Finding Shortest Path" }
56286
<p>A node has a next and down pointer. Merge the linked-list such that end result is sorted. Here we have a top level linked-list, followed by a down-list. If { 10 : {20, 30} , 35 { 40, 50 } } is the input data structure. It means that, 10 is connected to 35, using the next pointer. 10 is connected to 20 and 20 to 30...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T22:44:41.940", "Id": "99058", "Score": "0", "body": "Hypothetical code here. This is an example of 'WOM', write only memory." } ]
[ { "body": "<p>What you're really asking for is a <a href=\"http://en.wikipedia.org/wiki/Mergesort\" rel=\"nofollow\">mergesort</a>, where each of the \"down\" lists is already sorted and you're trying to merge them into a master list.</p>\n\n<h1>Analysis of Computational Complexity</h1>\n\n<p>I'm surprised you ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T21:19:17.947", "Id": "56287", "Score": "0", "Tags": [ "java", "linked-list" ], "Title": "Given a two dimensional linked list, create a flattened sorted list" }
56287
<p>Douglas Hofstadter's Pulitzer-prize-winning book, Gödel, Escher, Bach, poses the following mathematical puzzle:</p> <blockquote> <ul> <li>Pick a positive integer <em>n</em> as the start.</li> <li>If <em>n</em> is even, divide it by 2.</li> <li>If <em>n</em> is odd, multiply it by 3 and add 1.</li> <li>Con...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-07T13:46:34.623", "Id": "99168", "Score": "1", "body": "This is also known as the [Collatz sequence](http://en.wikipedia.org/wiki/Collatz_conjecture). And yes, it makes sense to use recursion - then you can memoize it for an easy \"dyn...
[ { "body": "<p>Your code is a bit awkward, mostly due to:</p>\n\n<ol>\n<li>Repetition;</li>\n<li>Repetition; and</li>\n<li>Doesn't follow <a href=\"http://legacy.python.org/dev/peps/pep-0008/#whitespace-in-expressions-and-statements\" rel=\"nofollow\">PEP-0008</a> (specifically, e.g. <code>if(n&lt;0):</code> sho...
{ "AcceptedAnswerId": "56414", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T22:08:14.183", "Id": "56288", "Score": "-2", "Tags": [ "python", "programming-challenge", "recursion", "collatz-sequence" ], "Title": "hailstone sequence using recursion in...
56288
<p>I ran it and it's working, but I just want someone to double check that I followed the directions. Any suggestions or corrections will be appreciated. </p> <ol> <li><blockquote> <p>Assume you have a <code>NSString *str</code> object containing some text. Write a code fragment to create a new string with all subst...
[]
[ { "body": "<p>In both cases, this is exactly the most efficient way for removing a substring from a string.</p>\n\n<p>In practice, I'm not sure how practical or how frequently you'll truly need to be using the second example, and for most of us, simply doing this:</p>\n\n<pre><code>string1 = [[string1 stringByR...
{ "AcceptedAnswerId": "56301", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T23:13:32.157", "Id": "56292", "Score": "5", "Tags": [ "beginner", "strings", "objective-c" ], "Title": "Replacing occurrences in NSString and NSMutableString" }
56292
<p>I am seeking advice on the efficiency and long term implications of various ways of capturing modifications to instance variables that I have tried implementing. Essentially, this is setup:</p> <p>In my framework, I originally had a class whose sub classes were only supposed to contain public instance variables - ...
[]
[ { "body": "<blockquote>\n <p>In my framework, I originally had a class whose sub classes were only supposed to contain public instance variables - kind of like a struct in C. </p>\n</blockquote>\n\n<p>^^^ That, that's the source of your problem ^^^</p>\n\n<p>Java is an object oriented language. Objects encapsu...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T23:47:11.327", "Id": "56294", "Score": "8", "Tags": [ "java", "observer-pattern" ], "Title": "Listening to modifications on variables" }
56294
<p><code>NSString</code> is the plain-text character-string class in Cocoa (<a href="/questions/tagged/cocoa" class="post-tag" title="show questions tagged &#39;cocoa&#39;" rel="tag">cocoa</a>) and Cocoa Touch (<a href="/questions/tagged/cocoa-touch" class="post-tag" title="show questions tagged &#39;cocoa-touch&#39;" ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-07T00:32:52.940", "Id": "56297", "Score": "0", "Tags": null, "Title": null }
56297
NSString is the plain-text character-string class in Cocoa and Cocoa Touch. See also NSMutableString, NSData and NSMutableData (for objects that contain bytes rather than human-language characters), and NSAttributedString and NSMutableAttributedString (for rich-text strings).
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-07T00:32:52.940", "Id": "56298", "Score": "0", "Tags": null, "Title": null }
56298
<p>To construct and manage an immutable string — or a string that cannot be changed after it has been created — use an object of the NSString class.</p> <p>The NSMutableString (<a href="/questions/tagged/nsmutablestring" class="post-tag" title="show questions tagged &#39;nsmutablestring&#39;" rel="tag">nsmutablestring...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-07T00:33:38.890", "Id": "56299", "Score": "0", "Tags": null, "Title": null }
56299