body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>Is there a way to make a threading/async post with a web reference not slow down the whole website just because the web reference takes a long time to return a response? </p> <p>I have a send email function that gets posted async with a threading system that basically looks like this. This whole .cs file is called ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T09:17:02.347", "Id": "103697", "Score": "0", "body": "\"After this we run SendMailAsyc function. This function itself is kinda too big to be posted here.\" Red flag for me. This screams \"my function is very big and ugly and I know ...
[ { "body": "<p>There's not enough information here to tell you what's wrong, but I'll tell you what I would do differently regardless.</p>\n\n<p>Manually spawning threads is something you should avoid doing, <em>especially</em> if there's a chance that thread is just going to wait on a lock. As the remote servi...
{ "AcceptedAnswerId": null, "CommentCount": "14", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T09:12:16.077", "Id": "57908", "Score": "1", "Tags": [ "c#", ".net", "multithreading", "asynchronous", "web-services" ], "Title": "Async function with slow web reference(w...
57908
<p>I finally set up my logging infrastructure to work as desired, however I feel like I had to do quite a lot things just to fulfill a few requirements. Now I'm worried if my approach has major drawbacks, e.g. in performance or stability, so I need your help!</p> <p><strong>Requirements</strong></p> <ul> <li>Logging ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T11:52:51.303", "Id": "103721", "Score": "2", "body": "I don't think you should inject logger as dependency, because it will increase parameters in constructor and it will look ugly. so rather create a singleton instance of logger an...
[ { "body": "<p>Using extension methods and the interface makes me think you should use an abstract class to encapsulate the logging framework you use. I put the <code>Write</code> method and the overloads <code>protected</code> but you could put it <code>public</code> back if you need. Also, as you'll see it, I ...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T09:16:00.077", "Id": "57909", "Score": "12", "Tags": [ "c#", "performance", "design-patterns", "logging", "ddd" ], "Title": "Logging strategy setup" }
57909
<p>I'm doing some exercises in Python and this one is about using the Luhn-algorithm to calculate the checksum digit in Swedish personal identification numbers.</p> <p>The description is the same as <a href="https://codereview.stackexchange.com/questions/57846/calculating-luhn-algorithm-checksum-digit">this question</...
[]
[ { "body": "<p>Some comments:</p>\n\n<ul>\n<li>Variable names could be improved a little bit. For example, I think <code>nbr_string</code> could be better as <code>swedish_id</code></li>\n<li>Please add a docstring (<a href=\"http://legacy.python.org/dev/peps/pep-0257/\" rel=\"nofollow\">PEP257</a>)</li>\n<li><c...
{ "AcceptedAnswerId": "57919", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T12:18:57.747", "Id": "57916", "Score": "13", "Tags": [ "python", "beginner", "checksum" ], "Title": "Calculating the checksum digit with the Luhn-algorithm" }
57916
<p><strong>The problem:</strong></p> <p>Treat an array as if it is circular; out-of-bounds indices "wrap around" the array to become in-bounds.</p> <p><strong>Current solution:</strong></p> <pre><code>// roudedArray.cpp #include &lt;iostream&gt; template &lt;typename T, int N&gt; int wrapAroundArray(int i, T(&amp;T...
[]
[ { "body": "<p>The arithmetic solution to this is relatively simple as we're talking modulo here:</p>\n\n<pre><code>return i % N;\n</code></pre>\n\n<p>This should produce the same results for your adjusted index.</p>\n\n<p>When I ran a few calculations on the modulo operator through WolframAlpha, I got the follo...
{ "AcceptedAnswerId": "57924", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T13:20:06.690", "Id": "57923", "Score": "19", "Tags": [ "c++", "array", "circular-list" ], "Title": "Index into array as if it is circular" }
57923
<p>I recently wanted to write a regression testing script that produces a report that looks like this:</p> <pre class="lang-none prettyprint-override"><code>Testing 'nmap -n -Pn -sT localhost' 0.0670049190521 =&gt; Trunk time 0.098452091217 =&gt; nsock time The results are consistent. Testing 'nmap -n -Pn -sT scanm...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T14:12:00.923", "Id": "57925", "Score": "2", "Tags": [ "python", "networking", "email", "child-process" ], "Title": "\"Transparently\" converting the output to an e-mail messag...
57925
<p>This code simply sends a <code>HttpRequest</code> message and, if it comes back Unauthorized, gets a new login and tries again.</p> <p>This code is meant to deal with the moment a JSON Web Token goes out of date. In this system the client is notified of this by having its request become Unauthorized, it then picks ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-08-02T21:25:07.373", "Id": "105854", "Score": "0", "body": "BTW, the code you post here should be your real code (no \"foo\"s or \"some stuff\"s), because we want to be able to review all aspects of your code. I think it doesn't matter mu...
[ { "body": "<blockquote>\n <p>How unpleasant is my use of delegates and what lengths should I go to change this code, if any?</p>\n</blockquote>\n\n<p>If you want the caller to provide some small piece of code, then a delegate is exactly the right way to do it, it's not unpleasant at all.</p>\n\n<p>But looking ...
{ "AcceptedAnswerId": "58861", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T14:33:27.330", "Id": "57927", "Score": "3", "Tags": [ "c#", "http", "delegates" ], "Title": "Sending a HttpRequest Message, and retrying in case of unauthorised" }
57927
<p>I have a string like <code>str = " 4+ 6 * 30";</code>. I have to perform an arithmetic operation on this using C#; My solution to this problem is as follows.</p> <pre><code> string temp = " 4 + 6 * 5"; int firstNaum = 0; int secondNum = 0; int ThirdNum = 0; int finalResults = 0; //Spliti...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T16:17:23.873", "Id": "103802", "Score": "6", "body": "The process that you're using is very tightly coupled to your example, and not at all extensible to other input strings." } ]
[ { "body": "<p>Can you clarify what you want us to feed back on.</p>\n\n<p>My thoughts are:</p>\n\n<ol>\n<li>Use a library that already performs infix mathematical parsing because the process is relatively complex but has been \"solved\" many times before.</li>\n<li>Your code assumes a very strict order in the t...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T14:59:44.790", "Id": "57928", "Score": "1", "Tags": [ "c#", "math-expression-eval" ], "Title": "Arithmetic operation from string" }
57928
<p>I am rewriting a VB.NET application in C#. This code was originally done in 50 lines and I am trying to clean it up. As you can see I have gotten it down to 10 but I still feel its ugly. I want to convert the call and assignments into one Linq statement or method chain. See Comments:</p> <pre><code>public void Upda...
[]
[ { "body": "<pre><code>var propertiesToBeUpdated = properties.Select(p =&gt; {\n var prop = _context.MyObjectProperties.FirstOrDefault(x =&gt; x.Key == output.Key);\n\n return prop == null ? null :\n new MyObjectProperties {\n Key = prop.propertiesKey,\n Name = prop.propertiesN...
{ "AcceptedAnswerId": "57940", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T16:19:31.490", "Id": "57938", "Score": "3", "Tags": [ "c#", "linq", "properties" ], "Title": "Updating properties and states" }
57938
<blockquote> <p><strong>Question</strong></p> <p>Your algorithms have become so good at predicting the market that you now know what the share price of Wooden Orange Toothpicks Inc. (WOT) will be for the next \$N\$ days.</p> <p>Each day, you can either buy one share of WOT, sell any number of shares o...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T23:57:25.760", "Id": "103928", "Score": "0", "body": "There is a well known way to do this O(N) time with dynamic if you could only hold on to 1 share at a time. However, I do not think that it is possible in this case (with as man...
[ { "body": "<p>The trick to getting this problem in O(n) is some clever pre-processing.</p>\n\n<h1>Examples</h1>\n\n<p>Let's take 2 trials:</p>\n\n<p>Trial 1: 1, 2, 3, 4, 5</p>\n\n<p>Trail 2: 5, 4, 3, 2, 1</p>\n\n<p>Obviously best case in Trial 1 is to buy for 4 days and sell on the 5th, for profit of 10.\nIn Tr...
{ "AcceptedAnswerId": "58009", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T17:27:25.350", "Id": "57943", "Score": "4", "Tags": [ "java", "algorithm", "functional-programming", "programming-challenge", "dynamic-programming" ], "Title": "Determi...
57943
<p>In my publications with meteor.js, I find myself repeating the same style of code and would like a cleaner approach. For example:</p> <p>I have a <code>users</code> collection that has the <strong>distinguishing</strong> field <code>school</code>, an identifier that tells me by which school, I should filter what in...
[]
[ { "body": "<p>I can't see how you can filter field B (school) that relies on field A (user) when there's no information about field A.</p>\n\n<p>What is the purpose of showing schools to anonymous users?</p>\n\n<p>If we take the scenario of displaying information to anonymous users without any related functiona...
{ "AcceptedAnswerId": "77252", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T18:15:10.103", "Id": "57947", "Score": "3", "Tags": [ "javascript", "meteor" ], "Title": "Filter by a distinguishing field when making publications using meteor" }
57947
<p>I'm writing a tool to create shortcut menus for an application that I maintain built on the Access runtime. I compile this app into an *.accde file, so much to my chagrin, all right click menus are disabled. </p> <p>After some research, I've been able to develop this tool to add the menus to the database. This code...
[]
[ { "body": "<p>As you already noticed, all the <code>CreateSomething</code> methods have the same repeating pattern. We can extract this pattern and encapsulate it in a method for reuse :</p>\n\n<pre><code>Private Sub CreateCommandBar(name As String, ParamArray buttonIDs() As Variant)\n Dim menu As Office.Com...
{ "AcceptedAnswerId": "57967", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T18:18:38.317", "Id": "57948", "Score": "12", "Tags": [ "vba", "ms-access" ], "Title": "Creating ShortCut (RightClick) Menus in Access" }
57948
<p>I have written the below code to get the unique factors. Please offer suggestions for better results.</p> <pre><code>#Python program to print out all ways to multiply smaller integers #that equal the original number, without repeating sets of factors def print_factors_list(dividend, factorstring, predivisor): "...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T19:07:57.350", "Id": "103842", "Score": "0", "body": "Your docstring is incorrectly indented; please fix." } ]
[ { "body": "<p>An alternative (and probably more efficient) approach would be to derive all prime factors (hint: you could use <code>divmod</code>) and then create each of the possible factorings from that (hint: you could use <code>itertools</code> <code>combinations</code>).</p>\n\n<p>Some notes:</p>\n\n<ol>\n...
{ "AcceptedAnswerId": "57959", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T18:40:08.223", "Id": "57950", "Score": "4", "Tags": [ "python", "optimization", "algorithm", "python-2.x" ], "Title": "Getting the unique factors of a number recursively" }
57950
<p>I've been learning about language theory and parsing, and decided to write my first parser: a LL(1) recursive descent parser. But actually, it does a little more than just expressions; it can also parse variable definitions with the "define" keyword. It parses into an AST and then the other portion of the program ev...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T18:24:29.827", "Id": "104090", "Score": "2", "body": "Is it intentional that you skip the `'k'` in `get_token()`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T18:47:37.840", "Id": "104094", ...
[ { "body": "<p>You've posted a lot of code, so this review focuses primarily on <code>lexer.h</code>, which you've indicated may have the most to improve.</p>\n\n<h1>Code Style</h1>\n\n<h2>Use include guards</h2>\n\n<p><a href=\"http://en.wikipedia.org/wiki/Include_guard\" rel=\"nofollow noreferrer\">Include gua...
{ "AcceptedAnswerId": "58084", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T18:42:48.467", "Id": "57951", "Score": "8", "Tags": [ "c++", "parsing", "boost", "math-expression-eval" ], "Title": "Predictive recursive descent parser for math expression...
57951
<p>I'm working on solving a problem involving finding the largest of a series of numbers being XORed.</p> <p><a href="https://www.hackerrank.com/challenges/xor-key">This</a> is the actual problem:</p> <blockquote> <p>Xorq has invented an encryption algorithm which uses bitwise XOR operations extensively. This enc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T19:17:06.490", "Id": "103845", "Score": "0", "body": "I get a little lost with these. Are these values right for the sample test case? N=15, Q=8, x<sub>1</sub> to x<sub>15</sub> are 1 to 15. There are Q (8) lines after the x valu...
[ { "body": "<p>Putting all variables of the same type onto a single line can be bad for readability and maintenance:</p>\n\n<blockquote>\n<pre><code>unsigned int T,N,Q,i,a,p,q,count,max,n[100000],res[100000];\n</code></pre>\n</blockquote>\n\n<p>Since the single-character variables are similar, they can still be ...
{ "AcceptedAnswerId": "57978", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T18:49:32.413", "Id": "57954", "Score": "12", "Tags": [ "optimization", "performance", "c", "programming-challenge", "bitwise" ], "Title": "Finding the largest of a seri...
57954
<p>Inspired by the <a href="https://codereview.stackexchange.com/questions/57905/xml-format-for-game-data" title="XML Format for game data">XML format for game data</a> question, I was interested to see how my system works for storing game data. My system works a lot like <em>Halo</em>, where there are a variety of gam...
[]
[ { "body": "<h1><strong>SQL</strong></h1>\n\n<p>I'm really not sure what you would gain from storing in SQL honestly. But I guess it would be worth a try. It would likely result in either a few very wide tables, or lots of very small tables that you would have to join. I'll provide a brief example below, please ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T19:06:49.393", "Id": "57956", "Score": "5", "Tags": [ "java", "game", "sql", "xml" ], "Title": "Unifying XML formatting with inheritable parsing" }
57956
<p>This PHP (5.3) code is intended to take an array and a key as inputs, and return an array of the values paired with that key‡</p> <pre><code>function valuelist($array, $array_column) { $return = array(); foreach($array AS $row){ $return[]=$row[$array_column]; }; return $return; }; </code></p...
[]
[ { "body": "<p>I was able to play around with your requirements, and I think I got a solution.</p>\n\n<p>Here is what I did to profile your code.</p>\n\n<p>I set up the data array with:</p>\n\n<pre><code>$new = array(\n array('a' =&gt; 1,\n 'b' =&gt; 2),\n array('a' =&gt; 3,\n 'b' =&gt; 4),\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T19:10:41.810", "Id": "57958", "Score": "3", "Tags": [ "php", "performance", "array" ], "Title": "Returns values for a specific array and key" }
57958
<p>There's this website I'm working on that needs to swap images every few seconds, like a slideshow or image fade swap in a way, except that you need to target 5 IMG tag elements. I was able to make a weak version of that function. But i'm sure this could be done even better, considering that I still have a few bugs t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T20:30:46.073", "Id": "103872", "Score": "0", "body": "An idea: instead of staggering the delay, add the index as a parameter. When one finishes, set a timeout for the next index." }, { "ContentLicense": "CC BY-SA 3.0", "...
[ { "body": "<ol>\n<li><p>Functions should be camelCase unless they're constructors. So <code>fadeChange</code> (also, <code>fadeChange</code> is a little vague - what's getting faded? What's being changed?)</p></li>\n<li><p>You probably don't need global variables of any kind. Closures should be fine.</p></li>\n...
{ "AcceptedAnswerId": "57980", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T19:53:03.883", "Id": "57963", "Score": "3", "Tags": [ "javascript", "jquery", "recursion", "image" ], "Title": "Optimization of recursive jQuery images swap function" }
57963
<p>When I was about 13 or 14 years old, I was a little interested in cryptography (which is, after all, an interesting field). I learnt quite a lot since that time (it has been about 8 years since then), but I'm still very far away from considering myself an expert in cryptography.</p> <p>Whatever, when I was at that ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T21:05:49.267", "Id": "103879", "Score": "1", "body": "I wonder whether this would belong on [security.se] instead..." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T21:08:18.113", "Id": "103881", ...
[ { "body": "<p>Just some quick thoughts (I can't even read Perl nor do I know much about crypto).</p>\n\n<ol>\n<li>The last module could lead to problems in decrypting. I understand that you want your cypter text be easily viewable but what if your $new_number before the module happend to be bigger len(alphabet)...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T21:03:59.070", "Id": "57969", "Score": "6", "Tags": [ "perl", "cryptography" ], "Title": "How easy is it to crack this encryption algorithm?" }
57969
<p>I have a type representing an immutable order which contains immutable order lines that belong to it. I want to use path-dependent types for this. Obviously you cannot instantiate a path-dependent type without having the value it depends on, so I decided to take a function from the constructor. Since <code>(order: O...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T01:57:12.837", "Id": "103941", "Score": "1", "body": "I'm not sure why you absolutely want to use path-dependent types. Wouldn't defining `OrderLine` in a companion `object Order` be clean enough? It would be a more common approac...
[ { "body": "<p>Taking a shower can do wonders. :)</p>\n\n<p>You can take tuples instead and convert those to <code>this.OrderLine</code>s in the constructor.</p>\n\n<pre><code>final class Order private() {\n case class OrderLine(x: Int, y: Double) { }\n\n def this(rawOrderLines: Seq[(Int, Double)]) = {\n th...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T21:13:03.210", "Id": "57972", "Score": "2", "Tags": [ "scala", "type-safety" ], "Title": "Aggregating values of a path-dependent type" }
57972
<p>I created a k-ary tree in C to be used as an easy and efficient way to organize "UML-like" data in embedded devices. The left node is at the lower logical level (a child) while the right node is at the same logical level but represent a different data or option (sibling).</p> <p>Since it is to be used in embedded d...
[]
[ { "body": "<blockquote>\n <p>...it [the program] is to be used in embedded devices with possibly very low available\n RAM</p>\n</blockquote>\n\n<p>In that case, we should be getting rid of everything that isn't of absolute necessity, and adding some things that are.</p>\n\n<hr>\n\n<p>Overall:</p>\n\n<ul>\n<li...
{ "AcceptedAnswerId": "57984", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T21:14:46.690", "Id": "57973", "Score": "9", "Tags": [ "c", "memory-management", "tree", "embedded" ], "Title": "Hierarchical k-ary tree in C without relying on RAM" }
57973
<p>Here is a Bitcoin address validator I am looking to have reviewed in C. Normally I would have the <code>enum</code> and function prototypes declared in a header file, but I decided for the purpose of this question to integrate them into one for easy copying and compilation.</p> <pre><code>/** * @file bitcoin.c *...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-28T13:32:50.913", "Id": "104540", "Score": "0", "body": "there is a [tag:c99] and a [tag:c11] I didn't edit either in because I don't know which one this is I was thinking that I just put in [tag:c99] because it sounds like that is the...
[ { "body": "<ul>\n<li><p>It would be nice to include a link to an authoritative reference. Until then, no comment on the algorithm compliance is possible.</p></li>\n<li><p>Instead of <code>switch</code> I'd rather have a table of strings indexed by <code>BitcoinAddressState</code> values.</p></li>\n<li><p>In C, ...
{ "AcceptedAnswerId": "57986", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T21:21:50.740", "Id": "57974", "Score": "12", "Tags": [ "c", "validation", "openssl", "bitcoin" ], "Title": "Bitcoin address validator in C" }
57974
<p>I'm using VS 2013/EF 6/WEB API 2.</p> <p>This application of mine which is working on will eventually grow to be big project and I'm in the very beginning stage and need your expertise to make it simple as possible without over-complication.</p> <p>My goal is to make it KISS solution and I'm trying my best. After...
[]
[ { "body": "<h3>Entity Framework already implements UoW+Repository for you.</h3>\n<p>To KISS, your code would simply &quot;wrap&quot; the <code>DbContext</code> with an interface, as explained <a href=\"https://codereview.stackexchange.com/a/57432/23788\">here</a>, <a href=\"https://codereview.stackexchange.com/...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T21:22:34.060", "Id": "57975", "Score": "2", "Tags": [ "c#", "design-patterns", "repository" ], "Title": "Is this Repository/UOW design workable?" }
57975
<h3>Use Case</h3> <p><code>_.pick</code> creates a shallow clone of an object given a predicate that identifies which keys to keep. <code>pickDeep</code> would perform a deep clone of the object and would "pick" up all nested objects containing the given keys. All containers containing the nested objects would remain ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T18:25:04.300", "Id": "104091", "Score": "0", "body": "And what is your question? I haven't tested, but I think it does, what it should. On first sight, I find nothing to complain about. So I am fine with it :]" }, { "Content...
[ { "body": "<p>I haven't worked with underscore yet (gasp), BUT, I'd like to give what I can here in case you get no better answer soon!</p>\n\n<h2>Readability</h2>\n\n<p>Your formatting is nearly flawless. However, <a href=\"http://javascript.crockford.com/code.html\" rel=\"nofollow noreferrer\">Douglas Crockfo...
{ "AcceptedAnswerId": "58279", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T21:32:21.437", "Id": "57976", "Score": "20", "Tags": [ "javascript", "performance", "underscore.js", "lodash.js" ], "Title": "Deep pick using lodash/underscore" }
57976
<p>I'm rewriting a simple app using HTML/CSS/JavaScript that creates animations with images using intervals, and there's a bunch of buttons that controls these animations.</p> <p>It's scaling and becoming really messed up, with logic mixed with DOM manipulations via jQuery all through one JavaScript script file.</p> ...
[]
[ { "body": "<p>The last piece is: Whoever is calling that <code>callback:</code> function itself may be passing params to it, which need to be repackaged into a genuine array from their source in the (implementation deficient) <code>arguments</code> array, before they can be passed to <code>method</code> via <co...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T21:35:06.173", "Id": "57977", "Score": "2", "Tags": [ "javascript", "design-patterns", "callback", "revealing-module-pattern" ], "Title": "Module pattern callback implementati...
57977
<p>Expression trees are the bread and butter of functional programming but when it comes to adding additional information to an established tree it can be difficult to incorporate such changes without breaking the existing interface. I have attempted to solve the problem with this example which demonstrates two differe...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-11-05T17:13:02.127", "Id": "341166", "Score": "0", "body": "It's been three years. Do you want to review your own code?" } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T22:16:23.407", "Id": "57985", "Score": "3", "Tags": [ "haskell", "functional-programming" ], "Title": "A solution to the AST Typing Problem" }
57985
A file structure is a way of organizing files in a fashion that allows them to be queried and/or updated efficiently. **Please do not use this tag to ask about project structure.**
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-24T23:02:15.867", "Id": "57991", "Score": "0", "Tags": null, "Title": null }
57991
<p>The code is generic, trying to support both STL iterators and normal C pointer arithmetic.</p> <pre><code>#include &lt;cstdio&gt; #include &lt;vector&gt; template&lt;typename I&gt; void quick_sort_step(const I left, const I right) { auto pivot = *(left + (right - left) / 2); auto l = left; auto r = rig...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T18:05:31.043", "Id": "104083", "Score": "1", "body": "Currently it fails to compile. Because it can not see `::sort()` before it is used. Use forward declaration or move `quick_sort()`." }, { "ContentLicense": "CC BY-SA 3.0"...
[ { "body": "<p>You need to somehow check or restrict your templates to iterators only. </p>\n\n<p>The way you have it written, I can perform the following: </p>\n\n<pre><code>int main(void)\n{\n const char a = '5';\n const char b = '$';\n sort(a,b);\n\n const int five = 5;\n const int zero = 0;\n sort(fi...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T00:27:55.057", "Id": "57996", "Score": "-1", "Tags": [ "c++", "algorithm", "c++11", "quick-sort" ], "Title": "STL implementation of quicksort" }
57996
<p>OpenSSL is an open source software toolkit that implements the SSL/TLS protocol, as well as a general cryptographic library.</p> <p>OpenSSL is maintained by the <a href="http://openssl.org/" rel="nofollow">OpenSSL Project</a>, which hosts several project <a href="http://openssl.org/support/community.html" rel="nofo...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T01:19:15.660", "Id": "57998", "Score": "0", "Tags": null, "Title": null }
57998
OpenSSL is an open source software toolkit that implements the SSL/TLS protocol, as well as a general cryptographic library.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T01:19:15.660", "Id": "57999", "Score": "0", "Tags": null, "Title": null }
57999
<p>I just started development on a <a href="https://github.com/hamsham/BigNum" rel="nofollow">new bignum library</a> that can operate on numbers of any arbitrary base (up to 2<sup>32</sup>). I want to get a good idea of where I can improve before taking things any further. Right now, the library supports basic addition...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T04:00:26.243", "Id": "103953", "Score": "0", "body": "Is this all the code there is to review?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T04:03:20.647", "Id": "103954", "Score": "0", ...
[ { "body": "<p>Since you are using C++, kill the macros. Macros are evil and dangerous.</p>\n\n<p>For example: </p>\n\n<pre><code> CREATE_BN_TEST(\"Apple\")\n struct Node\n {\n int value;\n struct Node * next;\n };\n CREATE_BN_TEST(Node)\n CREATE_BN_TEST(std);\n CREATE_BN_TEST(:::);\n</code></pr...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T03:54:34.327", "Id": "58003", "Score": "1", "Tags": [ "c++", "c++11", "api", "library", "integer" ], "Title": "Bignum library with arbitrary bases" }
58003
<p>I found myself in the need of a function to pairwise an array 2D so I created one:</p> <pre><code>public static IEnumerable&lt;TOut&gt; Pairwise&lt;TIn, TOut&gt;(this TIn[,] source ,Func&lt;TIn, TIn, TOut&gt; selector) { Point[] deltas = { new Point(-1, -1), new Point(0, -1), new Point(1, -1), ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T05:32:52.900", "Id": "103965", "Score": "0", "body": "To clarify, for each element `x` in the 2D-array, and for each neighbour `y` of `x`, you want the result of `f(x, y)` (and you're assuming that `f(x, y) = f(y, x)`, since you say...
[ { "body": "<p>Let's think about this geometrically.</p>\n\n<p>Since we're treating a pair of neighbours <code>(x, y)</code> as equivalent to <code>(y, x)</code>, we can think of our neighbour-relation as being directed. That is, from up/down we can pick one (let's pick down); similarly for left/right, up-left/d...
{ "AcceptedAnswerId": "58010", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T04:39:08.917", "Id": "58005", "Score": "5", "Tags": [ "c#", "performance", "array" ], "Title": "Array 2D pairwise function" }
58005
<p>I'm fairly new to Clojure and I struggled a bit coming up with a nice Clojure-y solution for implementing an algorithm for one of my applications. The real issue I'm trying to solve would require a large writeup in order to understand what it's about, so I've come up with a contrived problem statement that's much ea...
[]
[ { "body": "<p>I figured out a faster, more functional programming-oriented algorithm for this problem -- see below. Besides that, your code overall looks idiomatic and was easy for me to understand, so I have no real criticisms in that area.</p>\n\n<h2>zipmap</h2>\n\n<p><a href=\"http://clojuredocs.org/clojure_...
{ "AcceptedAnswerId": "58073", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T05:31:41.343", "Id": "58007", "Score": "5", "Tags": [ "beginner", "recursion", "functional-programming", "clojure" ], "Title": "Algorithm to Iterate All Possible Strings in...
58007
<p>I'm trying to save a webpage as text file, using the following function:</p> <pre><code>def html_to_txt(): import urllib.request url = str(input('Enter URL: ')) page = urllib.request.urlopen(url) with open(str(input('Enter filename: ')), "w") as f: for x in page: f.write(st...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T12:45:02.567", "Id": "104015", "Score": "0", "body": "I'm afraid this question does not match what this site is about. Code Review is about improving the cleanliness of existing, working code. Code Review is not the site to ask for ...
[ { "body": "<p>As a review, the code needs some work with regard separation of concerns. A single function shouldn't get user input, get a URL and write to a file. If you try to write unit tests for it, you'll quickly see it's better to split the functionality.</p>\n\n<p>With regard to the problem, try something...
{ "AcceptedAnswerId": "58018", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T08:21:12.853", "Id": "58014", "Score": "1", "Tags": [ "python", "html" ], "Title": "Saving a webpage to text file" }
58014
<p>I have a pretty large model library I'm working on and it's turning out quite complex, or so I believe at least and I could use a second opinion.</p> <p>The basic idea is that the user should only have to create an instance of a big base class and then build on that with the other object types.</p> <p>These are so...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T08:36:10.303", "Id": "103988", "Score": "0", "body": "How are subsequences related to sequences? Does each sequence have its own set of subsequences?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T08...
[ { "body": "<p>I think you should definitely keep class structure as close as possible to actual data structure. So, for example, if your <code>MainStep</code> \"contains\" <code>SequenceStep</code>, you should reflect that in your code by using aggregation:</p>\n\n<pre><code>class MainStep\n{\n public List&l...
{ "AcceptedAnswerId": "58021", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T08:29:31.973", "Id": "58016", "Score": "11", "Tags": [ "c#", "classes", "library" ], "Title": "Too many objects, too \"deep\" class structure?" }
58016
<p>I have such part in my script, how can I optimize such parts? I don't want to use many local variables.</p> <pre><code>size_variants = [] for size in sizes_list: size_variants.append({'size': size}) </code></pre> <p>Also here:</p> <pre><code>variants_tmp = list() all_color_list = list(get_all_colors()) [vari...
[]
[ { "body": "<p>Using a list comprehension means you can eliminate all local variables:</p>\n\n<pre><code>size_variants = [{'size': size} for size in sizes_list]\n</code></pre>\n\n<p>Generally, anything of the form:</p>\n\n<pre><code>&lt;new list initialization&gt;\nfor &lt;variable&gt; in &lt;list&gt;:\n &lt;...
{ "AcceptedAnswerId": "58020", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T08:39:08.040", "Id": "58019", "Score": "2", "Tags": [ "python", "optimization" ], "Title": "Optimizing and clarifying nested list appending" }
58019
<p>I have the following codes, which I created as extension for datatable in my project. It actually worked. Just wonder if there is any optimization can be made through. Thanks. =)</p> <pre><code>&lt;Extension()&gt; Public Function HasNull(ByVal dataTable As DataTable) As Boolean For Each column As DataColumn In ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T15:44:36.247", "Id": "104050", "Score": "0", "body": "I'm rolling back the last edit as it invalidates my answer. Please see this meta post. [For an iterative review, is it ok to edit my question to include updated code?](http://met...
[ { "body": "<p>Credit to <a href=\"https://stackoverflow.com/a/24956404\">@Tim Schmelter</a>:</p>\n\n<blockquote>\n <p>According to the first method: I would handle the case that the input\n table is Nothing, either throw an ArgumentNullException or return\n True/False.</p>\n \n <p>Also another minor improv...
{ "AcceptedAnswerId": "58047", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T09:38:18.903", "Id": "58024", "Score": "5", "Tags": [ "asp.net", "vb.net", ".net-datatable" ], "Title": "Set default value for NULL in datatable" }
58024
<p>I'm using <a href="http://jamescryer.github.io/grumble.js/" rel="nofollow">grumble</a> to create an interactive tour for a website I'm working on (I'm aware there is a plugin called <a href="https://github.com/tommoor/crumble" rel="nofollow">crumble</a> that does this but I want to have full control of the functiona...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T10:28:33.570", "Id": "104000", "Score": "3", "body": "I strongly doubt that `#someOtherId` is the actual id you use? It will be easier for us to give advice, if you use the actual id's and classes in your code. Welcome to [coderevie...
[ { "body": "<p>One idea:</p>\n\n<pre><code>var grumbles = [\n// id, text, angle, distance, type, hidenByDefault, isLast\n['#someID', 'This is a short tour, click to continue', 130, 10, 'firstGrumble', false, false],\n['#someOtherID', 'This is some tour text', 30, 230, 'secondGrumble', true, false],\n...\n];\n\n$...
{ "AcceptedAnswerId": "58035", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T09:40:10.820", "Id": "58025", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "Creating an interactive tour for a website" }
58025
<p>I'm currently learning PHP, SQL/MySQL and HTML to develop a web application project (I have very little practical experience in all of these).</p> <p>To get started, I spent far too long and many questions on Stack Overflow writing a web application which inserts records into my database for <em>Game of Thrones</em...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T10:36:27.070", "Id": "104003", "Score": "1", "body": "Hello there and welcome to [codereview.se]! Your quesion is IMO fully on-topic. Don't worry about comments on to-be-closed questions. I've yet to see a post that was closed witho...
[ { "body": "<h3>Security - XSS</h3>\n\n<p>In addition to the SQL injection you mentioned, your code is also prone to XSS attacks as you are not sanitising <code>echo \"&lt;br&gt;\".$_GET['msg'];</code></p>\n\n<p>Try this:</p>\n\n<pre class=\"lang-none prettyprint-override\"><code>http://localhost/asoiaf.php?msg=...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T10:06:54.647", "Id": "58029", "Score": "5", "Tags": [ "beginner", "php", "html", "mysql" ], "Title": "Web application to insert into MySQL database" }
58029
<p>I have source code for execute a command (<code>ProcessStart</code>) using Impersonate, and I want apply best practices and good design pattern, and good performance if possible.</p> <p>I also want to use good Logging pattern. I use the Log pattern for logging my "Executor".</p> <p>Any suggestions?</p> <p>Source...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T04:33:24.293", "Id": "104183", "Score": "0", "body": "This code did not compile" } ]
[ { "body": "<p>This is bad way to write code , I could not even read the code without headache. Please separate out your logging functionality, you function should not be more than 30 lines per method, so first </p>\n\n<p><pre>\n <code>\n Log(\n string.Format(\"•————————————————————————...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T11:01:43.957", "Id": "58030", "Score": "2", "Tags": [ "c#", "design-patterns", "logging" ], "Title": "Apply Good Patterns about Logging in Executor Process" }
58030
<p>I have some code that run a series of functions in order and then outputs the results of each. When I execute this code, I am reusing a ton of it, where only the function itself in the code is changing. MethodThatChanges in the below example, is a method that returns void.</p> <pre><code>Task[] task1 = new Task[1...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T12:43:57.197", "Id": "104014", "Score": "0", "body": "Welcome to Code Review! Unfortunately, it's a bit hard to review code like this because the code you are showing is example code rather than code that you're actually using in a ...
[ { "body": "<p>An <code>Action</code> variable would be what you're looking for as it appears as though your method doesn't return anything. (If it returns something, use a <code>Func</code>.) So create another method that will do the following:</p>\n\n<pre><code>void ActionMethod(Task[] tasks, Action&lt;int&gt;...
{ "AcceptedAnswerId": "58038", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T11:28:14.783", "Id": "58033", "Score": "-1", "Tags": [ "c#" ], "Title": "Reusing too much code, but I cannot figure out how to refactor this correctly" }
58033
<p>I'm not really seeing any use for a generator here, unless there's some way to hook a generator into a language dictionary.</p> <p>But in the following code, the longhand version of the <code>if</code> statement (<code>type_check()</code>) returns a tuple <code>(foo, bar)</code> but to get the tuple from (my first ...
[]
[ { "body": "<p>That's normal, because with the list comprehension you're generating a whole\nlist of results instead of returning the first time the check succeeds.</p>\n\n<p>If you want to have the equivalent code to the loop version, that is, just\ncompute the first value or return <code>None</code> if no chec...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T12:07:54.490", "Id": "58036", "Score": "4", "Tags": [ "python", "beginner", "python-2.x" ], "Title": "List Comprehension in Pythonic answer to LPTHW ex48" }
58036
<p>I'm new to Python (and generally to programming), and I have recently written this Minesweeper game:</p> <pre><code>import random import string import os class Square(object): """Represent a square in the cell. mine -- if the square has a mine, it's True. Otherwise, False. location -- a tuple that repr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-11-10T11:20:21.143", "Id": "275581", "Score": "0", "body": "Wheres the part that creates the x and allows the user to input the position if the x?" } ]
[ { "body": "<p>Purely from an OOP standpoint, I think that your classes don't make much sense.</p>\n\n<p><code>Square</code> should just be a square, it shouldn't modify any other square (as you do so in your <code>expose</code> function). In fact, a square doesn't even need to know it's own location (as its con...
{ "AcceptedAnswerId": "58075", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T12:20:53.553", "Id": "58039", "Score": "23", "Tags": [ "python", "beginner", "game", "python-2.x", "minesweeper" ], "Title": "Python - Minesweeper" }
58039
<p>I'm building a .NET Linq-esc query builder for my application and I'm wondering about my implementation and code structure when it comes a few classes.</p> <p>Basically I'm creating a query builder for SQL, and I need for my classes to be able to using the following behavior:</p> <pre><code>query.Select(...).From(...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T14:38:36.983", "Id": "104026", "Score": "0", "body": "Have a single class implement all of your interfaces. Where you need a composite interface, use another interface which just inherits from all the interfaces it composes. You'll ...
[ { "body": "<p>Interesting question. The most simple and direct way to approach this problem (not necessarily the wisest) - implement <code>Select()</code>, <code>From()</code>, <code>Join()</code> etc. as extension methods on the interfaces <code>ISelectable</code>, <code>IFromable</code>, <code>IJoinable</code...
{ "AcceptedAnswerId": "58066", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T14:05:50.103", "Id": "58042", "Score": "1", "Tags": [ "c#", "inheritance" ], "Title": "Duplicate code in similar classes where I cannot add more inheritance" }
58042
<p>I was wondering if there's a better way of doing LINQ projections than what I'm doing below. This method is one of many methods creating a view of an object tree.</p> <p>The first thing that I don't like is that I'm returning an anonymous object. Should I create a <code>BreakdownReport</code> class or something els...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T14:45:38.917", "Id": "104029", "Score": "0", "body": "You can't return an anonymous object. So yes, you'll have to create another object type to project it into." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2...
[ { "body": "<ul>\n<li>About the anonymous type: It depends on whether you need a name further on in your processing. If you're just going to keep everything in your flattened list, there's no need.</li>\n<li>About copying all the elements: It is not clear whether the listed members are the only members of the ch...
{ "AcceptedAnswerId": "58049", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T14:20:31.513", "Id": "58044", "Score": "5", "Tags": [ "c#", "linq" ], "Title": "A better way to do LINQ projections" }
58044
<p>I've translated <a href="https://gist.github.com/pkukielka/2842475" rel="noreferrer">this Java code</a> into Delphi code:</p> <pre><code>unit Trampoline; interface type ITrampoline&lt;T&gt; = interface function Get: T; function Run: ITrampoline&lt;T&gt;; function Execute: T; end; TTrampoline&lt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T19:11:45.057", "Id": "104272", "Score": "0", "body": "your code problem is **attractive:=0** for me. Why would I spend any time and thinking on a factorial problem. **What do you really need to solve, use, what is your real-life app...
[ { "body": "<p>Recursion can make for elegant code, but it can also make for very slow code. Calculating Fibonacci numbers and Factorials are both classic examples where the recursive algorithm is simple to implement, but slow beyond the first few (and very small) input values. </p>\n\n<p>I don't know Delphi, so...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T15:04:40.643", "Id": "58048", "Score": "8", "Tags": [ "optimization", "recursion", "delphi", "trampoline" ], "Title": "Factorial using trampolines" }
58048
<p>I am trying to generate Pascal's triangle table in Python 3. I started to like using this following pattern when dealing with 2D arrays.</p> <ol> <li>Generate a list of valid indices</li> <li>Use a function that works with those indices in a list comprehension. (may produce side effects)</li> </ol> <p>I wonder, is...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T16:18:24.387", "Id": "104059", "Score": "0", "body": "Hi, I appreciate the fact that you considered my answer as satisfying. However, I reckon it would be best for you not to accept it too quickly as it can prevent other people to w...
[ { "body": "<p>In :</p>\n\n<pre><code>table = []\nvalid_idxs = [(r,c) for r in range(level) for c in range(level)]\n[compute(table, r, c) for r, c in valid_idxs] \nprint(table)\n</code></pre>\n\n<p>the line <code>[compute(table, r, c) for r, c in valid_idxs]</code> definitly shouldn't be a list comprehension as ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-07-25T15:11:31.960", "Id": "58050", "Score": "6", "Tags": [ "python" ], "Title": "Generating Pascal's triangle" }
58050
<p>I'm previewing the data I'm about to delete, but this SQL looks a little redundant. Is there a better way to write this?</p> <pre><code>declare @history table(pid int) insert into @history select pid from plans p where p.pidSynergy = 'P0022' and p.pid != 2885 select * from forecast_FTEs where pid in (select pid f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T20:01:30.750", "Id": "104111", "Score": "0", "body": "You should add a primary key to the table variable and only insert distinct not null values. Also consider using `recompile` so it takes account of correct table variable cardina...
[ { "body": "<p><code>p</code> is a cryptic table alias and that <code>!=</code> is not ANSI compliant, you should try and use <code>&lt;&gt;</code> instead. Also, the <code>select * from</code> is inefficient because it has to go back to the information schema and look up every column, you should try and only se...
{ "AcceptedAnswerId": "58068", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T15:18:59.207", "Id": "58053", "Score": "5", "Tags": [ "sql", "sql-server", "t-sql" ], "Title": "Delete from multiple tables using temp table variable" }
58053
<p>It's often useful to be able to time code, for instance, to evaluate alternative approaches to the same problem. Because this is a thing I use frequently, I have created this Stopwatch templated class that I'd like for you all to review. Unlike some <a href="https://codereview.stackexchange.com/questions/2398/homem...
[]
[ { "body": "<p>Every time I've needed a stopwatch, this is the sort of thing I've been after. No complications, just a simple start and stop function. I reckon you just document what the units are in, and people can do conversion themselves.</p>\n\n<p>One thing that is convenient is something I saw in the .NET v...
{ "AcceptedAnswerId": "58062", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T15:30:08.800", "Id": "58055", "Score": "19", "Tags": [ "c++", "c++11", "template", "timer" ], "Title": "Stopwatch template" }
58055
<p>I have been trying to achieve the below requirements to get them working. Am I doing it the right way?</p> <ol> <li><p>We have a table with customised Cell (say: <code>firstViewController</code>)</p></li> <li><p>Customised Cell has a button, click event in this button, and carries row index value to another view c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T23:35:30.673", "Id": "104148", "Score": "2", "body": "http://meta.codereview.stackexchange.com/questions/2144/enough-reviewable-code" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-28T05:05:10.677", ...
[ { "body": "<p>Your \"next view controller\" shouldn't have to know anything about the view controller presenting it (\"first view controller\"). You should consider just passing your view model to the \"next view controller\". Also, consider passing something more concrete than just an NSDictionary as your view...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T16:27:18.483", "Id": "58061", "Score": "1", "Tags": [ "objective-c", "ios" ], "Title": "Passing Row Index of TableViewCell (custom) to another view controller" }
58061
<p>I'm implementing a game with a classical screen <a href="http://en.wikipedia.org/wiki/Wraparound_(video_games)" rel="nofollow">wraparound</a> effect. It is very simple: if the player goes out-of-screen, it reappears on the opposite side (<a href="http://en.wikipedia.org/wiki/Asteroids_(video_game)" rel="nofollow">A...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T20:34:30.220", "Id": "104121", "Score": "0", "body": "Are you sure that `float`s are appropriate? Screen size would typically be measured in pixels, which is integral." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDat...
[ { "body": "<p>This situation calls for a modulus operator.</p>\n\n<p>The modulus operator returns the remainder from a division. So 5 % 2 = 1, 10 % 15 = 10 and so on. This is because 5 goes into 2 twice, with remainder 1. This gets a bit tricky with negative numbers, as -5 % 2 could either be -1 or 1, since -5 ...
{ "AcceptedAnswerId": "58065", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T16:32:29.477", "Id": "58063", "Score": "11", "Tags": [ "java", "game" ], "Title": "Screen wraparound" }
58063
<p>For what I'm doing, I need to be able to draw a buffered image directly into a larger buffered image. I've searched around a little and still have failed to find a better way, but my current way is extremely inefficient and I would like a better way if it's possible. Any improvements onto this design would also be g...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T17:25:04.563", "Id": "104073", "Score": "0", "body": "I'm assuming that you tried the [option java offers itself](http://stackoverflow.com/questions/10961313/draw-buffered-image-ontop-of-another-buffered-image), and it is slower tha...
[ { "body": "<p>You'll need to obtain the the backing source of a <code>BufferedImage</code>, such that you can apply operations in constant time.</p>\n\n<p>You can obtain a both readable and writable backing source via:</p>\n\n<pre><code>BufferedImage bufferedImage = obtainSourceImage();\nRaster raster = buffere...
{ "AcceptedAnswerId": "58177", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-07-25T17:06:18.497", "Id": "58067", "Score": "5", "Tags": [ "java", "image" ], "Title": "Drawing a bufferedimage into another" }
58067
<p>I was bored, so I wrote a BrainFuck interpreter in Python. It essentially takes input for the amount of cells, then parses the inputted code through a series of <code>if</code> statements.</p> <pre><code># Simple BrainFuck interpreter from sys import exit # Main interpreter function def interpreter(cell_amount): ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T18:16:43.217", "Id": "104086", "Score": "10", "body": "Please note, if you're asking how your code should be modified to support nested loops or reading from a file, ...that's changing *what* the code does, not *how* it's doing it."...
[ { "body": "<p>This being Python, it should be relatively easy to present the illusion of an infinite tape, at least in the positive direction. I don't see reason that <code>cell_amount</code> has to be specified, and the user shouldn't have to worry about such details.</p>\n\n<p>Your input and output routines ...
{ "AcceptedAnswerId": "58082", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T18:06:20.127", "Id": "58071", "Score": "7", "Tags": [ "python", "python-2.x", "brainfuck", "interpreter" ], "Title": "Basic BrainFuck interpreter" }
58071
<p>I wrote a very simple CSS parser and would appreciate some general feedback regarding the security, code style etc...</p> <p>Basically, this does the following:</p> <ol> <li>Take user's uploaded CSS file</li> <li>Save it to disc</li> <li>Parse it and return some styles</li> <li>Save a JSON formatted file to disc</...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T03:15:40.107", "Id": "104170", "Score": "0", "body": "Keep in mind that if you want to adhere to the specification, there are some (quite specific) [rules you must follow](http://www.w3.org/TR/CSS21/syndata.html) to parse it correct...
[ { "body": "<p>I'll mostly judge the actual parsing part, and not that much the boilerplate stuff around it</p>\n\n<p>Why explode the file twice?</p>\n\n<p><code>$element</code> should be called <code>$elements</code>, and this loop won't really work as expected:</p>\n\n<pre><code>foreach ($element as $element)\...
{ "AcceptedAnswerId": "58094", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T23:27:59.630", "Id": "58085", "Score": "8", "Tags": [ "php", "parsing", "css", "html5" ], "Title": "Simple CSS Parser" }
58085
<p>Just what it says on the tin: a brainfuck interpreter in JavaScript.</p> <pre><code>function brainfuck(source) { var code = source.replace(/[^-+&lt;&gt;.,[\]]/g, '').split(''); // program code var loop = []; // stack of loops created by bracket operators var data = []; // array of data cells stored b...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T00:36:32.480", "Id": "104153", "Score": "8", "body": "At least it's not the other way around: a JavaScript interpreter written in Brainfuck" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-06-07T16:16:35.417...
[ { "body": "<p>It's nice and clean; I like it. I won't even try to figure out if its interpretation is correct, since I don't know Brainfuck, so I'll take your word for that and just look at the JS :)</p>\n\n<p>As you yourself pointed out, the <code>[</code> and <code>]</code> operators might be handled differen...
{ "AcceptedAnswerId": "58089", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T00:13:27.810", "Id": "58086", "Score": "23", "Tags": [ "javascript", "brainfuck", "interpreter" ], "Title": "Brainfuck interpreter in JavaScript" }
58086
<p>Below is my implementation of a pool. It is based on a hash table and supports using strong, soft or weak references to store objects. At the start there is a builder class to configure and create instances, followed by a subclass of <code>Pool</code> which allows multiple reference types to be used. Towards the end...
[]
[ { "body": "<pre><code>/** Removes all objects from this pool. */\n@SuppressWarnings(\"unchecked\")\npublic void clear() {\n size = 0;\n int s = getNewSize();\n if (s == nodes.length) {\n Arrays.fill(nodes, null);\n } else {\n nodes = new Node[s];\n }\n while (queue.poll() != null...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T01:46:51.230", "Id": "58093", "Score": "10", "Tags": [ "java", "hash-map" ], "Title": "Object pool implementation" }
58093
<p>I'm writing some Java code for some pretty large datasets, in a puzzle I'm trying to solve. The output is correct, but the program doesn't run within the time limit for all the test cases. I've tried a number of optimizations, but can't think about how to improve it. I'd appreciate your suggestions.</p> <p>The p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T13:06:55.853", "Id": "104220", "Score": "0", "body": "[Can you please provide the context to the question here?](http://meta.codereview.stackexchange.com/q/1993/41243) [Links are unreliable](http://meta.codereview.stackexchange.com/...
[ { "body": "<p>This is one of the beefs I have with online judging systems like this..... it is not testing the algorithm, or anything like that. Instead, consider doing the very last line like:</p>\n\n<pre><code>// the longest value will be 11 chars long because % 1000000007 + \" \"\nStringBuilder sb = new Stri...
{ "AcceptedAnswerId": "58096", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T02:14:08.377", "Id": "58095", "Score": "4", "Tags": [ "java", "optimization", "programming-challenge" ], "Title": "\"Sherlock and queries\" challenge" }
58095
<p>How can I make this better?</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;sys/types.h&gt; #include &lt;sys/stat.h&gt; #include &lt;fcntl.h&gt; #include &lt;unistd.h&gt; #include &lt;string.h&gt; #include &lt;stdlib.h&gt; #define ARP_CACHE "/proc/net/arp" #define ARP_BUFFER_LEN 1024 #define ARP_DELIM ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T03:13:21.820", "Id": "104168", "Score": "0", "body": "Out of curiosity, where did you learn to program in C, and is it your first language?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T03:21:41.483...
[ { "body": "<p>A few notes:</p>\n\n<ul>\n<li><p>Overall, you are doing a lot of unnecessary work. You could just use\n<a href=\"http://man7.org/linux/man-pages/man3/getifaddrs.3.html\" rel=\"nofollow\"><code>getifaddrs()</code></a> to get the IP address, MAC address, and interface\nname. There are plenty of co...
{ "AcceptedAnswerId": "58107", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T03:05:26.330", "Id": "58097", "Score": "13", "Tags": [ "c", "parsing", "linux", "networking" ], "Title": "Parsing ARP cache in C" }
58097
<p>I have data that looks like the "Input" below and need to convert it into JSON. My solution works by parsing the text to find a level for each data point. Then I use a recursive structure to build a JSON tree (or maybe its not JSON, but its much more useful than the original format).</p> <p>First, I transform the...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T04:34:32.537", "Id": "104184", "Score": "0", "body": "Is the format of the file constant, meaning there will always be those attributes present. For example, person will always have address and web and address will always have those...
[ { "body": "<p>I have not programmed in python but you should be able to do this in one shot. In pseudo-code it should be something like so:</p>\n\n<pre><code>function parseJsonInput (file)\n var parsedJson= {};\n var parentStack = [parsedJson]\n for each line in file\n var data = parseLine(line) //ret...
{ "AcceptedAnswerId": "58103", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T04:03:49.543", "Id": "58101", "Score": "3", "Tags": [ "python", "parsing", "recursion", "json" ], "Title": "More efficient conversion of tab-formatted nested data structure...
58101
<p>This is another revision of <a href="https://codereview.stackexchange.com/questions/56145/revision-1-step-1-psychoproductions-management-tool-project">my Psycho Productions database</a>, this time refactored from MySQL to PostgreSQL, after I found out about some of the shortcomings of MySQL. </p> <p>The following i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-09-05T03:15:42.790", "Id": "112850", "Score": "0", "body": "Anyone interested in the final code, scroll down to my answer from Sept 4." } ]
[ { "body": "<p><code>DROP SCHEMA IF EXISTS</code> will fail if there's anything in the schema. Either use <code>DROP SCHEMA IF EXISTS … CASCADE</code> (a bit bold and risky), or don't include it in the script at all.</p>\n\n<hr>\n\n<p>A you have a lot of <code>SERIAL</code>–<code>TEXT</code> tables with a few f...
{ "AcceptedAnswerId": "58194", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T06:48:48.447", "Id": "58104", "Score": "12", "Tags": [ "sql", "postgresql" ], "Title": "Revision 2 - Step 1: PsychoProductions management tool project" }
58104
<p>I would like to ask your comments on my contest code for the following problem:</p> <p>We're going to have a slightly more logical puzzle today. We're going to write a program that will find a path through a simple maze.</p> <blockquote> <p><strong>Formal Inputs &amp; Outputs</strong></p> <p><strong>Input D...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T02:17:25.673", "Id": "104313", "Score": "1", "body": "@Manny Meng Thank you for your comment, I did not check for possible exceptions during input because the rules of the contest stated that the inputs will always be correct. Also ...
[ { "body": "<h1>Code Style</h1>\n\n<p>Your code is actually not bad. However, I would modify the general OO structure.</p>\n\n<ul>\n<li><p>I would separate the Maze from its representation. There would be a <code>MazeTextRepresentation</code> which would read in text to create a <code>Maze</code> and a method ...
{ "AcceptedAnswerId": "58133", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T09:01:02.670", "Id": "58108", "Score": "12", "Tags": [ "java", "optimization", "programming-challenge", "pathfinding" ], "Title": "Contest code for a maze problem" }
58108
<p>I've run into the need to deserialize XML that returns from an http request. I've done some light work with XML deserialization in the past but that was against files on disk.</p> <p>While attempting to write the code I noticed that many of the methods in <code>HttpWeb*</code> and <code>XmlReader</code> had both an...
[]
[ { "body": "<p>I understand that this is an educational exercise, but <em>naming is important</em>. One and two letter names are highly discouraged. When Mr. Maintainer has to map letters to meanings it becomes difficult for him to focus on what's actually happening, because he has to constantly remember that<co...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T09:20:49.250", "Id": "58109", "Score": "3", "Tags": [ "c#", "xml", "async-await" ], "Title": "HttpWeb* and XmlReader Async?" }
58109
<p>Finding the prime numbers between two given integers in the minimum number of comparisons:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;conio.h&gt; #include &lt;math.h&gt; void main() { clrscr(); int i,n,count,n1,n2; printf("Enter n1 and n2:"); scanf("%d",&amp;n1); scanf("%d",&amp;n2); ...
[]
[ { "body": "<p>I have found some things that might help you improve your code:</p>\n\n<h2>Strive for portable code</h2>\n\n<p>Several of the features of this code are either platform-specific or compiler-specific or both. Specifically, <code>#include &lt;conio.h&gt;</code>, <code>clrscr()</code>, and <code>getc...
{ "AcceptedAnswerId": "58124", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T11:43:21.730", "Id": "58117", "Score": "6", "Tags": [ "optimization", "c", "primes" ], "Title": "Finding prime numbers in a range" }
58117
<p>This is part of my chat client's code. It works fine but it looks messy. Any ideas?</p> <pre><code>//IP Validation private void textBox3_Leave(object sender, EventArgs e) { IPAddress ip; bool ValidateIP = IPAddress.TryParse(textBox3.Text, out ip); if (ValidateIP) { button2.Enabled = true; ...
[]
[ { "body": "<h2>Naming</h2>\n\n<p>By convention, variables local to a method should be camelCased. You seem to have a mixture of PascalCased and alllowercase, making it hard to see at a glance what a variable is. All lower case has the additional disadvantage of being hard to read.</p>\n\n<p>Your boolean check v...
{ "AcceptedAnswerId": "58121", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T12:31:37.823", "Id": "58119", "Score": "3", "Tags": [ "c#", "validation", "networking", "client" ], "Title": "Simple IPv4 and port validation for chat client" }
58119
<p>This is my first bash script so I ask to you to say what you think.</p> <p>The script must check every directory and if it finds a pdf file in this directory: move all the pdf files to parent directory, change the name of the files and remove directory.</p> <p>So if I had this folder structure:</p> <pre><code>fo...
[]
[ { "body": "<p>For a first script, this is great, and I am impressed.</p>\n\n<ul>\n<li>your structure is neat</li>\n<li>you are using loops properly</li>\n<li>you are using variable substitution which is 'advanced'</li>\n</ul>\n\n<p>The script appears that it will work for all the standard cases, and, I have see...
{ "AcceptedAnswerId": "58129", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T13:40:18.270", "Id": "58123", "Score": "5", "Tags": [ "beginner", "bash", "file-system" ], "Title": "File handling script" }
58123
<p>The previous version is <a href="https://codereview.stackexchange.com/questions/58086/brainfuck-interpreter-in-javascript">here</a>. This version takes suggestions from that review into account:</p> <ul> <li><code>brainfuck</code> is now an object instead of a function, and <code>brainfuck.run(source)</code> kicks ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T16:09:35.417", "Id": "104231", "Score": "0", "body": "You have a typo in `exportModulo` for the exports case. Also most people do `module.exports = smt`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26...
[ { "body": "<p>I think I said I'd refrain from reviewing, since I reviewed the first take, but I can't help myself.</p>\n\n<p>Again: I like it! It's very neat and tidy. I really can't fault it.</p>\n\n<ul>\n<li>It's well-formatted</li>\n<li>It's readable</li>\n<li>It's efficient</li>\n</ul>\n\n<p>Hell, it even t...
{ "AcceptedAnswerId": null, "CommentCount": "11", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T14:03:07.833", "Id": "58125", "Score": "11", "Tags": [ "javascript", "brainfuck", "interpreter" ], "Title": "Brainfuck interpreter in JavaScript, take 2" }
58125
<p>The Contacts Data API provides two types of feed: contacts feed and contact groups feed.</p> <p><a href="https://developers.google.com/google-apps/contacts/v3/reference" rel="nofollow">Google Developer's Reference</a></p>
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T14:11:16.167", "Id": "58126", "Score": "0", "Tags": null, "Title": null }
58126
The Contacts Data API provides two types of feed: contacts feed and contact groups feed.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T14:11:16.167", "Id": "58127", "Score": "0", "Tags": null, "Title": null }
58127
<p>I have a piece of javascript I wrote for a recent work project that is essentially taking a <code>deviceorientation</code> event object, taking either the <code>beta</code> value or <code>gamma</code> value of that object and makes a calculation.</p> <p>While I can't necessarily put my exact code here just in case ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T14:31:11.043", "Id": "104224", "Score": "1", "body": "nothing can be done, if else is as per your requirement, This is a good code, what else you want. do not worry much, All you can do that encapsulate the whole logic in a class" ...
[ { "body": "<p>Given your conditions, there's no way around the if-else statements. You have to enforce the conditions somehow.</p>\n\n<p>Instead of if-else, another option is a <code>switch</code> statement, but the outcome is essentially the same:</p>\n\n<pre><code>switch (true) {\n case Math.round(e.gamma)...
{ "AcceptedAnswerId": "58138", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T14:21:07.367", "Id": "58128", "Score": "2", "Tags": [ "javascript" ], "Title": "Comparing numbers and making a calculation" }
58128
GWT (formerly the Google Web Toolkit) is a development toolkit for building and optimizing complex browser-based applications.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T15:34:50.493", "Id": "58132", "Score": "0", "Tags": null, "Title": null }
58132
<p>I am coding a simple blog engine for educational purposes.</p> <p>In the <code>PostsController</code> I have two two methods that share some common code namely, <code>Add</code> and <code>Edit</code>:</p> <pre><code>[HttpPost] public ActionResult Add(PostInputModel model) { if (!ModelState.IsValid) return View...
[]
[ { "body": "<p>The common code is about updating the post, so I'd extract this into it's own method:</p>\n\n<pre><code>private bool UpdatePost(Post post)\n{\n // convert the title to a slug (Hello World becomes hello-world for example)\n post.Slug = SlugConverter.Convert(post.Title);\n post.Summary = Su...
{ "AcceptedAnswerId": "58145", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T17:36:16.993", "Id": "58137", "Score": "4", "Tags": [ "c#", "asp.net-mvc" ], "Title": "Simple blog engine for educational purposes" }
58137
<p>I'm using the <a href="https://developers.google.com/gdata/samples/spreadsheet_sample" rel="nofollow">old Google Data API</a> to access several spreadsheets and put their contents in a database using Flask and SQLAlchemy. Each run deletes the contents of the database tables and repopulates them with results of the ...
[]
[ { "body": "<p>Some comments:</p>\n\n<ul>\n<li>Instead of using <code>print</code> statements, the <code>logging</code> module could be used</li>\n<li>The return value of <code>get_google_content</code> should be a boolean value (<code>True</code> on success, <code>False</code> on failure)</li>\n</ul>\n\n<p>Rega...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T19:19:43.557", "Id": "58143", "Score": "3", "Tags": [ "python", "api", "flask", "google-sheets", "sqlalchemy" ], "Title": "Catching API changes for a service that doesn't ...
58143
<blockquote> <p><strong>Problem Description:</strong></p> <p>Find the maximum sum of a compact subsequence of array elements after performing a single swap operation.</p> </blockquote> <p><strong>Solution:</strong></p> <pre><code>def maxsum(lst): # Get maximum sum of all possible slices in list max_endin...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-28T09:17:47.220", "Id": "104505", "Score": "0", "body": "Not a review but maybe this article coud help you : http://zh-wang.github.io/blog/2014/06/18/codility-aluminium-2014/ ." } ]
[ { "body": "<p>After reading through the <a href=\"http://zh-wang.github.io/blog/2014/06/18/codility-aluminium-2014/\" rel=\"nofollow\">article linked in Josay's comment</a>, I have translated the code into Python, removed extra fluff and added a bunch of comments to make it more readable then the version in the...
{ "AcceptedAnswerId": "60104", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T19:37:30.573", "Id": "58146", "Score": "8", "Tags": [ "python", "performance", "complexity" ], "Title": "Codility \"max slice swap\" challenge" }
58146
<p>I am trying to write a function called <code>countHand()</code> that takes in an array of <code>Card</code> instances and counts the total value of the cards given.</p> <p>The requirements are as follows:</p> <ol> <li>The function returns the value of the cards in the hand as an <code>Int</code>. It does not use ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-30T00:56:47.027", "Id": "104954", "Score": "0", "body": "Please do not remove the code from the question; that will invalidate the answers." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-30T00:59:18.667", ...
[ { "body": "<p>First a minor note. It is less efficient to create a temporary Array from the result of Zip2. You can use the function <code>map</code> instead of the method <code>map</code>:</p>\n\n<pre><code>map(Zip2(hand, dropFirst(hand))) { ... }.reduce(0, +)\n</code></pre>\n\n<p>Second, I believe that having...
{ "AcceptedAnswerId": "58150", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T19:34:34.960", "Id": "58148", "Score": "4", "Tags": [ "playing-cards", "swift" ], "Title": "Counting the total value of Card instances given" }
58148
<p>Known to developers as the Google Geocoding API, this API makes it possible to work Google maps into any website, but it also allows developers to convert an address to a longitude/latitude coordinate so that the google map can pinpoint the location and provide directions.</p> <p>When an application makes a request...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T21:48:48.863", "Id": "58152", "Score": "0", "Tags": null, "Title": null }
58152
Google Maps is a desktop and mobile web mapping service application and technology provided by Google, offering satellite imagery, street maps, and Street View perspectives.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T21:48:48.863", "Id": "58153", "Score": "0", "Tags": null, "Title": null }
58153
Google Sheets is an online spreadsheet app for creating and formatting spreadsheets.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T21:51:24.063", "Id": "58155", "Score": "0", "Tags": null, "Title": null }
58155
<p>I'm trying to create a filewatcher program that can watch different files. The files might have subfiles that are being imported into the main file, which is being represented by the file object. I'm feeling the code is a little messy and I would like to know how I can improve it.</p> <p>The <code>input_watcher()</...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T03:19:01.473", "Id": "104318", "Score": "0", "body": "I think what you're trying to do is similar to [peat](https://github.com/sjl/peat/blob/master/peat), so I'd recommend taking a look at it. Once you're done with the check part, y...
[ { "body": "<p>Sort your imports alphabetically. Make it easier to find. - Core libs first, then 3rd party.</p>\n\n<pre><code>import multiprocessing\nimport threading\nimport os\nimport time\n</code></pre>\n\n<p>Constants are typically in all caps.</p>\n\n<pre><code>file_lock = threading.Lock()\nupdate_interval...
{ "AcceptedAnswerId": "58216", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T22:14:39.293", "Id": "58157", "Score": "4", "Tags": [ "python", "multithreading", "file-system", "multiprocessing" ], "Title": "Filewatcher compiler for watching different ...
58157
<p>I'm trying to improve my Color Picker code. It works like Photoshop and I don't want to use a library.</p> <pre><code> for(var yColor = 0; yColor &lt; 255; yColor++) { var r = 255, g = 0, b = 0; for(var xColor = 0; xColor &lt; 255; xColor++) { if(r...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T00:29:49.880", "Id": "104306", "Score": "0", "body": "Just improve my code." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T00:30:45.243", "Id": "104307", "Score": "0", "body": "If I redra...
[ { "body": "<blockquote>\n <p>If I redraw it, It become a bit laggy.</p>\n</blockquote>\n\n<p>In my tests, using <code>createImageData</code> and <code>putImageData</code> to fill the individual pixels ran about 3x faster than <code>rect</code> and <code>fill</code>.</p>\n\n<p>You can replace this code:</p>\n\n...
{ "AcceptedAnswerId": "58199", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-26T23:21:36.700", "Id": "58159", "Score": "4", "Tags": [ "javascript", "canvas" ], "Title": "Photoshop Color Picker Gradient" }
58159
<p>I am trying to create an outline of what a character is in a game. </p> <p>Then I want to create 10 different characters and compare their stats at different levels. </p> <p>I am creating an interface called <code>Hero</code> that looks like this,</p> <pre><code>public interface Hero { // define methods that...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T04:43:26.130", "Id": "104323", "Score": "1", "body": "are you trying to create an `n` number of characters with arbitrary attributes based on that `Character`template? or are you creating a specific character type with different att...
[ { "body": "<h1>Modifiers</h1>\n\n<p>All methods declared in an interface are automatically <code>public</code> and <code>abstract</code>. Some people prefer putting one or both in anyway, but most seem to prefer that they simply be left out:</p>\n\n<p><code>public int getLevel();</code> &rarr; <code>int ge...
{ "AcceptedAnswerId": "58200", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T02:32:32.603", "Id": "58162", "Score": "3", "Tags": [ "java", "object-oriented", "game" ], "Title": "Structuring Class Objects And Defining The Variables" }
58162
<p>I have been wanting to learn programming for some time now and decided to really give it a shot today. I have edited and read lots of things in Java to fix small issues but never written from scratch. I've tried C and Java but both seemed just a bit too much to teach myself as a first language, so I'm going with Pyt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T05:54:10.437", "Id": "104335", "Score": "4", "body": "Do you actually do anything with the user input (`x` is initialized but never used)? If so, please include that aspect of the code *without making any changes already mentioned ...
[ { "body": "<p>Variable-naming is one of the important aspects of coding. You must name variables correctly; in this case, <code>x</code> and <code>y</code> do not make sense.</p>\n\n<p>Rather, it should be:</p>\n\n<pre><code>userInput = int(raw_input(\"Please enter a number up to 100. \"))\nselectedRandomNumbe...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T04:32:29.057", "Id": "58165", "Score": "24", "Tags": [ "python", "beginner", "python-2.x", "random" ], "Title": "Simple random number generator" }
58165
<p>I need to make thumbnails without empty space and in the original ratio. Please help me check this algorithm to improve it.</p> <pre><code>public function createThumbnail($imagePath, $thumbnailPath, $targetWidth, $targetHeight) { list( $originalWidth, $originalHeight, $originalType ) = getimagesize($imagePath);...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T19:41:39.900", "Id": "104440", "Score": "0", "body": "This [blog post](http://a32.me/2012/06/scale-images-to-fit-fill-bounding-box-in-php-using-gd/) shows some alternate usage of the API, specifically loading the image and inspectin...
[ { "body": "<p>The first thing that's really needed are some comments describing the different conditions. Sure, you can work them out every time you read the code, but that's error-prone busy-work that you can avoid for future maintainers. You don't need to go crazy with ASCII graphics, though this is one case ...
{ "AcceptedAnswerId": "58175", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T05:58:28.947", "Id": "58169", "Score": "5", "Tags": [ "php", "algorithm", "image" ], "Title": "Create thumbnail in the original ratio without empty space" }
58169
<p>Is this code correct? </p> <p>It appears to work in g++ 4.8.3 and clang (bcc64), however appearing to work is no guarantee of correctness :)</p> <p>The aim is to be able to replace a call to a member function:</p> <pre><code>void Master::go() { std::string s; func(s); // func is a member function of...
[]
[ { "body": "<p>I see a few potential problems that you might want to address. First, I'll have to say that it's not entirely clear what problem you're trying to solve. That is, it's not clear why one wouldn't just call <code>func(s)</code> as in your very first example.</p>\n\n<h2>Handle <code>const</code> func...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T06:52:42.503", "Id": "58172", "Score": "3", "Tags": [ "c++", "c++11", "template" ], "Title": "Wrapping std::bind call in a function returning std::function" }
58172
<p>I wrote a JavaScript function for validating bank account numbers in IBAN format for my own joy. Could you have a look if you don't see any obvious mistakes or places for improvement?</p> <pre><code>function isIbanValid(value) { var lengthMap = getLengthMap(); //cleanup value = value.toString().toUppe...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T11:32:34.070", "Id": "104363", "Score": "2", "body": "Could you include the rules against which you are validating? Some are familiar with them, some others aren't." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate":...
[ { "body": "<ol>\n<li><p>I'm pretty sure this will fail for some IBANs. You convert the country code to digits, but I don't see you doing the same for any other letters in the IBAN - and there might well be others. The example Wikipedia gives is <code>GB82WEST12345698765432</code>. The \"WEST\" should be convert...
{ "AcceptedAnswerId": "58180", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-07-27T08:13:47.123", "Id": "58174", "Score": "7", "Tags": [ "javascript", "validation", "finance" ], "Title": "Bank account number validation in IBAN format" }
58174
<p>I'd like this code to be improved </p> <pre><code>package com.array.demo; public class BinarySearchMethod { public static void main(String[] args) { int[] arr = { 2, 4, 5, 6, 8, 9, 11, 15, 17, 19, 22, 111, 117, 234, 543 }; int search = 2; BinarySearchMethod b = new BinarySearchMethod(); int size...
[]
[ { "body": "<p>For beginner code, this is quite good. I am impressed. Good enough for me to assume you have worked from some example code. That is not a criticism, everyone does that (me too).</p>\n<p>Still, many examples are based on other examples, and they have some issues that are 'historical' in nature, and...
{ "AcceptedAnswerId": "58185", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T09:45:06.837", "Id": "58176", "Score": "7", "Tags": [ "java", "beginner", "search", "binary-search" ], "Title": "Binary search an integer array" }
58176
<p>I'd like to improve this bubble sort code</p> <pre><code> package com.arun.sort; import java.util.Arrays; public class BubbleSort { public static void main(String[] args) { int[] arr={2,5,1,8,12,3,7}; int n=arr.length; for(int k=0;k&lt;n-1;k++){ for(int i=0;i&lt;n-k-1;i++){ if...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T13:05:39.767", "Id": "104375", "Score": "4", "body": "I'm assuming you know this, and that the bubble sort is an exercise, but the easiest way to improve on this would be to choose anything but a bubble sort. As far as I know, there...
[ { "body": "<p>Let me start with the glaring issue, I want to get that done, and leave the rest to others,,</p>\n<h1>Formatting</h1>\n<p>Your code formatting is messy. there is just three things that are not indented in a java-file as per conventions.</p>\n<p>these three things are:</p>\n<ol>\n<li>Package-declar...
{ "AcceptedAnswerId": "58187", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T11:08:24.343", "Id": "58178", "Score": "6", "Tags": [ "java", "beginner", "sorting" ], "Title": "Bubble sorting an int array" }
58178
<p>I am trying to implement <a href="http://en.wikipedia.org/wiki/Karatsuba_algorithm" rel="nofollow">Karatsuba multiplication algorithm</a> for binary (base 2) numbers.</p> <p>A requirement is that the intermediate / final results must also be in binary so as to assist in educative purposes.</p> <p>This is my implem...
[]
[ { "body": "<p>In Python, there's no reason to have <code>to_BitArray</code> as a staticmethod in an otherwise empty <code>BitTools</code> class, when it could just exist as a function. I'd put a set of related functions together in an appropriate python module versus group the functions in a class that is othe...
{ "AcceptedAnswerId": "58325", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T12:49:09.707", "Id": "58184", "Score": "6", "Tags": [ "python", "algorithm", "bitwise" ], "Title": "Implementing Karatsuba Multiplication Algorithm in Python" }
58184
<p>For my resources management, I wanted the objects allocated on the heap to be in a contiguous block of memory. Obviously, each data type then has to have their own chunk of memory. I could have used a vector for this, of course, but the resources need to be aligned properly with a given alignment which a vector can'...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T17:28:55.260", "Id": "104417", "Score": "0", "body": "This code is neither complete nor working: where's \"..\\General\\GeneralHeader.h\"? Several needed standard library headers aren't shown: `<memory>` (std::unique_ptr, etc.), `<t...
[ { "body": "<p>Starting on page:</p>\n\n<pre><code>Page( Page&amp;&amp; o )\n : page { std::move( o.page ) }\n , freeChunks { o.freeChunks } // You want to copy the free chunks.\n // Why not move them?\n , end { o.end }\n{}\n\nPage&amp; operator=( Page&amp;&amp; o )\...
{ "AcceptedAnswerId": null, "CommentCount": "15", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T14:00:23.123", "Id": "58188", "Score": "5", "Tags": [ "c++", "c++11", "memory-management", "pointers" ], "Title": "Singleton typed memory manager" }
58188
<p>I have this Objective-C code for use in an iOS app that makes a 'bar' on the screen, with a red exclamation mark that flashes in it at random places.</p> <p>Here's what it looks like:</p> <blockquote> <p><img src="https://i.stack.imgur.com/FH5RI.jpg" alt="enter image description here"></p> </blockquote> <p>Head...
[]
[ { "body": "<p>I'm just a beginner myself but I feel like I can point out a few things in this code.</p>\n\n<p>First, I would add some white space at the top of the file here:</p>\n\n<pre><code>#import \"ESFlashingErrorBar.h\"\n#import \"ESThemeManager.h\"\n@implementation ESFlashingErrorBar\n#define kNumOfPoint...
{ "AcceptedAnswerId": "58198", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T14:57:53.287", "Id": "58192", "Score": "12", "Tags": [ "objective-c", "ios", "animation", "graphics" ], "Title": "A flashing ! exclamation ! point ! bar" }
58192
<p>I published a concatenation utility lastly and I feel it could be very good help for many people, but before I promote it, I would like to polish the details as much as I can. So I'll like to ask you to review this less than 300 lines of code.</p> <pre><code>#ifndef THEYPSILON_CONCAT #define THEYPSILON_CONCAT #inc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T20:43:00.063", "Id": "104442", "Score": "3", "body": "Welcome to Code Review! I love it when new users ask such nice questions." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-28T02:58:39.737", "Id":...
[ { "body": "<p>In all, this is a nice piece of work. I have only a few minor points.</p>\n\n<h2>Remove formal name <code>separarator</code> to quiet compiler warnings</h2>\n\n<p>When I compile the code with g++ with maximum warning levels, it complains that the parameter <code>separator</code> is not used in se...
{ "AcceptedAnswerId": "58234", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T16:01:19.557", "Id": "58195", "Score": "11", "Tags": [ "c++", "strings", "c++11", "c++14" ], "Title": "String concatenation utility in C++11" }
58195
<p>Is using a static variable in a lambda function ok, or considered a bad practice? The code below works as intended (fills a vector with consecutive numbers).</p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;algorithm&gt; using namespace std; int main() { vector&lt;int&gt; vec(100)...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T16:24:39.830", "Id": "104402", "Score": "5", "body": "@Avery, C++ is great in that if something appears to work, it still might not always work. That said, this example should just use `std::iota`." }, { "ContentLicense": "C...
[ { "body": "<p>That's exactly what static variables are for - to keep some state between function calls.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T16:27:15.283", "Id": "58203", "ParentId": "58201...
{ "AcceptedAnswerId": "58206", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T16:21:43.087", "Id": "58201", "Score": "17", "Tags": [ "c++", "c++11" ], "Title": "Using a static variable inside a lambda" }
58201
<p>I created a loader animation for an Android app: a simple 3 dots loader.</p> <p>Is this the correct way to animate by using <code>TimerTask</code>?</p> <pre><code>public class ThreeDotsLoader extends View { Paint dot1; Paint dot2; Paint dot3; int defaultColor; int highlightColor; boolean...
[]
[ { "body": "<p>I would avoid \"new Timer();\" for this use case. \nThe timer task it changing the paint object on a thread other than the main UI thread, which is very likely to lead to non-deterministic behavior.</p>\n\n<p>I recommend using an <a href=\"http://developer.android.com/reference/android/animation/O...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T18:16:34.300", "Id": "58207", "Score": "2", "Tags": [ "java", "performance", "android", "animation" ], "Title": "Loader animation using Custom View in Android" }
58207
<pre><code>[Test] public void Post_ReturnsCorrectModel() { var post = new Post { Slug = "continuing-to-an-outer-loop", Title = "Continuing to an outer loop", Summary = "When you have a nested loop, sometimes", Content = "When you have a nested loop, sometimes", PublishedA...
[]
[ { "body": "<ul>\n<li><p>I think the test is reasonably well named (imho).</p></li>\n<li><p>If you assume you write the test against a black box (meaning you don't know how the controller code is implemented) then yes you should compare all properties. Someone could have forgotten to copy a property for example....
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T18:52:24.580", "Id": "58210", "Score": "4", "Tags": [ "c#", "unit-testing", "asp.net-mvc" ], "Title": "Best testing using a mocked repository" }
58210
<p>Here's a partial binomial heap implementation in Haskell (just <code>merge</code> and <code>insert</code>):</p> <pre><code>module BinomialHeap where data BinomialTree a = Tree { key :: a , order :: Integer , subTrees :: [BinomialTree a] ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2018-04-11T14:48:22.990", "Id": "368208", "Score": "0", "body": "It's been almost four years. Do you want to review your own code?" } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T18:57:26.973", "Id": "58211", "Score": "4", "Tags": [ "haskell", "heap" ], "Title": "Binomial Heap in Haskell" }
58211
<p>I implemented the following for Project 3 in <a href="https://projecteuler.net/problem=3" rel="nofollow">Project Euler</a>:</p> <pre><code>--Problem 3. The prime factors of 13195 are 5, 7, 13 and 29. What is the --largest prime factor of the number 600851475143? prime :: Integer -&gt; Bool prime x = prime' x (x `d...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T21:14:02.527", "Id": "104443", "Score": "0", "body": "You sure this isn't an issue with large number? Like an overflow or something like that? Did you try some other primes?" }, { "ContentLicense": "CC BY-SA 3.0", "Creat...
[ { "body": "<p>Your algorithm doesn't scale. In <a href=\"https://codereview.stackexchange.com/a/48185/9357\">this answer</a>, I've outlined the three common strategies for finding the largest prime factor of a number, only one of which is reasonably efficient. You've chosen Option 2 (testing largest candidate...
{ "AcceptedAnswerId": "58252", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T19:36:25.100", "Id": "58215", "Score": "5", "Tags": [ "haskell", "programming-challenge", "primes", "time-limit-exceeded" ], "Title": "Computation for finding the largest p...
58215
<p>I thought up a function that provides types with <code>InputStream</code> and <code>OutputStream</code>:</p> <pre><code>trait Format[A] { def read(i: TypedInput): A def write(o: TypedOutput, a: A) } trait TypedInput { def i: InputStream def reads[A](implicit f: Format[A]) = f.read(this) } trait TypedOutput ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-28T06:44:15.593", "Id": "104495", "Score": "0", "body": "Creating a new object (resp `DataInputStream(i.i)` and `DataOutputStream(o.o)`) does not seem really efficient." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate"...
[]
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T21:09:23.287", "Id": "58219", "Score": "3", "Tags": [ "functional-programming", "scala", "io", "serialization" ], "Title": "Functionally Typed I/O Streams" }
58219
<p>I created an Observable class that allows me to subscribe to a wrapped value. The implementation looks like this:</p> <pre><code>class Observable&lt;ValueType&gt; { typealias DidChangeHandler = (oldValue: ValueType?, newValue: ValueType) -&gt; () // MARK: Properties var value : ValueType { did...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-30T10:57:07.257", "Id": "105012", "Score": "1", "body": "Has there been an update to Swift that I don't know about? Last I checked, there was no way to set access levels..." }, { "ContentLicense": "CC BY-SA 3.0", "Creation...
[ { "body": "<p>You worry about <code>triggerImmediately</code> being too verbose (which can be fixed), yet you have <code>addObserverForOwner</code> as the primary function name, and for me, this is the part that is a bit too verbose.</p>\n\n<p>Since what we're doing with this is so similar to the existing KVO i...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T21:46:14.333", "Id": "58220", "Score": "5", "Tags": [ "swift" ], "Title": "Usability of this Observable class" }
58220
<p>I do not like to use <code>while</code> loops in Ruby. I was wondering how I can generate a "squared sequence" (e.g., squares the first input, then squares the outcome, etc.) in a more idiomatic Ruby way than this one:</p> <pre><code>value = 2 while value &lt; 10000 puts value = value**2 end # =&gt; 4 # 16 ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-29T05:18:51.620", "Id": "104734", "Score": "0", "body": "You could also write, `value = 2; loop do; break if value >= 10_000; puts value = value**2; end`." } ]
[ { "body": "<p>Using <code>while</code> would be idiomatic in almost any language. <code>while</code> is basically <em>the</em> way to iterate, uh, <em>while</em> a condition is true. Hence the name - it's practically plain English.</p>\n\n<p>You can postfix the <code>while</code> and save a couple of lines, but...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T22:26:20.480", "Id": "58223", "Score": "4", "Tags": [ "ruby" ], "Title": "Generating sequence that uses the previous outcome for the current" }
58223
<p>I've decided that I want to take a stab at test first programming. So, before I tackled writing an <code>isPrime</code> function, I wrote this unit test. It's my first and I'm not sure I'm doing this right.</p> <p>I was thinking that I might want to extract the loops to just two methods that I would pass an array t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-28T01:06:19.497", "Id": "104468", "Score": "1", "body": "You are missing BigNotPrime :) - By the way, the term for \"not prime\" is \"composite\" (excluding special cases like 1 which is called a \"unit\" and 0/negative which are reall...
[ { "body": "<p>This is quite an extensive set of tests, as each of the numbers in the list is a test of sorts.</p>\n\n<p>Here are some suggestions:</p>\n\n<ol>\n<li>How about testing negatives that are non-primes?</li>\n<li>Add a set of tests for big non-primes (pseudoprimes ideally)</li>\n<li>Add tests for valu...
{ "AcceptedAnswerId": "58226", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T23:00:56.457", "Id": "58224", "Score": "12", "Tags": [ "c#", "unit-testing", "primes" ], "Title": "Unit Testing for isPrime function" }
58224
<p>This loads a dictionary text file into memory to be used as part of a spell checker. It's part of a larger program, but I wanted general comments so I can clean it up further. </p> <pre><code>#define TABLESIZE 500 #define LENGTH 45 bool load(const char* dictionary) { //initiate hash table node* hashtable[...
[]
[ { "body": "<ul>\n<li><p>Since the function will terminate right away if the file fails to open, <code>hashtable</code> doesn't need to be declared before the check. Do it sometime afterwards, preferably the closest point at which it's used for the first time. This will keep it in the lowest scope possible, wh...
{ "AcceptedAnswerId": "58233", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-27T23:45:09.890", "Id": "58228", "Score": "5", "Tags": [ "c", "linked-list", "file-system", "hash-map" ], "Title": "Dictionary load function using hash table" }
58228
<p>I wrote a C++ function to calculate the binomial coefficient, trying to avoid overflows as much as possible.</p> <pre><code>/*! * @brief Calculates the binomial coefficient indexed by n and k * * This implementation is based on the algorithm described here: http://blog.plover.com/math/choose.html * and the rele...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-28T05:22:13.690", "Id": "104490", "Score": "2", "body": "Just so you know, binomial coefficients have a very naturally occurring lookup table: Pascal's Triangle. Using the triangle is actually a better way to calculate binomial coeffic...
[ { "body": "<p>Mostly minor things, but could still be helpful:</p>\n\n<ul>\n<li><p>Functions should generally be named in a verb form, so rename the function to something like <code>calculate_binomial_coefficient()</code>.</p></li>\n<li><p>This is a little hard to read:</p>\n\n<blockquote>\n<pre><code>if (r_mul...
{ "AcceptedAnswerId": "58307", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-28T01:03:02.773", "Id": "58236", "Score": "10", "Tags": [ "c++", "algorithm", "combinatorics" ], "Title": "Binomial coefficient" }
58236