body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I am trying to implement an expression parser via the shunting yard algorithm about which I learnt here.</p> <p>I am able to get the correct results for the cases I'm testing, but I think it would be better if someone experienced could go through it and verify it. Also, I plan to add more operators, such as '!' (fa...
[]
[ { "body": "<p>Dont do this:</p>\n\n<pre><code>struct numstack\n{\n double n;\n numstack *next;\n}*numtop=0; // &lt;---- WHAT\n // Type and variable declaration all crammed together..\n</code></pre>\n\n<p>Its not as if you need to save space so be clear.</p>\n\n<pre><code>struct Numstack\n{\n ...
{ "AcceptedAnswerId": "42549", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-21T18:19:49.187", "Id": "42448", "Score": "6", "Tags": [ "c++", "algorithm", "math-expression-eval" ], "Title": "Expression parser using the shunting yard algorithm" }
42448
<p>I have written this simple program that is a basically a maths test. I would like to know is there any areas I can improve on and if I have any bad habits that would be useful to break now. I realise I could have written this in the main class, but I was trying to practice implementing other classes, so I tried to u...
[]
[ { "body": "<p><strong>Member Names</strong> - don't use too short names, <code>answer</code> is better than <code>ans</code>; what exactly is <code>att</code>?</p>\n\n<p><strong>Method Names</strong> - method names should be verbs describing <em>what</em> the method does - <code>generateNewSum()</code> is bette...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-21T18:21:31.753", "Id": "42449", "Score": "11", "Tags": [ "java", "quiz" ], "Title": "Maths test program" }
42449
<p>This is a calculator I wrote for a student's project.</p> <p>It still has a problem (one that I know of), where it can't handle inputs of the form <code>2*2*2</code>... (more than one <code>*</code> or <code>/</code> sign). The case <code>2*2</code> was solved in hackish ways.</p> <p>I'd appreciate any remarks or ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-21T19:14:34.723", "Id": "73075", "Score": "0", "body": "This codes doesn't compile for multiple reasons, so I am led to believe this code doesn't work." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-21T20:...
[ { "body": "<h1>Things you did well on:</h1>\n\n<ul>\n<li><p>Organization</p></li>\n<li><p>Use of comments</p></li>\n<li><p>Using <code>switch</code> statements instead of multiple <code>if-else</code>s.</p></li>\n</ul>\n\n<h1>Things that could be improved:</h1>\n\n<h3>Compilation</h3>\n\n<ul>\n<li><p>I couldn't...
{ "AcceptedAnswerId": "42491", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-21T18:23:45.707", "Id": "42450", "Score": "11", "Tags": [ "c", "recursion", "math-expression-eval" ], "Title": "Recursive calculator in C" }
42450
<p>I have been doing some programming 'exercises'. I'm trying to come up with the most efficient algorithm for tree traversal.</p> <p>Consider the following function signature: </p> <pre><code>CNode * CNode::find(int number) const </code></pre> <p>where <code>CNode</code> structure is not organized as a binary sear...
[]
[ { "body": "<blockquote>\n <p>Do you see any way to optimize it further</p>\n</blockquote>\n\n<p>I don't see why you have (i.e. don't think you should have) <code>while (tmp != NULL)</code> at the top:</p>\n\n<ul>\n<li>On entry you know that this != NULL</li>\n<li>You verify that the result won't be NULL before...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-21T20:50:50.163", "Id": "42463", "Score": "2", "Tags": [ "c++", "optimization", "algorithm", "recursion", "tree" ], "Title": "Algorithms for traversing unordered tree" }
42463
<p>I have implemented an user defined colors enumerator, and if is possible I appreciate if I will get a code review. I want to know if my implementation is correctly or must improve it. If there exist a better alternative (color enumerator) to my code which is?</p> <p><strong>Usage example:</strong></p> <pre><code> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2018-04-19T21:40:09.043", "Id": "369792", "Score": "0", "body": "Here is full list of **Background** and **ForeGround** colors.\n[Complete list of WinAPI colors](https://stackoverflow.com/a/49929936/6219626)" } ]
[ { "body": "<blockquote>\n <p>If there exist a better alternative (color enumerator) to my code which is?</p>\n</blockquote>\n\n<p>You should use the constants defined in a Windows header file named <code>Wincon.h</code>, which are as follows:</p>\n\n<pre><code>#define FOREGROUND_BLUE 0x0001 // text color ...
{ "AcceptedAnswerId": "42469", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-21T22:03:52.877", "Id": "42467", "Score": "3", "Tags": [ "c++", "console", "windows", "enum" ], "Title": "User-defined color implementation in windows console" }
42467
<p>I'm working on my own little library on top of jQuery to make working with tabular data easier.</p> <p>Currently my script takes user clicks in a table's thead element and creates an array of all of the table cells in that column, and gives the user an animation of changing the background color of the td elements i...
[]
[ { "body": "<p>From a once over:</p>\n\n<ul>\n<li>I would call <code>tds</code> -> <code>$td</code>, it shows the reader that its the result of a td query</li>\n<li><p>There is some duplication in your dealing with <code>shiftKey</code>, you could try this:<br></p>\n\n<pre><code>if (!e.shiftKey) {\n //if no shi...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-21T22:08:13.503", "Id": "42468", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "Table manipulation/data extraction" }
42468
<p>I hope this isn't getting annoying, but I've asked a lot of questions about improving my game lately:</p> <ul> <li><a href="https://codereview.stackexchange.com/questions/31124/how-can-i-improve-my-game-project-design">How can I improve my game project design?</a></li> <li><a href="https://codereview.stackexchange....
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T16:51:36.060", "Id": "73541", "Score": "0", "body": "My strategy so far has been to go ahead and use the main game loop, rather than avoiding it. This doesn't mean I put all my code there, however. I'm really doing a lot of it itera...
[ { "body": "<p>I haven't done enough XNA to really get to the core of this question, I hope to see this reviewed from an XNA perspective.</p>\n<p>I'll only make a few observations about the <code>Program</code> class.</p>\n<h1>Main()</h1>\n<p>Looking at the <code>Main</code> method and the <code>Program</code> c...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-21T22:40:18.727", "Id": "42472", "Score": "4", "Tags": [ "c#", "dependency-injection", "inheritance", "xna" ], "Title": "Improving XNA's default project template" }
42472
<p>I'm looking for general advice on my code on the following problem:</p> <blockquote> <p>Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:</p> <p>1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...</p> <p>By considering the terms in the Fib...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-21T23:01:49.217", "Id": "73130", "Score": "1", "body": "Could you give some background on the `Problem<T>` class? Where is it from, what does it do? Is there a `main()` method somewhere? Thanks." }, { "ContentLicense": "CC BY-S...
[ { "body": "<p>So a fair amount of Java8 is new to me, including the Stream API, which is, in essence, why this review is useful to me too. Bear with me...</p>\n\n<h2>Readability</h2>\n\n<p>You say <em>\"my main concern is readability\"</em>. Now that I have spent some time looking in to what you are doing, what...
{ "AcceptedAnswerId": "42544", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-21T22:44:14.697", "Id": "42473", "Score": "18", "Tags": [ "java", "project-euler", "java-8" ], "Title": "Project Euler \"Even Fibonacci numbers\" in Java 8" }
42473
<blockquote> <p>Given an infinite stream with the property, such that after all 0's there are only all 1's, find the index of the last 0.</p> </blockquote> <p>I'm looking for code review, best practices, optimizations etc. Verifying complexity to be O (log n) where n is the first 1 encountered in the search (not the...
[]
[ { "body": "<p>You might have misunderstood the program requirements: an ArrayList is not an <a href=\"https://www.google.com/search?q=java+stream\" rel=\"nofollow noreferrer\">infinite Stream</a>.</p>\n\n<hr>\n\n<p>If you don't want a stream and do instead want to assume that multiple-threads are adding to it t...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-21T23:17:31.143", "Id": "42475", "Score": "2", "Tags": [ "java", "binary-search", "stream" ], "Title": "Find last zero in infinite stream of 0's followed by 1's" }
42475
<p>I have attempted to make a basic version [not complete] of the <code>std::basic_string</code> type in C++, and I would like to make sure that I have done everything correctly, and efficiently, as I can be prone to leaking memory in my programs.</p> <p>Note: I also created an <code>allocator</code> class, which work...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T17:41:58.373", "Id": "73211", "Score": "0", "body": "Read: http://stackoverflow.com/a/228797/14065" } ]
[ { "body": "<p>First stop using underscores like that.</p>\n\n<ol>\n<li>Double underscore is always reserved for the implementation. </li>\n<li>A leading underscore followed by a capital letter is always reserved for the implementation.</li>\n</ol>\n\n<p>There are a couple of more rules. But basically unless yo...
{ "AcceptedAnswerId": "42523", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-21T23:21:08.610", "Id": "42477", "Score": "4", "Tags": [ "c++", "strings", "reinventing-the-wheel" ], "Title": "basic_string implementation" }
42477
<p>I'm trying to implement a TcpListener using the TPL. I'm not sure If I'm doing everything correctly though. I'm trying to keep the code as small as possible as well. It all works fine in a console application.</p> <pre><code>public async Task RunAsync(CancellationToken cancellationToken) { var listener = new Tc...
[]
[ { "body": "<ol>\n<li><p>If you immediately <code>await</code> everything, you're not going to get any concurrency. This means that at any moment, there can be only one connection to this listener. Is this intentional?</p></li>\n<li><p>Because of the way TCP works, <a href=\"http://blog.stephencleary.com/2009/05...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-21T23:51:36.733", "Id": "42480", "Score": "4", "Tags": [ "c#", ".net", "async-await", "tcp" ], "Title": "Async TcpListener" }
42480
<p>Can you please review my PHP script below? It is for a contact form. Am I breaking any rules? Does it seem okay to you?</p> <pre><code>&lt;?php session_start(); if ($_SERVER['REQUEST_METHOD'] == 'POST'){ ob_start(); if(isset( $_REQUEST['name'], $_REQUEST['email'], $_...
[]
[ { "body": "<p>Using the <code>token</code> for CSRF protection and spam prevention is a good idea, especially for a form that will be generating e-mail.</p>\n\n<p>This is puzzling: <code>&lt;input name=\"ajax\" type=\"hidden\" value=\"1\"&gt;</code>. If a very basic, non-JavaScript-enabled user agent submits t...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T00:24:31.233", "Id": "42481", "Score": "3", "Tags": [ "php", "html", "form", "email" ], "Title": "Is this contact form code breaking any rules?" }
42481
<p>Is there a faster way to compute the bounding area between 2 points?</p> <pre><code>// Minified Version public static Rectangle computeBounds(Point2D.Double p1, Point2D.Double p2) { double dx = p2.x - p1.x, dy = p2.y - p1.y; return new Rectangle((int) (dx &lt; 0 ? p2.x : p1.x), (int) (dy &lt; 0 ? p2...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T05:32:13.957", "Id": "73175", "Score": "0", "body": "Why not use a Rectangle2D, by the way?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T05:34:30.270", "Id": "73176", "Score": "0", "bod...
[ { "body": "<p>You're doing two tests to compare <code>p1.x</code> with <code>p2.x</code>:</p>\n\n<ul>\n<li>One here: <code>int x = (int) (dx &lt; 0 ? p2.x : p1.x);</code></li>\n<li>Another here (implicit in the <code>Math.abs</code> method): <code>int w = (int) Math.abs(dx);</code></li>\n</ul>\n\n<p>You also ha...
{ "AcceptedAnswerId": "42495", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T01:05:19.263", "Id": "42484", "Score": "5", "Tags": [ "java", "performance", "awt" ], "Title": "Compute bounding rectangle given 2 points quickly and efficiently" }
42484
<p>My goal is to save space occupied by 2D array (sea) that has 3 different values.</p> <pre><code>Ocean sea; //Ocean class has member 'private int[][] oceanMatrix;' public final static int EMPTY = 1; public final static int SHARK = 2; public final static int FISH = 3; </code></pre> <p>by compressing it and place in...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T03:12:26.353", "Id": "73162", "Score": "0", "body": "You say `//i&j are width & height of a 2d array` .... but I say [I&J are Fish in the Ocean](http://www.za.all.biz/img/za/catalog/4386.jpeg) ;-)" }, { "ContentLicense": "CC...
[ { "body": "<p>This is an interesting problem. Your code looks effective, and there is little that sticks out at me as being a performance problem, except that I feel the two-array RLE is not the most efficient mechanism.</p>\n\n<p>There are ways that you can reduce the code size, but I don't think that will imp...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T01:24:01.627", "Id": "42488", "Score": "6", "Tags": [ "java", "optimization", "performance" ], "Title": "Save space occupied by 2D array" }
42488
<p>I have regrettably been away from C programming for a very long time, so I'd like to get a quick code review of a first proof of concept, before I get too far into adding capabilities, using the getopt library for arguments, alternate output and input character sets, a PolarSSL implementation, and so on and so forth...
[]
[ { "body": "<h1>Things you did well on:</h1>\n\n<ul>\n<li><p>Looks like you weren't too rusty based on this code. Looks very nice organizationally.</p></li>\n<li><p>You <code>return</code> different values for different error conditions.</p></li>\n</ul>\n\n<h1>Things you could improve on:</h1>\n\n<h3>Standards<...
{ "AcceptedAnswerId": "42494", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T04:13:09.537", "Id": "42492", "Score": "8", "Tags": [ "c", "security", "cryptography", "cli", "openssl" ], "Title": "OpenSSL PBKDF2-HMAC-SHAx proof of concept" }
42492
<p>The old function was:</p> <pre><code>&lt;?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" ...
[]
[ { "body": "<p>PHP is not my area of expretise, so just some generic notes:</p>\n\n<ol>\n<li><p>The function create a new MySQL connection on every call which could be a bottleneck in your application. You could use <a href=\"http://www.php.net/manual/en/mysqli.persistconns.php\" rel=\"nofollow\">persistent conn...
{ "AcceptedAnswerId": "45128", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T08:54:42.233", "Id": "42497", "Score": "5", "Tags": [ "php", "mysqli" ], "Title": "Update PHP function GetSQLValueString" }
42497
<p>I've been reading a lot about repository patterns these days. At first, the pattern seemed easy.</p> <p>Most of the examples I read over the web use an ORM like below.</p> <pre><code>interface MemberRepositoryInterface { public function find($id); } class MemberRepository implements MemberRepositoryInterface ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T10:00:50.217", "Id": "73181", "Score": "0", "body": "What's the purpose of `Model_Member` (and the difference to `MemberModel`)?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T10:30:02.140", "Id"...
[ { "body": "<p>You are already using the repository of Kohana. They hide their repository behind static factory methods though (copied from the <a href=\"http://kohanaframework.org/3.3/guide/orm/using#finding-an-object\" rel=\"nofollow\">documentation</a>):</p>\n\n<pre><code>// Find user with ID 20\n$user = ORM:...
{ "AcceptedAnswerId": "42560", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T09:39:37.610", "Id": "42498", "Score": "4", "Tags": [ "php", "design-patterns" ], "Title": "Repository pattern with plain old PHP object" }
42498
<p>I need to wait for short intervals of time in my program, but I really don't want to include <code>unistd.h</code> just to use <code>sleep</code>, so I'm doing it this way:</p> <pre><code>int main() { for(int i=0; i&lt;=100000000000; i++); // &lt;----- note that the loop doesn't do anything return 0; } </co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T15:42:54.740", "Id": "73194", "Score": "10", "body": "See also [What are trade offs for “busy wait” vs “sleep”?](http://stackoverflow.com/questions/1107593/what-are-trade-offs-for-busy-wait-vs-sleep)" }, { "ContentLicense": ...
[ { "body": "<p>The biggest problem with using a for-loop to do this is that you are wasting CPU power.</p>\n\n<p>When using <code>sleep</code>, the CPU can, in a sense, take a break (hence the name \"sleep\") from executing your program. This means that the CPU will be able to run other programs that have meanin...
{ "AcceptedAnswerId": "42508", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-02-22T14:58:38.780", "Id": "42506", "Score": "35", "Tags": [ "c", "performance" ], "Title": "Using a for-loop or sleeping to wait for short intervals of time" }
42506
<p>This is the C++ code of my implementation of Knuth's algorithm M that produces mixed-radix numbers:</p> <pre><code>#include "visit.h" void algorithmM(vector&lt;int&gt;&amp; m) { m.insert(m.begin(),2); const int n=m.size(); vector&lt;int&gt; a(n,0); M2: visit(false,a); int j=n-1; M4: if (a[j]==m[j]-...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T18:02:29.497", "Id": "73220", "Score": "0", "body": "For the C++ code, I'd recommend indenting by four spaces as it's more readable. Two isn't enough, plus some of your curly braces are placed strangely." }, { "ContentLicen...
[ { "body": "<p>Below is a more idiomatic to Haskell version that still follows your original imperative logic. I know elsewhere on SO you have been shown how to do this efficiently and functionally. I did this to show what could be done if the design requirements remained in place.</p>\n\n<p>This version is 52 l...
{ "AcceptedAnswerId": "45349", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T15:08:32.760", "Id": "42509", "Score": "3", "Tags": [ "optimization", "algorithm", "haskell" ], "Title": "Knuth's algorithm M that produces mixed-radix numbers" }
42509
<p>I am a very beginning in PHP and Design Patterns. I have been studying the amazing Head First Design patterns. So, I have been trying to translate the original into PHP. The class is working well, however, I would like to ask:</p> <ol> <li><p>Is this considered good PHP?</p></li> <li><p>Someone mentioned that this ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T15:26:22.883", "Id": "73190", "Score": "2", "body": "You are not really implementing the Strategy Pattern here. But don't feel bad, you are actually doing something even better (it's *almost* Dependency Injection, with a touch of Co...
[ { "body": "<p>Syntax errors aside, there's a major pitfall in your design choices that you need to watch out for. Namely, if you want to figure out if your animal is capable of some behaviour, you'll need to add an identifier function for every animal. This will limit you down the road.</p>\n\n<p>For example, s...
{ "AcceptedAnswerId": "73657", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T15:14:53.883", "Id": "42511", "Score": "4", "Tags": [ "php", "design-patterns", "beginner" ], "Title": "Is this a good PHP strategy pattern?" }
42511
<p>I'd made a project using pygame in python around 3 months ago. This was my first big project after I started learning how to program in college.</p> <p>Now I'd like to know just how good my programming syntax and style is. Whether there are any weird irritants that simply defy the unwritten rules of programming in ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T16:46:14.653", "Id": "73200", "Score": "4", "body": "The code seems to lack comments and has very high cyclomatic code complexity. Without debugging and scraping in the code, it is very hard to read. For example. if (1<=X1<=8 and 1<...
[ { "body": "<h2>Pythonic</h2>\n\n<p>Basically, a code is pythonic when <a href=\"http://blog.startifact.com/posts/older/what-is-pythonic.html\">it uses common Python idioms</a>. In Python, there is usually one (and only one) way to do things, so you should try to know what this thing is, and use it. You won't fi...
{ "AcceptedAnswerId": "42962", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T15:57:59.190", "Id": "42514", "Score": "10", "Tags": [ "python", "timer", "pygame", "chess" ], "Title": "First Chess project" }
42514
<p><strong>C# code</strong></p> <pre><code>static int KEY_NOT_FOUND = -1; private void Form1_Load(object sender, EventArgs e) { int[] A = createArray(1, 100000); Stopwatch sw1 = performCalcs(1, A); Stopwatch sw2 = performCalcs(2, A); TimeSpan lag = TimeSpan.FromTicks(sw1.Elapsed.Ticks - sw2.Elapsed.T...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T17:58:14.783", "Id": "73216", "Score": "0", "body": "Pure speculation: I'm guessing it has something to do with compiler optimization, and you could verify by examining the CLR that each generates. Microsoft had experience in writin...
[ { "body": "<p>Now that we have code to review - the first issue that I see is that you are not comparing identical source code, and that makes it impossible to get an accurate benchmark. The problem is likely this line in the VB source that isn't in the C# source:</p>\n\n<pre><code>Return imid 'Never reached; ...
{ "AcceptedAnswerId": "42534", "CommentCount": "14", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T17:40:20.233", "Id": "42522", "Score": "5", "Tags": [ "c#", "performance", "recursion", "vb.net" ], "Title": "Relevant performance difference C#-VB.NET - Integer Division"...
42522
<p>I'm trying to solve <a href="http://www.gutenberg.org/files/27635/27635-h/27635-h.htm#p1" rel="nofollow">the Reve's puzzle</a> (a variant of the <a href="https://en.wikipedia.org/wiki/Tower_of_Hanoi" rel="nofollow">Tower of Hanoi puzzle</a> with four pegs). This is what I've come up with so far:</p> <pre><code>def ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T19:08:12.763", "Id": "73242", "Score": "1", "body": "one question that comes immediately to mind is \"are you trying to actually solve? or just find the __minimum number of moves__ to solve?" } ]
[ { "body": "<p>if you are just trying to find the <strong>minimum number of moves</strong> and not necessarily a solution you can use the <a href=\"http://en.wikipedia.org/wiki/Tower_of_Hanoi#Frame.E2.80.93Stewart_algorithm\" rel=\"nofollow\">Frame–Stewart algorithm</a> that you linked to earlier</p>\n\n<p>this ...
{ "AcceptedAnswerId": "42527", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T18:53:39.173", "Id": "42524", "Score": "7", "Tags": [ "python", "performance", "algorithm", "tower-of-hanoi" ], "Title": "Solving the Reve's puzzle" }
42524
<p>Is there a more cleaner approach to this? I'm doing the String calculator Kata posted by Roy Osherove. I realized that my calculator has no way of clearing out a previous expression after calling add. How can I handle this, and also how can I cut down the number of methods?</p> <p>Here's a valid string: <code>calc....
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T17:48:42.883", "Id": "73428", "Score": "0", "body": "so, delimiter is set only on the first `add` (or in the constructor)?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T17:52:16.190", "Id": "734...
[ { "body": "<p>Some of the code seems to be missing - I can't see where you assign <code>@numbers</code>. I'm going to assume that it is set to <code>\"//+\\n1+2\"</code> or the like.</p>\n\n<p><strong>DRY</strong> - twice in your code you calculate the delimiter (<code>@numbers[2,1]</code>), either pass it as a...
{ "AcceptedAnswerId": "42612", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T18:57:32.697", "Id": "42525", "Score": "2", "Tags": [ "ruby" ], "Title": "Refactoring a Delimiter" }
42525
<p>I've written some Python code to generate a random hexadecimal string using 31 playing cards drawn without replacement (so no card appears more than once). This is sufficient to provide more than 160 random bits, which is considered sufficient for a bitcoin private key.</p> <p>I'm interested to know whether anythin...
[]
[ { "body": "<pre><code>from math import factorial\n\nfactorial52 = factorial(52)\n</code></pre>\n\n<p>Why do this? Its probably better to just call <code>factorial(52)</code> in the next line</p>\n\n<pre><code>upperLimit = factorial52//factorial(52-31) - 1\n</code></pre>\n\n<p>The python convention is make const...
{ "AcceptedAnswerId": "42554", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T19:24:19.083", "Id": "42526", "Score": "10", "Tags": [ "python", "python-3.x", "random", "playing-cards", "bitcoin" ], "Title": "Produce bitcoin private key from 31 pla...
42526
<p>I would like to execute code for many views whenever the window is unloaded.</p> <p>For instance, I could have something like this in a view's initialize:</p> <pre><code>initialize: function() { $(window).unload(this.stopListening.bind(this)); } </code></pre> <p>I'm wondering if it would be better to have a m...
[]
[ { "body": "<p>An opinion question, always tricky;</p>\n\n<p>I think we can all agree that the second approach is not <a href=\"http://en.wikipedia.org/wiki/KISS_principle\" rel=\"nofollow\">KISS</a> and requires more bandwidth to download to the browser. As far as I can tell, this will not save any memory eithe...
{ "AcceptedAnswerId": "42657", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T20:13:39.123", "Id": "42531", "Score": "2", "Tags": [ "javascript", "jquery", "backbone.js", "event-handling" ], "Title": "Proper techniques for allowing many views to subs...
42531
<p>I have this batch that builds some projects using msbuild.</p> <p>What I want to do is to skip building my-last.proj if any of the above builds fail: my-proj1.proj to my-proj5.proj using environment variables.</p> <p>I'm sure that there is another cleaner way to do this, but so far I just can't figure it out.</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T20:48:38.200", "Id": "73277", "Score": "1", "body": "Welcome to Code Review! It looks like you have figured out exactly what this site is about. You just passed the \"first post\" test with ease!" }, { "ContentLicense": "CC ...
[ { "body": "<p>You probably meant <code>set %BUILDFAILEDxx%=1</code>? <code>/p</code> is for prompting interactively (or reading from a file).</p>\n\n<p>Otherwise, except a minor typo <code>%BUILDFAILED32%</code> instead of just <code>%FAILED32%</code> (and same for 64bit builds), this looks good (and \"clean\")...
{ "AcceptedAnswerId": "42542", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T20:30:13.933", "Id": "42536", "Score": "3", "Tags": [ "batch" ], "Title": "Msbuild batch - if any build fails than skip the last one" }
42536
<blockquote> <p>Write the program <code>expr</code>, which evaluates a reverse Polish expression from the command line, where each operator or operand is a separate argument.</p> <p>For example:</p> <pre><code>expr 2 3 4 + * </code></pre> </blockquote> <p>There are 4 files:</p> <p><code>calc.c</code></p> <pr...
[]
[ { "body": "<h2>What you did well</h2>\n\n<p>Taking advantage of the shell to split your expression into tokens is smart. It saves you from the trouble of having to write a tokenizer.</p>\n\n<p>Beware, though, of a usability issue with Unix shells, where <code>*</code> and <code>\\</code> have special significa...
{ "AcceptedAnswerId": "43055", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T20:37:21.087", "Id": "42537", "Score": "7", "Tags": [ "c", "beginner", "console", "math-expression-eval" ], "Title": "Command line reverse polish calculator" }
42537
<p>For practice I decided that I wanted to write an animation class for SpriteSheets. The problem is that a single Sprite can have different widths depending on the action they are drawn to act. A tool called <a href="http://spritesheetpacker.codeplex.com/" rel="nofollow noreferrer">Sprite Sheet Packer</a> creates a Ma...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-01-30T06:28:06.200", "Id": "291232", "Score": "0", "body": "If you're using Google Guava, please state so and add the tag [tag:guava]." } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T20:39:38.187", "Id": "42538", "Score": "2", "Tags": [ "guava", "kotlin", "yaml" ], "Title": "Converting SpriteSheet Metadata .txt to .yaml" }
42538
<p>I have two files. </p> <ol> <li>File 1. Has a list of all the dictionary words </li> <li>File 2. Has a list of all prepositions.</li> </ol> <p>I want to remove all the prepositions from the dictionary. I want to reduce the number of lines in my code and also make it more elegant, idiomatic and readable. </p> <pre...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T06:26:44.467", "Id": "73486", "Score": "0", "body": "I ran some benchmarks that I reported in my answer." } ]
[ { "body": "<p>You can do this in Ruby with very little code. Here's one way:</p>\n\n<pre><code>DICT_FNAME = \"#{path}\" + \"dictionary.txt\"\nNEW_DICT_FNAME = \"#{path}\" + \"new_dictionary.txt\"\nPREP_FNAME = \"#{path}\" + \"prepositions.txt\"\n\nall_words = File.read(DICT_FNAME).split($/).map(&...
{ "AcceptedAnswerId": "42619", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T20:50:35.883", "Id": "42539", "Score": "3", "Tags": [ "ruby" ], "Title": "Removing list of words from a text file in Ruby" }
42539
<p>I need to implement something like "attached properties" from WPF that targets WinForms.</p> <p>What I came up with seems to work. Can you find any issues with it? The helper class and example are shown below.</p> <ul> <li>Not thread-safe since all access should be performed from the UI thread.</li> <li>Attach a v...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T20:36:37.973", "Id": "73280", "Score": "0", "body": "Whats the point if you don't have the databinding and change notification?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T20:37:58.550", "Id":...
[ { "body": "<h2>WinForms is not WPF.</h2>\n<p>Sad, boring truth. The correct way of extending WinForms controls is, as was mentioned, through inheritance.</p>\n<p>What you've got here is a set of <em>extension methods</em> in a dual-purpose <code>static</code> class that's asking for trouble in the sense that it...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T20:29:58.110", "Id": "42540", "Score": "3", "Tags": [ "c#", "winforms" ], "Title": "Naive implementation of attached properties for WinForms" }
42540
<p>I am trying to implement an AngularJS directive that would count the number of characters entered into a textarea and display it to the user. </p> <p><strong><em>Note</strong>: it will actually become much more complex later on and will become a full-fledged component that will be similar to the js component used b...
[]
[ { "body": "<p>Massive overkill indeed,</p>\n\n<pre><code>&lt;span&gt;{{name.length}}&lt;/span&gt;\n</code></pre>\n\n<p>will do the trick.</p>\n\n<p>On the whole, I am not sure why you would use Angular to write an editor if you are not an expert in Angular. It adds a layer of complexity and eats into performanc...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T21:17:33.793", "Id": "42543", "Score": "4", "Tags": [ "javascript", "html", "angular.js" ], "Title": "Simplifying an AngularJs directive that counts the number of characters enter...
42543
<p>I have the following scenario:</p> <p>The (web-) application is built with Java/Spring. I have several REST-endpoints which deliver data prepared to be consumed by a frontend by <code>datatables.net</code>. Each of this endpoint has a somehow similar signature (sEcho, iDisplayStart, iDisplayLength etc.) which are s...
[]
[ { "body": "<ol>\n<li><p>Actually #1 is called smurf naming (<a href=\"https://softwareengineering.stackexchange.com/q/191929/36726\">here is a question about it on Programmers.SE</a>). </p>\n\n<p>One thing to consider: Do you have to work with more than one <code>ViewOptions</code> at the same time (or at the s...
{ "AcceptedAnswerId": "42575", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T21:26:19.163", "Id": "42546", "Score": "2", "Tags": [ "java", "spring" ], "Title": "Class naming conventions" }
42546
<p>I have written a script that allows a user to walk around a dungeon pick up gold and once they have picked it all up they can exit the game through an exit.</p> <p>What I am doing now is writing a bot to do the same. So far I have come up with a 'stupid' bot that is based mainly on randomness. The bot has has actio...
[]
[ { "body": "<h3>Overall</h3>\n<p>I think you have too much code in the main method. You should split that into more digestible segments. Perhaps some more methods in your <code>GameLogic</code> class (which probably should be split into one <code>Game</code> class and one <code>GameBot</code> / <code>Player</cod...
{ "AcceptedAnswerId": "42551", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T21:54:57.977", "Id": "42548", "Score": "11", "Tags": [ "java", "game", "ai", "cli" ], "Title": "AI bot Java dungeon game" }
42548
<p>I got a random image rotator working by using the following script (<a href="http://painfulmouth.com/index4.php" rel="nofollow">demo</a>). But I was told that it is a bad practice to extend <code>Array.prototype</code>. And it does. It conflicts with the chained select box unless I modify the selected box script. So...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T23:35:25.227", "Id": "73332", "Score": "1", "body": "Don't forget to declare your variables, `i` is global. Also literal syntax is always preferred, so `[]` instead of `new Array()`." } ]
[ { "body": "<p>My advice is to use a known shuffle algorithm for this. </p>\n\n<p>This stackoverflow answer describes the Fisher-Yates shuffle and provides a function for you to use.</p>\n\n<p><a href=\"https://stackoverflow.com/a/2450976/423413\">https://stackoverflow.com/a/2450976/423413</a></p>\n\n<p>Bottom ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-22T22:05:23.553", "Id": "42550", "Score": "0", "Tags": [ "javascript", "jquery", "array" ], "Title": "Trying to convert an extended Array.prototype to a function" }
42550
<p>I have written the following function to concatenate the parts of a name to produce the full name:</p> <pre><code>/** * Returns the full name of the Person. * @param boolean $includeTitle Whether to include the Person's title. * @param boolean $includeMiddleNames Whether to include the Person's middle names. * ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T00:32:26.283", "Id": "73348", "Score": "0", "body": "Welcome to Code Review! Just wanted to tell you that it's a nice little first-post you have here. It seems like you have understood exactly what this site is about." } ]
[ { "body": "<p>I assume the class this method resides in represents a person's full name (and title). </p>\n\n<p>Two remarks before suggesting major refactorings:</p>\n\n<ul>\n<li>You are using a getter <code>getTitle</code> and direct access to <code>$this-&gt;title</code>: stick for one. Usually I prefer to us...
{ "AcceptedAnswerId": "42583", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T00:19:58.820", "Id": "42555", "Score": "5", "Tags": [ "php", "strings" ], "Title": "String concatenation of name parts" }
42555
<p>I'm creating a PHP website for a non-profit. They have some restrictions (no MySQL or pre-installed CMS) so I'm creating a CSS menu displayed by an unordered list where all of the elements are stored in a multi-dimensional array.</p> <p>I've gotten it to work but being new to PHP, I'm certain it's not optimized to ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T00:32:44.553", "Id": "73350", "Score": "0", "body": "Welcome to Code Review! Just wanted to tell you that it's a nice little first-post you have here. It seems like you have understood exactly what this site is about." } ]
[ { "body": "<p>I'm not sure for optimization but for readability and maintenance I would use a Class and create the menu items as objects instead of multi-dimension arrays.</p>\n\n<pre><code>class MenuItem {\n\n protected $id;\n protected $name;\n protected $url;\n protected $level;\n protected $seq;\n pro...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T00:21:13.290", "Id": "42556", "Score": "3", "Tags": [ "php", "html", "array" ], "Title": "Display PHP Menu Stored in an Array and Looped" }
42556
<p>Here is an "enhanced" Listview class. You can just add it your project and you're good to go. Most of the code came from here and there. It's not perfect by any means, so any input is appreciated.</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; usi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T22:58:27.630", "Id": "73464", "Score": "0", "body": "why two column sorter references? lvwColumnSorter = new ListViewColumnSorter();this.ListViewItemSorter = lvwColumnSorter; why not just set thisListViewColumnSorter = new ListView...
[ { "body": "<h3>Random observations...</h3>\n<p>Why is the <code>ListViewColumnSorter</code> class <code>partial</code>?</p>\n<p><strong>Compare</strong></p>\n<p>I think the code could get clearer here. First thing I'd address, I'd declare a <code>int result;</code> and <code>return</code> only once.</p>\n<p>The...
{ "AcceptedAnswerId": "42778", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T01:12:59.313", "Id": "42559", "Score": "1", "Tags": [ "c#", "winforms" ], "Title": "Winforms Enhanced ListView Class" }
42559
<p>I wrote this quick script to convert a genotype file into a BED file. Running it seems to be taking a very long time. </p> <pre><code>#BED file format #http://genome.ucsc.edu/FAQ/FAQformat.html#format1 #1.chrom - The name of the chromosome (e.g. chr3, chrY, chr2_random) or scaffold (e.g. scaffold10671). #2.chromSt...
[]
[ { "body": "<p>I do not know python, so I should probably restrain from answering. But my initial observation by looking at your code is the repeated call to <code>listToRange</code> in the last <code>for</code> loop.</p>\n\n<p>We can also skip the <code>if len() &gt; 1</code>.</p>\n\n<h3><em>Rewrite:</em></h3>\...
{ "AcceptedAnswerId": "42566", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T01:21:15.310", "Id": "42561", "Score": "3", "Tags": [ "python", "performance", "beginner" ], "Title": "Speed up file format conversion" }
42561
<p>The Wikipedia article on the <a href="http://en.wikipedia.org/wiki/Union_find" rel="nofollow">union find problem</a> gives a very simple implementation, which I ported to C# and tested.</p> <p>I know that the code should be, in the aggregate, asymptotically almost linear. But is it a practical implementation? Are t...
[]
[ { "body": "<ol>\n<li><p>If I read the wikipedia article correctly then the algorithm should have amortized constant cost - and you have implemented it pretty much 1:1. Given that with your implementation you always start with disjoint nodes and any call to any of the public methods ends up calling <code>Find</c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T04:26:45.033", "Id": "42573", "Score": "6", "Tags": [ "c#", "algorithm", "set", "union-find" ], "Title": "UnionFind implementation" }
42573
<p>I'm building a binary tree.</p> <p>Example: key AAAA1.ETR, value 1.</p> <p>I'm reading files with this structure:</p> <pre><code>DataLength Block-SequenceNummer FLag Start Data Ende 4 Bytes 8 Bytes 1 Byte S Datalength E </code></pre> <p>Data can be compressed or uncompressed (this is ...
[]
[ { "body": "<p>Just a few tidbits (mainly about error handling):</p>\n\n<ul>\n<li><a href=\"https://stackoverflow.com/questions/1941323/always-check-malloced-memory\">Depending on the architecture</a>, you may want to check whether your <code>malloc</code>s return <code>NULL</code>. It is generally not useful th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T07:13:40.620", "Id": "42577", "Score": "4", "Tags": [ "c", "tree", "csv" ], "Title": "Reading messages with binary tree" }
42577
<p>I have an array of integers and a number <code>n</code>. I want to sum the elements of the array and return the index where the sum passes <code>n</code>, <em>as efficiently as possible</em>.</p> <p>For example, assume:</p> <pre><code>theString = "6-7-7-10-7-6" theNumber = 33 expected result: 5 </code></pre> <p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T11:09:41.467", "Id": "73655", "Score": "0", "body": "1. Is `theString` always stored in a String format \"x-x-x\"? Where does it come from? 2. Rough idea how big `theString` is? Rough idea how big `theNumber` generally will be? 3. H...
[ { "body": "<p>I'm not sure what you mean by \"This does the trick but not very efficiently\". I don't really see a way to make the algorithm more efficient, as it is just making a single pass over the array and exits early when it gets the answer. If the input is really long, you could convert it to a byte arra...
{ "AcceptedAnswerId": "42629", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T08:54:05.427", "Id": "42580", "Score": "6", "Tags": [ "array", "vba" ], "Title": "Return index of array where sum first passes n" }
42580
<p>While trying to create an "admin" backend (to allow for CMS like functionality) to a site using AngularJS on the frontend, I came across an issue with routes.</p> <p>In order to allow the admin to create new content, ie install new component (view/controller), change menu item href locations etc, I would have to go...
[]
[ { "body": "<p>I don't think Angular has such CMS functions. Writing your own was probably the right call.</p>\n\n<p>The little code you provided is well written, JsHint could not find any fault and it is well commented.</p>\n\n<p>We can give more valuable feedback when you provide unsanitized code samples ;)</p...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T11:10:38.120", "Id": "42581", "Score": "8", "Tags": [ "javascript", "angular.js" ], "Title": "Dynamic routing with lazy load controllers" }
42581
<p>I was working with <a href="http://www.codechef.com/problems/FCTRL/" rel="nofollow">this</a> problem, which is to find the number of zeros at the end of any factorial.</p> <p>Here's my solution:</p> <pre><code>#include&lt;bits/stdc++.h&gt; using namespace std; int main(){ int numCases,num,zeroCount=0,mulFive,...
[]
[ { "body": "<p>There is a problem with your solution for large numbers ( >= 5^13 to be exact) because <code>mulFive=mulFive*5;</code> will go negative as the <code>int</code> overflows. </p>\n\n<p>To protect against this, you could do </p>\n\n<pre><code> while(num/5!=0)\n {\n zeroCount=zeroCount+ (num/5);\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T11:29:08.640", "Id": "42582", "Score": "3", "Tags": [ "c++", "algorithm", "mathematics" ], "Title": "Number of zeroes at the end of a factorial" }
42582
<p>Kotlin is an OSS statically typed programming language that runs on the JVM and also can be compiled to JavaScript or directly to native binaries. The language is inspired by existing languages such as Java, C#, JavaScript, Scala, and Groovy. It's developed by JetBrains.</p> <h2>Background</h2> <p><a href="https:/...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T12:23:24.013", "Id": "42584", "Score": "0", "Tags": null, "Title": null }
42584
Kotlin is a statically typed programming language that compiles to JVM bytecode, JavaScript, or native binaries.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T12:23:24.013", "Id": "42585", "Score": "0", "Tags": null, "Title": null }
42585
<p>Program must to find duplicate files (by content) in a given directory(and subdirectories).</p> <p>I collect all data in <code>Map&lt;Long, ArrayList&lt;String&gt;&gt; map</code> where Key is the size of file and Value is the List of paths to files with the same size.</p> <pre><code>public static void main(String[...
[]
[ { "body": "<p>Another approach: Currently if you have three big files (with the same size) the algorithm will compare A with B and A with C. It reads A twice which could be avoided. Read each file once, store a hash value (MD5, SHA1, etc.) of the content and compare the hash only.</p>\n\n<p>About the current im...
{ "AcceptedAnswerId": "42588", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T13:03:30.490", "Id": "42587", "Score": "7", "Tags": [ "java", "optimization", "performance" ], "Title": "Optimization of file scanner" }
42587
<p>I have written an implementation of the merge sort algorithm in Java.</p> <p>Here is the <code>MergeSort</code> class that I created.</p> <pre><code>public class MergeSort{ public static void sort(Comparable[] a){ Comparable[] b = new Comparable[a.length]; sort(a, b, 0, a.length-1); } ...
[]
[ { "body": "<h2>Generics</h2>\n\n<p>In Java, it is not safe to create an array of a generic type. This is what you are doing...</p>\n\n<p><code>Comparable</code> is really <code>Comparable&lt;T&gt;</code>, and you are creating an array of <code>Comparable[]</code>.</p>\n\n<p>Because the generic types get removed...
{ "AcceptedAnswerId": "42615", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T13:33:53.603", "Id": "42590", "Score": "3", "Tags": [ "java", "mergesort" ], "Title": "Is there anything to improve in this MergeSort code in Java?" }
42590
<p>The code is no longer relevant but I want to know how I can make it faster. It uses only about 10% of my CPU. Any advice about best practices, better algorithms, or how to make the existing one faster are welcome. This is purely for the purpose of personal learning.</p> <pre><code>public class BruteForce { public s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T20:50:11.230", "Id": "73453", "Score": "1", "body": "My recommendation is don't waste your time brute forcing over the network. The bottleneck will never be optimization of code (unless incredibly bad) it will be your connection." ...
[ { "body": "<p>A huge amount of you work is just plain work that has to be done.... (the joys of brute-forcing).</p>\n\n<h2>MessageDigest</h2>\n\n<p>On the other hand, this work is unnecessary:</p>\n\n<pre><code>byte[] pub2 = MessageDigest.getInstance(\"SHA-256\").digest(pub);\n</code></pre>\n\n<p>This should be...
{ "AcceptedAnswerId": "42593", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T14:08:47.550", "Id": "42591", "Score": "10", "Tags": [ "java", "performance" ], "Title": "Speeding up brute force algorithm" }
42591
<p>I am very beginning in PHP and Design Patterns. I have been studying the beautiful book "Head first: Design pattern" and I have been working in some of the codes originally presented in Java in order to learn more about PHP-OOP. The code below presents a kind of Observer Pattern. It is working well, however there ar...
[]
[ { "body": "<ol>\n<li>Your are using the observer-pattern in a right way. The pattern itself is probably one of the most important ones. In PHP it is not used that much though as applications have a rather quick life-cycle. Yet good to know the pattern of course. Some minor remarks about your code though:\n<ul>\...
{ "AcceptedAnswerId": "42882", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T14:27:37.593", "Id": "42594", "Score": "2", "Tags": [ "php", "design-patterns", "php5" ], "Title": "How to deal with some of the dependencies?" }
42594
<p>For YAML the data serialization standard visit: <a href="http://www.yaml.org/" rel="nofollow">http://www.yaml.org/</a></p> <p>For YAML the CSS framework visit: <a href="http://www.yaml.de/" rel="nofollow">http://www.yaml.de/</a></p> <p>Wiki link - <a href="http://en.wikipedia.org/wiki/YAML" rel="nofollow">http://e...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T14:36:45.350", "Id": "42597", "Score": "0", "Tags": null, "Title": null }
42597
YAML: YAML Ain't Markup Language. YAML is a human friendly data serialization standard for all programming languages. In some cases it can also refer to YAML: Yet Another Multicolumn Layout. An open source CSS framework. See http://www.yaml.de
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T14:36:45.350", "Id": "42598", "Score": "0", "Tags": null, "Title": null }
42598
<p>I am (in the process of) creating a system to store People and their details - names, date of birth (dob), addresses, phone numbers, etc. - and I'm curious how it is best achieved. Below is an an example of some of the SQL code with test data (the PHP classes match the structure in the db):</p> <pre><code>CREATE TA...
[]
[ { "body": "<p><strong>First Question</strong>: Don't let potential use-cases of your application drive how you model the data. As you experienced, this causes a lot of headache later on. </p>\n\n<p>Extracting the dob &amp; dod for performance reasons is premature in this case. It is absolutely ok to load data e...
{ "AcceptedAnswerId": "42618", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T15:00:44.373", "Id": "42599", "Score": "2", "Tags": [ "php", "classes" ], "Title": "Best structure for a Person in PHP classes (and databse)" }
42599
<p>I'm learning C for mainly for fun and to get a better understanding of how things work under the hood (most of my experience lies with high-level languages). I've been following quite a few books and working through the exercises. For extra practice, I've implemented a linked list using the knowledge I've learned - ...
[]
[ { "body": "<p><strong>Making it type-generic</strong></p>\n\n<p>The key to making it generic is in the ll add function. This should take the size of the object you want to add, and a pointer to the data member:</p>\n\n<p><code>llist_node *llist_node_create(void * pData, uint size);</code></p>\n\n<p>And then th...
{ "AcceptedAnswerId": "42627", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T15:04:44.297", "Id": "42600", "Score": "5", "Tags": [ "c", "linked-list", "memory-management", "pointers" ], "Title": "Linked list implementation in C" }
42600
<p>Here is a very basic Snake game in C, which I just want to make better. The game is working perfectly but it is very annoying because when playing it, it is always blinking. I hope that somebody could try it in their compiler to see how annoying it is. How can I improve this?</p> <p>Here is a screen shot of the gam...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-27T00:38:31.137", "Id": "74002", "Score": "3", "body": "Just use `gotoxy` instead of clearing the whole screen buffer with `system(\"cls\")` that is why it is flushing all over again when updating. I have done this before :D" } ]
[ { "body": "<h1>Things that could be improved:</h1>\n\n<h3>Portability:</h3>\n\n<ul>\n<li><p>Every time you add an <code>#import</code> to the top of your C file, you potentially create a dependency. For example: <code>#include &lt;windows.h&gt;</code> creates a dependency that the program can only be compiled ...
{ "AcceptedAnswerId": "42913", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T15:18:12.043", "Id": "42602", "Score": "15", "Tags": [ "performance", "c", "game", "snake-game" ], "Title": "Snake game in C" }
42602
<p>Here is what I have. I have it outputting most of the sums just so I can check there values. I think the problem is with the value of the elements in the array storing the column sums. I would greatly appreciate any feedback. </p> <pre><code>#include &lt;iostream&gt; #include &lt;cmath&gt; using namespace std; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T17:22:46.800", "Id": "73420", "Score": "0", "body": "You seem to lack the outermost level of indentation. If that is an artifact of pasting the code into Code Review, please be aware that the Stack Exchange text editor can indent a ...
[ { "body": "<p>The size of the matrix is hard-coded all over the place. You made a good attempt to define <code>const int SIZE = 4</code> in <code>main()</code>, and you pass <code>SIZE</code> to your functions. However, you still hard-code <code>int matrix[][4]</code>, <code>int row[4]</code>, and <code>int c...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T16:24:26.663", "Id": "42607", "Score": "1", "Tags": [ "c++", "matrix" ], "Title": "Test whether or not a 4x4 matrix is a magic square" }
42607
<blockquote> <p>The prime factors of 13195 are 5, 7, 13 and 29.</p> <p>What is the largest prime factor of the number 600851475143 ?</p> </blockquote> <p>I wrote the following code with help of some Java 8, I'll explain the equivalent to Java 7 under the code. I'd like general comments. One note to give up ahead is tha...
[]
[ { "body": "<p>Actually, your iterator is two iterators - one for the known primes (from previous 'warmups'), and one for unknown primes. Your known prime iterator's choice of implementation looks a bit cumbersome - you could have used a simple list of <code>Long</code>, and iterate over it:</p>\n\n<pre><code>pr...
{ "AcceptedAnswerId": "42693", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T16:51:29.207", "Id": "42609", "Score": "13", "Tags": [ "java", "project-euler", "primes", "java-8" ], "Title": "Project Euler \"Largest prime factor\" (#3) in Java" }
42609
<p>I have articles on my website (built in PHP) and when an article is viewed the number of views is recorded back in the database. The SQL code snippet of my <code>load</code> method is:</p> <pre><code>SELECT * FROM article WHERE id = :id; UPDATE article SET views = views + 1 WHERE id = :id; </code></pre> <p>This wo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T01:46:48.413", "Id": "73476", "Score": "1", "body": "An update statement like you have written is about as good as you will get (using sql). Whether it effects performance will be dependent on if your database does row or table lock...
[ { "body": "<p><strong>The performance with simple queries such as yours will depend more on what is going on in the database than what is going on in your code.</strong></p>\n\n<p>Here are a few things to consider if you are maintaining the DB yourself, or to bring up with the DBA if you are not:</p>\n\n<ol>\n<...
{ "AcceptedAnswerId": "44096", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T18:01:29.207", "Id": "42617", "Score": "5", "Tags": [ "php", "sql", "concurrency" ], "Title": "Updating number of article views - potential concurrent access issue?" }
42617
<p>I have this enum below:</p> <pre><code>public enum TestEnum { h1, h2, h3, h4; public static String forCode(int code) { return (code &gt;= 0 &amp;&amp; code &lt; values().length) ? values()[code].name() : null; } public static void main(String[] args) { System.out.println(TestEnum.h1.na...
[]
[ { "body": "<p>I would pass a <code>TestEnum</code> instead of a <code>String</code> to your method, forcing the exception handling to be outside the method. I don't see why you are using Strings at all actually (although I suspect that this is only a small part of your code, and that you have your reasons for n...
{ "AcceptedAnswerId": "42621", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T20:05:49.963", "Id": "42620", "Score": "4", "Tags": [ "java", "enum" ], "Title": "Validating an input string against some enum fields" }
42620
<p>I am trying to convert over to MySQLi and wanted expert advice. Is the enclosed code 100% OOP. Also, how secure is the code against attacks? I know nothing is 100% secure, but how good/safe is it? How and what can I make better? This is just a generic query as I wanted to get a basic model setup.</p> <pre><cod...
[]
[ { "body": "<p>Your binding of parameters will help in preventing SQL injections.</p>\n\n<p>You need to sanitize your data first though.\nYou need to treat everything that comes from a user (passed from the client machine) as 'dirty' and not allow it into your system before it's been 'cleaned'. Your first step w...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T21:11:33.713", "Id": "42623", "Score": "4", "Tags": [ "php", "object-oriented", "security", "mysqli" ], "Title": "Does this generic query follow good OOP standards?" }
42623
<p>I am working on some multi-threaded code that requires a prime-number source.</p> <p>The following code keeps an array of primes in memory, extending it as needed. It works in the 'int' domain, being careful to avoid overflows, and to keep the memory for storing the data relatively small.</p> <p>it uses a state-ba...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T06:52:36.747", "Id": "73490", "Score": "1", "body": "Regarding your comment in the code: A semi-decent sieve implementation uses bitsets and only requires 128MB memory :)" }, { "ContentLicense": "CC BY-SA 3.0", "Creation...
[ { "body": "<p>Think I've found one concurrency issue :</p>\n\n<p>in </p>\n\n<pre><code>private void extendStateTo(final PrimeState estate, final int to) {\n if (lock.compareAndSet(false, true)) {\n // we are the thread with the lock...\n try {\n // OK, we are the only thread in here,...
{ "AcceptedAnswerId": "42705", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T02:28:13.693", "Id": "42636", "Score": "18", "Tags": [ "java", "thread-safety", "primes" ], "Title": "Thread-safe prime number source" }
42636
<p>I have a website which has reviews about games. Right now, to list the advantages (+) and disadvantages (-) of that game, there's a textarea in the admin panel with a WYSIWYG editor with only element. So my users list their (+) with list elements :</p> <pre><code>&lt;ul&gt; &lt;li&gt;Game is too slow&lt;/li&gt...
[]
[ { "body": "<p>First of all, there's a problem with the HTML approach you have:</p>\n\n<ul>\n<li>That's risky (XSS most of the time)</li>\n<li>Do you expect them to be web developers? I can be a gamer/reviewer with zero HTML knowledge.</li>\n<li>We're writing a review, we should only write reviews, not HTML. Lea...
{ "AcceptedAnswerId": "42638", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T02:38:25.370", "Id": "42637", "Score": "3", "Tags": [ "php", "mysql", "json" ], "Title": "Listing with JSON or plain HTML" }
42637
<p>In an effort to complete <a href="https://codereview.meta.stackexchange.com/a/1472/23788">this month's code challenge</a>, I've started off with the basics. Below I have for review, a class that I can call to create the square/button a user would click to mark a spot on a Tic Tac Toe board. I haven't done any game l...
[]
[ { "body": "<p>Overall this is looking pretty good. I do have a few questions and suggestions based on what I see.</p>\n<ol>\n<li><p>Constructor<br />\nYour class extends MovieClip therefore it IS a Movieclip. What is the purpose of the inner <code>_square</code> class variable? Is SquareSpace meant to be purely...
{ "AcceptedAnswerId": "42728", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T05:41:46.110", "Id": "42642", "Score": "15", "Tags": [ "object-oriented", "game", "actionscript-3", "community-challenge" ], "Title": "UltimateTicTacToe - ActionScript Styl...
42642
<p>I'm new to this PDO PHP and I have coded this spaghetti style. I hope you can give me idea how to improve using prepared statements. I'm not a lazy person, but I really need your help to improve my coding style.</p> <pre><code> try { $select = "SELECT users.id, users.users_id, username, firstnam...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T08:34:32.567", "Id": "73492", "Score": "0", "body": "That's not spaghetti style. Spaghetti style is when you intermingle this code in the middle an html page while rendering a table from the results :)" } ]
[ { "body": "<p>First, a few minor remarks:</p>\n\n<ul>\n<li><p>Your spacing and indentation is inconsistent, e.g. <code>$category=='student'</code> vs. <code>$category == 'instructor'</code>, <code>else if</code> vs. <code>elseif</code>. If you have decided on a coding style, follow it through. It doesn't matter...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T07:08:59.297", "Id": "42644", "Score": "4", "Tags": [ "php", "beginner", "mysql", "pdo" ], "Title": "MySQL PDO query to search by name and role" }
42644
<p>I would like to improve the interfaces of some polymorphic classes going from positional to named parameters and I came up with the fluent interface.</p> <p>The following is the most clean, compact and compilable (-std=c++11 required) example that I have been able to come up with:</p> <pre><code>#include &lt;iostr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T10:15:58.053", "Id": "73496", "Score": "0", "body": "as a quick aside: you can solve the type problem with a template, e.g. `template <T> struct Figure { T name(...) ...}`, then `struct Square: Figure<Square*>`. Not sure if that's t...
[ { "body": "<blockquote>\n <p>After having called the method name(\"name\") the type is lost so there is still an ordering to be respected: add((new Square)->name(\"s1\")->side(1.)) will not compile. </p>\n</blockquote>\n\n<p>You could do that using a template as follows:</p>\n\n<pre><code>template&lt;typename ...
{ "AcceptedAnswerId": "42668", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T10:02:14.197", "Id": "42647", "Score": "10", "Tags": [ "c++", "c++11", "inheritance", "polymorphism", "fluent-interface" ], "Title": "Fluent interface and polymorphism ...
42647
<p>I have implemented customized encoding mechanism for javaUTF16. Does this implementation support all the characters? </p> <pre><code>public class Encoding { public static void main(String[] args) { byte [] arr = new byte[1000]; String str = "abcde" ; //even this encoding works supplementary ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T12:45:46.603", "Id": "73664", "Score": "0", "body": "I would like to be sure you already read http://utf8everywhere.org/" } ]
[ { "body": "<h2>Style</h2>\n\n<p>Method names in Java <a href=\"http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-135099.html#367\">start with a lower-case letter</a>.</p>\n\n<ul>\n<li><code>Encode(...)</code> -> <code>encode(...)</code></li>\n<li><code>Decode(...)</code> -> <code>decod...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T11:25:14.353", "Id": "42649", "Score": "11", "Tags": [ "java", "strings", "unicode" ], "Title": "Customised Java UTF-16" }
42649
<p>The word processor I've had in mind would be similar to Microsoft Word and OpenOffice. I am trying to keep my logic separated from the user Interface and that separated from the controller, basically using the MVC (Model View Controller).</p> <p>Other things I would like reviewed would be code layout: should I try ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T12:13:29.800", "Id": "73507", "Score": "3", "body": "You shouldn't extends JFrame: http://stackoverflow.com/questions/1143923/why-shouldnt-you-extend-jframe-and-other-components" }, { "ContentLicense": "CC BY-SA 3.0", "C...
[ { "body": "<p>At face value the code looks OK. I want to focus on one area, though: File Management</p>\n\n<p>You use <code>FileInputStream</code> and <code>FileOutputStream</code> to read and write your files.</p>\n\n<p>Input/Output streams are designed for byte data. You do not have bytes, you have characters...
{ "AcceptedAnswerId": "42653", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T11:42:57.807", "Id": "42651", "Score": "8", "Tags": [ "java", "object-oriented", "mvc" ], "Title": "Making a word processor" }
42651
<p>I've been trying to learn how to use the TPL for quite some time now. Basically I'm trying to fire off a group of Tasks, wait for them to complete and then fire off another group of tasks, waiting for them to complete before firing off the tasks that update form elements on the UI Thread.</p> <p>Here's what I got. ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T13:47:33.160", "Id": "73514", "Score": "0", "body": "I presume `DoSomething()` is just a method that runs something like `Thread.Sleep(1000);`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T15:03:26...
[ { "body": "<p>Since <code>await</code> is effectively a continuation anyway, you could simplify your function to:</p>\n\n<pre><code>private async Task PrepareData()\n{\n Task[] FirstTasks = new Task[] { TaskOne(), TaskTwo() }; // Do First group of Tasks\n await Task.WhenAll(FirstTasks); // Wait for Fir...
{ "AcceptedAnswerId": "44791", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T12:19:44.643", "Id": "42652", "Score": "6", "Tags": [ "c#", "multithreading", "winforms" ], "Title": "Chaining Tasks with async/await" }
42652
<p>How would you DRY up this RSpec code?</p> <pre><code>require "spec_helper" describe InvoiceMailer do let(:user) { create(:user) } let(:student) { create(:student, user: user) } let(:body) { "And I for one will join with anyone, don't care what color you are. As long as you want change this miserable conditio...
[]
[ { "body": "<p>You can use the <code>its</code> syntax:</p>\n\n<pre><code>require \"spec_helper\"\n\ndescribe InvoiceMailer do\n let(:user) { create(:user) }\n let(:student) { create(:student, user: user) }\n let(:body) { \"And I for one will join with anyone, don't care what color you are. As long as you wan...
{ "AcceptedAnswerId": "42679", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T13:59:29.417", "Id": "42656", "Score": "3", "Tags": [ "ruby", "email", "rspec" ], "Title": "RSpec tests for an invoice mailer" }
42656
<p>This is small piece of bigger puzzle, but usable by its own. It an attempt to have a nonblocking queue with "unlimited" (besides memory size) buffer length.</p> <p>Got unit-tests 100% statement coverage, it looks that it's ok, but I'm very new to Go and concurrency so I might miss something.</p> <pre><code>import ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2018-08-11T16:58:35.243", "Id": "387994", "Score": "0", "body": "I wonder why did you choose do it with channels. You can do much better with mutexes." } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T14:44:10.397", "Id": "42660", "Score": "4", "Tags": [ "asynchronous", "queue", "go" ], "Title": "Queue with \"unlimited\" buffer in Go" }
42660
<p>The architecture is showing a call to an external Web Service which is called by me. Then I will expose the data using WCF to be callable from another WCF client. But I really don't like how it's done. Interfaces, contracts, implementation in the BLO and implementations on the DAL.</p> <p>7 time copy &amp; paste of...
[]
[ { "body": "<p>You've turned your IoC container into a <a href=\"http://en.wikipedia.org/wiki/Service_locator_pattern\">Service Locator</a> (happens when you pass the IoC container around as a dependency)!</p>\n\n<pre><code>public void Install(IWindsorContainer container, IConfigurationStore store)\n ...
{ "AcceptedAnswerId": "42670", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T15:06:04.080", "Id": "42663", "Score": "3", "Tags": [ "c#", "web-services", "wcf" ], "Title": "Call to external web service" }
42663
<p>I'm writing wrapper functions for some of the functions in <code>&lt;algorithm&gt;</code>. While the following works perfectly, I'm not sure if this is the best way to approach it:</p> <pre><code>template&lt;class ContainerType, class Predicate&gt; ContainerType filter( const ContainerType&amp; container, P...
[]
[ { "body": "<p>The use of template parameters here is just fine. You can call the second one <code>UnaryPredicate</code> if that makes you happier, but in the end, C++ currently lacks the ability to specify further requirements on template arguments. (That's what concepts are for.)</p>\n\n<p>So you really need t...
{ "AcceptedAnswerId": "42672", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T15:56:37.477", "Id": "42671", "Score": "3", "Tags": [ "c++", "template" ], "Title": "Could this template function be improved?" }
42671
<p>I have these two carousels that randomly pick up pictures. <strong><a href="http://jsfiddle.net/stonecold111/YrPc7/18/" rel="nofollow">[fiddle]</a></strong> Each of them picks up pictures and links from their own different inner array. It works fine as it is, but I was just wondering if there's any part that I can e...
[]
[ { "body": "<p>From a once over:</p>\n\n<ul>\n<li><p>You can use <code>$('#carousel1, #carousel2').jsCarousel(...);</code> or even better<br></p>\n\n<pre><code>$('.carouselSelector').jsCarousel(...);\n</code></pre></li>\n<li>The name <code>theImagesabc</code> is terrible, just terrible</li>\n<li>Shuffling each a...
{ "AcceptedAnswerId": "42684", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T16:25:04.953", "Id": "42676", "Score": "1", "Tags": [ "javascript", "jquery", "array" ], "Title": "Same function but use different array data" }
42676
<p>I have implemented a basic <code>object</code> class in C++, and I want to make sure that I have implemented everything <em>efficiently and safely</em>, as I made a few mistakes while making it, which I corrected, but I could have left a few more mistakes behind:</p> <pre><code>class object { private: class dum...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T21:20:29.407", "Id": "73585", "Score": "0", "body": "1) Replace `{ }` with `= default;` 2) Get rid of names starting with underscore(s)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T21:51:12.147", ...
[ { "body": "<ul>\n<li><p>As per common naming convention, the class names should start with a capital letter.</p></li>\n<li><p>It may be more readable to put the <code>template</code> line above the <code>class</code> line:</p>\n\n<pre><code>template &lt; typename _Ty &gt;\nclass data : public dummy\n{\n}\n</cod...
{ "AcceptedAnswerId": "42689", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T17:37:53.770", "Id": "42681", "Score": "6", "Tags": [ "c++", "reinventing-the-wheel", "object" ], "Title": "Basic C++ object class" }
42681
<p>The following PHP code does exactly what I need it to do but, as a complete PHP novice, I am wondering: what can be improved here?</p> <pre><code>$theurl='./section-1.html'; function getbody1($filename) { $file = file_get_contents($filename); $bodypattern = ".*"; $bodyendpattern = ".*"; $thecontainer = "id=...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T19:34:34.710", "Id": "73569", "Score": "1", "body": "Can you please add a little description of what it is that your code does, and what you are using it for?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014...
[ { "body": "<pre><code>$theurl='./section-1.html';\nfunction getbody1($filename) {\n $file = file_get_contents($filename);\n //$bodypattern = \".*&lt;body&gt;\";\n //$bodyendpattern = \"&lt;/body&gt;.*\";\n //$thecontainer = \"id=\\'container\\'\";\n //$thecleanup = \"&lt;div &gt;\";\n $noheader = preg_rep...
{ "AcceptedAnswerId": "42761", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T18:42:14.797", "Id": "42691", "Score": "3", "Tags": [ "php", "beginner" ], "Title": "Get contents from file" }
42691
<p>I've implemented Excel's <a href="http://office.microsoft.com/en-us/excel-help/sumifs-function-HA010047504.aspx" rel="noreferrer">SUMIFS function</a> in <a href="http://pandas.pydata.org" rel="noreferrer">Pandas</a> using the following code. Is there a better — more Pythonic — implementation?</p> <pre><code>from pa...
[]
[ { "body": "<p>The usual approach -- if you want all the projects -- would be</p>\n\n<pre><code>&gt;&gt;&gt; df.groupby(\"PROJECT\")[\"HOURS\"].sum()\nPROJECT\nA001 15\nB002 6\nC003 11\nName: HOURS, dtype: float64\n</code></pre>\n\n<p>This only applies the <code>sum</code> on the desired colum...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T19:40:14.960", "Id": "42695", "Score": "6", "Tags": [ "python", "excel", "pandas" ], "Title": "Excel's SUMIFS implemented using PANDAS, the Python Data Analysis Library" }
42695
<pre><code>function transform(tree,fn){ var root = tree, node = tree, child, parent, is_node, dir; root.dir = 0; while(true) { is_node = typeof(node)==="object"; dir = is_node ? node.dir : 2; if (dir &lt; 2) child = node[dir], ...
[]
[ { "body": "<p>Ok, I've decided to write something after all, however not about the performance, but about the coding style. </p>\n\n<p>First off you should give more information what your function actually does. It took me a lot of time to understand that it you are working with binary trees here. </p>\n\n<p>I ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T21:22:43.230", "Id": "42700", "Score": "2", "Tags": [ "javascript", "algorithm", "tree" ], "Title": "JavaScript bottom-up tree transformer aimed for performance" }
42700
<p>Interested in a review of this code, in particular the (hopefully monadic) bind. I actually put this to good use. It was a nice complement to Guava's Optional, and shorter than:</p> <blockquote> <p>Optional.fromNullable(x).or(y);</p> </blockquote> <p>And I threw in a <code>bind</code> method, which I think lifts...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T04:17:43.370", "Id": "73613", "Score": "1", "body": "For what it's worth, in Haskell, the types for Either are `Left` and `Right`." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T05:05:20.903", "I...
[ { "body": "<p><strong>Documentation</strong></p>\n\n<p>I don't know if you're using this class as some kind of api are not, but if you're providing documentation, make sure it's useful and clear.</p>\n\n<pre><code>/**\n * constructor sets the default &amp; value the same\n * @param defaultValue\n */...
{ "AcceptedAnswerId": "42709", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T21:31:09.493", "Id": "42702", "Score": "10", "Tags": [ "java", "monads" ], "Title": "An Either Monad in Java" }
42702
<p>I've hacked together some code to read the content from a sequence of files:</p> <pre><code>let fileContents = [ "filename1"; "filename2"; "etc" ] |&gt; Seq.map(fun file -&gt; async { use fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read) let data = Array.create(int f...
[]
[ { "body": "<p>You can take advantage of async to do parallel IO which Async.Parallel makes very easy. Also, when you don't need the return value of an async call you can use Async.ignore in combination with do!: <code>do! fs.AsyncRead(data, 0, data.Length) |&gt; Async.ignore</code></p>\n\n<p>However this specif...
{ "AcceptedAnswerId": "42799", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T21:33:37.803", "Id": "42703", "Score": "2", "Tags": [ "asynchronous", "f#", "concurrency" ], "Title": "Is this a good use of Async in F#?" }
42703
<p>Recently I needed to save session state in cookies, instead of server side. I looked around and didn't see anything similar, so I decided to write something to handle the encryption, decryption, and validation of the cookies. I wanted some opinions before/if I release it on packagist.</p> <p>Any feedback would be...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T21:35:13.563", "Id": "73586", "Score": "0", "body": "Please embed the code you'd like reviewed. It shouldn't just be behind a link." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T21:36:28.893", ...
[ { "body": "<p>Overall your design looks good for me. Nothing really bad here. Some suggestions on your architecture though:</p>\n\n<p>Your cookie implementation is dependent on the <code>CryptoSystem</code> and the <code>CookieStorage</code>. But then a Cookie doesn't actually care about how it is stored or if ...
{ "AcceptedAnswerId": "42874", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T21:34:18.620", "Id": "42704", "Score": "4", "Tags": [ "php", "cryptography" ], "Title": "Cookie encryption library" }
42704
<p>I need some help reviewing this code in terms of making as fast as possible. This is a modified version of BFS that does quite a bit of processing on the side.</p> <p><strong>Use case:</strong></p> <p>I have a large graph (probably tens of thousands of nodes). Every edge is defined by three parameters currently - ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T06:18:23.823", "Id": "73627", "Score": "0", "body": "Wow...that is a lot of code. I won't even worry about the bfs implementation if I were you, instead I would be looking for a way to make that path comparison code have less code i...
[ { "body": "<p>I'd suggest having a look at <a href=\"http://lukauskas.co.uk/articles/2014/02/13/why-your-python-runs-slow-part-1-data-structures/\" rel=\"nofollow\">Why Your Python Runs Slow. Part 1: Data Structures</a> as it seems to apply to your code.</p>\n\n<hr>\n\n<p>Your <code>_path_comparison</code> is a...
{ "AcceptedAnswerId": "42757", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-24T23:23:39.137", "Id": "42708", "Score": "5", "Tags": [ "python", "optimization", "python-3.x", "graph", "breadth-first-search" ], "Title": "Modified BFS code optimizatio...
42708
<p>Based on my understanding of Verlet integration I tryed to use it over my Euler method to move my character in a 2D space. I will put only the neccessery code, but if anything else is needed I will edit my post.</p> <p>This is my Character class (which I probably need to rename to Charactor)</p> <pre><code>class P...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-26T08:52:36.373", "Id": "73849", "Score": "0", "body": "Hello! Does your code work? The question is currently unclear. We cannot really help with the integration method per se, but can help to get cleaner code. For example, simplifying...
[ { "body": "<pre><code> def handler(self):\n '''\n Calls Player on_x_key_pressed(), on_x_key_released()\n methods according to event bools set from the listener method.\n '''\n # Moving\n if self.left_key_pressed and self.right_key_pressed:\n self.player.ke...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T00:10:21.280", "Id": "42710", "Score": "3", "Tags": [ "python", "game", "python-3.x" ], "Title": "Verlet integration movement - doubt for on_key_press() methods" }
42710
<p>Cluster analysis or clustering is the task of grouping a set of objects in such a way that objects in the same group (called a cluster) are more similar (in some sense or another) to each other than to those in other groups (clusters). It is a main task of exploratory data mining, and a common technique for statisti...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T00:58:28.837", "Id": "42715", "Score": "0", "Tags": null, "Title": null }
42715
Cluster analysis or clustering is the task of grouping a set of objects in such a way that objects in the same group (called a cluster) are more similar (in some sense or another) to each other than to those in other groups (clusters).
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T00:58:28.837", "Id": "42716", "Score": "0", "Tags": null, "Title": null }
42716
<p>I have an image and a text title that I'm trying to center in a div. I would like the image to be to the left of the title, and for both of these elements to be centered both horizontally and vertically in the div.</p> <p>I've found one way to do it, by nesting the image inside of a paragraph. I'm assuming this i...
[]
[ { "body": "<p>You can simplify your HTML to this:</p>\n\n<pre><code>&lt;div id=\"parent\"&gt;\n &lt;div class=\"floaters right\"&gt;&lt;img src=\"cid:logo-img\" /&gt;&lt;/div&gt;\n &lt;div class=\"floaters\"&gt;Title&lt;/div&gt;\n &lt;div class=\"centerme\"&gt;$message&lt;/div&gt;\n&lt;/div&gt;\n</code...
{ "AcceptedAnswerId": "42724", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T01:00:44.483", "Id": "42717", "Score": "3", "Tags": [ "html", "css" ], "Title": "Vertically and horizontally center these HTML elements" }
42717
<p>I have coded up an implementation of Conway's Game of Life and I have a performance bottleneck in it which I wish to be optimized. The main logic is in the <code>Universe</code> class. I have omitted all code which is not applicable here for brewity:</p> <pre><code>public class Universe { private static final ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T01:12:03.050", "Id": "73599", "Score": "0", "body": "What was the problem with the old title?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T03:33:27.897", "Id": "73608", "Score": "0", "b...
[ { "body": "<p>That <code>countLiveNeighbors</code> function looks expensive; are you sure <code>for (CellNeighbor neighbor : CellNeighbor.values())</code> isn't doing a whole bunch of <code>new CellNeighbor</code> calls (and garbage-collection) behind the scenes?</p>\n\n<p>Even more importantly: All that except...
{ "AcceptedAnswerId": "42790", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T01:07:01.227", "Id": "42718", "Score": "22", "Tags": [ "java", "performance", "game-of-life" ], "Title": "Optimize Conway's Game of Life" }
42718
<p>I wanted to find out which states and cities the USA hockey team was from, but I didn't want to manually count from the roster site <a href="http://olympics.usahockey.com/page/show/1067902-roster" rel="noreferrer">here</a>.</p> <p>I'm really interested to see if someone has a more elegant way to do what I've done (...
[]
[ { "body": "<ul>\n<li><p>You can use <a href=\"http://docs.python.org/2/library/functions.html#enumerate\" rel=\"nofollow\">enumerate</a> in order not to play with <code>counter</code>.</p>\n\n<pre><code>for counter,entry in enumerate(entries):\n if counter == 6:\n locations.append(entry.get_text().enc...
{ "AcceptedAnswerId": "42785", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T03:44:09.983", "Id": "42727", "Score": "6", "Tags": [ "python", "html", "parsing" ], "Title": "First program with scraping, lists, string manipulation" }
42727
<p>I have two <code>div</code>s as seen in this <a href="http://jsfiddle.net/y7PEp/12/" rel="nofollow">JSFiddle</a>. To recreate the problem, keep clicking on the Gray container till both divisions touch each other.</p> <p>The purpose is to execute a certain function once the green <code>div</code> touches the red one...
[]
[ { "body": "<p><a href=\"http://jsfiddle.net/y7PEp/15/\" rel=\"nofollow\">You can do this</a>:</p>\n\n<pre><code>// Let's make it a jQuery plugin so each element acts independently\n$.fn.collider = function () {\n return $.each(this, function () {\n\n // a flag when done\n var done = false;\n\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T07:12:24.250", "Id": "42735", "Score": "3", "Tags": [ "javascript", "jquery", "html", "css", "collision" ], "Title": "Detecting collision of two divs" }
42735
<p>I would love a second opinion / another pair of eyes on this.</p> <pre><code>db.customers.mapReduce( function() { Array.prototype.getUnique = function() { var u = {}, a = []; for (var i = 0, l = this.length; i &lt; l; ++i) { if (u.hasOwnProperty(this[i])) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T14:39:08.157", "Id": "73684", "Score": "1", "body": "Hi, please provide more context to your code, and ideally put a title that says what the code does - *everybody* posting here is looking for a 2nd pair of eyes ;)" }, { "C...
[ { "body": "<p>I'm not familiar with MR best practices, but here are some JS-specific comments.</p>\n\n<h1>Key Points</h1>\n\n<ul>\n<li><p>DRY - that emit code is repeated all over the place and has only slight changes - parameterize what varies and put it all in a function</p></li>\n<li><p>You are repeating you...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T09:28:20.717", "Id": "42740", "Score": "3", "Tags": [ "javascript", "mongodb", "mapreduce" ], "Title": "Customer MapReduce implementation" }
42740
<p>I was wondering if there is a smarter way of doing the following code. Basically what is does is that it opens a data file with a lot of rows and columns. The columns are then sorted so each column is a vector with all the data inside.</p> <pre><code>"3.2.2 - Declare variables" lineData = list() for line in Fil...
[]
[ { "body": "<p>First of all don't create variables for those keys, store them in a list.</p>\n\n<pre><code>keys = [\"ElemNo\", \"Node1\", \"Node2\", \"Length\", \"Area\", \"Inertia\",\n \"Fnode1\", \"Fnode2\", \"SigmaMin\", \"SigmaMax\"]\n</code></pre>\n\n<p>You can use <code>collections.defaultdict</code...
{ "AcceptedAnswerId": "42742", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T09:44:06.953", "Id": "42741", "Score": "11", "Tags": [ "python", "matrix" ], "Title": "Row/Column Transpose" }
42741
<p>I have come up with a Java 8 solution for the following problem:</p> <blockquote> <p>In the 20×20 grid below, four numbers along a diagonal line have been marked in red (bold here).</p> <p>08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08<br> 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T10:29:52.717", "Id": "73650", "Score": "0", "body": "Can you please provide the string you give for the creation of your problem and anything else one might need to compile and run your program? Thanks in advance" }, { "Cont...
[ { "body": "<p>Your code looks great and I can see that you have put some thought and time into it. Also, you've used pretty fancy concepts that I didn't know (which is not so hard as my Java is pretty rusty). However, it looks slightly over-engineered to me so I'll try to make things more simple.</p>\n\n<ul>\n<...
{ "AcceptedAnswerId": "42749", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T10:21:21.387", "Id": "42744", "Score": "4", "Tags": [ "java", "project-euler", "lambda" ], "Title": "Project Euler \"Largest product in a grid\" (#11) in Java 8" }
42744
<p>I am writing a ASCII dungeon creator inspired from games such as Angband, Moria etc.</p> <p>The main goal of the project is to allow a user to come along and implement their own "DungeonLevelGenerator" so they can generate dungeons however they wish using the interface and tools I've provided to help speed it up.</...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T17:57:22.887", "Id": "73728", "Score": "0", "body": "I took a look at your `Direction` code on GitHub, and I would suggest that you create a new question about just that class. I have a whole lot of things to say about that one :)" ...
[ { "body": "<p><strong>Keep your code extendable</strong> - You created your enum <code>CoreMaterial</code> as an extendable enum, but then you implemented the various <code>isXXX()</code> methods repeating the enum values themselves in them. A better solution might be to let each material declare its own type:<...
{ "AcceptedAnswerId": "42793", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T10:48:56.637", "Id": "42745", "Score": "6", "Tags": [ "java", "game" ], "Title": "API for Dungeon Generator" }
42745
<p>I studied a bit and packed all the suggestions that I received here: <a href="https://codereview.stackexchange.com/questions/42647/fluent-interface-and-polymorphism">Fluent interface and polymorphism for building a scene with shapes</a> and I came up with this:</p> <pre class="lang-cpp prettyprint-override"><code...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-02-10T16:44:09.970", "Id": "145094", "Score": "0", "body": "Have you thought about how your design would work with a rectangle? Are you going to create `Length` and `Width` as new types to make `Rectangle` work? It seems to me that there ...
[ { "body": "<p>You said that you packed all the suggestions from the previous question, but there are still some pieces of advice that you did not integrate into your code. Here is how you can still improve your it:</p>\n\n<h2><code>math.h</code> legacy</h2>\n\n<p>In your code, you are using the constant <code>M...
{ "AcceptedAnswerId": "42869", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T11:12:33.100", "Id": "42748", "Score": "11", "Tags": [ "c++", "c++11", "template", "interface", "polymorphism" ], "Title": "Variadic templates and pointers to member fu...
42748
<p>Here is the code for the QuickSort class that I created.</p> <pre><code>public class QuickSort { public static void sort(Comparable[] a) { quicksort(a, 0, a.length-1); } private static void quicksort(Comparable[] a, int lo, int hi) { if(lo &gt;= hi) return; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-26T14:38:15.300", "Id": "73892", "Score": "0", "body": "Friendly reminder that `java.util.Arrays` has an optimized [`sort` method](http://docs.oracle.com/javase/6/docs/api/java/util/Arrays.html#sort%28java.lang.Object[]%29)" } ]
[ { "body": "<p>Just three quick notes:</p>\n\n<ol>\n<li><p>You could fix the compiler warnings with the following method declarations:</p>\n\n<pre><code>public static &lt;T extends Comparable&lt;T&gt;&gt; void sort(T[] a)\n\nprivate static &lt;T extends Comparable&lt;T&gt;&gt; void quicksort(T[] a, int lo, int h...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T11:28:35.697", "Id": "42750", "Score": "6", "Tags": [ "java", "recursion", "quick-sort" ], "Title": "QuickSort of Comparable[]" }
42750
<p>Here is a function that I've only slightly modified from its original context, found <a href="https://github.com/sightmachine/SimpleCV/pull/607" rel="nofollow noreferrer">here</a>.</p> <p>Before mentioning anything else, it should be noted that I'm desperately trying to optimize this code for speed. It presently t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T14:13:19.520", "Id": "73678", "Score": "2", "body": "Can you add the missing `import` statements so that this is runnable, please?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T14:18:57.063", "I...
[ { "body": "<p>As you indicated in the question, you need to vectorize the <code>for</code> loop:</p>\n\n<pre><code>it = product(xrange(n_divs), xrange(n_divs), xrange(cellx), xrange(celly))\nfor m, n, i, j in it:\n # grad value\n grad = magnit[m * cellx + i, n * celly + j][0]\n # normalized grad value\...
{ "AcceptedAnswerId": "42916", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T14:05:44.447", "Id": "42763", "Score": "7", "Tags": [ "python", "performance", "image", "numpy", "opencv" ], "Title": "\"Histogram of Oriented Gradients\" (HOG) feature...
42763
<p>I've two table (<code>t1</code> and <code>t2</code>) with 3 identical integer columns: <code>c1</code>, <code>c2</code> and <code>c3</code>. I want to count how many value in <code>t1</code> are in <code>t2</code>.</p> <pre><code>SELECT count(t1.value) FROM t1 INNER JOIN t2 ON ( t1.c1 = t2.c1 OR t1.c1 = t2.c2 ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T15:46:26.753", "Id": "73695", "Score": "0", "body": "If t1 contains `c1 = 1, c2 = 1, and c3 = 2` and the t2 has the values `1` and `2` *somewhere*, should that count as 1, 2, or 3 in the final total?" }, { "ContentLicense": ...
[ { "body": "<p>Your question is not very clear... but, the way I understand it is:</p>\n\n<p>Collect all the unique values in <code>t1</code>, and count how many of those unique values appear in <code>t2</code>.</p>\n\n<p>Interesting problem.... instead of a straight join with all the <code>or</code> conditions,...
{ "AcceptedAnswerId": "42776", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T14:49:14.540", "Id": "42766", "Score": "3", "Tags": [ "performance", "sql", "mysql" ], "Title": "Check for similar value with SQL" }
42766
<p>I have some function like:</p> <pre><code>void foo() { ... } int main() { ... try { ... foo(); ... } catch (const std::exception &amp;e) { std::cout &lt;&lt; "Fatal error: e.what() &lt;&lt; std::endl(); return; } ... } </code></pre> <p>If an exception is thrown from <code>foo</code>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T15:34:43.957", "Id": "73691", "Score": "0", "body": "I'd go for the last one. As it has the least chance of creating weird issues. However, I'd not ever throw (then again, I never used C++ Exceptions, just Python and Java). \n\nAnd ...
[ { "body": "<p>You can re-throw an exception:</p>\n\n<pre><code>int main() {\n ... \n try {\n ...\n try\n {\n foo();\n }\n catch(std::exception const&amp; e) {\n std::cout &lt;&lt; \"Fatal error: \" &lt;&lt; e.what() &lt;&lt; std::endl;\n\n ...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T14:54:33.463", "Id": "42767", "Score": "5", "Tags": [ "c++", "exception-handling", "exception", "logging" ], "Title": "How to chain exceptions?" }
42767
<p>Is there any way to make that code shorter? I still want to use jQuery. I don't want to use any validation script.</p> <pre><code>$("#form").submit(function (e) { var tmp = $('#select-1').val(); var tmp1 = $('#select-2').val(); var tmp2 = $('#select-3').val(); var error = $('#error-1'); var error2 =...
[]
[ { "body": "<p>You could hide the errors to begin with (just put <code>style=\"display: none;\"</code> on them), then you don't have to hide them in your script. Also you can group your variable declarations:</p>\n\n<pre><code>$(\"#form\").submit(function (e) {\n var tmp = $('#select-1').val(),\n tmp1 ...
{ "AcceptedAnswerId": "42827", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T15:27:55.033", "Id": "42770", "Score": "2", "Tags": [ "javascript", "jquery", "validation" ], "Title": "Select validation" }
42770
<p>I am a beginner in PHP-OOP and design patterns. I have got this basic piece of code in <a href="https://stackoverflow.com/questions/203336/creating-the-singleton-design-pattern-in-php5">Singleton Pattern</a> and I changed it in order to understand its behavior. I can see that it works as expected.</p> <p>However, i...
[]
[ { "body": "<p>You're misunderstanding how the <a href=\"http://us1.php.net/manual/en/language.oop5.static.php\">static</a> keyword works.</p>\n\n<p>The first time it is encountered for a specific variable in the method it defines the <code>$inst</code> variable as <code>null</code>, then checks to see if it is ...
{ "AcceptedAnswerId": "42774", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T15:35:26.713", "Id": "42771", "Score": "6", "Tags": [ "php", "beginner", "object-oriented", "singleton", "static" ], "Title": "Singleton design pattern" }
42771
<h2>The Setup</h2> <p>This kata is a spin on the old backpack problem. Please give feedback on both the kata itself as well as my solution. I'm not sure if the kata needs to lead the student more or if this is a good open-ended problem. My original intent with this kata was to practice using Hashes. This is why the ou...
[]
[ { "body": "<p><strong>Duck typing</strong> - the ruby language is duck-typed, and should be written that way. Checks on an object's class are frowned upon. If something wants to be an integer, and is prepared to go the distance - don't discourage it! I understand that the requirement says 'should throw an error...
{ "AcceptedAnswerId": "42809", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-25T16:37:58.210", "Id": "42779", "Score": "10", "Tags": [ "ruby", "rspec", "hash-map" ], "Title": "Cash Register Kata" }
42779