body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I am studying the composite pattern and have created a very simple project that uses composite to introduce family members. I have decided to go with the 'fully transparent' implementation by defining all of my common functions in the interface class, I feel this is the neatest implementation and am considering thro...
[]
[ { "body": "<blockquote>\n <ol>\n <li>Am I implementing composite correctly.</li>\n </ol>\n</blockquote>\n\n<p>Although you are doing it correctly, a part of me wonders if it was the correct solution for you problem. The reason I ask is because a interface usually means that each method that you define is goi...
{ "AcceptedAnswerId": "33488", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T01:55:35.273", "Id": "33487", "Score": "4", "Tags": [ "java" ], "Title": "Is this a good example of the composite pattern?" }
33487
<pre><code>public void something() { Session session = HibernateUtil.newSession(); AModelDAO amd = new AModelDAO(session); BModelDAO bmd = new BModelDAO(session); Transaction tx = session.beginTransaction(); amd.savesomething(object); bmd.savesomething(object2); tx.commit(); session.clo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T07:36:56.560", "Id": "53665", "Score": "0", "body": "I do not know hibernate. This is a general guideline that you should handle exception here and also think of the case where the transaction fails and how you revert back the state...
[ { "body": "<p>Instead of working with Hibernate sessions, I encourage you to use the JPA API. I think this is the most common way to work with Hibernate now. (<a href=\"http://www.theserverside.com/news/2240186700/The-JPA-20-EntityManager-vs-the-Hibernate-Session-Which-one-to-use\" rel=\"nofollow\">http://www.t...
{ "AcceptedAnswerId": "33516", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T07:06:54.167", "Id": "33495", "Score": "1", "Tags": [ "java", "session", "hibernate" ], "Title": "Coherent usage of Hibernate's session and DAO" }
33495
<p>I am pretty new to iOS development - I'm writing an app the uses web services, pretty extensively. With that in mind, I decided to use AFNetworking 2.0 and subclass <code>AFHTTPSessionManager</code>. </p> <p>I created a method to build a URL for me - based on <code>NSDictionary</code> parameters and then I use the ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-06-08T06:31:54.583", "Id": "168912", "Score": "0", "body": "@Tender I am also looking for same thing but could not able to handle if Service is Get, post..... Please if u could update ur complete answer then it would be great for us to ha...
[ { "body": "<p>My first thought is does AFNetworking not handle this already but if not I would suggest doing this in a more AFNetworking style: create an object of type AFHTTPResponseSerializer * and set an instance of it as the session manager's requestSerializer property</p>\n\n<p>This way you can use the de...
{ "AcceptedAnswerId": "33501", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T07:42:35.537", "Id": "33497", "Score": "4", "Tags": [ "beginner", "objective-c", "ios", "http", "session" ], "Title": "Subclassing AFNetworking to handle POST / GET req...
33497
<p>I've got a string that has values that are delimited by comma's, like so:</p> <pre><code>$var = '1,23,45,123,145,200'; </code></pre> <p>I'd like to get just the first value, so what I do is create an array from it and get the first element:</p> <pre><code>$first = current(explode(',', $var)); </code></pre> <p>Fi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T11:11:08.283", "Id": "53678", "Score": "0", "body": "+1 for _not_ ignoring your gut feeling, and being reluctant to tackle this using regex. It's proof of sentient activity, some people lack" } ]
[ { "body": "<p>I am not familiar with php syntax but I hope you could do this </p>\n\n<pre><code> $var = \"1,23,45,123,145,200\"; ...
{ "AcceptedAnswerId": "33503", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T10:01:23.603", "Id": "33500", "Score": "4", "Tags": [ "php", "performance", "strings", "array", "regex" ], "Title": "Performance: getting first value from comma delimit...
33500
<blockquote> <p><strong>Even Fibonacci numbers</strong></p> <p><strong>Problem 2</strong></p> <p>Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:</p> <p>1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...</p> <p>By ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T19:46:59.130", "Id": "53666", "Score": "0", "body": "Have you solved the problem on PE? Have you looked at the attached pdf (see http://i.stack.imgur.com/WLwim.png ) that goes into the math for a better implementation?" }, { ...
[ { "body": "<p>No iteration is required to calculate this result.</p>\n\n<p>Every third Fibonacci number is even. The <a href=\"http://en.wikipedia.org/wiki/Fibonacci_number\">Fibonacci numbers can be expressed in closed form</a> as: </p>\n\n<pre><code>Fib(n) = 1/sqrt(5) * (phi^n - psi'^n)\n</code></pre>\n\n<p>...
{ "AcceptedAnswerId": "33505", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-28T19:41:23.090", "Id": "33504", "Score": "1", "Tags": [ "optimization", "scala", "project-euler", "fibonacci-sequence" ], "Title": "Better way of calculating Project Euler #2...
33504
<p>As a challenge I decided to do the following problem:</p> <blockquote> <p>How many different numbers with <em>n</em> digits are there whose digits add up to <em>k</em>?</p> </blockquote> <p>As this is an embarrassingly parallel problem I decided to use a bit of GPGPU programming (partly for learning purposes) us...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T11:05:34.050", "Id": "54422", "Score": "0", "body": "Could you please clarify this: `How many different numbers with n digits are there that add up to k`\n\nDo you mean: `How many different numbers with n digits are there whose digi...
[ { "body": "<p>I understand that you are asking from a parallel point of view, but I am unable to provide feedback on that, as I have never worked with this system before. But from my point of view, creating a parallel solution is has been done premature.</p>\n\n<p>Prior to creating a parallel solution to speed ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T12:12:08.510", "Id": "33506", "Score": "3", "Tags": [ "c++", "c++11", "combinatorics", "amp" ], "Title": "Max-digits of digit summing" }
33506
<pre><code>public static DateTime NextByDayOfWeek(this DateTime target, IEnumerable&lt;DayOfWeek&gt; validDaysOfWeek) { validDaysOfWeek = validDaysOfWeek .OrderBy(item =&gt; item); var nextDayOfWeek = validDaysOfWeek .Where(item =&gt; item &gt; target.DayOfWeek) .FirstOrDefault(); ...
[]
[ { "body": "<p>I think a more readable way to write this would be to get the dates of the 7 days following the given date and return first one that matches the given days of week:</p>\n\n<pre><code>public static DateTime NextByDayOfWeek(\n this DateTime target, params DayOfWeek[] validDaysOfWeek)\n{\n retu...
{ "AcceptedAnswerId": "33517", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T13:31:22.417", "Id": "33510", "Score": "2", "Tags": [ "c#", "datetime" ], "Title": "Get the next date based on a collection of valid weekdays" }
33510
<p>I have wrote a simple util to submit my code to <a href="http://poj.org" rel="nofollow">a online judge site</a>, how to avoid the evil function?</p> <pre><code>(setq url-proxy-services '(("http" . "localhost:8888"))) (setq debug-on-error t) (require-package 'http-post-simple) (require 'http-post-simple) (eval-whe...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T15:06:22.967", "Id": "53702", "Score": "1", "body": "please indent your code properly!" } ]
[ { "body": "<p>The short answer to your question is that <em>forms</em> are <em>evaluated</em> while <em>functions</em> are <em>called</em> (using <code>funcall</code> or <code>apply</code>).</p>\n\n<p>I.e., the way you structure your code (lists of forms) you are painting yourself into the <code>eval</code> cor...
{ "AcceptedAnswerId": "33521", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T14:27:54.883", "Id": "33515", "Score": "1", "Tags": [ "lisp", "elisp" ], "Title": "How do I avoid eval in elisp?" }
33515
<p>I have created a module/factory/directive for AngularJS which allows to save user input to localStorage and restore it if needed.</p> <p>Although it works quite good, I am sure that I could improve its code base and am looking for advice to do so.</p> <p>It can be found on github: <a href="https://github.com/sprot...
[]
[ { "body": "<p>my two cents : </p>\n\n<ul>\n<li><p>add <code>.idea</code> to your <code>.gitignore</code>. If someone else uses the same IDE as you and works on this code, it could get very frustrating.</p></li>\n<li><p>your code is not minification-proof, which can be annoying for someone who plans to use it. S...
{ "AcceptedAnswerId": "33533", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T15:13:30.080", "Id": "33519", "Score": "1", "Tags": [ "javascript", "angular.js" ], "Title": "Local Storage accessor and modifier helper" }
33519
<p>So I was trying to do <a href="http://tour.golang.org/#71" rel="nofollow">this exercise from Tour of Go</a>. I managed to get it working. I am not at all sure that it is correctly concurrent or idiomatic (I started learning Go, like, 4 hours ago).</p> <p>I would really appreciate feedback about my solution. Here's ...
[]
[ { "body": "<p>There are two things I see.</p>\n\n<ul>\n<li><p>Don't store a reference to a time out. I think the count down starts when After() is called.</p>\n\n<pre><code>timeout := time.After(2000 * time.Millisecond)\n...\ncase &lt;- timeout:\n</code></pre>\n\n<p>Most code I've seen writes it like this.</p>\...
{ "AcceptedAnswerId": "36877", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T16:42:07.177", "Id": "33524", "Score": "4", "Tags": [ "go", "concurrency", "http" ], "Title": "Web Crawler (A Tour of Go #71)" }
33524
<p>I'll gladly appreciate it if you could review my code below and let me know if they are sufficiently secure.</p> <p>My main website and these scripts will use same database, so I need to make sure they are sufficiently secure before I put them live.</p> <p>Since I cannot post more than two links, I'll post my Anti...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T17:51:22.740", "Id": "53711", "Score": "3", "body": "[Please include the code in the question, not a link to it.](http://codereview.stackexchange.com/help/on-topic)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate":...
[ { "body": "<p>personally I would just parameterize your Queries, this is going to be easier and more secure to do for your code than to try and weed out all the bad words or Escape Characters or other SQL Symbols. </p>\n\n<p>I am not 100% sure how you do it PHP. lucky for us, someone has asked this question o...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T17:03:58.523", "Id": "33526", "Score": "3", "Tags": [ "php", "security", "sql-injection" ], "Title": "SQL-injection mitigation script" }
33526
<p>Given a particular <code>Date</code>, want to find the next occurring Friday. I solved it using the below code. Various tested scenarios work good for me.</p> <ol> <li>Are there any boundary conditions the code might break?</li> <li>Can it be written any better?</li> </ol> <p></p> <pre><code>function dates() {...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T18:50:50.023", "Id": "53712", "Score": "0", "body": "Do you mean the next friday following the date, or the next friday on the date or later? The code will do the latter. There is a bug i the code, you are using `6` instead of `diff...
[ { "body": "<ol>\n<li>No, it looks fine.</li>\n<li>Yes, it can be. A hint: use \"% 7\" - this will narrow the delta to the one week only.</li>\n</ol>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T08:41:47.153", "Id": "53770", "Score": ...
{ "AcceptedAnswerId": "33532", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T17:41:50.953", "Id": "33527", "Score": "19", "Tags": [ "javascript", "datetime" ], "Title": "Find next occurring Friday (or any dayOfWeek)" }
33527
<p>This was a revision, made when the code failed after an update (at least that is what I think happened).</p> <p>So I fixed it and now it works, but I think that this code can be written better and more efficiently, and perhaps made easier to read. Note that VBScript/VBA/VB6 isn't (aren't) my primary language(s), th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T20:31:49.047", "Id": "53721", "Score": "1", "body": "Yay, a [cyclomatic complexity](http://en.wikipedia.org/wiki/Cyclomatic_complexity) party!! I'll look at this when I have a chance :)" }, { "ContentLicense": "CC BY-SA 3.0"...
[ { "body": "<p>I'm assuming this is VBScript, and I'm not familiar at all with VBScript, and it seems pretty different from VBA/VB6 as far as iterating arrays (can't do <code>For Each</code> on an array in VBA/VB6) and string nullability is concerned - and VBA/VB6 isn't exactly crystal-clear as to what means wha...
{ "AcceptedAnswerId": "33625", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T19:02:39.260", "Id": "33535", "Score": "5", "Tags": [ "xml", "vbscript" ], "Title": "My script is about as scary as the XML it's reading" }
33535
<p>I have a piece of C++ code that transforms a vector where an element only stays one if itself and both of it's neighbors are one as well. End-points are handled as if the missing element is one. For example:</p> <pre><code>old: 1 1 0 1 1 1 0 1 1 0 new: 1 0 0 0 1 0 0 0 0 0 </code></pre> <p>The following block of co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T21:01:20.273", "Id": "53725", "Score": "1", "body": "Since you're just using `0`s and `1`s, you *could* consider [`std::vector<bool>`](http://en.cppreference.com/w/cpp/container/vector_bool). On the other hand, the answers [here](h...
[ { "body": "<p>What you have is probably good enough. If you want to try something crazy, you could always do:</p>\n\n<pre><code>boost::range::transform(boost::irange(0, N), block.begin(), [&amp;](const int i){\n int pre = i-1 &gt;= 0 ? state[i-1] : 1;\n int post = i+1 &lt; N ? state[i+1] : 1;\n return ...
{ "AcceptedAnswerId": "33545", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T20:00:00.507", "Id": "33540", "Score": "1", "Tags": [ "c++", "optimization" ], "Title": "Transforming a stl vector according to its neighbors" }
33540
<p>I am helping a friend with her Java homework and I adapted a solution I used in a similar project of my own for this. It is supposed to use loose/generous regex to make sure an email entered matches the forms abc123@xyz.net or abc.123@xyz.net.</p> <pre><code>import java.util.Scanner; public class App { Scanne...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T22:18:13.150", "Id": "53732", "Score": "0", "body": "Note: Your RegEx is not going to admit (a great many possible) eMail addresses, and will admit invalid ones. (e.g. domain names cannot have _, TLD's can be other than 3 letters, T...
[ { "body": "<p>My preference for accepting user input in a blocking loop like this might look more like:</p>\n\n<pre><code> public enum Returned { OK, ERROR_EMAIL };\n</code></pre>\n\n<p>…</p>\n\n<pre><code> // Long loop here to get valid user registration info.\n /* In a transactional/event-driven (GUI, web)...
{ "AcceptedAnswerId": "33550", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T21:19:52.277", "Id": "33546", "Score": "3", "Tags": [ "java", "regex", "validation" ], "Title": "Simple code to check format of user inputted email address" }
33546
<p>Requires Underscore and jQuery</p> <p>I'm looking for suggestions on how to make this a little more readable and additional suggestions on flow, logic, etc. </p> <p>The game can be run in a browser by just copying and pasting the code(HTML/JS/CSS) below. </p> <p><strong>JavaScript: app/js/app.js</strong></p> <pr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T22:52:15.590", "Id": "53737", "Score": "0", "body": "I took the liberty of copying your code (completely as-is) into [this jsfiddle](http://jsfiddle.net/NuDPq/) for people to try out." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>You code is looks good. I want to suggest a few coding style improvements:</p>\n\n<ul>\n<li>remove unnecessary punctuators (example: <code>(players.length)</code> in <code>return Math.floor(Math.random() * (players.length));</code>);</li>\n<li><code>if</code>s with one statements are not consisten...
{ "AcceptedAnswerId": "33553", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T22:06:01.550", "Id": "33547", "Score": "1", "Tags": [ "javascript", "jquery", "game", "html", "css" ], "Title": "Tic-Tac-Toe JavaScript readability and additional sugge...
33547
<p>I have recently written this Minesweeper game in Python:</p> <pre><code>import random class Cell(object): def __init__(self, is_mine, is_visible=False, is_flagged=False): self.is_mine = is_mine self.is_visible = is_visible self.is_flagged = is_flagged def show(self): self.i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-03-31T20:28:23.120", "Id": "165921", "Score": "0", "body": "Nice code, you could make it more detailed for it to be easier for the user to play, this can be done with something called `pygame` check it out (pygame.org), download a couple ...
[ { "body": "<p>From a user interface point of view, it would be good to have :</p>\n\n<ul>\n<li><p>letters for columns and numbers for rows (or the opposite)</p></li>\n<li><p>a clear area for empty cells.</p></li>\n<li><p>something to prevent you from winning just be flagging every single cell.</p></li>\n<li><p>...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-30T22:11:15.493", "Id": "33548", "Score": "6", "Tags": [ "python", "game", "minesweeper" ], "Title": "Minesweeper in Python" }
33548
<p>I have the following declaration in my String.h file:</p> <pre><code>private: char* nstring; int nlength; }; </code></pre> <p>The following are three constructors I've implemented in String.cpp. I would like these to be reviewed.</p> <pre><code>// Default constructor for this class. Initializes an empty ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T23:02:07.557", "Id": "53868", "Score": "4", "body": "Its not the constructor that it is hard. But the interaction of the compiler generated methods. Constructor (default - copy)/Destructor/Assignment (and now Move in C++11). These a...
[ { "body": "<p>Your lengths are off by 1 everywhere. An empty string has length 0 not 1, <code>\"Hello\"</code> has length 5 not 6, etc. </p>\n\n<p>Your constructor from the <code>const char*</code> can just assign every character in the loop (since we know the <code>nlength</code>th character of <code>input</co...
{ "AcceptedAnswerId": "33556", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T00:09:31.057", "Id": "33555", "Score": "2", "Tags": [ "c++", "strings", "constructor" ], "Title": "Review of three constructors for a String class" }
33555
<p>I have implemented a DOM parser. I would like any comments for optimizing, improving, and making the code coherent to best coding practices.</p> <pre><code>final class Node { private final String nodeName; private final String nodeValue; private final NodeTypeEnum nodeType; private final Map&lt;Str...
[]
[ { "body": "<p>You've tagged it \"XML\" so I suppose your intent is to parse anything that conforms to XML 1.0? If not, you should say what language you are intending to parse. At the moment, you're not remotely close to parsing general XML, for example you'll fail to handle \"&lt;\" in a CDATA section or commen...
{ "AcceptedAnswerId": "33740", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T00:49:36.427", "Id": "33558", "Score": "2", "Tags": [ "java", "parsing", "xml", "dom" ], "Title": "DOM parser implemented from scratch" }
33558
<p><code>dem_rows</code> and <code>dem_cols</code> contain float values for a number of things i can identify in an image, but I need to get the nearest pixel for each of them, and than to make sure I only get the unique points, and no duplicates. </p> <p>The problem is that this code is ugly and as far as I get it, a...
[]
[ { "body": "<p>I'm not sure what you are doing, exactly, but looping over <code>range(len(...))</code> is never very pythonic. Since you only use the index to look up values, you should just take the pairs using <code>zip</code>.</p>\n\n<p>Also, that <code>round() + 0.1</code> thing is unnecessary. Floats repres...
{ "AcceptedAnswerId": "33563", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T09:03:44.483", "Id": "33562", "Score": "3", "Tags": [ "python", "image", "numpy", "floating-point" ], "Title": "Distinct nearest pixels for floating-point coordinates" }
33562
<p>I am solving <a href="http://www.spoj.com/problems/ADV04B1" rel="nofollow">this problem</a> on SPOJ Upper Right King (Hard):</p> <blockquote> <p>There is a king in the lower left corner of the \$ n \times n \$ chess board. The king can move one step right, one step up or one step up-right. How many ways are there...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T14:00:58.900", "Id": "53790", "Score": "0", "body": "[See this code](http://oeis.org/A001850/a001850.py.txt) by Nick Hobson." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T06:26:37.037", "Id": "5...
[ { "body": "<h2>Flatten your method body</h2>\n\n<pre><code>def egcd(a, b):\n if a == 0:\n return (b, 0, 1)\n else:\n g, y, x = egcd(b % a, a)\n return (g, x - (b // a) * y, y)\n</code></pre>\n\n<p>can be re-written as:</p>\n\n<pre><code>def egcd(a, b):\n if a == 0:\n return ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T11:26:48.763", "Id": "33575", "Score": "6", "Tags": [ "python", "mathematics", "combinatorics", "time-limit-exceeded", "chess" ], "Title": "Central Delannoy numbers" }
33575
<p>Trying to write a substring function in Clojure. I am sure there is a more idiomatic way. Can anyone enlighten me? </p> <p>Otherwise, here is my version. Thoughts?</p> <pre><code>(defn substring? "is 'sub' in 'str'?" [sub str] (if (not= (.indexOf str sub) -1) true false)) </code></pre>
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T13:01:06.020", "Id": "53783", "Score": "0", "body": "hmmm...just discovered - (.contains \"abcdefghi\" \"abc\"), anyway that doesn't interop with Java (purely out of curiosity!)?" }, { "ContentLicense": "CC BY-SA 3.0", "...
[ { "body": "<p>As you wrote in your comments, (.contains \"str\" \"sub\") is perfectly fine. it is indeed java interop - it runs the method contains on String object \"str\".</p>\n\n<p>two more comments, first, passing str as a var name isnt so good, since str is a function, so you should consider giving it a di...
{ "AcceptedAnswerId": "35141", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T12:33:55.770", "Id": "33577", "Score": "9", "Tags": [ "strings", "clojure" ], "Title": "Clojure - substring? function" }
33577
<p>I'm using <a href="http://www.websupergoo.com/abcpdf-1.htm" rel="nofollow noreferrer">ABCPDF</a> (Version 8) to update an existing PDF document and I believe its API is hurting me in this situation and was curious whether anyone had any comments on how this looks as it appears ugly to me.</p> <p>The situation: I am...
[]
[ { "body": "<p>Could you you create your own <code>IEnumerable</code> that wraps all this up very well behind an interface?</p>\n\n<p>Then you can just do a <code>foreach</code> loop over the elements and not have to worry about the continues. </p>\n\n<p>It would iterate over <code>(Annotation)pdfDoc.ObjectSoup[...
{ "AcceptedAnswerId": "33595", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T13:25:34.497", "Id": "33579", "Score": "3", "Tags": [ "c#", "pdf" ], "Title": "Lots of Continues in an Inner Loop and Dictionary of Actions" }
33579
<pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;QR code generator&lt;/title&gt; &lt;style&gt; body { font-family: arial, sans-serif; } section { margin: 50px auto; max-width: 350px; text-align: center; } textarea { width: 100%; height: 50p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T17:17:05.283", "Id": "53815", "Score": "0", "body": "Minor nit: \"bellow\" => \"below\". ;-)" } ]
[ { "body": "<p>This code looks fine to me.</p>\n\n<p>If you are interested in nitpicking then : </p>\n\n<ul>\n<li>Style information should be in a css file</li>\n<li>JavaScript should be in a js file</li>\n<li>Your image tag should have an alt</li>\n<li>It should show some indication that you are leveraging a Go...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T13:29:09.743", "Id": "33580", "Score": "2", "Tags": [ "javascript", "html" ], "Title": "QR Code generator" }
33580
<p>i am looking for a faster and more efficient way of this code. What the code does is simply compares message context of (user, application, service and operation) and compares it with some rules.</p> <pre><code>private boolean match(Context messageContext, ContextRule contextRule) { if(contextRule.getMessag...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T15:22:38.433", "Id": "53799", "Score": "0", "body": "Please a little bit more information. What is `Context` and `ContextRule`. What doe all these functions return?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate":...
[ { "body": "<p>First of all, your formatting seems messy, please fix it.</p>\n\n<hr>\n\n<p>Did you rip it out or is there really zero documentation in there (JavaDoc)? Consider adding some, it will make your life and that of others easier.</p>\n\n<hr>\n\n<p>First step would be to add an overload to <code>match()...
{ "AcceptedAnswerId": "33589", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T15:10:40.170", "Id": "33586", "Score": "2", "Tags": [ "java" ], "Title": "Multiple if conditions in one block - looking for faster and more efficient code" }
33586
<p>I am writing a simple image rotation script. Users press either the prev or next button to view the previous or next images. It works well, but the code looks over the top. Is there a way I can reduce the amount of code used?</p> <p><strong>index.php</strong></p> <pre><code>&lt;div id="container"&gt; &lt;img src="...
[]
[ { "body": "<p>You need to abstract your code from the design, at the moment, adding another picture is going to yield !!!fun!!! (if I'm allowed to use my dwarven vocabulary). At the moment adding another picture would require that you copy and paste code and extend that if further. This is obviously not desirab...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T16:03:25.020", "Id": "33590", "Score": "2", "Tags": [ "javascript", "jquery", "image" ], "Title": "Simple image rotation script" }
33590
<p>I presented a code solution to a startup as part of their interview polity.</p> <p>The problem statement is to find the frequency of words occurring in a sentence. I got the code rejected saying, "Evaluating code is always subjective, but people generally leave a "fingerprint" with their design approach and the na...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T17:12:07.347", "Id": "53811", "Score": "2", "body": "Proper indentation would be a good start." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T17:12:23.447", "Id": "53812", "Score": "3", "...
[ { "body": "<p>I am not a fan of this type of interview process... but ... you can assume that you need to differentiate yourself from the other candidates in some way.</p>\n\n<p>Your solution may work, but does not show much in the way of 'clever' algorithms. You do the minimum to get the answer right, but not ...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T17:10:42.550", "Id": "33593", "Score": "3", "Tags": [ "java", "interview-questions" ], "Title": "Optimal code without using for, while and if" }
33593
<p>I keep using a pattern in ruby over and over again.</p> <p>Here are some examples:</p> <pre><code> def get_row_numbers_for_id(id_to_search_for) @results = [] (0...row_count).each do |row| get_row(row).css('td').each do |cell| @results &lt;&lt; row unless row.nil? if (cell['id'] == id_to_searc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-03T01:37:53.010", "Id": "53996", "Score": "0", "body": "A small thing, David: 'results' and 'cells' don't need to be instance variables; local variables would be within the scopes of the respective blocks." }, { "ContentLicense...
[ { "body": "<p>What you're looking for is Array#map or Enumerable#collect.</p>\n\n<p>The 2nd method can be written as</p>\n\n<pre><code>def cell_content_array\n @doc.css('td p span').map { |span| span.content }\nend\n</code></pre>\n\n<p>Or, as we're simply extracting <code>content</code>, it can be further simp...
{ "AcceptedAnswerId": "33608", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T17:28:19.833", "Id": "33598", "Score": "-2", "Tags": [ "ruby" ], "Title": "Initializing an array, using some sort of loop that shoves stuff onto it, and returning it" }
33598
<p>I put together a sample of how I am using the Unit of Work &amp; Repository pattern based on my understanding. Can anyone please let me know if I am implementing this the correct way? If I am not, how can I improve it?</p> <p>I have an EF model with two entities: Topic and Subtopic. The EF model is called CommonGoo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T19:50:57.370", "Id": "53848", "Score": "1", "body": "While accepting answers is an excellent idea, you should give it some more time, perhaps 2-3 days, to let the votes roll in and keep your question appealing to other answerers. Pr...
[ { "body": "<p>You're getting there. Here's a pattern that I've used that works really well. I don't like generic \"find\" and \"save\" methods because they tend to be really complicated in order to work with everything and I find you end up pulling your hair out when you want to do something special.</p>\n\n<p>...
{ "AcceptedAnswerId": "33613", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T18:15:55.857", "Id": "33611", "Score": "6", "Tags": [ "c#", "asp.net-mvc-4" ], "Title": "Unit of Work with Repository Pattern MVC 5 & EF 6" }
33611
<p>This is bit long, but I need to explain something before I can ask for actual reviews/advice.</p> <p>I have to test generated C code from Matlab Simulink model. I can create a executable binary from those. I need to test this application using tests developed using Python scripting.</p> <p>I came up with followin...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-06-02T12:24:34.557", "Id": "243168", "Score": "0", "body": "One thing: the `multiprocessing` module already natively supports shared memory." } ]
[ { "body": "<p>It is short and to the point. Looks fine.</p>\n\n<blockquote>\n <p>used via both Python scripts and application to interact with each other</p>\n</blockquote>\n\n<p>You didn't describe the interaction, in English nor in code. Maybe the two sides routinely manipulate lots of data structures (1500 ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T18:34:11.643", "Id": "33612", "Score": "7", "Tags": [ "python", "c++", "boost" ], "Title": "Signal simulation through Python scripts using shared memory for testing a C applicatio...
33612
<p>The overall intent is to consolidate individual sales transactions to total debits/credits summing up the totals by year and month--retaining a running balance from start to end. This code uses multiple <code>#temp</code> tables. I am interested in having this code reviewed in order to find a more efficient way to a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-07T15:23:40.087", "Id": "54603", "Score": "0", "body": "i can't even get this to build on SQLFiddle.com. there are a bunch of places where the column names don't match, etc please look over your post and make sure that it is correct"...
[ { "body": "<p>it is good Coding Practice to Capitalize all of the Reserved SQL words so that it is easier to tell them apart. </p>\n\n<p>words like <code>SELECT</code>, <code>FROM</code>, <code>WHERE</code>, <code>WITH</code>, <code>INTO</code>, <code>GROUP BY</code>, <code>ORDER BY</code>, <code>CREATE TABLE</...
{ "AcceptedAnswerId": "35655", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T21:28:39.480", "Id": "33621", "Score": "1", "Tags": [ "sql", "sql-server", "t-sql", "finance" ], "Title": "Maintaining a total balance of debit/credit sales transactions" }
33621
<p>I have a backup job that walks across a huge directory with potentially millions of files. Python's os.walk() works just fine.</p> <p>Now, I have implemented a feature to ignore files based in a black list of patterns. I just want it to behave like a .gitignore file.</p> <p>Currently I do this:</p> <pre><code>imp...
[]
[ { "body": "<p>You can simplify the loop by using a generator expression like this:</p>\n\n<pre><code>for filename in filenames:\n if any(fnmatch(filename, pattern) for pattern in ignore_list):\n print 'Ignore', filename\n continue\n</code></pre>\n", "comments": [], "meta_data": { ...
{ "AcceptedAnswerId": "33642", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T00:23:22.093", "Id": "33624", "Score": "1", "Tags": [ "python", "iterator", "generator" ], "Title": "Filtering a long list of files through a set of ignore patterns using itera...
33624
<p>My homework was to organize semaphores into a pyramid. The task was accomplished, but I ended up with this long ugly conditional and was wondering if anyone can see a better way/algorithm to accomplish the same thing.</p> <pre><code>if (me==0) { wait_sem(semaphore[1]); wait_sem(semaphore[2]); signal_sem...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T00:26:45.737", "Id": "53876", "Score": "2", "body": "You could use a `switch`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T00:31:05.583", "Id": "53877", "Score": "0", "body": "Yeah. A `...
[ { "body": "<p>Switch statements are quite helpful in such cases. They are also more efficient than your series of <code>if</code> statements which has to check all of them even after it finds the one it is looking for. The <code>switch</code> will immediately branch to the correct one and skip all the others....
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T00:24:44.873", "Id": "33626", "Score": "6", "Tags": [ "c", "homework", "thread-safety" ], "Title": "Organizing semaphores into a pyramid" }
33626
<p>This program takes a huge data set as input, processes it, calculates and then writes the output to an array. Most calculations may be quite simple, such as summation. In the input file, there are about 100 million rows and 3 columns.</p> <ol> <li>first column is the name of the gene (total 100 millions)</li> <li>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T08:16:18.833", "Id": "53887", "Score": "2", "body": "You import `numpy` but don't take advantage of its vectorized operations. See [What is NumPy?](http://docs.scipy.org/doc/numpy/user/whatisnumpy.html) to get some ideas." }, { ...
[ { "body": "<p>The first thing for solving a problem like this is to find out what the actual bottleneck is. In your case the two most likely parameters are disk IO or CPU power.</p>\n\n<p><strong>Disk IO</strong></p>\n\n<ul>\n<li>Make sure the data sits on local drives and not on a network share or USB stick or...
{ "AcceptedAnswerId": "33638", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T05:44:04.490", "Id": "33633", "Score": "2", "Tags": [ "python", "performance", "numpy", "statistics" ], "Title": "How to reduce runtime of gene data processing program?" }
33633
<p>I was trying another approach of sorting a linked list. Aside from the available methods, I've decided to take each node from the linked list and place it into an array. With that, I would be able to compare the data variables easily. I applied <code>quickSort()</code> on the array, and this is what I have. I woul...
[]
[ { "body": "<p>First of all I don't know why are you trying to <em>reinvent the wheel?</em> Java has a strong and beautiful API with many methods and there is also <a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html#sort%28T%5B%5D,%20java.util.Comparator%29\" rel=\"nofollow noreferrer\">a me...
{ "AcceptedAnswerId": "33645", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T05:58:08.117", "Id": "33634", "Score": "1", "Tags": [ "java", "linked-list", "quick-sort" ], "Title": "Review of linked list and quick sort" }
33634
<p>Simplification of code would be appreciated.</p> <pre><code>var textarea = document.getElementById("textarea"), statusBar = document.getElementById("status-bar"), inputFile = document.getElementById("input-file"), appname = "notepad", isModified = false, showStatusBar = true, filename; function changeD...
[]
[ { "body": "<p>The code is good. The only comment I have is that the data and its representation are highly coupled so it may be good idea to invest some time in separating them. But it will make sense only if this application will grow and evolve. Now it is very neat and good looking.</p>\n", "comments": []...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T06:47:53.410", "Id": "33637", "Score": "2", "Tags": [ "javascript" ], "Title": "Review of status bar code" }
33637
<p>I wrote this method that does the job and passes the assertion tests for a large java backend project but I'm not all happy with the way it reads, perhaps you can tell me how to refactor and/or improve this method?</p> <pre><code>public Set&lt;ProductOfferingJsonDto&gt; getJsonProductOfferings() { Set&lt;Produc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T13:57:45.977", "Id": "53906", "Score": "0", "body": "What's the problem of this code? Why you thing it is hard to reader and need refactor? You need a goal for reflector code, so other people can help you." }, { "ContentLice...
[ { "body": "<p>You could add a factory method for SimpleProductOfferingJsonDto and BundledProductOfferingJsonDto which only takes a piterdto and a bpod object.</p>\n\n<p>It could look something like:</p>\n\n<pre><code>public Set&lt;ProductOfferingJsonDto&gt; getJsonProductOfferings() {\nSet&lt;ProductOfferingJso...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T07:43:24.847", "Id": "33639", "Score": "2", "Tags": [ "java" ], "Title": "Converting between backend object and object suitable for JSON" }
33639
<p>Ever since reading Crockford's "Good Parts" and <a href="http://tddjs.com/" rel="nofollow">Johansen's TDD book</a>, I have wanted to use more of the <em>differential inheritance</em> pattern in my coding at work (as in avoiding <code>new</code> by using <code>Object.create()</code>), but I find that I am having a ha...
[]
[ { "body": "<p>I see a conceptual issue with this approach: it is nice to inherit from objects, but these entities are not the \"real\" object. In other words, there is no much sense in using them outside of initialization code. If you need new <code>[Cc]ar</code> then it will not be wise to take any car that is...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T12:47:05.417", "Id": "33646", "Score": "0", "Tags": [ "javascript", "inheritance", "prototypal-class-design" ], "Title": "Coding convention when using differential inheritance" }
33646
<p>Me and my colleagues do a small TDD-Kata practice everyday for 30 minutes. For reference this is the link for the excercise <a href="http://osherove.com/tdd-kata-1/" rel="nofollow">http://osherove.com/tdd-kata-1/</a> </p> <p>The objective is to write better code using TDD. This is my code which I've written</p> <p...
[]
[ { "body": "<p>I think the code should be easily readable from the start. My goal is to avoid the need for comments. Your colleagues make great points about the advantages of such verbose code as well. Additionally, tools such as Resharper make it incredibly easily to restructure code so it's easily readable li...
{ "AcceptedAnswerId": "33652", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T13:20:36.537", "Id": "33649", "Score": "2", "Tags": [ "c#", "tdd" ], "Title": "How to write simple code using TDD" }
33649
<p>The problem is not very complicated (I mean it is easy to solve it), but the question is how to make it in the easiest way (Java)</p> <p>Input String: </p> <pre><code>String inputString = "[value=20][param=304.2][indicator=1500]"; </code></pre> <p>Expected output: array of <code>double</code>s : [20.0][304.2][150...
[]
[ { "body": "<p>Don't know if using regex is overkill, but it does open up for a fairly concise and (in my opinion) readable solution.</p>\n\n<pre><code>public class ArgumentParser {\n public static final Pattern KEY_VALUE_PATTERN = Pattern.compile(\"\\\\[([a-zA-Z]+)=(-?\\\\d+\\\\.?\\\\d*)\\\\]\");\n\n publ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T13:49:10.710", "Id": "33650", "Score": "2", "Tags": [ "java", "strings", "parsing" ], "Title": "Retrieving doubles from string - simple problem" }
33650
<p>I have the following tables: </p> <pre><code> player | id | name | surname | |:-----------|------------:|:------------:| | 1001 | Mike | Tyson | | 2001 | John | Carlin | | 3001 | Dan | StanH | | 4001 | Alen ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T16:35:55.140", "Id": "53922", "Score": "1", "body": "I would consider, if possible, normalizing the database a touch so you don't have this repetition of data, and being forced to write queries like this. Having a table of 'Players'...
[ { "body": "<p>SQL is made to function on Joins, I wouldn't say that they are &quot;kind of &quot;expensive&quot; operation&quot; RDMS databases are made to relate to other tables. if you had Primary and Foreign Keys set up and/or even indexes then it shouldn't be an &quot;expensive operation&quot;.</p>\n<p><st...
{ "AcceptedAnswerId": "35447", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T15:37:58.743", "Id": "33657", "Score": "1", "Tags": [ "optimization", "sql" ], "Title": "Same records between two tables" }
33657
<p>Wanted some opinions on something I have been working with, I've tried a few ways of structuring the way I retrieve and return data to my WebAPI, and I'm pretty happy with what I have so far, but I was looking for a comparison of the pro's and con's of using models vs entities for returning data on the WebAPI.</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T16:48:35.307", "Id": "54121", "Score": "0", "body": "What about a *generic solution*: If I am getting you right, your (view-)models would be stripped down versions of your (database-)entities, so why not writing a generic Mapper cla...
[ { "body": "<p>No matter how simple I think my application is going to be, I always end up separating my viewmodels from my entities. Not only do I <strong>always</strong> encounter at least one case where the apparent convenience of any other approach makes it very unwieldly for me to finish a feature, but it's...
{ "AcceptedAnswerId": "33927", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T16:31:10.070", "Id": "33659", "Score": "6", "Tags": [ "c#", "asp.net", "api" ], "Title": "WebAPI - Return models vs entity and partial class with meta data" }
33659
<p>This is a query to return search results, but I feel it could be cleaned up a little. I just don't know how. </p> <pre><code>var queryResult = (from r in dc.Retailers where (string.IsNullOrEmpty(firstName) || SqlFunctions.PatIndex(firstName.Trim(...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T16:44:22.307", "Id": "53923", "Score": "1", "body": "What is the point of the query? It looks like, for each field, you're searching for Retailers where the field is null or empty OR is not null or empty... which doesn't make sense....
[ { "body": "<p>Apply the common refactoring used for repeated code: extracting a method. In your case, creating the method won't be trivial, because you want to create a different <code>Expression</code> each time. That is, unless you use <a href=\"http://www.albahari.com/nutshell/linqkit.aspx\" rel=\"nofollow\"...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T16:35:59.187", "Id": "33661", "Score": "1", "Tags": [ "c#", "linq" ], "Title": "Is there a way to eliminate the repetition in this linq query?" }
33661
<p>I want to return a list of the values from the binary tree. Is there a shorter and more efficient way to write the method for numbers?</p> <pre><code>class BTNode(object): """A node in a binary tree.""" def __init__(self, item, left=None, right=None): """(BTNode, object, BTNode, BTNode) -&gt; None...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-28T18:56:02.867", "Id": "63651", "Score": "0", "body": "I think `number` would be better named `enumerate`." } ]
[ { "body": "<ol>\n<li><p>There is no docstring for the <code>number</code> method.</p></li>\n<li><p>There are no test cases. This kind of code would be an ideal opportunity to write some <a href=\"http://docs.python.org/3/library/doctest.html\" rel=\"nofollow\">doctests</a>.</p></li>\n<li><p>The <code>depth</cod...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T18:09:45.487", "Id": "33662", "Score": "6", "Tags": [ "python", "tree", "python-3.x", "depth-first-search" ], "Title": "Returning a list of the values from the binary tree" }
33662
Portable Document Format (PDF) is an open standard for electronic document exchange maintained by the International Organization for Standardization (ISO). Questions can be about creating, reading, editing PDFs using different languages.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T18:32:23.530", "Id": "33664", "Score": "0", "Tags": null, "Title": null }
33664
Least Recently Used (LRU) is a family of caching algorithms. Please use the "cache" tag instead.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T19:23:21.703", "Id": "33667", "Score": "0", "Tags": null, "Title": null }
33667
In mathematics, a matrix (plural matrices) is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns. The individual items in a matrix are called its elements or entries.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T19:32:13.043", "Id": "33669", "Score": "0", "Tags": null, "Title": null }
33669
A programming idiom is a way to overcome a programming language limitation and/or to write commonly-used code with a purpose that is separated from a literal meaning of the code. Also, an idiom is a preferred way to write code, when there is more than one obvious way to do it.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T19:35:15.277", "Id": "33671", "Score": "0", "Tags": null, "Title": null }
33671
<h3>Description</h3> <p>A finite-state machine (FSM), or simply a state machine, is a mathematical model of computation. It is an abstract machine that can be in exactly one of a finite number of states at any given time. The FSM can change from one state to another in response to some external inputs; the change from...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-11-01T19:38:11.120", "Id": "33673", "Score": "0", "Tags": null, "Title": null }
33673
A state machine is a model for designing systems which change based upon their current state and what input they receive.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T19:38:11.120", "Id": "33674", "Score": "0", "Tags": null, "Title": null }
33674
<p>I've looked at <code>boost::exception</code> and realized it is too advanced for my project, as my colleagues mostly have legacy C background. I do not need arbitrarily complex information in exception, just some error messages and trace info that can be written to process log.</p> <p>Someone on Stack Overflow <a h...
[]
[ { "body": "<p>A note on the <a href=\"https://stackoverflow.com/questions/8481147/if-you-catch-an-exception-by-reference-can-you-modify-it-and-rethrow\">the link</a> you posted; the OP was asking a hypothetical question in regards to what happens ('under the hood') to the call stack/exception/etc. if the except...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T19:40:24.710", "Id": "33675", "Score": "1", "Tags": [ "c++", "c++11", "exception-handling" ], "Title": "Exception based on std::exception but easy to modify and rethrow" }
33675
<p>I'm working on a simple decorator that creates and manages a database cursor. The goal is to 'inject' the cursor as the first argument of the function, but not expose it to the caller.</p> <p><strong>Usage:</strong></p> <pre><code>import psycopg2 @needsNewCursor def findItem(cursor, item_id): cursor.execute(...
[]
[ { "body": "<p>No, I don't think this is a good approach. Anyone who sees the declaration <code>def findItem(cursor, item_id):</code> will call the function with two arguments and scratch one's head to no end when it does not work.</p>\n\n<p>You could just as well have <code>cursor = createDefaultCursor()</code>...
{ "AcceptedAnswerId": "33679", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T20:13:42.577", "Id": "33678", "Score": "3", "Tags": [ "python", "beginner", "cursor" ], "Title": "Simple decorator for creating and managing a database cursor" }
33678
<p>I've been working on this word search algorithm and had some issues about its speed. It kinda looks like it takes a little too much time.</p> <p>If anyone could offer suggestions on making this better and improving my skills, that would be great.</p> <pre><code> #include &lt;iostream&gt; #include &lt;string...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T21:14:20.370", "Id": "63570", "Score": "0", "body": "took me like 5 seconds to find all the words...." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-01T14:56:05.943", "Id": "63952", "Score": "0"...
[ { "body": "<ul>\n<li><p><code>widht</code> is misspelled; it should be <code>width</code>. :-)</p></li>\n<li><p>Some generalities regarding naming convention:</p>\n\n<p>Variables and functions should start with a lowercase letter:</p>\n\n<pre><code>// \"camel case\"\nint camelCaseVariable;\nvoid camelCaseFuncti...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-01T21:23:00.343", "Id": "33681", "Score": "6", "Tags": [ "c++", "algorithm", "performance", "search" ], "Title": "Improving speed of word search algorithm" }
33681
<p>I have a working solution for the given problem of A/B Optimization, but you as an experienced Python (3) developer will agree with me, that this solution is not very pythonic at all.</p> <p>My Question here is: <em>How do I make this code more pythonic?</em></p> <p>It's a very procedural process that one would expe...
[]
[ { "body": "<p>There is <em>massive</em> code duplication in your script. Basically you are doing the same things for <code>A</code> through <code>E</code>, so you could just put them in a list of dictionaries and use loops. Also, by using <code>defaultdict</code> you do not have to initialize them per hand (and...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T00:31:19.560", "Id": "33684", "Score": "2", "Tags": [ "python", "optimization", "python-3.x" ], "Title": "How to turn this working A/B optimization program into more pythonic code...
33684
<p>I'd like to simplify this Scala code:</p> <pre><code>private def getToken() = { val token = getTokenFromDb() token match { case Some(x) =&gt; token case None =&gt; { val remoteToken = getTokenRemote() remoteToken match { case Some(x) =&gt; { writeTokenToDb(...
[]
[ { "body": "<pre><code>private def getToken(): Option[Token] = {\n def remoteToken =\n getTokenRemote() map { r =&gt; writeTokenToDb(r); r }\n getTokenFromDb orElse remoteToken\n}\n</code></pre>\n\n<p>Please write always the type of a function for outer functions - it makes it far more readable to understan...
{ "AcceptedAnswerId": "33696", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T03:21:52.787", "Id": "33685", "Score": "2", "Tags": [ "scala" ], "Title": "Is there any way to simplify this code" }
33685
<p>I have written this code which finds duplicate numbers and the occurrence of a particular number in an array. I have used a <code>HashMap</code>, but I want to know if there is a more efficient way to do the same, or whether I should be using another method.</p> <pre><code>import java.util.*; class test7 { publ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-08-13T23:50:57.210", "Id": "327844", "Score": "0", "body": "Regardless of the fact that explicit boxing is unnecessary here, it's better to use [`Integer.valueOf(int)`](http://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#value...
[ { "body": "<p>I have modified your code. The logic is same as you have done. You do not need to create those <code>Integer</code>. Read about <a href=\"http://docs.oracle.com/javase/tutorial/java/data/autoboxing.html\" rel=\"nofollow\">Autoboxing</a>. If the input array is large, you will see performance hit fo...
{ "AcceptedAnswerId": "33688", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T03:54:51.693", "Id": "33686", "Score": "3", "Tags": [ "java" ], "Title": "Finding duplicate numbers" }
33686
<p>I posted a couple of weeks ago with a <a href="https://codereview.stackexchange.com/questions/32854/critique-a-beginners-linked-list-implementation">double linked list</a>. It was recommended that I rewrite the code as a singlely linked list and replace the recursive parts with loops.</p> <p>I've gone ahead and ma...
[]
[ { "body": "<p><strong>Stylistic/Function</strong></p>\n\n<ol>\n<li>Your list holds values of type <code>int</code> yet you named the node type very specific in relation to file descriptors which will be a bit weird if you make a list of lets say prime numbers you want to operate on. Consider renaming your node ...
{ "AcceptedAnswerId": "33723", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T04:52:44.387", "Id": "33687", "Score": "3", "Tags": [ "c", "linked-list" ], "Title": "Review of singlely linked list C" }
33687
<p>I write quite a bit of code in C, but haven't done much C++ since my college CS classes. I have been revisiting C++ recently, and thought I would re-implement a program I had previously written in C, but this time in C++. I particularly took advantage of containers and other features standardized recently by the C++...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T07:16:06.313", "Id": "53958", "Score": "2", "body": "Lot of extra copying. But it's hard to measure actual throughput with a set of input data. Also to help other people in the future we ask you post the code for review on the site....
[ { "body": "<p>As the comments alluded to, there's a lot of copying going on. Since I don't have profile data (wrong way to go after performance), I'll go over differences in the approach.</p>\n\n<h2>main()</h2>\n\n<p>In <code>main()</code>, the C version pre-allocates an array of <code>options.numfiles</code> p...
{ "AcceptedAnswerId": "35195", "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T05:17:36.707", "Id": "33689", "Score": "5", "Tags": [ "c++", "performance", "c", "c++11", "bioinformatics" ], "Title": "SAM mapped reads" }
33689
<p>I'm going to post some of my solutions to common interview questions. I would love it if you could critique me from a C++ purist's standpoint. Also, tell me if there's a better algorithm for each one of these. </p> <p><strong>Find the mode (most common element) of an array.</strong></p> <p>Note: My solution return...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T09:39:42.560", "Id": "53960", "Score": "1", "body": "a) It is unlikely that you would be asked for algorithmic alternatives in the interview b) everything in here revolves around arrays/\"list\"-structures. Unlikely as well during t...
[ { "body": "<ul>\n<li><p>Is the signature of the function imposed ? Your solution would work for any kind of iterable objects and would be probably more idiomatic than passing a pointer and a size. Also, the logic would work for any (comparable) types and not just <code>int</code> so it might be worth making it ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T05:49:32.983", "Id": "33690", "Score": "4", "Tags": [ "c++", "interview-questions" ], "Title": "Classic programming interview questions" }
33690
<pre><code>var textarea = document.getElementById("textarea"), statusBar = document.getElementById("status-bar"); function updateStatusBar() { var text = textarea.value, chars = text.length, words = text.split(/\b\S+\b/g).length - 1, lines = text.split("\n").length; statusBar.v...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T06:24:14.053", "Id": "53954", "Score": "0", "body": "Well, looks good :) But it is better to add at least a few words on what you want to expect us to do..." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-1...
[ { "body": "<p>I will give it a try:</p>\n\n<ul>\n<li><p>These days I would recommend using <em>document.querySelector</em>, to write generic code which is well amenable to code re-factoring without introducing bugs.</p>\n\n<p>So either:</p>\n\n<pre><code>var textarea = document.querySelector(\"#my-textarea\")\...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T06:11:09.833", "Id": "33691", "Score": "1", "Tags": [ "javascript", "html", "dom", "statistics" ], "Title": "Calculate number of words and characters (/statistics) from an HTM...
33691
<p>I'm making a database program that reads from a file info on tennis players. Everything works, but is there a simpler way of doing this? Is there anything I can improve here? </p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;stdlib.h&gt; const int MAX_PLAYERS = 5; struct player { ...
[]
[ { "body": "<p>This part hardly makes sense to me:</p>\n\n<pre><code> player[idx].fullname[0] = malloc(20);\n player[idx].fullname[1] = malloc(20);\n player[idx].racketBrand = malloc(20);\n</code></pre>\n\n<p>If you are always allocating 20 bytes for your strings, why bothering with a dynamic allocation...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T07:40:22.573", "Id": "33695", "Score": "2", "Tags": [ "c" ], "Title": "Reading in different datatypes from a file" }
33695
<p>I wrote a small Java class with documentation that is going to be a part of a library I am writing. I learned Java as my first programming language from many different sources on the web, and therefore I have developed my own style without any direct criticism along the way. So I would like some feedback on the clas...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T13:53:37.247", "Id": "73072", "Score": "0", "body": "Variables `DEFAULT_ACCEPT_TEXT, DEFAULT_CANCEL_TEXT` follows java naming convention for constants." } ]
[ { "body": "<p>You ask specific questions and the answers you get to them will be opinionated and subjective... but ...</p>\n\n<ol>\n<li>Using constants for the Defaults is a good thing. This will make subsequent efforts like i18n (internationalization) easier as the values can be replaced with resource lookups ...
{ "AcceptedAnswerId": "33714", "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-11-02T10:18:55.320", "Id": "33699", "Score": "2", "Tags": [ "java", "swing", "library" ], "Title": "Swing UI confirmation dialog" }
33699
<p>I've written some code to solve <a href="http://projecteuler.net/problem=13" rel="nofollow">this problem</a>:</p> <blockquote> <p>Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.</p> </blockquote> <p>My solution functions correctly, but I'm having some trouble deciding how ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T14:21:20.267", "Id": "53969", "Score": "0", "body": "What was wrong with [`System.Numerics.BigInteger`](http://msdn.microsoft.com/en-us/library/system.numerics.biginteger.aspx)?" }, { "ContentLicense": "CC BY-SA 3.0", "C...
[ { "body": "<p><strike>IMHO returning <code>null</code> as error handling is a misconception.</strike>\nI was wrong there, it is ok, but you have to use it consequently!</p>\n\n<p>Because you may have to make the \"exception handling\" in the consumer class twice. \nOne time for <code>Exceptions</code> and anoth...
{ "AcceptedAnswerId": "36520", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T14:16:40.173", "Id": "33706", "Score": "1", "Tags": [ "c#", "project-euler" ], "Title": "Project Euler: Problem 13 - Large Sum" }
33706
<p>Might there be a simpler way to write this code? I'd like to learn to write code more efficiently.</p> <pre><code>def leaves_and_internals(self): """(BTNode) -&gt; ([object], [object]) Return a pair of lists: (list of all the items stored in the leaves of the subtree rooted at this node, list of all th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-03T22:16:48.103", "Id": "54050", "Score": "0", "body": "You don't seem to have taken the comments on [your previous question](http://codereview.stackexchange.com/q/33662/11728) into account." } ]
[ { "body": "<p>In the docstring, I would mention that the traversal is done using pre-order.</p>\n\n<p>I suggest handling leaf nodes as a base case and returning early.</p>\n\n<p>The left and right child nodes can be handled using common code.</p>\n\n<pre><code>def leaves_and_internals(self):\n \"\"\"(BTNode)...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T16:06:02.190", "Id": "33711", "Score": "0", "Tags": [ "python", "python-3.x", "tree", "depth-first-search" ], "Title": "How to enumerate the internal nodes and leaves of a tre...
33711
<p>In an old project I tinker with from time to time, I have a DOM-like structure in an MMF database. I'd like the nodes to <em>act</em> like they have some C++ typing based on the content, and accessor methods that go along with that. Yet in actuality, the data is independent of the type system in C++.</p> <p><em>T...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T14:44:59.697", "Id": "67499", "Score": "0", "body": "Would you mind including the other classes from Github into the text of this question? I'm having a hard time understanding it based on only your descriptions of these classes, wi...
[ { "body": "<p>At least right now, I have only a few comments, and they're about style, not the pattern you've devised. First, I'm rather bothered by the number and redundancy of access specifiers in your code. For example:</p>\n\n<pre><code>class FooPrivate final { \n\n friend class Foo;\n template&lt;cla...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T17:11:09.170", "Id": "33713", "Score": "10", "Tags": [ "c++", "design-patterns", "c++11" ], "Title": "Proxy/Facade Implementation Concept in C++11, impedance matching DB with clas...
33713
<p>I started learning OOP in JavaScript at school and I have to do my homework in OOP. It is a shopping list, one fills in a product and price and that is put into an array, the array its contents are put in a table in HTML. The list also has got delete buttons for every product, I have thought about using <code>this</...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T18:42:03.383", "Id": "53984", "Score": "3", "body": "You actually have a decent start right there with proper separation of concerns - actually better than most code I see in the web so for starters - good work. \n\nSome things I'd ...
[ { "body": "<p>The trick is linking a row to its item object and vice-versa, so both are removed/added in lockstep.</p>\n\n<p>There are <em>a lot</em> of ways of going about that, but given your original code, the following should be a pretty good way to go.</p>\n\n<p>I'd suggest using a closure when defining th...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T18:09:23.543", "Id": "33715", "Score": "3", "Tags": [ "javascript", "object-oriented", "html5" ], "Title": "Deleting a table row in JavaScript with OOP" }
33715
<p>I understand that if you don't know the trick, it's not easy create a solution with a complexity of \$O(N)\$. However, I would like to ask you how to solve this tricky question:</p> <blockquote> <p>You are given two non-empty zero-indexed arrays A and B consisting of N integers. Arrays A and B represent N voraci...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T19:53:29.130", "Id": "53990", "Score": "2", "body": "Would you mind summarizing what the problem is asking for and a brief explanation of your algorithm? That's way too much junk to try to figure out what's going on for ourselves." ...
[ { "body": "<pre><code>import java.util.Stack;\nclass Solution {\n /* A POD struct to aggregate fish that will be eaten or not eaten together */\n /* If the front fish is larger than any fish in the school (ie they are ordered) */\n /* and the front fish is eaten, the rest of the school will also defini...
{ "AcceptedAnswerId": "33722", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T19:26:17.780", "Id": "33716", "Score": "10", "Tags": [ "java", "algorithm", "interview-questions", "complexity", "programming-challenge" ], "Title": "Fish Food Chain of...
33716
<p>I've tried to write a configurable OOP-style FizzBuzz program in PHP for learning purposes. I hope everything is quite easy to understand.</p> <ol> <li>What do you think of the overall architecture?</li> <li>Are OOP principles kept well?</li> <li>What can be improved?</li> <li>How could error-handling and input-che...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-03T04:15:52.803", "Id": "54005", "Score": "1", "body": "Wow, this is even more over-engineered than the solution I proposed: [Fizz Buzz interview question](http://codereview.stackexchange.com/questions/6957/fizz-buzz-interview-question...
[ { "body": "<p>First of: I like the iterator approach. We use the FizzBuzz problem as part of our interview process and to this date nobody went down that route.</p>\n\n<p>The main points I have:</p>\n\n<ol>\n<li>Apparently your solution is quite over-engineered for a problem like this so I just assume you did i...
{ "AcceptedAnswerId": "33724", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T21:05:37.747", "Id": "33717", "Score": "7", "Tags": [ "php", "object-oriented", "fizzbuzz" ], "Title": "OOP-style FizzBuzz program in PHP" }
33717
<p>I've just created a script in Google Spreadsheet in order to archive some things. I have data from four countries. If something is marked done, then that line could be archived into that country's archive.</p> <p>My code is pretty ugly. Is there a clearer way to do this?</p> <pre><code>function CroatianArchive() ...
[]
[ { "body": "<p>You have a lot of repeated code when creating the <code>data</code> array. Note that the names of each cell value are ultimately irrelevant. That part could also be expressed as:</p>\n\n<pre><code>var columns = [\"A\" // office\n ,\"B\" // title\n ,\"C\" // imdbId\n ...
{ "AcceptedAnswerId": "33749", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T21:13:36.510", "Id": "33718", "Score": "0", "Tags": [ "google-apps-script", "google-sheets" ], "Title": "Country data archiving script using Google Spreadsheet" }
33718
<p>A "DOMNodeList grouper" (<code>groupList()</code> function below) is a function that envelopes a set of nodes into a tag. Example:</p> <p>INPUT</p> <pre><code> &lt;root&gt;&lt;b&gt;10&lt;/b&gt;&lt;a/&gt;&lt;a&gt;1&lt;/a&gt;&lt;b&gt;20&lt;/b&gt;&lt;a&gt;2&lt;/a&gt;&lt;/root&gt; </code></pre> <p>OUTPUT of <code>gr...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T22:49:16.380", "Id": "33719", "Score": "1", "Tags": [ "php", "dom" ], "Title": "DOMDocument grouping nodes, with clone, nodeClone, importNode, fragment... What the better way?" }
33719
<p>I have coded my own lightbox for the sake of my own custom needs because I want to be able to do this kind of thing myself and learn all the various things involved. I realize I could use a plugin, but that is not the point here.</p> <p>Last week I posted <a href="https://codereview.stackexchange.com/questions/3334...
[]
[ { "body": "<p>First of all, this may be a matter of opinion (my CTO totally disagrees on this, for instance), but I think <strong>splitting a long method / function into tiny ones with a single, simple purpose is the right way of doing things.</strong> </p>\n\n<p>Actually, this is also the position held by <a h...
{ "AcceptedAnswerId": "33754", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T23:41:17.317", "Id": "33720", "Score": "0", "Tags": [ "javascript", "jquery" ], "Title": "jQuery lightbox" }
33720
<p>How do I improve the below code, which takes input from a file and does some word analysis? I find a lot of redundancy in it. I want to know a better way of implementing it.</p> <pre><code>analysis = {} wordanalysis = {} found = True for line in sys.stdin: (n1,n2,n3,n4,n5,n6) = re.split("\t+",line.strip()) ...
[]
[ { "body": "<p>First, I see some odd behaviour that seems buggy, and if it is intended then it deserves a comment:</p>\n\n<ul>\n<li>Variables <code>n2</code>, <code>n3</code>, <code>n4</code>, and <code>n5</code> are never used. A comment with some sample lines of the expected input would be very helpful.</li>\n...
{ "AcceptedAnswerId": "33732", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-03T00:20:52.443", "Id": "33721", "Score": "3", "Tags": [ "python", "hash-map", "file" ], "Title": "Word analysis on input from a file" }
33721
<p>My project uses at least 100 helper classes like the below:</p> <pre><code>.pa5 {padding:5px} .pa10 {padding:10px} /* ... */ .pt5 {padding-top:5px} .pt10 {padding-top:10px} /* ... */ .pr5 {padding-right:5px} .pr10 {padding-right:10px} /* ... */ /* ... */ </code></pre> <p>It comes handy in some cases like <code>&l...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T16:58:10.533", "Id": "54122", "Score": "1", "body": "Related: http://stackoverflow.com/questions/4354921/css-is-there-a-limit-on-how-many-classes-an-html-can-have" } ]
[ { "body": "<p>The use of that many classes is a sign of incorrect CSS usage, but not because of performance. I doubt eight or ten classes on an element will be a noticeable performance issue.</p>\n\n<p>I've never heard of an explicit limit on the number of classes assigned to an element, but that may due to a ...
{ "AcceptedAnswerId": "33738", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-03T05:10:06.577", "Id": "33727", "Score": "2", "Tags": [ "performance", "html", "css" ], "Title": "Number of HTML classes for one element" }
33727
<p>I need help making this code run faster. I am using it to import a CSV file into Excel. It works, but it is very slow. The file is almost 20MB.</p> <pre><code>{Sub OpenTextFile() Dim FilePath As String Dim linitem As Variant FilePath = "filepath.txt" Open FilePath For Input As #1 row_number = 0 Do Line Input #1, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-03T05:59:44.560", "Id": "54011", "Score": "0", "body": "Have you tried setting `Application.ScreenUpdating` to `False` and then back to `True` once you're done with the file?" } ]
[ { "body": "<p>Not sure about the \"faster\" thing but you can replace the 31 lines of assignments with a 3 line for loop:</p>\n\n<pre><code>For r As Integer = 0 To 30\n ActiveCell.Offset(row_number, 30 - r).Value = LineItems(r)\nNext\n</code></pre>\n\n<p>Programming is about automating repetitive tasks, this...
{ "AcceptedAnswerId": "33730", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-03T05:25:19.763", "Id": "33728", "Score": "5", "Tags": [ "optimization", "vba", "csv", "excel" ], "Title": "Importing a CSV file into Excel" }
33728
<p>So I introduced myself to templates in C++11 and I have to say it's really confusing, but also very fascinating. I just need to get my head around what happens at compile time so that I don't wind up making one line of driver code amount to a megabyte of asm...</p> <p>Anyway, to teach myself I wrote a little conta...
[]
[ { "body": "<p>I might be misreading things so correct me if I'm wrong but Ithink your assignment operator can deadlock. A <code>lockbox</code> only makes sense when accessed from multiple threads, doesn't it (otherwise what would be the point)? </p>\n\n<ul>\n<li>Let's say we have two boxes <code>box1</code> an...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-03T09:39:44.497", "Id": "33731", "Score": "3", "Tags": [ "c++", "c++11", "template-meta-programming" ], "Title": "lockbox (a boost-like container)" }
33731
<p>I want to collect all fields which have given Modifier(s) of a class. I have written following pieces of codes:</p> <pre><code>/** * Method getFields * @author TapasB * @since 03-Nov-2013 - 2:03:17 pm * @version DAM 1.0 * @param instanceClass * @return */ @SuppressWarnings({ "unchecked", "rawtypes" }) public...
[]
[ { "body": "<p>I've played with your code and have a few broad observations....</p>\n\n<ol>\n<li>The code is neat enough and generally readable.</li>\n<li>JavaDocs are not complete - return values are not documented</li>\n<li>@since JavaDoc tag traditionally records a version number, not a date.</li>\n</ol>\n\n<...
{ "AcceptedAnswerId": "33741", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-03T11:30:03.430", "Id": "33733", "Score": "3", "Tags": [ "java", "reflection" ], "Title": "Collect all fields having given Modifier(s)" }
33733
<p>I've got a JavaScript object and I am not sure how to implement the last part: adding up all of the prices and putting that in the last row of the table. Besides this question, I would also like to ask you to look at the code and advice me if I can make the code slimmer, less lines of code.</p> <p>This is the code ...
[]
[ { "body": "<p>I usually make some simple helper functions to simplify and shorten the code building html. (As your programme gets more complicated you can expand these to suit your needs, or if you prefer, switch to a library like jquery.) In the version below I have also added a few lines to add a total row to...
{ "AcceptedAnswerId": "33736", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-03T11:39:42.247", "Id": "33734", "Score": "2", "Tags": [ "javascript", "object-oriented" ], "Title": "Object in JavaScript, superfluous?" }
33734
<p>I have the following SQL. I want to make that the SP should work under load. Means it should not have any synchronization issues.</p> <pre><code>ALTER PROCEDURE [dbo].[DeleteOldDeviceID] ( @OldDeviceID VARCHAR(500) ,@NewDeviceID VARCHAR(500) ) AS BEGIN SET NOCOUNT ON; DECLARE @TranCount INT; SET @TranCount...
[]
[ { "body": "<p>No, the Second Query won't Delete anything.</p>\n\n<p>In the statement prior to the <code>delete</code> you change the <strong>oldID</strong> to the <strong>newID</strong> so there aren't any records with the <strong>oldID</strong> in that table.</p>\n\n<hr>\n\n<p><strong>Difference between the tw...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-03T11:50:52.503", "Id": "33735", "Score": "2", "Tags": [ "sql", "sql-server" ], "Title": "Checking Synchronization issue in SQL?" }
33735
<p>I would like you to review my regex. It's suppose to recognize common URLs like:</p> <pre><code>http://www.google.com http://www.sub1.sub2.google.com https://www.google.com http://www.google.com/path1/path2 http://www.google.com/path1/path2/ http://www.google.com/path1/path2/a=b&amp;c=d http://www.google.com/path1...
[]
[ { "body": "<p>Your regex has many false positives (matches without a valid URL being there), and many false negativs (URLs you don't recognize). You should read the appropriate RFCs which contain relevant parts of the grammar.</p>\n\n<p>Here are some failure scenarios:</p>\n\n<ul>\n<li><p>⊖ You don't match sche...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-03T14:16:38.790", "Id": "33739", "Score": "8", "Tags": [ "javascript", "regex", "url" ], "Title": "What do you think of my regex for URL validation?" }
33739
<p>We want to check if a URL is down or not. But sometimes, the environment is down for maintenance for 3-4 hours and we don't want to keep sending emails during that time.</p> <p>I have written a shell script for performing a URL check and running it every 30 mins using a cronjob.</p> <p>The actual requirements are:...
[]
[ { "body": "<ul>\n<li><strong>Quoting:</strong> Be in the habit of <em>always</em> double-quoting your variables when you use them, e.g. <code>\"$url\"</code> instead of <code>$url</code>. Otherwise, nasty vulnerabilities could happen if a variable's value contains spaces or shell metacharacters. URLs, especia...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-03T15:56:15.440", "Id": "33742", "Score": "3", "Tags": [ "bash", "http", "url", "shell" ], "Title": "Send an email if a URL is down twice only" }
33742
<p>I want to build a robust and highly scalable client server system. Here what I have so far(an echo server as my base of implementation)</p> <p>My Server</p> <pre><code> private void startServer_Click(object sender, RoutedEventArgs e) { if (anyIP.IsChecked == true) { listener = ne...
[]
[ { "body": "<ol>\n<li>The general issue with your code is that your client and server implementations reside in your control's code-behind. It is always a good idea to separate business logic from UI.</li>\n<li><p>This is copy-paste:</p>\n\n<pre><code>if (anyIP.IsChecked == true)\n{\n listener = new TcpListen...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-03T17:44:43.493", "Id": "33748", "Score": "6", "Tags": [ "c#", "tcp", "async-await" ], "Title": "WPF async await TcpClient/TcpListener sample" }
33748
<p>I'm trying to clean up my JQuery code for my tabs. I have 3 different styles. How do I make the following shorter?</p> <pre><code>$(document).ready(function () { $('.tabs-style1 li').click(function () { var tab_id = $(this).attr('data-tab'); $('.tabs-style1 li').removeClass('current'); $...
[]
[ { "body": "<p>The visual style of your tabs is actually independent of their functionality. That is, they all <em>behave</em> as tabs, regardless of how they look.</p>\n\n<p>So, while you could make your code more generic by making the selector strings on the fly (<code>$(\".tab-content-\" + styleName)</code> e...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-03T18:53:03.243", "Id": "33751", "Score": "3", "Tags": [ "javascript", "jquery" ], "Title": "How do I shorten my JQuery tabs?" }
33751
<p>So I ran into an issue where a client sent me a sample file and the line breaks were not preserved when reading the file using PHP from linux. So I wrote up a little function that should hopefully fix the issue for all platforms.</p> <p>This is from a larger File class. The function names are pretty self explanator...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-03T21:20:10.920", "Id": "54045", "Score": "0", "body": "And what exactly are you after?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-03T23:04:43.517", "Id": "54056", "Score": "0", "body": "Wh...
[ { "body": "<p>This conversion can be done by simple apps from the <a href=\"http://waterlan.home.xs4all.nl/dos2unix.html#DOS2UNIX\" rel=\"nofollow noreferrer\">Dos2Unix package</a>.</p>\n<p>However, if you insist on writing your own converter, I'd suggest making fewer function calls. The function <a href=\"http...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-03T20:21:11.260", "Id": "33755", "Score": "1", "Tags": [ "php" ], "Title": "Fix line breaks, cross-platform" }
33755
<p>Please check this program that sorts an integer array. It doesn't look very efficient. Please tell me how to correct this.</p> <pre><code>int temp; for(int i=0;i&lt;nums.length-1;i++) { if(nums[i]&gt;nums[i+1])// if this is true, swap the value { temp=nums[i]; nums[i]=nums[i+1]; nu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-17T23:30:57.917", "Id": "54061", "Score": "0", "body": "Check the Program with nums={5,4,3,2,1}, does not work." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-17T23:35:15.077", "Id": "54062", "Scor...
[ { "body": "<p>Ok, you might not be aware, but you will be now, Arrays has its own sort method you can use if you want to. Look at the <a href=\"http://docs.oracle.com/javase/6/docs/api/java/util/Arrays.html\" rel=\"nofollow\">Arrays java documentation</a>!\nAnd in terms of efficiency I think java has that cover...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-17T23:23:37.537", "Id": "33761", "Score": "1", "Tags": [ "java", "optimization", "sorting" ], "Title": "Sorting integer array" }
33761
<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<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T00:32:51.593", "Id": "54072", "Score": "1", "body": "It would probably be easier to give each related input an identical class. Other than that, I would do `$input = $(this).closest('div').find('input')` at the beginning of your fun...
[ { "body": "<p>One minor improvement I can think of is to create a variable to hold the input element since the element is used twice like</p>\n\n<pre><code>$(document).on('click', '.--copy', function () {\n var $input = $(this).closest('div').find('input'), input_name = $input.attr('name').split('-')[0];\n ...
{ "AcceptedAnswerId": "33766", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T00:29:11.703", "Id": "33765", "Score": "0", "Tags": [ "javascript", "jquery" ], "Title": "Is there a simpler way of copying and pasting one inputs value into other input with the s...
33765
<p>This tag is for questions related to the loading, formatting, saving, compression, and display of data representing pictures. For visual presentations that are programmatically generated, use the related tag <a href="/questions/tagged/graphics" class="post-tag" title="show questions tagged &#39;graphics&#39;" rel="...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T00:47:44.623", "Id": "33768", "Score": "0", "Tags": null, "Title": null }
33768
This tag is for questions related to the loading, formatting, saving, compression, and display of data representing pictures.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T00:47:44.623", "Id": "33769", "Score": "0", "Tags": null, "Title": null }
33769
<p>For <em>professional</em> game development assistance, consult <a href="https://gamedev.stackexchange.com/">Game Development SE</a>.</p> <hr> <p>Some tags on Code Review for specific types of games include:</p> <ul> <li><a href="/questions/tagged/adventure-game" class="post-tag" title="show questions tagged &#39;...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T00:57:30.330", "Id": "33770", "Score": "0", "Tags": null, "Title": null }
33770
For questions requesting reviews of game development code.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T00:57:30.330", "Id": "33771", "Score": "0", "Tags": null, "Title": null }
33771
<p>In the application I'm building, the user is able to define 'types' where each 'type' has a set of 'attributes'.</p> <p>The user is able to create instances of products by defining a value for each attribute the product's type has.</p> <p>A pic of the schema: <img src="https://i.stack.imgur.com/pdQ4N.jpg" alt="A p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T17:30:16.877", "Id": "54132", "Score": "0", "body": "what Database Engine are you using?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T17:54:07.190", "Id": "54137", "Score": "0", "body":...
[ { "body": "<p>SQL allows you to join the same table multiple times, so what you need here is:</p>\n\n<pre><code>SELECT p.id FROM products AS p\nJOIN attributes_products AS ap1\n ON ap1.product_id = p.id AND ap1.attribute_id = 27 AND ap1.value = '...'\nJOIN attributes_products AS ap2\n ON ap2.product_id = p.id...
{ "AcceptedAnswerId": "33792", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T01:17:02.960", "Id": "33772", "Score": "6", "Tags": [ "optimization", "sql", "postgresql" ], "Title": "Help optimizing this query with multiple where exists" }
33772
<p>I usually use the static methods from this designed class in order to perform objects serializing of custom classes.</p> <p>Even though I'm getting good results, I wonder if this is the most appropriate way for it and if there are any improvements for it?</p> <pre><code>public class InputOuput { privat...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T05:08:20.943", "Id": "54084", "Score": "1", "body": "When you have variable names like \"m\", you should always think of renaming." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-13T16:27:01.937", "I...
[ { "body": "<p>All of your variables should be local, except for maybe the <code>FileChooser</code>.</p>\n\n<p>You swallow exceptions. Printing a stack trace is no substitution for proper exception handling. (By the way, logging should be done using <code>java.util.logging</code>. If you <em>must</em> print a...
{ "AcceptedAnswerId": "33778", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-17T17:24:26.263", "Id": "33773", "Score": "2", "Tags": [ "java", "serialization" ], "Title": "Is this the only or best method for classes serializing in Java?" }
33773
<p>I am constructing a selector on every radio button click. Since I am using the table repeatedly on every radio click, I cached it like:</p> <pre><code>var $t1 = $("#tableone"); </code></pre> <p>but inside the radio check event, I need to retrieve the selector to construct a string.</p> <p><strong>Approach 1:</str...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-19T03:20:17.570", "Id": "54076", "Score": "0", "body": "It's unclear to me what you're doing. FYI, `.selector` is deprecated, and may be removed from jQuery in the future." } ]
[ { "body": "<p>I don't think your approach 2 will do what you want. So I the first one would be better.</p>\n\n<p>It looks to me though that you are building another selector. Probably to find the child element. So I would recommend something like this:</p>\n\n<pre><code>var $c = $t1.find(\".\" + $(this).attr(\"...
{ "AcceptedAnswerId": "33775", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-19T03:15:06.263", "Id": "33774", "Score": "0", "Tags": [ "javascript", "jquery", "comparative-review" ], "Title": "Selector on every radio button click" }
33774
<p>I redid a Reversi game state class that is online. It follows the conventional rules of the board game. The game state connects to a command line interface now. I am unfamiliar with Android so comments related to that would be especially appreciated. Java related comments would be useful too.</p> <pre><code>/** * ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T23:13:12.690", "Id": "54177", "Score": "0", "body": "This code mixes the idea of a board with the idea of a game's rules. Without a lot of effort, you could refactor this code to apply to visually similar games (e.g., Go, Pente, Nin...
[ { "body": "<p>Your code looks <em>very</em> much like something one would write in C. On the one hand this is good, because you choose fairly efficient solutions. On the other hand, you throw away many powerful features of Java that would make your code simpler and safer. I'll just present a couple of spotlight...
{ "AcceptedAnswerId": "33809", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T06:39:05.480", "Id": "33780", "Score": "3", "Tags": [ "java", "game", "android" ], "Title": "Reversi game state in Android" }
33780
<p>I'm building an iOS app that uses web services extensively. I've built classes that handle the requests. However since there are a lot of web service request. I need to find out how to detect which web service to run, based on the action - registration, login, image upload, etc.</p> <p>This is just a small snippet ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T14:57:21.377", "Id": "54114", "Score": "1", "body": "If you're mapping Url to an invented numeric value 1:1 wouldn't it make sense to rather create a dictionary where the key was the value and the object the URL? Then you could basi...
[ { "body": "<p>Here's a quick and dirty example to illustrate the benefit of the dictionary setup:</p>\n\n<pre><code>- (NSDictionary *)webServiceIDsAndURLs{\n NSDictionary *sillyExampleDictionary = @{ @1 : [NSURL URLWithString:@\"http://www.noreagle.com\"],\n @2 : ...
{ "AcceptedAnswerId": "33805", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T13:45:02.830", "Id": "33793", "Score": "0", "Tags": [ "objective-c", "ios" ], "Title": "Handling web services in an iOS app" }
33793
<p>I have been studying data structures, and I'm new to this. Here is my code for the push and pop operations.</p> <ol> <li><p>I considered using a node=top, so that I can avoid O(n) operations for the push (i.e. finding the last node every time).</p></li> <li><p>I can't seem to find a better implementation for the p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T17:06:16.663", "Id": "54128", "Score": "1", "body": "The `free()` should go before the `return`, otherwise the former will not be called." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T17:42:27.383",...
[ { "body": "<p>After looking at this, I'm not sure you should be freeing <code>cur</code> since you are freeing it before it is returned. You should always see <code>NULL</code>, then.</p>\n\n<p>As for this static implementation, I'm not sure you're even doing this correctly. From the code, it looks like you'r...
{ "AcceptedAnswerId": "33826", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T15:11:47.073", "Id": "33794", "Score": "6", "Tags": [ "c", "beginner", "linked-list", "stack" ], "Title": "Reviewing my implementation of a stack using linked list" }
33794
<p>Let a,b,c be a boolean value. I need to print all values of expression a &amp;&amp; b &amp;&amp; c. I'm writing the class</p> <pre><code>public class BooleanTriple{ private boolean a,b,c; public BooleanTriple(boolean a, boolean b, boolean c){ this.a =a; this.b=b; this.c=c;} /** *Increments the valu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T18:37:20.767", "Id": "54148", "Score": "0", "body": "can't understand what are you trying to achieve or furthermore what is the main application of your class and methods?" }, { "ContentLicense": "CC BY-SA 3.0", "Creatio...
[ { "body": "<p>if I quite understand your problem, to do a proper <code>incr()</code> method I would do so :</p>\n\n<pre><code>public class BooleanTriple {\n private boolean a,b,c;\n private int i;\n public BooleanTriple(boolean a, boolean b, boolean c){\n this.a =a; this.b=b; this.c=c;\n ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T16:02:15.130", "Id": "33797", "Score": "0", "Tags": [ "java" ], "Title": "Review implementation of boolean triple" }
33797
<p>I need to search some data encoded by a Huffman tree, but not by simply walking the tree: I need test combinations of the data for a property and continue searching based on whether the test is positive or not. To this end, I've also returned the intermediate steps of the Huffman algorithm> </p> <p>Here is the code...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-06T11:31:34.947", "Id": "54423", "Score": "0", "body": "I don't understand what you are trying to achieve here. Can you explain the problem you are trying to solve?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2...
[ { "body": "<p>I've change my data structure, so that the Huffman encoding procedure defines the combinations I need to test: </p>\n\n<pre><code>class Node(object):\n left = None\n right = None\n weight = None\n data = None\n code = ''\n length = len(code)\n\n def __init__(self, d, w, c):\n ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T18:44:55.270", "Id": "33802", "Score": "1", "Tags": [ "python", "algorithm" ], "Title": "Combinatorial searching of Huffman trees" }
33802
<p>Since the original post, I have explored further regarding this pattern. In an effort to fix one self-percieved flaw <em>(the lack of ability of prototype methods to access private object members)</em>, I have revised this Class pattern. As no one has responded regarding the pattern, I am offering a bounty. </p> <p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T21:48:59.310", "Id": "54170", "Score": "0", "body": "Where is `value` and `value2` set ? Also, this code does not work you are returning ClassName while you are setting it causing the obvious `ReferenceError: ClassName is not define...
[ { "body": "<p>It would be great if your code would actually instantiate a Class / object and maybe execute a function or get a value.</p>\n\n<p>You require <code>new</code> according to line 29, you should probably not return undefined, but either throw an exception or create the object yourself.</p>\n\n<p>All ...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-04T20:53:31.653", "Id": "33807", "Score": "4", "Tags": [ "javascript", "design-patterns", "classes" ], "Title": "Issues with this pattern to restrict access to private members?" }
33807
<p>If I have a <code>Person</code> class that outlines the properties of a person and one of <code>People</code> that just contains a <code>List&lt;Person&gt;</code> like so:</p> <pre><code>public class Person { public Person(){} public int personID {get;set;} public string name {get;set;} public strin...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T00:52:06.323", "Id": "54183", "Score": "1", "body": "I'm not seeing the point of those empty public constructors..." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T01:47:48.470", "Id": "54185", ...
[ { "body": "<p>Very few things in life are free. C# default constructors are one of those, the compiler generates one automatically for you if your class doesn't explicitly have one! So unless you have another constructor (with parameters) and you also <em>need</em> a parameterless one, putting it in is just clu...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T00:08:36.013", "Id": "33810", "Score": "4", "Tags": [ "c#", "object-oriented", "classes", "database", "beginner" ], "Title": "Implementation of OOP for retrieving list of ...
33810
<p>I'm a newbie trying to teach myself Python. Could somebody tell me if there is a better way to write this? I am also curious as to whether or not there is anything I should not do. This code does work, but some indentation may have been lost when I pasted it.</p> <pre><code>import random def game(): yes = ['...
[]
[ { "body": "<p>A few observations:</p>\n\n<ul>\n<li>In place of the while loop with you managing the <code>numAttempts</code> index, why not use a <code>for</code> loop with the <code>in</code> keyword? i.e. <code>for numAttempts in range(3):</code></li>\n<li>Note that with the above, you can still use your <co...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-05T00:35:58.737", "Id": "33811", "Score": "2", "Tags": [ "python", "beginner", "game", "python-3.x", "random" ], "Title": "How to make this random number game better?" }
33811