body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I am trying to write something that will copy the current <code>&lt;input&gt;</code>s value and enter it into any <code>&lt;input&gt;</code> that start with the same name.</p> <p><code>&lt;input&gt;</code> names will follow this pattern: <code>price-0</code>, <code>price-1</code>, <code>price-2</code>, <code>upc-0<...
[]
[ { "body": "<p>Why not at least save the intermediate to avoid rerunning that:</p>\n\n<pre><code>$(document).on('click', '.--copy', function () {\n var obj = $(this).closest('div').find('input');\n var input_name = obj.attr('name').split('-')[0];\n $('input[name^=' + input_name + ']').val(obj.val());\n}...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-10-25T05:41:33.127", "Id": "33213", "Score": "4", "Tags": [ "javascript", "jquery" ], "Title": "Copying and pasting one inputs value into other input with the same name" }
33213
<p>I have this code which compares data from two data tables. It does this by using a primary column and inserting the new record from <code>table2</code> to <code>table1</code>. This loop continues for a large number of tables. I want to optimize it. Kindly give suggestions.</p> <pre><code>foreach (DataRow drRow in ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T07:33:58.373", "Id": "53212", "Score": "0", "body": "What version of .net framework is being used ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T08:22:00.253", "Id": "53213", "Score": "0", ...
[ { "body": "<p>For .net framework 3.5, you can have following code improvements:</p>\n\n<pre><code>foreach (var drRow in table2.Rows.Cast&lt;DataRow&gt;()\n .Where(drRow =&gt; !table1.Rows.Contains(drRow[\"KeyId\"]))) \n{\n table1.ImportRow(drRow); \n}\n</code></pre>\n\n<ol>\n<li>part of ...
{ "AcceptedAnswerId": "33431", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T06:24:37.147", "Id": "33215", "Score": "1", "Tags": [ "c#", "optimization" ], "Title": "Comparing data from two data tables" }
33215
<p>At the moment I have seven if statements that resemble the following code:</p> <pre><code>if(hit.collider.gameObject.tag == "Colour1" &amp;&amp; start_time &gt; look_at_time) { new_colour1.ChangeObjectMaterialColour(hit.collider.gameObject.renderer.material.color); var colums = Game...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T08:48:43.847", "Id": "53214", "Score": "0", "body": "The only thing different in the bodies of the if statements is the new_colour1/new_colour2 object. If you made a helper function that took hit.collider.gameObject.tag and returne...
[ { "body": "<p>We can start looking at what is duplicated. For example, the only difference between the two blocks of code is the string <code>\"Color1\"</code> and <code>\"Color2\"</code> in the if statement, and the variable <code>new_colour1</code> which is replaced with <code>new_colour2</code>.</p>\n\n<p>F...
{ "AcceptedAnswerId": "33219", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T08:23:55.247", "Id": "33217", "Score": "1", "Tags": [ "c#" ], "Title": "Refactoring a collection of if statements that contain 2 arguments." }
33217
<p>CodeEval's "<a href="https://www.codeeval.com/public_sc/60/" rel="nofollow">Grid Walk</a>" problem is as follows:</p> <blockquote> <p>There is a monkey which can walk around on a planar grid. The monkey can move one space at a time left, right, up or down. That is, from (x, y) the monkey can go to (x+1, y), (x-1,...
[]
[ { "body": "<h3>1. Comments on your code</h3>\n\n<ol>\n<li><p>There are no docstrings. What do your functions do and how am I supposed to call them?</p></li>\n<li><p>This kind of code is a good opportunity to write some <a href=\"http://docs.python.org/3/library/doctest.html\" rel=\"noreferrer\">doctests</a>.</p...
{ "AcceptedAnswerId": "33223", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T09:41:34.707", "Id": "33220", "Score": "3", "Tags": [ "python", "search" ], "Title": "Grid walk problem" }
33220
<p>Would you please run through this code and provide your comments?</p> <pre><code>void quote_container::allocate(string *i_string, string *i_value){ string temp_name = *i_string; double temp_value; // Convert the input string to upper case. stringToUpper(temp_name); if (temp_name =="OPEN"){ ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T19:22:34.300", "Id": "53249", "Score": "0", "body": "Recommendation #1: Don't use strings!" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T20:28:03.057", "Id": "53255", "Score": "1", "bod...
[ { "body": "<p>First step: move the code common to all cases out of the conditions:<br>\n(you may add handling if *i_value cannot always be converted to float)</p>\n\n<pre><code>void quote_container::allocate(string *i_string, string *i_value){\n string temp_name = *i_string;\n double temp_value = atof( (*...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T12:20:53.193", "Id": "33225", "Score": "2", "Tags": [ "c++", "strings" ], "Title": "Comparing and assigning strings" }
33225
<p>I've wrote a generic function to add an item to an Array 2D</p> <p>This is what I have:</p> <pre><code>Private Sub Add_Item_Array_2D(ByRef Array_2D As String(,), _ ByVal Items As String()) Dim tmp_array(Array_2D.GetUpperBound(0) + 1, Array_2D.GetUpperBound(1)) As String For ...
[]
[ { "body": "<p>Couple nitpicks:</p>\n\n<ul>\n<li><strong>Try to stick to <em>PascalCasing</em> for method names</strong>. Using <code>_</code> underscores not only makes your method names look rather messy, the underscore is conventionally used for event handler methods (like <code>Form1_Load</code>, i.e. <code>...
{ "AcceptedAnswerId": "35738", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T13:59:35.427", "Id": "33232", "Score": "2", "Tags": [ ".net", "array", "linq", "vb.net", "generics" ], "Title": "Add item to an Array 2D using LINQ" }
33232
<p>Version 3.5 of the .NET Framework was released on 19 November 2007, but it is not included with Windows Server 2008. As with .NET Framework 3.0, version 3.5 uses Common Language Runtime (CLR) 2.0, that is, the same version as .NET Framework version 2.0. </p> <p>In addition, .NET Framework 3.5 also installs .NET Fra...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T14:12:30.787", "Id": "33233", "Score": "0", "Tags": null, "Title": null }
33233
Version #3.5.21022.8 of the .NET Framework was released on November 11th, 2007. It is needed to support windows 7 and windows server 2008 R2. Its preferred IDE is Visual Studio 2008.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T14:12:30.787", "Id": "33234", "Score": "0", "Tags": null, "Title": null }
33234
<p>I'm currently populating my drop downlists like this...</p> <pre><code> public List&lt;NewLogin&gt; GetRolesForDDL() { using (database db = new database()) { return (from r in db.UserRole select new NewLogin { UserRole...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T07:07:29.823", "Id": "53298", "Score": "1", "body": "Is there code missing? Why are you making a database connection twice?" } ]
[ { "body": "<blockquote>\n <p>Can I access both RoleName and ID without fetching it in the backend?</p>\n</blockquote>\n\n<p>Yes, I believe so if you want to write a bit of javascript. You would need to create a \nhidden field and on every select list change event set the value of that field.</p>\n\n<p>Somethi...
{ "AcceptedAnswerId": "33284", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T14:34:19.823", "Id": "33236", "Score": "2", "Tags": [ "c#", "linq", "asp.net-mvc-4" ], "Title": "Improving MVC 4 DropDownList" }
33236
<p>I've written my first completely self-written jQuery today. I just used the jQuery docs and I'm reasonably proud I got it to work, and working fine. It's not a very complex problem I'm solving, just an animated UI element, but it are my first steps, and I want to make sure I'm starting off right.</p> <p>I think it'...
[]
[ { "body": "<p>For one, it can be done <a href=\"http://jsfiddle.net/yeawg/4/\" rel=\"nofollow\">CSS-only</a>.</p>\n\n<p>JS:</p>\n\n<pre><code>None at all. Remove your JS.\n</code></pre>\n\n<p>HTML:</p>\n\n<pre><code>&lt;nav class=\"mobile-navigation\"&gt;\n &lt;!-- dummy target since CSS has no \"prev\" --&g...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T14:58:39.770", "Id": "33237", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "My first-ever jQuery works, but it's not efficient. Any pointers?" }
33237
<p>I've finally got all my code working as expected and it handles the data quickly. But now I'm looking to refactor it because there is some duplicate sections that just looks like can be broken down for more efficiency and readability. With out making this too long, here is the original:</p> <p>I created functions...
[]
[ { "body": "<p>Addressing the duplication, it seems that both conditions are processed the same with the exception of <code>format</code>. You could either provide an inline conditional (ternary statement) to determine the format to use or pass the <code>codeID</code> to a function and return the respective form...
{ "AcceptedAnswerId": "33246", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T16:16:45.477", "Id": "33240", "Score": "0", "Tags": [ "javascript", "performance" ], "Title": "Refactoring code for more readability" }
33240
<p>How will you merge two sorted arrays, when The longer array has empty spaces to accomodate the second array. Complexity: O (items in longer + items in smaller). Request for making code concise, clean and optimal. </p> <pre><code>public final class MergeArrays { private MergeArrays() {} private static vo...
[]
[ { "body": "<p>Do not throw NullPointerException when arguments are null. NPE is thrown when you are trying to access properties and methods of null reference. Not when you are checking on some preconditions. Throw IllegalArgumentException as you do in length validation. In other method you use assertions. Chose...
{ "AcceptedAnswerId": "33443", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T16:35:13.427", "Id": "33243", "Score": "1", "Tags": [ "java", "algorithm", "array" ], "Title": "Merge 2 arrays, when one is larger and can accomodate smaller" }
33243
<p>Someone posted a question on <a href="http://math.stackexchange.com">http://math.stackexchange.com</a> earlier because their program to tranpose a matrix wasn't working. I copied the code they posted (which was just the transpose method) and added the code necessary to check if it worked on their example matrix and ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T19:18:44.027", "Id": "53247", "Score": "2", "body": "Hmm, the code is awful but you did ask the right questions to improve it. However, any answer would have to focus more on Java basics than an actual code review." }, { "Co...
[ { "body": "<p>I've found the info I needed by looking at a sample program on the Java Outside In website. The problem was I was just putting </p>\n\n<p><code>printMatrix();</code></p>\n\n<p>in the main method rather, than instantiating a Matrix Ma and then putting </p>\n\n<p><code>Ma.printMatrix();</code></p>\n...
{ "AcceptedAnswerId": "33257", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T18:44:16.540", "Id": "33245", "Score": "0", "Tags": [ "java", "static" ], "Title": "How to overcome static referencing errors in Java/basic programming?" }
33245
<p>I plan on including this work in a portfolio. </p> <p>Will this code get me hired or laughed at?</p> <p>More specifically:</p> <ol> <li>How would you rate the general complexity of the code?</li> <li>How bad does the code smell?</li> <li>Is the VC too fat?</li> <li>Glaring best practices mistakes?</li> </ol> <p>...
[]
[ { "body": "<p>A few things I would ask if I saw this as an interviewer (from a very quick read, and obviously not having seen it run):</p>\n\n<ul>\n<li>why use a UIViewController and not a UITableViewController (refresh control property is free then)</li>\n<li>the rasterisation on table view shouldn't be needed...
{ "AcceptedAnswerId": "33382", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T19:22:40.940", "Id": "33247", "Score": "4", "Tags": [ "objective-c", "interview-questions", "ios" ], "Title": "MasterViewController" }
33247
<p>I'm open to any comments on this code/approach. This is mostly architecture and threading.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel; using System.ServiceModel; using System.ServiceProcess; using System.Configuration; using Sys...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T20:43:04.637", "Id": "53257", "Score": "2", "body": "it is unclear what you want us to review, if you would like an overall review please state this in the question please. Code-Only Questions are frowned upon, on Stack Exchange si...
[ { "body": "<ol>\n<li><p>Your double checked lock implementation for <code>messages</code> is subtly broken (the field should be volatile in order to create a memory barrier, this <a href=\"http://msdn.microsoft.com/en-us/library/ff650316.aspx\" rel=\"nofollow\">MSDN</a> explains it with singleton as example but...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T19:24:47.490", "Id": "33248", "Score": "1", "Tags": [ "c#", "wcf" ], "Title": "Simple WCF messaging system via EF" }
33248
<p>I need to use sockets from winsok2.h. So, I written a class NetObject to use it. But, when I do compilation I am getting an error:</p> <pre><code>error LNK2019: unresolved external symbol "public: int __thiscall wsa::NetObject::connect(void)" (?connect@NetObject@wsa@@QAEHXZ) referenced in function _main </code></pr...
[]
[ { "body": "<p>Thats because in Visual Studio, including <code>winsock2.h</code> to your headers is not enough. You have to tell the Linker your project will need the library <code>wsock32.lib</code>.</p>\n\n<p>You can do that either by editing the properties of your project, or by including this line to your co...
{ "AcceptedAnswerId": "33253", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T19:44:13.477", "Id": "33250", "Score": "2", "Tags": [ "c++" ], "Title": "Unresolved External Symbol C++" }
33250
<p>I'm trying to simulate the Monty Hall problem, to statistically determine if there is any benefit to changing my choice after a door containing a goat is open (testing <a href="https://www.youtube.com/watch?v=mhlc7peGlGg" rel="nofollow">this guy's</a> Monty Hall theory on YouTube).</p> <p>So, does this manage to si...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T20:52:44.257", "Id": "53260", "Score": "0", "body": "this question might be better suited for programmers.stackexchange.com rather than here. how have you tested this code to make sure that it works?" }, { "ContentLicense":...
[ { "body": "<p>ok, so i ended up changing more than was strictly necessary, sorry. as you probably know, it <em>does</em> pay to change doors, so your code <em>did</em> have a bug. i didn't try to trace it down exactly, but i assume it was related to you having 4 doors instead of 3, which i guess was because y...
{ "AcceptedAnswerId": "33264", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T20:26:38.323", "Id": "33256", "Score": "4", "Tags": [ "c", "simulation" ], "Title": "Is this an elegant/accurate simulation of the Monty Hall problem?" }
33256
<p>I'm new to scala and have been working to understand the syntax so that I can be more efficient. How does this look in terms of functional syntax and scala idioms?</p> <p>In particular, I'd like to know if this is a good way of handling futures. I'm aware of onComplete, onSuccess, etc..., matching but I had troub...
[]
[ { "body": "<p>Future \"callbacks\" can be simplified by using the <code>for</code> comprehension to compose futures. More information can be found here <a href=\"http://docs.scala-lang.org/overviews/core/futures.html#functional_composition_and_forcomprehensions\" rel=\"nofollow\">http://docs.scala-lang.org/over...
{ "AcceptedAnswerId": "39244", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T20:47:57.453", "Id": "33260", "Score": "4", "Tags": [ "scala" ], "Title": "is this future map scala syntax good?" }
33260
<p>Can this be shortened/improved? I'm trying to make a password checker in Python.</p> <p>Could the <code>if</code>s be put into a <code>for</code> loop? If so, how?</p> <pre><code>pw = input("Enter password to test: ") caps = sum(1 for c in pw if c.isupper()) lower = sum(1 for c in pw if c.islower()) nums = sum(1...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T22:18:01.170", "Id": "53268", "Score": "3", "body": "the code works from the looks of Gareth's answer, but I agree that your knowledge of Password strength is lacking. Note: [Password Strength](http://xkcd.com/936/)" } ]
[ { "body": "<pre class=\"lang-none prettyprint-override\"><code>Enter password to test: premaintenance disdainful hayloft seer\ntoo long\nyour password strength is medium\n\nEnter password to test: NXJCWGGDVQZO\nyour password strength is weak\n\nEnter password to test: Password1\nstrong\n</code></pre>\n\n<p>Your...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T21:34:34.717", "Id": "33262", "Score": "7", "Tags": [ "python", "security" ], "Title": "Password checker containing many conditional statements" }
33262
<p>I'm a beginner in JEE development. I have just finished a web application that I'm going to deploy in a server.</p> <p>It's a new level for me; it's not just a simple application that I can run for 10 min, etc.</p> <p>My question is for the quality of code. Of course we all know that a piece of code that works d...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T05:05:21.313", "Id": "53288", "Score": "3", "body": "you are iterating listChaletss two times. This could be expensive. When you have this type situation, try to manage your structure in one iteration." }, { "ContentLicense"...
[ { "body": "<p>A possible memory concern that I can think of is this line:</p>\n\n<pre><code>listChaletp.add(it);\n</code></pre>\n\n<p>If you're never <strong>removing</strong> elements from that list (which is hard for me to know since I only see a portion of your code), then sooner or later <strong>that list w...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T22:53:10.837", "Id": "33265", "Score": "3", "Tags": [ "java", "beginner", "memory-management" ], "Title": "A good management of Java code" }
33265
<p>This is my solution to the problem in the title. The code is pretty straightforward. The one problem is with <code>substring</code>; it's \$O(n)\$ in .Net and creates garbage. Any other improvements?</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Long...
[]
[ { "body": "<p>The first thing that strikes me is that you've put everything within the <code>Program</code> class, which forces your methods to be <code>static</code>, and any program where everything is <code>static</code> is a program I want to rewrite :)</p>\n\n<p>Let's start with <code>FindLongestWords(stri...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T23:38:19.377", "Id": "33266", "Score": "6", "Tags": [ "c#", "strings", "interview-questions" ], "Title": "Write a program to find the longest word made of other words" }
33266
<pre><code>function score_to_grade(score1) { var score = 100 - score1; if (score == 100) return 'A+'; else if (score &gt; 93) return 'A'; else if (score &gt; 87) return 'A-'; else if (score &gt; 81) return 'B+'; else if (score &gt; 69 ) return 'B'; else if (score &gt; 63 ) return...
[]
[ { "body": "<p>A <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch\" rel=\"nofollow\">switch statement</a> would serve you much better in this case.</p>\n\n<p>I'm not quite sure what the line <code>var score = 100 - score1;</code> does. is <code>score1</code> the numb...
{ "AcceptedAnswerId": "33272", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T23:44:42.317", "Id": "33267", "Score": "-1", "Tags": [ "javascript" ], "Title": "Mapping a score to a string" }
33267
<p>I have implemented kNN (<a href="http://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm" rel="nofollow">k-nearest neighbors</a>) as follows, but it is very slow. I want to get an exact k-nearest-neighbor, not the approximate ones, so I didn't use the <a href="http://www.cs.ubc.ca/research/flann/" rel="nofollow">...
[]
[ { "body": "<p>Your code appears to be very C-like with some C++. I'll just give some feedback in regards to that:</p>\n\n<ul>\n<li><p>Try not to use <a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\"><code>using namespace std</code></a>.</p></li>\n<li><p>...
{ "AcceptedAnswerId": "40006", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T00:00:05.037", "Id": "33269", "Score": "7", "Tags": [ "c++", "performance", "matlab", "clustering", "native-code" ], "Title": "k-nearest neighbors using MATLAB with MEX...
33269
<h1>background</h1> <p>A little over a year ago I was given the creative freedom to develop on the side of my primary responsibilities. I want to move into development, but am not currently in that role. I was given the resources to develop a PHP application that handled a lot of the reporting functions for our busines...
[]
[ { "body": "<p>My general suggestion to you is use a <a href=\"http://en.wikipedia.org/wiki/Web_content_management_system\" rel=\"nofollow\">CMS</a>, like <a href=\"http://wordpress.org/\" rel=\"nofollow\">WordPress</a> or <a href=\"https://drupal.org/\" rel=\"nofollow\">Drupal</a> or if you want a more low-leve...
{ "AcceptedAnswerId": "33276", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T01:52:16.230", "Id": "33273", "Score": "2", "Tags": [ "javascript", "php", "ajax" ], "Title": "PHP Application, attempting to restructure (Massive case/switch, ajax calls)" }
33273
<p>Is there any other way to shorten this code without sacrificing readability? I am fairly new to C#, let alone programming, and I wanted to know if this is as short as this code can possibly become. Feedback would be greatly welcomed.</p> <p>Side note: was <code>Questions.Questask</code> used properly here, or cou...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T02:48:51.090", "Id": "53281", "Score": "2", "body": "Stick the result of ToLower() into a new variable. You'll only have to call ToLower() once that way." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-...
[ { "body": "<p>When I need a simple <a href=\"http://en.wikipedia.org/wiki/Strategy_pattern\" rel=\"nofollow\">strategy pattern</a> I'll use a <code>Dictionary</code>. This can drastically reduce code by cutting repetition.</p>\n\n<p>Note the use of <code>StringComparer.InvariantCultureIgnoreCase</code> for <a h...
{ "AcceptedAnswerId": "33278", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T02:46:29.403", "Id": "33274", "Score": "2", "Tags": [ "c#", "beginner", "url" ], "Title": "Shortening my questions code" }
33274
<p>This works just fine, however, the assignment was to write a recursive "function". I'm curious to see if this should count. </p> <p>Any comments / suggestions/ stuff I should watch out for are appreciated. </p> <pre><code>#include &lt;iostream&gt; #include &lt;functional&gt; #include &lt;cctype&gt; #include &lt;c...
[]
[ { "body": "<p>Not that familiar with C++, but that certainly looks like recursion to me...</p>\n\n<p>The variable gcd contains a function, which then calls itself. The very definition of recursion.</p>\n\n<p>But I would ask what you gain by not making it a regular function?</p>\n", "comments": [], "met...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T05:53:48.603", "Id": "33280", "Score": "1", "Tags": [ "c++", "recursion", "lambda" ], "Title": "Recursive GCD using a lambda" }
33280
<p>[Please don't comment on using Turbo C++. I know that it's obsolete but we are taught this way only.]</p> <pre><code>#include&lt;fstream.h&gt; #include&lt;conio.h&gt; void main() { clrscr(); char ch; ifstream read; read.open("Employee.txt"); ofstream write; write.open("Another.txt"); while(!read.eof()) ...
[]
[ { "body": "<p>This is a deprecated head (C++ headers don't have .h on the end)</p>\n\n<pre><code>#include&lt;fstream.h&gt;\n// Should be\n#include&lt;fstream&gt;\n</code></pre>\n\n<p>OK your Turbo stuff:</p>\n\n<pre><code>#include&lt;conio.h&gt;\n</code></pre>\n\n<p>This is not a valid main() declaration:</p>\n...
{ "AcceptedAnswerId": "33290", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T07:41:33.817", "Id": "33285", "Score": "-1", "Tags": [ "c++", "file" ], "Title": "C++ File handling, inserts ÿ character while copying contents" }
33285
<p>I am looking for a review regarding C++ streams behaviour conformance.</p> <p>I have made this <code>win32_file_streambuf</code> so that I can use it in log4cplus project. I basically need it so that log files can be renamed when they are still opened by another process logging into the same file. This can be done ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T13:33:29.873", "Id": "53321", "Score": "0", "body": "Be careful imbuing a file after it has been opened. Once any data is read from the stream an imbue will usually fail. Sometimes when a file is opened the stream will read the BOM ...
[ { "body": "<p>When you have an <code>if</code>/<code>else</code> statement, and you find it necessary to use curly braces on the <code>if</code> statement, you should also use curly braces on the <code>else</code> statement.</p>\n\n<p>Like here:</p>\n\n<blockquote>\n<pre><code> if (result == std::codecvt_bas...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T09:14:03.323", "Id": "33288", "Score": "6", "Tags": [ "c++", "windows", "i18n" ], "Title": "custom win32_file_streambuf" }
33288
<p>I have just wrote this Pong game in Pygame:</p> <pre><code>import pygame import sys import math class Ball(object): def __init__(self, x, y, width, height, vx, vy, colour): self.x = x self.y = y self.width = width self.height = height self.vx = vx self.vy = vy ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T13:12:57.107", "Id": "53320", "Score": "0", "body": "See [this question](http://codereview.stackexchange.com/q/31408/11728) and its answer." } ]
[ { "body": "<p>Because Paddle and Ball have a lot in common, I think it would make sense if they were to inherit from a common class (PhysicalObject for instance) with size, position, velocity, color, etc...</p>\n\n<p><code>self.ball.vy = -self.ball.vy</code> can be written <code>self.ball.vy *= -1</code>.</p>\n...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T12:12:46.863", "Id": "33289", "Score": "3", "Tags": [ "python", "game", "pygame" ], "Title": "Basic Pong game in Pygame" }
33289
<p>I was working on a problem set and I came across this problem:</p> <blockquote> <p>Assume <code>s</code> is a string of lower case characters.</p> <p>Write a program that prints the longest substring of <code>s</code> in which the letters occur in alphabetical order. For example, if <code>s = 'azcbobobegghakl'</code...
[]
[ { "body": "<p>It's the famous <a href=\"http://en.wikipedia.org/wiki/Talk%3aLongest_increasing_subsequence\" rel=\"nofollow\">Longest increasing subsequence</a> problem. Convert the chars to ints using the ord function</p>\n\n<pre><code>def longest_increasing_subsequence(X):\n \"\"\"\n Find and return lon...
{ "AcceptedAnswerId": "33306", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T13:14:37.673", "Id": "33291", "Score": "4", "Tags": [ "python", "optimization", "algorithm", "strings" ], "Title": "Improving efficiency for finding longest contiguous non-...
33291
<p>Recently I was asked in an interview to convert the string say "aabbbccccddddd" to "a2b3c4d5". i.e we have to avoid repeating same character and just adding the repeat count. Here 'a' is repeated twice in the input and so we have to write it as 'a2' in the output. Also i have to write a function to reverse the forma...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T13:51:01.207", "Id": "53323", "Score": "0", "body": "First. Don't write C and claim it is C++. The languages are very distinct in the style they are used (they may have the same underlying base syntax but their usage is very differe...
[ { "body": "<h3>Did you ask any questions before you started?</h3>\n<p>It seems like there are a couple of holes in the design that need firming up.</p>\n<ol>\n<li>Is there a maximum run length? (ie is single digit lengths enough)</li>\n<li>Does the input string only contain alpha? (ie no numbers).</li>\n<li>Do...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T13:22:52.020", "Id": "33293", "Score": "0", "Tags": [ "c", "strings", "interview-questions", "compression" ], "Title": "Run-length encoding using C" }
33293
<p>I need to optimize this piece of code I made because this will run in real-time mode.</p> <p>It's a matrix shifter that pulls downward and will neglect any transparent element.</p> <p><strong>Code:</strong></p> <pre><code>void shiftDown(int col) { int x = 0; //transparent element int N = 5; //size i...
[]
[ { "body": "<p>You can sort each column separately (only move the transparent value to the top of the column) with a fast sorting algorithm like merge sort:</p>\n\n<pre><code>void mergeSortBlock(int *a, int index1, int index2, int size, int transparent){\n int *result;\n int resultIndex = 0;\n int merge...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T19:19:41.010", "Id": "33299", "Score": "2", "Tags": [ "c++", "optimization", "matrix" ], "Title": "Optimizing this matrix shifter" }
33299
<p>I recently had a programming challenge, which was to create the N grams. The description is as follows:</p> <blockquote> <p>Trigram analysis is very simple. Look at each set of three adjacent words in a document. Use the first two words of the set as a key, and remember the fact that the third word followed ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-04T22:51:44.547", "Id": "64387", "Score": "0", "body": "Can you include a `main()` method so that people can copy and paste this code, and immediately run it? It would help a lot in knowing whether I can improve the efficiency of the ...
[ { "body": "<p>If <code>text</code> is <code>null</code>, you throw an <code>IllegalArgumentException</code>. It should throw a <code>NullPointerException</code>.</p>\n\n<pre><code>if (text == null) throw new NullPointerException(\"Check the input parameters: String should not be null\");\nif(n&lt;1 || text.len...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T20:06:35.413", "Id": "33300", "Score": "11", "Tags": [ "java", "performance" ], "Title": "N grams generator" }
33300
<p>I have a method which checks all of its surrounding squares and returns the number of bombs around it. It uses a long list of <code>if</code> statements, which is pretty ugly and probably inefficient.</p> <pre><code> public int countArround(){ int bombNum = 0; //x=0 y=1 works if(((SmartSquare)boar...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-27T08:11:33.610", "Id": "53372", "Score": "1", "body": "Related question: [Neighbors of a matrix element](http://codereview.stackexchange.com/q/33042/9357)" } ]
[ { "body": "<p>A double-for-loop over <code>x</code> and <code>y</code> seems appropriate.</p>\n\n<p>Also, it seems like a good idea to assign <code>(SmartSquare)board.getSquareAt(...)</code> to a variable.</p>\n\n<pre><code>int bombNum = 0;\nfor (int xOffset = -1; xOffset &lt;= 1; xOffset++)\n for (int yOf...
{ "AcceptedAnswerId": "33302", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T20:48:37.167", "Id": "33301", "Score": "2", "Tags": [ "java", "game", "matrix", "minesweeper" ], "Title": "Minesweeper, Bombcount method" }
33301
<p>Maze, assumption - single point of entry and a single point of exit. Also directions to travel in maze are North South East West. Request for optimization and code cleanup.</p> <pre><code>final class Coordinate { private final int x; private final int y; public Coordinate(int x, int y) { this.x...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T23:03:54.187", "Id": "53342", "Score": "0", "body": "Wouldn't `hashCode()` return the same hash code for (1,2) and (2,1)?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T23:09:54.973", "Id": "5334...
[ { "body": "<p>Your algorithm finds all routes, but only returns one, which is sub-optimal. Run it on the following data:</p>\n\n<pre><code> int[][] m3 = { { 0, 0, 0, 0, 0 }, \n { 0, 1, 1, 1, 1 }, \n { 0, 1, 0, 1, 0 }, \n { 0, 1, 0, 1, 0 }, \n ...
{ "AcceptedAnswerId": "33309", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T21:30:20.490", "Id": "33303", "Score": "4", "Tags": [ "java", "optimization", "algorithm", "pathfinding" ], "Title": "Maze problem cleanup and optimization" }
33303
<p>I want to implement a thread-safe singly linked list in C. Its nodes contain unique entries and I only need functions to add nodes (to head only), remove nodes and to locate a specific node.</p> <p>I am reasonably confident of the linked-list logic (any performance tips would be greatly appreciated though), but I a...
[]
[ { "body": "<blockquote>\n <p>Is there a more performant way to get thread-safety for this data structure?</p>\n</blockquote>\n\n<p>It all depends on how the list will be used. Just a few examples:</p>\n\n<ul>\n<li>Reads are more common than writes - use separate read/write locks.</li>\n<li>Average list is shor...
{ "AcceptedAnswerId": "33322", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-27T03:40:23.457", "Id": "33311", "Score": "7", "Tags": [ "c", "thread-safety", "linked-list" ], "Title": "Thread-safe linked list review" }
33311
<p>I have implemented my first program in JavaScript, <a href="http://en.wikipedia.org/wiki/Rock-paper-scissors" rel="nofollow">Rock-Paper-Scissors</a>. I would like JavaScript developers to help me make this program more JavaScript-like by following the idioms of the language. I am also open to any suggestions related...
[]
[ { "body": "<p>Well, there might be a few things.</p>\n\n<p>The most important thing that can be changed is removing all those magic numbers: What happens when we want to play “<em>Rock, Paper, Scissors, Lizard, Spock</em>” instead? You'd think you would only have to update the <code>choiceArray</code> – but unf...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-27T04:18:09.297", "Id": "33314", "Score": "3", "Tags": [ "javascript", "game", "rock-paper-scissors" ], "Title": "How do I make my Rock-Paper-Scissor program more JavaScript-like?" }
33314
<p>According to <a href="https://stackoverflow.com/questions/19608546/optimize-regex-for-maximum-speed">https://stackoverflow.com/questions/19608546/optimize-regex-for-maximum-speed</a> and comments to ask my question here . Please help me to optimize following regex to best performance . I have read some articles but ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-04T05:03:53.213", "Id": "60131", "Score": "0", "body": "I realize it has been a while since you asked this question. In the interim, have you found a way to make your regexes faster? If you have, you should consider providing an answer...
[ { "body": "<p>Since all your patterns have similar structure, we only need to focus on one, e.g.</p>\n\n<pre class=\"lang-none prettyprint-override\"><code>refresh_pattern -i (.+\\.)?avg\\.com/.*?\\.(cab|exe|dll|ms[i|u|f]|asf|wm[v|a]|dat|zip|ctf|bin|gz)$\n</code></pre>\n\n<p>This pattern starts with <code>(.+\\...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-27T07:37:55.603", "Id": "33319", "Score": "4", "Tags": [ "optimization", "regex", "performance" ], "Title": "Optimize regex for maximum speed" }
33319
<p>I have an array of structure records and function <code>intersection</code> and <code>difference</code>.</p> <p>The <code>intersection</code> function take <code>list1</code>,<code>list2</code>,<code>list3</code>(an array of records),and <code>size</code> of both <code>list1</code> and <code>list2</code>. </p> <p...
[]
[ { "body": "<p>Given that the two lists are already sorted, you can do MUCH better than just the naive <code>O(|A| * |B|)</code> implementation. Let me reduce the problem to just intersecting lists of chars, and let's say our lists are:</p>\n\n<pre><code>A: [... a elems ..., 'C', 'D', ... ]\nB: [... b elems ...,...
{ "AcceptedAnswerId": "33338", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-27T10:10:04.257", "Id": "33321", "Score": "0", "Tags": [ "optimization", "c" ], "Title": "Optimised library database code for sorted array of structures" }
33321
<p><code>CellDrawableProvider</code> is an Android class used in the game <em>Tic-Tac-Toe</em>. It provides drawables for cells of game board (drawables for figures X and O, and "Fire" if the cell is in the firing line). To save memory, this class uses a <code>map</code> to store the already created drawables.</p> <pr...
[]
[ { "body": "<p>How about <code>DrawableCellProvider</code> and replacing the function name to 'get()' , </p>\n\n<p>Also is <code>null</code> really acceptable in </p>\n\n<pre><code>private Drawable getDrawable(int iconId) {\n Drawable drawable = drawables.get(iconId);\n if (drawable == null) {\n dra...
{ "AcceptedAnswerId": "35734", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-27T11:44:16.227", "Id": "33324", "Score": "1", "Tags": [ "java", "android", "tic-tac-toe" ], "Title": "Android class in Tic-Tac-Toe" }
33324
<p>This is my solution to <a href="http://projecteuler.net/problem=2" rel="nofollow">Project Euler problem 2</a>:</p> <blockquote> <p>By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.</p> </blockquote> <p>The class <code>fibonacci_Even...
[]
[ { "body": "<p>I think you are violating SRP, but not for the reason you think you are. Memoization is fine, it's definitely one approach to calculating the fibonacci values, but you have one class that is doing BOTH calculating the Fibonacci values AND summing the even ones. </p>\n\n<p>If you are really worried...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-27T13:00:41.487", "Id": "33326", "Score": "2", "Tags": [ "python", "programming-challenge", "fibonacci-sequence" ], "Title": "Maintaining the Single Responsibility Principle with Pro...
33326
<p>This is my importer to database from excel file. I would like to handle situations when any error raise. To not breaks whole import when one errors occurs.</p> <p>For example when there is duplicated record and I have uniqueness validations. I would like to store this row id in errors table and inform about that at...
[]
[ { "body": "<p>It can be as simple as :</p>\n\n<pre><code> def initialize(path)\n @path = path \n @imported = []\n @errors = []\n end\n\n def extract sheet_name\n @file.default_sheet = sheet_name\n\n header = file.row 1\n 2.upto(file.last_row) do |i|\n row = Hash[[header, file.row(i)].t...
{ "AcceptedAnswerId": "33351", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-27T14:20:00.773", "Id": "33327", "Score": "1", "Tags": [ "ruby", "ruby-on-rails", "exception-handling", "data-importer" ], "Title": "How to refactor this importer to handle va...
33327
<p>I want move a <strong>Vertical</strong> line segment across a plane or another way sweep the plane, from <em>Left</em> to <em>right</em>.</p> <p>The figure illustrates how the segment is moving at the <strong>X-axis</strong>. When <strong>x1 >= X</strong> beginning and i translate it to the upper part and so on, t...
[]
[ { "body": "<p>I don't know what your code is doing (it is a function without a return value OR side effects), but one way it could be greatly improved is if you use classes to represent the individual pieces:</p>\n\n<pre><code>struct Point {\n int x, y;\n};\n\nstruct LineSegment {\n Point left, right;\n\n...
{ "AcceptedAnswerId": "33336", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-27T15:02:47.310", "Id": "33328", "Score": "3", "Tags": [ "c++", "algorithm", "recursion", "computational-geometry" ], "Title": "Move Line across Plane" }
33328
<p>I'm just learning OOP, and I have an assignment to create a Stack. I came up with the following. Is it "beauty" enough, or to "schooly". Where can I evolve?</p> <p>This is the class:</p> <pre><code>class Stack { private int _length; private List&lt;int&gt; _members = new List&lt;int&gt;(); ...
[]
[ { "body": "<pre><code>class Stack\n</code></pre>\n\n<p>Stack (or any other collection) is a prime example of type that should be generic.</p>\n\n<pre><code>private int _length;\n</code></pre>\n\n<p>I think length is not a good name for this. You should rename it to something like <code>_maxLength</code>, or eve...
{ "AcceptedAnswerId": "33333", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-27T15:45:14.870", "Id": "33329", "Score": "3", "Tags": [ "c#", "stack" ], "Title": "Is it needed to \"beautify\" this Stack implementation?" }
33329
<p>I have just made what seems to me to be the first reliable prime-checking program that works. However, I am not sure if it is completely reliable, or if there are problems. It relies on list-making more than math, and it can be slow for bigger numbers. Do you think there are any problems?</p> <pre><code>def prim...
[]
[ { "body": "<p>There is lots of room for improvement here. Let me give some broad guidelines:</p>\n\n<p>First, Your function checking if its input is prime should return a boolean and probably be called something like <code>isPrime</code> or <code>is_prime</code>. The string you are returning is nice for being h...
{ "AcceptedAnswerId": "33339", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-27T18:20:51.193", "Id": "33337", "Score": "3", "Tags": [ "python", "beginner", "primes" ], "Title": "Any problems with this prime checker script?" }
33337
<p>Generate new password and send to user, if user is registered.</p> <ul> <li>Two <code>TextBox</code> on page, <code>txtUserName</code> &amp; <code>txtEamil</code>.</li> <li>User can provide either <code>UserName</code> or <code>Email</code> to get new password.</li> <li>If <code>UserName</code> is provided then fin...
[]
[ { "body": "<p>The only thing that I can think of right now is making <code>SendNewPasswordToUser</code> two separate methods.</p>\n\n<p>but this would just move the code around a little bit, on the other hand the way you have it written right now, you are sending an Empty variable into the Method whether the us...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-27T19:15:35.320", "Id": "33341", "Score": "5", "Tags": [ "c#", "asp.net" ], "Title": "Generating and sending new password to user" }
33341
<pre><code>let reply = ref "" let doAuto = async { let! resultAA = async { return SqlCmd.aaHits query |&gt; Async.RunSynchronously |&gt; List.ofSeq } let! resultBB = async { return SqlCmd.bbHits query |&gt; Async.RunSynchronously |&gt; List.ofSeq } let! resultCC ...
[]
[ { "body": "<p>Avoid <code>Async.RunSynchronously</code> until absolutely necessary. It is very inefficient by design. Looks like you need:</p>\n\n<pre><code>async { let! xs = SqlCmd.xxxHits query\n return List.ofSeq xs }\n</code></pre>\n\n<p>Which you should probably abstract into a function.</p>\n\n<p>O...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-27T21:47:50.927", "Id": "33347", "Score": "1", "Tags": [ "sql", "f#" ], "Title": "Async querying SQL in IIS" }
33347
<p>I have a list of tuples (<code>key</code>, <code>value1</code>, <code>value2</code>, ...). I simplify the tuple here so it is only of length 2. Keys contain duplicated figures.</p> <pre><code>xs = zip([1,2,2,3,3,3,4,1,1,2,2], range(11)) # simple to input [(1, 0), (2, 1), (2, 2), (3, 3), (3, 4), (3, 5), (4, 6...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-27T23:10:46.573", "Id": "53417", "Score": "0", "body": "@Barry I rephased a little bit. My input list is a list of tuples... so on input `[(1,a),(2,b),(2,c)]` I want `[(1,a),(2,b),(2,c)]`" }, { "ContentLicense": "CC BY-SA 3.0"...
[ { "body": "<p>The <code>itertools</code> library has a handy function for this problem called <a href=\"http://docs.python.org/2/library/itertools.html#itertools.groupby\" rel=\"nofollow\">groupby</a>:</p>\n\n<pre><code>def f1(xs):\n for _, group_iter in itertools.groupby(xs, key = lambda pair: pair[0]):\n ...
{ "AcceptedAnswerId": "33354", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-27T23:00:30.620", "Id": "33352", "Score": "2", "Tags": [ "python" ], "Title": "Returning items which are different from their preceding items from a list" }
33352
<p>The idea is to get a listing of monthly bills with amounts paid. The subquery does a total through a group by using <code>bill_id</code> and <code>party_id</code>.</p> <p>I wish to know how it can be improved. I'm not comfortable with <code>JOIN</code>s and am willing to learn.</p> <pre><code>SELECT bill.id as...
[]
[ { "body": "<p>Do you really need the subquery?</p>\n\n<pre><code>SELECT\nbill.id as bill_id,\nmaster.id as party_id,\nmaster.name as party_name,\n`amountExcVat`,\nbill.vat,\namountExcVat + bill.vat as 'amtIncVat',\n`purchasedDate`,\nbill.status,\nSUM(payment.cashPaid) + SUM(payment.chequePaid) as 'Amount Paid(c...
{ "AcceptedAnswerId": "33378", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-27T23:33:07.613", "Id": "33353", "Score": "4", "Tags": [ "sql", "mysql", "finance" ], "Title": "SQL query for monthly bills with amounts paid" }
33353
<p>Today I started to make a class called <code>Fraction</code>, where the class will act just like a fraction does in real mathematics. I am doing this just for the challenge. So far I only made the addition part, because I wanted to know if anybody had any suggestions for me.</p> <pre><code>#include &lt;iostream&gt;...
[]
[ { "body": "<p>Here's a few pointers:</p>\n\n<p>Do not typedef cv-qualified types. It will confuse everybody who reads your code. Seeing <code>cl</code> is really confusing, seeing <code>const long</code> is completely understandable. So get rid of the <code>cd</code> and <code>constr</code>. </p>\n\n<p>If you w...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T02:19:18.637", "Id": "33358", "Score": "3", "Tags": [ "c++", "rational-numbers" ], "Title": "Fraction program with Fraction class" }
33358
<p>I've made an unbeatable Tic-Tac-Toe in Python 3.3. While it truly was unbeatable, it was an eyesore to look at and nigh impossible to read. That code is <a href="https://github.com/gferiancek/ITicTacToe/blob/master/tic-tac-toe.py">here</a>.</p> <p>I have since then optimized it for Python 2.7.5 as follows:</p> <...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T05:26:56.997", "Id": "53438", "Score": "0", "body": "@Barry, remember that the interval on random() is [0, 1), meaning that in theory, 1 is never actually reached. I simply had .99/2 which is .495. I moved it down to .494 since that...
[ { "body": "<ol>\n<li><p>Some of the comments are wrong, for example:</p>\n\n<pre><code>#First, setup the board!!\n</code></pre>\n\n<p>appears just before the <code>draw_board</code> function, which does not set up the board.</p>\n\n<p>The best practice here is to write a <a href=\"http://docs.python.org/3/tutor...
{ "AcceptedAnswerId": "33441", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T02:24:00.710", "Id": "33359", "Score": "14", "Tags": [ "python", "game", "python-3.x", "tic-tac-toe" ], "Title": "Unbeatable Tic-Tac-Toe program seems difficult to read" }
33359
<p>My in-laws taught me a dice game a couple years ago, and we play every once in a while. <a href="https://codereview.stackexchange.com/a/33151/23788">A recent excellent answer from @radarbob</a> inspired me to proceed with translating the rules of that dice game into code.</p> <p>Here's what came out of it:</p> <p>...
[]
[ { "body": "<p>Well, I am not familiar with die, but the obvious improvement is to encapsulate those rules into separate entities. For example:</p>\n\n<pre><code>public interface IRollScoreRule\n{\n int CalculateRollScore(IEnumerable&lt;IRollResult&lt;int&gt;&gt; results);\n}\n\npublic interface IRollScoreRul...
{ "AcceptedAnswerId": "33370", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T03:36:05.213", "Id": "33363", "Score": "7", "Tags": [ "c#", "algorithm", "dice" ], "Title": "Dice game rules implementation" }
33363
<p>I wrote some math formulas in Haskell and was wondering about how to clean the code up and make it more readable.</p> <pre><code>import Math.Gamma pdf :: Double -&gt; Double -&gt; Double -&gt; Double -&gt; Double pdf mu alpha beta x = ( beta / (2 * alpha * gamma ( 1/beta) ) ) ** exp ( -1* ( abs(x - mu )/a...
[]
[ { "body": "<p>Your code looks fine to me. If you wish, you could use Greek letters. This makes the formula easier to read, but if you expect to modify it often, it may be too much trouble to enter the Greek letters. You might find it helpful to split up long formulas, as I've done for <code>pdf</code>. If you c...
{ "AcceptedAnswerId": "35865", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T03:40:27.207", "Id": "33364", "Score": "2", "Tags": [ "haskell", "mathematics" ], "Title": "Math formulas in Haskell" }
33364
<p>I know heaps are commonly implemented by an array. But, I wanted to share my pointer implementation and have your feedback(s) :)</p> <p>General idea:</p> <ol> <li><p>I convert the index to its binary value and then trace the heap (0 = leftChild &amp; 1 = rightChild)] Note: The first 1 is for entering the root.</p>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T04:10:56.287", "Id": "53434", "Score": "0", "body": "@Barry: it's the element counter. For example, 12 means the entered data will be the 12th element (at this time it has 11 elements). In its class version, you can have a protected...
[ { "body": "<p>This class uses a member variable and hides the size completely. As you can see there is no need to know the index value. It can be hidden from the user. (Note: This class is not complete. It's necessary to have ~cHeap() to free up all the allocated memories) </p>\n\n<pre><code>#include &lt;ios...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T03:46:58.570", "Id": "33365", "Score": "5", "Tags": [ "c++", "heap", "pointers" ], "Title": "Heap implementation using pointer" }
33365
<pre><code>SELECT * FROM (SELECT a.*, ROWNUM rnum from (SELECT a.CUST_FULL_NAME,a.TAX_NET, (SELECT NEXT_INT_PAYMENT_AMOUNT_NET FROM (SELECT a.*, ROWNUM rnum from (SELECT NEXT_INT_PAYMENT_AMOUNT_NET,NEXT_INT_PAYMENT_DATE FROM SINAYA.T_XLS_DEPOSIT WHERE DEAL_TYPE IN ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T22:29:50.120", "Id": "53543", "Score": "0", "body": "Try asking on http://dba.stackexchange.com/." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T13:38:30.790", "Id": "53588", "Score": "0", ...
[]
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T05:14:39.757", "Id": "33367", "Score": "1", "Tags": [ "sql", "oracle" ], "Title": "is there a way to simplify this query?" }
33367
<p>I was just wondering if this is a good example, following good practices, of a C program for launching an interpreted script from a native binary executable. Here the interpreter is Perl and the script an implementation of something analogous to du --apparent-size, but the idea is general.</p> <p>Also, is this code...
[]
[ { "body": "<p>No it is not safe:</p>\n\n<ol>\n<li>Classic off-by-one error. You reserve space for 3 additional entries with <code>command[argc+3]</code> but you add 4. <code>argv[i+1]</code> and <code>command[i+4]</code> will be out of bounds on the last iteration (last valid index is <code>argv[argc-1]</code> ...
{ "AcceptedAnswerId": "33376", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T06:06:30.083", "Id": "33369", "Score": "15", "Tags": [ "c", "security", "perl", "unix" ], "Title": "Launching an interpreted script" }
33369
<p>I have a lock class, that handels a database lock. It's not important how.<br/> It is used in the beginning of a large operation, here is how it is used today:</p> <pre><code>public void LargeOperation() { try { MyLock.DoLock("SomeId"); // Do lots of stuff that might thorw excepti...
[]
[ { "body": "<p>Following the guidelines for implementing the <code>IDisposable</code> interface i would say it depends on how you have implemented the <code>MyLock</code> class. If your Lock class uses unmanaged resources it is correct to implement the interface. But i would not implement the <code>IDisposable</...
{ "AcceptedAnswerId": "33373", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T06:59:00.527", "Id": "33371", "Score": "6", "Tags": [ "c#", "design-patterns" ], "Title": "Custom database Lock - implemented with IDisposable" }
33371
<p>I have done the source code for my lesson, which I shall publish later on my website:</p> <pre><code>&lt;script src="three.min.js"&gt;&lt;/script&gt; &lt;script&gt; var renderer, scene, camera, geometry, material, mesh, light, axisRotation; function createScene() { renderer = new THREE.WebGLRenderer(); re...
[]
[ { "body": "<p>This code is good for tutorial use.</p>\n\n<p>Some suggestion:</p>\n\n<p>You are switching over 'x','y' and 'z' : </p>\n\n<pre><code>function rotateCube( axis ) {\n switch ( axis ) {\n case 'x':\n mesh.rotation.x += 0.02;\n break;\n case 'y':\n mes...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T08:29:54.910", "Id": "33375", "Score": "4", "Tags": [ "javascript", "dom", "opengl", "webgl" ], "Title": "WebGL (Three.js) simple application" }
33375
<p>I've written a program showing the process of bubble sort arithmetic in C. I need some suggestions on improving it.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;Windows.h&gt; #include &lt;stdlib.h&gt; #include &lt;time.h&gt; #define SIZE 20 #define WIDE (SIZE * 2) void RepaintScreen(int *pData, int count,...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T10:57:57.030", "Id": "53449", "Score": "0", "body": "I would create the line to print first and than print with one `printf`-call. Or even create all lines to print first and than make only one `printf`-call for all lines together."...
[ { "body": "<p>Your code works nicely. </p>\n\n<p>In <code>BubbleSort</code> I would move the definition of <code>iTemp</code> to the point of first use. The name <code>iTemp</code> is ugly and the 'i' makes me think you are using a type prefix (as does the 'p' in <code>pData</code>). I don't know anyone who t...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T08:59:35.177", "Id": "33377", "Score": "2", "Tags": [ "c", "sorting", "windows" ], "Title": "Visualization of bubble sort in progress" }
33377
<p>I have WCF Service. It works fine and I want to have test coverage for it. Unit tests and acceptance. </p> <p>The problem is the <code>static</code> class in the code. How is it possible to avoid it?</p> <p>If it will be refactored to the code without static classes - I can use mocks for example <code>Moq</code>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T09:12:47.227", "Id": "53444", "Score": "0", "body": "One way *might* be, if possible, to change the static class into a Singleton. Though, Singletons are a completely different beast." } ]
[ { "body": "<p>Personally I would not recommend writing a Unit test for a WCF service. It is an infrastructure and generally you would orchestrate routines, call a façade or a another service, provide addition infrastructure such as logging caching etc. There is no much behaviour, and you should not. I think you...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T09:10:41.690", "Id": "33379", "Score": "8", "Tags": [ "c#", "unit-testing", "wcf" ], "Title": "Make WCF Service testable" }
33379
<p>As I get to some performance issues in my app and find that I use database access in a bad way.<br/> So I decided to move to singleton pattern.<br/> I need someone to review this code and confirm me that I made a good database access via singleton pattern or I am doing something wrong:<br/> This is the class:</p> <...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T17:58:57.970", "Id": "53512", "Score": "0", "body": "To my untrained eye this looks like a straight-forward, by-the-book singleton construction. If there are still performance bottlenecks in your code, they're probably elsewhere" ...
[ { "body": "<p>Based on your provided code, this is the correct way to create a singleton object.</p>\n\n<p>In such, here's a <a href=\"http://www.galloway.me.uk/tutorials/singleton-classes/\" rel=\"nofollow noreferrer\">reference link</a> from Matt Gallow's site showing the same singleton setup as you're doing....
{ "AcceptedAnswerId": "37090", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T09:40:13.257", "Id": "33380", "Score": "2", "Tags": [ "objective-c", "ios", "singleton", "sqlite" ], "Title": "I need code review on using singleton to access local databas...
33380
<p>I have to create a button which counts from 0 to 9, and after 9 come 0 again. One of my friends said that this code is not good enough. Can you explain to me why it's a problem to use <code>-1</code>?</p> <pre><code>int szám = 0; private void counterButton_Click(object sender, EventArgs e) { szám++; this.Te...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T11:03:33.333", "Id": "53450", "Score": "3", "body": "szám? not very clear what is it" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T11:05:14.440", "Id": "53451", "Score": "0", "body": "it...
[ { "body": "<p>Your code is ok. But there are always other ways to get the same result which may be more elegant.</p>\n\n<pre><code>private void counterButton_Click(object sender, EventArgs e)\n{\n szám=(szám +1) % 10;\n this.Text = szám.ToString();\n}\n</code></pre>\n\n<p>or you can do:</p>\n\n<pre><code>...
{ "AcceptedAnswerId": "33395", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T10:59:21.337", "Id": "33383", "Score": "2", "Tags": [ "c#" ], "Title": "Button incrementing from 0 to 9 and repeating" }
33383
<p>I am fairly new to jQuery and I am making a new search results page. In this snippet I am switching from a grid to list view and vice versa. Can anyone suggest a cleaner method of performing this change? I did try using a variable to minimize all my (this) calls but I couldn't get them to work. Any help would be muc...
[]
[ { "body": "<p>You can simply use JS to toggle a list class. In CSS, you can simply override the style to either display block (item per row, list style), or display inline-block (several items side-by-side per row, grid style).</p>\n\n<p><a href=\"http://jsfiddle.net/7d6S3/1/\" rel=\"nofollow\">A simple demo he...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T11:03:00.920", "Id": "33384", "Score": "1", "Tags": [ "javascript", "jquery", "optimization" ], "Title": "Optimize ineffiecient Jquery - UX list to grid view" }
33384
<p>I'm writing a C++ library with MinGW (4.8.0, DW2, POSIX) compiler. But this library must be used by another compiler. I've read this <a href="http://chadaustin.me/cppinterface.html">post</a>, so I've re-written the C++ library interface in this way:</p> <pre><code>#ifndef SERIALPORT_H #define SERIALPORT_H #include...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T15:13:55.810", "Id": "54115", "Score": "0", "body": "This is not a good solution: The code above if compiled with MinGW won't work correctly on msvc compiler." } ]
[ { "body": "<ul>\n<li><p>You should just include <a href=\"http://en.cppreference.com/w/cpp/header/cstddef\"><code>&lt;cstddef&gt;</code></a> in order to use <code>std::size_t</code>. Including <code>&lt;cstring&gt;</code> seems unnecessary if you're not actually going to utilize anything else.</p></li>\n<li><p...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T11:09:56.447", "Id": "33386", "Score": "8", "Tags": [ "c++", "c++11", "library", "portability", "serial-port" ], "Title": "Serial port library across different compilers" ...
33386
<p>Here is my code. It works fine but I need to make the code more efficient.</p> <pre><code>def o(s): l=len(s) return len(set([a+b+c for a in s for b in s for c in s]) )==l*(l+1)*(l+2)//6 M=int(input()) N=3**M i=1 s=M*[i] while i: if s[i]-N: s[i]=s[i]+1 i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T09:55:30.423", "Id": "53465", "Score": "0", "body": "@Dilini: Have you profiled it?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T09:57:53.523", "Id": "53466", "Score": "6", "body": "Cou...
[ { "body": "<p>It is not clear what this code is supposed to do. How can you possibly expect us to help you improve it if we can't understand it?</p>\n\n<p>For example, consider the function <code>o</code>. It takes a collection of numbers, \\$s\\$ (with length \\$l\\$), iterates over all triples \\$a, b, c\\$ o...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-26T09:53:45.087", "Id": "33390", "Score": "-3", "Tags": [ "python", "performance", "combinatorics" ], "Title": "Distinct triple sums" }
33390
<p>I have written a <a href="http://en.wikipedia.org/wiki/Manchester_code" rel="noreferrer">Manchester Encoding</a> encoder / decoder based on my misconception of how it works (<em>whoops</em>). My encoder accepts an array of ones and zeroes, and returns the 'manchester encoded' data (pretending there is a constant clo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T18:21:59.870", "Id": "53518", "Score": "2", "body": "You shouldn't return and use a local dynamic variable. You must free it up before going out of scope, see this post about [memory leak](http://stackoverflow.com/questions/6261201/...
[ { "body": "<h1>Manipulating bits</h1>\n\n<p>One of the areas where your code may be improved is the way it handles and compares bits. You are using <code>char*</code> strings to represent bits while you could have used <code>unsigned</code> values and bitwise operations to speed up most of your operations. Actu...
{ "AcceptedAnswerId": "44946", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T13:10:00.360", "Id": "33396", "Score": "7", "Tags": [ "c++", "optimization", "beginner", "array" ], "Title": "Manchester encoder/decoder" }
33396
<p>I made this program in C that tests if a number is prime. I'm as yet unfamiliar with Algorithm complexity and all that Big O stuff, so I'm unsure if my approach, which is a <strong>combination of iteration and recursion</strong>, is actually more efficient than using a <strong>purely iterative</strong> method.</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T10:48:30.133", "Id": "53775", "Score": "1", "body": "Recursion _never_ gives the fastest possible algorithm, because the function calling/return overhead takes far longer to execute than the actual comparison. Also, recursion likely...
[ { "body": "<p>So after looking at this we can do some basic BigO analysis(recursion aside)</p>\n\n<p>so we have your number linked list(O(n)) + prime function(O(sqrt(n)) so lets just go with O(n) since it is larger so really yes this way is slower for smaller numbers since primes tend to be closer together when...
{ "AcceptedAnswerId": "33680", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T13:11:44.293", "Id": "33397", "Score": "6", "Tags": [ "c", "performance", "recursion", "primes", "iteration" ], "Title": "Is a Recursive-Iterative Method Better than a ...
33397
<p><a href="https://www.codeeval.com/open_challenges/45/" rel="nofollow">This is one of codeeval challenges</a></p> <blockquote> <p><strong>Challenge Description:</strong></p> <p>Credits: Programming Challenges by Steven S. Skiena and Miguel A. Revilla </p> <p>The problem is as follows: choose a number, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T16:18:53.387", "Id": "53500", "Score": "0", "body": "Two comments: Probably nice to error-handle cases where it blew past a 100 iterations (vs. finishing exactly on iteration 100! :)) Also for curiosity's sake, did you re-write pali...
[ { "body": "<p>Only 2 things:</p>\n\n<ol>\n<li><p>Why do you have this? This makes your code a bit unclear and confusing. Remove this if you do not want to use it as it might make your actual code look messy.</p>\n\n<pre><code># def reverse_num(num):\n# rev = 0\n# while(num &gt; 0):\n# rev = (10*rev)+num...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T15:12:23.463", "Id": "33403", "Score": "4", "Tags": [ "python", "programming-challenge", "palindrome" ], "Title": "Reverse and Add: find a palindrome" }
33403
<p>I am learning from <em>C++ Primer</em> 5th edition. This is exercise 5.17:</p> <blockquote> <p>Given two vectors of ints, write a program to determine whether one vector is a prefix of the other. For vectors of unequal length, compare the number of elements of the smaller vector. For example, given the vectors co...
[]
[ { "body": "<p>Ok first, we want to determine if some condition is true or not based on some input. That calls for a boolean function! In particular, our inputs are two vectors. :</p>\n\n<pre><code>bool isPrefixOf(const std::vector&lt;int&gt;&amp; smaller, const std::vector&lt;int&gt;&amp; larger) \n{\n ...\n...
{ "AcceptedAnswerId": "33405", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T15:25:17.927", "Id": "33404", "Score": "3", "Tags": [ "c++", "optimization", "beginner" ], "Title": "Determining whether one vector is a prefix of the other" }
33404
<p>Essentially I'm attempting to select the top read (based on <code>read_date</code>), and check if it has a <code>type in ( 'R','S','C','B','Q','F','I','A')</code></p> <pre><code>select * from ( select * from ( select * FROM table WHERE id = 369514 order b...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T13:51:42.247", "Id": "53589", "Score": "0", "body": "is this Query slow? is it inefficient?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T21:06:08.383", "Id": "53628", "Score": "0", "bod...
[ { "body": "<p>I was looking at the Query and you should be able to get rid of the outside Select.</p>\n\n<pre><code>select *\nfrom (\n select *\n FROM table\n WHERE id = 369514\n order by read_date desc\n )\nwhere rownum = 1 AND type IN ( 'R','S','C','B','Q','F','I','A')\n</code></pre>...
{ "AcceptedAnswerId": "33460", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T16:20:04.717", "Id": "33407", "Score": "3", "Tags": [ "sql", "oracle" ], "Title": "Oracle nested query" }
33407
<p>I've nearly got this working. I wanted to know if there is a <em>much</em> better way. One problem is that no matter what there will be cases where a URL is incorrectly identified and as such the end result will be dependent on requirements. My requirements are lackadaisy, I just want something that works most of...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T20:27:11.383", "Id": "53534", "Score": "0", "body": "what browser are you using? all of the links show up for me in chrome. and the code seems to be working. I am not very good at JavaScript, but there doesn't seem to be anything ...
[ { "body": "<p>I think that it's nutty to replace all characters 'a' and 'b' with junk, then un-replace them later, just so that you can use 'a' and 'b' as landmarks to indicate which points your two regular expressions have in common. If you're going to do that, then why not just use \"--ucsps--\" and \"--uspd...
{ "AcceptedAnswerId": "33425", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T18:08:02.547", "Id": "33412", "Score": "2", "Tags": [ "javascript", "regex" ], "Title": "How to replace plain URLs with links, in javascript?" }
33412
<p>I am thinking of writing some online notes/book. Amongst other things, I want to use Backbone to show different sections within a chapter as separate views. In other words, I want each chapter to behave like a single page application; different chapters will behave as separate single page applications. Within a ch...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-27T21:43:52.967", "Id": "53524", "Score": "0", "body": "Do you have a `<div id=\"chapter2\">` in the DOM? Are you sure you want to render both views into the same element?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
[ { "body": "<p>A few minor tweaks could help you out:</p>\n\n<ul>\n<li>Add a <code>close</code> method to all of your views, which cleans up your DOM, and unbinds any bound events (eg, with <code>this.stopListening()</code>). This will prevent 'zombie events' -- events bound to views which are no longer rendered...
{ "AcceptedAnswerId": "33416", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-27T21:04:16.607", "Id": "33414", "Score": "2", "Tags": [ "javascript", "backbone.js", "url-routing" ], "Title": "Backbone Router" }
33414
<p>I wanted to write a script, which starts a rails app, and opens it in the browser.<br/> I'm trying to implement this in a peculiar way though - I expect two things:</p> <ol> <li>the script must wait until the server is started, then open the browser within a short time</li> <li>when I stop the script (Ctrl+C), the ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T15:03:00.610", "Id": "54279", "Score": "0", "body": "Do you mean what anybody will edit you post, with better script, or make an answer below?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T20:13:01....
[ { "body": "<p>This was an interesting one. Thank you :)</p>\n\n<p>I dug around in the rails code and poked at webrick and rack for a while and this is what I came up with:</p>\n\n<pre><code>PROJECT_DIR = ENV['PROJECT_DIR'] || '/path/to/app'\nBROWSER_COMMAND = ENV['BROWSER_COMMAND'] || 'browser http://lo...
{ "AcceptedAnswerId": "33865", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T22:42:43.470", "Id": "33420", "Score": "2", "Tags": [ "ruby", "multithreading", "ruby-on-rails" ], "Title": "Script for starting a rails app, with some peculiarities" }
33420
<p>This is a function designed to return all the prime factors of a given number, in sorted order from least to greatest, in a list. It relies on another function that checks if a given number is prime. Here is the prime checking function:</p> <pre><code>def isPrime(x): if x &lt;= 1 or isinstance(x,float): ...
[]
[ { "body": "<p>Your result is incorrect:</p>\n\n<pre><code>&gt;&gt;&gt; allPrimeFactors(360)\n[2, 2, 3, 3, 5]\n&gt;&gt;&gt; import operator\n&gt;&gt;&gt; reduce(operator.mul, allPrimeFactors(360), 1)\n180\n</code></pre>\n\n<p>It is also unnecessarily complicated. The usual approach is, whenever you encounter a ...
{ "AcceptedAnswerId": "33426", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T23:46:53.383", "Id": "33423", "Score": "1", "Tags": [ "python", "beginner", "primes" ], "Title": "Review my prime factorization function. Is it complete?" }
33423
<p>I've hacked a method that auto-fits text into an <a href="http://www.php.net/manual/en/class.imagick.php" rel="nofollow"><code>Imagick</code></a> image, given a bounding box: the image's width (minus optional margins) and a certain maximum height. What it does is find the optimal font size and line lengths within th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T10:29:43.337", "Id": "53961", "Score": "0", "body": "Looking at this code, If I feel you may consider rewriting the entire do-while part.There is a \"while\" inside the first do block. Inside the \"while\" there is another do block....
[ { "body": "<p>I'll give this my best shot, but first...</p>\n\n<p><strong>Some Minor Improvements</strong></p>\n\n<p><code>strlen()</code> can only return a positive number or 0. If the string is empty you get a 0 otherwise you get the length. So a less than check is unnecessary and can be replaced with a plain...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T00:07:25.247", "Id": "33424", "Score": "2", "Tags": [ "php", "performance", "algorithm", "image" ], "Title": "Auto-fitting text into an Imagick image" }
33424
<p>I wrote an FAQ on a third-party website which pertains to thread-protecting objects in Delphi. What I'd like to know is if this thread-protection approach is accurate, or if I should change anything about it. I don't intend to ask about the FAQ in general, just the aim at the actual topic of multi-threading.</p> <p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T09:42:54.960", "Id": "53577", "Score": "2", "body": "One tip: regarding \"In general, a deadlock is when two different threads try to access the same block of memory at the same time\", as far as I know, this is the definition of a ...
[ { "body": "<p>Your first paragraph says \"this is the most commonly used method\" without saying what \"this\" is. When writing a FAQ answer, especially one about something as thorny as multithreading, it's important to be precise from the very start. Maybe \"this\" refers to something from the question, but I ...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T02:01:51.910", "Id": "33427", "Score": "3", "Tags": [ "multithreading", "thread-safety", "delphi" ], "Title": "Is this the right way to thread-protect an object?" }
33427
<p>Which of the following is cleaner / more adopted standard of handling exceptions while coding a stream ? I would also appreciate a reason why one of the following trumps over other ? In my opinion I find option 1 better but nested try where first try does nothing more than a wrapper is making me not satisfied with ...
[]
[ { "body": "<p>For the second example you posted, I do not think <code>finally</code> is used in a correct way. using <code>try</code> in <code>finally</code> block is not a good idea\nyou can check the <a href=\"http://docs.oracle.com/javase/tutorial/essential/exceptions/finally.html\" rel=\"nofollow\">document...
{ "AcceptedAnswerId": "33436", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T02:37:47.860", "Id": "33428", "Score": "3", "Tags": [ "java", "exception", "stream" ], "Title": "Reading a text file, need help cleaning exception handling" }
33428
<p>I have written a custom endless/infinite scroll, which allows the user to load images as they scroll down.</p> <p>How can i make this code below modular and easily reusable? </p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /...
[]
[ { "body": "<p>I would wrap your jquery as a plugin. Here's a <a href=\"http://stefangabos.ro/jquery/jquery-plugin-boilerplate-revisited/\" rel=\"nofollow noreferrer\">boilerplate</a> to help you refactor this.</p>\n\n<p>You could then call your function as <code>$('#photos').myInfinteScroll();</code></p>\n\n<p>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T04:35:58.220", "Id": "33429", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "How can I make my custom infinte scroll more reusable?" }
33429
<p>Consider an interface:</p> <pre><code>public interface IWindowOperations { // Some operation methods. } </code></pre> <p>Class definitions:</p> <ol> <li><pre><code>public abstract class BaseWindow&lt;T&gt; : IWindowOperations { // partially implemented class. } </code></pre></li> <li><pre><code>public cla...
[]
[ { "body": "<p>It depends on your design entirely. If classes (2) and (3) can not operate on their own, should not be instanciated and are there to serve as base classes only, then you are justified to make them abstract, and i think you should.</p>\n\n<p>Also, you should probably reflect your intent in class na...
{ "AcceptedAnswerId": "33433", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T06:56:14.123", "Id": "33432", "Score": "3", "Tags": [ "c#", "classes" ], "Title": "Marking class with no abstract methods as an abstract" }
33432
<p>I'm having an argument with my boss about whether or not it's better to have a separate function for a single line of code.</p> <p>The code reads something like:</p> <pre><code>while (count &lt;= poscount) { key = etc.substr(pos2prev+1, pos-pos2prev-1); std::string::iterator end_pos = std::remove(key.begin...
[]
[ { "body": "<p>I would leave it as it is.</p>\n\n<p>It's only 1 line, and it's a function call of itself and not an evaluation or an operation, so why wrap a function call within a separate function.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0",...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T07:45:02.800", "Id": "33434", "Score": "3", "Tags": [ "c++" ], "Title": "Separate method for a single line code? Or embed in the caller function?" }
33434
<p>I need to call a function exactly at certain hour, daily, my programs runs 24/7.</p> <p>I wrote the following timer mechanism, which generally works that way:</p> <ol> <li><p>Calculate time until hour and generate timer with that interval. </p></li> <li><p>When timer elapse, call timer event and generate another 2...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T08:36:03.610", "Id": "53569", "Score": "4", "body": "For this kind of Task you should use something like the TaskScheduler of Windows of a library like Quartz.NET" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "...
[ { "body": "<p>Without knowing what you're trying to do, I'd say this is the wrong approach. I would create an executable and set it up as a scheduled task to run every 24 hours. </p>\n\n<p>Not sure what OS you are using, but assuming it's windows its fairly easy <a href=\"http://windows.microsoft.com/en-au/wind...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T07:50:36.950", "Id": "33435", "Score": "2", "Tags": [ "c#", "callback", "timer" ], "Title": "Time of day based timer - run function at certain time, daily" }
33435
<p>The following code takes a decimal number and gives its IEEE 754 floating point representation. However, the code is not complete and I am totally fine because it does the job for me: </p> <ol> <li>It does not consider negative numbers. </li> <li>The input number is not a fraction. Its always in the form xx.yy</li>...
[]
[ { "body": "<p>I just don't get what you're trying to do. JavaScript does not know of integers, floats or any other numeric type, except for <code>Number</code>.<br/>\nThis data-type just happens to be a 64bit IEEE754 floating point value (or <code>double</code> in most strong-typed languages). <a href=\"http://...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T11:04:11.153", "Id": "33442", "Score": "2", "Tags": [ "javascript", "floating-point" ], "Title": "Floating point representation in IEEE 754 format" }
33442
Simulation is the imitation of some real thing, state of affairs, or process. The act of simulating something generally entails representing certain key characteristics or behaviours of a selected physical or abstract system.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T12:16:43.837", "Id": "33445", "Score": "0", "Tags": null, "Title": null }
33445
<p>This tag refers to the <em>State</em> design pattern.</p> <p>References:</p> <ul> <li><p>The <a href="http://en.wikipedia.org/wiki/State_pattern" rel="nofollow">Wikipedia page</a> on the State pattern.</p></li> <li><p><a href="http://gameprogrammingpatterns.com/state.html" rel="nofollow">Design Patterns Revisited<...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T12:18:53.457", "Id": "33446", "Score": "0", "Tags": null, "Title": null }
33446
The State pattern is used to represent the internal state of an object and to encapsulate varying behavior for the same object based on its state. This can be a cleaner way for an object to change its behavior at runtime without resorting to large monolithic conditional statements and thus improve maintainability.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T12:18:53.457", "Id": "33447", "Score": "0", "Tags": null, "Title": null }
33447
An abstract data type that simulates a pointer while providing additional features, such as automatic garbage collection or bounds-checking.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T12:20:27.857", "Id": "33449", "Score": "0", "Tags": null, "Title": null }
33449
<p>A <a href="http://en.wikipedia.org/wiki/Heap_%28data_structure%29" rel="nofollow">heap</a> is a specialized tree-based data structure that is either</p> <ul> <li><strong>a max heap:</strong> the largest key is in the root node, and the keys of parent nodes ≥ those of the children</li> <li><strong>a min heap:</stro...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T12:23:05.960", "Id": "33450", "Score": "0", "Tags": null, "Title": null }
33450
A heap is a tree-based data structure that satisfies the heap property. For questions about memory allocated from the system heap, use the [memory-management] tag.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T12:23:05.960", "Id": "33451", "Score": "0", "Tags": null, "Title": null }
33451
SFML (Simple Fast Media Library) is a portable and easy to use multimedia API written in C++. You can see it as a modern, object-oriented alternative to SDL. SFML is composed of several packages to perfectly suit your needs. You can use SFML as a minimal windowing system to interface with OpenGL, or as a fully-featured...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T12:25:23.423", "Id": "33453", "Score": "0", "Tags": null, "Title": null }
33453
<p>I have created a function using jQuery Ajax which create a new CSS element whenever I update the database using a form.</p> <p>Is it ok? If not, hat can be the best method to do it?</p> <pre><code>$(document).ready(function(){ $('#statusupdater').submit(function(e) { updatestatus(); e.preventD...
[]
[ { "body": "<p>Set the return datatype to html and update the DOM in the success callback:</p>\n\n<pre><code>function updatestatus()\n{\n $.ajax({\n type: \"POST\",\n url: \"statusupdate.php\",\n data: $('#statusupdater').serialize(),\n dataType: \"html\",\n success: functio...
{ "AcceptedAnswerId": "33457", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T13:07:12.027", "Id": "33455", "Score": "1", "Tags": [ "javascript", "php", "jquery", "css", "ajax" ], "Title": "Creating new CSS element everytime database updates" }
33455
<p>I would like some feedback on the appropriate way of ordering a numerical list using the most elementary <code>scheme</code> functions (sorry, i realise that elementary is not well defined). </p> <p>By way of background: I've been learning a bit of <code>scheme</code> on my ipad, where I have only a basic implemen...
[]
[ { "body": "<p>So to answer your specific question, yes you can greatly simplify your algorithm in a couple places:</p>\n\n<pre><code>(list-tail numList (- (length numList) 1))\n</code></pre>\n\n<p>So you're taking the last <code>n - 1</code> elements of a list of length <code>n</code>? That's exactly:</p>\n\n<p...
{ "AcceptedAnswerId": "33476", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T13:24:15.113", "Id": "33456", "Score": "1", "Tags": [ "scheme", "sorting" ], "Title": "sorting a numerical list using basic scheme" }
33456
<p>I have a static class:</p> <pre><code>public static class ConfigurationDetails { public static string SharepointServer { get; set; } public static string Username { get; set; } public static string Password { get; set; } public static string SharepointDomain { get; set; } public static string Se...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T16:21:57.930", "Id": "54296", "Score": "1", "body": "As a side-note: I wouldn't make configuration a static class" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T18:14:05.990", "Id": "54326", ...
[ { "body": "<p>One solution would be to encapsulate the logic into a method. A problem with that is that there is no simple way to pass a property to the method.</p>\n\n<p>If the case where the key is not in the dictionary means that the value is <code>null</code>, then you could write an extension method for <c...
{ "AcceptedAnswerId": "33467", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T14:36:52.673", "Id": "33463", "Score": "7", "Tags": [ "c#", ".net", "linq" ], "Title": "Optimizing multiple if-else from static class with LINQ" }
33463
<p>I have the following structure:</p> <pre><code>struct Keys { //value of word in the vector&lt;string&gt; words. string word; //index of word in the vector&lt;string&gt; words. int index; //I want to compare the element **word** of the structure, this is why i overloaded the operators //After Editi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T18:36:17.837", "Id": "53600", "Score": "0", "body": "I'm getting an auto-flag saying that this is excessively long. You could probably split the red-black code into different parts, or just leave out some portion of it. Just keep ...
[ { "body": "<ul>\n<li><p><code>operator&gt;</code> and <code>operator==</code> are correct, but you should also define their complements. Users may also expect an <code>operator&lt;</code> and an <code>operator!=</code>:</p>\n\n<pre><code>bool operator&lt;(const Keys&amp; rhs) const { return word &lt; rhs.word;...
{ "AcceptedAnswerId": "33478", "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T16:19:46.197", "Id": "33470", "Score": "2", "Tags": [ "c++", "beginner", "classes", "tree" ], "Title": "Building a Red Black tree using a structure as a node" }
33470
<p>I have a form that I feel I am overcomplicating because of the relationship between models that are involved. Can you let me know if there's a more elegant solution to what I have?</p> <p>(<em>for reference</em>) The form ultimately looks like this:</p> <p><img src="https://i.stack.imgur.com/AOJ85.png" alt="Form ...
[]
[ { "body": "<p>This is hard to say because I don't have a broader context but you may have over normalized your database. Something to consider when building these is that it can sometimes be better to add items to a model instead of doing a has relationship with them. This is the first 4 level deep nested for...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T16:35:45.727", "Id": "33471", "Score": "0", "Tags": [ "ruby", "ruby-on-rails", "form", "active-record" ], "Title": "Form involving several models related to each other" }
33471
<p>I'm working on implementing a syntax highlighter for a simple text editor I've been working on. To do this, I need a simple lexer for various languages (I don't need a full one - I'm only interested in highlighting things like comments, strings, numbers and keywords). The way my editor component works is it highligh...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T23:45:44.633", "Id": "53637", "Score": "0", "body": "It would be much easier to write in `flex`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T23:49:04.733", "Id": "53638", "Score": "0", ...
[ { "body": "<ul>\n<li><p>You're using single-character variables in various places. With the exception of typical loop counters (such as <code>i</code>), variables should be descriptive and not need comments to help explain their meaning. This will also help you remember what they're for at a later point in th...
{ "AcceptedAnswerId": "43890", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T16:41:25.210", "Id": "33472", "Score": "17", "Tags": [ "c++", "c++11", "parsing" ], "Title": "C-style language lexer for a syntax highlighter" }
33472
<p>I'm trying to solve 15 puzzle using A* algorithm, but something really bad goes on in my <code>get_solution()</code> function that ruins performance. I guess there is a too much usage of maps in here, but I don't understand why it slows down my program so much. What do you think?</p> <p>I would be really happy if ...
[]
[ { "body": "<h3>1. You can't fix what you can't measure</h3>\n\n<p>In order to improve the performance of your code, we need to be able to measure its performance, and that's hard to do, because your <code>Puzzle15</code> class randomly shuffles the <code>Desk</code> associated with each instance, so it is not e...
{ "AcceptedAnswerId": "33549", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T17:36:02.183", "Id": "33473", "Score": "14", "Tags": [ "python", "performance", "sliding-tile-puzzle", "a-star" ], "Title": "Solving 15 puzzle" }
33473
<p>This code completes under a second, however its seems like I've taken the "Mr. Bean" way around getting there.</p> <p>The goal is to get the average number of orders processed in a single day based on how many days exist in the current database. The loadcount column represents how many orders are processed in a sin...
[]
[ { "body": "<p>this doesn't look bad to me at all,</p>\n\n<ul>\n<li>I had no trouble following along</li>\n<li>you said it is a Fast Query</li>\n<li>nothing looks over complicated</li>\n</ul>\n\n<p>I would suggest testing it more, maybe see how it would run in a very large database, that is something that I alw...
{ "AcceptedAnswerId": "33528", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T21:31:53.523", "Id": "33480", "Score": "3", "Tags": [ "sql", "sql-server" ], "Title": "SQL Server 2012: How do I eliminate multiple statements in this code to a more efficient, sin...
33480
<p>As explained <a href="https://codereview.stackexchange.com/questions/33456/sorting-a-numerical-list-using-basic-scheme">here</a>, I'm learning a limited subset of Scheme.</p> <p>My task has been to sort a numerical list. To implement a simple insertion sort, I need to remove a single element from a list.</p> <p>I'...
[]
[ { "body": "<p>That looks mostly right to me. I'll suggest two things.</p>\n\n<p>First, there is nice syntatic sugar for defining functions:</p>\n\n<pre><code>(define (remove-elem xs elem) \n (cond ...)\n)\n</code></pre>\n\n<p>Save yourself the lambda. </p>\n\n<p>Second, you are using <code>eq?</code>. That i...
{ "AcceptedAnswerId": "33482", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-10-29T22:17:15.743", "Id": "33481", "Score": "2", "Tags": [ "scheme" ], "Title": "Remove first occurrence of element from list" }
33481
<p>I've been reading too many papers and writing too little code. These are my first 300 lines of Haskell:</p> <pre><code>{-# LANGUAGE NoMonomorphismRestriction, TemplateHaskell #-} module Forth where import qualified Data.Map.Lazy as Map import Control.Monad.State import Control.Monad.Error import Text.Read (read...
[]
[ { "body": "<p>I think <code>popStack</code> might look a little nicer using the <code>LambdaCase</code> extension:</p>\n\n<pre><code>popStack :: ForthS Integer\npopStack = use stack &gt;&gt;= \\case\n [] -&gt; throwError \"Empty stack. Can't pop!\"\n (n:ns) -&gt; stack .= ns &gt;&gt; return n\n</code></pr...
{ "AcceptedAnswerId": "74351", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-29T23:10:22.350", "Id": "33483", "Score": "6", "Tags": [ "haskell", "forth" ], "Title": "Toy Forth interpreter" }
33483
<p>I am trying to simplify my code, which will do several things:</p> <ol> <li>Give the same width to every columns no matter how many columns the table has.</li> <li>Add input field if there is no text inside a <code>td</code></li> <li>Make sure the input field is no wider than its table cell</li> <li>Make sure, if t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T00:30:14.687", "Id": "53646", "Score": "0", "body": "one huge efficiency improvement is only test first row for number of columns. Checking how many cells in row...for every td is a massive duplication of effort. Same with setting ...
[ { "body": "<p>At first, you code looks good enough for the set of the requrements you specified. The constructions that you use are simple, so here may be place for the improvements, but this requeres developing understanding in the nontrivial subjects: CSS selectors, jQuery selectors and jQuery chaining detail...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T00:24:46.147", "Id": "33485", "Score": "0", "Tags": [ "javascript", "jquery", "html", "form", "layout" ], "Title": "Resizing table widths and making input fields" }
33485